8000 [WIP] Caching resolutions in buildInfo and reusing them by sheetalkamat · Pull Request #50007 · microsoft/TypeScript · GitHub
[go: up one dir, main page]

Skip to content

[WIP] Caching resolutions in buildInfo and reusing them #50007

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

Closed
wants to merge 31 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
3172629
Add new option to cacheResolution (No actual functionality yet)
sheetalkamat Jun 30, 2022
e1600ab
Add baselining of modules and type refs
sheetalkamat Dec 9, 2022
666eece
Add tests
sheetalkamat Jul 1, 2022
1eeea26
Store resolved module and type reference resolution cache in buildinfo
sheetalkamat Jul 7, 2022
76100d7
Read reusable module cache information from the buildinfo
sheetalkamat Jul 8, 2022
4bc74b9
Add reusing cache stub
sheetalkamat Jul 8, 2022
23cfc79
Buildinfo resolutions actually reused
sheetalkamat Jul 18, 2022
0132dc0
Handle project reference redirects for the module and type reference …
sheetalkamat Jul 22, 2022
d55ab98
Test for module resolutions from different directories
sheetalkamat Jul 22, 2022
ce07d0e
Handle resolutions that would be same in ancestor directory and can b…
sheetalkamat Jul 23, 2022
959206d
Do not store failed lookups with cacheResolution option if it is reso…
sheetalkamat Jul 25, 2022
0446430
Add tests where module resolution caches should reuse the resolutions…
sheetalkamat Jul 25, 2022
207226a
Reusing resolutions in tsserver scenario
sheetalkamat Jul 25, 2022
591960e
Set old program build info as a location to look for from module reso…
sheetalkamat Jul 25, 2022
71ebed9
Modify resolution cache to update on program creation completion
sheetalkamat Nov 29, 2022
4d127fa
Remove files that are not in program from cache of unresolved imports
sheetalkamat Jul 27, 2022
feb3220
Tests for unresolved imports from multiple places
sheetalkamat Jul 27, 2022
84cda33
More tests for cache reuse directory structure
sheetalkamat Jul 27, 2022
2219b5d
Start using cache as perDirectory lookup
sheetalkamat Nov 16, 2022
6261b6c
Add tests where cache resoluition is incorrectly used because of not …
sheetalkamat Jul 27, 2022
e1ed9ea
Store package json hash in buildinfo
sheetalkamat Nov 29, 2022
7de4780
Use the hashes to verify the affecting location before using the reso…
sheetalkamat Jul 28, 2022
5c11252
Add tests for package json edits
sheetalkamat Aug 2, 2022
e21738c
Store package.json for the directories in buildinfo
sheetalkamat Aug 2, 2022
be5ecb2
During cacheResolutions dont watch failed lookups and dont look at th…
sheetalkamat Aug 3, 2022
78e215f
Dont store package json path if its found in same directory
sheetalkamat Aug 4, 2022
1e123ec
Cache packagejson scopes per directory
sheetalkamat Dec 9, 2022
81a1af9
Dont store isExternalLibraryImport in the buildInfo
sheetalkamat Dec 9, 2022
3115572
Store resolvedFileName as fileId instead of structure if thats the on…
sheetalkamat Dec 10, 2022
2bb56da
Always respect preserveSymlinks
sheetalkamat Dec 10, 2022
b179c7c
Dont store originalPath as separate, instead store originalPath || re…
sheetalkamat Dec 10, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Tests for unresolved imports from multiple places
  • Loading branch information
