renovate/lib/helpers/yarn.js

33 lines
1 KiB
JavaScript
Raw Normal View History

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);
}
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));
yarnLock = fs.readFileSync(path.join(tmpDir.name, 'yarn.lock'));
} catch (error) {
throw error;
}
return yarnLock;
}