Skip to content

Commit

Permalink
Add system requirements to the engines field in package (#406)
Browse files Browse the repository at this point in the history
  • Loading branch information
aladdin-add authored and sindresorhus committed May 29, 2019
1 parent 0842b07 commit 68d0584
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 13 deletions.
4 changes: 3 additions & 1 deletion package.json
Expand Up @@ -7,7 +7,9 @@
"bin": "source/cli.js",
"engines": {
"node": ">=8",
"npm": ">=6.8.0"
"npm": ">=6.8.0",
"git": ">=2.11.0",
"yarn": ">=1.7.0"
},
"scripts": {
"test": "xo && FORCE_HYPERLINK=1 ava"
Expand Down
7 changes: 3 additions & 4 deletions source/git-util.js
Expand Up @@ -3,6 +3,8 @@ const execa = require('execa');
const escapeStringRegexp = require('escape-string-regexp');
const version = require('./version');

const {versionSatisfiesRequirement} = version;

exports.latestTag = () => execa.stdout('git', ['describe', '--abbrev=0', '--tags']);

const firstCommit = () => execa.stdout('git', ['rev-list', '--max-parents=0', 'HEAD']);
Expand Down Expand Up @@ -128,9 +130,6 @@ const gitVersion = async () => {

exports.verifyRecentGitVersion = async () => {
const installedVersion = await gitVersion();
const minVersion = '2.11.0';

if (!version(minVersion).isGreaterThanOrEqualTo(installedVersion)) {
throw new Error('Please upgrade to git@2.11.0 or newer.');
}
versionSatisfiesRequirement('git', installedVersion);
};
6 changes: 2 additions & 4 deletions source/npm/util.js
Expand Up @@ -5,6 +5,7 @@ const ow = require('ow');
const npmName = require('npm-name');
const version = require('../version');

const {versionSatisfiesRequirement} = version;
exports.checkConnection = () => pTimeout(
(async () => {
try {
Expand Down Expand Up @@ -85,8 +86,5 @@ 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');
}
versionSatisfiesRequirement('npm', npmVersion);
};
7 changes: 3 additions & 4 deletions source/prerequisite-tasks.js
Expand Up @@ -6,6 +6,8 @@ const git = require('./git-util');
const npm = require('./npm/util');
const {getTagVersionPrefix} = require('./util');

const {versionSatisfiesRequirement} = version;

module.exports = (input, pkg, options) => {
const isExternalRegistry = npm.isExternalRegistry(pkg);
let newVersion = null;
Expand All @@ -25,10 +27,7 @@ module.exports = (input, pkg, options) => {
enabled: () => options.yarn === true,
task: async () => {
const yarnVersion = await execa.stdout('yarn', ['--version']);

if (version(yarnVersion).satisfies('<1.7.0')) {
throw new Error('Please upgrade to yarn@1.7.0 or newer');
}
versionSatisfiesRequirement('yarn', yarnVersion);
}
},
{
Expand Down
7 changes: 7 additions & 0 deletions source/version.js
Expand Up @@ -57,3 +57,10 @@ module.exports.validate = version => {
throw new Error('Version should be a valid semver version.');
}
};

module.exports.versionSatisfiesRequirement = (dependency, version) => {
const depRange = require('../package.json').engines[dependency];
if (!module.exports(version).satisfies(depRange)) {
throw new Error(`Please upgrade to ${dependency}${depRange}`);
}
};

0 comments on commit 68d0584

Please sign in to comment.