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.
TypeScript 2d-game-engine3d3d-game-engineandroidcppecsgame-editorgame-enginegamedeviostypescriptwebassemblywebglwebgpuwechat-minigame
fix(editor): mirror SDK types into .esengine/sdk on project open
yhh58258d261148
diff --git a/desktop/electron/main.ts b/desktop/electron/main.tsindex 1d59517f9..9fc0da33b 100644--- a/desktop/electron/main.ts+++ b/desktop/electron/main.ts@@ -29,6 +29,7 @@ import { startProjectWatch, stopProjectWatch } from './projectWatcher';import { importAssets, createAsset, IMPORT_EXTENSIONS } from './importAssets';import { exportGame } from './exportGame';import { buildPlayRealm } from './buildPlayRealm';+import { syncSdkTypes } from './syncSdkTypes';import { resolveScripts } from '../src/project/format';import type { WorkspaceState } from '../src/project/format';@@ -250,10 +251,16 @@ const requireRoot = (): string => {};// Adopt a freshly opened project as the active root + (re)start the fs watcher-// so on-disk changes push to the renderer.-function adoptRoot(root: string): void {+// so on-disk changes push to the renderer, and mirror the SDK types into+// .esengine/sdk so the project's tsconfig resolves `esengine` in the IDE.+async function adoptRoot(root: string): Promise<void> {projectRoot = root;if (win) startProjectWatch(root, win.webContents);+ try {+ await syncSdkTypes(root, path.join(process.env.APP_ROOT!, 'node_modules', 'esengine', 'dist'));+ } catch (err) {+ console.warn('[sdk-types] mirror failed:', err);+ }}ipcMain.handle('project:openDialog', async () => {@@ -264,13 +271,13 @@ ipcMain.handle('project:openDialog', async () => {});if (res.canceled || res.filePaths.length === 0) return null;const opened = await openProject(res.filePaths[0]);- adoptRoot(opened.root);+ await adoptRoot(opened.root);return opened;});ipcMain.handle('project:open', async (_e, root: string) => {const opened = await openProject(root);- adoptRoot(opened.root);+ await adoptRoot(opened.root);return opened;});diff --git a/desktop/electron/syncSdkTypes.ts b/desktop/electron/syncSdkTypes.tsnew file mode 100644index 000000000..3a6449a32--- /dev/null+++ b/desktop/electron/syncSdkTypes.ts@@ -0,0 +1,32 @@+// SPDX-License-Identifier: Apache-2.0+// SPDX-FileCopyrightText: Copyright (c) 2024-present ESEngine Team+/**+ * @file Mirror the SDK's type declarations into a project's `.esengine/sdk` so+ * its tsconfig (`esengine` → ./.esengine/sdk/index.d.ts) resolves in the+ * IDE the moment the project is opened — before it is ever played. Types+ * only; the play runtime (js + wasm) is staged separately under+ * `.esengine/play` by buildPlayRealm.+ */+import { cp, mkdir, readdir } from 'node:fs/promises';+import { existsSync } from 'node:fs';+import path from 'node:path';++/** Copy every `*.d.ts` under `sdkDistDir` into `<root>/.esengine/sdk`, preserving+ * the directory layout so index.d.ts's chunk imports (shared/, physics/, spine/)+ * resolve. Overwrites, so a newer SDK refreshes the mirror on the next open. */+export async function syncSdkTypes(root: string, sdkDistDir: string): Promise<void> {+ if (!existsSync(sdkDistDir)) return;+ await copyDeclarations(sdkDistDir, path.join(root, '.esengine', 'sdk'));+}++async function copyDeclarations(src: string, dst: string): Promise<void> {+ let made = false;+ for (const entry of await readdir(src, { withFileTypes: true })) {+ if (entry.isDirectory()) {+ await copyDeclarations(path.join(src, entry.name), path.join(dst, entry.name));+ } else if (entry.name.endsWith('.d.ts')) {+ if (!made) { await mkdir(dst, { recursive: true }); made = true; }+ await cp(path.join(src, entry.name), path.join(dst, entry.name));+ }+ }+}