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
Monorepository import support #33828
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM with a couple of requests.
packages/compiler-cli/src/ngtsc/file_system/testing/src/mock_file_system.ts
Outdated
Show resolved
Hide resolved
packages/compiler-cli/src/ngtsc/file_system/testing/src/mock_file_system.ts
Outdated
Show resolved
Hide resolved
new LogicalProjectStrategy(this.reflector, new LogicalFileSystem(this.rootDirs)); | ||
} else { | ||
// Plain relative imports are all that's needed. | ||
localImportStrategy = new RelativePathStrategy(this.reflector); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think you should be able to replace the LocigalProjectStrategy
with RelativePath
strategy within ngcc, as I recall there being a TODO there and this new strategy looks to implement exactly that.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You're right that there is. But looking at this makes me wonder.
Right now LogicalProjectStrategy
protects ngcc from emitting a relative import that points outside of the current entrypoint (and thus outside of the current package). This seems like it might be a reasonable assertion to make. I'll leave it as-is for now, and we can examine the tradeoffs here in another PR. I don't wanna couple this important fix to that decision.
28499d9
to
87aa0f7
Compare
This commit adds the ability to change directories using the compiler's internal filesystem abstraction. This is a prerequisite for writing tests which are sensitive to the current working directory. In addition to supporting the `chdir()` operation, this commit also fixes `getDefaultLibLocation()` for mock filesystems to not assume `node_modules` is in the current directory, but to resolve it similarly to how Node does by progressively looking higher in the directory tree.
Previously, the compiler assumed that all TS files logically within a project existed under one or more "root directories". If the TS compiler option `rootDir` or `rootDirs` was set, they would dictate the root directories in use, otherwise the current directory was used. Unfortunately this assumption was unfounded - it's common for projects without explicit `rootDirs` to import from files outside the current working directory. In such cases the `LogicalProjectStrategy` would attempt to generate imports into those files, and fail. This would lead to no `ReferenceEmitStrategy` being able to generate an import, and end in a compiler assertion failure. This commit introduces a new strategy to use when there are no `rootDirs` explicitly present, the `RelativePathStrategy`. It uses simpler, filesystem- relative paths to generate imports, even to files above the current working directory. Fixes angular#33659 Fixes angular#33562
87aa0f7
to
2662c77
Compare
Presubmit |
…3828) Previously, the compiler assumed that all TS files logically within a project existed under one or more "root directories". If the TS compiler option `rootDir` or `rootDirs` was set, they would dictate the root directories in use, otherwise the current directory was used. Unfortunately this assumption was unfounded - it's common for projects without explicit `rootDirs` to import from files outside the current working directory. In such cases the `LogicalProjectStrategy` would attempt to generate imports into those files, and fail. This would lead to no `ReferenceEmitStrategy` being able to generate an import, and end in a compiler assertion failure. This commit introduces a new strategy to use when there are no `rootDirs` explicitly present, the `RelativePathStrategy`. It uses simpler, filesystem- relative paths to generate imports, even to files above the current working directory. Fixes #33659 Fixes #33562 PR Close #33828
…33828) This commit adds the ability to change directories using the compiler's internal filesystem abstraction. This is a prerequisite for writing tests which are sensitive to the current working directory. In addition to supporting the `chdir()` operation, this commit also fixes `getDefaultLibLocation()` for mock filesystems to not assume `node_modules` is in the current directory, but to resolve it similarly to how Node does by progressively looking higher in the directory tree. PR Close #33828
…3828) Previously, the compiler assumed that all TS files logically within a project existed under one or more "root directories". If the TS compiler option `rootDir` or `rootDirs` was set, they would dictate the root directories in use, otherwise the current directory was used. Unfortunately this assumption was unfounded - it's common for projects without explicit `rootDirs` to import from files outside the current working directory. In such cases the `LogicalProjectStrategy` would attempt to generate imports into those files, and fail. This would lead to no `ReferenceEmitStrategy` being able to generate an import, and end in a compiler assertion failure. This commit introduces a new strategy to use when there are no `rootDirs` explicitly present, the `RelativePathStrategy`. It uses simpler, filesystem- relative paths to generate imports, even to files above the current working directory. Fixes #33659 Fixes #33562 PR Close #33828
This issue has been automatically locked due to inactivity. Read more about our automatic conversation locking policy. This action has been performed automatically by a bot. |
❤️