Skip to content

Commit e0bfac5

Browse files
authored
Rename module resolution option node to node10 (preserving backward-compatible alias) (#51901)
* Rename `node` to `node10` (preserving alias) * Revert dogfooding change because of LKG * Update baselines
1 parent 2993ea8 commit e0bfac5

File tree

236 files changed

+780
-628
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

236 files changed

+780
-628
lines changed

src/compiler/checker.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4704,7 +4704,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
47044704
function resolveExternalModuleName(location: Node, moduleReferenceExpression: Expression, ignoreErrors?: boolean): Symbol | undefined {
47054705
const isClassic = getEmitModuleResolutionKind(compilerOptions) === ModuleResolutionKind.Classic;
47064706
const errorMessage = isClassic?
4707-
Diagnostics.Cannot_find_module_0_Did_you_mean_to_set_the_moduleResolution_option_to_node_or_to_add_aliases_to_the_paths_option
4707+
Diagnostics.Cannot_find_module_0_Did_you_mean_to_set_the_moduleResolution_option_to_nodenext_or_to_add_aliases_to_the_paths_option
47084708
: Diagnostics.Cannot_find_module_0_or_its_corresponding_type_declarations;
47094709
return resolveExternalModuleNameWorker(location, moduleReferenceExpression, ignoreErrors ? undefined : errorMessage);
47104710
}
@@ -29807,7 +29807,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
2980729807
}
2980829808
const isClassic = getEmitModuleResolutionKind(compilerOptions) === ModuleResolutionKind.Classic;
2980929809
const errorMessage = isClassic
29810-
? Diagnostics.Cannot_find_module_0_Did_you_mean_to_set_the_moduleResolution_option_to_node_or_to_add_aliases_to_the_paths_option
29810+
? Diagnostics.Cannot_find_module_0_Did_you_mean_to_set_the_moduleResolution_option_to_nodenext_or_to_add_aliases_to_the_paths_option
2981129811
: Diagnostics.Cannot_find_module_0_or_its_corresponding_type_declarations;
2981229812
const mod = resolveExternalModule(location!, runtimeImportSpecifier, errorMessage, location!);
2981329813
const result = mod && mod !== unknownSymbol ? getMergedSymbol(resolveSymbol(mod)) : undefined;

