Skip to content
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

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
Add tests for package json edits
  • Loading branch information
sheetalkamat committed Dec 9, 2022
commit 5c11252b71c8a4741d2b65affbf31aaebdb86e64
50 changes: 50 additions & 0 deletions src/testRunner/unittests/tsbuild/cacheResolutions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import {
getFsWithMultipleProjects,
getFsWithNode16,
getFsWithOut,
getFsWithPackageJsonEdits,
getFsWithSameResolutionFromMultiplePlaces,
getPkgImportContent,
getPkgTypeRefContent,
Expand Down Expand Up @@ -213,4 +214,53 @@ describe("unittests:: tsbuild:: cacheResolutions::", () => {
},
]
});

verifyTsc({
scenario: "cacheResolutions",
subScenario: "packageJson edited",
commandLineArgs: ["--b", "/src/projects/project/src", "--explainFiles"],
fs: getFsWithPackageJsonEdits,
baselineModulesAndTypeRefs: true,
edits: [
{
caption: "random edit",
edit: fs => appendText(fs, "/src/projects/project/src/randomFile.ts", `export const y = 10;`),
},
{
caption: "Modify package json file to add type module",
edit: fs => fs.writeFileSync(`/src/projects/project/package.json`, JSON.stringify({ name: "app", version: "1.0.0", type: "module" })),
},
{
caption: "Modify package.json file to remove type module and randmon edit",
edit: fs => {
fs.writeFileSync(`/src/projects/project/package.json`, JSON.stringify({ name: "app", version: "1.0.0" }));
appendText(fs, "/src/projects/project/src/randomFile.ts", `export const z = 10;`);
},
discrepancyExplanation: () => [
`Clean build and incremental build differ in emit signature and latestChangedDtsFile since incremental persists it from previous build and clean has errors`
]
},
{
caption: "Delete package.json",
edit: fs => fs.unlinkSync(`/src/projects/project/package.json`),
discrepancyExplanation: () => [
`Clean build and incremental build differ in emit signature and latestChangedDtsFile since incremental persists it from previous build and clean has errors`
]
},
{
caption: "Add package json file with type module",
edit: fs => fs.writeFileSync(`/src/projects/project/package.json`, JSON.stringify({ name: "app", version: "1.0.0", type: "module" })),
},
{
caption: "Delete package.json and random edit",
edit: fs => {
fs.unlinkSync(`/src/projects/project/package.json`);
appendText(fs, "/src/projects/project/src/randomFile.ts", `export const k = 10;`);
},
discrepancyExplanation: () => [
`Clean build and incremental build differ in emit signature and latestChangedDtsFile since incremental persists it from previous build and clean has errors`
]
},
],
});
});
89 changes: 89 additions & 0 deletions src/testRunner/unittests/tsbuild/cacheResolutionsHelper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -361,4 +361,93 @@ export function getServerHostWithSameResolutionFromMultiplePlacesWithBuild() {
const system = getServerHostWithSameResolutionFromMultiplePlaces();
solutionBuildWithBaseline(system, ["/src/project"]);
return system;
}

