zizi f59991b9f3 feat(game-runtime): T1b-α Gate0 七件落地(core-protocol-v0-rc)
- core 协议:Plugin 接口/注册器(重名拒绝/生命周期正序逆序/dispose幂等/错误隔离不连坐)+受控面 PluginContext(禁直透 littlejsengine)——前任agent核心设计17测绿收编(死于收尾的工具调用解析失败,续作字节级未碰)
- _example 空插件样例五件全(克隆母本)+PLUGIN-TEMPLATE 六节规格+manifest schema+零依赖校验器(负例自检逮6违规)
- scripts:esbuild锁参build/增量法size/test.sh遍历;browser-evidence harness纯计算口径冻结(FNV-1a/直方图/几何,CDP四函数=集成段占位)
- 22/22 测全绿(RESULT.txt 留档);ESM JS+JSDoc+手写d.ts 零工具链纪律全程
- rc 状态:待 Gate0.1 受控面补丁(input/audio+per-plugin派生RNG+useContext守卫)后冻结 core-protocol-v0

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
2026-06-12 11:10:12 +00:00

76 lines
3.2 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

/**
* scripts/build.mjs — LittleJS 增强发行版打包脚本esbuild 锁参core-protocol-v0
*
* ⚠️ 运行环境纪律(执行版 §1/§5
* **本脚本仅在「集成段mini-desktop」运行**,不在 lane 本机跑。lane 阶段一切测试 =
* 零依赖 `node --test`esbuild 是工具链依赖(需 `npm i -D esbuild`),只在 mini-desktop 装与跑。
* 在无 esbuild 的本机执行本脚本会**显式报错并给出安装指引**(不静默失败)。
*
* 锁定参数§5不得擅改 —— 改动影响 SIZES 口径与 channel-spike 对照):
* bundle + minify + format=iife + target=es2019 + sourcemap=false
*
* 用法(集成段):
* node scripts/build.mjs <入口.js> <输出.js> [--global-name=NAME]
* 例node scripts/build.mjs src/core/plugin.js dist/core.iife.js --global-name=GameRuntimeCore
*/
'use strict';
import { argv, exit } from 'node:process';
/** 锁定的 esbuild 构建参数§5 写死,集成段与 size.mjs 必须同口径)。 */
export const LOCKED_BUILD_OPTIONS = {
bundle: true,
minify: true,
format: 'iife',
target: 'es2019',
sourcemap: false,
// legalComments:'none' 去掉许可证注释,保证 minify 后字节口径稳定(不影响合规,许可证在仓内 LICENSE 留存)。
legalComments: 'none',
};
/**
* 用锁定参数构建单个入口。集成段调用;本机无 esbuild 时抛错给指引。
* @param {string} entry 入口文件路径
* @param {string} outfile 输出文件路径
* @param {string} [globalName] iife 全局变量名(可选)
* @returns {Promise<void>}
*/
export async function build(entry, outfile, globalName) {
let esbuild;
try {
// 动态 import仅集成段装了 esbuild 才解析得到;本机解析失败走下方指引。
esbuild = await import('esbuild');
} catch {
console.error(
'[build] 未找到 esbuild —— 本脚本仅在集成段mini-desktop运行。\n' +
' 请在集成段执行npm i -D esbuild再重跑本脚本。\n' +
' lane 本机请勿运行构建(纪律:本机零依赖、只跑 node --test。'
);
throw new Error('esbuild 不可用(非集成段环境)');
}
await esbuild.build({
...LOCKED_BUILD_OPTIONS,
entryPoints: [entry],
outfile,
...(globalName ? { globalName } : {}),
});
console.log(`[build] OK ${entry}${outfile} (iife/es2019/min/no-sourcemap)`);
}
// ── CLI 入口(仅集成段使用)──────────────────────────────────────────────────
// 仅当作为脚本直接运行时执行 CLI被 import如 size.mjs 复用 LOCKED_BUILD_OPTIONS时不触发。
if (import.meta.url === `file://${argv[1]}`) {
const [entry, outfile, ...rest] = argv.slice(2);
if (!entry || !outfile) {
console.error('用法node scripts/build.mjs <入口.js> <输出.js> [--global-name=NAME]');
exit(1);
}
const gn = (rest.find((a) => a.startsWith('--global-name=')) || '').split('=')[1];
build(entry, outfile, gn).catch((e) => {
console.error('[build] 失败:' + (e && e.message ? e.message : e));
exit(1);
});
}