mirror of
https://github.com/citizenfx/cfx-server-data.git
synced 2025-01-21 15:42:56 +08:00
fix(yarn): per-server cache folder, mutex, cleaner phrasing for reinit, cleaner async call
This commit is contained in:
parent
dd38bd0192
commit
25fd26e2e4
@ -4,6 +4,8 @@ const child_process = require('child_process');
|
||||
let buildingInProgress = false;
|
||||
let currentBuildingModule = '';
|
||||
|
||||
const initCwd = process.cwd();
|
||||
|
||||
const yarnBuildTask = {
|
||||
shouldBuild(resourceName) {
|
||||
try {
|
||||
@ -32,20 +34,19 @@ const yarnBuildTask = {
|
||||
},
|
||||
|
||||
build(resourceName, cb) {
|
||||
let buildYarn = async () => {
|
||||
while (buildingInProgress) {
|
||||
console.log(`yarn is busy by another process: we are waiting to compile ${resourceName}`);
|
||||
(async () => {
|
||||
while (buildingInProgress && currentBuildingModule !== resourceName) {
|
||||
console.log(`yarn is currently busy: we are waiting to compile ${resourceName}`);
|
||||
await sleep(3000);
|
||||
}
|
||||
buildingInProgress = true;
|
||||
currentBuildingModule = resourceName;
|
||||
const process = child_process.fork(
|
||||
require.resolve('./yarn_cli.js'),
|
||||
['install', '--ignore-scripts'],
|
||||
['install', '--ignore-scripts', '--cache-folder', path.join(initCwd, 'cache', 'yarn-cache'), '--mutex', 'file:' + path.join(initCwd, 'cache', 'yarn-mutex')],
|
||||
{
|
||||
cwd: path.resolve(GetResourcePath(resourceName))
|
||||
});
|
||||
|
||||
process.on('exit', (code, signal) => {
|
||||
setImmediate(() => {
|
||||
if (code != 0 || signal) {
|
||||
@ -69,8 +70,7 @@ const yarnBuildTask = {
|
||||
cb(true);
|
||||
});
|
||||
});
|
||||
};
|
||||
buildYarn().then();
|
||||
})();
|
||||
}
|
||||
};
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user