mirror of
https://github.com/microsoft/TypeScript.git
synced 2025-11-18 17:21:48 +00:00
Correctly use ownMap from module resolution cache (#43986)
* Test showing the moduleResolutionCache reset issue with tsc --b --w * Fix incorrect usage of ownMap by making it function returning ownMap instead of constant value
This commit is contained in:
@@ -504,7 +504,7 @@ namespace ts {
|
||||
|
||||
/*@internal*/
|
||||
export interface CacheWithRedirects<T> {
|
||||
ownMap: ESMap<string, T>;
|
||||
getOwnMap: () => ESMap<string, T>;
|
||||
redirectsMap: ESMap<Path, ESMap<string, T>>;
|
||||
getOrCreateMapOfCacheRedirects(redirectedReference: ResolvedProjectReference | undefined): ESMap<string, T>;
|
||||
clear(): void;
|
||||
@@ -517,7 +517,7 @@ namespace ts {
|
||||
let ownMap: ESMap<string, T> = new Map();
|
||||
const redirectsMap = new Map<Path, ESMap<string, T>>();
|
||||
return {
|
||||
ownMap,
|
||||
getOwnMap,
|
||||
redirectsMap,
|
||||
getOrCreateMapOfCacheRedirects,
|
||||
clear,
|
||||
@@ -525,6 +525,10 @@ namespace ts {
|
||||
setOwnMap
|
||||
};
|
||||
|
||||
function getOwnMap() {
|
||||
return ownMap;
|
||||
}
|
||||
|
||||
function setOwnOptions(newOptions: CompilerOptions) {
|
||||
options = newOptions;
|
||||
}
|
||||
@@ -586,10 +590,10 @@ namespace ts {
|
||||
if (directoryToModuleNameMap.redirectsMap.size === 0) {
|
||||
// The own map will be for projectCompilerOptions
|
||||
Debug.assert(!moduleNameToDirectoryMap || moduleNameToDirectoryMap.redirectsMap.size === 0);
|
||||
Debug.assert(directoryToModuleNameMap.ownMap.size === 0);
|
||||
Debug.assert(!moduleNameToDirectoryMap || moduleNameToDirectoryMap.ownMap.size === 0);
|
||||
directoryToModuleNameMap.redirectsMap.set(options.configFile.path, directoryToModuleNameMap.ownMap);
|
||||
moduleNameToDirectoryMap?.redirectsMap.set(options.configFile.path, moduleNameToDirectoryMap.ownMap);
|
||||
Debug.assert(directoryToModuleNameMap.getOwnMap().size === 0);
|
||||
Debug.assert(!moduleNameToDirectoryMap || moduleNameToDirectoryMap.getOwnMap().size === 0);
|
||||
directoryToModuleNameMap.redirectsMap.set(options.configFile.path, directoryToModuleNameMap.getOwnMap());
|
||||
moduleNameToDirectoryMap?.redirectsMap.set(options.configFile.path, moduleNameToDirectoryMap.getOwnMap());
|
||||
}
|
||||
else {
|
||||
// Set correct own map
|
||||
|
||||
@@ -1020,4 +1020,59 @@ const a: string = "hello";`),
|
||||
]
|
||||
});
|
||||
});
|
||||
|
||||
describe("unittests:: tsbuild:: watchMode:: module resolution different in referenced project", () => {
|
||||
verifyTscWatch({
|
||||
scenario: "moduleResolutionCache",
|
||||
subScenario: "handles the cache correctly when two projects use different module resolution settings",
|
||||
sys: () => createWatchedSystem(
|
||||
[
|
||||
{ path: `${projectRoot}/project1/index.ts`, content: `import { foo } from "file";` },
|
||||
{ path: `${projectRoot}/project1/node_modules/file/index.d.ts`, content: "export const foo = 10;" },
|
||||
{
|
||||
path: `${projectRoot}/project1/tsconfig.json`,
|
||||
content: JSON.stringify({
|
||||
compilerOptions: { composite: true, types: ["foo", "bar"] },
|
||||
files: ["index.ts"]
|
||||
})
|
||||
},
|
||||
{ path: `${projectRoot}/project2/index.ts`, content: `import { foo } from "file";` },
|
||||
{ path: `${projectRoot}/project2/file.d.ts`, content: "export const foo = 10;" },
|
||||
{
|
||||
path: `${projectRoot}/project2/tsconfig.json`,
|
||||
content: JSON.stringify({
|
||||
compilerOptions: { composite: true, types: ["foo"], moduleResolution: "classic" },
|
||||
files: ["index.ts"]
|
||||
})
|
||||
},
|
||||
{ path: `${projectRoot}/node_modules/@types/foo/index.d.ts`, content: "export const foo = 10;" },
|
||||
{ path: `${projectRoot}/node_modules/@types/bar/index.d.ts`, content: "export const bar = 10;" },
|
||||
{
|
||||
path: `${projectRoot}/tsconfig.json`,
|
||||
content: JSON.stringify({
|
||||
files: [],
|
||||
references: [
|
||||
{ path: "./project1" },
|
||||
{ path: "./project2" }
|
||||
]
|
||||
})
|
||||
},
|
||||
libFile
|
||||
],
|
||||
{ currentDirectory: projectRoot }
|
||||
),
|
||||
commandLineArgs: ["--b", "-w", "-v"],
|
||||
changes: [
|
||||
{
|
||||
caption: "Append text",
|
||||
change: sys => sys.appendFile(`${projectRoot}/project1/index.ts`, "const bar = 10;"),
|
||||
timeouts: sys => {
|
||||
sys.checkTimeoutQueueLengthAndRun(1); // build project1
|
||||
sys.checkTimeoutQueueLengthAndRun(1); // Solution
|
||||
sys.checkTimeoutQueueLength(0);
|
||||
}
|
||||
},
|
||||
]
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user