mirror of
https://github.com/renovatebot/renovate.git
synced 2025-01-12 06:56:24 +00:00
63dae3d901
Remove the direct call to `tmp`'s manual cleanup function as `tmp` adds a listener on process exit to call cleanup on all created directories (that weren't created with the `keep` option set to `true`). This is considered a fix because under some conditions the cleanup will fail on Windows, and because the cleanup is called manually in the middle of a renovate cycle, any sporadic failure will fail the entire renovate process. Instead, defer the temporary directory cleanup until after renovate has completed, where a failure won't de-rail the entire cycle. (I have not been able to track down why `tmp` fails sometimes on Windows with my various project setups.)
29 lines
897 B
JavaScript
29 lines
897 B
JavaScript
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);
|
|
}
|
|
cp.spawnSync('yarn', ['install'], { cwd: tmpDir.name, shell: true });
|
|
yarnLock = fs.readFileSync(path.join(tmpDir.name, 'yarn.lock'));
|
|
} catch (error) {
|
|
throw error;
|
|
}
|
|
return yarnLock;
|
|
}
|