Skip to content

Commit

Permalink
Require Node.js 6
Browse files Browse the repository at this point in the history
  • Loading branch information
sindresorhus committed Apr 30, 2018
1 parent 6a86102 commit 305bdc4
Show file tree
Hide file tree
Showing 7 changed files with 67 additions and 69 deletions.
1 change: 0 additions & 1 deletion .travis.yml
Expand Up @@ -2,4 +2,3 @@ language: node_js
node_js:
- '8'
- '6'
- '4'
2 changes: 1 addition & 1 deletion lib/prerequisite.js
Expand Up @@ -32,7 +32,7 @@ module.exports = (input, pkg, opts) => {
.then(collaborators => {
const json = JSON.parse(collaborators);
const permissions = json[username];
if (!permissions || permissions.indexOf('write') === -1) {
if (!permissions || !permissions.includes('write')) {
throw new Error('You do not have write permissions required to publish this package.');
}
})
Expand Down
15 changes: 7 additions & 8 deletions lib/publish.js
Expand Up @@ -4,29 +4,28 @@ const listrInput = require('listr-input');
const Observable = require('any-observable');
const chalk = require('chalk');

const npmPublish = opts => {
const npmPublish = options => {
const args = ['publish'];

if (opts.tag) {
args.push('--tag', opts.tag);
if (options.tag) {
args.push('--tag', options.tag);
}

if (opts.otp) {
args.push('--otp', opts.otp);
if (options.otp) {
args.push('--otp', options.otp);
}

return execa('npm', args);
};

const handleError = (task, err, tag, message) => {
if (err.stderr.indexOf('one-time pass') !== -1) {
const title = task.title;
if (err.stderr.includes('one-time pass')) {
const {title} = task;
task.title = `${title} ${chalk.yellow('(waiting for input…)')}`;

return listrInput(message || 'Enter OTP:', {
done: otp => {
task.title = title;

return npmPublish({tag, otp});
}
}).catch(err => handleError(task, err, tag, 'OTP was incorrect, try again:'));
Expand Down
2 changes: 1 addition & 1 deletion lib/ui.js
Expand Up @@ -24,6 +24,7 @@ function prettyVersionDiff(oldVersion, inc) {
output.push(chalk.reset.dim(newVersion[i]));
}
}

return output.join(chalk.reset.dim('.'));
}

Expand All @@ -38,7 +39,6 @@ function printCommitLog(repositoryUrl) {
const history = result.split('\n')
.map(commit => {
const commitParts = commit.match(/^(.+)\s([a-f\d]{7})$/);

const commitMessage = util.linkifyIssues(repositoryUrl, commitParts[1]);
const commitId = util.linkifyCommit(repositoryUrl, commitParts[2]);

Expand Down
2 changes: 1 addition & 1 deletion lib/util.js
Expand Up @@ -4,7 +4,7 @@ const issueRegex = require('issue-regex');
const terminalLink = require('terminal-link');

exports.readPkg = () => {
const pkg = readPkgUp.sync().pkg;
const {pkg} = readPkgUp.sync();

if (!pkg) {
throw new Error(`No package.json found. Make sure you're in the correct project.`);
Expand Down
6 changes: 3 additions & 3 deletions lib/version.js
Expand Up @@ -6,16 +6,16 @@ exports.PRERELEASE_VERSIONS = ['prepatch', 'preminor', 'premajor', 'prerelease']

const isValidVersion = input => Boolean(semver.valid(input));

exports.isValidVersionInput = input => exports.SEMVER_INCREMENTS.indexOf(input) !== -1 || isValidVersion(input);
exports.isValidVersionInput = input => exports.SEMVER_INCREMENTS.includes(input) || isValidVersion(input);

exports.isPrereleaseVersion = version => exports.PRERELEASE_VERSIONS.indexOf(version) !== -1 || Boolean(semver.prerelease(version));
exports.isPrereleaseVersion = version => exports.PRERELEASE_VERSIONS.includes(version) || Boolean(semver.prerelease(version));

exports.getNewVersion = (oldVersion, input) => {
if (!exports.isValidVersionInput(input)) {
throw new Error(`Version should be either ${exports.SEMVER_INCREMENTS.join(', ')} or a valid semver version.`);
}

return exports.SEMVER_INCREMENTS.indexOf(input) === -1 ? input : semver.inc(oldVersion, input);
return exports.SEMVER_INCREMENTS.includes(input) ? semver.inc(oldVersion, input) : input;
};

exports.isVersionGreater = (oldVersion, newVersion) => {
Expand Down
108 changes: 54 additions & 54 deletions package.json
@@ -1,56 +1,56 @@
{
"name": "np",
"version": "2.20.1",
"description": "A better `npm publish`",
"license": "MIT",
"repository": "sindresorhus/np",
"bin": "cli.js",
"engines": {
"node": ">=4"
},
"scripts": {
"test": "xo && FORCE_HYPERLINK=1 ava"
},
"files": [
"index.js",
"cli.js",
"lib"
],
"keywords": [
"cli-app",
"cli",
"npm",
"publish",
"git",
"push",
"version",
"bump",
"commit"
],
"dependencies": {
"any-observable": "^0.2.0",
"chalk": "^2.3.0",
"del": "^3.0.0",
"execa": "^0.8.0",
"github-url-from-git": "^1.5.0",
"has-yarn": "^1.0.0",
"inquirer": "^3.0.6",
"issue-regex": "^1.0.0",
"listr": "^0.12.0",
"listr-input": "^0.1.1",
"log-symbols": "^2.1.0",
"meow": "^4.0.0",
"p-timeout": "^2.0.1",
"read-pkg-up": "^3.0.0",
"rxjs": "5.4.3",
"semver": "^5.2.0",
"split": "^1.0.0",
"stream-to-observable": "^0.2.0",
"terminal-link": "^1.1.0",
"update-notifier": "^2.1.0"
},
"devDependencies": {
"ava": "*",
"xo": "*"
}
"name": "np",
"version": "2.20.1",
"description": "A better `npm publish`",
"license": "MIT",
"repository": "sindresorhus/np",
"bin": "cli.js",
"engines": {
"node": ">=6"
},
"scripts": {
"test": "xo && FORCE_HYPERLINK=1 ava"
},
"files": [
"index.js",
"cli.js",
"lib"
],
"keywords": [
"cli-app",
"cli",
"npm",
"publish",
"git",
"push",
"version",
"bump",
"commit"
],
"dependencies": {
"any-observable": "^0.2.0",
"chalk": "^2.3.0",
"del": "^3.0.0",
"execa": "^0.10.0",
"github-url-from-git": "^1.5.0",
"has-yarn": "^1.0.0",
"inquirer": "^3.0.6",
"issue-regex": "^1.0.0",
"listr": "^0.12.0",
"listr-input": "^0.1.1",
"log-symbols": "^2.1.0",
"meow": "^5.0.0",
"p-timeout": "^2.0.1",
"read-pkg-up": "^3.0.0",
"rxjs": "5.4.3",
"semver": "^5.2.0",
"split": "^1.0.0",
"stream-to-observable": "^0.2.0",
"terminal-link": "^1.1.0",
"update-notifier": "^2.1.0"
},
"devDependencies": {
"ava": "*",
"xo": "*"
}
}

0 comments on commit 305bdc4

Please sign in to comment.