@bepack/cli 0.1.0-beta.1 → 0.1.0-beta.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -25,7 +25,9 @@ BePack is a build tool for Minecraft Bedrock add-ons. It keeps behavior-pack and
25
25
  - Create a BePack configuration from scratch or import it from existing manifests.
26
26
  - Keep `manifest.json` in sync without overwriting fields that BePack does not own.
27
27
  - Build a Behavior Pack's TypeScript Script API entry into its `scripts/` directory.
28
+ - Type-check that source with `tsc --noEmit` before bundling — **on by default**.
28
29
  - Inject build-time feature flags with `compile.define` (identifier-level, typecheck-safe) or `replace` tokens.
30
+ - Customize the Rolldown build with inline options, a function, or your own `rolldown.config.ts`.
29
31
  - Resolve supported `@minecraft/*` dependencies and write their concrete versions to your project.
30
32
  - Keep `manifest.json` in sync with a `preserve` (incremental) or `clean` (config-generated) merge strategy.
31
33
  - Copy packs into a Minecraft development folder and create release archives.
@@ -172,8 +174,42 @@ bepack install --target 1.21.120
172
174
  bepack build --install --target 1.21.120
173
175
  ```
174
176
 
177
+ > **Type checking runs by default.** Every `bepack build` and `bepack dev` executes `tsc --noEmit` before Rolldown bundles your source. A failing check stops the build with `TYPECHECK_FAILED` instead of emitting a broken pack. Skip it with `--skip-typecheck`, or set `packs.bp.compile.typecheck: false`. This is independent of any custom Rolldown options — adding them does **not** turn the type check off.
178
+
175
179
  `stable`, `beta`, `preview`, and exact versions can be used for the supported `@minecraft/*` dependency entries. BePack resolves selectors such as `stable` to concrete package versions before updating `package.json` and the BP manifest.
176
180
 
181
+ ## Customize the Rolldown build
182
+
183
+ `packs.bp.compile` covers the common cases. When you need the rest of Rolldown (extra plugins, `resolve.alias`, `treeshake`, `sourcemap`, ...), pass your own options inline, through a function, or through a config file:
184
+
185
+ ```ts
186
+ export default defineConfig({
187
+ // name, version, packs.bp.root, uuid, ... omitted
188
+ packs: {
189
+ bp: {
190
+ compile: {
191
+ entry: "src/main.ts",
192
+ // Object form, or a function (options, context) => options
193
+ rolldown: {
194
+ resolve: { alias: { "@lib": "./src/lib" } },
195
+ output: { sourcemap: true },
196
+ },
197
+ // Or a config file (relative to the project root):
198
+ // rolldownConfig: "rolldown.bp.config.ts",
199
+ },
200
+ },
201
+ },
202
+ });
203
+ ```
204
+
205
+ ```bash
206
+ # Temporarily replace the configured file
207
+ bepack build --rolldown-config rolldown.staging.mjs
208
+ bepack dev --rolldown-config rolldown.staging.mjs
209
+ ```
210
+
211
+ Your options are merged on top of the ones BePack generates: `plugins` are appended, `external` is unioned, and `transform` / `resolve` / `output` / `experimental` are merged one level deep. `input` and the output location fields stay under BePack's control and are rejected with `CONFIG_INVALID` if a customization tries to move them. Custom config files may be `.ts`, `.mts`, `.js`, or `.mjs` and must export a single configuration. See [the reference guide](./reference.md) for the full merge table and the list of protected fields.
212
+
177
213
  ## Run in Minecraft during development
178
214
 
179
215
  Configure a copy target once, then add `--copy` to `dev` or `build`:
@@ -232,18 +268,43 @@ bepack pack --name my-addon-preview
232
268
  | RP only | `.mcpack` |
233
269
  | BP and RP | `.mcaddon` |
234
270
 
271
+ ### Pack optimization (`__brarchive`)
272
+
273
+ Bedrock 1.26.40 introduced Mojang's **pack optimizer**, which stores a pack's loose files in `__brarchive/` archives. BePack can produce the same layout:
274
+
275
+ ```ts
276
+ pack: { outDir: "dist", optimize: true }
277
+ ```
278
+
279
+ ```bash
280
+ bepack pack --optimize # --no-optimize turns it back off
281
+ bepack build --pack --optimize
282
+ ```
283
+
284
+ BePack writes `header.pack_optimization_version: "0.1.0"` into the packaged manifest — that field is what makes the engine read the archives (a game version such as `"1.26.40"` is ignored). Registry folders such as `entities/`, `items/`, `blocks/`, `recipes/` and `models/` are archived in full and their loose files dropped; path-addressed folders (`functions/`, `loot_tables/`, `structures/`, `texts/`, `textures/`, `sounds/`, `font/`, `materials/`) keep their real files and get a name-only stub entry in the archive, exactly like Mojang's own packs. Verified in-game with an embedded `@minecraft/server` probe: archived blocks/items/entities/recipes register, and functions/loot tables resolve from the loose files.
285
+
286
+ Your pack folder on disk is never modified, and `bepack copy` only optimizes when you ask it to.
287
+
288
+ > **Compatibility:** only clients that understand `__brarchive/` (1.26.40+) see the archived content; older clients only see the folders that were kept loose. `min_engine_version` does not gate any of this, so BePack just warns when it is below 1.26.40 (`allowUnsupportedTarget: true` silences it). See the reference guide for every option.
289
+
290
+ Copies to a development folder stay loose by default. Turn on `copy.optimize` (or pass `--optimize` to `copy` / `dev` / `build --copy`) to put the **optimized** shape into the dev folder, so you can catch archive-only problems in-game before shipping:
291
+
292
+ ```ts
293
+ copy: { defaultTarget: "minecraft", optimize: true }
294
+ ```
295
+
235
296
  ## Commands at a glance
236
297
 
237
- | Command | Purpose |
238
- | ------------------------- | --------------------------------------------------------------------- |
239
- | `bepack init` | Create a config, or import one with `--from-bp` / `--from-rp`. |
240
- | `bepack install` | Resolve managed dependencies and update `package.json` and manifests. |
241
- | `bepack manifest` | Update manifests without running dependency installation. |
242
- | `bepack build` | Patch manifests and compile the configured BP source. |
243
- | `bepack dev` | Build once, then watch and rebuild. |
244
- | `bepack copy` | Copy configured packs to a development target. |
245
- | `bepack pack` | Create a `.mcpack` or `.mcaddon`. |
246
- | `bepack config --summary` | Inspect the resolved configuration. |
298
+ | Command | Purpose |
299
+ | ------------------------- | -------------------------------------------------------------------------------- |
300
+ | `bepack init` | Create a config, or import one with `--from-bp` / `--from-rp`. |
301
+ | `bepack install` | Resolve managed dependencies and update `package.json` and manifests. |
302
+ | `bepack manifest` | Update manifests without running dependency installation. |
303
+ | `bepack build` | Patch manifests, type-check with `tsc`, then compile the configured BP source. |
304
+ | `bepack dev` | Build once, then watch and rebuild (type checking on by default). |
305
+ | `bepack copy` | Copy configured packs to a development target. |
306
+ | `bepack pack` | Create a `.mcpack` or `.mcaddon`. |
307
+ | `bepack config --summary` | Inspect the resolved configuration. |
247
308
 
248
309
  All commands accept `--cwd <project-dir>` and `--config <path>` when the current directory or config filename is different. Add `--dry-run` to preview file-writing commands, or `--json` for machine-readable output. Run `bepack <command> --help` for every command option.
249
310
 
package/README.zh-CN.md CHANGED
@@ -25,7 +25,9 @@ BePack 是 Minecraft 基岩版附加包的构建工具。它将行为包和资
25
25
  - 从零创建 BePack 配置,或从已有 manifest 导入配置。
26
26
  - 同步 `manifest.json`,同时保留不由 BePack 管理的字段。
27
27
  - 将行为包的 TypeScript Script API 入口构建到 `scripts/` 目录。
28
+ - 打包前用 `tsc --noEmit` 做类型检查——**默认开启**。
28
29
  - 通过 `compile.define`(标识符级、typecheck 安全)或 `replace` 标记注入编译期 feature flag。
30
+ - 自定义 Rolldown 构建:内联选项、函数,或独立的 `rolldown.config.ts`。
29
31
  - 解析受支持的 `@minecraft/*` 依赖,并将具体版本写入项目。
30
32
  - 以 `preserve`(增量)或 `clean`(从配置生成)策略同步 `manifest.json`。
31
33
  - 将包复制到 Minecraft 开发目录,并生成发布压缩包。
@@ -172,8 +174,42 @@ bepack install --target 1.21.120
172
174
  bepack build --install --target 1.21.120
173
175
  ```
174
176
 
177
+ > **类型检查默认开启。** 每次 `bepack build` / `bepack dev` 都会先用 `tsc --noEmit` 检查源码,再交给 Rolldown 打包。检查失败会以 `TYPECHECK_FAILED` 终止构建,而不是产出一个损坏的包。可用 `--skip-typecheck` 跳过,或设置 `packs.bp.compile.typecheck: false`。这与自定义 Rolldown 选项无关——加了自定义选项**不会**关闭类型检查。
178
+
175
179
  受支持的 `@minecraft/*` 依赖可使用 `stable`、`beta`、`preview` 或精确版本。BePack 会先把如 `stable` 这样的选择器解析为具体包版本,再更新 `package.json` 和 BP manifest。
176
180
 
181
+ ## 自定义 Rolldown 构建
182
+
183
+ `packs.bp.compile` 覆盖了常见场景。需要 Rolldown 的其它能力时(额外插件、`resolve.alias`、`treeshake`、`sourcemap` 等),可以用内联选项、函数或配置文件传入:
184
+
185
+ ```ts
186
+ export default defineConfig({
187
+ // 此处省略 name、version、packs.bp.root、uuid 等
188
+ packs: {
189
+ bp: {
190
+ compile: {
191
+ entry: "src/main.ts",
192
+ // 对象形式,或函数形式 (options, context) => options
193
+ rolldown: {
194
+ resolve: { alias: { "@lib": "./src/lib" } },
195
+ output: { sourcemap: true },
196
+ },
197
+ // 或使用配置文件(相对项目根):
198
+ // rolldownConfig: "rolldown.bp.config.ts",
199
+ },
200
+ },
201
+ },
202
+ });
203
+ ```
204
+
205
+ ```bash
206
+ # 临时替换配置里指定的文件
207
+ bepack build --rolldown-config rolldown.staging.mjs
208
+ bepack dev --rolldown-config rolldown.staging.mjs
209
+ ```
210
+
211
+ 自定义选项会合并在 BePack 生成的选项之上:`plugins` 追加,`external` 取并集,`transform` / `resolve` / `output` / `experimental` 一层深合并。`input` 和输出位置字段始终由 BePack 管理,尝试修改会报 `CONFIG_INVALID`。自定义配置文件支持 `.ts` / `.mts` / `.js` / `.mjs`,且只能导出单个配置。完整合并规则与受保护字段见[参考文档](./reference.md)。
212
+
177
213
  ## 开发时复制到 Minecraft
178
214
 
179
215
  配置一次复制目标,然后在 `dev` 或 `build` 中加 `--copy`:
@@ -232,18 +268,43 @@ bepack pack --name my-addon-preview
232
268
  | 仅 RP | `.mcpack` |
233
269
  | BP 和 RP | `.mcaddon` |
234
270
 
271
+ ### Pack 优化(`__brarchive`)
272
+
273
+ 1.26.40 起官方提供 **pack optimizer**:把包里的散文件装进 `__brarchive/` 归档。BePack 可以在打包时生成同样的结构:
274
+
275
+ ```ts
276
+ pack: { outDir: "dist", optimize: true }
277
+ ```
278
+
279
+ ```bash
280
+ bepack pack --optimize # --no-optimize 可覆盖配置里的开启状态
281
+ bepack build --pack --optimize
282
+ ```
283
+
284
+ BePack 会往产物 manifest 写入 `header.pack_optimization_version: "0.1.0"` —— **这个字段才是引擎读取归档的开关**(写游戏版本号如 `"1.26.40"` 无效)。`entities/`、`items/`、`blocks/`、`recipes/`、`models/` 这类注册表目录会完整进归档并删除散文件;而按路径引用的目录(`functions/`、`loot_tables/`、`structures/`、`texts/`、`textures/`、`sounds/`、`font/`、`materials/`)保留真实散文件,归档里只登记一条 0 字节存根 —— 与官方包的做法一致。已用内置 `@minecraft/server` 探针脚本实机验证:归档的 blocks/items/entities/recipes 全部正常注册,functions/loot_tables 从散文件正常解析。
285
+
286
+ 磁盘上的包目录不会被修改,`bepack copy` 也只在显式开启时才优化。
287
+
288
+ > **兼容性**:只有支持 `__brarchive/` 的客户端(1.26.40+)才能看到归档内容;旧客户端只能看到保留散文件的目录。`min_engine_version` 不参与这个判断,所以低于 1.26.40 时 BePack 只打印警告(`allowUnsupportedTarget: true` 可关闭)。完整选项见参考文档。
289
+
290
+ 复制到开发目录默认仍是散文件形态。开启 `copy.optimize`(或给 `copy` / `dev` / `build --copy` 传 `--optimize`)可以把**优化后的形态**放进开发目录,这样打包后才可能出现的问题能在实机里提前发现:
291
+
292
+ ```ts
293
+ copy: { defaultTarget: "minecraft", optimize: true }
294
+ ```
295
+
235
296
  ## 命令速查
236
297
 
237
- | 命令 | 用途 |
238
- | ------------------------- | ----------------------------------------------------- |
239
- | `bepack init` | 创建配置,或用 `--from-bp` / `--from-rp` 导入配置。 |
240
- | `bepack install` | 解析受管理的依赖,并更新 `package.json` 和 manifest。 |
241
- | `bepack manifest` | 不安装依赖,仅更新 manifest。 |
242
- | `bepack build` | 修补 manifest 并编译已配置的 BP 源码。 |
243
- | `bepack dev` | 先构建一次,随后监听并重建。 |
244
- | `bepack copy` | 复制已配置的包到开发目标。 |
245
- | `bepack pack` | 生成 `.mcpack` 或 `.mcaddon`。 |
246
- | `bepack config --summary` | 查看解析后的配置摘要。 |
298
+ | 命令 | 用途 |
299
+ | ------------------------- | ------------------------------------------------------------- |
300
+ | `bepack init` | 创建配置,或用 `--from-bp` / `--from-rp` 导入配置。 |
301
+ | `bepack install` | 解析受管理的依赖,并更新 `package.json` 和 manifest。 |
302
+ | `bepack manifest` | 不安装依赖,仅更新 manifest。 |
303
+ | `bepack build` | 修补 manifest,用 `tsc` 类型检查,再编译已配置的 BP 源码。 |
304
+ | `bepack dev` | 先构建一次,随后监听并重建(类型检查默认开启)。 |
305
+ | `bepack copy` | 复制已配置的包到开发目标。 |
306
+ | `bepack pack` | 生成 `.mcpack` 或 `.mcaddon`。 |
307
+ | `bepack config --summary` | 查看解析后的配置摘要。 |
247
308
 
248
309
  所有命令都支持 `--cwd <项目目录>` 和 `--config <路径>`,可用于在非项目目录执行或使用不同的配置文件名。对于会写入文件的命令,可添加 `--dry-run` 预览;如需机器可读输出,可添加 `--json`。使用 `bepack <命令> --help` 查看每个命令的全部参数。
249
310