Skip to content

Commit

Permalink
Verify installed Yarn version is >=1.7.0 (#360)
Browse files Browse the repository at this point in the history
Fixes #248
  • Loading branch information
itaisteinherz authored and sindresorhus committed Mar 16, 2019
1 parent 70fd0c1 commit 537aa8e
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 6 deletions.
3 changes: 2 additions & 1 deletion package.json
Expand Up @@ -6,7 +6,8 @@
"repository": "sindresorhus/np",
"bin": "source/cli.js",
"engines": {
"node": ">=8"
"node": ">=8",
"npm": ">=6.8.0"
},
"scripts": {
"test": "xo && FORCE_HYPERLINK=1 ava"
Expand Down
2 changes: 1 addition & 1 deletion source/git-util.js
Expand Up @@ -120,6 +120,6 @@ exports.verifyRecentGitVersion = async () => {
const minVersion = '2.11.0';

if (!version(minVersion).isGreaterThanOrEqualTo(installedVersion)) {
throw new Error('Please upgrade git to version 2.11 or higher.');
throw new Error('Please upgrade to git@2.11.0 or newer.');
}
};
11 changes: 11 additions & 0 deletions source/npm-util.js
Expand Up @@ -3,6 +3,7 @@ const execa = require('execa');
const pTimeout = require('p-timeout');
const ow = require('ow');
const npmName = require('npm-name');
const version = require('./version');

exports.checkConnection = () => pTimeout(
(async () => {
Expand Down Expand Up @@ -79,3 +80,13 @@ exports.isPackageNameAvailable = async pkg => {
};

exports.isExternalRegistry = pkg => typeof pkg.publishConfig === 'object' && typeof pkg.publishConfig.registry === 'string';

exports.version = () => execa.stdout('npm', ['--version']);

exports.verifyRecentNpmVersion = async () => {
const npmVersion = await exports.version();

if (version(npmVersion).satisfies('<6.8.0')) {
throw new Error('Please upgrade to npm@6.8.0 or newer');
}
};
13 changes: 9 additions & 4 deletions source/prerequisite-tasks.js
Expand Up @@ -18,11 +18,16 @@ module.exports = (input, pkg, options) => {
},
{
title: 'Check npm version',
task: async () => npm.verifyRecentNpmVersion()
},
{
title: 'Check yarn version',
enabled: () => options.yarn === true,
task: async () => {
const versions = JSON.parse(await execa.stdout('npm', ['version', '--json']));
const yarnVersion = await execa.stdout('yarn', ['--version']);

if (version(versions.npm).satisfies('<6.8.0')) {
throw new Error('Please upgrade to npm@6.8.0 or newer');
if (version(yarnVersion).satisfies('<1.7.0')) {
throw new Error('Please upgrade to yarn@1.7.0 or newer');
}
}
},
Expand All @@ -47,7 +52,7 @@ module.exports = (input, pkg, options) => {
}
},
{
title: 'Verify git version is recent',
title: 'Check git version',
task: async () => git.verifyRecentGitVersion()
},
{
Expand Down

0 comments on commit 537aa8e

Please sign in to comment.