Skip to content

Commit

Permalink
fix: prevent packages that haven't been published from failing (#9169)
Browse files Browse the repository at this point in the history
Simple change that will let us run `yarn run publish` even if packages don't exist.
  • Loading branch information
DSchau authored and pieh committed Nov 13, 2018
1 parent 8aa5081 commit e81dd09
Showing 1 changed file with 17 additions and 4 deletions.
21 changes: 17 additions & 4 deletions scripts/get-unowned-packages/index.js
Expand Up @@ -3,11 +3,13 @@ const PackageGraph = require(`@lerna/package-graph`)
const filterPackages = require(`@lerna/filter-packages`)
const util = require(`util`)
const path = require(`path`)
const exec = util.promisify(require(`child_process`).exec)
const { exec, execSync } = require(`child_process`)

const execP = util.promisify(exec)

const getPackagesWithReadWriteAccess = async user => {
const cmd = `npm access ls-packages ${user}`
const { stdout } = await exec(cmd)
const { stdout } = await execP(cmd)
const permissions = JSON.parse(stdout)
return Object.entries(permissions).reduce((lookup, [pkgName, access]) => {
if (access === `read-write`) {
Expand Down Expand Up @@ -36,15 +38,26 @@ module.exports = function getUnownedPackages({
// infer user from npm whoami
// set registry because yarn run hijacks registry
if (!user) {
user = await exec(`npm whoami --registry https://registry.npmjs.org`)
user = await execP(`npm whoami --registry https://registry.npmjs.org`)
.then(({ stdout }) => stdout.trim())
.catch(() => process.exit(1))
}

const alreadyOwnedPackages = await getPackagesWithReadWriteAccess(user)

const publicGatsbyPackagesWithoutAccess = publicGatsbyPackages.filter(
pkg => !alreadyOwnedPackages[pkg.name]
pkg => {
if (alreadyOwnedPackages[pkg.name]) {
return false
}

try {
return !execSync(`npm view ${pkg.name} version`, { stdio: `pipe` })
.stderr
} catch (e) {
return false
}
}
)

return {
Expand Down

0 comments on commit e81dd09

Please sign in to comment.