Skip to content

Commit 911873b

Browse files
committed
Dont store package json path if its found in same directory
1 parent 839ef57 commit 911873b

File tree

11 files changed

+119
-405
lines changed

11 files changed

+119
-405
lines changed

src/compiler/builder.ts

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -992,7 +992,7 @@ export type ProgramBuildInfoResolutionCacheWithRedirects = ProgramBuildInfoResol
992992
redirects: readonly ProgramBuildInfoResolutionRedirectsCache[];
993993
};
994994
/** @internal */
995-
export type ProgramBuildInfoPackageJson = ProgramBuildInfoAbsoluteFileId | [dirId: ProgramBuildInfoFileId, packageJson: ProgramBuildInfoAbsoluteFileId];
995+
export type ProgramBuildInfoPackageJson = [dirId: ProgramBuildInfoFileId, packageJson: ProgramBuildInfoAbsoluteFileId];
996996
/** @internal */
997997
export interface ProgramBuildInfoCacheResolutions {
998998
resolutions: readonly ProgramBuildInfoResolution[];
@@ -1347,12 +1347,8 @@ function getBuildInfo(state: BuilderProgramState, host: BuilderProgramHost, bund
13471347
let result: ProgramBuildInfoPackageJson[] | undefined;
13481348
cache?.forEach((packageJson, dirPath) => {
13491349
const packageJsonDirPath = getDirectoryPath(toPath(packageJson, currentDirectory, state.program!.getCanonicalFileName));
1350-
(result ??= []).push(packageJsonDirPath === dirPath ?
1351-
toAbsoluteFileId(packageJson) :
1352-
[
1353-
toFileId(dirPath),
1354-
toAbsoluteFileId(packageJson),
1355-
]);
1350+
// Dont need to store package json found in same directory
1351+
if (packageJsonDirPath !== dirPath) (result ??= []).push([toFileId(dirPath), toAbsoluteFileId(packageJson)]);
13561352
});
13571353
return result;
13581354
}

src/testRunner/unittests/tsc/helpers.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -570,7 +570,7 @@ type ReadableProgramBuildInfoResolutionCacheWithRedirects = ReadableProgramBuild
570570
redirects: readonly ReadableProgramBuildInfoResolutionRedirectsCache[];
571571
};
572572
type ReadableProgramBuildInfoHash = string | [file: string, hash: string];
573-
type ReadableProgramBuildInfoPackageJson = string | [dir: string, packageJson: string];
573+
type ReadableProgramBuildInfoPackageJson = [dir: string, packageJson: string];
574574
type ReadableProgramBuildInfoCacheResolutions = Omit<ts.ProgramBuildInfoCacheResolutions,
575575
"resolutions" | "hash" | "resolutionEntries" | "modules" | "typeRefs" | "packageJsons"
576576
> & {
@@ -763,9 +763,7 @@ function generateBuildInfoProgramBaseline(sys: ts.System, buildInfoPath: string,
763763
}
764764

765765
function toReadableProgramBuildInfoPackageJson(entry: ts.ProgramBuildInfoPackageJson): ReadableProgramBuildInfoPackageJson {
766-
return ts.isArray(entry) ?
767-
[toFileName(entry[0]), toFileName(entry[1])] :
768-
toFileName(entry);
766+
return [toFileName(entry[0]), toFileName(entry[1])];
769767
}
770768

771769
function toReadableProgramBuildInfoHash(hash: ts.ProgramBuildInfoHash): ReadableProgramBuildInfoHash {

tests/baselines/reference/tsbuild/cacheResolutions/multi-file-discrepancies.js

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -398,11 +398,6 @@ CleanBuild:
398398
}
399399
]
400400
}
401-
],
402-
"packageJsons": [
403-
"./node_modules/pkg0/package.json",
404-
"./node_modules/pkg2/package.json",
405-
"./node_modules/pkg3/package.json"
406401
]
407402
}
408403
},
@@ -805,11 +800,6 @@ IncrementalBuild:
805800
}
806801
]
807802
}
808-
],
809-
"packageJsons": [
810-
"./node_modules/pkg0/package.json",
811-
"./node_modules/pkg2/package.json",
812-
"./node_modules/pkg3/package.json"
813803
]
814804
}
815805
},

tests/baselines/reference/tsbuild/cacheResolutions/multi-file.js

Lines changed: 14 additions & 52 deletions
Large diffs are not rendered by default.

tests/baselines/reference/tsbuildWatch/cacheResolutions/multi-file-already-built.js

Lines changed: 16 additions & 56 deletions
Large diffs are not rendered by default.

tests/baselines/reference/tsbuildWatch/cacheResolutions/multi-file.js

Lines changed: 16 additions & 56 deletions
Large diffs are not rendered by default.

