Skip to content

Commit 71d179a

Browse files
committed
Merge branch 'master' into issue_103
2 parents c43f900 + abe21ab commit 71d179a

File tree

8 files changed

+43
-37
lines changed

8 files changed

+43
-37
lines changed

package.json

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "np",
3-
"version": "5.1.0",
3+
"version": "5.2.1",
44
"description": "A better `npm publish`",
55
"license": "MIT",
66
"repository": "sindresorhus/np",
@@ -30,34 +30,34 @@
3030
],
3131
"dependencies": {
3232
"@samverschueren/stream-to-observable": "^0.3.0",
33-
"any-observable": "^0.4.0",
33+
"any-observable": "^0.5.0",
3434
"async-exit-hook": "^2.0.1",
35-
"chalk": "^2.3.0",
35+
"chalk": "^3.0.0",
3636
"cosmiconfig": "^5.2.1",
3737
"del": "^4.1.0",
3838
"escape-string-regexp": "^2.0.0",
39-
"execa": "^2.0.1",
39+
"execa": "^3.4.0",
4040
"github-url-from-git": "^1.5.0",
4141
"has-yarn": "^2.1.0",
4242
"hosted-git-info": "^3.0.0",
4343
"ignore-walk": "^3.0.2",
4444
"inquirer": "^7.0.0",
45-
"is-installed-globally": "^0.2.0",
45+
"is-installed-globally": "^0.3.1",
4646
"is-scoped": "^2.1.0",
4747
"issue-regex": "^2.0.0",
4848
"listr": "^0.14.3",
49-
"listr-input": "^0.1.3",
49+
"listr-input": "^0.2.0",
5050
"log-symbols": "^3.0.0",
5151
"meow": "^5.0.0",
5252
"minimatch": "^3.0.4",
5353
"npm-name": "^5.4.0",
5454
"onetime": "^5.1.0",
55-
"open": "^6.1.0",
56-
"ow": "^0.13.2",
55+
"open": "^7.0.0",
56+
"ow": "^0.15.0",
5757
"p-memoize": "^3.1.0",
5858
"p-timeout": "^3.1.0",
5959
"pkg-dir": "^4.1.0",
60-
"read-pkg-up": "^6.0.0",
60+
"read-pkg-up": "^7.0.0",
6161
"rxjs": "^6.3.3",
6262
"semver": "^6.1.2",
6363
"split": "^1.0.0",
@@ -70,6 +70,6 @@
7070
"proxyquire": "^2.1.0",
7171
"mockery": "^2.1.0",
7272
"sinon": "^7.3.2",
73-
"xo": "^0.24.0"
73+
"xo": "^0.25.3"
7474
}
7575
}

source/index.js

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ const exec = (cmd, args) => {
3535
).pipe(filter(Boolean));
3636
};
3737

