Skip to content

Commit

Permalink
fix(add): Use pacote to resolve third-party registry authentication…
Browse files Browse the repository at this point in the history
… woes

`package-json` did not play well with third-party registries due to authentication issues.
`pacote.manifest()` combined with `@lerna/npm-conf` uses the actual machinery behind the npm CLI, and should be more robust.

Fixes #1572
Fixes #1539
  • Loading branch information
evocateur committed Aug 17, 2018
1 parent 3c534eb commit a0fbf46
Show file tree
Hide file tree
Showing 3 changed files with 540 additions and 129 deletions.
12 changes: 7 additions & 5 deletions commands/add/index.js
Expand Up @@ -2,12 +2,13 @@

const dedent = require("dedent");
const npa = require("npm-package-arg");
const packageJson = require("package-json");
const pMap = require("p-map");
const path = require("path");
const pacote = require("pacote");
const semver = require("semver");

const Command = require("@lerna/command");
const npmConf = require("@lerna/npm-conf");
const bootstrap = require("@lerna/bootstrap");
const ValidationError = require("@lerna/validation-error");
const getRangeToReference = require("./lib/get-range-to-reference");
Expand Down Expand Up @@ -142,15 +143,16 @@ class AddCommand extends Command {
}

getPackageVersion() {
const { name, fetchSpec } = this.spec;

if (this.selfSatisfied) {
const node = this.packageGraph.get(name);
const node = this.packageGraph.get(this.spec.name);

return Promise.resolve(this.spec.saveRelativeFileSpec ? node.location : node.version);
}

return packageJson(name, { version: fetchSpec }).then(pkg => pkg.version);
// @see https://github.com/zkat/pacote/blob/latest/lib/util/opt-check.js
const opts = npmConf(this.options);

return pacote.manifest(this.spec, opts).then(pkg => pkg.version);
}

packageSatisfied() {
Expand Down
3 changes: 2 additions & 1 deletion commands/add/package.json
Expand Up @@ -35,11 +35,12 @@
"@lerna/bootstrap": "file:../bootstrap",
"@lerna/command": "file:../../core/command",
"@lerna/filter-options": "file:../../core/filter-options",
"@lerna/npm-conf": "file:../../utils/npm-conf",
"@lerna/validation-error": "file:../../core/validation-error",
"dedent": "^0.7.0",
"npm-package-arg": "^6.0.0",
"p-map": "^1.2.0",
"package-json": "^4.0.1",
"pacote": "^9.1.0",
"semver": "^5.5.0"
}
}

0 comments on commit a0fbf46

Please sign in to comment.