Skip to content

Commit

Permalink
fix(publish): Prevent retries during access validation so third-party…
Browse files Browse the repository at this point in the history
… registries are skipped faster
  • Loading branch information
evocateur committed Oct 9, 2018
1 parent 7ba41a6 commit a89ae62
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 3 deletions.
9 changes: 8 additions & 1 deletion commands/publish/__tests__/verify-npm-package-access.test.js
Expand Up @@ -38,7 +38,14 @@ describe("verifyNpmPackageAccess", () => {

await verifyNpmPackageAccess(packages, opts);

expect(access.lsPackages).lastCalledWith("lerna-test", opts);
expect(access.lsPackages).lastCalledWith(
"lerna-test",
expect.objectContaining({
username: "lerna-test",
registry: "https://registry.npmjs.org/",
retry: 0,
})
);
});

test("allows unpublished packages to pass", async () => {
Expand Down
11 changes: 9 additions & 2 deletions commands/publish/lib/verify-npm-package-access.js
Expand Up @@ -2,14 +2,21 @@

const log = require("npmlog");
const access = require("libnpmaccess");
const RegistryConfig = require("npm-registry-fetch/config");
const ValidationError = require("@lerna/validation-error");

module.exports = verifyNpmPackageAccess;

function verifyNpmPackageAccess(packages, opts) {
log.silly("verifyNpmPackageAccess");

return access.lsPackages(opts.get("username"), opts).then(success, failure);
// eslint-disable-next-line no-param-reassign
opts = RegistryConfig(opts, {
// don't wait forever for third-party failures to be dealt with
retry: 0,
});

return access.lsPackages(opts.username, opts.toJSON()).then(success, failure);

function success(result) {
// when _no_ results received, access.lsPackages returns null
Expand Down Expand Up @@ -39,7 +46,7 @@ function verifyNpmPackageAccess(packages, opts) {
"EREGISTRY",
"Registry %j does not support `npm access ls-packages`, skipping permission checks...",
// registry
opts.get("registry")
opts.registry
);

// don't log redundant errors
Expand Down

0 comments on commit a89ae62

Please sign in to comment.