src/compiler/commandLineParser.ts

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -961,12 +961,15 @@ const commandOptionsWithoutBuild: CommandLineOption[] = [
961961
{
962962
name: "moduleResolution",
963963
type: new Map(getEntries({
964-
node: ModuleResolutionKind.NodeJs,
964+
// N.B. The first entry specifies the value shown in `tsc --init`
965+
node10: ModuleResolutionKind.Node10,
966+
node: ModuleResolutionKind.Node10,
965967
classic: ModuleResolutionKind.Classic,
966968
node16: ModuleResolutionKind.Node16,
967969
nodenext: ModuleResolutionKind.NodeNext,
968970
bundler: ModuleResolutionKind.Bundler,
969971
})),
972+
deprecatedKeys: new Set(["node"]),
970973
affectsModuleResolution: true,
971974
paramType: Diagnostics.STRATEGY,
972975
category: Diagnostics.Modules,
@@ -1685,8 +1688,9 @@ export function createCompilerDiagnosticForInvalidCustomType(opt: CommandLineOpt
16851688
}
16861689

16871690
function createDiagnosticForInvalidCustomType(opt: CommandLineOptionOfCustomType, createDiagnostic: (message: DiagnosticMessage, arg0: string, arg1: string) => Diagnostic): Diagnostic {
1688-
const namesOfType = arrayFrom(opt.type.keys()).map(key => `'${key}'`).join(", ");
1689-
return createDiagnostic(Diagnostics.Argument_for_0_option_must_be_Colon_1, `--${opt.name}`, namesOfType);
1691+
const namesOfType = arrayFrom(opt.type.keys());
1692+
const stringNames = (opt.deprecatedKeys ? namesOfType.filter(k => !opt.deprecatedKeys!.has(k)) : namesOfType).map(key => `'${key}'`).join(", ");
1693+
return createDiagnostic(Diagnostics.Argument_for_0_option_must_be_Colon_1, `--${opt.name}`, stringNames);
16901694
}
16911695

16921696
/** @internal */
@@ -3404,7 +3408,7 @@ function getExtendsConfigPath(
34043408
return extendedConfigPath;
34053409
}
34063410
// If the path isn't a rooted or relative path, resolve like a module
3407-
const resolved = nodeModuleNameResolver(extendedConfig, combinePaths(basePath, "tsconfig.json"), { moduleResolution: ModuleResolutionKind.NodeJs }, host, /*cache*/ undefined, /*projectRefs*/ undefined, /*lookupConfig*/ true);
3411+
const resolved = nodeModuleNameResolver(extendedConfig, combinePaths(basePath, "tsconfig.json"), { moduleResolution: ModuleResolutionKind.Node10 }, host, /*cache*/ undefined, /*projectRefs*/ undefined, /*lookupConfig*/ true);
34083412
if (resolved.resolvedModule) {
34093413
return resolved.resolvedModule.resolvedFileName;
34103414
}

src/compiler/diagnosticMessages.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3391,7 +3391,7 @@
33913391
"category": "Error",
33923392
"code": 2791
33933393
},
3394-
"Cannot find module '{0}'. Did you mean to set the 'moduleResolution' option to 'node', or to add aliases to the 'paths' option?": {
3394+
"Cannot find module '{0}'. Did you mean to set the 'moduleResolution' option to 'nodenext', or to add aliases to the 'paths' option?": {
33953395
"category": "Error",
33963396
"code": 2792
33973397
},
@@ -4121,7 +4121,7 @@
41214121
"category": "Error",
41224122
"code": 5069
41234123
},
4124-
"Option '--resolveJsonModule' cannot be specified without 'node' module resolution strategy.": {
4124+
"Option '--resolveJsonModule' cannot be specified when 'moduleResolution' is set to 'classic'.": {
41254125
"category": "Error",
41264126
"code": 5070
41274127
},

src/compiler/moduleNameResolver.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1248,7 +1248,7 @@ export function resolveModuleName(moduleName: string, containingFile: string, co
12481248
if (moduleResolution === undefined) {
12491249
switch (getEmitModuleKind(compilerOptions)) {
12501250
case ModuleKind.CommonJS:
1251-
moduleResolution = ModuleResolutionKind.NodeJs;
1251+
moduleResolution = ModuleResolutionKind.Node10;
12521252
break;
12531253
case ModuleKind.Node16:
12541254
moduleResolution = ModuleResolutionKind.Node16;
@@ -1278,7 +1278,7 @@ export function resolveModuleName(moduleName: string, containingFile: string, co
12781278
case ModuleResolutionKind.NodeNext:
12791279
result = nodeNextModuleNameResolver(moduleName, containingFile, compilerOptions, host, cache, redirectedReference, resolutionMode);
12801280
break;
1281-
case ModuleResolutionKind.NodeJs:
1281+
case ModuleResolutionKind.Node10:
12821282
result = nodeModuleNameResolver(moduleName, containingFile, compilerOptions, host, cache, redirectedReference);
12831283
break;
12841284
case ModuleResolutionKind.Classic:
@@ -1593,7 +1593,7 @@ function tryResolveJSModuleWorker(moduleName: string, initialDir: string, host:
15931593
NodeResolutionFeatures.None,
15941594
moduleName,
15951595
initialDir,
1596-
{ moduleResolution: ModuleResolutionKind.NodeJs, allowJs: true },
1596+
{ moduleResolution: ModuleResolutionKind.Node10, allowJs: true },
15971597
host,
15981598
/*cache*/ undefined,
15991599
Extensions.JavaScript,
@@ -1656,7 +1656,7 @@ function nodeModuleNameResolverWorker(features: NodeResolutionFeatures, moduleNa
16561656
}
16571657

16581658
let result;
1659-
if (getEmitModuleResolutionKind(compilerOptions) === ModuleResolutionKind.NodeJs) {
1659+
if (getEmitModuleResolutionKind(compilerOptions) === ModuleResolutionKind.Node10) {
16601660
const priorityExtensions = extensions & (Extensions.TypeScript | Extensions.Declaration);
16611661
const secondaryExtensions = extensions & ~(Extensions.TypeScript | Extensions.Declaration);
16621662
result =

src/compiler/program.ts

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3772,7 +3772,7 @@ export function createProgram(rootNamesOrOptions: readonly string[] | CreateProg
37723772
i++;
37733773
}
37743774
const resolveFrom = combinePaths(currentDirectory, `__lib_node_modules_lookup_${libFileName}__.ts`);
3775-
const localOverrideModuleResult = resolveModuleName("@typescript/lib-" + path, resolveFrom, { moduleResolution: ModuleResolutionKind.NodeJs }, host, moduleResolutionCache);
3775+
const localOverrideModuleResult = resolveModuleName("@typescript/lib-" + path, resolveFrom, { moduleResolution: ModuleResolutionKind.Node10 }, host, moduleResolutionCache);
37763776
if (localOverrideModuleResult?.resolvedModule) {
37773777
return localOverrideModuleResult.resolvedModule.resolvedFileName;
37783778
}
@@ -4118,11 +4118,8 @@ export function createProgram(rootNamesOrOptions: readonly string[] | CreateProg
41184118
}
41194119

41204120
if (getResolveJsonModule(options)) {
4121-
if (getEmitModuleResolutionKind(options) !== ModuleResolutionKind.NodeJs &&
4122-
getEmitModuleResolutionKind(options) !== ModuleResolutionKind.Node16 &&
4123-
getEmitModuleResolutionKind(options) !== ModuleResolutionKind.NodeNext &&
4124-
getEmitModuleResolutionKind(options) !== ModuleResolutionKind.Bundler) {
4125-
createDiagnosticForOptionName(Diagnostics.Option_resolveJsonModule_cannot_be_specified_without_node_module_resolution_strategy, "resolveJsonModule");
4121+
if (getEmitModuleResolutionKind(options) === ModuleResolutionKind.Classic) {
4122+
createDiagnosticForOptionName(Diagnostics.Option_resolveJsonModule_cannot_be_specified_when_moduleResolution_is_set_to_classic, "resolveJsonModule");
41264123
}
41274124
// Any emit other than common js, amd, es2015 or esnext is error
41284125
else if (!hasJsonModuleEmitEnabled(options)) {

src/compiler/types.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6903,7 +6903,7 @@ export function diagnosticCategoryName(d: { category: DiagnosticCategory }, lowe
69036903

69046904
export enum ModuleResolutionKind {
69056905
Classic = 1,
6906-
NodeJs = 2,
6906+
Node10 = 2,
69076907
// Starting with node12, node's module resolver has significant departures from traditional cjs resolution
69086908
// to better support ecmascript modules and their use within node - however more features are still being added.
69096909
// TypeScript's Node ESM support was introduced after Node 12 went end-of-life, and Node 14 is the earliest stable
@@ -7322,6 +7322,7 @@ export interface CommandLineOptionOfBooleanType extends CommandLineOptionBase {
73227322
export interface CommandLineOptionOfCustomType extends CommandLineOptionBase {
73237323
type: Map<string, number | string>; // an object literal mapping named values to actual values
73247324
defaultValueDescription: number | string | undefined | DiagnosticMessage;
7325+
deprecatedKeys?: Set<string>;
73257326
}
73267327

73277328
/** @internal */

src/compiler/utilities.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7715,7 +7715,7 @@ export function getEmitModuleResolutionKind(compilerOptions: CompilerOptions) {
77157715
if (moduleResolution === undefined) {
77167716
switch (getEmitModuleKind(compilerOptions)) {
77177717
case ModuleKind.CommonJS:
7718-
moduleResolution = ModuleResolutionKind.NodeJs;
7718+
moduleResolution = ModuleResolutionKind.Node10;
77197719
break;
77207720
case ModuleKind.Node16:
77217721
moduleResolution = ModuleResolutionKind.Node16;

src/server/session.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1566,7 +1566,7 @@ export class Session<TMessage = string> implements EventSender {
15661566
// resolved from the package root under --moduleResolution node
15671567
const entrypoints = getEntrypointsFromPackageJsonInfo(
15681568
packageJson,
1569-
{ moduleResolution: ModuleResolutionKind.NodeJs },
1569+
{ moduleResolution: ModuleResolutionKind.Node10 },
15701570
project,
15711571
project.getModuleResolutionCache());
15721572
// This substring is correct only because we checked for a single `/node_modules/` at the top.

src/services/codefixes/importFixes.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -964,7 +964,7 @@ function compareModuleSpecifiers(
964964
function isFixPossiblyReExportingImportingFile(fix: ImportFixWithModuleSpecifier, importingFile: SourceFile, compilerOptions: CompilerOptions, toPath: (fileName: string) => Path): boolean {
965965
if (fix.isReExport &&
966966
fix.exportInfo?.moduleFileName &&
967-
getEmitModuleResolutionKind(compilerOptions) === ModuleResolutionKind.NodeJs &&
967+
getEmitModuleResolutionKind(compilerOptions) === ModuleResolutionKind.Node10 &&
968968
isIndexFileName(fix.exportInfo.moduleFileName)
969969
) {
970970
const reExportDir = toPath(getDirectoryPath(fix.exportInfo.moduleFileName));

src/services/utilities.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2411,7 +2411,7 @@ export function getModuleSpecifierResolverHost(program: Program, host: LanguageS
24112411

24122412
/** @internal */
24132413
export function moduleResolutionUsesNodeModules(moduleResolution: ModuleResolutionKind): boolean {
2414-
return moduleResolution === ModuleResolutionKind.NodeJs || moduleResolution >= ModuleResolutionKind.Node16 && moduleResolution <= ModuleResolutionKind.NodeNext;
2414+
return moduleResolution === ModuleResolutionKind.Node10 || moduleResolution >= ModuleResolutionKind.Node16 && moduleResolution <= ModuleResolutionKind.NodeNext;
24152415
}
24162416

24172417
/** @internal */

0 commit comments

Comments
 (0)