-
Notifications
You must be signed in to change notification settings - Fork 13k
Fix auto-import when paths
points to project reference redirect
#51492
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
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
41 changes: 41 additions & 0 deletions
41
tests/cases/fourslash/server/autoImportCrossProject_baseUrl_toDist.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
/// <reference path="../fourslash.ts" /> | ||
|
||
// @Filename: /common/tsconfig.json | ||
//// { | ||
//// "compilerOptions": { | ||
//// "module": "commonjs", | ||
//// "outDir": "dist", | ||
//// "composite": true | ||
//// }, | ||
//// "include": ["src"] | ||
//// } | ||
|
||
// @Filename: /common/src/MyModule.ts | ||
//// export function square(n: number) { | ||
//// return n * 2; | ||
//// } | ||
|
||
// @Filename: /web/tsconfig.json | ||
//// { | ||
//// "compilerOptions": { | ||
//// "module": "esnext", | ||
//// "moduleResolution": "node", | ||
//// "noEmit": true, | ||
//// "baseUrl": "." | ||
//// }, | ||
//// "include": ["src"], | ||
//// "references": [{ "path": "../common" }] | ||
//// } | ||
|
||
// @Filename: /web/src/MyApp.ts | ||
//// import { square } from "../../common/dist/src/MyModule"; | ||
|
||
// @Filename: /web/src/Helper.ts | ||
//// export function saveMe() { | ||
//// square/**/(2); | ||
//// } | ||
|
||
goTo.file("/web/src/Helper.ts"); | ||
verify.importFixModuleSpecifiers("", ["../../common/src/MyModule"], { | ||
importModuleSpecifierPreference: "non-relative" | ||
}); |
43 changes: 43 additions & 0 deletions
43
tests/cases/fourslash/server/autoImportCrossProject_paths_toDist2.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
/// <reference path="../fourslash.ts" /> | ||
|
||
// @Filename: /common/tsconfig.json | ||
//// { | ||
//// "compilerOptions": { | ||
//// "module": "commonjs", | ||
//// "outDir": "dist", | ||
//// "composite": true | ||
//// }, | ||
//// "include": ["src"] | ||
//// } | ||
|
||
// @Filename: /common/src/MyModule.ts | ||
//// export function square(n: number) { | ||
//// return n * 2; | ||
//// } | ||
|
||
// @Filename: /web/tsconfig.json | ||
//// { | ||
//// "compilerOptions": { | ||
//// "module": "esnext", | ||
//// "moduleResolution": "node", | ||
//// "noEmit": true, | ||
//// "paths": { | ||
//// "@common/*": ["../common/dist/src/*"] | ||
//// } | ||
//// }, | ||
//// "include": ["src"], | ||
//// "references": [{ "path": "../common" }] | ||
//// } | ||
|
||
// @Filename: /web/src/MyApp.ts | ||
//// import { square } from "@common/MyModule"; | ||
|
||
// @Filename: /web/src/Helper.ts | ||
//// export function saveMe() { | ||
//// square/**/(2); | ||
//// } | ||
|
||
goTo.file("/web/src/Helper.ts"); | ||
verify.importFixModuleSpecifiers("", ["@common/MyModule"], { | ||
importModuleSpecifierPreference: "non-relative" | ||
}); |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Offtopic question: I was actually exploring using exactly this structure in one of the projects. However, I only want this because Remix doesn't allow me to alias paths - but it can infer aliases from the
compilerOptions.paths
.I wonder what are the pros/cons of this structure. I guess that in this test case here it might be required to use non-relative paths as
/common/
isn't actually symlinked as a monorepo package. However, when referenced projects are symlinked in node_modules, I expect this to be unnecessary and less performant. In the IDE this might be roughly the same thanks to "behind-the-scenes in-memory .d.ts generation process" but when runningtsc -b
this might not be able to actually leverage the generated.d.ts
files as thepaths
map to/src/
, right?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.
Well, in this example
paths
map todist
(the original repro didn’t set arootDir
so the output is indist/src
and I kept that quirk in the test). But IIRC whether you map to the inputs or outputs of a referenced project, TypeScript understands what you’re doing and tsc will find the.d.ts
outputs and the language service will find the.ts
inputs.