Minimal fix for auto-importing node_modules in node12/nodenext (#46148)

This commit is contained in:
Andrew Branch 2021-09-30 13:42:06 -07:00 committed by GitHub
parent d613748932
commit 96f259ddcc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 12 additions and 1 deletions

View File

@ -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);

View File

@ -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"]);