Schematics : Copy then delete can cause "This should never happen" error.
- Lingua principale
- TypeScript
- Stelle
- 27k
- Fork
- 11.8k
- Merge medio
- 14h 23m
- PR unite (30g)
- 162
Descrizione
# 🐞 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
Guida per i contributori
Apri la guida per i contributori
Direzione di ricerca
Inizia eseguendo la riproduzione minima della specifica schematica dell’issue, soprattutto quando il Tree viene creato da un altro Schematic. Poi esamina il comportamento Copy/Delete di Tree e la regola Move in @angular-devkit/schematics/src/rules. Il lavoro è completato quando il caso Copy-then-delete non genera più “This should never happen” e la regola Move non segnala più ENOENT.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Valutazione
- Stack tecnologico
- angular, typescript
- Ambito
- tooling
- Tipo di issue
- Bug
- Difficoltà
- 4/5
- Tempo stimato
- 3-5 giorni
- Stato di attività
- Ferma
- Chiarezza
- Abbastanza chiara
- Idoneità per principianti
- 35/100