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(ng-update): properly handle update from different working directory #19934

Conversation

devversion
Copy link
Member

In some situations, developers will run ng update from a sub directory
of the project. This currently results in a noop migration as file
system paths were computed incorrectly. This is because ng-update
always assumed that the CWD is the workspace root in the real file
system. This is not the case and therefore threw off path resolution.

We fix this by fully relying on the virtual file system now. Previously
we mixed virtual and real file system as TypeScript relied on the
real file system for parsing configuration, matching and reading files.

This commit adds a new compiler host for config parsing and program
creation that works fully with a virtual file system. This is something
we had planned a long time ago as schematics should never deal with
the real file system. We can re-use this logic in other repositories
too (such as Angular framework, potentially the CLI, and universal
schematics). Ideally we will share this as part of better tooling for
migrations.

Fixes #19779. Resolves COMP-387.

@googlebot googlebot added the cla: yes PR author has agreed to Google's Contributor License Agreement label Jul 10, 2020
@devversion devversion force-pushed the fix/properly-handle-ng-update-from-different-working-dir branch 2 times, most recently from d41fd2c to 841ea3a Compare July 10, 2020 09:55
@devversion devversion added merge safe target: patch This PR is targeted for the next patch release labels Jul 10, 2020
@devversion devversion force-pushed the fix/properly-handle-ng-update-from-different-working-dir branch from 841ea3a to ce40cfd Compare July 10, 2020 18:11
@devversion devversion added the merge: preserve commits When the PR is merged, a rebase and merge should be performed label Jul 10, 2020
@devversion devversion marked this pull request as ready for review July 10, 2020 18:12
@devversion devversion requested a review from jelbourn as a code owner July 10, 2020 18:12
src/cdk/schematics/ng-update/devkit-file-system.ts Outdated Show resolved Hide resolved
src/cdk/schematics/ng-update/devkit-file-system.ts Outdated Show resolved Hide resolved
src/cdk/schematics/ng-update/find-stylesheets.ts Outdated Show resolved Hide resolved
src/cdk/schematics/ng-update/find-stylesheets.ts Outdated Show resolved Hide resolved
src/cdk/schematics/ng-update/find-stylesheets.ts Outdated Show resolved Hide resolved
}

readDirectory(dirPath: Path): DirectoryEntry {
const {subdirs: directories, subfiles: files} = this._tree.getDir(dirPath);
Copy link
Member

Choose a reason for hiding this comment

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

Not something we control, but it's a little weird for this to be called "sub files" since all files are nested in each other. Maybe we can change it if we're changing other things.

Copy link
Member Author

Choose a reason for hiding this comment

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

Yeah, it's definitely a bit ambiguous. You mean that we create a proposal upstream for them to change it?

In some situations, developers will run `ng update` from a sub directory
of the project. This currently results in a noop migration as file
system paths were computed incorrectly. This is because ng-update
always assumed that the CWD is the workspace root in the real file
system. This is not the case and therefore threw off path resolution.

We fix this by fully relying on the virtual file system now. Previously
we mixed virtual and real file system as TypeScript relied on the
real file system for parsing configuration, matching and reading files.

This commit adds a new compiler host for config parsing and program
creation that works fully with a virtual file system. This is something
we had planned a long time ago as schematics should never deal with
the real file system. We can re-use this logic in other repositories
too (such as Angular framework, potentially the CLI, and universal
schematics). Ideally we will share this as part of better tooling for
migrations.

Fixes angular#19779.
…lesheets

Previously we globbed the project directory for global stylesheets
per target of a project. This is unnecessary and slowing down
the update as the project root remains the same across arbitrary
targets.
@devversion devversion force-pushed the fix/properly-handle-ng-update-from-different-working-dir branch from ce40cfd to 196feda Compare July 10, 2020 20:11
@devversion
Copy link
Member Author

@crisbeto I've addressed the feedback. Thanks!

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

@crisbeto crisbeto added lgtm action: merge The PR is ready for merge by the caretaker labels Jul 10, 2020
@mmalerba mmalerba merged commit b441bdf into angular:master Jul 11, 2020
@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 Aug 11, 2020
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 merge: preserve commits When the PR is merged, a rebase and merge should be performed target: patch This PR is targeted for the next patch release
Projects
None yet
Development

Successfully merging this pull request may close these issues.

bug(cdk): Update Failed : Cannot read property 'length' of null
5 participants