From e6c8d4f3f273dcca95b7fb4ac9c393846241cce1 Mon Sep 17 00:00:00 2001 From: Zaid Humaimidi Date: Mon, 18 Dec 2023 23:57:44 -0800 Subject: [PATCH] Build script improvements --- build/build.ts | 24 ++++++++---------------- npm-shrinkwrap.json | 1 + package.json | 1 + 3 files changed, 10 insertions(+), 16 deletions(-) diff --git a/build/build.ts b/build/build.ts index 3f16f22..b3dc1f7 100644 --- a/build/build.ts +++ b/build/build.ts @@ -13,7 +13,7 @@ const fsAsync = { copyFile: promisify(fs.copyFile), rename: promisify(fs.rename), chmod: promisify(fs.chmod), - stat: promisify(fs.stat), + lstat: promisify(fs.lstat), exists: promisify(fs.exists), rmdir: promisify(fs.rmdir), unlink: promisify(fs.unlink), @@ -36,8 +36,8 @@ async function rmDir(dirPath: string): Promise { for (const file of files) { const filePath = path.join(dirPath, file); - if ((await fsAsync.stat(filePath)).isFile()) await fsAsync.unlink(filePath); - else await rmDir(filePath); + if ((await fsAsync.lstat(filePath)).isDirectory()) await rmDir(filePath); + else await fsAsync.unlink(filePath); } await fsAsync.rmdir(dirPath); } @@ -116,18 +116,9 @@ const inlineDepsPlugin = { "mithril", "yaml", ]; - const sym = Symbol(); build.onResolve({ filter: /^[^.]/ }, async (args) => { - if (args.pluginData === sym) return undefined; if (deps.some((d) => args.path.startsWith(d))) return undefined; - const res = await build.resolve(args.path, { - pluginData: sym, - importer: args.importer, - namespace: args.namespace, - resolveDir: args.resolveDir, - kind: args.kind, - }); - return { path: res.path, sideEffects: false, external: true }; + return { sideEffects: false, external: true }; }); }, } as esbuild.Plugin; @@ -268,7 +259,7 @@ async function generateBackendJs(): Promise { const p = path.join(OUTPUT_DIR, "bin", bin); await fsAsync.rename(`${p}.js`, p); // Mark as executable - const mode = (await fsAsync.stat(p)).mode; + const mode = (await fsAsync.lstat(p)).mode; await fsAsync.chmod(p, mode | 73); } } @@ -287,18 +278,19 @@ async function generateFrontendJs(): Promise { entryPoints: ["ui/app.ts"], entryNames: "[dir]/[name]-[hash]", outdir: path.join(OUTPUT_DIR, "public"), - plugins: [packageDotJsonPlugin, inlineDepsPlugin, assetsPlugin], metafile: true, }); 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") { ASSETS.APP_JS = path.relative( path.join(OUTPUT_DIR, "public"), path.join(INPUT_DIR, k), ); - break; } } } diff --git a/npm-shrinkwrap.json b/npm-shrinkwrap.json index 5dddc14..83c844a 100644 --- a/npm-shrinkwrap.json +++ b/npm-shrinkwrap.json @@ -10,6 +10,7 @@ "license": "AGPL-3.0", "dependencies": { "@breejs/later": "^4.1.0", + "bson": "^4.7.2", "espresso-iisojs": "^1.0.7", "iconv-lite": "^0.6.3", "ipaddr.js": "^2.0.1", diff --git a/package.json b/package.json index 7a0f37a..24ac031 100644 --- a/package.json +++ b/package.json @@ -20,6 +20,7 @@ }, "dependencies": { "@breejs/later": "^4.1.0", + "bson": "^4.7.2", "espresso-iisojs": "^1.0.7", "iconv-lite": "^0.6.3", "ipaddr.js": "^2.0.1",