Skip to content

Commit b2159e4

Browse files
committed
Dont store package json path if its found in same directory
1 parent df70939 commit b2159e4

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
@@ -530,7 +530,7 @@ type ReadableProgramBuildInfoResolutionCacheWithRedirects = ReadableProgramBuild
530530
redirects: readonly ReadableProgramBuildInfoResolutionRedirectsCache[];
531531
};
532532
type ReadableProgramBuildInfoHash = string | [file: string, hash: string];
533-
type ReadableProgramBuildInfoPackageJson = string | [dir: string, packageJson: string];
533+
type ReadableProgramBuildInfoPackageJson = [dir: string, packageJson: string];
534534
type ReadableProgramBuildInfoCacheResolutions = Omit<ts.ProgramBuildInfoCacheResolutions,
535535
"resolutions" | "hash" | "resolutionEntries" | "modules" | "typeRefs" | "packageJsons"
536536
> & {
@@ -723,9 +723,7 @@ function generateBuildInfoProgramBaseline(sys: ts.System, buildInfoPath: string,
723723
}
724724

725725
function toReadableProgramBuildInfoPackageJson(entry: ts.ProgramBuildInfoPackageJson): ReadableProgramBuildInfoPackageJson {
726-
return ts.isArray(entry) ?
727-
[toFileName(entry[0]), toFileName(entry[1])] :
728-
toFileName(entry);
726+
return [toFileName(entry[0]), toFileName(entry[1])];
729727
}
730728

731729
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
@@ -97,7 +97,7 @@ exports.x = 10;
9797
9898
9999
//// [/src/project/dist/tsconfig.tsbuildinfo]
100-
{"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"}
100+
{"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"}
101101
102102
//// [/src/project/dist/tsconfig.tsbuildinfo.readable.baseline.txt]
103103
{
@@ -273,14 +273,11 @@ exports.x = 10;
273273
}
274274
]
275275
}
276-
],
277-
"packageJsons": [
278-
"../package.json"
279276
]
280277
}
281278
},
282279
"version": "FakeTSVersion",
283-
"size": 1962
280+
"size": 1943
284281
}
285282
286283
//// [/src/project/types/index.d.ts]
@@ -338,7 +335,7 @@ exitCode:: ExitStatus.DiagnosticsPresent_OutputsGenerated
338335

339336
//// [/src/project/dist/randomFileForImport.js] file written with same contents
340337
//// [/src/project/dist/tsconfig.tsbuildinfo]
341-
{"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"}
338+
{"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"}
342339

343340
//// [/src/project/dist/tsconfig.tsbuildinfo.readable.baseline.txt]
344341
{
@@ -517,14 +514,11 @@ exitCode:: ExitStatus.DiagnosticsPresent_OutputsGenerated
517514
}
518515
]
519516
}
520-
],
521-
"packageJsons": [
522-
"../package.json"
523517
]
524518
}
525519
},
526520
"version": "FakeTSVersion",
527-
"size": 2006
521+
"size": 1987
528522
}
529523

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

0 commit comments

Comments
 (0)