Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add new option "libReplacement", disable by default #60829

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
9 changes: 9 additions & 0 deletions src/compiler/commandLineParser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -855,6 +855,15 @@ const commandOptionsWithoutBuild: CommandLineOption[] = [
affectsBuildInfo: true,
affectsSemanticDiagnostics: true,
},
{
name: "libReplacement",
type: "boolean",
affectsSemanticDiagnostics: true,
affectsBuildInfo: true,
category: Diagnostics.Language_and_Environment,
description: Diagnostics.Enable_lib_replacement,
defaultValueDescription: false,
},

// Strict Type Checks
{
Expand Down
4 changes: 4 additions & 0 deletions src/compiler/diagnosticMessages.json
Original file line number Diff line number Diff line change
Expand Up @@ -6492,6 +6492,10 @@
"category": "Error",
"code": 6807
},
"Enable lib replacement.": {
"category": "Message",
"code": 6808
},

"one of:": {
"category": "Message",
Expand Down
11 changes: 11 additions & 0 deletions src/compiler/program.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4065,6 +4065,17 @@ export function createProgram(rootNamesOrOptions: readonly string[] | CreateProg
const existing = resolvedLibProcessing?.get(libFileName);
if (existing) return existing;

if (!options.libReplacement) {
const result: LibResolution = {
resolution: {
resolvedModule: undefined,
},
actual: combinePaths(defaultLibraryPath, libFileName),
};
(resolvedLibProcessing ??= new Map()).set(libFileName, result);
return result;
}

if (structureIsReused !== StructureIsReused.Not && oldProgram && !hasInvalidatedLibResolutions(libFileName)) {
const oldResolution = oldProgram.resolvedLibReferences?.get(libFileName);
if (oldResolution) {
Expand Down
1 change: 1 addition & 0 deletions src/compiler/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7406,6 +7406,7 @@ export interface CompilerOptions {
/** @deprecated */
keyofStringsOnly?: boolean;
lib?: string[];
libReplacement?: boolean;
/** @internal */ listEmittedFiles?: boolean;
/** @internal */ listFiles?: boolean;
/** @internal */ explainFiles?: boolean;
Expand Down
11 changes: 7 additions & 4 deletions src/testRunner/unittests/helpers/libraryResolution.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,23 +21,23 @@ function getSysForLibResolution(libRedirection?: boolean, forTsserver?: boolean)
/// <reference lib="es5"/>
`,
"/home/src/workspace/projects/project1/tsconfig.json": jsonToReadableText({
compilerOptions: { composite: true, typeRoots: ["./typeroot1"], lib: ["es5", "dom"], traceResolution: true },
compilerOptions: { composite: true, typeRoots: ["./typeroot1"], lib: ["es5", "dom"], traceResolution: true, libReplacement: libRedirection },
}),
"/home/src/workspace/projects/project1/typeroot1/sometype/index.d.ts": `export type TheNum = "type1";`,
"/home/src/workspace/projects/project2/utils.d.ts": `export const y = 10;`,
"/home/src/workspace/projects/project2/index.ts": `export const y = 10`,
"/home/src/workspace/projects/project2/tsconfig.json": jsonToReadableText({
compilerOptions: { composite: true, lib: ["es5", "dom"], traceResolution: true },
compilerOptions: { composite: true, lib: ["es5", "dom"], traceResolution: true, libReplacement: libRedirection },
}),
"/home/src/workspace/projects/project3/utils.d.ts": `export const y = 10;`,
"/home/src/workspace/projects/project3/index.ts": `export const z = 10`,
"/home/src/workspace/projects/project3/tsconfig.json": jsonToReadableText({
compilerOptions: { composite: true, lib: ["es5", "dom"], traceResolution: true },
compilerOptions: { composite: true, lib: ["es5", "dom"], traceResolution: true, libReplacement: libRedirection },
}),
"/home/src/workspace/projects/project4/utils.d.ts": `export const y = 10;`,
"/home/src/workspace/projects/project4/index.ts": `export const z = 10`,
"/home/src/workspace/projects/project4/tsconfig.json": jsonToReadableText({
compilerOptions: { composite: true, lib: ["esnext", "dom", "webworker"], traceResolution: true },
compilerOptions: { composite: true, lib: ["esnext", "dom", "webworker"], traceResolution: true, libReplacement: libRedirection },
}),
[getTypeScriptLibTestLocation("dom")]: "interface DOMInterface { }",
[getTypeScriptLibTestLocation("webworker")]: "interface WebWorkerInterface { }",
Expand Down Expand Up @@ -71,6 +71,7 @@ function getLibResolutionEditOptions(
typeRoots: ["./typeroot1", "./typeroot2"],
lib: ["es5", "dom"],
traceResolution: true,
libReplacement: true,
},
}),
),
Expand All @@ -90,6 +91,7 @@ function getLibResolutionEditOptions(
typeRoots: ["./typeroot1"],
lib: ["es5", "dom"],
traceResolution: true,
libReplacement: true,
},
}),
);
Expand Down Expand Up @@ -235,6 +237,7 @@ export function getSysForLibResolutionUnknown(): TestServerHost {
compilerOptions: {
composite: true,
traceResolution: true,
libReplacement: true,
},
}),
[getTypeScriptLibTestLocation("webworker")]: "interface WebWorkerInterface { }",
Expand Down
86 changes: 1 addition & 85 deletions tests/baselines/reference/allowJsCrossMonorepoPackage.trace.json
Original file line number Diff line number Diff line change
Expand Up @@ -75,89 +75,5 @@
"======== Module name 'pkg' was successfully resolved to '/node_modules/pkg/index.d.ts'. ========",
"File '/node_modules/pkg/package.json' does not exist according to earlier cached lookups.",
"File '/node_modules/package.json' does not exist.",
"File '/package.json' does not exist.",
"======== Resolving module '@typescript/lib-es5' from '/packages/main/__lib_node_modules_lookup_lib.es5.d.ts__.ts'. ========",
"Explicitly specified module resolution kind: 'Node10'.",
"Loading module '@typescript/lib-es5' from 'node_modules' folder, target file types: TypeScript, Declaration.",
"Searching all ancestor node_modules directories for preferred extensions: TypeScript, Declaration.",
"Directory '/packages/main/node_modules/@types' does not exist, skipping all lookups in it.",
"Scoped package detected, looking in 'typescript__lib-es5'",
"Directory '/packages/node_modules' does not exist, skipping all lookups in it.",
"Scoped package detected, looking in 'typescript__lib-es5'",
"Directory '/node_modules/@types' does not exist, skipping all lookups in it.",
"Scoped package detected, looking in 'typescript__lib-es5'",
"Loading module '@typescript/lib-es5' from 'node_modules' folder, target file types: JavaScript.",
"Searching all ancestor node_modules directories for fallback extensions: JavaScript.",
"Directory '/packages/node_modules' does not exist, skipping all lookups in it.",
"======== Module name '@typescript/lib-es5' was not resolved. ========",
"======== Resolving module '@typescript/lib-decorators' from '/packages/main/__lib_node_modules_lookup_lib.decorators.d.ts__.ts'. ========",
"Explicitly specified module resolution kind: 'Node10'.",
"Loading module '@typescript/lib-decorators' from 'node_modules' folder, target file types: TypeScript, Declaration.",
"Searching all ancestor node_modules directories for preferred extensions: TypeScript, Declaration.",
"Directory '/packages/main/node_modules/@types' does not exist, skipping all lookups in it.",
"Scoped package detected, looking in 'typescript__lib-decorators'",
"Directory '/packages/node_modules' does not exist, skipping all lookups in it.",
"Scoped package detected, looking in 'typescript__lib-decorators'",
"Directory '/node_modules/@types' does not exist, skipping all lookups in it.",
"Scoped package detected, looking in 'typescript__lib-decorators'",
"Loading module '@typescript/lib-decorators' from 'node_modules' folder, target file types: JavaScript.",
"Searching all ancestor node_modules directories for fallback extensions: JavaScript.",
"Directory '/packages/node_modules' does not exist, skipping all lookups in it.",
"======== Module name '@typescript/lib-decorators' was not resolved. ========",
"======== Resolving module '@typescript/lib-decorators/legacy' from '/packages/main/__lib_node_modules_lookup_lib.decorators.legacy.d.ts__.ts'. ========",
"Explicitly specified module resolution kind: 'Node10'.",
"Loading module '@typescript/lib-decorators/legacy' from 'node_modules' folder, target file types: TypeScript, Declaration.",
"Searching all ancestor node_modules directories for preferred extensions: TypeScript, Declaration.",
"Directory '/packages/main/node_modules/@types' does not exist, skipping all lookups in it.",
"Scoped package detected, looking in 'typescript__lib-decorators/legacy'",
"Directory '/packages/node_modules' does not exist, skipping all lookups in it.",
"Scoped package detected, looking in 'typescript__lib-decorators/legacy'",
"Directory '/node_modules/@types' does not exist, skipping all lookups in it.",
"Scoped package detected, looking in 'typescript__lib-decorators/legacy'",
"Loading module '@typescript/lib-decorators/legacy' from 'node_modules' folder, target file types: JavaScript.",
"Searching all ancestor node_modules directories for fallback extensions: JavaScript.",
"Directory '/packages/node_modules' does not exist, skipping all lookups in it.",
"======== Module name '@typescript/lib-decorators/legacy' was not resolved. ========",
"======== Resolving module '@typescript/lib-dom' from '/packages/main/__lib_node_modules_lookup_lib.dom.d.ts__.ts'. ========",
"Explicitly specified module resolution kind: 'Node10'.",
"Loading module '@typescript/lib-dom' from 'node_modules' folder, target file types: TypeScript, Declaration.",
"Searching all ancestor node_modules directories for preferred extensions: TypeScript, Declaration.",
"Directory '/packages/main/node_modules/@types' does not exist, skipping all lookups in it.",
"Scoped package detected, looking in 'typescript__lib-dom'",
"Directory '/packages/node_modules' does not exist, skipping all lookups in it.",
"Scoped package detected, looking in 'typescript__lib-dom'",
"Directory '/node_modules/@types' does not exist, skipping all lookups in it.",
"Scoped package detected, looking in 'typescript__lib-dom'",
"Loading module '@typescript/lib-dom' from 'node_modules' folder, target file types: JavaScript.",
"Searching all ancestor node_modules directories for fallback extensions: JavaScript.",
"Directory '/packages/node_modules' does not exist, skipping all lookups in it.",
"======== Module name '@typescript/lib-dom' was not resolved. ========",
"======== Resolving module '@typescript/lib-webworker/importscripts' from '/packages/main/__lib_node_modules_lookup_lib.webworker.importscripts.d.ts__.ts'. ========",
"Explicitly specified module resolution kind: 'Node10'.",
"Loading module '@typescript/lib-webworker/importscripts' from 'node_modules' folder, target file types: TypeScript, Declaration.",
"Searching all ancestor node_modules directories for preferred extensions: TypeScript, Declaration.",
"Directory '/packages/main/node_modules/@types' does not exist, skipping all lookups in it.",
"Scoped package detected, looking in 'typescript__lib-webworker/importscripts'",
"Directory '/packages/node_modules' does not exist, skipping all lookups in it.",
"Scoped package detected, looking in 'typescript__lib-webworker/importscripts'",
"Directory '/node_modules/@types' does not exist, skipping all lookups in it.",
"Scoped package detected, looking in 'typescript__lib-webworker/importscripts'",
"Loading module '@typescript/lib-webworker/importscripts' from 'node_modules' folder, target file types: JavaScript.",
"Searching all ancestor node_modules directories for fallback extensions: JavaScript.",
"Directory '/packages/node_modules' does not exist, skipping all lookups in it.",
"======== Module name '@typescript/lib-webworker/importscripts' was not resolved. ========",
"======== Resolving module '@typescript/lib-scripthost' from '/packages/main/__lib_node_modules_lookup_lib.scripthost.d.ts__.ts'. ========",
"Explicitly specified module resolution kind: 'Node10'.",
"Loading module '@typescript/lib-scripthost' from 'node_modules' folder, target file types: TypeScript, Declaration.",
"Searching all ancestor node_modules directories for preferred extensions: TypeScript, Declaration.",
"Directory '/packages/main/node_modules/@types' does not exist, skipping all lookups in it.",
"Scoped package detected, looking in 'typescript__lib-scripthost'",
"Directory '/packages/node_modules' does not exist, skipping all lookups in it.",
"Scoped package detected, looking in 'typescript__lib-scripthost'",
"Directory '/node_modules/@types' does not exist, skipping all lookups in it.",
"Scoped package detected, looking in 'typescript__lib-scripthost'",
"Loading module '@typescript/lib-scripthost' from 'node_modules' folder, target file types: JavaScript.",
"Searching all ancestor node_modules directories for fallback extensions: JavaScript.",
"Directory '/packages/node_modules' does not exist, skipping all lookups in it.",
"======== Module name '@typescript/lib-scripthost' was not resolved. ========"
"File '/package.json' does not exist."
]
1 change: 1 addition & 0 deletions tests/baselines/reference/api/typescript.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7025,6 +7025,7 @@ declare namespace ts {
/** @deprecated */
keyofStringsOnly?: boolean;
lib?: string[];
libReplacement?: boolean;
locale?: string;
mapRoot?: string;
maxNodeModuleJsDepth?: number;
Expand Down
Loading
Loading