Build script improvements

This commit is contained in:
Zaid Humaimidi committed 2023-12-18 23:57:44 -08:00
1 parent 0dee9a5f00
commit e6c8d4f3f2
3 files changed
+10 -16

No files matched your search

+8 -16
View File
@@ -13,7 +13,7 @@ const fsAsync = {
copyFile: promisify(fs.copyFile), copyFile: promisify(fs.copyFile),
rename: promisify(fs.rename), rename: promisify(fs.rename),
chmod: promisify(fs.chmod), chmod: promisify(fs.chmod),
stat: promisify(fs.stat), lstat: promisify(fs.lstat),
exists: promisify(fs.exists), exists: promisify(fs.exists),
rmdir: promisify(fs.rmdir), rmdir: promisify(fs.rmdir),
unlink: promisify(fs.unlink), unlink: promisify(fs.unlink),
@@ -36,8 +36,8 @@ async function rmDir(dirPath: string): Promise<void> {
for (const file of files) { for (const file of files) {
const filePath = path.join(dirPath, file); const filePath = path.join(dirPath, file);
if ((await fsAsync.stat(filePath)).isFile()) await fsAsync.unlink(filePath); if ((await fsAsync.lstat(filePath)).isDirectory()) await rmDir(filePath);
else await rmDir(filePath); else await fsAsync.unlink(filePath);
} }
await fsAsync.rmdir(dirPath); await fsAsync.rmdir(dirPath);
} }
@@ -116,18 +116,9 @@ const inlineDepsPlugin = {
"mithril", "mithril",
"yaml", "yaml",
]; ];
const sym = Symbol();
build.onResolve({ filter: /^[^.]/ }, async (args) => { build.onResolve({ filter: /^[^.]/ }, async (args) => {
if (args.pluginData === sym) return undefined;
if (deps.some((d) => args.path.startsWith(d))) return undefined; if (deps.some((d) => args.path.startsWith(d))) return undefined;
const res = await build.resolve(args.path, { return { sideEffects: false, external: true };
pluginData: sym,
importer: args.importer,
namespace: args.namespace,
resolveDir: args.resolveDir,
kind: args.kind,
});
return { path: res.path, sideEffects: false, external: true };
}); });
}, },
} as esbuild.Plugin; } as esbuild.Plugin;
@@ -268,7 +259,7 @@ async function generateBackendJs(): Promise<void> {
const p = path.join(OUTPUT_DIR, "bin", bin); const p = path.join(OUTPUT_DIR, "bin", bin);
await fsAsync.rename(`${p}.js`, p); await fsAsync.rename(`${p}.js`, p);
// Mark as executable // Mark as executable
const mode = (await fsAsync.stat(p)).mode; const mode = (await fsAsync.lstat(p)).mode;
await fsAsync.chmod(p, mode | 73); await fsAsync.chmod(p, mode | 73);
} }
} }
@@ -287,18 +278,19 @@ async function generateFrontendJs(): Promise<void> {
entryPoints: ["ui/app.ts"], entryPoints: ["ui/app.ts"],
entryNames: "[dir]/[name]-[hash]", entryNames: "[dir]/[name]-[hash]",
outdir: path.join(OUTPUT_DIR, "public"), outdir: path.join(OUTPUT_DIR, "public"),
plugins: [packageDotJsonPlugin, inlineDepsPlugin, assetsPlugin], plugins: [packageDotJsonPlugin, inlineDepsPlugin, assetsPlugin],
metafile: true, metafile: true,
}); });
for (const [k, v] of Object.entries(res.metafile.outputs)) { for (const [k, v] of Object.entries(res.metafile.outputs)) {
for (const imp of v.imports)
if (imp.external) throw new Error(`External import found: ${imp.path}`);
if (v.entryPoint === "ui/app.ts") { if (v.entryPoint === "ui/app.ts") {
ASSETS.APP_JS = path.relative( ASSETS.APP_JS = path.relative(
path.join(OUTPUT_DIR, "public"), path.join(OUTPUT_DIR, "public"),
path.join(INPUT_DIR, k), path.join(INPUT_DIR, k),
); );
break;
} }
} }
} }
+1
View File
@@ -10,6 +10,7 @@
"license": "AGPL-3.0", "license": "AGPL-3.0",
"dependencies": { "dependencies": {
"@breejs/later": "^4.1.0", "@breejs/later": "^4.1.0",
"bson": "^4.7.2",
"espresso-iisojs": "^1.0.7", "espresso-iisojs": "^1.0.7",
"iconv-lite": "^0.6.3", "iconv-lite": "^0.6.3",
"ipaddr.js": "^2.0.1", "ipaddr.js": "^2.0.1",
+1
View File
@@ -20,6 +20,7 @@
}, },
"dependencies": { "dependencies": {
"@breejs/later": "^4.1.0", "@breejs/later": "^4.1.0",
"bson": "^4.7.2",
"espresso-iisojs": "^1.0.7", "espresso-iisojs": "^1.0.7",
"iconv-lite": "^0.6.3", "iconv-lite": "^0.6.3",
"ipaddr.js": "^2.0.1", "ipaddr.js": "^2.0.1",