sheetalkamat committed Dec 9, 2022
commit feb322029967ef6e354e52145c49e1509b18494d
27 changes: 27 additions & 0 deletions src/testRunner/unittests/tsbuild/cacheResolutions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,33 @@ describe("unittests:: tsbuild:: cacheResolutions::", () => {
caption: "modify e/ea/eaa/eaaa/x/y/z/ra 8000 ndomFileForImport by adding import",
edit: fs => prependText(fs, "/src/project/e/ea/eaa/eaaa/x/y/z/randomFileForImport.ts", `import type { ImportInterface0 } from "pkg0";\n`),
},
{
caption: "modify randomFileForImport by adding unresolved import",
edit: fs => prependText(fs, "/src/project/randomFileForImport.ts", `import type { ImportInterface1 } from "pkg1";\n`),
},
{
caption: "modify b/randomFileForImport by adding unresolved import",
edit: fs => prependText(fs, "/src/project/b/randomFileForImport.ts", `import type { ImportInterface1 } from "pkg1";\n`),
},
{
caption: "modify c/ca/caa/randomFileForImport by adding unresolved import",
edit: fs => prependText(fs, "/src/project/c/ca/caa/randomFileForImport.ts", `import type { ImportInterface1 } from "pkg1";\n`),
},
{
caption: "modify d/da/daa/daaa/x/y/z/randomFileForImport by adding unresolved import",
edit: fs => prependText(fs, "/src/project/d/da/daa/daaa/x/y/z/randomFileForImport.ts", `import type { ImportInterface1 } from "pkg1";\n`),
},
{
caption: "modify e/ea/eaa/eaaa/x/y/z/randomFileForImport by adding unresolved import",
edit: fs => prependText(fs, "/src/project/e/ea/eaa/eaaa/x/y/z/randomFileForImport.ts", `import type { ImportInterface1 } from "pkg1";\n`),
},
{
caption: "add file for unresolved import",
edit: fs => {
fs.mkdirpSync("/src/project/node_modules/pkg1");
fs.writeFileSync("/src/project/node_modules/pkg1/index.d.ts", getPkgImportContent("Import", 1));
},
},
]
});
});
12 changes: 12 additions & 0 deletions src/testRunner/unittests/tsbuild/cacheResolutionsHelper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -273,43 +273,55 @@ function getFsMapWithSameResolutionFromMultiplePlaces(): { [path: string]: strin
}),
"/src/project/fileWithImports.ts": Utils.dedent`
import type { ImportInterface0 } from "pkg0";
import type { ImportInterface1 } from "pkg1";
`,
"/src/project/randomFileForImport.ts": getRandomFileContent(),
"/src/project/a/fileWithImports.ts": Utils.dedent`
import type { ImportInterface0 } from "pkg0";
import type { ImportInterface1 } from "pkg1";
`,
"/src/project/b/ba/fileWithImports.ts": Utils.dedent`
import type { ImportInterface0 } from "pkg0";
import type { ImportInterface1 } from "pkg1";
`,
"/src/project/b/randomFileForImport.ts": getRandomFileContent(),
"/src/project/c/ca/fileWithImports.ts": Utils.dedent`
import type { ImportInterface0 } from "pkg0";
import type { ImportInterface1 } from "pkg1";
`,
"/src/project/c/ca/caa/randomFileForImport.ts": getRandomFileContent(),
"/src/project/c/ca/caa/caaa/fileWithImports.ts": Utils.dedent`
import type { ImportInterface0 } from "pkg0";
import type { ImportInterface1 } from "pkg1";
`,
"/src/project/c/cb/fileWithImports.ts": Utils.dedent`
import type { ImportInterface0 } from "pkg0";
import type { ImportInterface1 } from "pkg1";
`,
"/src/project/d/da/daa/daaa/x/y/z/randomFileForImport.ts": getRandomFileContent(),
"/src/project/d/da/daa/daaa/fileWithImports.ts": Utils.dedent`
import type { ImportInterface0 } from "pkg0";
import type { ImportInterface1 } from "pkg1";
`,
"/src/project/d/da/daa/fileWithImports.ts": Utils.dedent`
import type { ImportInterface0 } from "pkg0";
import type { ImportInterface1 } from "pkg1";
`,
"/src/project/d/da/fileWithImports.ts": Utils.dedent`
import type { ImportInterface0 } from "pkg0";
import type { ImportInterface1 } from "pkg1";
`,
"/src/project/e/ea/fileWithImports.ts": Utils.dedent`
import type { ImportInterface0 } from "pkg0";
import type { ImportInterface1 } from "pkg1";
`,
"/src/project/e/ea/eaa/fileWithImports.ts": Utils.dedent`
import type { ImportInterface0 } from "pkg0";
import type { ImportInterface1 } from "pkg1";
`,
"/src/project/e/ea/eaa/eaaa/fileWithImports.ts": Utils.dedent`
import type { ImportInterface0 } from "pkg0";
import type { ImportInterface1 } from "pkg1";
`,
"/src/project/e/ea/eaa/eaaa/x/y/z/randomFileForImport.ts": getRandomFileContent(),
"/src/project/node_modules/pkg0/index.d.ts": getPkgImportContent("Import", 0),
Expand Down
33 changes: 33 additions & 0 deletions src/testRunner/unittests/tsbuildWatch/cacheResolutions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,39 @@ describe("unittests:: tsbuildWatch:: watchMode:: cacheResolutions::", () => {
edit: sys => sys.prependFile("/src/project/e/ea/eaa/eaaa/x/y/z/randomFileForImport.ts", `import type { ImportInterface0 } from "pkg0";\n`),
timeouts: sys => sys.runQueuedTimeoutCallbacks(),
},
{
caption: "modify randomFileForImport by adding unresolved import",
edit: sys => sys.prependFile("/src/project/randomFileForImport.ts", `import type { ImportInterface1 } from "pkg1";\n`),
timeouts: sys => sys.runQueuedTimeoutCallbacks(),
},
{
caption: "modify b/randomFileForImport by adding unresolved import",
edit: sys => sys.prependFile("/src/project/b/randomFileForImport.ts", `import type { ImportInterface1 } from "pkg1";\n`),
timeouts: sys => sys.runQueuedTimeoutCallbacks(),
},
{
caption: "modify c/ca/caa/randomFileForImport by adding unresolved import",
edit: sys => sys.prependFile("/src/project/c/ca/caa/randomFileForImport.ts", `import type { ImportInterface1 } from "pkg1";\n`),
timeouts: sys => sys.runQueuedTimeoutCallbacks(),
},
{
caption: "modify d/da/daa/daaa/x/y/z/randomFileForImport by adding unresolved import",
edit: sys => sys.prependFile("/src/project/d/da/daa/daaa/x/y/z/randomFileForImport.ts", `import type { ImportInterface1 } from "pkg1";\n`),
timeouts: sys => sys.runQueuedTimeoutCallbacks(),
},
{
caption: "modify e/ea/eaa/eaaa/x/y/z/randomFileForImport by adding unresolved import",
edit: sys => sys.prependFile("/src/project/e/ea/eaa/eaaa/x/y/z/randomFileForImport.ts", `import type { ImportInterface1 } from "pkg1";\n`),
timeouts: sys => sys.runQueuedTimeoutCallbacks(),
},
{
caption: "add file for unresolved import and random edit",
edit: sys => {
sys.ensureFileOrFolder({ path: "/src/project/node_modules/pkg1/index.d.ts", content: getPkgImportContent("Import", 1) });
sys.appendFile("/src/project/randomFileForImport.ts", `export const y = 10;`);
},
timeouts: sys => sys.runQueuedTimeoutCallbacks(),
},
]
});
}
Expand Down
27 changes: 27 additions & 0 deletions src/testRunner/unittests/tsc/cacheResolutions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,33 @@ describe("unittests:: tsc:: cacheResolutions::", () => {
caption: "modify e/ea/eaa/eaaa/x/y/z/randomFileForImport by adding import",
edit: fs => prependText(fs, "/src/project/e/ea/eaa/eaaa/x/y/z/randomFileForImport.ts", `import type { ImportInterface0 } from "pkg0";\n`),
},
{
caption: "modify randomFileForImport by adding unresolved import",
edit: fs => prependText(fs, "/src/project/randomFileForImport.ts", `import type { ImportInterface1 } from "pkg1";\n`),
},
{
caption: "modify b/randomFileForImport by adding unresolved import",
edit: fs => prependText(fs, "/src/project/b/randomFileForImport.ts", `import type { ImportInterface1 } from "pkg1";\n`),
},
{
caption: "modify c/ca/caa/randomFileForImport by adding unresolved import",
edit: fs => prependText(fs, "/src/project/c/ca/caa/randomFileForImport.ts", `import type { ImportInterface1 } from "pkg1";\n`),
},
{
caption: "modify d/da/daa/daaa/x/y/z/randomFileForImport by adding unresolved import",
edit: fs => prependText(fs, "/src/project/d/da/daa/daaa/x/y/z/randomFileForImport.ts", `import type { ImportInterface1 } from "pkg1";\n`),
},
{
caption: "modify e/ea/eaa/eaaa/x/y/z/randomFileForImport by adding unresolved import",
edit: fs => prependText(fs, "/src/project/e/ea/eaa/eaaa/x/y/z/randomFileForImport.ts", `import type { ImportInterface1 } from "pkg1";\n`),
},
{
caption: "add file for unresolved import",
edit: fs => {
fs.mkdirpSync("/src/project/node_modules/pkg1");
fs.writeFileSync("/src/project/node_modules/pkg1/index.d.ts", getPkgImportContent("Import", 1));
},
},
]
});
});
36 changes: 36 additions & 0 deletions src/testRunner/unittests/tscWatch/cacheResolutions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,42 @@ describe("unittests:: tsc-watch:: cacheResolutions::", () => {
edit: sys => sys.prependFile("/src/project/e/ea/eaa/eaaa/x/y/z/randomFileForImport.ts", `import type { ImportInterface0 } from "pkg0";\n`),
timeouts: sys => sys.runQueuedTimeoutCallbacks(),
},
{
caption: "modify randomFileForImport by adding unresolved import",
edit: sys => sys.prependFile("/src/project/randomFileForImport.ts", `import type { ImportInterface1 } from "pkg1";\n`),
timeouts: sys => sys.runQueuedTimeoutCallbacks(),
},
{
caption: "modify b/randomFileForImport by adding unresolved import",
edit: sys => sys.prependFile("/src/project/b/randomFileForImport.ts", `import type { ImportInterface1 } from "pkg1";\n`),
timeouts: sys => sys.runQueuedTimeoutCallbacks(),
},
{
caption: "modify c/ca/caa/randomFileForImport by adding unresolved import",
edit: sys => sys.prependFile("/src/project/c/ca/caa/randomFileForImport.ts", `import type { ImportInterface1 } from "pkg1";\n`),
timeouts: sys => sys.runQueuedTimeoutCallbacks(),
},
{
caption: "modify d/da/daa/daaa/x/y/z/randomFileForImport by adding unresolved import",
edit: sys => sys.prependFile("/src/project/d/da/daa/daaa/x/y/z/randomFileForImport.ts", `import type { ImportInterface1 } from "pkg1";\n`),
timeouts: sys => sys.runQueuedTimeoutCallbacks(),
},
{
caption: "modify e/ea/eaa/eaaa/x/y/z/randomFileForImport by adding unresolved import",
edit: sys => sys.prependFile("/src/project/e/ea/eaa/eaaa/x/y/z/randomFileForImport.ts", `import type { ImportInterface1 } from "pkg1";\n`),
timeouts: sys => sys.runQueuedTimeoutCallbacks(),
},
{
caption: "add file for unresolved import and random edit",
edit: sys => {
sys.ensureFileOrFolder({ path: "/src/project/node_modules/pkg1/index.d.ts", content: getPkgImportContent("Import", 1) });
sys.appendFile("/src/project/randomFileForImport.ts", `export const y = 10;`);
},
timeouts: sys => {
sys.runQueuedTimeoutCallbacks(); // Failed lookups
sys.runQueuedTimeoutCallbacks(); // actual update
},
},
]
});
}
Expand Down
76 changes: 76 additions & 0 deletions src/testRunner/unittests/tsserver/cacheResolutions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -292,6 +292,82 @@ describe("unittests:: tsserver:: cacheResolutions:: tsserverProjectSystem cachin
});
ts.server.updateProjectIfDirty(session.getProjectService().configuredProjects.get("/src/project/tsconfig.json")!);

