@bleedingdev/modern-js-main-doc 3.8.2-ultramodern.10 → 3.8.2-ultramodern.12

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.
@@ -255,6 +255,94 @@ directories, and caches are isolated per app, build target, and Rspack
255
255
  environment so local `build`, `cloudflare:build`, and multi-environment
256
256
  compilers do not share mutable build state.
257
257
 
258
+ ## Configure the public preset
259
+
260
+ Use `presetUltramodern(appConfig, presetOptions)` inside the normal Modern.js
261
+ `defineConfig` call:
262
+
263
+ ```ts title="modern.config.ts"
264
+ import { defineConfig, presetUltramodern } from '@modern-js/app-tools';
265
+
266
+ export default defineConfig(
267
+ presetUltramodern(
268
+ {
269
+ output: {
270
+ precompress: false,
271
+ },
272
+ server: {
273
+ telemetry: {
274
+ failLoudStartup: true,
275
+ },
276
+ },
277
+ },
278
+ {
279
+ appId: 'catalog',
280
+ enableModuleFederationSSR: false,
281
+ enableTelemetryExporters: false,
282
+ },
283
+ ),
284
+ );
285
+ ```
286
+
287
+ The first argument is ordinary `AppUserConfig`. It contains app-owned config
288
+ and wins where it supplies an override. The second argument controls the
289
+ preset itself. Use its typed options, such as `enableBffRequestId: false`,
290
+ `enableTelemetry: false`, `enableTelemetryExporters: false`, and
291
+ `enableModuleFederationSSR: false`, to turn preset features off.
292
+
293
+ Composition follows the Modern.js config merge rules:
294
+
295
+ - Nested records merge, so changing one nested field keeps its preset
296
+ siblings.
297
+ - Scalars and `false` supplied by the app override preset values. Omitting a
298
+ field, or leaving it `undefined`, keeps the preset value.
299
+ - Arrays and config hooks compose in preset-first order. Non-function array
300
+ entries are deduplicated by deep equality, while function entries are all
301
+ retained. An empty array or empty record does not clear values already
302
+ supplied by the preset.
303
+
304
+ There is no generic reset sentinel. Use a typed preset option for preset-owned
305
+ behavior and a normal app config override for app-owned behavior.
306
+
307
+ `createPresetUltramodernConfig(options)` is an advanced API for inspecting or
308
+ materializing a fresh preset config. Do not spread its result into another
309
+ config object. Object spread is shallow, so replacing `server`, `output`, or
310
+ another nested record can silently discard preset siblings. Use
311
+ `presetUltramodern(...)` for authoring `modern.config.ts`.
312
+
313
+ ### Bare preset and generated workspace policy
314
+
315
+ The preset and the workspace generator own different parts of the config:
316
+
317
+ | Source | Identity | Remaining config |
318
+ | --- | --- | --- |
319
+ | Bare `createPresetUltramodernConfig()` result | Uses `appId: 'app'` and has no `deliveryUnit` | Uses the preset defaults. Telemetry stays enabled, but no exporter is configured until its endpoint is set. |
320
+ | Generated app | Supplies the app-specific `appId` and stamped `deliveryUnit` | Inherits the other strict defaults from `presetUltramodern(...)`. |
321
+ | Application | Supplies the first `appConfig` argument | Overrides app-owned fields through the normal Modern.js merge. |
322
+
323
+ Keep the generated `appId` and `deliveryUnit` options intact. To change
324
+ preset-owned behavior, use typed options such as
325
+ `enableTelemetryExporters: false`,
326
+ `enableTelemetry: false`, `enableBffRequestId: false`, or
327
+ `enableModuleFederationSSR: false`. To change an app-owned field, put the
328
+ override in the first argument, as in the example above.
329
+
330
+ Telemetry exporter endpoints are unset by default:
331
+
332
+ - `MODERN_TELEMETRY_OTLP_ENDPOINT` enables only the OTLP exporter.
333
+ - `MODERN_TELEMETRY_VICTORIA_ENDPOINT` enables only the VictoriaMetrics
334
+ exporter.
335
+ - Setting both enables both. Leaving both unset keeps the telemetry pipeline
336
+ enabled without configuring an exporter.
337
+
338
+ The typed `otlpEndpoint` and `victoriaMetricsEndpoint` preset options provide
339
+ the same per-exporter behavior without environment variables.
340
+
341
+ ```bash
342
+ MODERN_TELEMETRY_OTLP_ENDPOINT=https://otel.example.com/v1/logs \
343
+ mise exec -- pnpm dev
344
+ ```
345
+
258
346
  ## Human Workflow
259
347
 
260
348
  The public BleedingDev create package has one supported generated product. The
@@ -433,18 +521,6 @@ BleedingDev packages are published through GitHub Actions trusted publishing.
433
521
  The public workflow is tokenless; do not publish packages manually from a
434
522
  developer machine.
435
523
 
