Skip to content

Commit 6c1e8aa

Browse files
authored
Sort the arrays of fileNames in the build info (#37541)
* Sort the arrays of fileNames in the build info Earlier we did this in testing to ensure we could baseline now moved to actual build info writing Fixes #37156 * Sort using compareStringsCaseSensitive
1 parent e1772fa commit 6c1e8aa

File tree

8 files changed

+55
-85
lines changed

8 files changed

+55
-85
lines changed

src/compiler/builder.ts

Lines changed: 20 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -710,37 +710,39 @@ namespace ts {
710710
};
711711
if (state.referencedMap) {
712712
const referencedMap: MapLike<string[]> = {};
713-
state.referencedMap.forEach((value, key) => {
714-
referencedMap[relativeToBuildInfo(key)] = arrayFrom(value.keys(), relativeToBuildInfo);
715-
});
713+
for (const key of arrayFrom(state.referencedMap.keys()).sort(compareStringsCaseSensitive)) {
714+
referencedMap[relativeToBuildInfo(key)] = arrayFrom(state.referencedMap.get(key)!.keys(), relativeToBuildInfo).sort(compareStringsCaseSensitive);
715+
}
716716
result.referencedMap = referencedMap;
717717
}
718718

719719
if (state.exportedModulesMap) {
720720
const exportedModulesMap: MapLike<string[]> = {};
721-
state.exportedModulesMap.forEach((value, key) => {
721+
for (const key of arrayFrom(state.exportedModulesMap.keys()).sort(compareStringsCaseSensitive)) {
722722
const newValue = state.currentAffectedFilesExportedModulesMap && state.currentAffectedFilesExportedModulesMap.get(key);
723723
// Not in temporary cache, use existing value
724-
if (newValue === undefined) exportedModulesMap[relativeToBuildInfo(key)] = arrayFrom(value.keys(), relativeToBuildInfo);
724+
if (newValue === undefined) exportedModulesMap[relativeToBuildInfo(key)] = arrayFrom(state.exportedModulesMap.get(key)!.keys(), relativeToBuildInfo).sort(compareStringsCaseSensitive);
725725
// Value in cache and has updated value map, use that
726-
else if (newValue) exportedModulesMap[relativeToBuildInfo(key)] = arrayFrom(newValue.keys(), relativeToBuildInfo);
727-
});
726+
else if (newValue) exportedModulesMap[relativeToBuildInfo(key)] = arrayFrom(newValue.keys(), relativeToBuildInfo).sort(compareStringsCaseSensitive);
727+
}
728728
result.exportedModulesMap = exportedModulesMap;
729729
}
730730

731731
if (state.semanticDiagnosticsPerFile) {
732732
const semanticDiagnosticsPerFile: ProgramBuildInfoDiagnostic[] = [];
733-
// Currently not recording actual errors since those mean no emit for tsc --build
734-
state.semanticDiagnosticsPerFile.forEach((value, key) => semanticDiagnosticsPerFile.push(
735-
value.length ?
736-
[
737-
relativeToBuildInfo(key),
738-
state.hasReusableDiagnostic ?
739-
value as readonly ReusableDiagnostic[] :
740-
convertToReusableDiagnostics(value as readonly Diagnostic[], relativeToBuildInfo)
741-
] :
742-
relativeToBuildInfo(key)
743-
));
733+
for (const key of arrayFrom(state.semanticDiagnosticsPerFile.keys()).sort(compareStringsCaseSensitive)) {
734+
const value = state.semanticDiagnosticsPerFile.get(key)!;
735+
semanticDiagnosticsPerFile.push(
736+
value.length ?
737+
[
738+
relativeToBuildInfo(key),
739+
state.hasReusableDiagnostic ?
740+
value as readonly ReusableDiagnostic[] :
741+
convertToReusableDiagnostics(value as readonly Diagnostic[], relativeToBuildInfo)
742+
] :
743+
relativeToBuildInfo(key)
744+
);
745+
}
744746
result.semanticDiagnosticsPerFile = semanticDiagnosticsPerFile;
745747
}
746748

src/harness/fakesHosts.ts

Lines changed: 0 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -496,37 +496,6 @@ ${indentText}${text}`;
496496
return text;
497497
}
498498

499-
function compareProgramBuildInfoDiagnostic(a: ts.ProgramBuildInfoDiagnostic, b: ts.ProgramBuildInfoDiagnostic) {
500-
return ts.compareStringsCaseSensitive(ts.isString(a) ? a : a[0], ts.isString(b) ? b : b[0]);
501-
}
502-
503-
export function sanitizeBuildInfoProgram(buildInfo: ts.BuildInfo) {
504-
if (buildInfo.program) {
505-
// reference Map
506-
if (buildInfo.program.referencedMap) {
507-
const referencedMap: ts.MapLike<string[]> = {};
508-
for (const path of ts.getOwnKeys(buildInfo.program.referencedMap).sort()) {
509-
referencedMap[path] = buildInfo.program.referencedMap[path].sort();
510-
}
511-
buildInfo.program.referencedMap = referencedMap;
512-
}
513-
514-
// exportedModulesMap
515-
if (buildInfo.program.exportedModulesMap) {
516-
const exportedModulesMap: ts.MapLike<string[]> = {};
517-
for (const path of ts.getOwnKeys(buildInfo.program.exportedModulesMap).sort()) {
518-
exportedModulesMap[path] = buildInfo.program.exportedModulesMap[path].sort();
519-
}
520-
buildInfo.program.exportedModulesMap = exportedModulesMap;
521-
}
522-
523-
// semanticDiagnosticsPerFile
524-
if (buildInfo.program.semanticDiagnosticsPerFile) {
525-
buildInfo.program.semanticDiagnosticsPerFile.sort(compareProgramBuildInfoDiagnostic);
526-
}
527-
}
528-
}
529-
530499
export const version = "FakeTSVersion";
531500

532501
export function patchHostForBuildInfoReadWrite<T extends ts.System>(sys: T) {
@@ -547,7 +516,6 @@ ${indentText}${text}`;
547516
sys.writeFile = (fileName: string, content: string, writeByteOrderMark: boolean) => {
548517
if (!ts.isBuildInfoFile(fileName)) return originalWriteFile.call(sys, fileName, content, writeByteOrderMark);
549518
const buildInfo = ts.getBuildInfo(content);
550-
sanitizeBuildInfoProgram(buildInfo);
551519
buildInfo.version = version;
552520
originalWriteFile.call(sys, fileName, ts.getBuildInfoText(buildInfo), writeByteOrderMark);
553521
};

tests/baselines/reference/tsbuild/demo/initial-build/in-master-branch-with-everything-setup-correctly-and-reports-no-error.js

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -242,35 +242,35 @@ exports.lastElementOf = lastElementOf;
242242
"configFilePath": "../../zoo/tsconfig.json"
243243
},
244244
"referencedMap": {
245-
"../../zoo/zoo.ts": [
246-
"../animals/index.d.ts"
247-
],
248245
"../animals/dog.d.ts": [
249246
"../animals/index.d.ts"
250247
],
251248
"../animals/index.d.ts": [
252249
"../animals/animal.d.ts",
253250
"../animals/dog.d.ts"
251+
],
252+
"../../zoo/zoo.ts": [
253+
"../animals/index.d.ts"
254254
]
255255
},
256256
"exportedModulesMap": {
257-
"../../zoo/zoo.ts": [
258-
"../animals/index.d.ts"
259-
],
260257
"../animals/dog.d.ts": [
261258
"../animals/index.d.ts"
262259
],
263260
"../animals/index.d.ts": [
264261
"../animals/animal.d.ts",
265262
"../animals/dog.d.ts"
263+
],
264+
"../../zoo/zoo.ts": [
265+
"../animals/index.d.ts"
266266
]
267267
},
268268
"semanticDiagnosticsPerFile": [
269269
"../../../lib/lib.d.ts",
270-
"../../zoo/zoo.ts",
271270
"../animals/animal.d.ts",
272271
"../animals/dog.d.ts",
273-
"../animals/index.d.ts"
272+
"../animals/index.d.ts",
273+
"../../zoo/zoo.ts"
274274
]
275275
},
276276
"version": "FakeTSVersion"

