Skip to content

Commit

Permalink
Minimal fix for auto-importing node_modules in node12/nodenext (#46148)
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewbranch authored Sep 30, 2021
1 parent d613748 commit 96f259d
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/compiler/moduleSpecifiers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -619,7 +619,7 @@ namespace ts.moduleSpecifiers {
const nodeModulesDirectoryName = moduleSpecifier.substring(parts.topLevelPackageNameIndex + 1);
const packageName = getPackageNameFromTypesPackageName(nodeModulesDirectoryName);
// For classic resolution, only allow importing from node_modules/@types, not other node_modules
return getEmitModuleResolutionKind(options) !== ModuleResolutionKind.NodeJs && packageName === nodeModulesDirectoryName ? undefined : packageName;
return getEmitModuleResolutionKind(options) === ModuleResolutionKind.Classic && packageName === nodeModulesDirectoryName ? undefined : packageName;

function tryDirectoryWithPackageJson(packageRootIndex: number) {
const packageRootPath = path.substring(0, packageRootIndex);
Expand Down
11 changes: 11 additions & 0 deletions tests/cases/fourslash/autoImport_node12_node_modules1.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
/// <reference path="fourslash.ts" />

// @module: node12

// @Filename: /node_modules/undici/index.d.ts
//// export function request(): any;

// @Filename: /index.mts
//// request/**/

verify.importFixModuleSpecifiers("", ["undici"]);

0 comments on commit 96f259d

Please sign in to comment.