fix(tier2): build-phaser 从 cwd(game-runtime) 解析 esbuild
裸 import('esbuild') 按模块位置(tier2/engine/)解析,找不到 game-runtime/node_modules 的 esbuild。改:裸 import 失败则从 cwd(集成段总是 cd game-runtime)createRequire 解析。
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
parent
856a583325
commit
b5acf7c4b5
@ -29,6 +29,8 @@
|
||||
|
||||
import { argv, exit } from 'node:process';
|
||||
import { join, isAbsolute, resolve } from 'node:path';
|
||||
import { createRequire } from 'node:module';
|
||||
import { pathToFileURL } from 'node:url';
|
||||
|
||||
/** tier2 锁定构建参数(与 A3 buildProfile 对齐;spike 期可调,第二引擎落地后固化)。 */
|
||||
export const TIER2_BUILD_OPTIONS = {
|
||||
@ -54,8 +56,16 @@ export const TIER2_BUILD_OPTIONS = {
|
||||
export async function buildPhaserProject(projectDir, opts = {}) {
|
||||
let esbuild;
|
||||
try {
|
||||
// 动态 import:仅集成段装了 esbuild 才解析得到;本机解析失败走下方指引。
|
||||
esbuild = await import('esbuild');
|
||||
// 动态 import esbuild。本脚本在 tier2/engine/ 下,裸 import('esbuild') 按"模块位置"解析,
|
||||
// 找不到 game-runtime/node_modules(构建依赖按 wg1 惯例装在 game-runtime)。
|
||||
// 故:先裸 import(repo 根/tier2 装了才命中),失败再从 cwd 解析——集成段(smoke/run.py)总是
|
||||
// 先 cd 到 game-runtime 再调本脚本,cwd 即 game-runtime、esbuild 在其 node_modules 下。
|
||||
try {
|
||||
esbuild = await import('esbuild');
|
||||
} catch {
|
||||
const requireFromCwd = createRequire(join(process.cwd(), 'package.json'));
|
||||
esbuild = await import(pathToFileURL(requireFromCwd.resolve('esbuild')).href);
|
||||
}
|
||||
} catch {
|
||||
const msg =
|
||||
'[build-phaser] 未找到 esbuild —— 本脚本仅在集成段(mini-desktop)运行。\n' +
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user