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(project): a build target can answer differently about a module

esengine7dc1c6bcc805
diff --git a/pipeline/src/bundle/engineInstalls.ts b/pipeline/src/bundle/engineInstalls.ts
index 3b987ce1a..5ef24d5d6 100644
--- a/pipeline/src/bundle/engineInstalls.ts
+++ b/pipeline/src/bundle/engineInstalls.ts
@@ -41,14 +41,19 @@ const SIDE_MODULE_SUBPATH: Readonly<Record<string, string>> = {
* module is installed from, and absorbing the older `features.physics.enabled`,
* which was this for one module: a way to name what only a script reaches.
*/
-export function moduleChoices(features: ProjectFeatures | undefined): Readonly<Record<string, ModuleChoice>> {
+export function moduleChoices(
+ features: ProjectFeatures | undefined,
+ /** Per-target overrides, laid over the project's own — one target's limits
+ * are not another's. Omit for the project-wide answer. */
+ perPlatform?: Readonly<Record<string, ModuleChoice>>,
+): Readonly<Record<string, ModuleChoice>> {
const out: Record<string, ModuleChoice> = { ...(features?.modules ?? {}) };
// The old field, and only where the new one is silent: a project that says
// both means the one it was last edited with.
if (features?.physics?.enabled && out['esengine/physics'] === undefined) {
out['esengine/physics'] = 'include';
}
- return out;
+ return { ...out, ...(perPlatform ?? {}) };
}
/** A module the project refused that its own content uses. */
diff --git a/pipeline/src/export/exportGame.ts b/pipeline/src/export/exportGame.ts
index 6282d642a..4b0777ddd 100644
--- a/pipeline/src/export/exportGame.ts
+++ b/pipeline/src/export/exportGame.ts
@@ -63,7 +63,7 @@ import { assembleDesktopApp } from '../../../build-tools/utils/desktopApp.js';
import { emitSteamBuild, defaultDepotId } from '../../../build-tools/utils/steamChannel.js';
import { debugSigningKey, type SigningKey } from '../../../build-tools/utils/androidKeystore.js';
import { compileTargetFor, isNativePlatform, desktopTemplateFor, type DesktopOs, type ExportPlatform } from '../project/platforms';
-import type { DesktopPackaging, ProjectFeatures, SteamPackaging } from '../project/format';
+import type { DesktopPackaging, ProjectFeatures, ProjectPackaging, SteamPackaging } from '../project/format';
import type { SizeBudget } from '../project/sizeBudget';
import { measureBuild, type BuildSizeReport } from './sizeReport';
import { sizeSettingsOf } from './sizeHistory';
@@ -415,6 +415,8 @@ export interface ExportGameOptions {
/** What the project says about its engine modules (`ProjectFeatures.modules`).
* Absent ⇒ every module is `auto`, which is what detection alone gives. */
features?: ProjectFeatures;
+ /** Per-target overrides laid over those; one target's limits are not another's. */
+ modulesByPlatform?: ProjectPackaging['modulesByPlatform'];
/** Desktop product/display name (Project Settings); default the project title. */
desktopProductName?: string;
/**
@@ -632,6 +634,7 @@ async function produceExport(opts: ExportGameOptions): Promise<ExportGameResult>
title,
appid: opts.miniGameAppid,
features: opts.features,
+ modulesByPlatform: opts.modulesByPlatform,
orientation,
runtime,
minify: opts.minify,
@@ -665,6 +668,7 @@ async function produceExport(opts: ExportGameOptions): Promise<ExportGameResult>
title,
appid: opts.miniGameAppid,
features: opts.features,
+ modulesByPlatform: opts.modulesByPlatform,
orientation,
runtime,
minify: opts.minify,
@@ -852,7 +856,7 @@ async function produceExport(opts: ExportGameOptions): Promise<ExportGameResult>
assetPaths: cook.includedPaths,
sideModuleIds,
scriptImports,
- choices: moduleChoices(opts.features),
+ choices: moduleChoices(opts.features, opts.modulesByPlatform?.[platform]),
});
// 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 d74d35bb7..b26784d3e 100644
--- a/pipeline/src/export/exportMiniGame.ts
+++ b/pipeline/src/export/exportMiniGame.ts
@@ -29,7 +29,7 @@
* own path. Pure Node (esbuild + fs) — IPC wiring is in main.ts.
*/
import { loadEsbuild } from '../bundle/esbuildRuntime';
-import type { ProjectFeatures } from '../project/format';
+import type { ProjectFeatures, ProjectPackaging } from '../project/format';
import {
DEFAULT_RUNTIME_CONFIG, packagedRuntimeFields, type RuntimeProjectConfig,
} from '../project/runtimeConfig';
@@ -276,6 +276,8 @@ export async function exportMiniGame(profile: MiniGameExportProfile, opts: {
engineSubpackage?: boolean;
/** What the project says about its engine modules; see ProjectFeatures.modules. */
features?: ProjectFeatures;
+ /** Per-target overrides laid over those. */
+ modulesByPlatform?: ProjectPackaging['modulesByPlatform'];
onProgress?: OnExportProgress;
}): Promise<ExportMiniGameResult> {
const title = opts.title ?? 'Game';
@@ -468,7 +470,7 @@ export async function exportMiniGame(profile: MiniGameExportProfile, opts: {
subsystems: usedSubsystems.keys(),
assetPaths: cook.includedPaths,
sideModuleIds: sideModules.map((m) => m.id),
- choices: moduleChoices(opts.features),
+ choices: moduleChoices(opts.features, opts.modulesByPlatform?.[profile.id]),
});
// 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/sizeHistory.ts b/pipeline/src/export/sizeHistory.ts
index 9fb6ad65d..d0717029f 100644
--- a/pipeline/src/export/sizeHistory.ts
+++ b/pipeline/src/export/sizeHistory.ts
@@ -56,6 +56,7 @@ export const PACKAGING_SIZE_ROLE: Readonly<Record<string, keyof SizeSettings | '
compressWasm: 'compressWasm',
engineSubpackage: 'engineSubpackage',
excludeScenes: 'content',
+ modulesByPlatform: 'content',
outDir: 'inert',
sizeBudget: 'inert',
appId: 'inert',
diff --git a/pipeline/src/project/format.ts b/pipeline/src/project/format.ts
index ba6b31bd6..022eb95cd 100644
--- a/pipeline/src/project/format.ts
+++ b/pipeline/src/project/format.ts
@@ -340,6 +340,12 @@ export interface ProjectPackaging {
* `sizeBudget.ts`).
*/
sizeBudget?: Partial<Record<ExportPlatform, number>>;
+ /**
+ * Per-target module overrides, laid over `features.modules`. One target's
+ * limits are not another's — a playable ad has a size cap a web build does
+ * not, and refusing 3D physics there should not refuse it everywhere.
+ */
+ modulesByPlatform?: Partial<Record<ExportPlatform, Record<string, ModuleChoice>>>;
/**
* The application identifier (reverse-DNS) every installable target needs: the
* Android manifest package, the iOS bundle id, the Electron appId. One project
@@ -739,6 +745,18 @@ export function parseManifest(raw: unknown): ProjectManifest {
}
if (Object.keys(budgets).length > 0) pkg.sizeBudget = budgets;
}
+ if (p.modulesByPlatform && typeof p.modulesByPlatform === 'object') {
+ const byPlatform: NonNullable<ProjectPackaging['modulesByPlatform']> = {};
+ for (const [platform, v] of Object.entries(p.modulesByPlatform as Record<string, unknown>)) {
+ if (!v || typeof v !== 'object') continue;
+ const modules: Record<string, ModuleChoice> = {};
+ for (const [id, choice] of Object.entries(v as Record<string, unknown>)) {
+ if (choice === 'include' || choice === 'exclude') modules[id] = choice;
+ }
+ if (Object.keys(modules).length > 0) byPlatform[normalizePlatform(platform)] = modules;
+ }
+ if (Object.keys(byPlatform).length > 0) pkg.modulesByPlatform = byPlatform;
+ }
// Deduplicated and trimmed: a store keys achievements by this string, so a
// stray blank or a repeat is a row that can never match one.
if (Array.isArray(p.achievements)) {
diff --git a/pipeline/src/project/runtimeConfig.ts b/pipeline/src/project/runtimeConfig.ts
index 970120a4a..fcbac046f 100644
--- a/pipeline/src/project/runtimeConfig.ts
+++ b/pipeline/src/project/runtimeConfig.ts
@@ -27,7 +27,7 @@
* or is not listed there as a declared, reasoned gap.
*/
import type { AudioProjectConfig, PackagedGameConfig, Physics2DPluginConfig } from 'esengine';
-import { resolveScreenFit, SORTING_LAYER_COUNT, type ProjectFeatures, type ProjectManifest } from './format';
+import { resolveScreenFit, SORTING_LAYER_COUNT, type ProjectFeatures, type ProjectManifest, type ProjectPackaging } from './format';
/** The project's camera fit as a runtime takes it (`scaleMode < 0` ⇒ off). */
export interface RuntimeScreenFit {
@@ -239,6 +239,8 @@ export function cookOptionsOf(manifest: Pick<ProjectManifest, 'packaging'>): Coo
export interface PackagingOptions {
/** What the project says about its engine modules; see ProjectFeatures.modules. */
features: ProjectFeatures | undefined;
+ /** Per-target overrides laid over those. */
+ modulesByPlatform: ProjectPackaging['modulesByPlatform'];
compressWasm: boolean;
engineSubpackage: boolean;
excludeScenes: string[];
@@ -253,6 +255,7 @@ export function packagingOptionsOf(manifest: Pick<ProjectManifest, 'packaging' |
// options because every caller already spreads those — a second place to
// remember is a place one caller forgets.
features: manifest.features,
+ modulesByPlatform: p?.modulesByPlatform,
compressWasm: p?.compressWasm ?? false,
engineSubpackage: p?.engineSubpackage ?? false,
excludeScenes: p?.excludeScenes ?? [],
diff --git a/pipeline/tests/engine-installs.test.ts b/pipeline/tests/engine-installs.test.ts
index ab01ffcf6..f443a4529 100644
--- a/pipeline/tests/engine-installs.test.ts
+++ b/pipeline/tests/engine-installs.test.ts
@@ -189,3 +189,35 @@ describe('every module a project can refuse', () => {
expect(ENGINE_MODULES.filter((m) => !byComponent.has(m))).toEqual([]);
});
});
+
+/**
+ * One target's limits are not another's. A playable ad has a size cap a web
+ * build does not, so refusing 3D physics there must not refuse it everywhere —
+ * and forcing a module in for one target must not force it into the rest.
+ */
+describe('a project that answers differently per target', () => {
+ const project = { modules: { 'esengine/physics3d': 'include' } } as const;
+
+ it('uses the project-wide answer when the target said nothing', () => {
+ expect(moduleChoices(project)).toEqual({ 'esengine/physics3d': 'include' });
+ });
+
+ it('lets a target overrule the project for itself', () => {
+ expect(moduleChoices(project, { 'esengine/physics3d': 'exclude' }))
+ .toEqual({ 'esengine/physics3d': 'exclude' });
+ });
+
+ it('leaves the modules that target did not mention alone', () => {
+ expect(moduleChoices(
+ { modules: { 'esengine/ai': 'exclude', 'esengine/physics3d': 'include' } },
+ { 'esengine/physics3d': 'exclude' },
+ )).toEqual({ 'esengine/ai': 'exclude', 'esengine/physics3d': 'exclude' });
+ });
+
+ it('refuses on the target that excluded it and builds on the one that did not', () => {
+ const used = { subsystems: ['physics3d'] } as const;
+ expect(engineInstalls({ ...used, choices: moduleChoices(project) }).refused).toEqual([]);
+ expect(engineInstalls({ ...used, choices: moduleChoices(project, { 'esengine/physics3d': 'exclude' }) })
+ .refused.map((r) => r.specifier)).toEqual(['esengine/physics3d']);
+ });
+});
diff --git a/pipeline/tests/packaging-settings-reach.test.ts b/pipeline/tests/packaging-settings-reach.test.ts
index fb0270ada..34a23eb40 100644
--- a/pipeline/tests/packaging-settings-reach.test.ts
+++ b/pipeline/tests/packaging-settings-reach.test.ts
@@ -76,3 +76,31 @@ describe('the modules a project declares', () => {
expect(packagingOptionsOf(m).features?.physics?.enabled).toBe(true);
});
});
+
+describe('the per-target module overrides', () => {
+ it('survive the parser, keyed by target', () => {
+ const m = parseManifest({
+ formatVersion: '1', name: 'p',
+ packaging: { modulesByPlatform: { playable: { 'esengine/physics3d': 'exclude' } } },
+ });
+ expect(m.packaging?.modulesByPlatform?.playable)
+ .toEqual({ 'esengine/physics3d': 'exclude' });
+ });
+
+ it('drop `auto`, as the project-wide ones do', () => {
+ const m = parseManifest({
+ formatVersion: '1', name: 'p',
+ packaging: { modulesByPlatform: { playable: { 'esengine/ai': 'auto' } } },
+ });
+ expect(m.packaging?.modulesByPlatform).toBeUndefined();
+ });
+
+ it('reach the export options every caller spreads', () => {
+ const m = parseManifest({
+ formatVersion: '1', name: 'p',
+ packaging: { modulesByPlatform: { wechat: { 'esengine/spine': 'exclude' } } },
+ });
+ expect(packagingOptionsOf(m).modulesByPlatform?.wechat)
+ .toEqual({ 'esengine/spine': 'exclude' });
+ });
+});