From 3822e3e4ed0e3524ffde41a85742df7cdc93cd72 Mon Sep 17 00:00:00 2001 From: Andy Date: Thu, 7 Jun 2018 15:45:03 -0700 Subject: [PATCH] tryGetModuleNameAsNodeModule: Ignore file extension (#24774) --- src/compiler/moduleSpecifiers.ts | 2 +- .../fourslash/importNameCodeFixNewImportNodeModules7.ts | 9 +-------- 2 files changed, 2 insertions(+), 9 deletions(-) diff --git a/src/compiler/moduleSpecifiers.ts b/src/compiler/moduleSpecifiers.ts index 50daa81d60c3f..6da0fc61e63d7 100644 --- a/src/compiler/moduleSpecifiers.ts +++ b/src/compiler/moduleSpecifiers.ts @@ -248,7 +248,7 @@ namespace ts.moduleSpecifiers { const mainFileRelative = packageJsonContent.typings || packageJsonContent.types || packageJsonContent.main; if (mainFileRelative) { const mainExportFile = toPath(mainFileRelative, packageRootPath, getCanonicalFileName); - if (mainExportFile === getCanonicalFileName(path)) { + if (removeFileExtension(mainExportFile) === removeFileExtension(getCanonicalFileName(path))) { return packageRootPath; } } diff --git a/tests/cases/fourslash/importNameCodeFixNewImportNodeModules7.ts b/tests/cases/fourslash/importNameCodeFixNewImportNodeModules7.ts index 9032018a7f59c..beaaad57f19d0 100644 --- a/tests/cases/fourslash/importNameCodeFixNewImportNodeModules7.ts +++ b/tests/cases/fourslash/importNameCodeFixNewImportNodeModules7.ts @@ -15,15 +15,8 @@ // @Filename: node_modules/package-name/package.json //// { "main": "bin/lib/libfile.js" } - -// In this case, importing the module by its package name: -// import { f1 } from 'package-name' -// could in theory work, however the resulting code compiles with a module resolution error -// since bin/lib/libfile.d.ts isn't declared under "typings" in package.json -// Therefore just import the module by its qualified path - verify.importFixAtPosition([ -`import { f1 } from "package-name/bin/lib/libfile"; +`import { f1 } from "package-name"; f1('');` ]); \ No newline at end of file