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.
TypeScript 2d-game-engine3d3d-game-engineandroidcppecsgame-editorgame-enginegamedeviostypescriptwebassemblywebglwebgpuwechat-minigame
fix(desktop): wechat export fails fast without the -t wechat runtime; ships only needed side modules
yhha2ee32524745
diff --git a/build-tools/cli.js b/build-tools/cli.jsindex 693f18c30..10a8316f6 100644--- a/build-tools/cli.js+++ b/build-tools/cli.js@@ -83,7 +83,6 @@ programif (options.sync) {await syncToDesktop();- await zipExamples(config.paths.root);}if (manifest) {diff --git a/desktop/electron/exportGame.ts b/desktop/electron/exportGame.tsindex 900748b4d..ad1c147d3 100644--- a/desktop/electron/exportGame.ts+++ b/desktop/electron/exportGame.ts@@ -322,12 +322,14 @@ export async function exportGame(opts: {return { ok: false, platform, outDir: absOut, included: cook.included.length, warnings, errors };}- // 4. SDK (import-map target) + wasm runtime.+ // 4. SDK (import-map target) + wasm runtime. The import map and the game+ // host reference both unconditionally — a missing tree is not a degraded+ // export but a package that cannot boot, so it fails the export.progress({ phase: 'Copying SDK + runtime' });if (existsSync(opts.sdkDistDir)) await cp(opts.sdkDistDir, path.join(payloadDir, 'sdk'), { recursive: true });- else warnings.push(`sdk dist not found: ${opts.sdkDistDir}`);+ else errors.push(`sdk dist not found: ${opts.sdkDistDir}`);if (existsSync(opts.wasmDir)) await cp(opts.wasmDir, path.join(payloadDir, 'wasm'), { recursive: true });- else warnings.push(`wasm runtime dir not found: ${opts.wasmDir}`);+ else errors.push(`wasm runtime dir not found: ${opts.wasmDir}`);// 5. Host page + entry-scene config.progress({ phase: 'Writing host page' });diff --git a/desktop/electron/exportWeChat.ts b/desktop/electron/exportWeChat.tsindex f170587bd..b279ea7ae 100644--- a/desktop/electron/exportWeChat.ts+++ b/desktop/electron/exportWeChat.ts@@ -233,6 +233,22 @@ export async function exportWeChat(opts: {const progress = opts.onProgress ?? (() => {});const warnings: string[] = [];const errors: string[] = [];++ // 0. The generated entry unconditionally requires the engine glue, so a+ // missing wechat runtime cannot produce a runnable package — fail before+ // cooking. Require by its ACTUAL name in the wasm dir (the -t wechat+ // build emits esengine.wxgame.js; a web-aligned build, esengine.js).+ const engineGlueFile = ['esengine.wxgame.js', 'esengine.js']+ .find((f) => existsSync(path.join(opts.wasmDir, f)));+ if (!engineGlueFile) {+ errors.push(+ `wechat engine runtime not found in ${opts.wasmDir} — ` ++ 'build it with `node build-tools/cli.js build -t wechat` ' ++ '(add -t physics-wechat / -t spine-wechat if the project uses physics or Spine)',+ );+ return { ok: false, platform: 'wechat', outDir: absOut, included: 0, warnings, errors };+ }+await mkdir(absOut, { recursive: true });// 1. Cook reachable assets (paths preserved) + the flat manifest.@@ -304,18 +320,26 @@ export async function exportWeChat(opts: {errors.push(...(e.errors?.map((x) => x.text) ?? [String(e.message ?? err)]));}- // 5. Entry + config. Require the engine glue by its ACTUAL name in the wasm dir- // (the -t wechat build emits esengine.wxgame.js; a web-aligned build, esengine.js).- const engineGlueFile = ['esengine.js', 'esengine.wxgame.js']- .find((f) => existsSync(path.join(opts.wasmDir, f))) ?? 'esengine.js';+ // 5. Entry + config.await writeFile(path.join(absOut, 'game.js'), gameEntryJs(sideModules, engineGlueFile));await writeFile(path.join(absOut, 'game.json'), gameJson(opts.orientation ?? 'portrait', subPackagesOf(cookEntries)));await writeFile(path.join(absOut, 'project.config.json'), projectConfigJson(title, opts.appid ?? ''));- // 6. The -t wechat engine runtime (WXWebAssembly glue + binary + side modules).+ // 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.progress({ phase: 'Copying runtime' });- if (existsSync(opts.wasmDir)) await cp(opts.wasmDir, path.join(absOut, 'wasm'), { recursive: true });- else warnings.push(`wechat wasm runtime dir not found: ${opts.wasmDir}`);+ const wasmOut = path.join(absOut, 'wasm');+ await mkdir(wasmOut, { recursive: true });+ const runtimeFiles = [+ engineGlueFile,+ engineGlueFile.replace(/\.js$/, '.wasm'),+ ...sideModules.flatMap((m) => [`${m.file}.js`, `${m.file}.wasm`]),+ ];+ for (const f of runtimeFiles) {+ const src = path.join(opts.wasmDir, f);+ if (existsSync(src)) await cp(src, path.join(wasmOut, f));+ else errors.push(`wechat runtime file missing: ${f} (in ${opts.wasmDir}) — rebuild with \`node build-tools/cli.js build -t wechat\``);+ }return { ok: errors.length === 0, platform: 'wechat', outDir: absOut, included: cook.included.length, warnings, errors };}diff --git a/desktop/tests/export-game.test.ts b/desktop/tests/export-game.test.tsindex 8a75ba349..c85b8827b 100644--- a/desktop/tests/export-game.test.ts+++ b/desktop/tests/export-game.test.ts@@ -130,4 +130,20 @@ describe('exportGame', () => {expect(existsSync(path.join(out2, 'scenes/main.esscene'))).toBe(true);expect(existsSync(path.join(out2, 'game.js'))).toBe(true);}, 60_000);++ it('fails when the wasm runtime is missing — the build cannot boot without it', async () => {+ const out3 = path.join(root, 'dist-game-nowasm');+ const res = await exportGame({+ root,+ entryScene: 'scenes/main.esscene',+ gameHostEntry: GAME_HOST,+ scriptsEntry: 'src/main.ts',+ sdkDistDir: path.join(root, '_sdk'),+ wasmDir: path.join(root, '_no-such-wasm'),+ outDir: out3,+ title: 'My Game',+ });+ expect(res.ok).toBe(false);+ expect(res.errors.some((e) => e.includes('wasm runtime dir not found'))).toBe(true);+ }, 60_000);});diff --git a/desktop/tests/export-wechat.test.ts b/desktop/tests/export-wechat.test.tsindex c5be0dfe5..8a7381eae 100644--- a/desktop/tests/export-wechat.test.ts+++ b/desktop/tests/export-wechat.test.ts@@ -109,6 +109,50 @@ describe('exportGame (wechat)', () => {expect(existsSync(path.join(out, 'subpackages', 'level2', 'extra.png'))).toBe(true);}, 60_000);+ it('requires the glue by its actual -t wechat name; unneeded side modules stay out (4MB budget)', async () => {+ const wxDir = path.join(root, '_wxwasm-wxgame');+ mkdirSync(wxDir, { recursive: true });+ writeFileSync(path.join(wxDir, 'esengine.wxgame.js'), 'module.exports = () => Promise.resolve({});');+ writeFileSync(path.join(wxDir, 'esengine.wxgame.wasm'), 'wasmbytes');+ // Present in the runtime dir but not needed by the scene — must not ship.+ writeFileSync(path.join(wxDir, 'physics.js'), 'module.exports = () => {};');+ writeFileSync(path.join(wxDir, 'physics.wasm'), 'wasmbytes');+ const outWx = path.join(root, 'dist-wechat-wxgame');+ const res = await exportGame({+ root,+ entryScene: 'scenes/main.esscene',+ gameHostEntry: 'unused-for-wechat',+ scriptsEntry: 'src/main.ts',+ sdkDistDir: path.join(root, '_sdk'),+ wasmDir: wxDir,+ outDir: outWx,+ platform: 'wechat',+ });+ expect(res.ok).toBe(true);+ expect(readFileSync(path.join(outWx, 'game.js'), 'utf8')).toContain("require('./wasm/esengine.wxgame.js')");+ expect(existsSync(path.join(outWx, 'wasm', 'esengine.wxgame.wasm'))).toBe(true);+ expect(existsSync(path.join(outWx, 'wasm', 'physics.js'))).toBe(false);+ expect(existsSync(path.join(outWx, 'wasm', 'physics.wasm'))).toBe(false);+ }, 60_000);++ it('fails fast when the -t wechat engine runtime is missing', async () => {+ const outMissing = path.join(root, 'dist-wechat-missing');+ 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, '_no-such-wasm'),+ outDir: outMissing,+ platform: 'wechat',+ });+ expect(res.ok).toBe(false);+ expect(res.errors[0]).toContain('build -t wechat');+ // Failed before cooking — no half-assembled package left behind.+ expect(existsSync(outMissing)).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({