tests/baselines/reference/tsc/cacheResolutions/diagnostics-from-cache.js

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ exports.x = 10;
168168
169169
170170
//// [/src/project/dist/tsconfig.tsbuildinfo]
171-
{"program":{"fileNames":["../../../lib/lib.d.ts","../index.ts","../index2.ts","../randomfileforimport.ts","..","../package.json"],"fileInfos":[{"version":"3858781397-/// <reference no-default-lib=\"true\"/>\ninterface Boolean {}\ninterface Function {}\ninterface CallableFunction {}\ninterface NewableFunction {}\ninterface IArguments {}\ninterface Number { toExponential: any; }\ninterface Object {}\ninterface RegExp {}\ninterface String { charAt: any; }\ninterface Array<T> { length: number; [n: number]: T; }\ninterface ReadonlyArray<T> {}\ndeclare const console: { log(msg: any): void; };","affectsGlobalScope":true,"impliedFormat":1},{"version":"5618920854-import * as me from \"@this/package\";\nme.thing()\nexport function thing(): void {}\n","signature":"-4018078458-export declare function thing(): void;\r\n","impliedFormat":99},{"version":"5871974342-export function thing(): void {}\n","signature":"-4018078458-export declare function thing(): void;\r\n","impliedFormat":99},{"version":"-10726455937-export const x = 10;","signature":"-6057683066-export declare const x = 10;\r\n","impliedFormat":99}],"options":{"cacheResolutions":true,"declaration":true,"declarationDir":"../types","moduleResolution":99,"outDir":"./"},"fileIdsList":[[2]],"referencedMap":[[2,1]],"exportedModulesMap":[],"cacheResolutions":{"resolutions":[{"resolvedModule":{"resolvedFileName":2,"isExternalLibraryImport":true},"affectingLocations":[6],"resolutionDiagnostics":[{"messageText":"The project root is ambiguous, but is required to resolve export map entry '.' in file '/src/project/package.json'. Supply the `rootDir` compiler option to disambiguate.","category":1,"code":2209}]}],"names":["@this/package"],"hash":[[6,"25383995153-{\"name\":\"@this/package\",\"type\":\"module\",\"exports\":{\".\":{\"default\":\"./dist/index.js\",\"types\":\"./types/index.d.ts\"}}}"]],"resolutionEntries":[[1,1,99]],"modules":[[5,[1]]],"packageJsons":[6]}},"version":"FakeTSVersion"}
171+
{"program":{"fileNames":["../../../lib/lib.d.ts","../index.ts","../index2.ts","../randomfileforimport.ts","..","../package.json"],"fileInfos":[{"version":"3858781397-/// <reference no-default-lib=\"true\"/>\ninterface Boolean {}\ninterface Function {}\ninterface CallableFunction {}\ninterface NewableFunction {}\ninterface IArguments {}\ninterface Number { toExponential: any; }\ninterface Object {}\ninterface RegExp {}\ninterface String { charAt: any; }\ninterface Array<T> { length: number; [n: number]: T; }\ninterface ReadonlyArray<T> {}\ndeclare const console: { log(msg: any): void; };","affectsGlobalScope":true,"impliedFormat":1},{"version":"5618920854-import * as me from \"@this/package\";\nme.thing()\nexport function thing(): void {}\n","signature":"-4018078458-export declare function thing(): void;\r\n","impliedFormat":99},{"version":"5871974342-export function thing(): void {}\n","signature":"-4018078458-export declare function thing(): void;\r\n","impliedFormat":99},{"version":"-10726455937-export const x = 10;","signature":"-6057683066-export declare const x = 10;\r\n","impliedFormat":99}],"options":{"cacheResolutions":true,"declaration":true,"declarationDir":"../types","moduleResolution":99,"outDir":"./"},"fileIdsList":[[2]],"referencedMap":[[2,1]],"exportedModulesMap":[],"cacheResolutions":{"resolutions":[{"resolvedModule":{"resolvedFileName":2,"isExternalLibraryImport":true},"affectingLocations":[6],"resolutionDiagnostics":[{"messageText":"The project root is ambiguous, but is required to resolve export map entry '.' in file '/src/project/package.json'. Supply the `rootDir` compiler option to disambiguate.","category":1,"code":2209}]}],"names":["@this/package"],"hash":[[6,"25383995153-{\"name\":\"@this/package\",\"type\":\"module\",\"exports\":{\".\":{\"default\":\"./dist/index.js\",\"types\":\"./types/index.d.ts\"}}}"]],"resolutionEntries":[[1,1,99]],"modules":[[5,[1]]]}},"version":"FakeTSVersion"}
172172
173173
//// [/src/project/dist/tsconfig.tsbuildinfo.readable.baseline.txt]
174174
{
@@ -344,14 +344,11 @@ exports.x = 10;
344344
}
345345
]
346346
}
347-
],
348-
"packageJsons": [
349-
"../package.json"
350347
]
351348
}
352349
},
353350
"version": "FakeTSVersion",
354-
"size": 1962
351+
"size": 1943
355352
}
356353
357354
//// [/src/project/types/index.d.ts]
@@ -498,7 +495,7 @@ resolvedModules:
498495

