1
0
mirror of https://github.com/citizenfx/cfx-server-data.git synced 2025-02-02 01:52:57 +08:00

fix(yarn): per-server cache folder, mutex, cleaner phrasing for reinit, cleaner async call

This commit is contained in:
blattersturm 2020-09-09 10:34:19 +02:00
parent dd38bd0192
commit 25fd26e2e4

View File

@ -4,6 +4,8 @@ const child_process = require('child_process');
let buildingInProgress = false; let buildingInProgress = false;
let currentBuildingModule = ''; let currentBuildingModule = '';
const initCwd = process.cwd();
const yarnBuildTask = { const yarnBuildTask = {
shouldBuild(resourceName) { shouldBuild(resourceName) {
try { try {
@ -32,20 +34,19 @@ const yarnBuildTask = {
}, },
build(resourceName, cb) { build(resourceName, cb) {
let buildYarn = async () => { (async () => {
while (buildingInProgress) { while (buildingInProgress && currentBuildingModule !== resourceName) {
console.log(`yarn is busy by another process: we are waiting to compile ${resourceName}`); console.log(`yarn is currently busy: we are waiting to compile ${resourceName}`);
await sleep(3000); await sleep(3000);
} }
buildingInProgress = true; buildingInProgress = true;
currentBuildingModule = resourceName; currentBuildingModule = resourceName;
const process = child_process.fork( const process = child_process.fork(
require.resolve('./yarn_cli.js'), 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)) cwd: path.resolve(GetResourcePath(resourceName))
}); });
process.on('exit', (code, signal) => { process.on('exit', (code, signal) => {
setImmediate(() => { setImmediate(() => {
if (code != 0 || signal) { if (code != 0 || signal) {
@ -69,8 +70,7 @@ const yarnBuildTask = {
cb(true); cb(true);
}); });
}); });
}; })();
buildYarn().then();
} }
}; };