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): the shared mini-game entry names no vendor's API

esengineb194fba5c18b
diff --git a/pipeline/src/export/exportMiniGame.ts b/pipeline/src/export/exportMiniGame.ts
index 2d02e7e11..e6e748f79 100644
--- a/pipeline/src/export/exportMiniGame.ts
+++ b/pipeline/src/export/exportMiniGame.ts
@@ -527,7 +527,7 @@ export async function exportMiniGame(profile: MiniGameExportProfile, opts: {
}
await writeFile(path.join(absOut, 'game.js'),
profile.emitEntry({ sideModules, engineGlueFile, runtimeDir: runtimeLayout.runtimeDir,
- engineSubpackage: runtimeLayout.subpackage?.name ?? null }));
+ engineSubpackage: runtimeLayout.subpackage?.name ?? null, hostGlobal: profile.hostGlobal }));
const configFiles = profile.emitConfigFiles({
title,
appid: opts.appid ?? '',
diff --git a/pipeline/src/export/miniGameExportProfile.ts b/pipeline/src/export/miniGameExportProfile.ts
index 3ac9102ca..b91b9ebfd 100644
--- a/pipeline/src/export/miniGameExportProfile.ts
+++ b/pipeline/src/export/miniGameExportProfile.ts
@@ -61,6 +61,8 @@ export interface MiniGameEntryContext {
/** Package-relative directory those artifacts landed in, decided by the
* export's runtime layout. The entry asks for them WHERE THEY ARE. */
runtimeDir: string;
+ /** The host's API global (`wx` / `tt`), from the profile. */
+ hostGlobal: string;
/** The 分包 holding the engine binary, when it is in one: the entry has to
* ask the host for it before booting, since the file is not in the package
* until then. Null when the binary ships in the main package. */
@@ -95,7 +97,7 @@ ${boot}
// binary there is no game to start, and the reason is worth saying once.
return `'use strict';
// Generated by Estella exportGame (MiniGame entry, engine in a subpackage).
-wx.loadSubpackage({
+${ctx.hostGlobal}.loadSubpackage({
name: ${JSON.stringify(ctx.engineSubpackage)},
success() {
${boot.split('\n').map((l) => (l ? ` ${l}` : l)).join('\n')}
@@ -128,6 +130,12 @@ export interface MiniGameExportProfile {
readonly nativeSuffixes: ReadonlySet<string>;
/** Custom extensions the packer denies unless restaged to `<ext>.bin`. */
readonly binRestageExts: readonly string[];
+ /**
+ * The global this host exposes its API on: `wx` for WeChat, `tt` for Douyin.
+ * The shared entry needs it to ask for a 分包, and taking it from the profile
+ * is what keeps that entry free of any one vendor's name.
+ */
+ readonly hostGlobal: string;
/**
* Whether this vendor's loader takes a `.wasm.br` path — a CAPABILITY;
* spending the build time is `packaging.compressWasm`. WeChat's
@@ -194,6 +202,7 @@ export const wechatExportProfile: MiniGameExportProfile = {
// accepts it; es2017 down-levels those while keeping async/await.
esTarget: 'es2017',
wasmBuildHint: 'wechat',
+ hostGlobal: 'wx',
sideModuleBuildTargets: WECHAT_MODULE_BUILD_TARGET,
// Script + config WeChat's packer compiles itself; every OTHER staged custom
// extension needs a packOptions.include rule (fs reads are otherwise denied).
diff --git a/pipeline/tests/platform-catalog.test.ts b/pipeline/tests/platform-catalog.test.ts
index 729f86891..4a0927855 100644
--- a/pipeline/tests/platform-catalog.test.ts
+++ b/pipeline/tests/platform-catalog.test.ts
@@ -240,11 +240,25 @@ describe('loadProjectPlatform — the profile handed to exportMiniGame', () => {
expect(typeof p.emitEntry).toBe('function');
// The default entry is the same CommonJS shape WeChat ships.
- const entry = p.emitEntry({ sideModules: [{ id: 'physics', file: 'physics' }], engineGlueFile: 'esengine.js', runtimeDir: 'wasm', engineSubpackage: null });
+ const entry = p.emitEntry({ sideModules: [{ id: 'physics', file: 'physics' }], engineGlueFile: 'esengine.js', runtimeDir: 'wasm', engineSubpackage: null, hostGlobal: 'wx' });
expect(entry).toContain("require('./wasm/esengine.js')");
expect(entry).toContain(`"physics": asFactory(require('./wasm/physics.js'))`);
expect(entry).toContain("require('./game-bundle.js')");
+ // The shared entry carries no vendor's API name: the host global is a profile
+ // fact, so a 分包 is asked for through whichever object that vendor exposes.
+ const wxEntry = p.emitEntry({
+ sideModules: [], engineGlueFile: 'esengine.js', runtimeDir: 'wasm',
+ engineSubpackage: 'engine', hostGlobal: 'wx',
+ });
+ expect(wxEntry).toContain('wx.loadSubpackage(');
+ const ttEntry = p.emitEntry({
+ sideModules: [], engineGlueFile: 'esengine.js', runtimeDir: 'wasm',
+ engineSubpackage: 'engine', hostGlobal: 'tt',
+ });
+ expect(ttEntry).toContain('tt.loadSubpackage(');
+ expect(ttEntry).not.toContain('wx.');
+
// And the project's own emitter is what runs for config.
expect(p.emitConfigFiles({ title: 'T', appid: '', orientation: 'portrait', subPackages: [], includeSuffixes: [], hasOpenData: false, openDataRoot: 'open-data' }))
.toEqual([{ file: 'game.json', content: '{"t":"T"}' }]);
diff --git a/tools/releaseNotes.mjs b/tools/releaseNotes.mjs
index 7597e93ee..903a05c31 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(export): the shared mini-game entry names no vendor's API":
+ { internal: 'Fixes an unreleased commit from this same cycle; the shipped behaviour never had it.' },
+
'feat(theme): a dialog title reads as a title':
{ note: "A dialog's title now looks like one." },