499496
//// [/src/project/dist/randomFileForImport.js] file written with same contents
500497
//// [/src/project/dist/tsconfig.tsbuildinfo]
501-
{"program":{"fileNames":["../../../lib/lib.d.ts","../index.ts","../index2.ts","../randomfileforimport.ts","..","../package.json"],"fileInfos":[{"version":"3858781397-/// <reference no-default-lib=\"true\"/>\ninterface Boolean {}\ninterface Function {}\ninterface CallableFunction {}\ninterface NewableFunction {}\ninterface IArguments {}\ninterface Number { toExponential: any; }\ninterface Object {}\ninterface RegExp {}\ninterface String { charAt: any; }\ninterface Array<T> { length: number; [n: number]: T; }\ninterface ReadonlyArray<T> {}\ndeclare const console: { log(msg: any): void; };","affectsGlobalScope":true,"impliedFormat":1},{"version":"5618920854-import * as me from \"@this/package\";\nme.thing()\nexport function thing(): void {}\n","signature":"-4018078458-export declare function thing(): void;\r\n","impliedFormat":99},{"version":"5871974342-export function thing(): void {}\n","signature":"-4018078458-export declare function thing(): void;\r\n","impliedFormat":99},{"version":"4314805146-import * as me from \"@this/package\";\nexport const x = 10;","signature":"-6057683066-export declare const x = 10;\r\n","impliedFormat":99}],"options":{"cacheResolutions":true,"declaration":true,"declarationDir":"../types","moduleResolution":99,"outDir":"./"},"fileIdsList":[[2]],"referencedMap":[[2,1],[4,1]],"exportedModulesMap":[],"cacheResolutions":{"resolutions":[{"resolvedModule":{"resolvedFileName":2,"isExternalLibraryImport":true},"affectingLocations":[6],"resolutionDiagnostics":[{"messageText":"The project root is ambiguous, but is required to resolve export map entry '.' in file '/src/project/package.json'. Supply the `rootDir` compiler option to disambiguate.","category":1,"code":2209}]}],"names":["@this/package"],"hash":[[6,"25383995153-{\"name\":\"@this/package\",\"type\":\"module\",\"exports\":{\".\":{\"default\":\"./dist/index.js\",\"types\":\"./types/index.d.ts\"}}}"]],"resolutionEntries":[[1,1,99]],"modules":[[5,[1]]],"packageJsons":[6]}},"version":"FakeTSVersion"}
498+
{"program":{"fileNames":["../../../lib/lib.d.ts","../index.ts","../index2.ts","../randomfileforimport.ts","..","../package.json"],"fileInfos":[{"version":"3858781397-/// <reference no-default-lib=\"true\"/>\ninterface Boolean {}\ninterface Function {}\ninterface CallableFunction {}\ninterface NewableFunction {}\ninterface IArguments {}\ninterface Number { toExponential: any; }\ninterface Object {}\ninterface RegExp {}\ninterface String { charAt: any; }\ninterface Array<T> { length: number; [n: number]: T; }\ninterface ReadonlyArray<T> {}\ndeclare const console: { log(msg: any): void; };","affectsGlobalScope":true,"impliedFormat":1},{"version":"5618920854-import * as me from \"@this/package\";\nme.thing()\nexport function thing(): void {}\n","signature":"-4018078458-export declare function thing(): void;\r\n","impliedFormat":99},{"version":"5871974342-export function thing(): void {}\n","signature":"-4018078458-export declare function thing(): void;\r\n","impliedFormat":99},{"version":"4314805146-import * as me from \"@this/package\";\nexport const x = 10;","signature":"-6057683066-export declare const x = 10;\r\n","impliedFormat":99}],"options":{"cacheResolutions":true,"declaration":true,"declarationDir":"../types","moduleResolution":99,"outDir":"./"},"fileIdsList":[[2]],"referencedMap":[[2,1],[4,1]],"exportedModulesMap":[],"cacheResolutions":{"resolutions":[{"resolvedModule":{"resolvedFileName":2,"isExternalLibraryImport":true},"affectingLocations":[6],"resolutionDiagnostics":[{"messageText":"The project root is ambiguous, but is required to resolve export map entry '.' in file '/src/project/package.json'. Supply the `rootDir` compiler option to disambiguate.","category":1,"code":2209}]}],"names":["@this/package"],"hash":[[6,"25383995153-{\"name\":\"@this/package\",\"type\":\"module\",\"exports\":{\".\":{\"default\":\"./dist/index.js\",\"types\":\"./types/index.d.ts\"}}}"]],"resolutionEntries":[[1,1,99]],"modules":[[5,[1]]]}},"version":"FakeTSVersion"}
502499

503500
//// [/src/project/dist/tsconfig.tsbuildinfo.readable.baseline.txt]
504501
{
@@ -677,14 +674,11 @@ resolvedModules:
677674
}
678675
]
679676
}
680-
],
681-
"packageJsons": [
682-
"../package.json"
683677
]
684678
}
685679
},
686680
"version": "FakeTSVersion",
687-
"size": 2006
681+
"size": 1987
688682
}
689683

690684
//// [/src/project/types/randomFileForImport.d.ts] file written with same contents

0 commit comments

Comments
 (0)