perf(webui): lazily load module descriptors
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
import { spawnSync } from "node:child_process";
|
||||
import { mkdirSync, readFileSync, writeFileSync } from "node:fs";
|
||||
|
||||
const packageByModule = {
|
||||
access: "@govoplan/access-webui",
|
||||
@@ -19,7 +20,9 @@ const packageByModule = {
|
||||
ops: "@govoplan/ops-webui",
|
||||
policy: "@govoplan/policy-webui",
|
||||
postbox: "@govoplan/postbox-webui",
|
||||
risk_compliance: "@govoplan/risk-compliance-webui",
|
||||
scheduling: "@govoplan/scheduling-webui",
|
||||
search: "@govoplan/search-webui",
|
||||
views: "@govoplan/views-webui",
|
||||
workflow: "@govoplan/workflow-webui"
|
||||
};
|
||||
@@ -52,19 +55,23 @@ const cases = [
|
||||
{ name: "campaign-with-mail-no-files", modules: ["campaigns", "mail"] },
|
||||
{ name: "scheduling-only", modules: ["scheduling"] },
|
||||
{ name: "scheduling-with-calendar", modules: ["scheduling", "calendar"] },
|
||||
{ name: "search-only", modules: ["search"] },
|
||||
{ name: "risk-compliance-only", modules: ["risk_compliance"] },
|
||||
{ name: "docs-and-ops", modules: ["access", "docs", "ops"] },
|
||||
{ name: "full-product", modules: ["access", "admin", "addresses", "policy", "audit", "dashboard", "datasources", "dataflow", "workflow", "views", "organizations", "idm", "campaigns", "files", "mail", "notifications", "docs", "ops", "calendar", "scheduling", "postbox"] }
|
||||
{ name: "full-product", modules: ["access", "admin", "addresses", "policy", "audit", "dashboard", "datasources", "dataflow", "workflow", "views", "organizations", "idm", "campaigns", "files", "mail", "notifications", "docs", "ops", "calendar", "scheduling", "postbox", "risk_compliance", "search"] }
|
||||
];
|
||||
|
||||
const npmExec = process.env.npm_execpath;
|
||||
const command = npmExec ? process.execPath : (process.platform === "win32" ? "npm.cmd" : "npm");
|
||||
const baseArgs = npmExec ? [npmExec, "run", "build"] : ["run", "build"];
|
||||
const collectedMetrics = [];
|
||||
|
||||
for (const testCase of cases) {
|
||||
const packages = testCase.modules.map((moduleId) => packageByModule[moduleId]).join(",");
|
||||
const env = {
|
||||
...process.env,
|
||||
GOVOPLAN_WEBUI_MODULE_PACKAGES: packages
|
||||
GOVOPLAN_WEBUI_MODULE_PACKAGES: packages,
|
||||
GOVOPLAN_WEBUI_BUILD_NAME: testCase.name
|
||||
};
|
||||
delete env.npm_config_tmp;
|
||||
delete env.NPM_CONFIG_TMP;
|
||||
@@ -81,4 +88,15 @@ for (const testCase of cases) {
|
||||
if (result.status !== 0) {
|
||||
process.exit(result.status ?? 1);
|
||||
}
|
||||
collectedMetrics.push(
|
||||
JSON.parse(readFileSync(new URL("../dist/bundle-metrics.json", import.meta.url), "utf8"))
|
||||
);
|
||||
}
|
||||
|
||||
const metricsDirectory = new URL("../dist/", import.meta.url);
|
||||
mkdirSync(metricsDirectory, { recursive: true });
|
||||
writeFileSync(
|
||||
new URL("module-permutation-bundle-metrics.json", metricsDirectory),
|
||||
`${JSON.stringify({ schemaVersion: 1, builds: collectedMetrics }, null, 2)}\n`
|
||||
);
|
||||
console.log(`\nRecorded bundle metrics for ${collectedMetrics.length} module permutations.`);
|
||||
|
||||
Reference in New Issue
Block a user