Skip to content

Commit

Permalink
Require Node.js 8
Browse files Browse the repository at this point in the history
  • Loading branch information
sindresorhus committed Dec 15, 2018
1 parent eafd3a0 commit 223ba6b
Show file tree
Hide file tree
Showing 9 changed files with 216 additions and 198 deletions.
3 changes: 1 addition & 2 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
* text=auto
*.js text eol=lf
* text=auto eol=lf
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
language: node_js
node_js:
- '10'
- '8'
- '6'
49 changes: 20 additions & 29 deletions cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,34 +68,25 @@ process.on('SIGINT', () => {
process.exit(1);
});

Promise
.resolve()
.then(() => {
const pkg = util.readPkg();
return Promise.all([npmName(pkg.name), pkg]);
})
.then(([available, pkg]) => {
if (cli.input.length > 0) {
return Object.assign({}, cli.flags, {
confirm: true,
version: cli.input[0]
});
}
(async () => {
const pkg = util.readPkg();
const isAvailable = await npmName(pkg.name);

return ui(Object.assign({}, cli.flags, {exists: !available}), pkg);
})
.then(options => {
if (!options.confirm) {
process.exit(0);
}
const options = cli.input.length > 0 ?
{
...cli.flags,
confirm: true,
version: cli.input[0]
} :
await ui({...cli.flags, exists: !isAvailable}, pkg);

if (!options.confirm) {
process.exit(0);
}

return options;
})
.then(options => np(options.version, options))
.then(pkg => {
console.log(`\n ${pkg.name} ${pkg.version} published 🎉`);
})
.catch(error => {
console.error(`\n${logSymbols.error} ${error.message}`);
process.exit(1);
});
const newPkg = await np(options.version, options);
console.log(`\n ${newPkg.name} ${newPkg.version} published 🎉`);
})().catch(error => {
console.error(`\n${logSymbols.error} ${error.message}`);
process.exit(1);
});
67 changes: 34 additions & 33 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,39 +24,38 @@ const exec = (cmd, args) => {
).pipe(filter(Boolean));
};

module.exports = (input, opts) => {
input = input || 'patch';

opts = Object.assign({
module.exports = async (input = 'patch', options) => {
options = {
cleanup: true,
publish: true
}, opts);
publish: true,
...options
};

if (!hasYarn() && opts.yarn) {
if (!hasYarn() && options.yarn) {
throw new Error('Could not use Yarn without yarn.lock file');
}

// TODO: remove sometime far in the future
if (opts.skipCleanup) {
opts.cleanup = false;
// TODO: Remove sometime far in the future
if (options.skipCleanup) {
options.cleanup = false;
}

const runTests = !opts.yolo;
const runCleanup = opts.cleanup && !opts.yolo;
const runPublish = opts.publish;
const runTests = !options.yolo;
const runCleanup = options.cleanup && !options.yolo;
const runPublish = options.publish;
const pkg = util.readPkg();
const pkgManager = opts.yarn === true ? 'yarn' : 'npm';
const pkgManagerName = opts.yarn === true ? 'Yarn' : 'npm';
const pkgManager = options.yarn === true ? 'yarn' : 'npm';
const pkgManagerName = options.yarn === true ? 'Yarn' : 'npm';

const tasks = new Listr([
{
title: 'Prerequisite check',
enabled: () => runPublish,
task: () => prerequisiteTasks(input, pkg, opts)
task: () => prerequisiteTasks(input, pkg, options)
},
{
title: 'Git',
task: () => gitTasks(opts)
task: () => gitTasks(options)
}
], {
showSubtasks: false
Expand All @@ -70,19 +69,20 @@ module.exports = (input, opts) => {
},
{
title: 'Installing dependencies using Yarn',
enabled: () => opts.yarn === true,
enabled: () => options.yarn === true,
task: () => exec('yarn', ['install', '--frozen-lockfile', '--production=false']).pipe(
catchError(err => {
if (err.stderr.startsWith('error Your lockfile needs to be updated')) {
catchError(error => {
if (error.stderr.startsWith('error Your lockfile needs to be updated')) {
throwError(new Error('yarn.lock file is outdated. Run yarn, commit the updated lockfile and try again.'));
}
throwError(err);

throwError(error);
})
)
},
{
title: 'Installing dependencies using npm',
enabled: () => opts.yarn === false,
enabled: () => options.yarn === false,
task: () => exec('npm', ['install', '--no-package-lock', '--no-production'])
}
]);
Expand All @@ -92,19 +92,19 @@ module.exports = (input, opts) => {
tasks.add([
{
title: 'Running tests using npm',
enabled: () => opts.yarn === false,
enabled: () => options.yarn === false,
task: () => exec('npm', ['test'])
},
{
title: 'Running tests using Yarn',
enabled: () => opts.yarn === true,
enabled: () => options.yarn === true,
task: () => exec('yarn', ['test']).pipe(
catchError(err => {
if (err.message.includes('Command "test" not found')) {
catchError(error => {
if (error.message.includes('Command "test" not found')) {
return [];
}

throwError(err);
throwError(error);
})
)
}
Expand All @@ -114,12 +114,12 @@ module.exports = (input, opts) => {
tasks.add([
{
title: 'Bumping version using Yarn',
enabled: () => opts.yarn === true,
enabled: () => options.yarn === true,
task: () => exec('yarn', ['version', '--new-version', input])
},
{
title: 'Bumping version using npm',
enabled: () => opts.yarn === false,
enabled: () => options.yarn === false,
task: () => exec('npm', ['version', input])
}
]);
Expand All @@ -133,7 +133,7 @@ module.exports = (input, opts) => {
return `Private package: not publishing to ${pkgManagerName}.`;
}
},
task: (ctx, task) => publish(pkgManager, task, opts, input)
task: (context, task) => publish(pkgManager, task, options, input)
}
]);
}
Expand All @@ -143,7 +143,8 @@ module.exports = (input, opts) => {
task: () => exec('git', ['push', '--follow-tags'])
});

return tasks.run()
.then(() => readPkgUp())
.then(result => result.pkg);
await tasks.run();

const {pkg: newPkg} = await readPkgUp();
return newPkg;
};
21 changes: 12 additions & 9 deletions lib/git.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,35 +2,38 @@
const execa = require('execa');
const Listr = require('listr');

module.exports = opts => {
module.exports = options => {
const tasks = [
{
title: 'Check current branch',
task: () => execa.stdout('git', ['symbolic-ref', '--short', 'HEAD']).then(branch => {
task: async () => {
const {stdout: branch} = await execa('git', ['symbolic-ref', '--short', 'HEAD']);
if (branch !== 'master') {
throw new Error('Not on `master` branch. Use --any-branch to publish anyway.');
}
})
}
},
{
title: 'Check local working tree',
task: () => execa.stdout('git', ['status', '--porcelain']).then(status => {
task: async () => {
const {stdout: status} = await execa('git', ['status', '--porcelain']);
if (status !== '') {
throw new Error('Unclean working tree. Commit or stash changes first.');
}
})
}
},
{
title: 'Check remote history',
task: () => execa.stdout('git', ['rev-list', '--count', '--left-only', '@{u}...HEAD']).then(result => {
if (result !== '0') {
task: async () => {
const {stdout} = await execa('git', ['rev-list', '--count', '--left-only', '@{u}...HEAD']);
if (stdout !== '0') {
throw new Error('Remote history differs. Please pull changes.');
}
})
}
}
];

if (opts.anyBranch) {
if (options.anyBranch) {
tasks.shift();
}

Expand Down

0 comments on commit 223ba6b

Please sign in to comment.