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(export): remove obsolete web runtime files on rebuild
yhhd941fedbb33a
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex c7408fe1c..d54505fab 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -16,6 +16,8 @@ published separately; it ships inside the editor.### Fixed+- **Repeated Web exports drop obsolete runtime files.** Rebuilding into the same output replaces the shipped SDK and WASM trees, removing modules the project no longer needs and old SDK chunks. Turning off source maps removes maps from the previous build. Output-root configuration files are preserved, and a runtime output overlapping its input is rejected before removing that tree.+- **Editor export results report failed builds accurately.** The automation export door returns `exported: false` when the exporter fails, retaining errors such as missing optional runtime modules instead of marking a partial package as successfully exported. Preflight refusals remain distinguishable from attempted builds.- **Asset loaders release their App's resources on shutdown.** Asset plugin cleanup releases the default loader and any runtime replacement, clearing reference bookkeeping and making held textures evictable before the renderer is reused. Shared plugin instances clean up only the selected App; stopped device recovery cannot continue through a later loader. Unused loaders can release safely before a native resource manager exists.diff --git a/pipeline/src/export/exportGame.ts b/pipeline/src/export/exportGame.tsindex 57386abbc..25ad84fdb 100644--- a/pipeline/src/export/exportGame.ts+++ b/pipeline/src/export/exportGame.ts@@ -25,7 +25,7 @@ import { runtimeHostEntry } from '../bundle/runtimeHosts';import { writeFile, readFile, mkdir, cp, readdir, rm } from 'node:fs/promises';import { existsSync, readFileSync, statSync } from 'node:fs';import { spawnSync } from 'node:child_process';-import { isInsideRoot } from '../fs/pathSandbox';+import { containsPath, isInsideRoot, realPathOf } from '../fs/pathSandbox';import path from 'node:path';import { cookAssets, type CookManifest, type Inclusion } from '../assets/cookAssets';import { cookWorlds, streamedScenes } from '../world/cookWorld';@@ -235,6 +235,17 @@ async function dropSourceMapRefs(dir: string): Promise<void> {}}+/** Replace an exporter-owned runtime tree without removing its input files. */+async function resetRuntimeTree(output: string, name: 'sdk' | 'wasm', sources: readonly string[]): Promise<string> {+ const target = path.resolve(output, name);+ if (!isInsideRoot(output, target)+ || sources.some((source) => containsPath(realPathOf(target), realPathOf(source)))) {+ throw new Error(`runtime output ${target} overlaps an input or escapes the build output`);+ }+ await rm(target, { recursive: true, force: true, maxRetries: 10, retryDelay: 50 });+ return target;+}+/*** Warn about content this target cannot render. The editor authors every* subsystem the engine has, but a target may compile only some of them (the@@ -888,6 +899,11 @@ async function produceExport(opts: ExportGameOptions): Promise<ExportGameResult>// One answer for the whole package: the bundles esbuild writes here and the// SDK tree copied in beside them.const sourceMaps = opts.sourcemap ?? false;+ if (!sourceMaps) {+ for (const name of ['game.js.map', 'scripts.js.map', 'scripts.mjs.map']) {+ await rm(path.join(payloadDir, name), { force: true });+ }+ }const common: BuildOptions = {bundle: true,format: 'esm',@@ -1101,7 +1117,8 @@ async function produceExport(opts: ExportGameOptions): Promise<ExportGameResult>progress({ phase: 'Copying SDK + runtime' });if (existsSync(opts.sdkDistDir)) {- await cp(opts.sdkDistDir, path.join(payloadDir, 'sdk'), {+ const sdkOut = await resetRuntimeTree(payloadDir, 'sdk', [opts.sdkDistDir, opts.wasmDir]);+ await cp(opts.sdkDistDir, sdkOut, {recursive: true, filter: shipsToBrowser(sourceMaps, opts.sdkDistDir, engineMap.entries),});if (!sourceMaps) await dropSourceMapRefs(path.join(payloadDir, 'sdk'));@@ -1114,7 +1131,8 @@ async function produceExport(opts: ExportGameOptions): Promise<ExportGameResult>errors.push(`content needs "${id}" but ${file}.js is not in ${opts.wasmDir} — build the target that produces it (build-tools/build.config.js maps artifacts to targets) and re-export.`);}}- await cp(opts.wasmDir, path.join(payloadDir, 'wasm'), {+ const wasmOut = await resetRuntimeTree(payloadDir, 'wasm', [opts.sdkDistDir, opts.wasmDir]);+ await cp(opts.wasmDir, wasmOut, {recursive: true, filter: shipsSideModule(files.map((f) => f.file)),});} else errors.push(`wasm runtime dir not found: ${opts.wasmDir}`);diff --git a/pipeline/tests/export-side-modules.test.ts b/pipeline/tests/export-side-modules.test.tsindex 35f02f8da..9b2e95106 100644--- a/pipeline/tests/export-side-modules.test.ts+++ b/pipeline/tests/export-side-modules.test.ts@@ -68,6 +68,20 @@ const entities = (...components: Array<{ type: string; data?: unknown }>) =>[{ id: 0, components }];describe('web package side modules', () => {+ it('drops a removed solver and preserves output-root files on re-export', async () => {+ const f = setup({ version: '1.0', name: 'Main', entities: entities({ type: 'RigidBody2D', data: {} }) });+ try {+ expect((await run(f)).ok).toBe(true);+ expect(shipped(f.out)).toEqual(['physics']);+ writeFileSync(path.join(f.out, 'host-config.json'), 'KEEP');+ writeFileSync(path.join(f.root, 'scenes', 'main.esscene'), JSON.stringify({ version: '1.0', name: 'Main', entities: [] }));+ expect((await run(f)).ok).toBe(true);+ expect(shipped(f.out)).toEqual([]);+ expect(existsSync(path.join(f.out, 'wasm', 'physics.js'))).toBe(false);+ expect(existsSync(path.join(f.out, 'host-config.json'))).toBe(true);+ } finally { rmSync(f.root, { recursive: true, force: true, maxRetries: 10, retryDelay: 50 }); }+ }, 60_000);+it('carries the engine and nothing optional for a scene that asks for nothing', async () => {const f = setup({ version: '1.0', name: 'Main', entities: entities({ type: 'Sprite', data: {} }) });try {diff --git a/pipeline/tests/export-source-maps.test.ts b/pipeline/tests/export-source-maps.test.tsindex b9b0541c1..8457c4229 100644--- a/pipeline/tests/export-source-maps.test.ts+++ b/pipeline/tests/export-source-maps.test.ts@@ -5,7 +5,7 @@* bundles the export writes and the SDK tree it copies beside them.*/import { describe, it, expect } from 'vitest';-import { mkdtempSync, mkdirSync, writeFileSync, readFileSync, existsSync, rmSync } from 'node:fs';+import { mkdtempSync, mkdirSync, writeFileSync, readFileSync, existsSync, rmSync, renameSync } from 'node:fs';import { tmpdir } from 'node:os';import path from 'node:path';import { fileURLToPath } from 'node:url';@@ -48,6 +48,33 @@ const run = (f: { root: string; out: string }, sourcemap?: boolean) => exportGam});describe('source maps in a web package', () => {+ it('refuses to replace a runtime output that also supplies the SDK input', async () => {+ const f = setup();+ try {+ mkdirSync(f.out);+ const sdk = path.join(f.out, 'sdk');+ renameSync(path.join(f.root, '_sdk'), sdk);+ const before = readFileSync(path.join(sdk, 'index.js'), 'utf8');+ await expect(exportGame({+ root: f.root, entryScene: 'scenes/main.esscene', hostsDir: HOSTS, packagesDir: OFFICIAL_PACKAGES,+ sdkDistDir: sdk, wasmDir: path.join(f.root, '_wasm'), outDir: f.out,+ })).rejects.toThrow(/overlaps an input/);+ expect(readFileSync(path.join(sdk, 'index.js'), 'utf8')).toBe(before);+ } finally { rmSync(f.root, { recursive: true, force: true, maxRetries: 10, retryDelay: 50 }); }+ }, 60_000);++ it('removes maps when re-exporting a development package without them', async () => {+ const f = setup();+ try {+ expect((await run(f, true)).ok).toBe(true);+ expect(existsSync(path.join(f.out, 'game.js.map'))).toBe(true);+ expect((await run(f, false)).ok).toBe(true);+ for (const rel of ['game.js.map', 'sdk/index.js.map', 'sdk/shared/resource.js.map']) {+ expect([rel, existsSync(path.join(f.out, rel))]).toEqual([rel, false]);+ }+ } finally { rmSync(f.root, { recursive: true, force: true, maxRetries: 10, retryDelay: 50 }); }+ }, 60_000);+it('ships none by default, and leaves no script asking for one', async () => {const f = setup();try {diff --git a/tools/releaseNotes.mjs b/tools/releaseNotes.mjsindex e922b3cb5..c6f98b609 100644--- a/tools/releaseNotes.mjs+++ b/tools/releaseNotes.mjs@@ -28,6 +28,8 @@ export const NOTES_FLOOR = 'v0.65.0';* the reader recognises anyway.*/export const NOTED = {+ 'fix(export): remove obsolete web runtime files on rebuild':+ { note: 'Repeated Web exports drop obsolete runtime files.' },'fix(editor): report failed exports accurately':{ note: 'Editor export results report failed builds accurately.' },'fix(assets): release app-owned loaders during plugin cleanup':