CI: nx affected 不会在其他包的运行时测试依赖 schematics-core 时构建 schematics-core
作者: robert-md-or创建于 2026年7月24日更新于 2026年7月24日
何个 @ngrx/* 包是 bug 的来源? schematics 描述 在处理 PR #5203 时, test-affected CI 任务在几乎每个库包( store, effects, entity, router-store, store-devtools, component-store, operators, component, data, schematics, signals, example-app) 中都失败,原因相同: "Error: Failed to resolve import '@ngrx/schematics-core/testing' from 'modules/store/migrations/18_0_0-beta/index.spec.ts'. Does the file exist?"(在其他包中对 @ngrx/schematics-core/testing/create-package 的类似错误) 我发现 CI 任务(pnpm exec nx affected -t test --skip-nx-cache --parallel=3)计算出了 15 个受影响的项目, schematics-core 并不在其中 — 这很合理,因为 PR 的更改(从根目录的 tsconfig.json 中删除一个已过时的 baseUrl)并不影响 schematics-core 自己的源代码。 然而,几乎每个其他包的测试套件在运行时都直接从 @ngrx/schematics-core/testing 导入(通过 node_modules/@ngrx/schematics-core 解析,该文件只有在 schematics-core 自己的构建目标运行其 ncp dist/... node_modules/@ngrx/schematics-core 步骤时才会生成)。 由于 schematics-core 不属于此受影响的运行,它从未被构建,因此导入无法解析 — 尽管 store:build, effects:build 等都在事先成功完成。 本次运行中唯一通过的测试目标是 www:test, standalone-app:test 和 eslint-plugin:test — 其中均不从 @ngrx/schematics-core 导入。 为什么我认为这是一个图/配置差距,而不仅仅是我 PR 中的特定问题 - nx.json 的 targetDefaults 具有 test: { dependsOn: ["build"] } 和 build: { dependsOn: ["^build"] },因此原则上一个项目的自身构建依赖应该被传递性地采用。 但是,由于 @ngrx/schematics-core 导入是在运行时通过 node_modules 路径解析的(而不是 Nx 的依赖图分析可以看到的源级 TS 项目引用),Nx 似乎不知道这些包的 test 目标隐式地依赖 schematics-core 的 build 输出。 本地运行例如 pnpm nx run store:test 直接(而不是通过 nx affected) 就能成功通过,但仅是因为 node_modules/@ngrx/schematics-core 在我的机器上已经从早期的无关的手动构建中生成。 除非 schematics-core 在特定运行中受到影响,否则该文件在新的 CI 检出中将不存在。 如果这个推理是正确的, 任何 PR 其差异不直接影响 schematics-core 都将在受影响的基于 CI 任务中遇到同样的失败,无论 PR 实际更改是什么。 支持证据:与兄弟 PR 的比较 我大约同时开启的一个相关 PR, #5202(在少数非根 tsconfig 文件中修改 moduleResolution),在 CI 中成功通过。 查看其 test-affected 输出,仅运行了 3 个项目: schematics, …
内容来源: ngrx/platform