@longzai-intelligence-builder/config 0.2.9 → 0.2.11

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.
Files changed (2) hide show
  1. package/dist/index.d.ts +69 -4
  2. package/package.json +3 -3
package/dist/index.d.ts CHANGED
@@ -198,6 +198,68 @@ type CopyOptions = Arrayable<string | CopyEntry>;
198
198
  * copy 选项函数(对齐 tsdown CopyOptionsFn)
199
199
  */
200
200
  type CopyOptionsFn = (options: BuilderConfig) => Awaitable<CopyOptions>;
201
+ /**
202
+ * clean 选项对象形态(issue 0064 原子替换模式)
203
+ *
204
+ * 当 `clean` 配置为对象时,启用原子替换:构建产物先写到 tmpDir,构建成功后原子替换 outDir,
205
+ * 失败则丢弃 tmpDir、保留旧 outDir。消除构建期 clean 空窗期(旧 outDir 全程不动),
206
+ * 适用于构建工具运行时依赖被构建包 dist 的自举场景(如 builder 仓库构建 core 时,
207
+ * lzi-builder 运行时执行 core 源码,core 动态 import css,css 静态 import core)。
208
+ */
209
+ type CleanOptions = {
210
+ /**
211
+ * 是否启用原子替换模式
212
+ *
213
+ * - `true`:构建写到 tmpDir,成功后替换 outDir(默认 tmpDir = `<outDir>.tmp`)
214
+ * - `false`:退回默认行为(等价于 `clean: true`,构建前直接清空 outDir)
215
+ *
216
+ * @default false
217
+ */
218
+ atomic?: boolean;
219
+ /**
220
+ * 原子模式的临时构建目录(相对 cwd 或绝对路径)
221
+ *
222
+ * 不指定时默认 `<outDir>.tmp`(与 outDir 同父目录,保证同设备 rename 不触发 EXDEV)。
223
+ * 指定时构建产物先写到该目录,成功后 rm 旧 outDir + rename 此目录 → outDir。
224
+ *
225
+ * 注意:指定跨设备的 tmp 路径会触发 EXDEV,rename 失败时自动 fallback 为 copy + delete。
226
+ */
227
+ tmpDir?: string;
228
+ /**
229
+ * 原子模式之外额外清理的路径(glob 模式,相对 cwd)
230
+ *
231
+ * 这些路径在构建前直接删除(非原子,与默认 clean 的 string[] 行为一致),
232
+ * 用于清理 outDir 之外的产物(如 node_modules/.rolldown、exe 输出目录)。
233
+ */
234
+ extraTargets?: string[];
235
+ };
236
+ /**
237
+ * resolveClean 归一化后的 clean 配置
238
+ *
239
+ * 所有 clean 形态(boolean / string[] / CleanOptions)归一化为本结构。
240
+ * - `paths`:构建前直接删除的路径(glob 模式)。默认模式含 outDir;原子模式仅含 extraTargets
241
+ * - `atomic`:是否启用原子替换(构建写 tmpDir,成功后替换 outDir)
242
+ * - `tmpDir`:原子模式的临时目录绝对路径(atomic 为 true 时有值)
243
+ */
244
+ type ResolvedClean = {
245
+ /**
246
+ * 构建前直接删除的路径列表(glob 模式,相对 cwd)
247
+ *
248
+ * 默认模式:含 outDir(clean:true 时)或用户指定的 string[]
249
+ * 原子模式:仅含 extraTargets(outDir 由原子替换处理,不在此列表)
250
+ */
251
+ paths: string[];
252
+ /**
253
+ * 是否启用原子替换模式
254
+ */
255
+ atomic: boolean;
256
+ /**
257
+ * 原子模式的临时构建目录绝对路径
258
+ *
259
+ * 仅 atomic 为 true 时有值;默认 `<cwd>/<outDir>.tmp`,或用户指定的 tmpDir 解析为绝对路径。
260
+ */
261
+ tmpDir?: string;
262
+ };
201
263
  /**
202
264
  * report 选项(对齐 tsdown ReportOptions)
203
265
  */
