angular / angular/angular-cli

Library schematic does not support path property

未關閉
#16,080 6 則留言 9 個 reaction 已指派 0 人 在 GitHub 檢視
area: @schematics/angular feature feature: insufficient votes
主要語言
TypeScript
星號
27k
分支
11.8k
平均合併
14 小時 23 分鐘
30 天內合併 PR
162

描述

# 🐞 Bug report

### Command (mark with an `x`)

```
- [ ] new
- [ ] build
- [ ] serve
- [ ] test
- [ ] e2e
- [ ] generate
- [ ] add
- [ ] update
- [ ] lint
- [ ] xi18n
- [ ] run
- [ ] config
- [ ] help
- [ ] version
- [ ] doc
- [X] schematics
```

### Is this a regression?

Not as far as I know

### Description

I tried to create a schematic that generates an application and adds a library to it. However, the library schematic does not accept a `path` as parameter and it then attempts to create the library in the folder that contains the application. Specifically, it tries to read the `angular.json` file from the folder containing the application folder (e.g. the folder where the schematic is run).

Note that I expected the `path` property to work, as it's included with most of the other Angular schematics, for example component, module and service.

## 🔬 Minimal Reproduction

A minimal reproduction may be found [in this repo](https://github.com/CobusKruger/AngularProjectMergeIssues).

It also addresses a problem I had when trying to work around this with `applyToSubtree`.

Here is the simplest description I could come up with.

Given this factory:

```typescript
export function createProject(_options: any): Rule {
return (_tree: Tree, _context: SchematicContext) => {
return chain([
externalSchematic('@schematics/angular', 'ng-new', optionsNew),
externalSchematic('@schematics/angular', 'library', optionsLib)
]);
};
}
```

If you execute the schematic in a folder named `/parent/folder` and the app generates in a new folder named app (`/parent/folder/app`), the library schematic searches for the `angular.json` in `/parent/folder` instead of `/parent/folder/app`.

## 🔥 Exception or Error
```
An error occured:
Error: Unable to locate a workspace file for workspace path.
at Object.readWorkspace (C:\dev\scratchpad\scaffolding-tests\node_modules\@angular-devkit\core\src\workspace\core.js:74:19)
at async Object.getWorkspace (C:\dev\scratchpad\scaffolding-tests\node_modules\@schematics\angular\utility\workspace.js:51:27)
at async C:\dev\scratchpad\scaffolding-tests\node_modules\@schematics\angular\library\index.js:153:27
```

## 🌍 Your Environment



_ _ ____ _ ___
/ \ _ __ __ _ _ _| | __ _ _ __ / ___| | |_ _|
/ △ \ | '_ \ / _` | | | | |/ _` | '__| | | | | | |
/ ___ \| | | | (_| | |_| | | (_| | | | |___| |___ | |
/_/ \_\_| |_|\__, |\__,_|_|\__,_|_| \____|_____|___|
|___/

Angular CLI: 8.3.1
Node: 12.12.0
OS: win32 x64
Angular: undefined
...

Package Version
------------------------------------------------------
@angular-devkit/architect 0.803.1 (cli-only)
@angular-devkit/core 8.3.17
@angular-devkit/schematics 8.3.17
@schematics/angular 8.3.1 (cli-only)
@schematics/update 0.803.1 (cli-only)
rxjs 6.4.0
typescript 3.5.3

## Similar issues
https://github.com/angular/angular-cli/issues/17598

貢獻指南

開啟貢獻指南

研究方向

從 issue 中連結的最小重現儲存庫開始,追蹤 @schematics/angular/library/index.js 中的 library schematic 進入點,以及錯誤堆疊中的 utility/workspace.js。確認應用程式在子資料夾中產生時,路徑是如何處理的。當 library schematic 接受該路徑,並且能夠在沒有 workspace 錯誤的情況下找到產生之應用程式的 angular.json 時,即表示完成。

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

評估

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

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

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