Skip to content

Commit 1280b76

Browse files
committed
Don't use needsUpdate for quick tasks
needsUpdate may be wrong when the branch changes; these ones are now so fast thanks to being pure JS that we can just always run their contents and be sure that the outputs are right.
1 parent b88df81 commit 1280b76

File tree

1 file changed

+25
-29
lines changed

1 file changed

+25
-29
lines changed

Herebyfile.mjs

Lines changed: 25 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -86,21 +86,21 @@ export const generateLibs = task({
8686
await fs.promises.mkdir("./built/local", { recursive: true });
8787
const allSources = libs.flatMap((lib) => lib.sources);
8888
const allTargets = libs.flatMap((lib) => lib.target);
89-
if (needsUpdate([copyright, ...allSources], allTargets)) {
90-
for (const lib of libs) {
91-
let output = getCopyrightHeader();
92-
93-
await fs.promises.writeFile(lib.target, getCopyrightHeader());
94-
for (const source of lib.sources) {
95-
const contents = await fs.promises.readFile(source, "utf-8");
96-
// TODO(jakebailey): "\n\n" is for compatibility with our current tests; our test baselines
97-
// are sensitive to the positions of things in the lib files. Eventually remove this,
98-
// or remove lib.d.ts line numbers from our baselines.
99-
output += "\n\n" + contents.replace(/\r\n/g, "\n");
100-
}
101-
102-
await fs.promises.writeFile(lib.target, output);
89+
// if (needsUpdate([copyright, ...allSources], allTargets)) {
90+
// }
91+
for (const lib of libs) {
92+
let output = getCopyrightHeader();
93+
94+
await fs.promises.writeFile(lib.target, getCopyrightHeader());
95+
for (const source of lib.sources) {
96+
const contents = await fs.promises.readFile(source, "utf-8");
97+
// TODO(jakebailey): "\n\n" is for compatibility with our current tests; our test baselines
98+
// are sensitive to the positions of things in the lib files. Eventually remove this,
99+
// or remove lib.d.ts line numbers from our baselines.
100+
output += "\n\n" + contents.replace(/\r\n/g, "\n");
103101
}
102+
103+
await fs.promises.writeFile(lib.target, output);
104104
}
105105
},
106106
});
@@ -121,9 +121,7 @@ export const generateDiagnostics = task({
121121
name: "generate-diagnostics",
122122
description: "Generates a diagnostic file in TypeScript based on an input JSON file",
123123
run: async () => {
124-
if (needsUpdate(diagnosticMessagesJson, [diagnosticMessagesGeneratedJson, diagnosticInformationMapTs])) {
125-
await exec(process.execPath, ["scripts/processDiagnosticMessages.mjs", diagnosticMessagesJson]);
126-
}
124+
await exec(process.execPath, ["scripts/processDiagnosticMessages.mjs", diagnosticMessagesJson]);
127125
}
128126
});
129127

@@ -156,9 +154,11 @@ const localizationTargets = localizationDirectories
156154

157155
const localize = task({
158156
name: "localize",
157+
dependencies: [generateDiagnostics],
159158
run: async () => {
160-
await fs.promises.mkdir("./built/local", { recursive: true });
159+
await fs.promises.mkdir("./built/local", { recursive: true }); // TODO(jakebailey): needed?
161160
if (needsUpdate(diagnosticMessagesGeneratedJson, generatedLCGFile)) {
161+
// TODO(jakebailey): slow; need needsUpdate to not block the builds
162162
return exec(process.execPath, ["scripts/generateLocalizedDiagnosticMessages.mjs", "src/loc/lcl", "built/local", diagnosticMessagesGeneratedJson], { ignoreExitCode: true });
163163
}
164164
}
@@ -535,11 +535,9 @@ export const generateTypesMap = task({
535535
run: async () => {
536536
const source = "src/server/typesMap.json";
537537
const target = "built/local/typesMap.json";
538-
if (needsUpdate(source, target)) {
539-
const contents = await fs.promises.readFile(source, "utf-8");
540-
JSON.parse(contents);
541-
await fs.promises.writeFile(target, contents);
542-
}
538+
const contents = await fs.promises.readFile(source, "utf-8");
539+
JSON.parse(contents); // Validates that the JSON parses.
540+
await fs.promises.writeFile(target, contents);
543541
}
544542
});
545543

@@ -554,15 +552,13 @@ cleanTasks.push(cleanTypesMap);
554552
// it to be synced to the Azure DevOps repo, so that it can get picked up by the build
555553
// pipeline that generates the localization artifacts that are then fed into the translation process.
556554
const builtLocalDiagnosticMessagesGeneratedJson = "built/local/diagnosticMessages.generated.json";
557-
const copyBuiltLocalDiagnosticMessages = task({
555+
export const copyBuiltLocalDiagnosticMessages = task({
558556
name: "copy-built-local-diagnostic-messages",
559557
dependencies: [generateDiagnostics],
560558
run: async () => {
561-
if (needsUpdate(diagnosticMessagesGeneratedJson, builtLocalDiagnosticMessagesGeneratedJson)) {
562-
const contents = await fs.promises.readFile(diagnosticMessagesGeneratedJson, "utf-8");
563-
JSON.parse(contents);
564-
await fs.promises.writeFile(builtLocalDiagnosticMessagesGeneratedJson, contents);
565-
}
559+
const contents = await fs.promises.readFile(diagnosticMessagesGeneratedJson, "utf-8");
560+
JSON.parse(contents); // Validates that the JSON parses.
561+
await fs.promises.writeFile(builtLocalDiagnosticMessagesGeneratedJson, contents);
566562
}
567563
});
568564

0 commit comments

Comments
 (0)