Skip to content

A fast 2D and 3D game engine — TypeScript SDK, C++/WebAssembly core, visual editor. Ship one project to web, desktop, WeChat MiniGames, playable ads, and native Android / iOS.

fix(export): rematerialize mini-game wasm/ so stale side modules can't ship

yhhcb1c4d04352d
diff --git a/desktop/electron/exportMiniGame.ts b/desktop/electron/exportMiniGame.ts
index 168754ffa..45c57ba66 100644
--- a/desktop/electron/exportMiniGame.ts
+++ b/desktop/electron/exportMiniGame.ts
@@ -378,8 +378,18 @@ export async function exportMiniGame(profile: MiniGameExportProfile, opts: {
// 6. The engine runtime + exactly the side modules the scene needs. WeChat's
// main package has a 4MB budget — unneeded side modules must not ride along.
+ // Rematerialize wasm/ from scratch: it holds EXACTLY this export's runtime
+ // set and nothing else. A prior export into the same outDir may have staged
+ // a module this project no longer needs (e.g. basis.js when KTX2 was on),
+ // and this run — copying only the current set — would leave that stale .js
+ // behind. The mini-game packer compiles EVERY .js in the package, so a stale
+ // glue built by an older pipeline (raw es2020 `?.`/`??`, not down-leveled)
+ // fails real-device compile ("invalid file: wasm/basis.js … Unexpected token .").
+ // Scoped to wasm/ (exporter-owned); the outDir root also hosts devtools'
+ // project.private.config.json, so we don't wipe the whole tree.
progress({ phase: 'Copying runtime' });
const wasmOut = path.join(absOut, 'wasm');
+ await rm(wasmOut, { recursive: true, force: true });
await mkdir(wasmOut, { recursive: true });
const runtimeFiles = [
engineGlueFile,
diff --git a/desktop/tests/export-wechat.test.ts b/desktop/tests/export-wechat.test.ts
index 63af7f3e0..f50b56c9a 100644
--- a/desktop/tests/export-wechat.test.ts
+++ b/desktop/tests/export-wechat.test.ts
@@ -279,6 +279,33 @@ describe('exportGame (wechat)', () => {
expect(res.errors.some((e) => e.includes('basis-wechat'))).toBe(true);
}, 60_000);
+ it('re-exporting into a populated dir rematerializes wasm/, dropping a stale side module', async () => {
+ // A prior export shipped the Basis transcoder (KTX2 was on then), including
+ // a glue file an older pipeline emitted with un-down-leveled es2020 syntax —
+ // the mini-game packer compiles EVERY .js in the package, so a leftover
+ // `wasm/basis.js` with `?.` fails real-device compile. This project needs no
+ // basis (plain texture scene); the re-export must wipe wasm/ and repopulate
+ // it with exactly the engine glue, so the stale module cannot ride along.
+ const outStale = path.join(root, 'dist-wechat-stale');
+ mkdirSync(path.join(outStale, 'wasm'), { recursive: true });
+ writeFileSync(path.join(outStale, 'wasm', 'basis.js'), 'var s = globalThis.document?.currentScript?.src;');
+ writeFileSync(path.join(outStale, 'wasm', 'basis.wasm'), 'stalebytes');
+ const res = await exportGame({
+ root,
+ entryScene: 'scenes/main.esscene',
+ gameHostEntry: 'unused-for-wechat',
+ scriptsEntry: 'src/main.ts',
+ sdkDistDir: path.join(root, '_sdk'),
+ wasmDir: path.join(root, '_wxwasm'),
+ outDir: outStale,
+ platform: 'wechat',
+ });
+ expect(res.ok).toBe(true);
+ expect(existsSync(path.join(outStale, 'wasm', 'esengine.js'))).toBe(true);
+ expect(existsSync(path.join(outStale, 'wasm', 'basis.js'))).toBe(false);
+ expect(existsSync(path.join(outStale, 'wasm', 'basis.wasm'))).toBe(false);
+ }, 60_000);
+
it('content-addressed export carries the logical path as the asset address', async () => {
const outCa = path.join(root, 'dist-wechat-ca');
const res = await exportGame({