angular / angular/angular-cli

Schematics : Copy then delete can cause "This should never happen" error.

未關閉
#16,527 0 則留言 7 個 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

### Description

Moving files as part of a schematic can cause an error to be thrown:

```bash
Message:
Error: This should never happen. Path: "/projects/bar".
```

It seems to happen if those files were created by a previous rule and the move is done by copy and deletion.

(As an aside here, it _seems_ that delete operations are hoisted somehow...whenever they occur in a schematic, the logger output shows them to always happen first, this is *not* what I'd expect)

I'm aware that there is a `move` rule in `@angular-devkit/schematics/src/rules`, but this **does not work**. Attempting to use this rule to move files from one folder to another results in this error: `ENOENT: no such file or directory, rename '' -> ''`

## 🔬 Minimal Reproduction

```ts
export function move(schema: Schema): Rule {
return (host: Tree, _context: SchematicContext): Tree => {
const dir = host.getDir(schema.source);
dir.visit(file => {
const newPath = file.replace(schema.source, schema.destination);

const buffer = host.read(file);
if (buffer === null) {
return;
}

host.create(newPath, buffer);
});

host.delete(schema.source);

return host;
};
}
```

See also: https://github.com/jdpearce/move-schematic

NB - this schematic will probably work if run against a pre-existing workspace, but when the tree is set up by another schematic, as in the spec file, that's when the error is thrown.

## 🌍 Your Environment

Angular CLI: 8.3.21
Node: 13.5.0
OS: darwin x64
Angular: undefined
...

Package Version
------------------------------------------------------
@angular-devkit/architect 0.803.21 (cli-only)
@angular-devkit/core 8.3.21
@angular-devkit/schematics 8.3.21
@schematics/angular 8.3.21
@schematics/update 0.803.21 (cli-only)
rxjs 6.5.4
typescript 3.5.3

貢獻指南

開啟貢獻指南

研究方向

首先執行 issue 的 schematic 規格中的最小重現,尤其是在 Tree 由另一個 Schematic 建立時。接著檢查 Tree 的 Copy/Delete 行為,以及 @angular-devkit/schematics/src/rules 中的 Move 規則。完成的標準是 Copy-then-delete 情況不再擲出 “This should never happen”,且 Move 規則不再回報 ENOENT。

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

評估

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

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

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