-
Notifications
You must be signed in to change notification settings - Fork 13.3k
Description
Bug Report
π Search Terms
structure reuse, performance
π Version & Regression Information
Current main (b53073b)
- This is the behavior in every version I tried
β― Playground Link
Not applicable.
π» Code
it("successful if change affects a single module of a package", () => {
const files = [
{ name: "/a.ts", text: SourceText.New("", "import {b} from 'b'", "var a = b;") },
{ name: "/node_modules/b/index.d.ts", text: SourceText.New("", "export * from './internal';", "") },
{ name: "/node_modules/b/internal.d.ts", text: SourceText.New("", "", "export const b = 1;") },
{ name: "/node_modules/b/package.json", text: SourceText.New("", "", JSON.stringify({ name: "b", version: "1.2.3" })) },
];
const options: CompilerOptions = { target, moduleResolution: ModuleResolutionKind.NodeJs };
const program1 = newProgram(files, ["/a.ts"], options);
const program2 = updateProgram(program1, ["/a.ts"], options, files => {
files[2].text = files[2].text.updateProgram("export const b = 2;");
});
assert.equal(program2.structureIsReused, StructureIsReused.Completely);
const program1Diagnostics = program1.getSemanticDiagnostics(program1.getSourceFile("a.ts"));
const program2Diagnostics = program2.getSemanticDiagnostics(program1.getSourceFile("a.ts"));
assert.equal(program1Diagnostics.length, program2Diagnostics.length);
});π Actual behavior
TypeScript determines that StructureIsReused.Not is in order for the change to the declaration file node_modules/b/internal.d.ts, because it notices that there's two files node_modules/b/index.d.ts and ``node_modules/b/internal.d.ts` corresponding with the same package name. This currently prevents structure reuse to detect changes to redirect source files, but here the declaration files are not involved in redirects.
The structure reuse logic for redirects was initially implemented in #16274, in which PackageId only consisted of name and version and the structure reuse check was based on name. Then in #18185 the PackageId structure was extended with subModuleName but this extension was not reflected in the structure reuse logic.
Because the structure reuse detection is based on having multiple files for the same package, structural reuse is possible when updating the declaration of a package when there is only a single declaration file present.
π Expected behavior
The structure should be reused, as an update to a declaration file within a package should not be interpreted to be related to a redirect.