Skip to content

Commit

Permalink
Make npm.timeout configurable
Browse files Browse the repository at this point in the history
  • Loading branch information
webpro committed Aug 25, 2020
1 parent 0332981 commit ea3f608
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 6 deletions.
3 changes: 2 additions & 1 deletion config/release-it.json
Expand Up @@ -24,7 +24,8 @@
"tag": null,
"otp": null,
"ignoreVersion": false,
"skipChecks": false
"skipChecks": false,
"timeout": 10
},
"github": {
"release": false,
Expand Down
13 changes: 8 additions & 5 deletions lib/plugin/npm/npm.js
Expand Up @@ -8,7 +8,6 @@ const prompts = require('./prompts');
const options = { write: false };

const MANIFEST_PATH = './package.json';
const REGISTRY_TIMEOUT = 10000;
const DEFAULT_TAG = 'latest';
const DEFAULT_TAG_PRERELEASE = 'next';
const NPM_BASE_URL = 'https://www.npmjs.com';
Expand All @@ -27,18 +26,22 @@ class npm extends Plugin {
const { name, version: latestVersion, private: isPrivate, publishConfig } = require(path.resolve(MANIFEST_PATH));
this.setContext({ name, latestVersion, private: isPrivate, publishConfig });

if (this.options.publish === false || isPrivate) return;
const { publish, skipChecks } = this.options;

if (this.options.skipChecks) return;
const timeout = Number(this.options.timeout) * 1000;

if (publish === false || isPrivate) return;

if (skipChecks) return;

const validations = Promise.all([this.isRegistryUp(), this.isAuthenticated(), this.getLatestRegistryVersion()]);

await Promise.race([validations, rejectAfter(REGISTRY_TIMEOUT)]);
await Promise.race([validations, rejectAfter(timeout)]);

const [isRegistryUp, isAuthenticated, latestVersionInRegistry] = await validations;

if (!isRegistryUp) {
throw new Error(`Unable to reach npm registry (timed out after ${REGISTRY_TIMEOUT}ms).`);
throw new Error(`Unable to reach npm registry (timed out after ${timeout}ms).`);
}

if (!isAuthenticated) {
Expand Down

0 comments on commit ea3f608

Please sign in to comment.