function getFsMapWithPackageJsonEdits(): { [path: string]: string; } {
return {
"/src/projects/project/src/tsconfig.json": JSON.stringify({
compilerOptions: {
target: "es2016",
composite: true,
module: "node16",
outDir: "../out",
cacheResolutions: true,
traceResolution: true,
},
files: [
"fileA.ts",
"fileB.mts",
"randomFile.ts",
"a/randomFile.ts",
"b/ba/randomFile.ts",
"b/randomFile.ts",
"c/ca/randomFile.ts",
"c/ca/caa/randomFile.ts",
"c/ca/caa/caaa/randomFile.ts",
"c/cb/randomFile.ts",
"d/da/daa/daaa/x/y/z/randomFile.ts",
"d/da/daa/daaa/randomFile.ts",
"d/da/daa/randomFile.ts",
"d/da/randomFile.ts",
"e/ea/randomFile.ts",
"e/ea/eaa/randomFile.ts",
"e/ea/eaa/eaaa/randomFile.ts",
"e/ea/eaa/eaaa/x/y/z/randomFile.ts",
"f/fa/faa/x/y/z/randomFile.ts",
"f/fa/faa/faaa/randomFile.ts",
],
}),
"/src/projects/project/src/fileA.ts": Utils.dedent`
import { foo } from "./fileB.mjs";
foo();
`,
"/src/projects/project/src/fileB.mts": `export function foo() {}`,
"/src/projects/project/src/randomFile.ts": getRandomFileContent(),
"/src/projects/project/src/a/randomFile.ts": getRandomFileContent(),
"/src/projects/project/src/b/ba/randomFile.ts": getRandomFileContent(),
"/src/projects/project/src/b/randomFile.ts": getRandomFileContent(),
"/src/projects/project/src/c/ca/randomFile.ts": getRandomFileContent(),
"/src/projects/project/src/c/ca/caa/randomFile.ts": getRandomFileContent(),
"/src/projects/project/src/c/ca/caa/caaa/randomFile.ts": getRandomFileContent(),
"/src/projects/project/src/c/cb/randomFile.ts": getRandomFileContent(),
"/src/projects/project/src/d/da/daa/daaa/x/y/z/randomFile.ts": getRandomFileContent(),
"/src/projects/project/src/d/da/daa/daaa/randomFile.ts": getRandomFileContent(),
"/src/projects/project/src/d/da/daa/randomFile.ts": getRandomFileContent(),
"/src/projects/project/src/d/da/randomFile.ts": getRandomFileContent(),
"/src/projects/project/src/e/ea/randomFile.ts": getRandomFileContent(),
"/src/projects/project/src/e/ea/eaa/randomFile.ts": getRandomFileContent(),
"/src/projects/project/src/e/ea/eaa/eaaa/randomFile.ts": getRandomFileContent(),
"/src/projects/project/src/e/ea/eaa/eaaa/x/y/z/randomFile.ts": getRandomFileContent(),
"/src/projects/project/src/f/fa/faa/faaa/randomFile.ts": getRandomFileContent(),
"/src/projects/project/src/f/fa/faa/x/y/z/randomFile.ts": getRandomFileContent(),
"/src/projects/project/package.json": JSON.stringify({ name: "app", version: "1.0.0" }),
};
}

export function getFsWithPackageJsonEdits() {
return loadProjectFromFiles(getFsMapWithPackageJsonEdits(), /*libContentsToAppend*/ undefined, "/lib/lib.es2016.full.d.ts");
}

export function getWatchSystemWithPackageJsonEdits() {
const system = createWatchedSystem(getFsMapWithPackageJsonEdits(), { currentDirectory: "/src/projects/project" });
system.ensureFileOrFolder({ ...libFile, path: "/a/lib/lib.es2016.full.d.ts" });
return system;
}

export function getServerHostWithPackageJsonEdits() {
const system = createServerHost(getFsMapWithPackageJsonEdits(), { currentDirectory: "/src/projects/project" });
system.ensureFileOrFolder({ ...libFile, path: "/a/lib/lib.es2016.full.d.ts" });
return system;
}

export function getWatchSystemWithPackageJsonEditsWithBuild() {
const system = getWatchSystemWithPackageJsonEdits();
solutionBuildWithBaseline(system, ["/src/project/src"]);
return system;
}

export function getServerHostWithPackageJsonEditsWithBuild() {
const system = getServerHostWithPackageJsonEdits();
solutionBuildWithBaseline(system, ["/src/project/src"]);
return system;
}
54 changes: 54 additions & 0 deletions src/testRunner/unittests/tsbuildWatch/cacheResolutions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ import {
getWatchSystemWithNode16WithBuild,
getWatchSystemWithOut,
getWatchSystemWithOutWithBuild,
getWatchSystemWithPackageJsonEdits,
getWatchSystemWithPackageJsonEditsWithBuild,
getWatchSystemWithSameResolutionFromMultiplePlaces,
getWatchSystemWithSameResolutionFromMultiplePlacesWithBuild,
} from "../tsbuild/cacheResolutionsHelper";
Expand Down Expand Up @@ -265,4 +267,56 @@ describe("unittests:: tsbuildWatch:: watchMode:: cacheResolutions::", () => {
});
}
});

