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(wechat): an atlas page is one file however many sprites name it

esenginea36d3265b620
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 57ec48cc9..3e65e6341 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -23,6 +23,12 @@ published separately; it ships inside the editor.
### Fixed
+- **A mini-game export no longer fails on a project whose sprites are atlased.** Names that
+ a vendor's packer will not upload are shipped with a `.bin` suffix, and the rename walked
+ the manifest one asset at a time — so the seven sprites packed into one atlas page tried to
+ move the same file seven times, and the export died on the second. Any 2D project with an
+ atlas, which is most of them.
+
- **The size report says which subsystem each byte of the scripts came from.** A mini-game
inlines the engine's JavaScript, and the report grouped it by the bundler's own chunks —
so two thirds of it sat in one row named after one of the four hundred modules inside it.
diff --git a/pipeline/src/export/exportMiniGame.ts b/pipeline/src/export/exportMiniGame.ts
index 9630a6586..6480c5f6b 100644
--- a/pipeline/src/export/exportMiniGame.ts
+++ b/pipeline/src/export/exportMiniGame.ts
@@ -324,6 +324,8 @@ export async function exportMiniGame(profile: MiniGameExportProfile, opts: {
const flatManifestPath = path.join(absOut, 'assets.manifest.json');
let cookEntries: CookManifest['entries'] = [];
const sceneRawByName = new Map<string, unknown>();
+ /** Where a staged file went, so a second entry naming it does not move it again. */
+ const restaged = new Map<string, string>();
try {
const flat = JSON.parse(await readFile(flatManifestPath, 'utf8')) as CookManifest;
for (const e of flat.entries) {
@@ -332,8 +334,15 @@ export async function exportMiniGame(profile: MiniGameExportProfile, opts: {
// beside the transformed one, under a name nothing reads.
const scene = scenes.find((s) => s.path === e.path);
if (!scene && needsRestage(e.path)) {
- await rename(path.join(absOut, e.path), path.join(absOut, `${e.path}.bin`));
- e.path = `${e.path}.bin`;
+ // Assets share an output freely — every sprite packed into an atlas
+ // names the same page — so the file moves once and the rest follow it.
+ let moved = restaged.get(e.path);
+ if (moved === undefined) {
+ moved = `${e.path}.bin`;
+ await rename(path.join(absOut, e.path), path.join(absOut, moved));
+ restaged.set(e.path, moved);
+ }
+ e.path = moved;
continue;
}
if (scene) {
diff --git a/pipeline/tests/export-wechat.test.ts b/pipeline/tests/export-wechat.test.ts
index f1018917f..5e03b79a1 100644
--- a/pipeline/tests/export-wechat.test.ts
+++ b/pipeline/tests/export-wechat.test.ts
@@ -784,3 +784,60 @@ describe('exportGame (wechat) — open data context', () => {
expect(JSON.parse(readFileSync(path.join(o, 'game.json'), 'utf8'))).not.toHaveProperty('openDataContext');
}, 60_000);
});
+
+/**
+ * Assets share a staged file freely: every sprite packed into an atlas names the
+ * same page, and content addressing hands identical bytes one name. The packer
+ * rename walked manifest ENTRIES, so the first moved the file and the rest died
+ * on a path that was no longer there — which is every atlased 2D project.
+ */
+describe('two assets, one staged file', () => {
+ const roots: string[] = [];
+ afterAll(() => {
+ for (const r of roots) rmSync(r, { recursive: true, force: true, maxRetries: 10, retryDelay: 50 });
+ });
+
+ it('renames it once and points both entries at the new name', async () => {
+ const dir = mkdtempSync(path.join(tmpdir(), 'estella-export-shared-'));
+ roots.push(dir);
+ const A = '11111111-1111-1111-1111-111111111111';
+ const B = '22222222-2222-2222-2222-222222222222';
+ // `.eslocale` is not on WeChat's upload whitelist, and identical bytes under
+ // content addressing cook to one file — the shape an atlas page has.
+ mkdirSync(path.join(dir, 'assets', 'i18n'), { recursive: true });
+ for (const [name, uuid] of [['en', A], ['fr', B]] as const) {
+ writeFileSync(path.join(dir, 'assets', 'i18n', `${name}.eslocale`), JSON.stringify({ hello: 'hi' }));
+ writeFileSync(path.join(dir, 'assets', 'i18n', `${name}.eslocale.meta`), meta(uuid, 'locale'));
+ }
+ mkdirSync(path.join(dir, 'scenes'), { recursive: true });
+ writeFileSync(path.join(dir, 'scenes', 'main.esscene'), JSON.stringify({
+ version: '1.0', name: 'Main', entities: [{ id: 0, components: [] }],
+ }));
+ writeFileSync(path.join(dir, 'scenes', 'main.esscene.meta'), meta(SCN, 'scene'));
+ mkdirSync(path.join(dir, '_sdk'), { recursive: true });
+ writeFileSync(path.join(dir, '_sdk', 'index.wechat.js'), 'export function initWeChatRuntime(){return Promise.resolve();}\n');
+ mkdirSync(path.join(dir, '_wxwasm'), { recursive: true });
+ writeFileSync(path.join(dir, '_wxwasm', 'esengine.js'), 'module.exports = () => Promise.resolve({});');
+ writeFileSync(path.join(dir, '_wxwasm', 'esengine.wasm'), 'wasmbytes');
+
+ const outDir = path.join(dir, 'dist-wechat');
+ const res = await exportGame({
+ root: dir, entryScene: 'scenes/main.esscene', hostsDir: 'unused-for-wechat',
+ sdkDistDir: path.join(dir, '_sdk'), wasmDir: path.join(dir, '_wxwasm'),
+ outDir, platform: 'wechat', contentAddressed: true,
+ });
+
+ expect(res.errors.join('\n')).not.toMatch(/ENOENT/);
+ expect(res.ok).toBe(true);
+ const manifest = JSON.parse(readFileSync(path.join(outDir, 'asset-manifest.json'), 'utf8'));
+ const paths = Object.values(manifest.groups as Record<string, { assets: Record<string, { path: string }> }>)
+ .flatMap((g) => Object.values(g.assets).map((a) => a.path))
+ .filter((p) => p.includes('.eslocale'));
+ expect(paths.length).toBe(2);
+ expect(new Set(paths).size).toBe(1);
+ for (const p of paths) {
+ expect(p.endsWith('.bin')).toBe(true);
+ expect(existsSync(path.join(outDir, p))).toBe(true);
+ }
+ }, 60_000);
+});
diff --git a/tools/releaseNotes.mjs b/tools/releaseNotes.mjs
index 26ac25750..f312d79e3 100644
--- a/tools/releaseNotes.mjs
+++ b/tools/releaseNotes.mjs
@@ -680,4 +680,6 @@ export const NOTED = {
{ note: 'The size report says which subsystem each byte of the scripts came from.' },
'fix(gates): a start screen that faded is not one that never did':
{ internal: 'a verifier\'s reading of a boot it already watched finish' },
+ 'fix(wechat): an atlas page is one file however many sprites name it':
+ { note: 'A mini-game export no longer fails on a project whose sprites are atlased.' },
};