38+
// eslint-disable-next-line default-param-last
3839
module.exports = async (input = 'patch', options) => {
3940
options = {
4041
cleanup: true,
@@ -87,11 +88,13 @@ module.exports = async (input = 'patch', options) => {
8788

8889
// The default parameter is a workaround for https://github.com/Tapppi/async-exit-hook/issues/9
8990
exitHook((callback = () => {}) => {
90-
if (publishStatus === 'FAILED' && runPublish) {
91+
if (publishStatus === 'FAILED') {
9192
(async () => {
9293
await rollback();
9394
callback();
9495
})();
96+
} else if (publishStatus === 'SUCCESS') {
97+
callback();
9598
} else {
9699
console.log('\nAborted!');
97100
callback();
@@ -210,6 +213,8 @@ module.exports = async (input = 'patch', options) => {
210213
}
211214
]);
212215
}
216+
} else {
217+
publishStatus = 'SUCCESS';
213218
}
214219

215220
tasks.add({
@@ -235,6 +240,6 @@ module.exports = async (input = 'patch', options) => {
235240

236241
await tasks.run();
237242

238-
const {package: newPkg} = await readPkgUp();
243+
const {packageJson: newPkg} = await readPkgUp();
239244
return newPkg;
240245
};

source/npm/handle-npm-error.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@ const handleNpmError = (error, task, message, executor) => {
99
message = undefined;
1010
}
1111

12-
if (error.stderr.includes('one-time pass') || error.message.includes('user TTY')) {
12+
// `one-time pass` is for npm and `Two factor authentication` is for Yarn.
13+
if (error.stderr.includes('one-time pass') || error.stdout.includes('Two factor authentication')) {
1314
const {title} = task;
1415
task.title = `${title} ${chalk.yellow('(waiting for input…)')}`;
1516

source/npm/util.js

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -79,12 +79,14 @@ exports.prereleaseTags = async packageName => {
7979
};
8080

8181
exports.isPackageNameAvailable = async pkg => {
82-
const isExternalRegistry = exports.isExternalRegistry(pkg);
83-
if (isExternalRegistry) {
84-
return true;
82+
const args = [pkg.name];
83+
if (exports.isExternalRegistry(pkg)) {
84+
args.push({
85+
registryUrl: pkg.publishConfig.registry
86+
});
8587
}
8688

87-
return npmName(pkg.name);
89+
return npmName(...args);
8890
};
8991

9092
exports.isExternalRegistry = pkg => typeof pkg.publishConfig === 'object' && typeof pkg.publishConfig.registry === 'string';
@@ -139,10 +141,7 @@ async function getFilesIgnoredByDotnpmignore(fileList) {
139141
ignoreFiles: ['.npmignore']
140142
});
141143
for (const file of fileList) {
142-
const found = whiteList.find(whiteListItem => {
143-
return whiteListItem === file;
144-
});
145-
if (found === undefined) {
144+
if (!whiteList.includes(file)) {
146145
result.push(file);
147146
}
148147
}

source/pretty-version-diff.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,16 +8,16 @@ module.exports = (oldVersion, inc) => {
88
let firstVersionChange = false;
99
const output = [];
1010

11-
for (let i = 0; i < newVersion.length; i++) {
12-
if ((newVersion[i] !== oldVersion[i] && !firstVersionChange)) {
13-
output.push(`${chalk.dim.cyan(newVersion[i])}`);
11+
for (const [i, element] of newVersion.entries()) {
12+
if ((element !== oldVersion[i] && !firstVersionChange)) {
13+
output.push(`${chalk.dim.cyan(element)}`);
1414
firstVersionChange = true;
15-
} else if (newVersion[i].indexOf('-') >= 1) {
15+
} else if (element.indexOf('-') >= 1) {
1616
let preVersion = [];
17-
preVersion = newVersion[i].split('-');
17+
preVersion = element.split('-');
1818
output.push(`${chalk.dim.cyan(`${preVersion[0]}-${preVersion[1]}`)}`);
1919
} else {
20-
output.push(chalk.reset.dim(newVersion[i]));
20+
output.push(chalk.reset.dim(element));
2121
}
2222
}
2323

source/ui.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ module.exports = async (options, pkg) => {
6969
const oldVersion = pkg.version;
7070
const extraBaseUrls = ['gitlab.com'];
7171
const repoUrl = pkg.repository && githubUrlFromGit(pkg.repository.url, {extraBaseUrls});
72+
const runPublish = options.publish && !pkg.private;
7273

7374
if (runPublish) {
7475
checkIgnoreStrategy(pkg);
@@ -125,7 +126,7 @@ module.exports = async (options, pkg) => {
125126
type: 'list',
126127
name: 'tag',
127128
message: 'How should this pre-release version be tagged in npm?',
128-
when: answers => !pkg.private && version.isPrereleaseOrIncrement(answers.version) && !options.tag,
129+
when: answers => options.publish && !pkg.private && version.isPrereleaseOrIncrement(answers.version) && !options.tag,
129130
choices: async () => {
130131
const existingPrereleaseTags = await prereleaseTags(pkg.name);
131132

@@ -143,7 +144,7 @@ module.exports = async (options, pkg) => {
143144
type: 'input',
144145
name: 'tag',
145146
message: 'Tag',
146-
when: answers => !pkg.private && version.isPrereleaseOrIncrement(answers.version) && !options.tag && !answers.tag,
147+
when: answers => options.publish && !pkg.private && version.isPrereleaseOrIncrement(answers.version) && !options.tag && !answers.tag,
147148
validate: input => {
148149
if (input.length === 0) {
149150
return 'Please specify a tag, for example, `next`.';

source/util.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,13 @@ const gitUtil = require('./git-util');
99
const npmUtil = require('./npm/util');
1010

1111
exports.readPkg = () => {
12-
const {package: pkg} = readPkgUp.sync();
12+
const {packageJson} = readPkgUp.sync();
1313

14-
if (!pkg) {
14+
if (!packageJson) {
1515
throw new Error('No package.json found. Make sure you\'re in the correct project.');
1616
}
1717

18-
return pkg;
18+
return packageJson;
1919
};
2020

2121
exports.linkifyIssues = (url, message) => {

test/npmignore.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,11 @@ test.before(() => {
3838
moduleUnderTest = require('../source/util');
3939
});
4040

41+
test.after(() => {
42+
mockery.deregisterAll();
43+
mockery.disable();
44+
});
45+
4146
test('ignored files using file-attribute in package.json with one item', async t => {
4247
t.deepEqual(await moduleUnderTest.getNewFilesIgnoredByNpm({files: ['pay_attention.txt']}),
4348
['source/ignore.txt']);
@@ -52,8 +57,3 @@ test('ignored files using .npmignore', async t => {
5257
t.deepEqual(await moduleUnderTest.getNewFilesIgnoredByNpm({name: 'without file-attribute'}),
5358
['source/ignore.txt']);
5459
});
55-
56-
test.after(() => {
57-
mockery.deregisterAll();
58-
mockery.disable();
59-
});

0 commit comments

Comments
 (0)