@@ -462,8 +524,11 @@ type BuilderConfig = {
462
524
  * - `true`(默认):清理输出目录
463
525
  * - `false`:不清理
464
526
  * - `string[]`:清理指定路径列表(glob 模式)
527
+ * - 对象形态 `{ atomic, tmpDir }`(issue 0064):原子替换模式,构建写到 tmpDir(默认
528
+ * `<outDir>.tmp`),成功后原子替换 outDir,失败保留旧产物。消除构建期 clean 空窗期,
529
+ * 适用于构建工具运行时依赖被构建包 dist 的自举场景
465
530
  */
466
- clean?: boolean | string[];
531
+ clean?: boolean | string[] | CleanOptions;
467
532
  /**
468
533
  * 输出文件扩展名
469
534
  */
@@ -1121,9 +1186,9 @@ type ResolvedBuilderConfig = Required<Omit<BuilderConfig, 'format' | 'dts' | 'ts
1121
1186
  */
1122
1187
  css: BuilderConfig['css'];
1123
1188
  /**
1124
- * 解析后的 clean 路径列表(glob 模式)
1189
+ * 解析后的 clean 配置(归一化后)
1125
1190
  */
1126
- clean: string[];
1191
+ clean: ResolvedClean;
1127
1192
  /**
1128
1193
  * 是否写入磁盘(对齐 tsdown ResolvedConfig.write)
1129
1194
  */
@@ -1195,4 +1260,4 @@ type BuilderConfigFn = (inlineConfig?: {
1195
1260
  */
1196
1261
  type BuilderConfigExport = Awaitable<Arrayable<BuilderConfig> | BuilderConfigFn>;
1197
1262
  //#endregion
1198
- export type { Arrayable, AttwOptions, BuildContext, BuildFormat, BuilderConfig, BuilderConfigExport, BuilderConfigFn, BuilderHooks, CIOption, ConfigLoader, ConfigOptions, CopyEntry, CopyOptions, CopyOptionsFn, DepsOptions, DevtoolsOptions, DtsOptions, EntryConfig, ExportsOptions, LogLevel, LogType, Logger, LoggerOptions, NoExternalFn, PackageJsonWithPath, PresetDefinition, PublintOptions, ReportOptions, ResolvedBuilderConfig, RolldownChunk, RolldownContext, TsdownInputOption, WithEnabled, Workspace };
1263
+ export type { Arrayable, AttwOptions, BuildContext, BuildFormat, BuilderConfig, BuilderConfigExport, BuilderConfigFn, BuilderHooks, CIOption, CleanOptions, ConfigLoader, ConfigOptions, CopyEntry, CopyOptions, CopyOptionsFn, DepsOptions, DevtoolsOptions, DtsOptions, EntryConfig, ExportsOptions, LogLevel, LogType, Logger, LoggerOptions, NoExternalFn, PackageJsonWithPath, PresetDefinition, PublintOptions, ReportOptions, ResolvedBuilderConfig, ResolvedClean, RolldownChunk, RolldownContext, TsdownInputOption, WithEnabled, Workspace };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@longzai-intelligence-builder/config",
3
- "version": "0.2.9",
3
+ "version": "0.2.11",
4
4
  "private": false,
5
5
  "license": "UNLICENSED",
6
6
  "type": "module",
@@ -31,11 +31,11 @@
31
31
  },
32
32
  "dependencies": {},
33
33
  "peerDependencies": {
34
- "@longzai-intelligence-builder/rolldown-plugin-dts": "0.2.9",
34
+ "@longzai-intelligence-builder/rolldown-plugin-dts": "0.2.11",
35
35
  "hookable": "^6.1.1",
36
36
  "rolldown": "^1.0.0"
37
37
  },
38
38
  "devDependencies": {
39
- "@longzai-intelligence-builder/esm": "0.2.9"
39
+ "@longzai-intelligence-builder/esm": "0.2.11"
40
40
  }
41
41
  }