436
- ## Baseline Switches (Opt-out)
437
-
438
- The generated `presetUltramodern(...)` starter enables strict platform contracts. Use these env switches to opt out per app or per environment:
439
-
440
- - `MODERN_BASELINE_ENABLE_MF_SSR` (default: `true`): Enables app-level MF SSR baseline contract (`server.ssr.mode: 'stream'` + `moduleFederationAppSSR`). Disable when the app does not use app-level MF SSR, or when you need plain SSR/CSR behavior first.
441
- - `MODERN_BASELINE_ENABLE_BFF_REQUEST_ID` (default: `true`): Enables default BFF producer identity contract (`bff.requestId`). Disable when the app does not need cross-project producer isolation.
442
- - `MODERN_BASELINE_ENABLE_TELEMETRY_EXPORTERS` (default: `true`): Enables telemetry exporters in baseline config. Disable when the environment has no telemetry backend yet.
443
- - `MODERN_BASELINE_APP_ID` (default: `basename(process.cwd())`): Overrides baseline `bff.requestId` identity. Set this when you need a fixed platform-wide producer ID convention.
444
- - `MODERN_TELEMETRY_OTLP_ENDPOINT` (default: `http://127.0.0.1:4318/v1/logs`): OTLP exporter endpoint. Override when you route telemetry through a different collector endpoint.
445
- - `MODERN_TELEMETRY_VICTORIA_ENDPOINT` (default: `http://127.0.0.1:8428/api/v1/import/prometheus`): VictoriaMetrics exporter endpoint. Override when you use a different VM ingress endpoint.
446
- - `MODERN_TELEMETRY_FAIL_LOUD_STARTUP` (default: `true`): Fails startup if configured exporters fail startup health checks. Disable in local/dev environments where temporary telemetry outage should not block boot.
447
-
448
524
  ## Related Docs
449
525
 
450
526
  - [BFF Runtime Frameworks](/guides/advanced-features/bff/frameworks)
@@ -219,6 +219,87 @@ migration 时不要再用 app 本地 postprocess。Cloudflare public output 默
219
219
  会按 app、构建目标和 Rspack environment 隔离,避免本地 `build`、`cloudflare:build`
220
220
  以及多 environment compiler 共享可变构建状态。
221
221
 
222
+ ## 配置公开预设
223
+
224
+ 在标准 Modern.js `defineConfig` 调用中使用
225
+ `presetUltramodern(appConfig, presetOptions)`:
226
+
227
+ ```ts title="modern.config.ts"
228
+ import { defineConfig, presetUltramodern } from '@modern-js/app-tools';
229
+
230
+ export default defineConfig(
231
+ presetUltramodern(
232
+ {
233
+ output: {
234
+ precompress: false,
235
+ },
236
+ server: {
237
+ telemetry: {
238
+ failLoudStartup: true,
239
+ },
240
+ },
241
+ },
242
+ {
243
+ appId: 'catalog',
244
+ enableModuleFederationSSR: false,
245
+ enableTelemetryExporters: false,
246
+ },
247
+ ),
248
+ );
249
+ ```
250
+
251
+ 第一个参数是普通的 `AppUserConfig`,用于应用自己拥有的配置,并在提供覆盖值时胜出。
252
+ 第二个参数控制预设本身。关闭预设能力时,使用它提供的类型化选项,例如
253
+ `enableBffRequestId: false`、`enableTelemetry: false`、
254
+ `enableTelemetryExporters: false` 和 `enableModuleFederationSSR: false`。
255
+
256
+ 组合过程遵循 Modern.js 配置合并规则:
257
+
258
+ - 嵌套对象会递归合并。修改一个嵌套字段时,预设中的同级字段会保留。
259
+ - 应用提供的标量和 `false` 会覆盖预设值。省略字段或将其保留为 `undefined` 时,
260
+ 预设值会保留。
261
+ - 数组和配置 hook 按预设优先的顺序组合。非函数数组项按深度相等去重,函数项则全部
262
+ 保留。空数组或空对象不会清除预设已经提供的值。
263
+
264
+ 这里没有通用的 reset sentinel。预设拥有的行为应使用类型化预设选项控制,应用拥有的
265
+ 行为应使用普通应用配置覆盖。
266
+
267
+ `createPresetUltramodernConfig(options)` 是用于检查或生成一份全新预设配置的高级 API。
268
+ 不要把它的结果展开进另一个配置对象。对象展开是浅层操作,替换 `server`、`output`
269
+ 或其他嵌套对象时,会无提示地丢弃预设中的同级字段。编写 `modern.config.ts` 时应使用
270
+ `presetUltramodern(...)`。
271
+
272
+ ### 裸预设与生成 workspace 的策略
273
+
274
+ 预设和 workspace 生成器分别负责不同的配置:
275
+
276
+ | 来源 | 身份配置 | 其他配置 |
277
+ | --- | --- | --- |
278
+ | 裸 `createPresetUltramodernConfig()` 的结果 | 使用 `appId: 'app'`,不设置 `deliveryUnit` | 使用预设默认值。Telemetry 保持启用,但只有设置具体端点后才会配置对应导出器。 |
279
+ | 生成的应用 | 提供应用专属的 `appId` 和生成时写入的 `deliveryUnit` | 其他严格默认值继承自 `presetUltramodern(...)`。 |
280
+ | 应用 | 通过第一个 `appConfig` 参数提供配置 | 按 Modern.js 的正常合并规则覆盖应用拥有的字段。 |
281
+
282
+ 应保留生成的 `appId` 和 `deliveryUnit` 选项。修改预设拥有的行为时,使用类型化选项,
283
+ 例如
284
+ `enableTelemetryExporters: false`、`enableTelemetry: false`、
285
+ `enableBffRequestId: false` 或 `enableModuleFederationSSR: false`。修改应用拥有的
286
+ 字段时,应像上面的示例一样,把覆盖值放在第一个参数中。
287
+
288
+ Telemetry 导出端点默认不设置:
289
+
290
+ - `MODERN_TELEMETRY_OTLP_ENDPOINT` 只启用 OTLP 导出器。
291
+ - `MODERN_TELEMETRY_VICTORIA_ENDPOINT` 只启用 VictoriaMetrics 导出器。
292
+ - 同时设置两个变量会启用两个导出器。两个变量都未设置时,telemetry 管线保持启用,
293
+ 但不会配置导出器。
294
+
295
+ 类型化的 `otlpEndpoint` 和 `victoriaMetricsEndpoint` 预设选项也能提供同样的
296
+ 逐导出器行为,无需使用环境变量。
297
+
298
+ ```bash
299
+ MODERN_TELEMETRY_OTLP_ENDPOINT=https://otel.example.com/v1/logs \
300
+ mise exec -- pnpm dev
301
+ ```
302
+
222
303
  ## 人类工作流
