2017-08-22 04:28:46 +00:00
|
|
|
const fs = require('fs-extra');
|
2017-11-24 06:50:49 +00:00
|
|
|
const upath = require('upath');
|
2017-10-08 04:30:01 +00:00
|
|
|
const { getInstalledPath } = require('get-installed-path');
|
2017-09-20 20:56:57 +00:00
|
|
|
const { exec } = require('child-process-promise');
|
2017-02-14 07:08:40 +00:00
|
|
|
|
|
|
|
module.exports = {
|
|
|
|
generateLockFile,
|
|
|
|
};
|
|
|
|
|
2017-11-08 05:44:03 +00:00
|
|
|
async function generateLockFile(tmpDir) {
|
2017-09-20 05:52:44 +00:00
|
|
|
logger.debug(`Spawning yarn install to create ${tmpDir}/yarn.lock`);
|
2017-08-26 14:10:18 +00:00
|
|
|
let lockFile = null;
|
2017-09-20 20:56:57 +00:00
|
|
|
let stdout;
|
|
|
|
let stderr;
|
2017-02-14 07:08:40 +00:00
|
|
|
try {
|
2017-09-15 07:10:50 +00:00
|
|
|
const startTime = process.hrtime();
|
2017-09-20 20:56:57 +00:00
|
|
|
let cmd;
|
2017-09-20 05:52:44 +00:00
|
|
|
try {
|
|
|
|
// See if renovate is installed locally
|
2017-11-24 06:50:49 +00:00
|
|
|
const installedPath = upath.join(
|
2017-09-20 20:56:57 +00:00
|
|
|
await getInstalledPath('yarn', {
|
|
|
|
local: true,
|
|
|
|
}),
|
|
|
|
'bin/yarn.js'
|
2017-09-20 05:52:44 +00:00
|
|
|
);
|
2017-09-20 20:56:57 +00:00
|
|
|
cmd = `node ${installedPath}`;
|
2017-09-20 05:52:44 +00:00
|
|
|
} catch (localerr) {
|
|
|
|
logger.debug('No locally installed yarn found');
|
|
|
|
// Look inside globally installed renovate
|
|
|
|
try {
|
|
|
|
const renovateLocation = await getInstalledPath('renovate');
|
2017-11-24 06:50:49 +00:00
|
|
|
const installedPath = upath.join(
|
2017-09-20 20:56:57 +00:00
|
|
|
await getInstalledPath('yarn', {
|
|
|
|
local: true,
|
|
|
|
cwd: renovateLocation,
|
|
|
|
}),
|
|
|
|
'bin/yarn.js'
|
2017-09-20 05:52:44 +00:00
|
|
|
);
|
2017-09-20 20:56:57 +00:00
|
|
|
cmd = `node ${installedPath}`;
|
2017-09-20 05:52:44 +00:00
|
|
|
} catch (nestederr) {
|
|
|
|
logger.debug('Could not find globally nested yarn');
|
|
|
|
// look for global yarn
|
|
|
|
try {
|
2017-11-24 06:50:49 +00:00
|
|
|
const installedPath = upath.join(
|
2017-09-20 20:56:57 +00:00
|
|
|
await getInstalledPath('yarn'),
|
|
|
|
'bin/yarn.js'
|
2017-09-20 05:52:44 +00:00
|
|
|
);
|
2017-09-20 20:56:57 +00:00
|
|
|
cmd = `node ${installedPath}`;
|
2017-09-20 05:52:44 +00:00
|
|
|
} catch (globalerr) {
|
|
|
|
logger.warn('Could not find globally installed yarn');
|
|
|
|
cmd = 'yarn';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2017-09-20 20:56:57 +00:00
|
|
|
logger.debug(`Using yarn: ${cmd}`);
|
|
|
|
cmd += ' install';
|
|
|
|
cmd += ' --ignore-scripts';
|
2017-09-23 06:05:43 +00:00
|
|
|
cmd += ' --ignore-engines';
|
2017-09-20 20:56:57 +00:00
|
|
|
// TODO: Switch to native util.promisify once using only node 8
|
|
|
|
({ stdout, stderr } = await exec(cmd, {
|
2017-08-22 04:28:46 +00:00
|
|
|
cwd: tmpDir,
|
2017-04-21 08:12:41 +00:00
|
|
|
shell: true,
|
2017-09-15 09:48:12 +00:00
|
|
|
env: { NODE_ENV: 'dev', PATH: process.env.PATH },
|
2017-09-20 20:56:57 +00:00
|
|
|
}));
|
|
|
|
logger.debug(`yarn stdout:\n${stdout}`);
|
|
|
|
logger.debug(`yarn stderr:\n${stderr}`);
|
2017-09-15 07:10:50 +00:00
|
|
|
const duration = process.hrtime(startTime);
|
2017-09-24 14:53:47 +00:00
|
|
|
const seconds = Math.round(duration[0] + duration[1] / 1e9);
|
2017-11-24 06:50:49 +00:00
|
|
|
lockFile = await fs.readFile(upath.join(tmpDir, 'yarn.lock'), 'utf8');
|
2017-09-15 07:10:50 +00:00
|
|
|
logger.info(
|
2017-09-24 14:53:47 +00:00
|
|
|
{ seconds, type: 'yarn.lock', stdout, stderr },
|
2017-09-15 07:10:50 +00:00
|
|
|
'Generated lockfile'
|
|
|
|
);
|
2017-08-05 03:53:24 +00:00
|
|
|
} catch (err) /* istanbul ignore next */ {
|
2017-10-19 12:05:10 +00:00
|
|
|
logger.info(
|
2017-08-05 03:53:24 +00:00
|
|
|
{
|
|
|
|
err,
|
|
|
|
},
|
2017-08-26 14:10:18 +00:00
|
|
|
'yarn install error'
|
2017-08-05 03:53:24 +00:00
|
|
|
);
|
2017-10-19 12:05:10 +00:00
|
|
|
return { error: true, stderr: err.stderr };
|
2017-02-14 07:08:40 +00:00
|
|
|
}
|
2017-10-19 12:05:10 +00:00
|
|
|
return { lockFile };
|
2017-04-20 10:15:46 +00:00
|
|
|
}
|