Skip to content

Commit

Permalink
feat(run): Add engines check before executing scripts.
Browse files Browse the repository at this point in the history
  • Loading branch information
alloy committed Feb 10, 2019
1 parent 0e380a1 commit 4eb6391
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 1 deletion.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Expand Up @@ -20,6 +20,10 @@ Please add one entry in this file for each change in Yarn's behavior. Use the sa

[#6983](https://github.com/yarnpkg/yarn/pull/6983) - [**Micha Reiser**](https://github.com/MichaReiser)

- Run the engines check before executing `run` scripts.

[#7013](https://github.com/yarnpkg/yarn/issues/7013) - [**Eloy Dur谩n**](https://github.com/alloy)

## 1.14.0

- Improves PnP compatibility with Node 6
Expand Down
8 changes: 8 additions & 0 deletions src/cli/commands/run.js
Expand Up @@ -6,6 +6,7 @@ import {execCommand, makeEnv} from '../../util/execute-lifecycle-script.js';
import {dynamicRequire} from '../../util/dynamic-require.js';
import {MessageError} from '../../errors.js';
import {registries} from '../../resolvers/index.js';
import {checkOne as checkCompatibility} from '../../package-compatibility.js';
import * as fs from '../../util/fs.js';
import * as constants from '../../constants.js';

Expand Down Expand Up @@ -118,6 +119,13 @@ export async function run(config: Config, reporter: Reporter, flags: Object, arg
}

if (cmds.length) {
const ignoreEngines = !!(flags.ignoreEngines || config.getOption('ignore-engines'));
try {
await checkCompatibility({_reference: {}, ...pkg}, config, ignoreEngines);
} catch (err) {
throw err instanceof MessageError ? new MessageError(reporter.lang('cannotRunWithIncompatibleEnv')) : err;
}

// Disable wrapper in executed commands
process.env.YARN_WRAP_OUTPUT = 'false';
for (const [stage, cmd] of cmds) {
Expand Down
3 changes: 2 additions & 1 deletion src/reporters/lang/en.js
Expand Up @@ -229,11 +229,12 @@ const messages = {
nodeGypAutoInstallFailed:
'Failed to auto-install node-gyp. Please run "yarn global add node-gyp" manually. Error: $0',

foundIncompatible: 'Found incompatible module',
foundIncompatible: 'Found incompatible module.',
incompatibleEngine: 'The engine $0 is incompatible with this module. Expected version $1. Got $2',
incompatibleCPU: 'The CPU architecture $0 is incompatible with this module.',
incompatibleOS: 'The platform $0 is incompatible with this module.',
invalidEngine: 'The engine $0 appears to be invalid.',
cannotRunWithIncompatibleEnv: 'Commands cannot run with an incompatible environment.',

optionalCompatibilityExcluded:
'$0 is an optional dependency and failed compatibility check. Excluding it from installation.',
Expand Down

0 comments on commit 4eb6391

Please sign in to comment.