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

fix(cdk/schematics): avoid runtime errors thrown by devkit tree when TypeScript tries non-existent path #22982

Merged
merged 1 commit into from Jun 16, 2021

Conversation

devversion
Copy link
Member

@devversion devversion commented Jun 15, 2021

TypeScript resolves modules using a rather complicated module
resolution algorithm. The algorithm tries various paths to
determine a possible entry-point for a module. e.g. it also
respects a containing package.json file, or respects the closest
node_modules parent directory.

In some situations, TypeScript could end up trying a path where
a parent directory segment resolves to an existent file. e.g.

consider the following directory structure:

node_modules/my-pkg/package.json
node_modules/my-pkg/styles.css

TypeScript could end up trying paths like: node_modules/my-pkg/styles.css/package.json or
node_modules/my-pkg/styles.css/a/b/package.json. This depends on how
the module resolution executes, and how the module is referenced.

In the example above though, TypeScript checks if the files exist. Our update
logic delegates this check to our virtual file system. The virtual file
system currently would throw an error by accident as it walks up the
path and discovers that styles.css is not a directory, but a file (https://github.com/angular/angular-cli/blob/master/packages/angular_devkit/schematics/src/tree/host-tree.ts#L321)

This results in an error as seen in
#22919. This seems to have been introduced
accidentally with #21161.

@devversion devversion added merge safe target: patch This PR is targeted for the next patch release labels Jun 15, 2021
@devversion devversion requested a review from crisbeto June 15, 2021 14:22
@google-cla google-cla bot added the cla: yes PR author has agreed to Google's Contributor License Agreement label Jun 15, 2021
Copy link
Member

@crisbeto crisbeto left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

src/cdk/schematics/update-tool/file-system.ts Outdated Show resolved Hide resolved
@devversion devversion added the action: merge The PR is ready for merge by the caretaker label Jun 15, 2021
TypeScript resolves modules using a rather complicated module
resolution algorithm. The algorithm tries various paths to
determine a possible entry-point for a module. e.g. it also
respects a containing `package.json` file, or respects the closest
`node_modules` parent directory.

In some situations, TypeScript could end up trying a path where
a parent directory segment resolves to an existent file. e.g.

consider the following directory structure:

```
node_modules/my-pkg/package.json
node_modules/my-pkg/styles.css
```

TypeScript could end up trying a path like:
`node_modules/my-pkg/styles.css/package.json` or
`node_modules/my-pkg/styles.css/a/b/package.json`. This depends on how
the module resolution executes, and how the module is referenced. In the
example above though, TypeScript checks if the files exist. Our update
logic delegates this check to our virtual file system. The virtual file
system currently would throw an error by accident as it walks up the
path and discovers that `styles.css` is not a directory, _but_ a file.

This results in an error as seen in
angular#22919.

Fixes angular#22919.
@wagnermaciel wagnermaciel merged commit 805d3ae into angular:master Jun 16, 2021
wagnermaciel pushed a commit that referenced this pull request Jun 16, 2021
TypeScript resolves modules using a rather complicated module
resolution algorithm. The algorithm tries various paths to
determine a possible entry-point for a module. e.g. it also
respects a containing `package.json` file, or respects the closest
`node_modules` parent directory.

In some situations, TypeScript could end up trying a path where
a parent directory segment resolves to an existent file. e.g.

consider the following directory structure:

```
node_modules/my-pkg/package.json
node_modules/my-pkg/styles.css
```

TypeScript could end up trying a path like:
`node_modules/my-pkg/styles.css/package.json` or
`node_modules/my-pkg/styles.css/a/b/package.json`. This depends on how
the module resolution executes, and how the module is referenced. In the
example above though, TypeScript checks if the files exist. Our update
logic delegates this check to our virtual file system. The virtual file
system currently would throw an error by accident as it walks up the
path and discovers that `styles.css` is not a directory, _but_ a file.

This results in an error as seen in
#22919.

Fixes #22919.

(cherry picked from commit 805d3ae)
@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 17, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
action: merge The PR is ready for merge by the caretaker cla: yes PR author has agreed to Google's Contributor License Agreement target: patch This PR is targeted for the next patch release
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants