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,12 +100,14 @@ 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;
promises.push(new Promise((resolve, reject) => {
workers({ workers({
configPath, configPath,
resourcePath, resourcePath,
@@ -116,8 +124,7 @@ const webpackBuildTask = {
buildingInProgress = false; buildingInProgress = false;
currentBuildingModule = ''; currentBuildingModule = '';
currentBuildingScript = ''; currentBuildingScript = '';
error = "worker farm webpack errored out"; reject("worker farm webpack errored out");
console.error("worker farm webpack errored out");
return; return;
} }
@@ -128,19 +135,27 @@ const webpackBuildTask = {
buildingInProgress = false; buildingInProgress = false;
currentBuildingModule = ''; currentBuildingModule = '';
currentBuildingScript = ''; currentBuildingScript = '';
error = "webpack got an error"; reject("webpack got an error");
console.error("webpack got an error");
return; return;
} }
console.log(`${resourceName}: built ${configName}`); console.log(`${resourceName}: built ${configName}`);
resolve();
});
}));
}
}
try {
await Promise.all(promises);
} catch (e) {
error = e.toString();
}
buildingInProgress = false; buildingInProgress = false;
currentBuildingModule = ''; currentBuildingModule = '';
currentBuildingScript = '';
});
}
}
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 = '';