angular / angular/angular-cli

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

未關閉
#21,131 1 則留言 0 個 reaction 已指派 0 人 在 GitHub 檢視
area: @angular-devkit/schematics freq1: low severity3: broken type: bug/fix
主要語言
TypeScript
星號
27k
分支
11.8k
平均合併
14 小時 23 分鐘
30 天內合併 PR
162

描述

# 🐞 Bug report

### Command

- [ ] new
- [ ] build
- [ ] serve
- [ ] test
- [ ] e2e
- [ ] generate
- [ ] add
- [x] 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`.

貢獻指南

開啟貢獻指南

研究方向

從 SchematicEngine.createCollection 和報告中描述的 externalSchematic 呼叫開始,然後追蹤 collection.json 和 migration.json 如何以相同的套件名稱載入並快取。重現 ngx-my-lib 情境,並驗證 externalSchematic 解析的是 collection.json 中的 schematic,而不是 migration.json 中的 schematic。

由索引模型根據 Issue 內容生成。

評估

技術堆疊
angular, typescript
領域
tooling
Issue 類型
缺陷
難度
4/5
預估耗時
3-5 天
活躍度
停滯
描述清晰度
基本清楚
新手友好度
35/100

把新 issue 寄到你的電子郵件信箱

精選適合新手參與的 GitHub issue 摘要。