session.logger.info("modify randomFileForImport by adding unresolved import");
session.executeCommandSeq<ts.server.protocol.ChangeRequest>({
command: ts.server.protocol.CommandTypes.Change,
arguments: {
file: "/src/project/randomFileForImport.ts",
line: 1,
offset: 1,
endLine: 1,
endOffset: 1,
insertString: `import type { ImportInterface1 } from "pkg1";\n`,
}
});
ts.server.updateProjectIfDirty(session.getProjectService().configuredProjects.get("/src/project/tsconfig.json")!);

session.logger.info("modify b/randomFileForImport by adding unresolved import");
session.executeCommandSeq<ts.server.protocol.ChangeRequest>({
command: ts.server.protocol.CommandTypes.Change,
arguments: {
file: "/src/project/b/randomFileForImport.ts",
line: 1,
offset: 1,
endLine: 1,
endOffset: 1,
insertString: `import type { ImportInterface1 } from "pkg1";\n`,
}
});
ts.server.updateProjectIfDirty(session.getProjectService().configuredProjects.get("/src/project/tsconfig.json")!);

session.logger.info("modify c/ca/caa/randomFileForImport by adding unresolved import");
session.executeCommandSeq<ts.server.protocol.ChangeRequest>({
command: ts.server.protocol.CommandTypes.Change,
arguments: {
file: "/src/project/c/ca/caa/randomFileForImport.ts",
line: 1,
offset: 1,
endLine: 1,
endOffset: 1,
insertString: `import type { ImportInterface1 } from "pkg1";\n`,
}
});
ts.server.updateProjectIfDirty(session.getProjectService().configuredProjects.get("/src/project/tsconfig.json")!);

