mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-06-11 10:46:28 -05:00
Updates to type reference directive resolution and module resolution when failed (#51715)
This commit is contained in:
@@ -970,28 +970,36 @@ declare const eval: any`
|
||||
]
|
||||
});
|
||||
|
||||
verifyTscWatch({
|
||||
scenario,
|
||||
subScenario: "types should load from config file path if config exists",
|
||||
commandLineArgs: ["-w", "-p", configFilePath],
|
||||
sys: () => {
|
||||
const f1 = {
|
||||
path: "/a/b/app.ts",
|
||||
content: "let x = 1"
|
||||
};
|
||||
const config = {
|
||||
path: configFilePath,
|
||||
content: JSON.stringify({ compilerOptions: { types: ["node"], typeRoots: [] } })
|
||||
};
|
||||
const node = {
|
||||
path: "/a/b/node_modules/@types/node/index.d.ts",
|
||||
content: "declare var process: any"
|
||||
};
|
||||
const cwd = {
|
||||
path: "/a/c"
|
||||
};
|
||||
return createWatchedSystem([f1, config, node, cwd, libFile], { currentDirectory: cwd.path });
|
||||
},
|
||||
describe("types from config file", () => {
|
||||
function verifyTypesLoad(includeTypeRoots: boolean) {
|
||||
verifyTscWatch({
|
||||
scenario,
|
||||
subScenario: includeTypeRoots ?
|
||||
"types should not load from config file path if config exists but does not specifies typeRoots" :
|
||||
"types should load from config file path if config exists",
|
||||
commandLineArgs: ["-w", "-p", configFilePath],
|
||||
sys: () => {
|
||||
const f1 = {
|
||||
path: "/a/b/app.ts",
|
||||
content: "let x = 1"
|
||||
};
|
||||
const config = {
|
||||
path: configFilePath,
|
||||
content: JSON.stringify({ compilerOptions: { types: ["node"], typeRoots: includeTypeRoots ? [] : undefined } })
|
||||
};
|
||||
const node = {
|
||||
path: "/a/b/node_modules/@types/node/index.d.ts",
|
||||
content: "declare var process: any"
|
||||
};
|
||||
const cwd = {
|
||||
path: "/a/c"
|
||||
};
|
||||
return createWatchedSystem([f1, config, node, cwd, libFile], { currentDirectory: cwd.path });
|
||||
},
|
||||
});
|
||||
}
|
||||
verifyTypesLoad(/*includeTypeRoots*/ false);
|
||||
verifyTypesLoad(/*includeTypeRoots*/ true);
|
||||
});
|
||||
|
||||
verifyTscWatch({
|
||||
|
||||
@@ -345,27 +345,32 @@ describe("unittests:: tsserver:: resolutionCache:: tsserverProjectSystem rename
|
||||
projectService.checkNumberOfProjects({ configuredProjects: 1 });
|
||||
});
|
||||
|
||||
it("types should load from config file path if config exists", () => {
|
||||
const f1 = {
|
||||
path: "/a/b/app.ts",
|
||||
content: "let x = 1"
|
||||
};
|
||||
const config = {
|
||||
path: "/a/b/tsconfig.json",
|
||||
content: JSON.stringify({ compilerOptions: { types: ["node"], typeRoots: [] } })
|
||||
};
|
||||
const node = {
|
||||
path: "/a/b/node_modules/@types/node/index.d.ts",
|
||||
content: "declare var process: any"
|
||||
};
|
||||
const cwd = {
|
||||
path: "/a/c"
|
||||
};
|
||||
const host = createServerHost([f1, config, node, cwd], { currentDirectory: cwd.path });
|
||||
const projectService = createProjectService(host);
|
||||
projectService.openClientFile(f1.path);
|
||||
projectService.checkNumberOfProjects({ configuredProjects: 1 });
|
||||
checkProjectActualFiles(configuredProjectAt(projectService, 0), [f1.path, node.path, config.path]);
|
||||
describe("types from config file", () => {
|
||||
function verifyTypesLoad(subScenario: string, includeTypeRoots: boolean) {
|
||||
it(subScenario, () => {
|
||||
const f1 = {
|
||||
path: "/a/b/app.ts",
|
||||
content: "let x = 1"
|
||||
};
|
||||
const config = {
|
||||
path: "/a/b/tsconfig.json",
|
||||
content: JSON.stringify({ compilerOptions: { types: ["node"], typeRoots: includeTypeRoots ? [] : undefined } })
|
||||
};
|
||||
const node = {
|
||||
path: "/a/b/node_modules/@types/node/index.d.ts",
|
||||
content: "declare var process: any"
|
||||
};
|
||||
const cwd = {
|
||||
path: "/a/c"
|
||||
};
|
||||
const host = createServerHost([f1, config, node, cwd], { currentDirectory: cwd.path });
|
||||
const projectService = createProjectService(host, { logger: createLoggerWithInMemoryLogs(host) });
|
||||
projectService.openClientFile(f1.path);
|
||||
baselineTsserverLogs("resolutionCache", subScenario, projectService);
|
||||
});
|
||||
}
|
||||
verifyTypesLoad("types should load from config file path if config exists", /*includeTypeRoots*/ false);
|
||||
verifyTypesLoad("types should not load from config file path if config exists but does not specifies typeRoots", /*includeTypeRoots*/ true);
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user