describe("packageJson edited", () => {
verifyTscWatchPackageJsonEdits("packageJson edited", getWatchSystemWithPackageJsonEdits);
verifyTscWatchPackageJsonEdits("packageJson edited already built", getWatchSystemWithPackageJsonEditsWithBuild);
function verifyTscWatchPackageJsonEdits(subScenario: string, sys: () => TestServerHost) {
verifyTscWatch({
scenario: "cacheResolutions",
subScenario,
commandLineArgs: ["--b", "src", "-w", "--explainFiles", "--extendedDiagnostics"],
baselineModulesAndTypeRefs: true,
sys,
edits: [
{
caption: "random edit",
edit: sys => sys.appendFile("/src/projects/project/src/randomFile.ts", `export const y = 10;`),
timeouts: sys => sys.runQueuedTimeoutCallbacks(),
},
{
caption: "Modify package json file to add type module",
edit: sys => sys.writeFile(`/src/projects/project/package.json`, JSON.stringify({ name: "app", version: "1.0.0", type: "module" })),
timeouts: sys => sys.runQueuedTimeoutCallbacks(),
},
{
caption: "Modify package.json file to remove type module and random edit",
edit: sys => {
sys.writeFile(`/src/projects/project/package.json`, JSON.stringify({ name: "app", version: "1.0.0" }));
sys.appendFile("/src/projects/project/src/randomFile.ts", `export const z = 10;`);
},
timeouts: sys => sys.runQueuedTimeoutCallbacks(),
},
{
caption: "Delete package.json",
edit: sys => sys.deleteFile(`/src/projects/project/package.json`),
timeouts: sys => sys.runQueuedTimeoutCallbacks(),
},
{
caption: "Add package json file with type module",
edit: sys => sys.writeFile(`/src/projects/project/package.json`, JSON.stringify({ name: "app", version: "1.0.0", type: "module" })),
timeouts: sys => sys.runQueuedTimeoutCallbacks(),
},
{
caption: "Delete package.json and random edit and random edit",
edit: sys => {
sys.deleteFile(`/src/projects/project/package.json`);
sys.appendFile("/src/projects/project/src/randomFile.ts", `export const k = 10;`);
},
timeouts: sys => sys.runQueuedTimeoutCallbacks(),
},
],
});
}
});
});
36 changes: 36 additions & 0 deletions src/testRunner/unittests/tsc/cacheResolutions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,13 @@ import {
import {
getFsWithNode16,
getFsWithOut,
getFsWithPackageJsonEdits,
getFsWithSameResolutionFromMultiplePlaces,
getPkgImportContent,
getPkgTypeRefContent,
} from "../tsbuild/cacheResolutionsHelper";
import {
appendText,
loadProjectFromFiles,
noChangeRun,
prependText,
Expand Down Expand Up @@ -298,4 +300,38 @@ describe("unittests:: tsc:: cacheResolutions::", () => {
},
]
});

