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(debug): a shipping package no longer carries the debug channel

esengine9d4273753d8f
diff --git a/CHANGELOG.md b/CHANGELOG.md
index aa7d70425..469b06251 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -24,6 +24,7 @@ published separately; it ships inside the editor.
### Fixed
+- A shipping package no longer carries the development debug channel's code (13 KB on a WeChat package): only a development export that names an editor imports it, as `esengine/debug-channel`.
- Capturing a development build whose tab is in the background says so at once, instead of waiting 30 seconds for a frame the browser will not draw.
- A web game opened in a background tab starts paused and reports itself hidden until it is shown; before, it counted as visible.
- The hot-update demo no longer says the remote manifest matches when it could not reach one; offline it says it keeps the local content.
diff --git a/pipeline/src/bundle/engineInstalls.ts b/pipeline/src/bundle/engineInstalls.ts
index f5d8faea0..cf2381af4 100644
--- a/pipeline/src/bundle/engineInstalls.ts
+++ b/pipeline/src/bundle/engineInstalls.ts
@@ -92,6 +92,8 @@ export interface EngineInstallEvidence {
scriptImports?: Iterable<string>;
/** What the project said, from {@link moduleChoices}. */
choices?: Readonly<Record<string, ModuleChoice>>;
+ /** A development build that names an editor to connect to. */
+ debugChannel?: boolean;
}
/** What a package installs, and whether a lean entry can carry it. */
@@ -158,6 +160,8 @@ export function engineInstalls(evidence: EngineInstallEvidence): EngineInstallPl
if (specifier in ESENGINE_SUBPATHS) saw(specifier, `a project script imports "${specifier}"`);
}
+ if (evidence.debugChannel) saw('esengine/debug-channel', 'a development build that names an editor');
+
const choices = evidence.choices ?? {};
const refused: ExcludedInUse[] = [];
const subpaths = new Set<string>();
diff --git a/pipeline/src/bundle/engineSubpaths.ts b/pipeline/src/bundle/engineSubpaths.ts
index f19cd3b47..ccdc9b334 100644
--- a/pipeline/src/bundle/engineSubpaths.ts
+++ b/pipeline/src/bundle/engineSubpaths.ts
@@ -13,6 +13,7 @@ export const ESENGINE_SUBPATHS: Readonly<Record<string, string>> = {
'esengine/spine': 'spine/index.js',
'esengine/tilemap': 'tilemap/index.js',
'esengine/logic': 'logic/index.js',
+ 'esengine/debug-channel': 'debug-channel/index.js',
'esengine/ai': 'ai/index.js',
'esengine/replication': 'net/replication/index.js',
'esengine/gameplay': 'gameplay/index.js',
@@ -30,10 +31,10 @@ export const ESENGINE_SUBPATHS: Readonly<Record<string, string>> = {
/**
* 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.
+ * loads, a platform adapter an entry chooses rather than content asking for it,
+ * and the debug channel a development export adds. Named here so the pickable set is derived rather than written twice.
*/
-export const NOT_A_MODULE: ReadonlySet<string> = new Set(['esengine/wasm', 'esengine/douyin', 'esengine/kuaishou', 'esengine/bilibili', 'esengine/quickgame', 'esengine/alipay', 'esengine/huawei']);
+export const NOT_A_MODULE: ReadonlySet<string> = new Set(['esengine/wasm', 'esengine/debug-channel', 'esengine/douyin', 'esengine/kuaishou', 'esengine/bilibili', 'esengine/quickgame', 'esengine/alipay', 'esengine/huawei']);
/** The modules a project can force in or refuse, as `features.modules` keys it. */
export const ENGINE_MODULES: readonly string[] =
diff --git a/pipeline/src/export/exportGame.ts b/pipeline/src/export/exportGame.ts
index 765dc94b0..f2b3cfab2 100644
--- a/pipeline/src/export/exportGame.ts
+++ b/pipeline/src/export/exportGame.ts
@@ -946,6 +946,7 @@ async function produceExport(opts: ExportGameOptions): Promise<ExportGameResult>
sideModuleIds,
scriptImports,
choices: moduleChoices(opts.features, opts.modulesByPlatform?.[platform]),
+ debugChannel: !!debugChannel,
});
// A package missing half a scene, with nothing saying which half, is worse
// than one that refuses to be made.
diff --git a/pipeline/src/export/exportMiniGame.ts b/pipeline/src/export/exportMiniGame.ts
index 126a7853a..becd79234 100644
--- a/pipeline/src/export/exportMiniGame.ts
+++ b/pipeline/src/export/exportMiniGame.ts
@@ -526,6 +526,7 @@ export async function exportMiniGame(profile: MiniGameExportProfile, opts: {
assetPaths: cook.includedPaths,
sideModuleIds: sideModules.map((m) => m.id),
choices: moduleChoices(opts.features, opts.modulesByPlatform?.[profile.id]),
+ debugChannel: !!debugChannel,
});
// A package missing half a scene, with nothing saying which half, is worse than
// one that refuses to be made.
diff --git a/pipeline/tests/export-engine-installs.test.ts b/pipeline/tests/export-engine-installs.test.ts
index c04b36366..6d2280453 100644
--- a/pipeline/tests/export-engine-installs.test.ts
+++ b/pipeline/tests/export-engine-installs.test.ts
@@ -32,6 +32,7 @@ const SDK_FILES = {
'tilemap/index.js': 'export const tilemap = 1;\n',
'ai/index.js': 'export const ai = 1;\n',
'net/replication/index.js': 'export const repl = 1;\n',
+ 'debug-channel/index.js': 'export const channel = 1;\n',
'shared/core.js': 'export const core = 1;\n',
};
@@ -134,6 +135,35 @@ describe('a web package built on a lean entry', () => {
* subsystem its own scene needs, with nothing saying which one — so the export
* refuses to make it, and names what argued.
*/
+describe('the debug channel', () => {
+ it('is installed in a development build that names an editor, and nowhere else', async () => {
+ const f = setup(['Transform', 'Sprite']);
+ const dev = { ...f, out: path.join(f.root, 'dev') };
+ try {
+ await run(f);
+ const res = await exportGame({
+ root: f.root, entryScene: 'scenes/main.esscene', hostsDir: HOSTS, packagesDir: OFFICIAL_PACKAGES,
+ sdkDistDir: path.join(f.root, '_sdk'), wasmDir: path.join(f.root, '_wasm'),
+ outDir: dev.out, debugChannel: { url: 'ws://192.168.1.2:37420/?token=t' },
+ });
+ expect(res.errors).toEqual([]);
+ const shipped = (out: string) => ({
+ page: readFileSync(path.join(out, 'index.html'), 'utf8'),
+ game: readFileSync(path.join(out, 'game.js'), 'utf8'),
+ staged: existsSync(path.join(out, 'sdk', 'debug-channel', 'index.js')),
+ });
+ const withChannel = shipped(dev.out);
+ expect(withChannel.page).toContain('"esengine/debug-channel":"./sdk/debug-channel/index.js"');
+ expect(withChannel.game).toContain('import "esengine/debug-channel"');
+ expect(withChannel.staged).toBe(true);
+ const without = shipped(f.out);
+ expect(without.page).not.toContain('debug-channel');
+ expect(without.game).not.toContain('debug-channel');
+ expect(without.staged).toBe(false);
+ } finally { rmSync(f.root, { recursive: true, force: true, maxRetries: 10, retryDelay: 50 }); }
+ });
+});
+
describe('a web package whose project excluded a module', () => {
/** The export takes what the project said as an option, the way it takes every
* other project-derived setting; `packagingOptionsOf` is what derives it. */
diff --git a/sdk/etc/debug-channel.api.md b/sdk/etc/debug-channel.api.md
new file mode 100644
index 000000000..db0dca19c
--- /dev/null
+++ b/sdk/etc/debug-channel.api.md
@@ -0,0 +1,5 @@
+# API surface — esengine/debug-channel
+
+<!-- Generated by tools/api-surface.mjs — do not edit. Run --update to accept changes. -->
+Symbols: 0 public · 0 beta · 0 experimental · 0 deprecated
+
diff --git a/sdk/package.json b/sdk/package.json
index 50bf1d983..0628be4cf 100644
--- a/sdk/package.json
+++ b/sdk/package.json
@@ -17,6 +17,7 @@
"./dist/spine/index.js",
"./dist/tilemap/index.js",
"./dist/logic/index.js",
+ "./dist/debug-channel/index.js",
"./dist/ai/index.js",
"./dist/net/replication/index.js",
"./dist/gameplay/index.js",
@@ -72,6 +73,10 @@
"import": "./dist/logic/index.js",
"types": "./dist/logic/index.d.ts"
},
+ "./debug-channel": {
+ "import": "./dist/debug-channel/index.js",
+ "types": "./dist/debug-channel/index.d.ts"
+ },
"./ai": {
"import": "./dist/ai/index.js",
"types": "./dist/ai/index.d.ts"
diff --git a/sdk/rolldown.config.js b/sdk/rolldown.config.js
index d4a726bc4..2c55ba31b 100644
--- a/sdk/rolldown.config.js
+++ b/sdk/rolldown.config.js
@@ -97,6 +97,7 @@ export default defineConfig([
'spine/index': 'src/spine/index.ts',
'tilemap/index': 'src/tilemap/index.ts',
'logic/index': 'src/logic/index.ts',
+ 'debug-channel/index': 'src/debug-channel/index.ts',
'ai/index': 'src/ai/index.ts',
'net/replication/index': 'src/net/replication/index.ts',
'gameplay/index': 'src/gameplay/index.ts',
diff --git a/sdk/rollup.config.js b/sdk/rollup.config.js
index d027d54dc..ec5055f16 100644
--- a/sdk/rollup.config.js
+++ b/sdk/rollup.config.js
@@ -25,6 +25,7 @@ export default [
'spine/index': 'src/spine/index.ts',
'tilemap/index': 'src/tilemap/index.ts',
'logic/index': 'src/logic/index.ts',
+ 'debug-channel/index': 'src/debug-channel/index.ts',
'ai/index': 'src/ai/index.ts',
'net/replication/index': 'src/net/replication/index.ts',
'gameplay/index': 'src/gameplay/index.ts',
diff --git a/sdk/src/core-content.ts b/sdk/src/core-content.ts
index 65061e7eb..5fe9ad518 100644
--- a/sdk/src/core-content.ts
+++ b/sdk/src/core-content.ts
@@ -455,14 +455,14 @@ export {
type SnapshotEntity,
type SnapshotComponent,
} from './runtime/worldSnapshot';
+export { startDebugChannel } from './runtime/debugChannelHook';
export {
- startDebugChannel,
DEBUG_CHANNEL_PROTOCOL,
type DebugChannelConfig,
type DebugControl,
type DebugChannelMessage,
type DebugChannelQuery,
-} from './runtime/debugChannel';
+} from './runtime/debugChannelProtocol';
// =============================================================================
// Preview
diff --git a/sdk/src/debug-channel/debugChannelSupport.ts b/sdk/src/debug-channel/debugChannelSupport.ts
new file mode 100644
index 000000000..142e375e0
--- /dev/null
+++ b/sdk/src/debug-channel/debugChannelSupport.ts
@@ -0,0 +1,12 @@
+// SPDX-License-Identifier: Apache-2.0
+// SPDX-FileCopyrightText: Copyright (c) 2024-present ESEngine Team
+/**
+ * @file debugChannelSupport.ts — hands the runtime the channel it starts for a
+ * development build.
+ */
+import { setDebugChannelImpl } from '../runtime/debugChannelHook';
+import { startDebugChannel, attachDebugChannel } from '../runtime/debugChannel';
+
+export function registerDebugChannelSupport(): void {
+ setDebugChannelImpl({ start: startDebugChannel, attach: attachDebugChannel });
+}
diff --git a/sdk/src/debug-channel/index.ts b/sdk/src/debug-channel/index.ts
new file mode 100644
index 000000000..800608342
--- /dev/null
+++ b/sdk/src/debug-channel/index.ts
@@ -0,0 +1,10 @@
+// SPDX-License-Identifier: Apache-2.0
+// SPDX-FileCopyrightText: Copyright (c) 2024-present ESEngine Team
+/**
+ * @file index.ts — `esengine/debug-channel`: importing it gives a development
+ * build its line to the editor. The export adds the import to a package
+ * that names an editor, and to no other.
+ */
+import { registerDebugChannelSupport } from './debugChannelSupport';
+
+registerDebugChannelSupport();
diff --git a/sdk/src/runtime/debugChannel.ts b/sdk/src/runtime/debugChannel.ts
index 6757458cf..fba97c366 100644
--- a/sdk/src/runtime/debugChannel.ts
+++ b/sdk/src/runtime/debugChannel.ts
@@ -4,6 +4,7 @@
* @file debugChannel.ts
* @brief A development build's line back to the editor that exported it, over
* which the editor's frame debugger captures the device's frames.
+ * Carried only by a package that imports `esengine/debug-channel`.
*
* Only a build whose config carries `debugChannel` opens one, and only a
* development export writes that field. The device dials out: a phone or a
@@ -21,45 +22,9 @@ import { Lifecycle } from '../ecs/lifecycle';
import { frameStatsReport } from './frameStats';
import { worldSnapshot } from './worldSnapshot';
import { forwardConsole, type ConsoleLevel } from './consoleForward';
-
-export const DEBUG_CHANNEL_PROTOCOL = 1;
-
-/** The editor's address as a development export writes it into the config. */
-export interface DebugChannelConfig {
- /** `ws://<editor host>:<port>/?token=<token>` */
- url: string;
- /** The project the build was made from, so the editor can tell a build of
- * another project from one of the project it has open. */
- project?: string;
-}
-
-/** What `control` changes; each field absent leaves that setting alone. */
-export interface DebugControl {
- paused?: boolean;
- /** Advance this many frames — a paused game included. */
- step?: number;
- /** A cap on the frame rate; 0 lifts it. */
- fps?: number;
-}
-
-export type DebugChannelQuery =
- | { t: 'query'; reqId: number; kind: 'frameCapture' }
- | { t: 'query'; reqId: number; kind: 'frameReplay'; drawIndex: number; maxSide?: number }
- | { t: 'query'; reqId: number; kind: 'stats' }
- | { t: 'query'; reqId: number; kind: 'snapshot'; selectedId: number | null; withTree: boolean }
- | ({ t: 'query'; reqId: number; kind: 'control' } & DebugControl);
-
-/**
- * What a device sends. A replay's pixels follow their `reply` as binary frames,
- * `pixels` of them: text would add a third to every byte, and a mini-game host's
- * socket drops a frame the size of a whole screen. Lines go in batches, since a
- * host that traces its own every call prints thousands a second.
- */
-export type DebugChannelMessage =
- | { t: 'hello'; v: number; platform: string; title: string; project: string | null; revision: string | null }
- | { t: 'reply'; reqId: number; data: unknown; pixels?: number }
- | { t: 'reply'; reqId: number; error: string }
- | { t: 'logs'; entries: Array<{ level: ConsoleLevel; line: string }> };
+import {
+ DEBUG_CHANNEL_PROTOCOL, type DebugChannelConfig, type DebugChannelMessage, type DebugChannelQuery,
+} from './debugChannelProtocol';
const RECONNECT_MS = 3000;
const START_WAIT_MS = 20_000;
diff --git a/sdk/src/runtime/debugChannelHook.ts b/sdk/src/runtime/debugChannelHook.ts
new file mode 100644
index 000000000..36faf6c4e
--- /dev/null
+++ b/sdk/src/runtime/debugChannelHook.ts
@@ -0,0 +1,37 @@
+// SPDX-License-Identifier: Apache-2.0
+// SPDX-FileCopyrightText: Copyright (c) 2024-present ESEngine Team
+/**
+ * @file debugChannelHook.ts — where the runtime starts a development build's
+ * channel, without carrying it: a shipping package never opens one, so
+ * the channel arrives only with `esengine/debug-channel`.
+ */
+import type { App } from '../app/app';
+import { log } from '../util/logger';
+import type { DebugChannelConfig } from './debugChannelProtocol';
+
+export interface DebugChannelImpl {
+ start(config: DebugChannelConfig): void;
+ attach(app: App): void;
+}
+
+let impl: DebugChannelImpl | null = null;
+
+/** @internal Installed by `esengine/debug-channel`. */
+export function setDebugChannelImpl(next: DebugChannelImpl): void {
+ impl = next;
+}
+
+/** Open this build's line to the editor, from a host as soon as it has read its
+ * config: what it prints while the engine boots is then heard too. */
+export function startDebugChannel(config: DebugChannelConfig): void {
+ if (!impl) {
+ log.warn('debug', 'this build names an editor to connect to but was packaged without esengine/debug-channel');
+ return;
+ }
+ impl.start(config);
+}
+
+/** @internal Give the channel the running game, once there is one. */
+export function attachDebugChannel(app: App): void {
+ impl?.attach(app);
+}
diff --git a/sdk/src/runtime/debugChannelProtocol.ts b/sdk/src/runtime/debugChannelProtocol.ts
new file mode 100644
index 000000000..2553eb925
--- /dev/null
+++ b/sdk/src/runtime/debugChannelProtocol.ts
@@ -0,0 +1,47 @@
+// SPDX-License-Identifier: Apache-2.0
+// SPDX-FileCopyrightText: Copyright (c) 2024-present ESEngine Team
+/**
+ * @file debugChannelProtocol.ts — what a development build and the editor say to
+ * each other. Its own module so the core can name the protocol without
+ * carrying the channel.
+ */
+import type { ConsoleLevel } from './consoleForward';
+
+export const DEBUG_CHANNEL_PROTOCOL = 1;
+
+/** The editor's address as a development export writes it into the config. */
+export interface DebugChannelConfig {
+ /** `ws://<editor host>:<port>/?token=<token>` */
+ url: string;
+ /** The project the build was made from, so the editor can tell a build of
+ * another project from one of the project it has open. */
+ project?: string;
+}
+
+/** What `control` changes; each field absent leaves that setting alone. */
+export interface DebugControl {
+ paused?: boolean;
+ /** Advance this many frames — a paused game included. */
+ step?: number;
+ /** A cap on the frame rate; 0 lifts it. */
+ fps?: number;
+}
+
+export type DebugChannelQuery =
+ | { t: 'query'; reqId: number; kind: 'frameCapture' }
+ | { t: 'query'; reqId: number; kind: 'frameReplay'; drawIndex: number; maxSide?: number }
+ | { t: 'query'; reqId: number; kind: 'stats' }
+ | { t: 'query'; reqId: number; kind: 'snapshot'; selectedId: number | null; withTree: boolean }
+ | ({ t: 'query'; reqId: number; kind: 'control' } & DebugControl);
+
+/**
+ * What a device sends. A replay's pixels follow their `reply` as binary frames,
+ * `pixels` of them: text would add a third to every byte, and a mini-game host's
+ * socket drops a frame the size of a whole screen. Lines go in batches, since a
+ * host that traces its own every call prints thousands a second.
+ */
+export type DebugChannelMessage =
+ | { t: 'hello'; v: number; platform: string; title: string; project: string | null; revision: string | null }
+ | { t: 'reply'; reqId: number; data: unknown; pixels?: number }
+ | { t: 'reply'; reqId: number; error: string }
+ | { t: 'logs'; entries: Array<{ level: ConsoleLevel; line: string }> };
diff --git a/sdk/src/runtime/miniGameRuntime.ts b/sdk/src/runtime/miniGameRuntime.ts
index 787b96f30..e39a762b6 100644
--- a/sdk/src/runtime/miniGameRuntime.ts
+++ b/sdk/src/runtime/miniGameRuntime.ts
@@ -31,7 +31,8 @@ import { createMiniGameSideModuleHost, type MiniGameSideModuleFactories } from '
import type { Physics2DPluginConfig } from '../physics/PhysicsTypes';
import type { SceneData } from '../scene/scene';
import type { AotManifest } from '../ecs/aot/AotSystems';
-import { startDebugChannel, type DebugChannelConfig } from './debugChannel';
+import { startDebugChannel } from './debugChannelHook';
+import type { DebugChannelConfig } from './debugChannelProtocol';
import type { PackagedGameConfig } from './packagedRuntime';
import { log } from '../util/logger';
import { Schedule, defineSystem } from '../ecs/system';
diff --git a/sdk/src/runtime/nativeGameRuntime.ts b/sdk/src/runtime/nativeGameRuntime.ts
index 924d5d51e..a6e809549 100644
--- a/sdk/src/runtime/nativeGameRuntime.ts
+++ b/sdk/src/runtime/nativeGameRuntime.ts
@@ -15,7 +15,7 @@
* before the async boot settles).
*/
-import { startDebugChannel } from './debugChannel';
+import { startDebugChannel } from './debugChannelHook';
import type { App } from '../app/app';
import { initRuntime } from './runtimeLoader';
import { createNativeApp } from '../ecs/bridge/nativeRuntime';
diff --git a/sdk/src/runtime/optionalPlugins.ts b/sdk/src/runtime/optionalPlugins.ts
index 235074384..59868f4de 100644
--- a/sdk/src/runtime/optionalPlugins.ts
+++ b/sdk/src/runtime/optionalPlugins.ts
@@ -24,6 +24,7 @@ import { registerScriptGraphSupport } from '../logic/logicSupport';
import { registerAiSupport } from '../ai/aiSupport';
import { registerReplicationSupport } from '../net/replication/replicationSupport';
import { registerGameplaySupport } from '../gameplay/gameplaySupport';
+import { registerDebugChannelSupport } from '../debug-channel/debugChannelSupport';
export function installOptionalPlugins(): void {
registerSpineSupport();
@@ -35,6 +36,7 @@ export function installOptionalPlugins(): void {
registerAiSupport();
registerReplicationSupport();
registerGameplaySupport();
+ registerDebugChannelSupport();
// Video has no subpath of its own to be installed from, so it registers here.
setSceneOptionals({
video: {
diff --git a/sdk/src/runtime/packagedRuntime.ts b/sdk/src/runtime/packagedRuntime.ts
index c9ff39029..142343f1c 100644
--- a/sdk/src/runtime/packagedRuntime.ts
+++ b/sdk/src/runtime/packagedRuntime.ts
@@ -12,7 +12,7 @@
* the bytes arrive, so the same code serves both realms.
*/
-import type { DebugChannelConfig } from './debugChannel';
+import type { DebugChannelConfig } from './debugChannelProtocol';
import { extractUuid } from '../asset/AssetRegistry';
import { platformReadTextFile, platformLoadImagePixels } from '../platform';
import { ManifestModel, type AddressableManifest } from '../asset/AddressableManifest';
diff --git a/sdk/src/runtime/runtimeLoader.ts b/sdk/src/runtime/runtimeLoader.ts
index ece2aa59a..3e534780e 100644
--- a/sdk/src/runtime/runtimeLoader.ts
+++ b/sdk/src/runtime/runtimeLoader.ts
@@ -44,7 +44,8 @@ import { flushPendingRegistrations } from '../app/app';
import { installHotUpdateRebind } from '../hotUpdateRebind';
import { requireResourceManager } from '../wasm/resourceManager';
import { log } from '../util/logger';
-import { startDebugChannel, attachDebugChannel, type DebugChannelConfig } from './debugChannel';
+import { startDebugChannel, attachDebugChannel } from './debugChannelHook';
+import type { DebugChannelConfig } from './debugChannelProtocol';
import type { AotManifest } from '../ecs/aot/AotSystems';
import { type RuntimeAssetSource, type TextureParams } from './runtimeAssets';
import type { SpineAssetInfo } from '../spine/loadSpineScene';
diff --git a/tools/apiSubsystems.mjs b/tools/apiSubsystems.mjs
index 9f6ffa3db..4c167a297 100644
--- a/tools/apiSubsystems.mjs
+++ b/tools/apiSubsystems.mjs
@@ -26,6 +26,7 @@
* subsystem cannot be mistaken for adding plumbing.
*/
export const INFRASTRUCTURE = {
+ 'debug-channel': 'a development build\'s line back to the editor — tooling, never in a shipped game',
diagnostics: 'the engine reporting on itself — a census and a stats overlay, read by tooling',
document: 'document-model diagnostics shared with the editor, not part of a game',
platform: 'the PlatformAdapter implementations; a game meets these through the subsystems above',
diff --git a/tools/check-entry-boots.mjs b/tools/check-entry-boots.mjs
index 2ba06fb78..8db9e8e07 100644
--- a/tools/check-entry-boots.mjs
+++ b/tools/check-entry-boots.mjs
@@ -17,7 +17,7 @@
* node tools/check-entry-boots.mjs
*/
import { spawnSync } from 'node:child_process';
-import { mkdtempSync, mkdirSync, rmSync, symlinkSync, writeFileSync, existsSync } from 'node:fs';
+import { mkdtempSync, mkdirSync, rmSync, symlinkSync, writeFileSync, existsSync, readFileSync } from 'node:fs';
import { tmpdir } from 'node:os';
import path from 'node:path';
import { fileURLToPath } from 'node:url';
@@ -98,5 +98,37 @@ for (const [first, second] of [['esengine', 'esengine/node'], ['esengine/node',
results.push(`${first}+${second} → ${got}`);
}
+// The debug channel reaches a package only through its subpath, which a
+// development export imports: a lean shipping bundle must neither carry it nor
+// find it, and one that imports the subpath must have it installed.
+const NO_CHANNEL = 'packaged without esengine/debug-channel';
+for (const c of [
+ { name: 'lean', imports: [], installed: false },
+ { name: 'lean+channel', imports: ['esengine/debug-channel'], installed: true },
+ { name: 'full', imports: [], entry: 'esengine', installed: true },
+]) {
+ const src = path.join(work, `channel-${c.name.replace(/\W+/g, '-')}.mjs`);
+ const out = `${src}.bundle.mjs`;
+ const entry = c.entry ?? 'esengine/lean';
+ writeFileSync(src, c.imports.map((m) => `import ${JSON.stringify(m)};\n`).join('')
+ + `import { startDebugChannel } from ${JSON.stringify(entry)};\n`
+ + `startDebugChannel({ url: 'ws://127.0.0.1:9/?token=t' });\n`
+ + `setTimeout(() => process.exit(0), 50);\n`);
+ await build({
+ entryPoints: [src], outfile: out, bundle: true, format: 'esm', platform: 'node', logLevel: 'silent',
+ alias: { 'esengine/lean': path.join(SDK, 'dist/index.lean.js') },
+ });
+ const run = spawnSync(process.execPath, [out], { encoding: 'utf8' });
+ const said = `${run.stdout ?? ''}${run.stderr ?? ''}`;
+ const carried = readFileSync(out, 'utf8').includes('draws no frames');
+ if (c.installed === said.includes(NO_CHANNEL) || c.installed !== carried) {
+ fail(`${c.name}: the debug channel ${c.installed ? 'should be installed' : 'should be absent'}, `
+ + `but the bundle ${carried ? 'carries' : 'lacks'} it and starting it ${said.includes(NO_CHANNEL) ? 'found none' : 'found one'}.`
+ + '\n\nThe subpath installs it with a call (debug-channel/index.ts); the full entries call the'
+ + ' same registration; the lean entries must not.');
+ }
+ results.push(`${c.name} channel → ${c.installed ? 'installed' : 'absent'}`);
+}
+
rmSync(work, { recursive: true, force: true, maxRetries: 10, retryDelay: 50 });
console.log(`check-entry-boots: ${results.length} case(s) bundled and run — ${results.join(', ')}.`);
diff --git a/tools/lib/sdkProgram.mjs b/tools/lib/sdkProgram.mjs
index 68a75fb50..498c9a8f8 100644
--- a/tools/lib/sdkProgram.mjs
+++ b/tools/lib/sdkProgram.mjs
@@ -60,6 +60,7 @@ export const ENTRIES = {
'dragonbones': 'src/dragonbones/index.ts',
'tilemap': 'src/tilemap/index.ts',
'logic': 'src/logic/index.ts',
+ 'debug-channel': 'src/debug-channel/index.ts',
'ai': 'src/ai/index.ts',
'replication': 'src/net/replication/index.ts',
'gameplay': 'src/gameplay/index.ts',
diff --git a/tools/nativeScriptModules.js b/tools/nativeScriptModules.js
index 33f907c56..354e62bfd 100644
--- a/tools/nativeScriptModules.js
+++ b/tools/nativeScriptModules.js
@@ -74,6 +74,10 @@ export const MODULES = {
disposition: 'forbidden-native-script',
why: 'the SDK entry the host itself evaluated — a game script importing it is asking for a second copy of the thing already running',
},
+ 'esengine/debug-channel': {
+ disposition: 'forbidden-native-script',
+ why: 'a development export adds it to a web or mini-game package; a native host has no socket for it, and a game script has no reason to import it',
+ },
'esengine/wasm': {
disposition: 'forbidden-native-script',
why: 'the emscripten module surface; a native build embeds Dawn and QuickJS and has no such module',
diff --git a/tools/releaseNotes.mjs b/tools/releaseNotes.mjs
index d0223c136..545382832 100644
--- a/tools/releaseNotes.mjs
+++ b/tools/releaseNotes.mjs
@@ -1108,4 +1108,6 @@ export const NOTED = {
{ note: 'Connected development builds are named by the device they run on — `web (Chrome · Android)`, a phone\'s model on a mini-game — and numbered when two read alike, in the Profiler, Outliner, Frame Debugger and `device_targets`.' },
'feat(debug): connected builds are named by the device they run on':
{ note: 'Connected development builds are named by the device they run on — `web (Chrome · Android)`, a phone\'s model on a mini-game — and numbered when two read alike, in the Profiler, Outliner, Frame Debugger and `device_targets`.' },
+ 'fix(debug): a shipping package no longer carries the debug channel':
+ { note: 'A shipping package no longer carries the development debug channel\'s code (13 KB on a WeChat package): only a development export that names an editor imports it, as `esengine/debug-channel`.' },
};