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 size report reads a Windows path as it reads any other

esengine10a4bd8a4f2c
diff --git a/pipeline/src/export/bundleBreakdown.ts b/pipeline/src/export/bundleBreakdown.ts
index 082a66cab..0d3e626c8 100644
--- a/pipeline/src/export/bundleBreakdown.ts
+++ b/pipeline/src/export/bundleBreakdown.ts
@@ -37,7 +37,9 @@ export interface BundleMetafile {
* Which module a path belongs to — an original source, or a built chunk when
* there is no map to read it through.
*/
-export function moduleOfInput(input: string): string {
+export function moduleOfInput(spelled: string): string {
+ // A source map's sources are resolved with `path`, which spells them with `\` on Windows.
+ const input = spelled.replace(/\\/g, '/');
const chunk = /(?:^|\/)sdk\/dist\/(?:shared\/)?([^/]+)\.[cm]?js$/.exec(input);
if (chunk) return chunk[1];
const src = /(?:^|\/)sdk\/src\/([^/]+)\/.+$/.exec(input);
diff --git a/pipeline/tests/bundle-breakdown.test.ts b/pipeline/tests/bundle-breakdown.test.ts
index d1cd6208f..fec45664c 100644
--- a/pipeline/tests/bundle-breakdown.test.ts
+++ b/pipeline/tests/bundle-breakdown.test.ts
@@ -32,6 +32,11 @@ const metaWith = (inputs: Record<string, number>) => ({
});
describe('moduleOfInput', () => {
+ it('reads a Windows path as it reads any other', () => {
+ expect(moduleOfInput('D:\\dev\\game\\sdk\\src\\ai\\fsm.ts')).toBe('ai');
+ expect(moduleOfInput('C:\\p\\node_modules\\yoga\\index.js')).toBe('dep:yoga');
+ });
+
it('names an SDK chunk by the chunk, which is the unit a bundler can drop', () => {
expect(moduleOfInput('sdk/dist/shared/spine.js')).toBe('spine');
expect(moduleOfInput('sdk/dist/index.wechat.js')).toBe('index.wechat');