verifyTsc({
scenario: "cacheResolutions",
subScenario: "packageJson edited",
commandLineArgs: ["--p", "/src/projects/project/src", "--explainFiles"],
baselineModulesAndTypeRefs: true,
fs: getFsWithPackageJsonEdits,
edits: [
{
caption: "random edit",
edit: fs => appendText(fs, "/src/projects/project/src/randomFile.ts", `export const y = 10;`),
},
{
caption: "Modify package json file to add type module",
edit: fs => fs.writeFileSync(`/src/projects/project/package.json`, JSON.stringify({ name: "app", version: "1.0.0", type: "module" })),
},
{
caption: "Modify package.json file to remove type module",
edit: fs => fs.writeFileSync(`/src/projects/project/package.json`, JSON.stringify({ name: "app", version: "1.0.0" })),
},
{
caption: "Delete package.json",
edit: fs => fs.unlinkSync(`/src/projects/project/package.json`),
},
{
caption: "Add package json file with type module",
edit: fs => fs.writeFileSync(`/src/projects/project/package.json`, JSON.stringify({ name: "app", version: "1.0.0", type: "module" })),
},
{
caption: "Delete package.json and random edit",
edit: fs => fs.unlinkSync(`/src/projects/project/package.json`)
},
],
});
});
9 changes: 5 additions & 4 deletions src/testRunner/unittests/tsc/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -461,20 +461,21 @@ export function loadProjectFromDisk(
*/
export function loadProjectFromFiles(
files: vfs.FileSet,
libContentToAppend?: string
libContentToAppend?: string,
libPath?: string,
): vfs.FileSystem {
const fs = new vfs.FileSystem(/*ignoreCase*/ true, {
files,
cwd: "/",
meta: { defaultLibLocation: "/lib" },
});
addLibAndMakeReadonly(fs, libContentToAppend);
addLibAndMakeReadonly(fs, libContentToAppend, libPath);
return fs;
}

function addLibAndMakeReadonly(fs: vfs.FileSystem, libContentToAppend?: string) {
function addLibAndMakeReadonly(fs: vfs.FileSystem, libContentToAppend?: string, libPath?: string) {
fs.mkdirSync("/lib");
fs.writeFileSync("/lib/lib.d.ts", libContentToAppend ? `${libContent}${libContentToAppend}` : libContent);
fs.writeFileSync(libPath || "/lib/lib.d.ts", libContentToAppend ? `${libContent}${libContentToAppend}` : libContent);
fs.makeReadonly();
}

Expand Down
66 changes: 66 additions & 0 deletions src/testRunner/unittests/tscWatch/cacheResolutions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import {
getWatchSystemWithNode16WithBuild,
getWatchSystemWithOut,
getWatchSystemWithOutWithBuild,
getWatchSystemWithPackageJsonEdits,
getWatchSystemWithPackageJsonEditsWithBuild,
getWatchSystemWithSameResolutionFromMultiplePlaces,
getWatchSystemWithSameResolutionFromMultiplePlacesWithBuild,
} from "../tsbuild/cacheResolutionsHelper";
Expand Down Expand Up @@ -278,4 +280,68 @@ describe("unittests:: tsc-watch:: cacheResolutions::", () => {
});
}
});

describe("packageJson edited", () => {
verifyTscWatchPackageJsonEdits("packageJson edited", getWatchSystemWithPackageJsonEdits);
verifyTscWatchPackageJsonEdits("packageJson edited already built", getWatchSystemWithPackageJsonEditsWithBuild);
function verifyTscWatchPackageJsonEdits(subScenario: string, sys: () => TestServerHost) {
verifyTscWatch({
scenario: "cacheResolutions",
subScenario,
commandLineArgs: ["--p", "src", "-w", "--explainFiles", "--extendedDiagnostics"],
baselineModulesAndTypeRefs: true,
sys,
edits: [
{
caption: "random edit",
edit: sys => sys.appendFile("/src/projects/project/src/randomFile.ts", `export const y = 10;`),
timeouts: sys => {
sys.runQueuedTimeoutCallbacks(); // Failed lookups
sys.runQueuedTimeoutCallbacks(); // actual update
},
},
{
caption: "Modify package json file to add type module",
edit: sys => sys.writeFile(`/src/projects/project/package.json`, JSON.stringify({ name: "app", version: "1.0.0", type: "module" })),
timeouts: sys => {
sys.runQueuedTimeoutCallbacks(); // Failed lookups
sys.runQueuedTimeoutCallbacks(); // actual update
},
},
{
caption: "Modify package.json file to remove type module",
edit: sys => sys.writeFile(`/src/projects/project/package.json`, JSON.stringify({ name: "app", version: "1.0.0" })),
timeouts: sys => {
sys.runQueuedTimeoutCallbacks(); // Failed lookups
sys.runQueuedTimeoutCallbacks(); // actual update
},
},
{
caption: "Delete package.json",
edit: sys => sys.deleteFile(`/src/projects/project/package.json`),
timeouts: sys => {
sys.runQueuedTimeoutCallbacks(); // Failed lookups
sys.runQueuedTimeoutCallbacks(); // actual update
},
},
{
caption: "Add package json file with type module",
edit: sys => sys.writeFile(`/src/projects/project/package.json`, JSON.stringify({ name: "app", version: "1.0.0", type: "module" })),
timeouts: sys => {
sys.runQueuedTimeoutCallbacks(); // Failed lookups
sys.runQueuedTimeoutCallbacks(); // actual update
},
},
{
caption: "Delete package.json",
edit: sys => sys.deleteFile(`/src/projects/project/package.json`),
timeouts: sys => {
sys.runQueuedTimeoutCallbacks(); // Failed lookups
sys.runQueuedTimeoutCallbacks(); // actual update
},
},
],
});
}
});
});
Loading