session.logger.info("modify d/da/daa/daaa/x/y/z/randomFileForImport by adding unresolved import");
session.executeCommandSeq<ts.server.protocol.ChangeRequest>({
command: ts.server.protocol.CommandTypes.Change,
arguments: {
file: "/src/project/d/da/daa/daaa/x/y/z/randomFileForImport.ts",
line: 1,
offset: 1,
endLine: 1,
endOffset: 1,
insertString: `import type { ImportInterface1 } from "pkg1";\n`,
}
});
ts.server.updateProjectIfDirty(session.getProjectService().configuredProjects.get("/src/project/tsconfig.json")!);

session.logger.info("modify e/ea/eaa/eaaa/x/y/z/randomFileForImport by adding unresolved import");
session.executeCommandSeq<ts.server.protocol.ChangeRequest>({
command: ts.server.protocol.CommandTypes.Change,
arguments: {
file: "/src/project/e/ea/eaa/eaaa/x/y/z/randomFileForImport.ts",
line: 1,
offset: 1,
endLine: 1,
endOffset: 1,
insertString: `import type { ImportInterface1 } from "pkg1";\n`,
}
});
ts.server.updateProjectIfDirty(session.getProjectService().configuredProjects.get("/src/project/tsconfig.json")!);

session.logger.info("add file for unresolved import and random edit");
host.ensureFileOrFolder({ path: "/src/project/node_modules/pkg1/index.d.ts", content: getPkgImportContent("Import", 1) });
host.appendFile("/src/project/randomFileForImport.ts", `export const y = 10;`);
host.runQueuedTimeoutCallbacks(); // Failed lookups
host.runQueuedTimeoutCallbacks(); // actual update

baselineTsserverLogs("cacheResolutions", scenario, session);
});
}
Expand Down
Loading
0