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.

refactor(bundle): the published subpaths move to a module the renderer can read

esengineb393b459e896
diff --git a/desktop b/desktop
index 0428f6930..aaf6a8998 160000
--- a/desktop
+++ b/desktop
@@ -1 +1 @@
-Subproject commit 0428f69301661eb98bf8710d8125b7eb95db474e
+Subproject commit aaf6a8998298097c58659adca0b12c173ba4f7ff
diff --git a/pipeline/src/bundle/engineInstalls.ts b/pipeline/src/bundle/engineInstalls.ts
index 743ea48d8..3b987ce1a 100644
--- a/pipeline/src/bundle/engineInstalls.ts
+++ b/pipeline/src/bundle/engineInstalls.ts
@@ -18,7 +18,7 @@
*/
import { SUBSYSTEM_INSTALL, type Subsystem } from '../project/targetSupport';
import type { ModuleChoice, ProjectFeatures } from '../project/format';
-import { ESENGINE_SUBPATHS } from './esengineResolve';
+import { ESENGINE_SUBPATHS } from './engineSubpaths';
/** A subsystem a document names by ASSET rather than by component: nothing in a
* scene says "script graph", the `.esgraph` it references does. */
diff --git a/pipeline/src/bundle/engineSubpaths.ts b/pipeline/src/bundle/engineSubpaths.ts
new file mode 100644
index 000000000..24ce4d913
--- /dev/null
+++ b/pipeline/src/bundle/engineSubpaths.ts
@@ -0,0 +1,35 @@
+// SPDX-License-Identifier: Apache-2.0
+// SPDX-FileCopyrightText: Copyright (c) 2024-present ESEngine Team
+/**
+ * @file The `esengine/*` subpaths the SDK publishes, and which are modules.
+ *
+ * Its own module because of who reads it: the bundler's resolver, the export's
+ * import map, and the editor's renderer — which cannot import anything that
+ * touches `node:`. Deliberately node-free for that reason, like targetSupport.
+ */
+
+/** Specifier → the file under `sdk/dist` it resolves to. */
+export const ESENGINE_SUBPATHS: Readonly<Record<string, string>> = {
+ 'esengine/spine': 'spine/index.js',
+ 'esengine/tilemap': 'tilemap/index.js',
+ 'esengine/logic': 'logic/index.js',
+ 'esengine/ai': 'ai/index.js',
+ 'esengine/replication': 'net/replication/index.js',
+ 'esengine/gameplay': 'gameplay/index.js',
+ 'esengine/dragonbones': 'dragonbones/index.js',
+ 'esengine/physics': 'physics/index.js',
+ 'esengine/physics3d': 'physics3d/index.js',
+ 'esengine/douyin': 'douyin/index.js',
+ 'esengine/wasm': 'wasm.js',
+};
+
+/**
+ * Subpaths that are not modules a project picks: the engine binary every target
+ * loads, and a platform adapter an entry chooses rather than content asking for
+ * it. Named here so the pickable set is derived rather than written twice.
+ */
+const NOT_A_MODULE = new Set(['esengine/wasm', 'esengine/douyin']);
+
+/** The modules a project can force in or refuse, as `features.modules` keys it. */
+export const ENGINE_MODULES: readonly string[] =
+ Object.keys(ESENGINE_SUBPATHS).filter((s) => !NOT_A_MODULE.has(s)).sort();
diff --git a/pipeline/src/bundle/esengineResolve.ts b/pipeline/src/bundle/esengineResolve.ts
index 9b21e14c7..ece072513 100644
--- a/pipeline/src/bundle/esengineResolve.ts
+++ b/pipeline/src/bundle/esengineResolve.ts
@@ -12,6 +12,7 @@
* inlines the SDK; esbuild `alias` points esengine (+ subpaths) at dist.
*/
import path from 'node:path';
+import { ESENGINE_SUBPATHS } from './engineSubpaths';
/** esengine left external (web / desktop import-map builds). */
export const ESENGINE_EXTERNAL = ['esengine', 'esengine/*'];
@@ -22,19 +23,8 @@ export const ESENGINE_EXTERNAL = ['esengine', 'esengine/*'];
* hand-written copy is how a specifier the SDK never exported survived in both.
* check-import-map.mjs holds it against the package.
*/
-export const ESENGINE_SUBPATHS: Readonly<Record<string, string>> = {
- 'esengine/spine': 'spine/index.js',
- 'esengine/tilemap': 'tilemap/index.js',
- 'esengine/logic': 'logic/index.js',
- 'esengine/ai': 'ai/index.js',
- 'esengine/replication': 'net/replication/index.js',
- 'esengine/gameplay': 'gameplay/index.js',
- 'esengine/dragonbones': 'dragonbones/index.js',
- 'esengine/physics': 'physics/index.js',
- 'esengine/physics3d': 'physics3d/index.js',
- 'esengine/douyin': 'douyin/index.js',
- 'esengine/wasm': 'wasm.js',
-};
+// One author, in a module the editor's renderer can also read.
+export { ESENGINE_SUBPATHS, ENGINE_MODULES } from './engineSubpaths';
/**
* esbuild `alias` resolving `esengine` and its subpath exports to files under
diff --git a/tools/check-import-map.mjs b/tools/check-import-map.mjs
index 081fb682d..6129da50d 100644
--- a/tools/check-import-map.mjs
+++ b/tools/check-import-map.mjs
@@ -20,7 +20,7 @@ import path from 'node:path';
import { fileURLToPath } from 'node:url';
const ROOT = path.resolve(path.dirname(fileURLToPath(import.meta.url)), '..');
-const RESOLVE = 'pipeline/src/bundle/esengineResolve.ts';
+const RESOLVE = 'pipeline/src/bundle/engineSubpaths.ts';
const src = readFileSync(path.join(ROOT, RESOLVE), 'utf8');
const block = /export const ESENGINE_SUBPATHS[^{]*\{([\s\S]*?)\n\};/.exec(src);