From c75329b47da3842eac20e16f0f5eba7a6f5b6c33 Mon Sep 17 00:00:00 2001 From: PalmDevs Date: Tue, 8 Jul 2025 22:14:22 +0700 Subject: [PATCH] feat(scripts/build): improve perf by changing compiler flags --- scripts/build.ts | 24 +++++++++++++++++++----- 1 file changed, 19 insertions(+), 5 deletions(-) diff --git a/scripts/build.ts b/scripts/build.ts index fb5725f..afd7b66 100644 --- a/scripts/build.ts +++ b/scripts/build.ts @@ -87,11 +87,16 @@ export default async function build(dev = Dev, log = true) { hermesCPlugin({ flags: [ dev ? '-Og' : '-O', - '-eager', + dev ? '-g3' : '-g1', + '-reuse-prop-cache', + '-optimized-eval', + '-strict', + '-fno-static-builtins', '-finline', '-fno-static-require', - '-Wno-direct-eval', - '-Wno-undefined-variable', + '-Wdirect-eval', + '-Wundefined-variable', + '-funsafe-intrinsics', ], before(ver) { if (log) { @@ -142,7 +147,7 @@ function swcPlugin() { name: 'swc', transform: { filter: { - id: /\.[cm]?[jt]sx?$/, + moduleType: ['js', 'jsx', 'ts', 'tsx'], }, handler(code) { return transform(code, { @@ -229,12 +234,21 @@ async function hermesCPlugin({ const cmdlist = [binPath, '-emit-binary', ...(flags ?? [])] - const cmd = Bun.spawnSync(cmdlist, { + const cmd = Bun.spawnSync<'pipe', 'pipe'>(cmdlist, { // @ts-expect-error: Types are incorrect, but this works stdin: new Blob([file.code]), stdout: 'pipe', }) + if (cmd.exitCode) { + if (cmd.stderr.length) + throw new Error( + `Got error from hermesc: ${cmd.stderr.toString()}`, + ) + else + throw new Error(`hermesc exited with code: ${cmd.exitCode}`) + } + const buf = cmd.stdout if (!buf.length) throw new Error(