Skip to content

Commit

Permalink
Merge branch 'master' into issue_103
Browse files Browse the repository at this point in the history
  • Loading branch information
bunysae committed Dec 11, 2019
2 parents c43f900 + abe21ab commit 01e5073
Show file tree
Hide file tree
Showing 7 changed files with 37 additions and 28 deletions.
20 changes: 10 additions & 10 deletions 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",
Expand Down Expand Up @@ -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",
Expand All @@ -70,6 +70,6 @@
"proxyquire": "^2.1.0",
"mockery": "^2.1.0",
"sinon": "^7.3.2",
"xo": "^0.24.0"
"xo": "^0.25.3"
}
}
9 changes: 7 additions & 2 deletions source/index.js
Expand Up @@ -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,
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -210,6 +213,8 @@ module.exports = async (input = 'patch', options) => {
}
]);
}
} else {
publishStatus = 'SUCCESS';
}

tasks.add({
Expand All @@ -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;
};
3 changes: 2 additions & 1 deletion source/npm/handle-npm-error.js
Expand Up @@ -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…)')}`;

Expand Down
10 changes: 6 additions & 4 deletions source/npm/util.js
Expand Up @@ -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';
Expand Down
12 changes: 6 additions & 6 deletions source/pretty-version-diff.js
Expand Up @@ -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));
}
}

Expand Down
5 changes: 3 additions & 2 deletions source/ui.js
Expand Up @@ -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);
Expand Down Expand Up @@ -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);

Expand All @@ -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`.';
Expand Down
6 changes: 3 additions & 3 deletions source/util.js
Expand Up @@ -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) => {
Expand Down

0 comments on commit 01e5073

Please sign in to comment.