223
304
 
224
305
  公开的 BleedingDev create 包只有一个受支持的生成产品。默认命令会创建一个
@@ -384,18 +465,6 @@ Live Cloudflare 与 Zephyr 证明需要公开 Worker URL 和 Zephyr 凭据。没
384
465
  BleedingDev 包通过 GitHub Actions trusted publishing 发布。公开发布 workflow 不使用
385
466
  长期 npm token;不要从开发机器手动发布包。
386
467
 
387
- ## 基线开关(可按需关闭)
388
-
389
- 生成的 `presetUltramodern(...)` 脚手架会开启更严格的平台契约。以下环境变量会在生成的 `modern.config.ts` 中读取,可按应用或按环境关闭/覆盖:
390
-
391
- - `MODERN_BASELINE_ENABLE_MF_SSR`(默认:`true`):开启应用级 MF SSR 基线契约(`server.ssr.mode: 'stream'` + `moduleFederationAppSSR`)。应用不使用 app-level MF SSR 或希望先走普通 SSR/CSR 路径时可关闭。
392
- - `MODERN_BASELINE_ENABLE_BFF_REQUEST_ID`(默认:`true`):开启默认 BFF producer 身份契约(`bff.requestId`)。应用不需要跨项目 producer 隔离时可关闭。
393
- - `MODERN_BASELINE_ENABLE_TELEMETRY_EXPORTERS`(默认:`true`):在基线配置中启用 telemetry 导出器。当前环境还没有 telemetry 后端时可关闭。
394
- - `MODERN_BASELINE_APP_ID`(默认:`basename(process.cwd())`):覆盖基线 `bff.requestId` 身份。需要固定、可治理的统一 producer ID 命名时建议设置。
395
- - `MODERN_TELEMETRY_OTLP_ENDPOINT`(默认:`http://127.0.0.1:4318/v1/logs`):OTLP 导出端点。接入其他 OTLP collector 地址时覆盖。
396
- - `MODERN_TELEMETRY_VICTORIA_ENDPOINT`(默认:`http://127.0.0.1:8428/api/v1/import/prometheus`):VictoriaMetrics 导出端点。接入其他 VM 写入地址时覆盖。
397
- - `MODERN_TELEMETRY_FAIL_LOUD_STARTUP`(默认:`true`):导出器健康检查失败时启动即失败(fail-loud)。本地/开发环境希望 telemetry 故障不阻断启动时可关闭。
398
-
399
468
  ## 相关文档
400
469
 
401
470
  - [BFF 运行时框架](/guides/advanced-features/bff/frameworks)
package/package.json CHANGED
@@ -19,12 +19,12 @@
19
19
  "modern.js",
20
20
  "ultramodern.js"
21
21
  ],
22
- "version": "3.8.2-ultramodern.10",
22
+ "version": "3.8.2-ultramodern.12",
23
23
  "publishConfig": {
24
24
  "access": "public"
25
25
  },
26
26
  "dependencies": {
27
- "@modern-js/sandpack-react": "npm:@bleedingdev/modern-js-sandpack-react@3.8.2-ultramodern.10",
27
+ "@modern-js/sandpack-react": "npm:@bleedingdev/modern-js-sandpack-react@3.8.2-ultramodern.12",
28
28
  "mermaid": "^11.16.0"
29
29
  },
30
30
  "devDependencies": {