build.js: support outputting esbuild metadata file

ESbuild supports outputting a metadata file which can be used to view
bundle size information using https://esbuild.github.io/analyze/

Closes: #18267
This commit is contained in:
Jelle van der Waa 2024-06-26 10:55:36 +02:00 committed by Martin Pitt
parent 81bc3677e9
commit 9f4cda65d5

View file

@ -50,9 +50,13 @@ const qunitOptions = {
const parser = (await import('argparse')).default.ArgumentParser();
parser.add_argument('-r', '--rsync', { help: "rsync bundles to ssh target after build", metavar: "HOST" });
parser.add_argument('-w', '--watch', { action: 'store_true', help: "Enable watch mode" });
parser.add_argument('-m', '--metafile', { help: "Enable bund size information file", metavar: "FILE" });
parser.add_argument('onlydir', { nargs: '?', help: "The pkg/<DIRECTORY> to build (eg. base1, shell, ...)", metavar: "DIRECTORY" });
const args = parser.parse_args();
if (args.metafile)
pkgOptions.metafile = true;
if (args.onlydir?.includes('/'))
parser.error("Directory must not contain '/'");
@ -201,7 +205,9 @@ async function build() {
});
try {
await Promise.all([pkgContext.rebuild(), qunitContext.rebuild()]);
const results = await Promise.all([pkgContext.rebuild(), qunitContext.rebuild()]);
if (args.metafile)
fs.writeFileSync(args.metafile, JSON.stringify(results[0].metafile));
} catch (e) {
if (!args.watch)
process.exit(1);