Skip to content

Schematics fail when moving a file and updating its content #21083

Closed
@leosvelperez

Description

@leosvelperez

🐞 Bug report

Description

When a schematic moves a file and update its content, an error is thrown saying that the file doesn't exist:

ERROR! docs/README.md does not exist.
The Schematic workflow failed. See above.

If the file is not moved, it all works fine.

🔬 Minimal Reproduction

A minimal reproduction of this issue can be found in https://github.com/leosvelperez/schematics-overwrite-issue.

The repo provides 2 schematics, one broken and one successful. The broken one does the following operations:

  1. Moves /README.md to /docs/README.md.
  2. Updates /docs/README.md content.

The successful schematics just update the /README.md content and it works fine.

Below are the steps to run the schematic (it runs in dry run mode, but this doesn't affect the outcome):

# 1. Install deps
yarn install
# 2. Run broken schematic
yarn run-broken-schematic
# 3. Run successful schematic
yarn run-schematic

The issue most likely happens because when an action is validated, it validates if the file exists, and depending on the kind of action and the result it will result in an error. The function that checks for the existence of the file https://github.com/angular/angular-cli/blob/master/packages/angular_devkit/schematics/src/sink/host.ts#L36 is not checking if the file path is in any tuple of the _filesToRename object as part of the to (destination).

🔥 Exception or Error

ERROR! docs/README.md does not exist.
The Schematic workflow failed. See above.

🌍 Your Environment

Angular CLI: 12.0.3
Node: 14.17.0
Package Manager: yarn 1.22.10
OS: darwin x64

Angular: 12.0.3
... animations, cli, common, compiler, compiler-cli, core, forms
... platform-browser, platform-browser-dynamic, router

Package                          Version
----------------------------------------------------------
@angular-devkit/architect        0.1200.3
@angular-devkit/build-angular    12.0.3
@angular-devkit/core             12.0.3
@angular-devkit/schematics       12.0.3
@angular-devkit/schematics-cli   12.0.3
@schematics/angular              12.0.3
rxjs                             6.6.7
typescript                       4.2.4

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions