Skip to content

Commit

Permalink
Dont store package json path if its found in same directory
Browse files Browse the repository at this point in the history
  • Loading branch information
sheetalkamat committed Dec 1, 2022
1 parent 8825057 commit 03e1204
Show file tree
Hide file tree
Showing 11 changed files with 119 additions and 405 deletions.
10 changes: 3 additions & 7 deletions src/compiler/builder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -996,7 +996,7 @@ export type ProgramBuildInfoResolutionCacheWithRedirects = ProgramBuildInfoResol
redirects: readonly ProgramBuildInfoResolutionRedirectsCache[];
};
/** @internal */
export type ProgramBuildInfoPackageJson = ProgramBuildInfoAbsoluteFileId | [dirId: ProgramBuildInfoFileId, packageJson: ProgramBuildInfoAbsoluteFileId];
export type ProgramBuildInfoPackageJson = [dirId: ProgramBuildInfoFileId, packageJson: ProgramBuildInfoAbsoluteFileId];
/** @internal */
export interface ProgramBuildInfoCacheResolutions {
resolutions: readonly ProgramBuildInfoResolution[];
Expand Down Expand Up @@ -1347,12 +1347,8 @@ function getBuildInfo(state: BuilderProgramState, host: BuilderProgramHost, bund
let result: ProgramBuildInfoPackageJson[] | undefined;
cache?.forEach((packageJson, dirPath) => {
const packageJsonDirPath = getDirectoryPath(toPath(packageJson, currentDirectory, getCanonicalFileName));
(result ??= []).push(packageJsonDirPath === dirPath ?
toAbsoluteFileId(packageJson) :
[
toFileId(dirPath),
toAbsoluteFileId(packageJson),
]);
// Dont need to store package json found in same directory
if (packageJsonDirPath !== dirPath) (result ??= []).push([toFileId(dirPath), toAbsoluteFileId(packageJson)]);
});
return result;
}
Expand Down
6 changes: 2 additions & 4 deletions src/testRunner/unittests/tsc/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -505,7 +505,7 @@ type ReadableProgramBuildInfoResolutionCacheWithRedirects = ReadableProgramBuild
redirects: readonly ReadableProgramBuildInfoResolutionRedirectsCache[];
};
type ReadableProgramBuildInfoHash = string | [file: string, hash: string];
type ReadableProgramBuildInfoPackageJson = string | [dir: string, packageJson: string];
type ReadableProgramBuildInfoPackageJson = [dir: string, packageJson: string];
type ReadableProgramBuildInfoCacheResolutions = Omit<ts.ProgramBuildInfoCacheResolutions,
"resolutions" | "hash" | "resolutionEntries" | "modules" | "typeRefs" | "packageJsons"
> & {
Expand Down Expand Up @@ -698,9 +698,7 @@ function generateBuildInfoProgramBaseline(sys: ts.System, buildInfoPath: string,
}

function toReadableProgramBuildInfoPackageJson(entry: ts.ProgramBuildInfoPackageJson): ReadableProgramBuildInfoPackageJson {
return ts.isArray(entry) ?
[toFileName(entry[0]), toFileName(entry[1])] :
toFileName(entry);
return [toFileName(entry[0]), toFileName(entry[1])];
}

function toReadableProgramBuildInfoHash(hash: ts.ProgramBuildInfoHash): ReadableProgramBuildInfoHash {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -421,11 +421,6 @@ CleanBuild:
}
]
}
],
"packageJsons": [
"./node_modules/pkg0/package.json",
"./node_modules/pkg2/package.json",
"./node_modules/pkg3/package.json"
]
}
},
Expand Down Expand Up @@ -828,11 +823,6 @@ IncrementalBuild:
}
]
}
],
"packageJsons": [
"./node_modules/pkg0/package.json",
"./node_modules/pkg2/package.json",
"./node_modules/pkg3/package.json"
]
}
},
Expand Down
66 changes: 14 additions & 52 deletions tests/baselines/reference/tsbuild/cacheResolutions/multi-file.js

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ exports.x = 10;
//// [/src/project/dist/tsconfig.tsbuildinfo]
{"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"}
{"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"}
//// [/src/project/dist/tsconfig.tsbuildinfo.readable.baseline.txt]
{
Expand Down Expand Up @@ -273,14 +273,11 @@ exports.x = 10;
}
]
}
],
"packageJsons": [
"../package.json"
]
}
},
"version": "FakeTSVersion",
"size": 1962
"size": 1943
}
//// [/src/project/types/index.d.ts]
Expand Down Expand Up @@ -338,7 +335,7 @@ exitCode:: ExitStatus.DiagnosticsPresent_OutputsGenerated
//// [/src/project/dist/randomFileForImport.js] file written with same contents
//// [/src/project/dist/tsconfig.tsbuildinfo]
{"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"}
{"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"}
//// [/src/project/dist/tsconfig.tsbuildinfo.readable.baseline.txt]
{
Expand Down Expand Up @@ -517,14 +514,11 @@ exitCode:: ExitStatus.DiagnosticsPresent_OutputsGenerated
}
]
}
],
"packageJsons": [
"../package.json"
]
}
},
"version": "FakeTSVersion",
"size": 2006
"size": 1987
}

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

0 comments on commit 03e1204

Please sign in to comment.