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(size): a subpackage is off the main package, and a compressed engine is still the engine

esengine7a2e4e20b5e1
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 4b3a12442..a4c36cc24 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -23,6 +23,14 @@ published separately; it ships inside the editor.
### Fixed
+- **The size report counts a mini-game's main package without its subpackages.** Everything on
+ disk that the asset manifest did not claim was counted as "downloaded before anything runs",
+ so a binary moved into a subpackage was still judged against the 4MB it had just been moved
+ off — the setting that moves it looked like it did nothing. The export names its subpackage
+ roots now. On hello-world the main package reads 1.55MB against a 1.91MB total, where it read
+ 1.91MB for both. A compressed `.wasm.br` also reads as the engine again rather than as
+ "other", so the biggest file in the package is no longer missing from the chart that finds it.
+
- **A WeChat package can put its engine binary in a compressed subpackage.** The settings for both — `compressWasm` and `engineSubpackage` — existed, had a
row in Project Settings and were honoured by the exporter, and the manifest parser read
neither, so turning them on did nothing anywhere. Five other packaging settings were dropped
diff --git a/pipeline/src/export/exportGame.ts b/pipeline/src/export/exportGame.ts
index 708e39bcd..d423f2fee 100644
--- a/pipeline/src/export/exportGame.ts
+++ b/pipeline/src/export/exportGame.ts
@@ -239,6 +239,9 @@ export interface ExportGameResult {
* size report and dropped: a project's whole asset graph has no business
* crossing to the editor on every build. */
inclusion?: Record<string, Inclusion>;
+ /** @internal Subpackage roots the export staged, for the size report to keep
+ * off the main package's cap. Consumed here and dropped. */
+ subPackageRoots?: string[];
warnings: string[];
errors: string[];
/** Android: the generated Gradle project, for the editor to reveal. Absent
@@ -539,6 +542,7 @@ async function attachSizeReport(result: ExportGameResult, opts: ExportGameOption
projectMaxBytes: opts.sizeBudgetBytes,
deliverable,
packages,
+ subPackageRoots: result.subPackageRoots,
inlineOf: result.inlineParts ? { file: 'index.html', parts: result.inlineParts } : undefined,
inclusion: result.inclusion,
// The project, not the build: what this target weighed last time lives with
diff --git a/pipeline/src/export/exportMiniGame.ts b/pipeline/src/export/exportMiniGame.ts
index 0cef0aa23..09c589086 100644
--- a/pipeline/src/export/exportMiniGame.ts
+++ b/pipeline/src/export/exportMiniGame.ts
@@ -66,6 +66,8 @@ export interface ExportMiniGameResult {
* a vendor's brotli path does not take `.js`, so this is where the remaining
* room is. */
bundleModules?: ModuleBytes[];
+ /** Project-relative subpackage roots — what is NOT on the main package's cap. */
+ subPackageRoots?: string[];
}
interface CookManifest {
@@ -646,5 +648,9 @@ export async function exportMiniGame(profile: MiniGameExportProfile, opts: {
ok: errors.length === 0, platform: profile.id, outDir: absOut,
included: cook.included.length, warnings, errors, inclusion: cook.inclusion,
bundleModules,
+ // The size report weighs the main package against a cap the subpackages are
+ // NOT on, and it cannot tell a subpackage root from any other directory. The
+ // export that made them names them.
+ subPackageRoots: subPackages.subPackages.map((sp) => sp.root),
};
}
diff --git a/pipeline/src/export/sizeReport.ts b/pipeline/src/export/sizeReport.ts
index b0b835565..89e11c9dc 100644
--- a/pipeline/src/export/sizeReport.ts
+++ b/pipeline/src/export/sizeReport.ts
@@ -150,6 +150,12 @@ export function kindOf(rel: string): SizeKind {
const inner = path.extname(p.slice(0, -'.bin'.length));
if (inner) ext = inner;
}
+ // Same shape one layer out: a host whose loader takes `.wasm.br` is shipped the
+ // compressed binary, and it is still whatever it was before compression.
+ if (ext === '.br') {
+ const inner = path.extname(p.slice(0, -'.br'.length));
+ if (inner) ext = inner;
+ }
return EXT_KIND[ext] ?? 'other';
}
@@ -393,6 +399,14 @@ export async function measureBuild(opts: {
* ("does this repackage what is already there?"), rather than a proxy for it.
*/
packages?: readonly string[];
+ /**
+ * Project-relative directories whose contents are a SUBPACKAGE — fetched at
+ * startup, and off whatever cap the main package is judged against.
+ *
+ * Named by the export that staged them, for the reason `packages` is: a path
+ * prefix would be a guess about what a vendor happens to call one.
+ */
+ subPackageRoots?: readonly string[];
/**
* A single-file target's file, and what it is made of — each span under the
* path those bytes would carry loose. The file is replaced by its spans, so
@@ -441,8 +455,18 @@ export async function measureBuild(opts: {
} catch { /* not produced (no template installed) — the limit is then skipped */ }
}
+ // The manifest's own answer first; a subpackage root the export named wins
+ // over the default, since nothing in the manifest claims the engine binary.
+ const buckets = bucketIndexFrom(manifest);
+ const roots = (opts.subPackageRoots ?? []).map((r) => `${normalizeRel(r)}/`);
+ if (roots.length > 0) {
+ for (const f of files) {
+ const rel = normalizeRel(f.path);
+ if (roots.some((r) => rel.startsWith(r))) buckets.set(rel, 'lazy');
+ }
+ }
const entries = entriesOf(files, {
- buckets: bucketIndexFrom(manifest),
+ buckets,
logical: logicalIndexFrom(manifest),
inclusion: opts.inclusion,
});
diff --git a/pipeline/tests/export-wechat.test.ts b/pipeline/tests/export-wechat.test.ts
index dd997e0d5..f1018917f 100644
--- a/pipeline/tests/export-wechat.test.ts
+++ b/pipeline/tests/export-wechat.test.ts
@@ -166,11 +166,11 @@ describe('exportGame (wechat)', () => {
expect(total?.budget.maxBytes).toBe(30 * 1024 * 1024);
expect(initial?.status).toBe('ok');
expect(res.size?.byKind.find((k) => k.kind === 'engine')?.bytes).toBeGreaterThan(0);
- // The fixture's subpackage asset (`subpackages/level2/extra.png`, 8 bytes of
- // "PNG2DATA") is in the package but NOT in the main one — the distinction the
- // 4MB limit is judged on, measured end-to-end on the real mini-game path.
- expect(res.size?.lazyBytes).toBe(8);
- expect(res.size?.packageBytes).toBe(res.size!.initialBytes + 8);
+ // Everything under a subpackage root is off the main package: the asset
+ // (8 bytes) AND the entry `game.js` WeChat demands in every root (169).
+ const lazy = 8 + 169;
+ expect(res.size?.lazyBytes).toBe(lazy);
+ expect(res.size?.packageBytes).toBe(res.size!.initialBytes + lazy);
expect(initial?.measuredBytes).toBe(res.size?.initialBytes);
}, 60_000);
diff --git a/pipeline/tests/size-report.test.ts b/pipeline/tests/size-report.test.ts
index 9776b2318..15670c3b1 100644
--- a/pipeline/tests/size-report.test.ts
+++ b/pipeline/tests/size-report.test.ts
@@ -100,6 +100,17 @@ describe('composition', () => {
expect(kindOf('scripts.mjs')).toBe('scripts');
});
+ it('still reads the engine binary once it is compressed and moved to a subpackage', () => {
+ // Both halves of the move matter: the `wasm/` prefix is gone and `.wasm.br`
+ // is not `.wasm`, and either alone files it under "other".
+ expect(kindOf('subpackages/engine/esengine.wxgame.wasm.br')).toBe('engine');
+ expect(kindOf('subpackages/engine/esengine.wxgame.wasm')).toBe('engine');
+ expect(kindOf('wasm/esengine.wxgame.wasm.br')).toBe('engine');
+ // One layer, not a guess: a compressed texture is still a texture.
+ expect(kindOf('assets/9f8a7c.ktx2.br')).toBe('texture');
+ expect(kindOf('notes.br')).toBe('other');
+ });
+
it('separates scenes from the rest of the JSON', () => {
expect(kindOf('scenes/level1.json')).toBe('scene');
expect(kindOf('game.config.json')).toBe('data');
diff --git a/tools/releaseNotes.mjs b/tools/releaseNotes.mjs
index 66c0e0766..87ed2f977 100644
--- a/tools/releaseNotes.mjs
+++ b/tools/releaseNotes.mjs
@@ -28,6 +28,9 @@ export const NOTES_FLOOR = 'v0.65.0';
* the reader recognises anyway.
*/
export const NOTED = {
+ 'fix(size): a subpackage is off the main package, and a compressed engine is still the engine':
+ { note: "The size report counts a mini-game's main package without its subpackages." },
+
'fix(project): seven packaging settings a project could declare did nothing':
{ note: "A WeChat package can put its engine binary in a compressed subpackage." },