2017-02-14 07:08:40 +00:00
|
|
|
const logger = require('winston');
|
|
|
|
const fs = require('fs');
|
|
|
|
const cp = require('child_process');
|
|
|
|
const tmp = require('tmp');
|
|
|
|
const path = require('path');
|
|
|
|
|
|
|
|
module.exports = {
|
|
|
|
generateLockFile,
|
|
|
|
};
|
|
|
|
|
|
|
|
async function generateLockFile(newPackageJson, npmrcContent, yarnrcContent) {
|
|
|
|
logger.debug('Generating new yarn.lock file');
|
|
|
|
const tmpDir = tmp.dirSync({ unsafeCleanup: true });
|
|
|
|
let yarnLock;
|
|
|
|
try {
|
|
|
|
fs.writeFileSync(path.join(tmpDir.name, 'package.json'), newPackageJson);
|
|
|
|
if (npmrcContent) {
|
|
|
|
fs.writeFileSync(path.join(tmpDir.name, '.npmrc'), npmrcContent);
|
|
|
|
}
|
|
|
|
if (yarnrcContent) {
|
|
|
|
fs.writeFileSync(path.join(tmpDir.name, '.yarnrc'), yarnrcContent);
|
|
|
|
}
|
2017-04-13 20:39:46 +00:00
|
|
|
logger.debug('Spawning yarn install');
|
|
|
|
const result = cp.spawnSync('yarn', ['install'], { cwd: tmpDir.name, shell: true });
|
|
|
|
logger.debug(String(result.stdout));
|
|
|
|
logger.debug(String(result.stderr));
|
2017-02-14 07:08:40 +00:00
|
|
|
yarnLock = fs.readFileSync(path.join(tmpDir.name, 'yarn.lock'));
|
|
|
|
} catch (error) {
|
|
|
|
throw error;
|
|
|
|
}
|
|
|
|
return yarnLock;
|
|
|
|
}
|