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): a WeChat 分包 root carries the entry its vendor demands

esengine392ba4476eb3
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 44d1ab7f3..5d385dae7 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -14,6 +14,19 @@ published separately; it ships inside the editor.
## [Unreleased]
+### Fixed
+
+- **A WeChat 分包 root carries the entry file the vendor demands.** With the phantom
+ roots gone, the export hit the next requirement behind them: devtools refuses to
+ compile a package whose subpackage root has no `game.js`, naming the missing file
+ rather than the rule (`未找到 ["subPackages"][0]["root"] 对应的
+ /subpackages/pack/game.js 文件`). A root of pure assets is not a subpackage to
+ WeChat. The profile declares what its vendor wants there and the export writes it,
+ so a criterion can hold every declared root to it.
+
+ Nothing could have found this before a real root existed — the check never got far
+ enough to run.
+
### Changed
- **The hot-update demo now ships a real 分包.** Its two groups take the two modes
diff --git a/pipeline/src/export/exportMiniGame.ts b/pipeline/src/export/exportMiniGame.ts
index aeec486ab..2142a4ecf 100644
--- a/pipeline/src/export/exportMiniGame.ts
+++ b/pipeline/src/export/exportMiniGame.ts
@@ -430,6 +430,19 @@ export async function exportMiniGame(profile: MiniGameExportProfile, opts: {
// 5. Entry + config (vendor-specific emission).
const subPackages = subPackagesOf(cookEntries, profile.subpackageDir);
warnings.push(...subPackages.strays);
+ // A vendor that wants an entry in every subpackage root refuses the package
+ // without one, naming the missing file rather than the rule. These roots hold
+ // assets the runtime reads by path, so the entry has nothing to do but exist.
+ if (profile.subpackageEntry) {
+ for (const sp of subPackages.subPackages) {
+ await writeFile(
+ path.join(absOut, sp.root, profile.subpackageEntry),
+ `// Entry for the "${sp.name}" subpackage, which ${profile.id} requires in every\n`
+ + '// subpackage root. This one carries assets the runtime loads by path, so it\n'
+ + '// has nothing to run.\n',
+ );
+ }
+ }
await writeFile(path.join(absOut, 'game.js'), profile.emitEntry({ sideModules, engineGlueFile }));
const configFiles = profile.emitConfigFiles({
title,
diff --git a/pipeline/src/export/miniGameExportProfile.ts b/pipeline/src/export/miniGameExportProfile.ts
index 31c92222f..804bf882a 100644
--- a/pipeline/src/export/miniGameExportProfile.ts
+++ b/pipeline/src/export/miniGameExportProfile.ts
@@ -105,6 +105,13 @@ export interface MiniGameExportProfile {
readonly binRestageExts: readonly string[];
/** Subpackage root prefix (files stage under `<subpackageDir>/<name>/`). */
readonly subpackageDir: string;
+ /**
+ * The entry script a subpackage root must carry, or absent when the vendor
+ * asks for none. WeChat refuses to compile a 分包 whose root has no
+ * `game.js` — a root full of assets and no entry is not a subpackage to it,
+ * and the message names the missing FILE rather than the rule.
+ */
+ readonly subpackageEntry?: string;
/**
* What this host refuses to accept — the main package cap, the all-in cap.
@@ -162,6 +169,7 @@ export const wechatExportProfile: MiniGameExportProfile = {
// WeChat's code-package suffix whitelist has no ktx2/esv; restage to *.bin.
binRestageExts: ['ktx2', 'esv'],
subpackageDir: 'subpackages',
+ subpackageEntry: 'game.js',
emitConfigFiles(ctx) {
const gameCfg: Record<string, unknown> = {
diff --git a/pipeline/src/export/platformCatalog.ts b/pipeline/src/export/platformCatalog.ts
index 49cf1cb1f..2d535571c 100644
--- a/pipeline/src/export/platformCatalog.ts
+++ b/pipeline/src/export/platformCatalog.ts
@@ -162,6 +162,9 @@ export const MINIGAME_PROFILE_DEFAULTS = {
nativeSuffixes: new Set(['.js', '.json']) as ReadonlySet<string>,
binRestageExts: [] as readonly string[],
subpackageDir: 'subpackages',
+ // Most vendors take a root of assets as a subpackage; the ones that want an
+ // entry script in it say so (WeChat: game.js).
+ subpackageEntry: undefined as string | undefined,
emitEntry: defaultMiniGameEntry,
};
diff --git a/pipeline/tests/export-wechat-subpackage.test.ts b/pipeline/tests/export-wechat-subpackage.test.ts
index f7fe5f8db..487f7d24b 100644
--- a/pipeline/tests/export-wechat-subpackage.test.ts
+++ b/pipeline/tests/export-wechat-subpackage.test.ts
@@ -82,6 +82,10 @@ describe('WeChat 分包 declared through asset-groups.json', () => {
const dir = path.join(out, sp.root);
expect(existsSync(dir), `${sp.root} missing from the package`).toBe(true);
expect(readdirSync(dir, { recursive: true }).length, `${sp.root} is empty`).toBeGreaterThan(0);
+ // …and its entry. Devtools refuses to compile a 分包 root without one:
+ // "未找到 ["subPackages"][0]["root"] 对应的 /subpackages/pack/game.js 文件".
+ // A root of pure assets is not a subpackage to WeChat.
+ expect(existsSync(path.join(dir, 'game.js')), `${sp.root} has no game.js entry`).toBe(true);
}
}, 120_000);