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.

feat(tooling): the examples type-check the official packages the way a project does

esengine617a061a2b1a
diff --git a/.gitignore b/.gitignore
index 145ab6b99..8228d41d2 100644
--- a/.gitignore
+++ b/.gitignore
@@ -145,6 +145,7 @@ docs/local/
**/.esengine/cache/
**/.esengine/play/
**/.esengine/sdk/
+**/.esengine/packages/
**/.esengine/editor/
# Crash-recovery snapshots (electron/autosave.ts): a copy of unsaved edits, so a
# committed one is somebody's interrupted session, never the scene of record.
diff --git a/build-tools/tasks/check-examples.js b/build-tools/tasks/check-examples.js
index 0c9106943..38897a830 100644
--- a/build-tools/tasks/check-examples.js
+++ b/build-tools/tasks/check-examples.js
@@ -48,6 +48,7 @@ function setupTypeLinks(exampleDir, rootDir) {
const esengineDir = path.join(exampleDir, '.esengine');
const sdkLink = path.join(esengineDir, 'sdk');
const editorLink = path.join(esengineDir, 'editor');
+ const packagesLink = path.join(esengineDir, 'packages');
mkdirSync(esengineDir, { recursive: true });
@@ -59,6 +60,11 @@ function setupTypeLinks(exampleDir, rootDir) {
rmSync(sdkLink, { recursive: true, force: true, maxRetries: 10, retryDelay: 50 });
symlinkSync(sdkDist, sdkLink, LINK_TYPE);
+ // What the editor mirrors on open: the official packages, which a project's
+ // tsconfig maps as `estella-plugin-*` → ./.esengine/packages/*.
+ rmSync(packagesLink, { recursive: true, force: true, maxRetries: 10, retryDelay: 50 });
+ symlinkSync(path.join(rootDir, 'plugins'), packagesLink, LINK_TYPE);
+
if (existsSync(editorDist)) {
rmSync(editorLink, { recursive: true, force: true, maxRetries: 10, retryDelay: 50 });
symlinkSync(editorDist, editorLink, LINK_TYPE);
@@ -72,8 +78,10 @@ function isSymlinkOrExists(p) {
function cleanTypeLinks(exampleDir) {
const sdkLink = path.join(exampleDir, '.esengine', 'sdk');
const editorLink = path.join(exampleDir, '.esengine', 'editor');
+ const packagesLink = path.join(exampleDir, '.esengine', 'packages');
try { if (isSymlinkOrExists(sdkLink)) unlinkSync(sdkLink); } catch {}
+ try { if (isSymlinkOrExists(packagesLink)) unlinkSync(packagesLink); } catch {}
try { if (isSymlinkOrExists(editorLink)) unlinkSync(editorLink); } catch {}
}
diff --git a/desktop b/desktop
index f4428e854..bb9bb1a05 160000
--- a/desktop
+++ b/desktop
@@ -1 +1 @@
-Subproject commit f4428e854a72836bf5e1c0483274a3d5927f0992
+Subproject commit bb9bb1a0561be6c6992879f80d71b3ae63d731f9
diff --git a/pipeline/src/bundle/officialPackages.ts b/pipeline/src/bundle/officialPackages.ts
index 57c8668ad..b32ff3653 100644
--- a/pipeline/src/bundle/officialPackages.ts
+++ b/pipeline/src/bundle/officialPackages.ts
@@ -15,15 +15,23 @@ import type { Plugin } from 'esbuild';
const OFFICIAL = /^(estella-plugin-[^/]+)(\/.+)?$/;
-/** A package name → its export subpath ('.', './open-data') → absolute entry file. */
-export type OfficialPackages = ReadonlyMap<string, ReadonlyMap<string, string>>;
+export interface OfficialPackage {
+ /** The package's directory under the shipped `plugins/`. */
+ readonly dir: string;
+ /** Export subpath ('.', './open-data') → absolute entry file. Empty for an
+ * editor-only plugin, which a game has nothing to import from. */
+ readonly exports: ReadonlyMap<string, string>;
+}
+
+/** Package name → package. */
+export type OfficialPackages = ReadonlyMap<string, OfficialPackage>;
const cache = new Map<string, OfficialPackages>();
export function readOfficialPackages(packagesDir: string): OfficialPackages {
const hit = cache.get(packagesDir);
if (hit) return hit;
- const out = new Map<string, Map<string, string>>();
+ const out = new Map<string, OfficialPackage>();
const entries = existsSync(packagesDir) ? readdirSync(packagesDir, { withFileTypes: true }) : [];
for (const entry of entries) {
if (!entry.isDirectory()) continue;
@@ -38,7 +46,7 @@ export function readOfficialPackages(packagesDir: string): OfficialPackages {
: pkg.exports ?? (pkg.main ? { '.': pkg.main } : {});
const subpaths = new Map<string, string>();
for (const [sub, rel] of Object.entries(exportsMap)) subpaths.set(sub, path.join(dir, rel));
- out.set(pkg.name, subpaths);
+ out.set(pkg.name, { dir, exports: subpaths });
}
cache.set(packagesDir, out);
return out;
@@ -61,7 +69,7 @@ export function officialPackagesPlugin(packagesDir: string): Plugin {
const [, name, rest] = OFFICIAL.exec(args.path)!;
const packages = readOfficialPackages(packagesDir);
- const subpaths = packages.get(name);
+ const subpaths = packages.get(name)?.exports;
if (!subpaths) {
return { errors: [{ text: `"${name}" is not one of the packages the editor ships (${[...packages.keys()].join(', ') || 'none found'}), and the project has not installed it` }] };
}
diff --git a/templates/wechat-minigame/tsconfig.json b/templates/wechat-minigame/tsconfig.json
index 1f11ff310..86043684a 100644
--- a/templates/wechat-minigame/tsconfig.json
+++ b/templates/wechat-minigame/tsconfig.json
@@ -12,7 +12,8 @@
"rootDir": ".",
"paths": {
"esengine": ["./.esengine/sdk/index.d.ts"],
- "esengine/wasm": ["./.esengine/sdk/wasm.d.ts"]
+ "esengine/wasm": ["./.esengine/sdk/wasm.d.ts"],
+ "estella-plugin-*": ["./.esengine/packages/*"]
}
},
"include": ["src/**/*"],