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

builders: fix webpack and improve yarn

This commit is contained in:
blattersturm 2020-11-01 12:48:04 +01:00
parent 99dac40452
commit 65fc598a5f
4 changed files with 2381 additions and 46 deletions

View File

@ -1,2 +1,2 @@
yarn.lock .yarn.installed
node_modules/ node_modules/

View File

@ -4,7 +4,11 @@ const workerFarm = require('worker-farm');
const async = require('async'); const async = require('async');
let buildingInProgress = false; let buildingInProgress = false;
let currentBuildingModule = ''; let currentBuildingModule = '';
let currentBuildingScript = '';
// some modules will not like the custom stack trace logic
const ops = Error.prepareStackTrace;
Error.prepareStackTrace = undefined;
const webpackBuildTask = { const webpackBuildTask = {
shouldBuild(resourceName) { shouldBuild(resourceName) {
const numMetaData = GetNumResourceMetadata(resourceName, 'webpack_config'); const numMetaData = GetNumResourceMetadata(resourceName, 'webpack_config');
@ -71,11 +75,13 @@ const webpackBuildTask = {
let buildWebpack = async () => { let buildWebpack = async () => {
let error = null; let error = null;
const configs = []; const configs = [];
const promises = [];
const numMetaData = GetNumResourceMetadata(resourceName, 'webpack_config'); const numMetaData = GetNumResourceMetadata(resourceName, 'webpack_config');
for (let i = 0; i < numMetaData; i++) { for (let i = 0; i < numMetaData; i++) {
configs.push(GetResourceMetadata(resourceName, 'webpack_config', i)); configs.push(GetResourceMetadata(resourceName, 'webpack_config', i));
} }
for (const configName of configs) { for (const configName of configs) {
const configPath = GetResourcePath(resourceName) + '/' + configName; const configPath = GetResourcePath(resourceName) + '/' + configName;
@ -94,53 +100,62 @@ const webpackBuildTask = {
const resourcePath = path.resolve(GetResourcePath(resourceName)); const resourcePath = path.resolve(GetResourcePath(resourceName));
while (buildingInProgress) { while (buildingInProgress) {
console.log(`webpack is busy by another process: we are waiting to compile ${resourceName} (${configName})`); console.log(`webpack is busy: we are waiting to compile ${resourceName} (${configName})`);
await sleep(3000); await sleep(3000);
} }
buildingInProgress = true; buildingInProgress = true;
currentBuildingModule = resourceName; currentBuildingModule = resourceName;
currentBuildingScript = configName;
workers({
configPath,
resourcePath,
cachePath
}, (err, outp) => {
workerFarm.end(workers);
if (err) { promises.push(new Promise((resolve, reject) => {
console.error(err.stack || err); workers({
if (err.details) { configPath,
console.error(err.details); resourcePath,
cachePath
}, (err, outp) => {
workerFarm.end(workers);
if (err) {
console.error(err.stack || err);
if (err.details) {
console.error(err.details);
}
buildingInProgress = false;
currentBuildingModule = '';
currentBuildingScript = '';
reject("worker farm webpack errored out");
return;
} }
buildingInProgress = false; if (outp.errors) {
currentBuildingModule = ''; for (const error of outp.errors) {
currentBuildingScript = ''; console.log(error);
error = "worker farm webpack errored out"; }
console.error("worker farm webpack errored out"); buildingInProgress = false;
return; currentBuildingModule = '';
} currentBuildingScript = '';
reject("webpack got an error");
if (outp.errors) { return;
for (const error of outp.errors) {
console.log(error);
} }
buildingInProgress = false;
currentBuildingModule = '';
currentBuildingScript = '';
error = "webpack got an error";
console.error("webpack got an error");
return;
}
console.log(`${resourceName}: built ${configName}`); console.log(`${resourceName}: built ${configName}`);
buildingInProgress = false; resolve();
currentBuildingModule = ''; });
currentBuildingScript = ''; }));
});
} }
} }
try {
await Promise.all(promises);
} catch (e) {
error = e.toString();
}
buildingInProgress = false;
currentBuildingModule = '';
if (error) { if (error) {
cb(false, error); cb(false, error);
} else cb(true); } else cb(true);

File diff suppressed because it is too large Load Diff

View File

@ -12,7 +12,7 @@ const yarnBuildTask = {
const resourcePath = GetResourcePath(resourceName); const resourcePath = GetResourcePath(resourceName);
const packageJson = path.resolve(resourcePath, 'package.json'); const packageJson = path.resolve(resourcePath, 'package.json');
const yarnLock = path.resolve(resourcePath, 'yarn.lock'); const yarnLock = path.resolve(resourcePath, '.yarn.installed');
const packageStat = fs.statSync(packageJson); const packageStat = fs.statSync(packageJson);
@ -23,7 +23,7 @@ const yarnBuildTask = {
return true; return true;
} }
} catch (e) { } catch (e) {
// no yarn.lock, but package.json - install time! // no yarn.installed, but package.json - install time!
return true; return true;
} }
} catch (e) { } catch (e) {
@ -57,13 +57,8 @@ const yarnBuildTask = {
} }
const resourcePath = GetResourcePath(resourceName); const resourcePath = GetResourcePath(resourceName);
const yarnLock = path.resolve(resourcePath, 'yarn.lock'); const yarnLock = path.resolve(resourcePath, '.yarn.installed');
fs.writeFileSync(yarnLock, '');
try {
fs.utimesSync(yarnLock, new Date(), new Date());
} catch (e) {
}
buildingInProgress = false; buildingInProgress = false;
currentBuildingModule = ''; currentBuildingModule = '';