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

オープン
#16,527 コメント 0 件 リアクション 7 件 担当者 0 名 GitHub で見る

まだ誰も着手していません。

評価

難易度
4/5
見積もり時間
3〜5日
初心者へのやさしさ
35/100
issue の種類
バグ
明瞭さ
おおむね明確
活発さ
停滞
技術スタック
angular, typescript
領域
tooling

調査の方向性

まず、issue の schematic 仕様にある最小再現を実行します。特に、Tree が別の Schematic によって作成される場合を確認してください。次に、Tree の Copy/Delete の動作と、@angular-devkit/schematics/src/rules にある Move ルールを調べます。Copy-then-delete のケースで “This should never happen” がスローされなくなり、Move ルールが ENOENT を報告しなくなれば完了です。

索引モデルが issue の本文から書いたものです。

説明

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

主要言語
TypeScript
スター
27k
フォーク
11.8k
平均マージ
16時間 35分
マージ済み PR(30日)
176

コントリビューションガイド

コントリビューションガイドを開く

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

angular/angular-cli のほかの issue

angular/angular-cli の issue をすべて見る

似ている issue

TypeScript の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。