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(core): fix module resolution in project locator #2941

Merged
merged 1 commit into from May 24, 2020

Conversation

rhutchison
Copy link
Contributor

@rhutchison rhutchison commented Apr 30, 2020

On windows, there is a bug in project module resolution, caused by path separator. TypeScript resolveModuleName will always return a posix normalized path, so our appRootPath needs to be normalized for string replacement.

I came across the issue when trying to run dep-graph, but other areas (ex: affected:*) which rely on TargetProjectLocator are going to be impacted.

findProjectWithImport is using typescript utils to resolve modules by import expressions. appRootPath on windows is using the windows separator \, while TypeScript resolveModuleName is returning a module with resolvedFileName containing posix separator /.

Since (angular.json) project root path's are relative, the condition is not met, and it relies on npmScope -

if (resolvedModule && resolvedModule.startsWith(p.data.root)) {

Current Behavior (This is the behavior we have today, before the PR is merged)

resolveModuleByImport returns project files with absolute path.

Expected Behavior (This is the new behavior we can expect after the PR is merged)

resolveModuleByImport should return project files with relative path (appRootPath removed).

Issue

I have not tested, but these might be related:

#2472

#2820

On windows, there is a bug in project module resolution, cause by path separator.  TypeScript resolveModuleName will always return a posix normalized path, so our appRootPath needs to be normalized for string replacement.

I came across the issue when trying to run dep-graph, but other areas (ex: affected:*) which rely on TargetProjectLocator are going to be impacted.
@FrozenPandaz
Copy link
Collaborator

FrozenPandaz commented May 1, 2020

Thanks for the fix!

I think this normalization should happen in https://github.com/nrwl/nx/blob/master/packages/workspace/src/utils/app-root.ts#L4 (as dictated by a todo comment by @vsavkin 😅.)

Can you please look into moving the normalization there so that the path is normalized for every usage of appRootPath?

@FrozenPandaz FrozenPandaz self-requested a review May 1, 2020 14:38
@rhutchison
Copy link
Contributor Author

rhutchison commented May 1, 2020

I think this normalization should happen in https://github.com/nrwl/nx/blob/master/packages/workspace/src/utils/app-root.ts#L4 (as dictated by a todo comment by @vsavkin 😅.)

Can you please look into moving the normalization there so that the path is normalized for every usage of appRootPath?

I did come across that, but I feel a change there would be too risky. The Windows -> POSIX separator replacement is only necessary to do string replacement. If we normalize appRoot to use POSIX separator everywhere, there might be further implications for the rest of the app. @FrozenPandaz @vsavkin thoughts?

@rhutchison rhutchison changed the title [WIP] fix(core): fix module resolution in project locator fix(core): fix module resolution in project locator May 15, 2020
@rhutchison rhutchison marked this pull request as ready for review May 15, 2020 02:09
@rhutchison
Copy link
Contributor Author

Resolves #2955

Closes #3028

Copy link
Collaborator

@FrozenPandaz FrozenPandaz left a comment

Choose a reason for hiding this comment

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

Thank you for your contribution! LGTM!

@FrozenPandaz FrozenPandaz merged commit b5025ef into nrwl:master May 24, 2020
FrozenPandaz pushed a commit that referenced this pull request May 24, 2020
On windows, there is a bug in project module resolution, cause by path separator.  TypeScript resolveModuleName will always return a posix normalized path, so our appRootPath needs to be normalized for string replacement.

I came across the issue when trying to run dep-graph, but other areas (ex: affected:*) which rely on TargetProjectLocator are going to be impacted.
@rhutchison rhutchison deleted the fix/windows-project-locator branch November 23, 2021 17:10
@github-actions
Copy link

This pull request has already been merged/closed. If you experience issues related to these changes, please open a new issue referencing this pull request.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Mar 19, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants