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

Always use resolved file to figure out subModule name in package id #31541

Merged
merged 3 commits into from May 23, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
14 changes: 9 additions & 5 deletions src/compiler/diagnosticMessages.json
Expand Up @@ -3811,10 +3811,6 @@
"category": "Error",
"code": 6189
},
"Found 'package.json' at '{0}'. Package ID is '{1}'.": {
"category": "Message",
"code": 6190
},
"Whether to keep outdated console output in watch mode instead of clearing the screen.": {
"category": "Message",
"code": 6191
Expand Down Expand Up @@ -3923,6 +3919,14 @@
"category": "Message",
"code": 6217
},
"======== Module name '{0}' was successfully resolved to '{1}' with Package ID '{2}'. ========": {
"category": "Message",
"code": 6218
},
"======== Type reference directive '{0}' was successfully resolved to '{1}' with Package ID '{2}', primary: {3}. ========": {
"category": "Message",
"code": 6219
},

"Projects to reference": {
"category": "Message",
Expand Down Expand Up @@ -4975,7 +4979,7 @@
"code": 95079
},

"No value exists in scope for the shorthand property '{0}'. Either declare one or provide an initializer." :{
"No value exists in scope for the shorthand property '{0}'. Either declare one or provide an initializer.": {
"category": "Error",
"code": 18004
},
Expand Down
150 changes: 65 additions & 85 deletions src/compiler/moduleNameResolver.ts

Large diffs are not rendered by default.

Expand Up @@ -2,13 +2,13 @@
"======== Resolving module 'foo/use' from '/index.ts'. ========",
"Module resolution kind is not specified, using 'NodeJs'.",
"Loading module 'foo/use' from 'node_modules' folder, target file type 'TypeScript'.",
"Found 'package.json' at '/node_modules/foo/package.json'.",
"'package.json' does not have a 'typesVersions' field.",
"Found 'package.json' at '/node_modules/foo/package.json'. Package ID is 'foo/use/index.d.ts@1.2.3'.",
"File '/node_modules/foo/use.ts' does not exist.",
"File '/node_modules/foo/use.tsx' does not exist.",
"File '/node_modules/foo/use.d.ts' exist - use it as a name resolution result.",
"Resolving real path for '/node_modules/foo/use.d.ts', result '/node_modules/foo/use.d.ts'.",
"======== Module name 'foo/use' was successfully resolved to '/node_modules/foo/use.d.ts'. ========",
"======== Module name 'foo/use' was successfully resolved to '/node_modules/foo/use.d.ts' with Package ID 'foo/use.d.ts@1.2.3'. ========",
"======== Resolving module 'a' from '/index.ts'. ========",
"Module resolution kind is not specified, using 'NodeJs'.",
"Loading module 'a' from 'node_modules' folder, target file type 'TypeScript'.",
Expand All @@ -27,17 +27,14 @@
"File '/node_modules/foo/index.ts' does not exist.",
"File '/node_modules/foo/index.tsx' does not exist.",
"File '/node_modules/foo/index.d.ts' exist - use it as a name resolution result.",
"Found 'package.json' at '/node_modules/foo/package.json'.",
"'package.json' does not have a 'typesVersions' field.",
"Found 'package.json' at '/node_modules/foo/package.json'. Package ID is 'foo/index.d.ts@1.2.3'.",
"======== Module name './index' was successfully resolved to '/node_modules/foo/index.d.ts'. ========",
"======== Module name './index' was successfully resolved to '/node_modules/foo/index.d.ts' with Package ID 'foo/index.d.ts@1.2.3'. ========",
"======== Resolving module 'foo' from '/node_modules/a/index.d.ts'. ========",
"Module resolution kind is not specified, using 'NodeJs'.",
"Loading module 'foo' from 'node_modules' folder, target file type 'TypeScript'.",
"'package.json' does not have a 'typings' field.",
"'package.json' does not have a 'types' field.",
"'package.json' does not have a 'main' field.",
"Found 'package.json' at '/node_modules/a/node_modules/foo/package.json'.",
"'package.json' does not have a 'typesVersions' field.",
"Found 'package.json' at '/node_modules/a/node_modules/foo/package.json'. Package ID is 'foo/index.d.ts@1.2.3'.",
"File '/node_modules/a/node_modules/foo.ts' does not exist.",
"File '/node_modules/a/node_modules/foo.tsx' does not exist.",
"File '/node_modules/a/node_modules/foo.d.ts' does not exist.",
Expand All @@ -48,5 +45,5 @@
"File '/node_modules/a/node_modules/foo/index.tsx' does not exist.",
"File '/node_modules/a/node_modules/foo/index.d.ts' exist - use it as a name resolution result.",
"Resolving real path for '/node_modules/a/node_modules/foo/index.d.ts', result '/node_modules/a/node_modules/foo/index.d.ts'.",
"======== Module name 'foo' was successfully resolved to '/node_modules/a/node_modules/foo/index.d.ts'. ========"
"======== Module name 'foo' was successfully resolved to '/node_modules/a/node_modules/foo/index.d.ts' with Package ID 'foo/index.d.ts@1.2.3'. ========"
]
Expand Up @@ -2,13 +2,13 @@
"======== Resolving module '@foo/bar/use' from '/index.ts'. ========",
"Module resolution kind is not specified, using 'NodeJs'.",
"Loading module '@foo/bar/use' from 'node_modules' folder, target file type 'TypeScript'.",
"Found 'package.json' at '/node_modules/@foo/bar/package.json'.",
"'package.json' does not have a 'typesVersions' field.",
"Found 'package.json' at '/node_modules/@foo/bar/package.json'. Package ID is '@foo/bar/use/index.d.ts@1.2.3'.",
"File '/node_modules/@foo/bar/use.ts' does not exist.",
"File '/node_modules/@foo/bar/use.tsx' does not exist.",
"File '/node_modules/@foo/bar/use.d.ts' exist - use it as a name resolution result.",
"Resolving real path for '/node_modules/@foo/bar/use.d.ts', result '/node_modules/@foo/bar/use.d.ts'.",
"======== Module name '@foo/bar/use' was successfully resolved to '/node_modules/@foo/bar/use.d.ts'. ========",
"======== Module name '@foo/bar/use' was successfully resolved to '/node_modules/@foo/bar/use.d.ts' with Package ID '@foo/bar/use.d.ts@1.2.3'. ========",
"======== Resolving module 'a' from '/index.ts'. ========",
"Module resolution kind is not specified, using 'NodeJs'.",
"Loading module 'a' from 'node_modules' folder, target file type 'TypeScript'.",
Expand All @@ -27,17 +27,14 @@
"File '/node_modules/@foo/bar/index.ts' does not exist.",
"File '/node_modules/@foo/bar/index.tsx' does not exist.",
"File '/node_modules/@foo/bar/index.d.ts' exist - use it as a name resolution result.",
"Found 'package.json' at '/node_modules/@foo/bar/package.json'.",
"'package.json' does not have a 'typesVersions' field.",
"Found 'package.json' at '/node_modules/@foo/bar/package.json'. Package ID is '@foo/bar/index.d.ts@1.2.3'.",
"======== Module name './index' was successfully resolved to '/node_modules/@foo/bar/index.d.ts'. ========",
"======== Module name './index' was successfully resolved to '/node_modules/@foo/bar/index.d.ts' with Package ID '@foo/bar/index.d.ts@1.2.3'. ========",
"======== Resolving module '@foo/bar' from '/node_modules/a/index.d.ts'. ========",
"Module resolution kind is not specified, using 'NodeJs'.",
"Loading module '@foo/bar' from 'node_modules' folder, target file type 'TypeScript'.",
"'package.json' does not have a 'typings' field.",
"'package.json' does not have a 'types' field.",
"'package.json' does not have a 'main' field.",
"Found 'package.json' at '/node_modules/a/node_modules/@foo/bar/package.json'.",
"'package.json' does not have a 'typesVersions' field.",
"Found 'package.json' at '/node_modules/a/node_modules/@foo/bar/package.json'. Package ID is '@foo/bar/index.d.ts@1.2.3'.",
"File '/node_modules/a/node_modules/@foo/bar.ts' does not exist.",
"File '/node_modules/a/node_modules/@foo/bar.tsx' does not exist.",
"File '/node_modules/a/node_modules/@foo/bar.d.ts' does not exist.",
Expand All @@ -48,5 +45,5 @@
"File '/node_modules/a/node_modules/@foo/bar/index.tsx' does not exist.",
"File '/node_modules/a/node_modules/@foo/bar/index.d.ts' exist - use it as a name resolution result.",
"Resolving real path for '/node_modules/a/node_modules/@foo/bar/index.d.ts', result '/node_modules/a/node_modules/@foo/bar/index.d.ts'.",
"======== Module name '@foo/bar' was successfully resolved to '/node_modules/a/node_modules/@foo/bar/index.d.ts'. ========"
"======== Module name '@foo/bar' was successfully resolved to '/node_modules/a/node_modules/@foo/bar/index.d.ts' with Package ID '@foo/bar/index.d.ts@1.2.3'. ========"
]
6 changes: 2 additions & 4 deletions tests/baselines/reference/library-reference-10.trace.json
@@ -1,18 +1,16 @@
[
"======== Resolving type reference directive 'jquery', containing file '/foo/consumer.ts', root directory './types'. ========",
"Resolving with primary search path './types'.",
"'package.json' has 'typings' field 'jquery.d.ts' that references 'types/jquery/jquery.d.ts'.",
"'package.json' does not have a 'typesVersions' field.",
"Found 'package.json' at './types/jquery/package.json'.",
"'package.json' does not have a 'typesVersions' field.",
"'package.json' has 'typings' field 'jquery.d.ts' that references 'types/jquery/jquery.d.ts'.",
"File 'types/jquery/jquery.d.ts' exist - use it as a name resolution result.",
"Resolving real path for 'types/jquery/jquery.d.ts', result '/foo/types/jquery/jquery.d.ts'.",
"======== Type reference directive 'jquery' was successfully resolved to '/foo/types/jquery/jquery.d.ts', primary: true. ========",
"======== Resolving type reference directive 'jquery', containing file '/foo/__inferred type names__.ts', root directory './types'. ========",
"Resolving with primary search path './types'.",
"'package.json' has 'typings' field 'jquery.d.ts' that references 'types/jquery/jquery.d.ts'.",
"'package.json' does not have a 'typesVersions' field.",
"Found 'package.json' at './types/jquery/package.json'.",
"'package.json' does not have a 'typesVersions' field.",
"'package.json' has 'typings' field 'jquery.d.ts' that references 'types/jquery/jquery.d.ts'.",
"File 'types/jquery/jquery.d.ts' exist - use it as a name resolution result.",
"Resolving real path for 'types/jquery/jquery.d.ts', result '/foo/types/jquery/jquery.d.ts'.",
Expand Down
3 changes: 1 addition & 2 deletions tests/baselines/reference/library-reference-11.trace.json
Expand Up @@ -3,9 +3,8 @@
"Root directory cannot be determined, skipping primary search paths.",
"Looking up in 'node_modules' folder, initial location '/a/b'.",
"Directory '/a/b/node_modules' does not exist, skipping all lookups in it.",
"'package.json' has 'typings' field 'jquery.d.ts' that references '/a/node_modules/jquery/jquery.d.ts'.",
"'package.json' does not have a 'typesVersions' field.",
"Found 'package.json' at '/a/node_modules/jquery/package.json'.",
"'package.json' does not have a 'typesVersions' field.",
"File '/a/node_modules/jquery.d.ts' does not exist.",
"'package.json' has 'typings' field 'jquery.d.ts' that references '/a/node_modules/jquery/jquery.d.ts'.",
"File '/a/node_modules/jquery/jquery.d.ts' exist - use it as a name resolution result.",
Expand Down
4 changes: 1 addition & 3 deletions tests/baselines/reference/library-reference-12.trace.json
Expand Up @@ -3,10 +3,8 @@
"Root directory cannot be determined, skipping primary search paths.",
"Looking up in 'node_modules' folder, initial location '/a/b'.",
"Directory '/a/b/node_modules' does not exist, skipping all lookups in it.",
"'package.json' does not have a 'typings' field.",
"'package.json' has 'types' field 'dist/jquery.d.ts' that references '/a/node_modules/jquery/dist/jquery.d.ts'.",
"'package.json' does not have a 'typesVersions' field.",
"Found 'package.json' at '/a/node_modules/jquery/package.json'.",
"'package.json' does not have a 'typesVersions' field.",
"File '/a/node_modules/jquery.d.ts' does not exist.",
"'package.json' does not have a 'typings' field.",
"'package.json' has 'types' field 'dist/jquery.d.ts' that references '/a/node_modules/jquery/dist/jquery.d.ts'.",
Expand Down
8 changes: 2 additions & 6 deletions tests/baselines/reference/library-reference-2.trace.json
@@ -1,21 +1,17 @@
[
"======== Resolving type reference directive 'jquery', containing file '/consumer.ts', root directory '/types'. ========",
"Resolving with primary search path '/types'.",
"'package.json' does not have a 'typings' field.",
"'package.json' has 'types' field 'jquery.d.ts' that references '/types/jquery/jquery.d.ts'.",
"'package.json' does not have a 'typesVersions' field.",
"Found 'package.json' at '/types/jquery/package.json'.",
"'package.json' does not have a 'typesVersions' field.",
"'package.json' does not have a 'typings' field.",
"'package.json' has 'types' field 'jquery.d.ts' that references '/types/jquery/jquery.d.ts'.",
"File '/types/jquery/jquery.d.ts' exist - use it as a name resolution result.",
"Resolving real path for '/types/jquery/jquery.d.ts', result '/types/jquery/jquery.d.ts'.",
"======== Type reference directive 'jquery' was successfully resolved to '/types/jquery/jquery.d.ts', primary: true. ========",
"======== Resolving type reference directive 'jquery', containing file '/test/__inferred type names__.ts', root directory '/types'. ========",
"Resolving with primary search path '/types'.",
"'package.json' does not have a 'typings' field.",
"'package.json' has 'types' field 'jquery.d.ts' that references '/types/jquery/jquery.d.ts'.",
"'package.json' does not have a 'typesVersions' field.",
"Found 'package.json' at '/types/jquery/package.json'.",
"'package.json' does not have a 'typesVersions' field.",
"'package.json' does not have a 'typings' field.",
"'package.json' has 'types' field 'jquery.d.ts' that references '/types/jquery/jquery.d.ts'.",
"File '/types/jquery/jquery.d.ts' exist - use it as a name resolution result.",
Expand Down
@@ -0,0 +1,44 @@
//// [tests/cases/compiler/moduleResolutionPackageIdWithRelativeAndAbsolutePath.ts] ////

//// [package.json]
{
"name": "troublesome-lib",
"version": "1.17.1"
}
//// [Compactable.d.ts]
import { Option } from './Option';
export class Compactable {
option: Option;
}
//// [Option.d.ts]
export class Option {
someProperty: string;
}
//// [app.d.ts]
import { Option } from "troublesome-lib/lib/Option";
export class SharedOption extends Option { }
export const makeSharedOption: () => SharedOption;
//// [index.d.ts]
import { Compactable } from "troublesome-lib/lib/Compactable"; // Including this will resolve Option as relative through the imports of compactable
//// [package.json]
{
"name": "troublesome-lib",
"version": "1.17.1"
}
//// [Compactable.d.ts]
import { Option } from './Option';
export class Compactable {
option: Option;
}
//// [Option.d.ts]
export class Option {
someProperty: string;
}
//// [app.ts]
import * as t from "anotherLib"; // Include the lib that recursively includes option as relative module resolution in this directory
import { makeSharedOption } from "@shared/lib/app"; // Includes option as module in shared folder but as module in node_modules folder


//// [/project/src/app.js]
"use strict";
exports.__esModule = true;
@@ -0,0 +1,48 @@
=== /project/src/app.ts ===
import * as t from "anotherLib"; // Include the lib that recursively includes option as relative module resolution in this directory
>t : Symbol(t, Decl(app.ts, 0, 6))

import { makeSharedOption } from "@shared/lib/app"; // Includes option as module in shared folder but as module in node_modules folder
>makeSharedOption : Symbol(makeSharedOption, Decl(app.ts, 1, 8))

=== /shared/node_modules/troublesome-lib/lib/Option.d.ts ===
export class Option {
>Option : Symbol(Option, Decl(Option.d.ts, 0, 0))

someProperty: string;
>someProperty : Symbol(Option.someProperty, Decl(Option.d.ts, 0, 21))
}
=== /shared/lib/app.d.ts ===
import { Option } from "troublesome-lib/lib/Option";
>Option : Symbol(Option, Decl(app.d.ts, 0, 8))

export class SharedOption extends Option { }
>SharedOption : Symbol(SharedOption, Decl(app.d.ts, 0, 52))
>Option : Symbol(Option, Decl(app.d.ts, 0, 8))

export const makeSharedOption: () => SharedOption;
>makeSharedOption : Symbol(makeSharedOption, Decl(app.d.ts, 2, 12))
>SharedOption : Symbol(SharedOption, Decl(app.d.ts, 0, 52))

=== /project/node_modules/anotherLib/index.d.ts ===
import { Compactable } from "troublesome-lib/lib/Compactable"; // Including this will resolve Option as relative through the imports of compactable
>Compactable : Symbol(Compactable, Decl(index.d.ts, 0, 8))

=== /project/node_modules/troublesome-lib/lib/Compactable.d.ts ===
import { Option } from './Option';
>Option : Symbol(Option, Decl(Compactable.d.ts, 0, 8))

export class Compactable {
>Compactable : Symbol(Compactable, Decl(Compactable.d.ts, 0, 34))

option: Option;
>option : Symbol(Compactable.option, Decl(Compactable.d.ts, 1, 26))
>Option : Symbol(Option, Decl(Compactable.d.ts, 0, 8))
}
=== /project/node_modules/troublesome-lib/lib/Option.d.ts ===
export class Option {
>Option : Symbol(Option, Decl(Option.d.ts, 0, 0))

someProperty: string;
>someProperty : Symbol(Option.someProperty, Decl(Option.d.ts, 0, 21))
}