Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 0 additions & 4 deletions lib/create-options.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,6 @@ function createOptions(cwd, context) {
options.env['TEMP'] = context.npmConfigTmp;
options.env['TMP'] = context.npmConfigTmp;
options.env['TMPDIR'] = context.npmConfigTmp;
// Explicitly tell yarn to ignore the "engines" field in `package.json`.
// If dependencies of tested modules have set it and CITGM is testing an
// unreleased version of Node.js, this prevents `yarn install` from failing.
options.env['YARN_IGNORE_ENGINES'] = 'true';

if (context.options.nodedir) {
const nodedir = path.resolve(process.cwd(), context.options.nodedir);
Expand Down
1 change: 1 addition & 0 deletions lib/lookup.json
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,7 @@
"maintainers": "mafintosh"
},
"ember-cli": {
"envVar": { "YARN_IGNORE_ENGINES": "true" },
"prefix": "v",
"flaky": ["win32", "rhel", "sles"],
"master": true,
Expand Down
42 changes: 42 additions & 0 deletions lib/package-manager/install.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,48 @@

const path = require('path');

const semverLt = require('semver/functions/lt');
const stripAnsi = require('strip-ansi');

const createOptions = require('../create-options');
const spawn = require('../spawn');
const { spawnSync } = require('child_process');
const timeout = require('../timeout');

const envSeparator = process.platform === 'win32' ? ';' : ':';

function getVersion(packageManager, context) {
const options = createOptions(
path.join(context.path, context.module.name),
context
);
const packageManagerBin =
packageManager === 'npm' ? context.npmPath : context.yarnPath;

const binDirectory = path.dirname(packageManagerBin);
options.env.PATH = `${binDirectory}${envSeparator}${process.env.PATH}`;
options.encoding = 'utf8';

const proc = spawnSync(packageManagerBin, ['--version'], options);
if (proc.status !== 0) {
context.emit(
'data',
'warn',
`${context.module.name} ${packageManager}:`,
`Unable to determine ${packageManager} version:\n${proc.stdout}` +
`\n${proc.stderr}`
);
return undefined;
}
context.emit(
'data',
'verbose',
`${context.module.name} ${packageManager}:`,
`${packageManager} version ${proc.stdout}`
);
return proc.stdout;
}

function install(packageManager, context) {
return new Promise((resolve, reject) => {
const options = createOptions(
Expand All @@ -34,6 +68,14 @@ function install(packageManager, context) {
if (packageManager === 'npm') {
args.push('--no-audit');
args.push('--no-fund');
} else if (packageManager === 'yarn') {
// Tell yarn versions earlier than v2 to ignore the "engines" field in
// `package.json` (if present) to allow installation with unreleased
// versions of Node.js.
const version = getVersion(packageManager, context);
if (version && semverLt(version, '2.0.0', { includePrerelease: true })) {
options.env['YARN_IGNORE_ENGINES'] = 'true';
}
}

if (context.module.install) {
Expand Down
1 change: 0 additions & 1 deletion test/test-create-options.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ test('create-options:', (t) => {
env['TEMP'] = 'npm_config_tmp';
env['TMP'] = 'npm_config_tmp';
env['TMPDIR'] = 'npm_config_tmp';
env['YARN_IGNORE_ENGINES'] = 'true';
// Set dynamically to support Windows.
env['npm_config_nodedir'] = path.resolve(process.cwd(), nodePath);

Expand Down