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

Ouverte
#16,527 0 commentaires 7 réactions 0 personnes assignées Voir sur GitHub

Personne n'a encore pris cette issue.

Évaluation

Difficulté
4/5
Temps estimé
3-5 jours
Accessibilité débutants
35/100
Type d'issue
Bug
Clarté
Plutôt claire
Activité
À l'abandon
Stack technique
angular, typescript
Domaine
tooling

Piste de recherche

Commencez par exécuter la reproduction minimale de la spécification schematic de l’issue, en particulier lorsque le Tree est créé par un autre Schematic. Examinez ensuite le comportement Copy/Delete de Tree et la règle Move dans @angular-devkit/schematics/src/rules. C’est terminé lorsque le cas Copy-then-delete ne déclenche plus « This should never happen » et que la règle Move ne signale plus ENOENT.

Rédigé par le modèle d'indexation à partir du texte de l'issue.

Description

area: @angular-devkit/schematics freq1: low severity3: broken type: bug/fix

🐞 Bug report

Description

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

  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 '<source>' -> '<destination>'

🔬 Minimal Reproduction

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

Langage dominant
TypeScript
Étoiles
27k
Forks
11.8k
Merge moyen
16 h 35 min
PR mergées (30 j)
176

Guide de contribution

Ouvrir le guide de contribution

Par où commencer

  1. Lisez l'issue en entier, puis le guide de contribution du projet.
  2. Signalez en commentaire que vous la prenez — cela évite que deux personnes fassent le même travail.
  3. Forkez le dépôt et travaillez sur une branche.
  4. Ouvrez une pull request qui référence le numéro de l'issue.

Autres issues de angular/angular-cli

Toutes les issues de angular/angular-cli

Issues similaires

Plus d'issues TypeScript

Recevez les nouvelles issues par e-mail

Un résumé court des issues GitHub adaptées aux débutants.