Skip to content

Log packageId in --traceResolution #21233

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
1 commit merged into from
Jan 17, 2018
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/compiler/diagnosticMessages.json
Original file line number Diff line number Diff line change
Expand Up @@ -3451,6 +3451,10 @@
"category": "Error",
"code": 6189
},
"Found 'package.json' at '{0}'. Package ID is '{1}'.": {
"category": "Message",
"code": 6190
},
"Variable '{0}' implicitly has an '{1}' type.": {
"category": "Error",
"code": 7005
Expand Down
11 changes: 8 additions & 3 deletions src/compiler/moduleNameResolver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -960,13 +960,18 @@ namespace ts {
const directoryExists = !onlyRecordFailures && directoryProbablyExists(nodeModuleDirectory, host);
const packageJsonPath = pathToPackageJson(nodeModuleDirectory);
if (directoryExists && host.fileExists(packageJsonPath)) {
if (traceEnabled) {
trace(host, Diagnostics.Found_package_json_at_0, packageJsonPath);
}
const packageJsonContent = readJson(packageJsonPath, host);
const packageId: PackageId = typeof packageJsonContent.name === "string" && typeof packageJsonContent.version === "string"
? { name: packageJsonContent.name, subModuleName, version: packageJsonContent.version }
: undefined;
if (traceEnabled) {
if (packageId) {
trace(host, Diagnostics.Found_package_json_at_0_Package_ID_is_1, packageJsonPath, packageIdToString(packageId));
}
else {
trace(host, Diagnostics.Found_package_json_at_0, packageJsonPath);
}
}
return { found: true, packageJsonContent, packageId };
}
else {
Expand Down
2 changes: 1 addition & 1 deletion src/compiler/program.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1817,7 +1817,7 @@ namespace ts {
}, shouldCreateNewSourceFile);

if (packageId) {
const packageIdKey = `${packageId.name}/${packageId.subModuleName}@${packageId.version}`;
const packageIdKey = packageIdToString(packageId);
const fileFromPackageId = packageIdToSourceFile.get(packageIdKey);
if (fileFromPackageId) {
// Some other SourceFile already exists with this package name and version.
Expand Down
5 changes: 5 additions & 0 deletions src/compiler/utilities.ts
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,11 @@ namespace ts {
return a === b || a && b && a.name === b.name && a.subModuleName === b.subModuleName && a.version === b.version;
}

export function packageIdToString({ name, subModuleName, version }: PackageId): string {
const fullName = subModuleName ? `${name}/${subModuleName}` : name;
return `${fullName}@${version}`;
}

export function typeDirectiveIsEqualTo(oldResolution: ResolvedTypeReferenceDirective, newResolution: ResolvedTypeReferenceDirective): boolean {
return oldResolution.resolvedFileName === newResolution.resolvedFileName && oldResolution.primary === newResolution.primary;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"======== 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'.",
"Found 'package.json' at '/node_modules/foo/package.json'. Package ID is 'foo/[email protected]'.",
"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.",
Expand All @@ -26,12 +26,12 @@
"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'.",
"Found 'package.json' at '/node_modules/foo/package.json'. Package ID is '[email protected]'.",
"======== Module name './index' was successfully resolved to '/node_modules/foo/index.d.ts'. ========",
"======== 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'.",
"Found 'package.json' at '/node_modules/a/node_modules/foo/package.json'.",
"Found 'package.json' at '/node_modules/a/node_modules/foo/package.json'. Package ID is '[email protected]'.",
"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 Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"======== 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'.",
"Found 'package.json' at '/node_modules/@foo/bar/package.json'. Package ID is '@foo/bar/[email protected]'.",
"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.",
Expand All @@ -26,12 +26,12 @@
"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'.",
"Found 'package.json' at '/node_modules/@foo/bar/package.json'. Package ID is '@foo/[email protected]'.",
"======== Module name './index' was successfully resolved to '/node_modules/@foo/bar/index.d.ts'. ========",
"======== 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'.",
"Found 'package.json' at '/node_modules/a/node_modules/@foo/bar/package.json'.",
"Found 'package.json' at '/node_modules/a/node_modules/@foo/bar/package.json'. Package ID is '@foo/[email protected]'.",
"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 Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"Module resolution kind is not specified, using 'NodeJs'.",
"Loading module 'foo/bar' from 'node_modules' folder, target file type 'TypeScript'.",
"File '/node_modules/foo/bar/package.json' does not exist.",
"Found 'package.json' at '/node_modules/foo/package.json'.",
"Found 'package.json' at '/node_modules/foo/package.json'. Package ID is 'foo/[email protected]'.",
"File '/node_modules/foo/bar.ts' does not exist.",
"File '/node_modules/foo/bar.tsx' does not exist.",
"File '/node_modules/foo/bar.d.ts' does not exist.",
Expand All @@ -13,7 +13,7 @@
"Directory '/node_modules/@types' does not exist, skipping all lookups in it.",
"Loading module 'foo/bar' from 'node_modules' folder, target file type 'JavaScript'.",
"File '/node_modules/foo/bar/package.json' does not exist.",
"Found 'package.json' at '/node_modules/foo/package.json'.",
"Found 'package.json' at '/node_modules/foo/package.json'. Package ID is 'foo/[email protected]'.",
"File '/node_modules/foo/bar.js' does not exist.",
"File '/node_modules/foo/bar.jsx' does not exist.",
"File '/node_modules/foo/bar/index.js' exist - use it as a name resolution result.",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"Module resolution kind is not specified, using 'NodeJs'.",
"Loading module 'foo/@bar' from 'node_modules' folder, target file type 'TypeScript'.",
"File '/node_modules/foo/@bar/package.json' does not exist.",
"Found 'package.json' at '/node_modules/foo/package.json'.",
"Found 'package.json' at '/node_modules/foo/package.json'. Package ID is 'foo/@[email protected]'.",
"File '/node_modules/foo/@bar.ts' does not exist.",
"File '/node_modules/foo/@bar.tsx' does not exist.",
"File '/node_modules/foo/@bar.d.ts' does not exist.",
Expand All @@ -13,7 +13,7 @@
"Directory '/node_modules/@types' does not exist, skipping all lookups in it.",
"Loading module 'foo/@bar' from 'node_modules' folder, target file type 'JavaScript'.",
"File '/node_modules/foo/@bar/package.json' does not exist.",
"Found 'package.json' at '/node_modules/foo/package.json'.",
"Found 'package.json' at '/node_modules/foo/package.json'. Package ID is 'foo/@[email protected]'.",
"File '/node_modules/foo/@bar.js' does not exist.",
"File '/node_modules/foo/@bar.jsx' does not exist.",
"File '/node_modules/foo/@bar/index.js' exist - use it as a name resolution result.",
Expand Down