Skip to content

fix(core): avoid migration error when non-existent symbol is imported#36367

Closed
devversion wants to merge 1 commit intoangular:masterfrom
devversion:fix/migrations-do-not-throw-root-dirs
Closed

fix(core): avoid migration error when non-existent symbol is imported#36367
devversion wants to merge 1 commit intoangular:masterfrom
devversion:fix/migrations-do-not-throw-root-dirs

Conversation

@devversion
Copy link
Copy Markdown
Member

In rare cases a project with configured rootDirs that has imports to
non-existent identifiers could fail in the migration.

This happens because based on the application code, the migration could
end up trying to resolve the ts.Symbol of such non-existent
identifiers. This isn't a problem usually, but due to a upstream bug
in the TypeScript compiler, a runtime error is thrown.

This is because TypeScript is unable to compute a relative path from the
originating source file to the imported source file which should
provide the non-existent identifier. An issue for this has been reported
upstream: microsoft/TypeScript#37731. The
issue only surfaces since our migrations don't provide an absolute base
path that is used for resolving the root directories.

To fix this, we ensure that we never use relative paths when parsing
tsconfig files. More details can be found in the TS issue.

Fixes #36346.

@devversion devversion added area: migrations Issues related to `ng update`/`ng generate` migrations action: review The PR is still awaiting reviews from at least one requested reviewer target: patch This PR is targeted for the next patch release labels Apr 1, 2020
@ngbot ngbot bot modified the milestone: needsTriage Apr 1, 2020
@devversion devversion marked this pull request as ready for review April 1, 2020 13:10
@pullapprove pullapprove bot requested a review from kara April 1, 2020 13:10
@devversion devversion requested a review from crisbeto April 1, 2020 13:10
Copy link
Copy Markdown
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.

The changes LGTM, but I'm wondering whether we couldn't move the resolve call into a common place (e.g. where the new error was added). It seems like we're repeating it in several places and we could forget to add it in any new migrations.

@devversion devversion force-pushed the fix/migrations-do-not-throw-root-dirs branch from 6573756 to e5ce569 Compare April 2, 2020 08:35
@devversion
Copy link
Copy Markdown
Member Author

@crisbeto Agreed. I wanted to reduce the overall TS program duplication separately, but now did it in this PR. Can you please have another look?

@devversion devversion force-pushed the fix/migrations-do-not-throw-root-dirs branch from e5ce569 to f838c26 Compare April 2, 2020 09:02
Copy link
Copy Markdown
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 on the latest changes.

@devversion devversion added action: merge The PR is ready for merge by the caretaker and removed action: review The PR is still awaiting reviews from at least one requested reviewer labels Apr 2, 2020
Copy link
Copy Markdown
Contributor

@kara kara left a comment

Choose a reason for hiding this comment

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

LGTM

@kara
Copy link
Copy Markdown
Contributor

kara commented Apr 2, 2020

@devversion Can you rebase?

@kara kara added the action: cleanup The PR is in need of cleanup, either due to needing a rebase or in response to comments from reviews label Apr 2, 2020
@devversion devversion force-pushed the fix/migrations-do-not-throw-root-dirs branch from f838c26 to 9101561 Compare April 3, 2020 07:54
In rare cases a project with configured `rootDirs` that has imports to
non-existent identifiers could fail in the migration.

This happens because based on the application code, the migration could
end up trying to resolve the `ts.Symbol` of such non-existent
identifiers. This isn't a problem usually, but due to a upstream bug
in the TypeScript compiler, a runtime error is thrown.

This is because TypeScript is unable to compute a relative path from the
originating source file to the imported source file which _should_
provide the non-existent identifier. An issue for this has been reported
upstream: microsoft/TypeScript#37731. The
issue only surfaces since our migrations don't provide an absolute base
path that is used for resolving the root directories.

To fix this, we ensure that we never use relative paths when parsing
tsconfig files. More details can be found in the TS issue.

Fixes angular#36346.
@devversion devversion force-pushed the fix/migrations-do-not-throw-root-dirs branch from 9101561 to d7cfc9e Compare April 3, 2020 19:12
@devversion
Copy link
Copy Markdown
Member Author

devversion commented Apr 3, 2020

@kara Done. Thx for reviewing! Waiting for the PR to turn green.

@devversion devversion added merge: caretaker note Alert the caretaker performing the merge to check the PR for an out of normal action needed or note action: presubmit The PR is in need of a google3 presubmit and removed action: cleanup The PR is in need of cleanup, either due to needing a rebase or in response to comments from reviews labels Apr 3, 2020
@devversion
Copy link
Copy Markdown
Member Author

Caretaker: Can you please run presubmit for this? Thank you!

@kara
Copy link
Copy Markdown
Contributor

kara commented Apr 6, 2020

presubmit

@kara kara removed the action: presubmit The PR is in need of a google3 presubmit label Apr 6, 2020
kara pushed a commit that referenced this pull request Apr 6, 2020
…#36367)

In rare cases a project with configured `rootDirs` that has imports to
non-existent identifiers could fail in the migration.

This happens because based on the application code, the migration could
end up trying to resolve the `ts.Symbol` of such non-existent
identifiers. This isn't a problem usually, but due to a upstream bug
in the TypeScript compiler, a runtime error is thrown.

This is because TypeScript is unable to compute a relative path from the
originating source file to the imported source file which _should_
provide the non-existent identifier. An issue for this has been reported
upstream: microsoft/TypeScript#37731. The
issue only surfaces since our migrations don't provide an absolute base
path that is used for resolving the root directories.

To fix this, we ensure that we never use relative paths when parsing
tsconfig files. More details can be found in the TS issue.

Fixes #36346.

PR Close #36367
@kara kara closed this in d43c306 Apr 6, 2020
@angular-automatic-lock-bot
Copy link
Copy Markdown

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 May 7, 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 area: migrations Issues related to `ng update`/`ng generate` migrations cla: yes merge: caretaker note Alert the caretaker performing the merge to check the PR for an out of normal action needed or note target: patch This PR is targeted for the next patch release

Projects

None yet

Development

Successfully merging this pull request may close these issues.

ng update 8.0 to 9.1 fails during ModuleWithProviders migration

4 participants