externalSchematic executes schematics from migration.json instead of collection.json

未关闭
#21,131 1 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

还没有人认领这个 Issue。

评估

难度
4/5
预计耗时
3-5 天
新手友好度
35/100
Issue 类型
缺陷
描述清晰度
基本清楚
活跃度
停滞
技术栈
angular, typescript
领域
tooling

调研方向

从 SchematicEngine.createCollection 和报告中描述的 externalSchematic 调用开始,然后跟踪 collection.json 和 migration.json 如何以相同的包名加载并缓存。复现 ngx-my-lib 场景,并验证 externalSchematic 解析的是 collection.json 中的 schematic,而不是 migration.json 中的 schematic。

由索引模型根据 Issue 内容生成。

描述

area: @angular-devkit/schematics freq1: low severity3: broken type: bug/fix

🐞 Bug report

Command
  • new
  • build
  • serve
  • test
  • e2e
  • generate
  • add
  • update
  • lint
  • extract-i18n
  • run
  • config
  • help
  • version
  • doc
Is this a regression?
No
Description

The function externalSchematic from @angular-devkit/schematics does not call the schematic from the collection.json but instead from the migration.json If the collection (package) name is the same as the current package that is migrated.

🔬 Minimal Reproduction

  1. The package ngx-my-lib has the schematic config defined in the collection.json
  2. Create a migration schematic for the package ngx-my-lib.
  3. Call the externalSchematic function with externalSchematic('ngx-my-lib', 'config') in the migration schematic.
  4. Execute the migration schematic

🔥 Exception or Error

Schematic "config" not found in collection "ngx-my-lib"

🌍 Your Environment


Angular CLI: 12.0.3
Node: 14.16.1
Package Manager: yarn 1.22.10
OS: linux x64

Angular: undefined
... 

Package                      Version
------------------------------------------------------
@angular-devkit/architect    0.1200.3
@angular-devkit/core         12.0.3
@angular-devkit/schematics   12.0.3
@angular/cli                 12.0.3
@schematics/angular          12.0.3
typescript                   4.2.4

Anything else relevant?

I could track down this error to the createCollection method in the class SchematicEngine. Invoking the externalSchematic the Collection instance for the migration.json is cached with the key ngx-my-lib. So the external schematic execution does not load the collection for the collection.json, but for the migration.json.

主要语言
TypeScript
星标
27k
派生
11.8k
平均合并
16 小时 35 分钟
30 天内合并 PR
176

贡献指南

打开贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

angular/angular-cli 的其他 Issue

查看 angular/angular-cli 的全部 Issue

相似的 Issue

更多 TypeScript Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。