Repository navigation
With allowJs, process JS files found searching node_modules when they have a realpath outside node_modules
#56946
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
Andrew Branch (andrewbranch)
merged 5 commits into
microsoft:main
from
andrewbranch:allow-js-across-monorepo-packages
Jan 10, 2024
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
10be2c3
Process JS files found searching node_modules when they have a realpa…
andrewbranch b1b69c8
Fix import sort
andrewbranch 87fc159
Ensure imports in JS file are processed
andrewbranch ce1af6c
Also resolve from node_modules again and show types
andrewbranch ba79704
Add baselines
andrewbranch 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
22 changes: 22 additions & 0 deletions
22
tests/baselines/reference/allowJsCrossMonorepoPackage.symbols
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,22 @@ | ||
| //// [tests/cases/compiler/allowJsCrossMonorepoPackage.ts] //// | ||
|
|
||
| === /packages/main/index.ts === | ||
| import { x } from "shared"; | ||
| >x : Symbol(x, Decl(index.ts, 0, 8)) | ||
|
|
||
| === /node_modules/pkg/index.d.ts === | ||
| export declare function pkg(): "pkg"; | ||
| >pkg : Symbol(pkg, Decl(index.d.ts, 0, 0)) | ||
|
|
||
| === /packages/shared/utils.js === | ||
| export { pkg } from "pkg"; | ||
| >pkg : Symbol(pkg, Decl(utils.js, 0, 8)) | ||
|
|
||
| === /packages/shared/index.js === | ||
| import { pkg } from "./utils.js"; | ||
| >pkg : Symbol(pkg, Decl(index.js, 0, 8)) | ||
|
|
||
| export const x = pkg(); | ||
| >x : Symbol(x, Decl(index.js, 1, 12)) | ||
| >pkg : Symbol(pkg, Decl(index.js, 0, 8)) | ||
|
|
159 changes: 159 additions & 0 deletions
159
tests/baselines/reference/allowJsCrossMonorepoPackage.trace.json
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,159 @@ | ||
| [ | ||
| "======== Resolving module 'shared' from '/packages/main/index.ts'. ========", | ||
| "Explicitly specified module resolution kind: 'Bundler'.", | ||
| "Resolving in CJS mode with conditions 'import', 'types'.", | ||
| "Found 'package.json' at '/packages/main/package.json'.", | ||
| "Loading module 'shared' from 'node_modules' folder, target file types: TypeScript, JavaScript, Declaration, JSON.", | ||
| "Searching all ancestor node_modules directories for preferred extensions: TypeScript, Declaration.", | ||
| "Found 'package.json' at '/packages/main/node_modules/shared/package.json'.", | ||
| "Using 'exports' subpath '.' with target './index.js'.", | ||
| "File name '/packages/main/node_modules/shared/index.js' has a '.js' extension - stripping it.", | ||
| "File '/packages/main/node_modules/shared/index.ts' does not exist.", | ||
| "File '/packages/main/node_modules/shared/index.tsx' does not exist.", | ||
| "File '/packages/main/node_modules/shared/index.d.ts' does not exist.", | ||
| "Directory '/packages/main/node_modules/@types' does not exist, skipping all lookups in it.", | ||
| "Directory '/packages/node_modules' does not exist, skipping all lookups in it.", | ||
| "File '/node_modules/shared.ts' does not exist.", | ||
| "File '/node_modules/shared.tsx' does not exist.", | ||
| "File '/node_modules/shared.d.ts' does not exist.", | ||
| "Directory '/node_modules/@types' does not exist, skipping all lookups in it.", | ||
| "Searching all ancestor node_modules directories for fallback extensions: JavaScript, JSON.", | ||
| "File '/packages/main/node_modules/shared/package.json' exists according to earlier cached lookups.", | ||
| "Using 'exports' subpath '.' with target './index.js'.", | ||
| "File name '/packages/main/node_modules/shared/index.js' has a '.js' extension - stripping it.", | ||
| "File '/packages/main/node_modules/shared/index.js' exists - use it as a name resolution result.", | ||
| "Resolution of non-relative name failed; trying with modern Node resolution features disabled to see if npm library needs configuration update.", | ||
| "File '/packages/main/package.json' exists according to earlier cached lookups.", | ||
| "Loading module 'shared' from 'node_modules' folder, target file types: TypeScript, Declaration.", | ||
| "Searching all ancestor node_modules directories for preferred extensions: TypeScript, Declaration.", | ||
| "File '/packages/main/node_modules/shared/package.json' exists according to earlier cached lookups.", | ||
| "File '/packages/main/node_modules/shared.ts' does not exist.", | ||
| "File '/packages/main/node_modules/shared.tsx' does not exist.", | ||
| "File '/packages/main/node_modules/shared.d.ts' does not exist.", | ||
| "'package.json' does not have a 'typesVersions' field.", | ||
| "'package.json' does not have a 'typings' field.", | ||
| "'package.json' does not have a 'types' field.", | ||
| "'package.json' does not have a 'main' field.", | ||
| "File '/packages/main/node_modules/shared/index.ts' does not exist.", | ||
| "File '/packages/main/node_modules/shared/index.tsx' does not exist.", | ||
| "File '/packages/main/node_modules/shared/index.d.ts' does not exist.", | ||
| "Directory '/packages/main/node_modules/@types' does not exist, skipping all lookups in it.", | ||
| "Directory '/packages/node_modules' does not exist, skipping all lookups in it.", | ||
| "File '/node_modules/shared.ts' does not exist.", | ||
| "File '/node_modules/shared.tsx' does not exist.", | ||
| "File '/node_modules/shared.d.ts' does not exist.", | ||
| "Directory '/node_modules/@types' does not exist, skipping all lookups in it.", | ||
| "Resolving real path for '/packages/main/node_modules/shared/index.js', result '/packages/shared/index.js'.", | ||
| "======== Module name 'shared' was successfully resolved to '/packages/shared/index.js' with Package ID 'shared/index.js@1.0.0'. ========", | ||
| "======== Resolving module './utils.js' from '/packages/shared/index.js'. ========", | ||
| "Explicitly specified module resolution kind: 'Bundler'.", | ||
| "Resolving in CJS mode with conditions 'import', 'types'.", | ||
| "Loading module as file / folder, candidate module location '/packages/shared/utils.js', target file types: TypeScript, JavaScript, Declaration, JSON.", | ||
| "File name '/packages/shared/utils.js' has a '.js' extension - stripping it.", | ||
| "File '/packages/shared/utils.ts' does not exist.", | ||
| "File '/packages/shared/utils.tsx' does not exist.", | ||
| "File '/packages/shared/utils.d.ts' does not exist.", | ||
| "File '/packages/shared/utils.js' exists - use it as a name resolution result.", | ||
| "======== Module name './utils.js' was successfully resolved to '/packages/shared/utils.js'. ========", | ||
| "======== Resolving module 'pkg' from '/packages/shared/utils.js'. ========", | ||
| "Explicitly specified module resolution kind: 'Bundler'.", | ||
| "Resolving in CJS mode with conditions 'import', 'types'.", | ||
| "Found 'package.json' at '/packages/shared/package.json'.", | ||
| "Loading module 'pkg' from 'node_modules' folder, target file types: TypeScript, JavaScript, Declaration, JSON.", | ||
| "Searching all ancestor node_modules directories for preferred extensions: TypeScript, Declaration.", | ||
| "Directory '/packages/shared/node_modules' does not exist, skipping all lookups in it.", | ||
| "Directory '/packages/node_modules' does not exist, skipping all lookups in it.", | ||
| "File '/node_modules/pkg/package.json' does not exist.", | ||
| "File '/node_modules/pkg.ts' does not exist.", | ||
| "File '/node_modules/pkg.tsx' does not exist.", | ||
| "File '/node_modules/pkg.d.ts' does not exist.", | ||
| "File '/node_modules/pkg/index.ts' does not exist.", | ||
| "File '/node_modules/pkg/index.tsx' does not exist.", | ||
| "File '/node_modules/pkg/index.d.ts' exists - use it as a name resolution result.", | ||
| "Resolving real path for '/node_modules/pkg/index.d.ts', result '/node_modules/pkg/index.d.ts'.", | ||
| "======== Module name 'pkg' was successfully resolved to '/node_modules/pkg/index.d.ts'. ========", | ||
| "======== Resolving module '@typescript/lib-es5' from '/packages/main/__lib_node_modules_lookup_lib.es5.d.ts__.ts'. ========", | ||
| "Explicitly specified module resolution kind: 'Node10'.", | ||
| "Loading module '@typescript/lib-es5' from 'node_modules' folder, target file types: TypeScript, Declaration.", | ||
| "Searching all ancestor node_modules directories for preferred extensions: TypeScript, Declaration.", | ||
| "Directory '/packages/main/node_modules/@types' does not exist, skipping all lookups in it.", | ||
| "Scoped package detected, looking in 'typescript__lib-es5'", | ||
| "Directory '/packages/node_modules' does not exist, skipping all lookups in it.", | ||
| "Scoped package detected, looking in 'typescript__lib-es5'", | ||
| "Directory '/node_modules/@types' does not exist, skipping all lookups in it.", | ||
| "Scoped package detected, looking in 'typescript__lib-es5'", | ||
| "Loading module '@typescript/lib-es5' from 'node_modules' folder, target file types: JavaScript.", | ||
| "Searching all ancestor node_modules directories for fallback extensions: JavaScript.", | ||
| "Directory '/packages/node_modules' does not exist, skipping all lookups in it.", | ||
| "======== Module name '@typescript/lib-es5' was not resolved. ========", | ||
| "======== Resolving module '@typescript/lib-decorators' from '/packages/main/__lib_node_modules_lookup_lib.decorators.d.ts__.ts'. ========", | ||
| "Explicitly specified module resolution kind: 'Node10'.", | ||
| "Loading module '@typescript/lib-decorators' from 'node_modules' folder, target file types: TypeScript, Declaration.", | ||
| "Searching all ancestor node_modules directories for preferred extensions: TypeScript, Declaration.", | ||
| "Directory '/packages/main/node_modules/@types' does not exist, skipping all lookups in it.", | ||
| "Scoped package detected, looking in 'typescript__lib-decorators'", | ||
| "Directory '/packages/node_modules' does not exist, skipping all lookups in it.", | ||
| "Scoped package detected, looking in 'typescript__lib-decorators'", | ||
| "Directory '/node_modules/@types' does not exist, skipping all lookups in it.", | ||
| "Scoped package detected, looking in 'typescript__lib-decorators'", | ||
| "Loading module '@typescript/lib-decorators' from 'node_modules' folder, target file types: JavaScript.", | ||
| "Searching all ancestor node_modules directories for fallback extensions: JavaScript.", | ||
| "Directory '/packages/node_modules' does not exist, skipping all lookups in it.", | ||
| "======== Module name '@typescript/lib-decorators' was not resolved. ========", | ||
| "======== Resolving module '@typescript/lib-decorators/legacy' from '/packages/main/__lib_node_modules_lookup_lib.decorators.legacy.d.ts__.ts'. ========", | ||
| "Explicitly specified module resolution kind: 'Node10'.", | ||
| "Loading module '@typescript/lib-decorators/legacy' from 'node_modules' folder, target file types: TypeScript, Declaration.", | ||
| "Searching all ancestor node_modules directories for preferred extensions: TypeScript, Declaration.", | ||
| "Directory '/packages/main/node_modules/@types' does not exist, skipping all lookups in it.", | ||
| "Scoped package detected, looking in 'typescript__lib-decorators/legacy'", | ||
| "Directory '/packages/node_modules' does not exist, skipping all lookups in it.", | ||
| "Scoped package detected, looking in 'typescript__lib-decorators/legacy'", | ||
| "Directory '/node_modules/@types' does not exist, skipping all lookups in it.", | ||
| "Scoped package detected, looking in 'typescript__lib-decorators/legacy'", | ||
| "Loading module '@typescript/lib-decorators/legacy' from 'node_modules' folder, target file types: JavaScript.", | ||
| "Searching all ancestor node_modules directories for fallback extensions: JavaScript.", | ||
| "Directory '/packages/node_modules' does not exist, skipping all lookups in it.", | ||
| "======== Module name '@typescript/lib-decorators/legacy' was not resolved. ========", | ||
| "======== Resolving module '@typescript/lib-dom' from '/packages/main/__lib_node_modules_lookup_lib.dom.d.ts__.ts'. ========", | ||
| "Explicitly specified module resolution kind: 'Node10'.", | ||
| "Loading module '@typescript/lib-dom' from 'node_modules' folder, target file types: TypeScript, Declaration.", | ||
| "Searching all ancestor node_modules directories for preferred extensions: TypeScript, Declaration.", | ||
| "Directory '/packages/main/node_modules/@types' does not exist, skipping all lookups in it.", | ||
| "Scoped package detected, looking in 'typescript__lib-dom'", | ||
| "Directory '/packages/node_modules' does not exist, skipping all lookups in it.", | ||
| "Scoped package detected, looking in 'typescript__lib-dom'", | ||
| "Directory '/node_modules/@types' does not exist, skipping all lookups in it.", | ||
| "Scoped package detected, looking in 'typescript__lib-dom'", | ||
| "Loading module '@typescript/lib-dom' from 'node_modules' folder, target file types: JavaScript.", | ||
| "Searching all ancestor node_modules directories for fallback extensions: JavaScript.", | ||
| "Directory '/packages/node_modules' does not exist, skipping all lookups in it.", | ||
| "======== Module name '@typescript/lib-dom' was not resolved. ========", | ||
| "======== Resolving module '@typescript/lib-webworker/importscripts' from '/packages/main/__lib_node_modules_lookup_lib.webworker.importscripts.d.ts__.ts'. ========", | ||
| "Explicitly specified module resolution kind: 'Node10'.", | ||
| "Loading module '@typescript/lib-webworker/importscripts' from 'node_modules' folder, target file types: TypeScript, Declaration.", | ||
| "Searching all ancestor node_modules directories for preferred extensions: TypeScript, Declaration.", | ||
| "Directory '/packages/main/node_modules/@types' does not exist, skipping all lookups in it.", | ||
| "Scoped package detected, looking in 'typescript__lib-webworker/importscripts'", | ||
| "Directory '/packages/node_modules' does not exist, skipping all lookups in it.", | ||
| "Scoped package detected, looking in 'typescript__lib-webworker/importscripts'", | ||
| "Directory '/node_modules/@types' does not exist, skipping all lookups in it.", | ||
| "Scoped package detected, looking in 'typescript__lib-webworker/importscripts'", | ||
| "Loading module '@typescript/lib-webworker/importscripts' from 'node_modules' folder, target file types: JavaScript.", | ||
| "Searching all ancestor node_modules directories for fallback extensions: JavaScript.", | ||
| "Directory '/packages/node_modules' does not exist, skipping all lookups in it.", | ||
| "======== Module name '@typescript/lib-webworker/importscripts' was not resolved. ========", | ||
| "======== Resolving module '@typescript/lib-scripthost' from '/packages/main/__lib_node_modules_lookup_lib.scripthost.d.ts__.ts'. ========", | ||
| "Explicitly specified module resolution kind: 'Node10'.", | ||
| "Loading module '@typescript/lib-scripthost' from 'node_modules' folder, target file types: TypeScript, Declaration.", | ||
| "Searching all ancestor node_modules directories for preferred extensions: TypeScript, Declaration.", | ||
| "Directory '/packages/main/node_modules/@types' does not exist, skipping all lookups in it.", | ||
| "Scoped package detected, looking in 'typescript__lib-scripthost'", | ||
| "Directory '/packages/node_modules' does not exist, skipping all lookups in it.", | ||
| "Scoped package detected, looking in 'typescript__lib-scripthost'", | ||
| "Directory '/node_modules/@types' does not exist, skipping all lookups in it.", | ||
| "Scoped package detected, looking in 'typescript__lib-scripthost'", | ||
| "Loading module '@typescript/lib-scripthost' from 'node_modules' folder, target file types: JavaScript.", | ||
| "Searching all ancestor node_modules directories for fallback extensions: JavaScript.", | ||
| "Directory '/packages/node_modules' does not exist, skipping all lookups in it.", | ||
| "======== Module name '@typescript/lib-scripthost' was not resolved. ========" | ||
| ] |
23 changes: 23 additions & 0 deletions
23
tests/baselines/reference/allowJsCrossMonorepoPackage.types
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,23 @@ | ||
| //// [tests/cases/compiler/allowJsCrossMonorepoPackage.ts] //// | ||
|
|
||
| === /packages/main/index.ts === | ||
| import { x } from "shared"; | ||
| >x : "pkg" | ||
|
|
||
| === /node_modules/pkg/index.d.ts === | ||
| export declare function pkg(): "pkg"; | ||
| >pkg : () => "pkg" | ||
|
|
||
| === /packages/shared/utils.js === | ||
| export { pkg } from "pkg"; | ||
| >pkg : () => "pkg" | ||
|
|
||
| === /packages/shared/index.js === | ||
| import { pkg } from "./utils.js"; | ||
| >pkg : () => "pkg" | ||
|
|
||
| export const x = pkg(); | ||
| >x : "pkg" | ||
| >pkg() : "pkg" | ||
| >pkg : () => "pkg" | ||
|
|
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,44 @@ | ||
| // @Filename: /node_modules/pkg/index.d.ts | ||
| export declare function pkg(): "pkg"; | ||
|
|
||
| // @Filename: /packages/shared/package.json | ||
| { | ||
| "name": "shared", | ||
| "version": "1.0.0", | ||
| "type": "module", | ||
| "exports": "./index.js" | ||
| } | ||
|
|
||
| // @Filename: /packages/shared/utils.js | ||
| export { pkg } from "pkg"; | ||
|
|
||
| // @Filename: /packages/shared/index.js | ||
| import { pkg } from "./utils.js"; | ||
| export const x = pkg(); | ||
|
|
||
| // @Filename: /packages/main/package.json | ||
| { | ||
| "name": "main", | ||
| "version": "1.0.0", | ||
| "type": "module", | ||
| "dependencies": { | ||
| "shared": "workspace:*" | ||
| } | ||
| } | ||
|
|
||
| // @Filename: /packages/main/tsconfig.json | ||
| { | ||
| "compilerOptions": { | ||
| "noEmit": true, | ||
| "checkJs": true, | ||
| "strict": true, | ||
| "module": "esnext", | ||
| "moduleResolution": "bundler", | ||
| "traceResolution": true, | ||
| } | ||
| } | ||
|
|
||
| // @link: /packages/shared -> /packages/main/node_modules/shared | ||
|
|
||
| // @Filename: /packages/main/index.ts | ||
| import { x } from "shared"; |
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.
Uh oh!
There was an error while loading. Please reload this page.