Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
leosvelperez opened this issue Jun 8, 2021 · 1 comment · Fixed by #21091
Closed

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

leosvelperez opened this issue Jun 8, 2021 · 1 comment · Fixed by #21091
Assignees
Labels
area: @angular-devkit/schematics freq1: low Only reported by a handful of users who observe it rarely severity3: broken type: bug/fix
Milestone

Comments

@leosvelperez
Copy link
Contributor

🐞 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
@alan-agius4 alan-agius4 added area: @angular-devkit/schematics freq1: low Only reported by a handful of users who observe it rarely severity3: broken type: bug/fix labels Jun 8, 2021
@ngbot ngbot bot modified the milestone: Backlog Jun 8, 2021
@alan-agius4 alan-agius4 self-assigned this Jun 9, 2021
alan-agius4 added a commit that referenced this issue Jun 9, 2021
With this change we fix an issue which caused a file not found error when trying to modify the file after it was renamed.

Closes #14255 and closes #21083
alan-agius4 added a commit that referenced this issue Jun 9, 2021
With this change we fix an issue which caused a file not found error when trying to modify the file after it was renamed.

Closes #14255 and closes #21083

(cherry picked from commit a30525b)
@angular-automatic-lock-bot
Copy link

This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

This action has been performed automatically by a bot.

@angular-automatic-lock-bot angular-automatic-lock-bot bot locked and limited conversation to collaborators Jul 10, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area: @angular-devkit/schematics freq1: low Only reported by a handful of users who observe it rarely severity3: broken type: bug/fix
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants