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

update webpack and yarn builders

Updating the WebPack and Yarn builders so that they do not launch simultaneously. Compiling some modules simultaneously causes conflicts/crashes
This commit is contained in:
GiroudMathias 2019-11-20 16:00:19 +01:00
parent 85419a6145
commit 3bac230553
2 changed files with 191 additions and 156 deletions

View File

@ -2,7 +2,9 @@ const fs = require('fs');
const path = require('path');
const workerFarm = require('worker-farm');
const async = require('async');
let buildingInProgress = false;
let currentBuildingModule = '';
let currentBuildingScript = '';
const webpackBuildTask = {
shouldBuild(resourceName) {
const numMetaData = GetNumResourceMetadata(resourceName, 'webpack_config');
@ -66,21 +68,23 @@ const webpackBuildTask = {
},
build(resourceName, cb) {
let buildWebpack = async () => {
let error = null;
const configs = [];
const numMetaData = GetNumResourceMetadata(resourceName, 'webpack_config');
for (let i = 0; i < numMetaData; i++) {
configs.push(GetResourceMetadata(resourceName, 'webpack_config', i));
}
async.forEachOf(configs, (configName, i, acb) => {
for (const configName of configs) {
const configPath = GetResourcePath(resourceName) + '/' + configName;
const cachePath = `cache/${resourceName}/${configName.replace(/\//g, '_')}.json`;
try {
fs.mkdirSync(path.dirname(cachePath));
} catch {}
} catch {
}
const config = require(configPath);
@ -89,6 +93,13 @@ const webpackBuildTask = {
if (config) {
const resourcePath = path.resolve(GetResourcePath(resourceName));
while (buildingInProgress) {
console.log(`webpack is busy by another process: we are waiting to compile ${resourceName} (${configName})`);
await sleep(3000);
}
buildingInProgress = true;
currentBuildingModule = resourceName;
currentBuildingScript = configName;
workers({
configPath,
resourcePath,
@ -102,7 +113,11 @@ const webpackBuildTask = {
console.error(err.details);
}
acb("worker farm webpack errored out");
buildingInProgress = false;
currentBuildingModule = '';
currentBuildingScript = '';
error = "worker farm webpack errored out";
console.error("worker farm webpack errored out");
return;
}
@ -110,30 +125,32 @@ const webpackBuildTask = {
for (const error of outp.errors) {
console.log(error);
}
acb("webpack got an error");
buildingInProgress = false;
currentBuildingModule = '';
currentBuildingScript = '';
error = "webpack got an error";
console.error("webpack got an error");
return;
}
console.log(`${resourceName}: built ${configName}`);
acb();
});
return;
}
acb("no configuration");
}, (err) => {
setImmediate(() => {
if (err) {
cb(false, err);
return;
}
cb(true);
});
buildingInProgress = false;
currentBuildingModule = '';
currentBuildingScript = '';
});
}
}
if (error) {
cb(false, error);
} else cb(true);
};
buildWebpack().then();
}
};
function sleep(ms) {
return new Promise(resolve => setTimeout(resolve, ms));
}
RegisterResourceBuildTaskFactory('z_webpack', () => webpackBuildTask);

View File

@ -1,6 +1,8 @@
const path = require('path');
const fs = require('fs');
const child_process = require('child_process');
let buildingInProgress = false;
let currentBuildingModule = '';
const yarnBuildTask = {
shouldBuild(resourceName) {
@ -30,6 +32,13 @@ const yarnBuildTask = {
},
build(resourceName, cb) {
let buildYarn = async () => {
while (buildingInProgress) {
console.log(`yarn is busy by another process: we are waiting to compile ${resourceName}`);
await sleep(3000);
}
buildingInProgress = true;
currentBuildingModule = resourceName;
const process = child_process.fork(
require.resolve('./yarn_cli.js'),
['install'],
@ -40,6 +49,8 @@ const yarnBuildTask = {
process.on('exit', (code, signal) => {
setImmediate(() => {
if (code != 0 || signal) {
buildingInProgress = false;
currentBuildingModule = '';
cb(false, 'yarn failed!');
return;
}
@ -53,10 +64,17 @@ const yarnBuildTask = {
}
buildingInProgress = false;
currentBuildingModule = '';
cb(true);
});
});
};
buildYarn().then();
}
}
};
function sleep(ms) {
return new Promise(resolve => setTimeout(resolve, ms));
}
RegisterResourceBuildTaskFactory('yarn', () => yarnBuildTask);