Skip to content

Commit 7956c00

Browse files
authored
Deprecate --moduleResolution node10 (#62338)
1 parent 3eb7b6a commit 7956c00

File tree

747 files changed

+13352
-6218
lines changed

Some content is hidden

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

747 files changed

+13352
-6218
lines changed

src/compiler/checker.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -338,6 +338,7 @@ import {
338338
getMembersOfDeclaration,
339339
getModifiers,
340340
getModuleInstanceState,
341+
getModuleSpecifierOfBareOrAccessedRequire,
341342
getNameFromImportAttribute,
342343
getNameFromIndexInfo,
343344
getNameOfDeclaration,
@@ -4713,7 +4714,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
47134714
? location
47144715
: (isModuleDeclaration(location) ? location : location.parent && isModuleDeclaration(location.parent) && location.parent.name === location ? location.parent : undefined)?.name ||
47154716
(isLiteralImportTypeNode(location) ? location : undefined)?.argument.literal ||
4716-
(isVariableDeclaration(location) && location.initializer && isRequireCall(location.initializer, /*requireStringLiteralLikeArgument*/ true) ? location.initializer.arguments[0] : undefined) ||
4717+
isVariableDeclarationInitializedToBareOrAccessedRequire(location) && getModuleSpecifierOfBareOrAccessedRequire(location) ||
47174718
findAncestor(location, isImportCall)?.arguments[0] ||
47184719
findAncestor(location, or(isImportDeclaration, isJSDocImportTag, isExportDeclaration))?.moduleSpecifier ||
47194720
findAncestor(location, isExternalModuleImportEqualsDeclaration)?.moduleReference.expression;

src/compiler/program.ts

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4436,10 +4436,7 @@ export function createProgram(_rootNamesOrOptions: readonly string[] | CreatePro
44364436
function getIgnoreDeprecationsVersion(): Version {
44374437
const ignoreDeprecations = options.ignoreDeprecations;
44384438
if (ignoreDeprecations) {
4439-
// While we could do Version.tryParse here to support any version,
4440-
// for now, only allow "5.0". We aren't planning on deprecating anything
4441-
// until 6.0.
4442-
if (ignoreDeprecations === "5.0") {
4439+
if (ignoreDeprecations === "5.0" || ignoreDeprecations === "6.0") {
44434440
return new Version(ignoreDeprecations);
44444441
}
44454442
reportInvalidIgnoreDeprecations();
@@ -4527,6 +4524,12 @@ export function createProgram(_rootNamesOrOptions: readonly string[] | CreatePro
45274524
createDeprecatedDiagnostic("preserveValueImports", /*value*/ undefined, "verbatimModuleSyntax");
45284525
}
45294526
});
4527+
4528+
checkDeprecations("6.0", "7.0", createDiagnostic, createDeprecatedDiagnostic => {
4529+
if (options.moduleResolution === ModuleResolutionKind.Node10) {
4530+
createDeprecatedDiagnostic("moduleResolution", "node10");
4531+
}
4532+
});
45304533
}
45314534

45324535
function verifyDeprecatedProjectReference(ref: ProjectReference, parentFile: JsonSourceFile | undefined, index: number) {

src/compiler/types.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7330,6 +7330,9 @@ export enum ModuleResolutionKind {
73307330
* Use the new name or consider switching to a modern module resolution target.
73317331
*/
73327332
NodeJs = 2,
7333+
/**
7334+
* @deprecated
7335+
*/
73337336
Node10 = 2,
73347337
// Starting with node12, node's module resolver has significant departures from traditional cjs resolution
73357338
// to better support ECMAScript modules and their use within node - however more features are still being added.

src/compiler/utilities.ts

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3824,6 +3824,20 @@ export function isBindingElementOfBareOrAccessedRequire(node: Node): node is Bin
38243824
return isBindingElement(node) && isVariableDeclarationInitializedToBareOrAccessedRequire(node.parent.parent);
38253825
}
38263826

3827+
/** @internal */
3828+
export function getModuleSpecifierOfBareOrAccessedRequire(node: VariableDeclarationInitializedTo<RequireOrImportCall | AccessExpression>): StringLiteralLike | undefined {
3829+
if (isVariableDeclarationInitializedToRequire(node)) {
3830+
return node.initializer.arguments[0];
3831+
}
3832+
if (isVariableDeclarationInitializedToBareOrAccessedRequire(node)) {
3833+
const leftmost = getLeftmostAccessExpression(node.initializer);
3834+
if (isRequireCall(leftmost, /*requireStringLiteralLikeArgument*/ true)) {
3835+
return leftmost.arguments[0];
3836+
}
3837+
}
3838+
return undefined;
3839+
}
3840+
38273841
function isVariableDeclarationInitializedWithRequireHelper(node: Node, allowAccessedRequire: boolean) {
38283842
return isVariableDeclaration(node) &&
38293843
!!node.initializer &&
@@ -8992,9 +9006,6 @@ const _computedOptions = createComputedCompilerOptions({
89929006
let moduleResolution = compilerOptions.moduleResolution;
89939007
if (moduleResolution === undefined) {
89949008
switch (_computedOptions.module.computeValue(compilerOptions)) {
8995-
case ModuleKind.CommonJS:
8996-
moduleResolution = ModuleResolutionKind.Node10;
8997-
break;
89989009
case ModuleKind.Node16:
89999010
case ModuleKind.Node18:
90009011
case ModuleKind.Node20:
@@ -9003,6 +9014,7 @@ const _computedOptions = createComputedCompilerOptions({
90039014
case ModuleKind.NodeNext:
90049015
moduleResolution = ModuleResolutionKind.NodeNext;
90059016
break;
9017+
case ModuleKind.CommonJS:
90069018
case ModuleKind.Preserve:
90079019
moduleResolution = ModuleResolutionKind.Bundler;
90089020
break;

src/server/protocol.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3269,6 +3269,7 @@ export const enum ModuleResolutionKind {
32693269
Node = "node",
32703270
/** @deprecated Renamed to `Node10` */
32713271
NodeJs = "node",
3272+
/** @deprecated */
32723273
Node10 = "node10",
32733274
Node16 = "node16",
32743275
NodeNext = "nodenext",

src/services/completions.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4185,10 +4185,6 @@ function getCompletionData(
41854185
return charactersFuzzyMatchInString(symbolName, lowerCaseTokenText);
41864186
},
41874187
(info, symbolName, isFromAmbientModule, exportMapKey) => {
4188-
if (detailsEntryId && !some(info, i => detailsEntryId.source === stripQuotes(i.moduleSymbol.name))) {
4189-
return;
4190-
}
4191-
41924188
// Do a relatively cheap check to bail early if all re-exports are non-importable
41934189
// due to file location or package.json dependency filtering. For non-node16+
41944190
// module resolution modes, getting past this point guarantees that we'll be
@@ -4217,6 +4213,10 @@ function getCompletionData(
42174213
({ exportInfo = info[0], moduleSpecifier } = result);
42184214
}
42194215

4216+
if (detailsEntryId && (detailsEntryId.source !== moduleSpecifier && !some(info, i => detailsEntryId.source === stripQuotes(i.moduleSymbol.name)))) {
4217+
return;
4218+
}
4219+
42204220
const isDefaultExport = exportInfo.exportKind === ExportKind.Default;
42214221
const symbol = isDefaultExport && getLocalSymbolForExportDefault(Debug.checkDefined(exportInfo.symbol)) || Debug.checkDefined(exportInfo.symbol);
42224222

src/services/stringCompletions.ts

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1067,8 +1067,9 @@ function getCompletionEntriesForNonRelativeModules(
10671067
if (tryFileExists(host, packageFile)) {
10681068
const packageJson = readJson(packageFile, host);
10691069
const fragmentSubpath = components.join("/") + (components.length && hasTrailingDirectorySeparator(fragment) ? "/" : "");
1070-
exportsOrImportsLookup((packageJson as MapLike<unknown>).exports, fragmentSubpath, packageDirectory, /*isExports*/ true, /*isImports*/ false);
1071-
return;
1070+
if (exportsOrImportsLookup((packageJson as MapLike<unknown>).exports, fragmentSubpath, packageDirectory, /*isExports*/ true, /*isImports*/ false)) {
1071+
return;
1072+
}
10721073
}
10731074
return nodeModulesDirectoryOrImportsLookup(ancestor);
10741075
};
@@ -1079,9 +1080,10 @@ function getCompletionEntriesForNonRelativeModules(
10791080

10801081
return arrayFrom(result.values());
10811082

1082-
function exportsOrImportsLookup(lookupTable: unknown, fragment: string, baseDirectory: string, isExports: boolean, isImports: boolean) {
1083+
/** Returns true if the search should stop */
1084+
function exportsOrImportsLookup(lookupTable: unknown, fragment: string, baseDirectory: string, isExports: boolean, isImports: boolean): boolean {
10831085
if (typeof lookupTable !== "object" || lookupTable === null) { // eslint-disable-line no-restricted-syntax
1084-
return; // null lookupTable or entrypoint only
1086+
return lookupTable !== undefined; // null lookupTable or entrypoint only
10851087
}
10861088
const keys = getOwnKeys(lookupTable as MapLike<unknown>);
10871089
const conditions = getConditions(compilerOptions, mode);
@@ -1105,6 +1107,7 @@ function getCompletionEntriesForNonRelativeModules(
11051107
},
11061108
comparePatternKeys,
11071109
);
1110+
return true;
11081111
}
11091112
}
11101113

src/testRunner/unittests/tscWatch/watchEnvironment.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -288,7 +288,7 @@ describe("unittests:: tscWatch:: watchEnvironment:: tsc-watch with different pol
288288
sys: () => {
289289
const configFile: File = {
290290
path: `/user/username/projects/myproject/tsconfig.json`,
291-
content: "{}",
291+
content: `{ "compilerOptions": { "moduleResolution": "node10" } }`,
292292
};
293293
const file1: File = {
294294
path: `/user/username/projects/myproject/src/file1.ts`,

src/testRunner/unittests/tsserver/autoImportProvider.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,11 @@ describe("unittests:: tsserver:: autoImportProvider::", () => {
188188

189189
// Create auto import provider project, ensure still !session.getProjectService().pendingEnsureProjectForOpenFiles
190190
host.writeFile(packageJson.path, packageJson.content);
191+
// package.json was watched in --moduleResolution bundler
192+
assert.isTrue(session.getProjectService().pendingEnsureProjectForOpenFiles);
193+
host.runQueuedTimeoutCallbacks();
194+
assert.isFalse(session.getProjectService().pendingEnsureProjectForOpenFiles);
195+
191196
session.host.baselineHost("Before getPackageJsonAutoImportProvider");
192197
hostProject.getPackageJsonAutoImportProvider();
193198
assert.isFalse(session.getProjectService().pendingEnsureProjectForOpenFiles);

src/testRunner/unittests/tsserver/completionsIncomplete.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ const indexFile: File = {
4949

5050
const tsconfigFile: File = {
5151
path: "/home/src/project/project/tsconfig.json",
52-
content: `{ "compilerOptions": { "module": "commonjs" } }`,
52+
content: `{ "compilerOptions": { "module": "commonjs", "moduleResolution": "node10" } }`,
5353
};
5454

5555
const packageJsonFile: File = {

0 commit comments

Comments
 (0)