Skip to content

Commit fe66643

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 1c5adef commit fe66643

File tree

1 file changed

+20
-32
lines changed

1 file changed

+20
-32
lines changed

Herebyfile.mjs

Lines changed: 20 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import del from "del";
55
import { task } from "hereby";
66
import _glob from "glob";
77
import util from "util";
8-
import { exec, readJson, needsUpdate, getDiffTool, getDirSize, memoize } from "./scripts/build/utils.mjs";
8+
import { exec, readJson, getDiffTool, getDirSize, memoize } from "./scripts/build/utils.mjs";
99
import { runConsoleTests, refBaseline, localBaseline, refRwcBaseline, localRwcBaseline } from "./scripts/build/tests.mjs";
1010
import { buildProject as realBuildProject, cleanProject } from "./scripts/build/projects.mjs";
1111
import { localizationDirectories } from "./scripts/build/localization.mjs";
@@ -80,20 +80,18 @@ export const generateLibs = task({
8080
description: "Builds the library targets",
8181
run: async () => {
8282
await fs.promises.mkdir("./built/local", { recursive: true });
83-
const allSources = libs().flatMap((lib) => lib.sources);
84-
const allTargets = libs().flatMap((lib) => lib.target);
85-
if (needsUpdate([copyrightFilename, ...allSources], allTargets)) {
86-
for (const lib of libs()) {
87-
let output = await copyright();
88-
89-
for (const source of lib.sources) {
90-
const contents = await fs.promises.readFile(source, "utf-8");
91-
// TODO(jakebailey): "\n\n" is for compatibility with our current tests; our test baselines
92-
// are sensitive to the positions of things in the lib files. Eventually remove this,
93-
// or remove lib.d.ts line numbers from our baselines.
94-
output += "\n\n" + contents.replace(/\r\n/g, "\n");
95-
}
83+
for (const lib of libs()) {
84+
let output = await copyright();
85+
86+
for (const source of lib.sources) {
87+
const contents = await fs.promises.readFile(source, "utf-8");
88+
// TODO(jakebailey): "\n\n" is for compatibility with our current tests; our test baselines
89+
// are sensitive to the positions of things in the lib files. Eventually remove this,
90+
// or remove lib.d.ts line numbers from our baselines.
91+
output += "\n\n" + contents.replace(/\r\n/g, "\n");
9692
}
93+
94+
await fs.promises.writeFile(lib.target, output);
9795
}
9896
},
9997
});
@@ -107,9 +105,7 @@ export const generateDiagnostics = task({
107105
name: "generate-diagnostics",
108106
description: "Generates a diagnostic file in TypeScript based on an input JSON file",
109107
run: async () => {
110-
if (needsUpdate(diagnosticMessagesJson, [diagnosticMessagesGeneratedJson, diagnosticInformationMapTs])) {
111-
await exec(process.execPath, ["scripts/processDiagnosticMessages.mjs", diagnosticMessagesJson]);
112-
}
108+
await exec(process.execPath, ["scripts/processDiagnosticMessages.mjs", diagnosticMessagesJson]);
113109
}
114110
});
115111

@@ -142,11 +138,7 @@ const localizationTargets = localizationDirectories
142138
const localize = task({
143139
name: "localize",
144140
dependencies: [generateDiagnostics],
145-
run: async () => {
146-
if (needsUpdate(diagnosticMessagesGeneratedJson, generatedLCGFile)) {
147-
return exec(process.execPath, ["scripts/generateLocalizedDiagnosticMessages.mjs", "src/loc/lcl", "built/local", diagnosticMessagesGeneratedJson], { ignoreExitCode: true });
148-
}
149-
}
141+
run: () => exec(process.execPath, ["scripts/generateLocalizedDiagnosticMessages.mjs", "src/loc/lcl", "built/local", diagnosticMessagesGeneratedJson], { ignoreExitCode: true }),
150142
});
151143

152144
export const buildSrc = task({
@@ -511,11 +503,9 @@ export const generateTypesMap = task({
511503
run: async () => {
512504
const source = "src/server/typesMap.json";
513505
const target = "built/local/typesMap.json";
514-
if (needsUpdate(source, target)) {
515-
const contents = await fs.promises.readFile(source, "utf-8");
516-
JSON.parse(contents);
517-
await fs.promises.writeFile(target, contents);
518-
}
506+
const contents = await fs.promises.readFile(source, "utf-8");
507+
JSON.parse(contents); // Validates that the JSON parses.
508+
await fs.promises.writeFile(target, contents);
519509
}
520510
});
521511

@@ -528,11 +518,9 @@ const copyBuiltLocalDiagnosticMessages = task({
528518
name: "copy-built-local-diagnostic-messages",
529519
dependencies: [generateDiagnostics],
530520
run: async () => {
531-
if (needsUpdate(diagnosticMessagesGeneratedJson, builtLocalDiagnosticMessagesGeneratedJson)) {
532-
const contents = await fs.promises.readFile(diagnosticMessagesGeneratedJson, "utf-8");
533-
JSON.parse(contents);
534-
await fs.promises.writeFile(builtLocalDiagnosticMessagesGeneratedJson, contents);
535-
}
521+
const contents = await fs.promises.readFile(diagnosticMessagesGeneratedJson, "utf-8");
522+
JSON.parse(contents); // Validates that the JSON parses.
523+
await fs.promises.writeFile(builtLocalDiagnosticMessagesGeneratedJson, contents);
536524
}
537525
});
538526

0 commit comments

Comments
 (0)