angular / angular/angular-cli

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

Đang mở
#16,527 0 bình luận 7 reaction 0 người được giao Xem trên GitHub
area: @angular-devkit/schematics freq1: low severity3: broken type: bug/fix
Ngôn ngữ chính
TypeScript
Star
27k
Fork
11.8k
Merge trung bình
14 giờ 23 phút
Pull request đã merge (30 ngày)
162

Mô tả

# 🐞 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

Hướng dẫn đóng góp

Mở hướng dẫn đóng góp

Hướng nghiên cứu

Bắt đầu bằng cách chạy bản tái hiện tối thiểu từ đặc tả schematic của issue, đặc biệt khi Tree được tạo bởi một Schematic khác. Sau đó kiểm tra hành vi Copy/Delete của Tree và quy tắc Move trong @angular-devkit/schematics/src/rules. Hoàn tất khi trường hợp Copy-then-delete không còn ném “This should never happen” và quy tắc Move không còn báo ENOENT.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Đánh giá

Công nghệ
angular, typescript
Lĩnh vực
tooling
Loại issue
Lỗi
Độ khó
4/5
Thời gian dự kiến
3-5 ngày
Mức độ hoạt động
Đình trệ
Độ rõ ràng
Khá rõ ràng
Mức phù hợp với người mới
35/100

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.