Do not remove extension js or jsx from the subModuleName if the subModule doesnt have js or jsx extension

This commit is contained in:
Sheetal Nandi
2018-05-14 13:42:45 -07:00
parent 7be85958a1
commit 22d5b0e19f
2 changed files with 6 additions and 4 deletions

View File

@@ -1012,8 +1012,10 @@ namespace ts {
}
else {
const jsPath = tryReadPackageJsonFields(/*readTypes*/ false, packageJsonContent, nodeModuleDirectory, state);
if (typeof jsPath === "string") {
subModuleName = removeExtension(removeExtension(jsPath.substring(nodeModuleDirectory.length + 1), Extension.Js), Extension.Jsx) + Extension.Dts;
if (typeof jsPath === "string" && jsPath.length > nodeModuleDirectory.length) {
const potentialSubModule = jsPath.substring(nodeModuleDirectory.length + 1);
subModuleName = (forEach(supportedJavascriptExtensions, extension =>
tryRemoveExtension(potentialSubModule, extension)) || potentialSubModule) + Extension.Dts;
}
else {
subModuleName = "index.d.ts";

View File

@@ -5,7 +5,7 @@
"'package.json' does not have a 'typings' field.",
"'package.json' does not have a 'types' field.",
"'package.json' has 'main' field 'src/index.js' that references '/node_modules/foo/src/index.js'.",
"Found 'package.json' at '/node_modules/foo/package.json'. Package ID is 'foo/src/i.d.ts@1.2.3'.",
"Found 'package.json' at '/node_modules/foo/package.json'. Package ID is 'foo/src/index.d.ts@1.2.3'.",
"File '/node_modules/foo.ts' does not exist.",
"File '/node_modules/foo.tsx' does not exist.",
"File '/node_modules/foo.d.ts' does not exist.",
@@ -19,7 +19,7 @@
"'package.json' does not have a 'typings' field.",
"'package.json' does not have a 'types' field.",
"'package.json' has 'main' field 'src/index.js' that references '/node_modules/foo/src/index.js'.",
"Found 'package.json' at '/node_modules/foo/package.json'. Package ID is 'foo/src/i.d.ts@1.2.3'.",
"Found 'package.json' at '/node_modules/foo/package.json'. Package ID is 'foo/src/index.d.ts@1.2.3'.",
"File '/node_modules/foo.js' does not exist.",
"File '/node_modules/foo.jsx' does not exist.",
"'package.json' has 'main' field 'src/index.js' that references '/node_modules/foo/src/index.js'.",