diff --git a/package.json b/package.json index 3f5d0400..f65a84bf 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "np", - "version": "5.1.0", + "version": "5.2.1", "description": "A better `npm publish`", "license": "MIT", "repository": "sindresorhus/np", @@ -30,34 +30,34 @@ ], "dependencies": { "@samverschueren/stream-to-observable": "^0.3.0", - "any-observable": "^0.4.0", + "any-observable": "^0.5.0", "async-exit-hook": "^2.0.1", - "chalk": "^2.3.0", + "chalk": "^3.0.0", "cosmiconfig": "^5.2.1", "del": "^4.1.0", "escape-string-regexp": "^2.0.0", - "execa": "^2.0.1", + "execa": "^3.4.0", "github-url-from-git": "^1.5.0", "has-yarn": "^2.1.0", "hosted-git-info": "^3.0.0", "ignore-walk": "^3.0.2", "inquirer": "^7.0.0", - "is-installed-globally": "^0.2.0", + "is-installed-globally": "^0.3.1", "is-scoped": "^2.1.0", "issue-regex": "^2.0.0", "listr": "^0.14.3", - "listr-input": "^0.1.3", + "listr-input": "^0.2.0", "log-symbols": "^3.0.0", "meow": "^5.0.0", "minimatch": "^3.0.4", "npm-name": "^5.4.0", "onetime": "^5.1.0", - "open": "^6.1.0", - "ow": "^0.13.2", + "open": "^7.0.0", + "ow": "^0.15.0", "p-memoize": "^3.1.0", "p-timeout": "^3.1.0", "pkg-dir": "^4.1.0", - "read-pkg-up": "^6.0.0", + "read-pkg-up": "^7.0.0", "rxjs": "^6.3.3", "semver": "^6.1.2", "split": "^1.0.0", @@ -70,6 +70,6 @@ "proxyquire": "^2.1.0", "mockery": "^2.1.0", "sinon": "^7.3.2", - "xo": "^0.24.0" + "xo": "^0.25.3" } } diff --git a/source/index.js b/source/index.js index 969489d4..4becf332 100644 --- a/source/index.js +++ b/source/index.js @@ -35,6 +35,7 @@ const exec = (cmd, args) => { ).pipe(filter(Boolean)); }; +// eslint-disable-next-line default-param-last module.exports = async (input = 'patch', options) => { options = { cleanup: true, @@ -87,11 +88,13 @@ module.exports = async (input = 'patch', options) => { // The default parameter is a workaround for https://github.com/Tapppi/async-exit-hook/issues/9 exitHook((callback = () => {}) => { - if (publishStatus === 'FAILED' && runPublish) { + if (publishStatus === 'FAILED') { (async () => { await rollback(); callback(); })(); + } else if (publishStatus === 'SUCCESS') { + callback(); } else { console.log('\nAborted!'); callback(); @@ -210,6 +213,8 @@ module.exports = async (input = 'patch', options) => { } ]); } + } else { + publishStatus = 'SUCCESS'; } tasks.add({ @@ -235,6 +240,6 @@ module.exports = async (input = 'patch', options) => { await tasks.run(); - const {package: newPkg} = await readPkgUp(); + const {packageJson: newPkg} = await readPkgUp(); return newPkg; }; diff --git a/source/npm/handle-npm-error.js b/source/npm/handle-npm-error.js index ccafd8f3..d3390151 100644 --- a/source/npm/handle-npm-error.js +++ b/source/npm/handle-npm-error.js @@ -9,7 +9,8 @@ const handleNpmError = (error, task, message, executor) => { message = undefined; } - if (error.stderr.includes('one-time pass') || error.message.includes('user TTY')) { + // `one-time pass` is for npm and `Two factor authentication` is for Yarn. + if (error.stderr.includes('one-time pass') || error.stdout.includes('Two factor authentication')) { const {title} = task; task.title = `${title} ${chalk.yellow('(waiting for input…)')}`; diff --git a/source/npm/util.js b/source/npm/util.js index 197953bb..0f9ba5f2 100644 --- a/source/npm/util.js +++ b/source/npm/util.js @@ -79,12 +79,14 @@ exports.prereleaseTags = async packageName => { }; exports.isPackageNameAvailable = async pkg => { - const isExternalRegistry = exports.isExternalRegistry(pkg); - if (isExternalRegistry) { - return true; + const args = [pkg.name]; + if (exports.isExternalRegistry(pkg)) { + args.push({ + registryUrl: pkg.publishConfig.registry + }); } - return npmName(pkg.name); + return npmName(...args); }; exports.isExternalRegistry = pkg => typeof pkg.publishConfig === 'object' && typeof pkg.publishConfig.registry === 'string'; diff --git a/source/pretty-version-diff.js b/source/pretty-version-diff.js index 3f34fba3..15eb60b8 100644 --- a/source/pretty-version-diff.js +++ b/source/pretty-version-diff.js @@ -8,16 +8,16 @@ module.exports = (oldVersion, inc) => { let firstVersionChange = false; const output = []; - for (let i = 0; i < newVersion.length; i++) { - if ((newVersion[i] !== oldVersion[i] && !firstVersionChange)) { - output.push(`${chalk.dim.cyan(newVersion[i])}`); + for (const [i, element] of newVersion.entries()) { + if ((element !== oldVersion[i] && !firstVersionChange)) { + output.push(`${chalk.dim.cyan(element)}`); firstVersionChange = true; - } else if (newVersion[i].indexOf('-') >= 1) { + } else if (element.indexOf('-') >= 1) { let preVersion = []; - preVersion = newVersion[i].split('-'); + preVersion = element.split('-'); output.push(`${chalk.dim.cyan(`${preVersion[0]}-${preVersion[1]}`)}`); } else { - output.push(chalk.reset.dim(newVersion[i])); + output.push(chalk.reset.dim(element)); } } diff --git a/source/ui.js b/source/ui.js index a89ca702..9e4d1c6b 100644 --- a/source/ui.js +++ b/source/ui.js @@ -69,6 +69,7 @@ module.exports = async (options, pkg) => { const oldVersion = pkg.version; const extraBaseUrls = ['gitlab.com']; const repoUrl = pkg.repository && githubUrlFromGit(pkg.repository.url, {extraBaseUrls}); + const runPublish = options.publish && !pkg.private; if (runPublish) { checkIgnoreStrategy(pkg); @@ -125,7 +126,7 @@ module.exports = async (options, pkg) => { type: 'list', name: 'tag', message: 'How should this pre-release version be tagged in npm?', - when: answers => !pkg.private && version.isPrereleaseOrIncrement(answers.version) && !options.tag, + when: answers => options.publish && !pkg.private && version.isPrereleaseOrIncrement(answers.version) && !options.tag, choices: async () => { const existingPrereleaseTags = await prereleaseTags(pkg.name); @@ -143,7 +144,7 @@ module.exports = async (options, pkg) => { type: 'input', name: 'tag', message: 'Tag', - when: answers => !pkg.private && version.isPrereleaseOrIncrement(answers.version) && !options.tag && !answers.tag, + when: answers => options.publish && !pkg.private && version.isPrereleaseOrIncrement(answers.version) && !options.tag && !answers.tag, validate: input => { if (input.length === 0) { return 'Please specify a tag, for example, `next`.'; diff --git a/source/util.js b/source/util.js index 802f9c46..ffd00df8 100644 --- a/source/util.js +++ b/source/util.js @@ -9,13 +9,13 @@ const gitUtil = require('./git-util'); const npmUtil = require('./npm/util'); exports.readPkg = () => { - const {package: pkg} = readPkgUp.sync(); + const {packageJson} = readPkgUp.sync(); - if (!pkg) { + if (!packageJson) { throw new Error('No package.json found. Make sure you\'re in the correct project.'); } - return pkg; + return packageJson; }; exports.linkifyIssues = (url, message) => {