tests/baselines/reference/tsbuild/javascriptProjectEmit/initial-build/loads-js-based-projects-and-emits-them-correctly.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,8 @@ module.exports = {};
3838
"referencedMap": {},
3939
"exportedModulesMap": {},
4040
"semanticDiagnosticsPerFile": [
41-
"../../src/common/nominal.js",
42-
"../lib.d.ts"
41+
"../lib.d.ts",
42+
"../../src/common/nominal.js"
4343
]
4444
},
4545
"version": "FakeTSVersion"
@@ -98,9 +98,9 @@ exports.__esModule = true;
9898
},
9999
"exportedModulesMap": {},
100100
"semanticDiagnosticsPerFile": [
101-
"../../src/sub-project/index.js",
102101
"../common/nominal.d.ts",
103-
"../lib.d.ts"
102+
"../lib.d.ts",
103+
"../../src/sub-project/index.js"
104104
]
105105
},
106106
"version": "FakeTSVersion"
@@ -163,9 +163,9 @@ exports.getVar = getVar;
163163
},
164164
"exportedModulesMap": {},
165165
"semanticDiagnosticsPerFile": [
166-
"../../src/sub-project-2/index.js",
167166
"../lib.d.ts",
168-
"../sub-project/index.d.ts"
167+
"../sub-project/index.d.ts",
168+
"../../src/sub-project-2/index.js"
169169
]
170170
},
171171
"version": "FakeTSVersion"

tests/baselines/reference/tsbuild/javascriptProjectEmit/initial-build/loads-js-based-projects-with-non-moved-json-files-and-emits-them-correctly.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -134,8 +134,8 @@ exports.getVar = getVar;
134134
"exportedModulesMap": {},
135135
"semanticDiagnosticsPerFile": [
136136
"../../lib/lib.d.ts",
137-
"../../src/sub-project-2/index.js",
138-
"../sub-project/index.d.ts"
137+
"../sub-project/index.d.ts",
138+
"../../src/sub-project-2/index.js"
139139
]
140140
},
141141
"version": "FakeTSVersion"

tests/baselines/reference/tsbuild/moduleSpecifiers/initial-build/synthesized-module-specifiers-resolve-correctly.js

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -109,8 +109,8 @@ exports.__esModule = true;
109109
},
110110
"semanticDiagnosticsPerFile": [
111111
"../../../../lib/lib.d.ts",
112-
"../../../solution/sub-project/index.ts",
113-
"../common/nominal.d.ts"
112+
"../common/nominal.d.ts",
113+
"../../../solution/sub-project/index.ts"
114114
]
115115
},
116116
"version": "FakeTSVersion"
@@ -166,26 +166,26 @@ exports.getVar = getVar;
166166
"configFilePath": "../../../solution/sub-project-2/tsconfig.json"
167167
},
168168
"referencedMap": {
169-
"../../../solution/sub-project-2/index.ts": [
170-
"../sub-project/index.d.ts"
171-
],
172169
"../sub-project/index.d.ts": [
173170
"../common/nominal.d.ts"
171+
],
172+
"../../../solution/sub-project-2/index.ts": [
173+
"../sub-project/index.d.ts"
174174
]
175175
},
176176
"exportedModulesMap": {
177-
"../../../solution/sub-project-2/index.ts": [
177+
"../sub-project/index.d.ts": [
178178
"../common/nominal.d.ts"
179179
],
180-
"../sub-project/index.d.ts": [
180+
"../../../solution/sub-project-2/index.ts": [
181181
"../common/nominal.d.ts"
182182
]
183183
},
184184
"semanticDiagnosticsPerFile": [
185185
"../../../../lib/lib.d.ts",
186-
"../../../solution/sub-project-2/index.ts",
187186
"../common/nominal.d.ts",
188-
"../sub-project/index.d.ts"
187+
"../sub-project/index.d.ts",
188+
"../../../solution/sub-project-2/index.ts"
189189
]
190190
},
191191
"version": "FakeTSVersion"

tests/baselines/reference/tsbuild/resolveJsonModule/initial-build/importing-json-module-from-project-reference.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,8 +61,8 @@ console.log(foo_json_1.foo);
6161
"exportedModulesMap": {},
6262
"semanticDiagnosticsPerFile": [
6363
"../../lib/lib.d.ts",
64-
"../strings/foo.json",
65-
"./index.ts"
64+
"./index.ts",
65+
"../strings/foo.json"
6666
]
6767
},
6868
"version": "FakeTSVersion"

tests/baselines/reference/tsbuild/watchMode/demo/updates-with-circular-reference.js

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -454,35 +454,35 @@ export declare function createZoo(): Array<Dog>;
454454
"configFilePath": "../../zoo/tsconfig.json"
455455
},
456456
"referencedMap": {
457-
"../../zoo/zoo.ts": [
458-
"../animals/index.d.ts"
459-
],
460457
"../animals/dog.d.ts": [
461458
"../animals/index.d.ts"
462459
],
463460
"../animals/index.d.ts": [
464461
"../animals/animal.d.ts",
465462
"../animals/dog.d.ts"
463+
],
464+
"../../zoo/zoo.ts": [
465+
"../animals/index.d.ts"
466466
]
467467
},
468468
"exportedModulesMap": {
469-
"../../zoo/zoo.ts": [
470-
"../animals/index.d.ts"
471-
],
472469
"../animals/dog.d.ts": [
473470
"../animals/index.d.ts"
474471
],
475472
"../animals/index.d.ts": [
476473
"../animals/animal.d.ts",
477474
"../animals/dog.d.ts"
475+
],
476+
"../../zoo/zoo.ts": [
477+
"../animals/index.d.ts"
478478
]
479479
},
480480
"semanticDiagnosticsPerFile": [
481481
"../../../../../../a/lib/lib.d.ts",
482-
"../../zoo/zoo.ts",
483482
"../animals/animal.d.ts",
484483
"../animals/dog.d.ts",
485-
"../animals/index.d.ts"
484+
"../animals/index.d.ts",
485+
"../../zoo/zoo.ts"
486486
]
487487
},
488488
"version": "FakeTSVersion"

0 commit comments

Comments
 (0)