Skip to content

Commit d5045ae

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 ab40f1f commit d5045ae

File tree

1 file changed

+21
-35
lines changed

1 file changed

+21
-35
lines changed

Diff for: Herebyfile.mjs

+21-35
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import esbuild from "esbuild";
66
import { task } from "hereby";
77
import _glob from "glob";
88
import util from "util";
9-
import { exec, readJson, needsUpdate, getDiffTool, getDirSize } from "./scripts/build/utils.mjs";
9+
import { exec, readJson, getDiffTool, getDirSize } from "./scripts/build/utils.mjs";
1010
import { runConsoleTests, refBaseline, localBaseline, refRwcBaseline, localRwcBaseline } from "./scripts/build/tests.mjs";
1111
import { buildProject as realBuildProject, cleanProject } from "./scripts/build/projects.mjs";
1212
import { localizationDirectories } from "./scripts/build/localization.mjs";
@@ -84,23 +84,19 @@ export const generateLibs = task({
8484
description: "Builds the library targets",
8585
run: async () => {
8686
await fs.promises.mkdir("./built/local", { recursive: true });
87-
const allSources = libs.flatMap((lib) => lib.sources);
88-
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);
87+
for (const lib of libs) {
88+
let output = getCopyrightHeader();
89+
90+
await fs.promises.writeFile(lib.target, getCopyrightHeader());
91+
for (const source of lib.sources) {
92+
const contents = await fs.promises.readFile(source, "utf-8");
93+
// TODO(jakebailey): "\n\n" is for compatibility with our current tests; our test baselines
94+
// are sensitive to the positions of things in the lib files. Eventually remove this,
95+
// or remove lib.d.ts line numbers from our baselines.
96+
output += "\n\n" + contents.replace(/\r\n/g, "\n");
10397
}
98+
99+
await fs.promises.writeFile(lib.target, output);
104100
}
105101
},
106102
});
@@ -121,9 +117,7 @@ export const generateDiagnostics = task({
121117
name: "generate-diagnostics",
122118
description: "Generates a diagnostic file in TypeScript based on an input JSON file",
123119
run: async () => {
124-
if (needsUpdate(diagnosticMessagesJson, [diagnosticMessagesGeneratedJson, diagnosticInformationMapTs])) {
125-
await exec(process.execPath, ["scripts/processDiagnosticMessages.mjs", diagnosticMessagesJson]);
126-
}
120+
await exec(process.execPath, ["scripts/processDiagnosticMessages.mjs", diagnosticMessagesJson]);
127121
}
128122
});
129123

@@ -157,11 +151,7 @@ const localizationTargets = localizationDirectories
157151
const localize = task({
158152
name: "localize",
159153
dependencies: [generateDiagnostics],
160-
run: async () => {
161-
if (needsUpdate(diagnosticMessagesGeneratedJson, generatedLCGFile)) {
162-
return exec(process.execPath, ["scripts/generateLocalizedDiagnosticMessages.mjs", "src/loc/lcl", "built/local", diagnosticMessagesGeneratedJson], { ignoreExitCode: true });
163-
}
164-
}
154+
run: () => exec(process.execPath, ["scripts/generateLocalizedDiagnosticMessages.mjs", "src/loc/lcl", "built/local", diagnosticMessagesGeneratedJson], { ignoreExitCode: true }),
165155
});
166156

167157
export const buildSrc = task({
@@ -534,11 +524,9 @@ export const generateTypesMap = task({
534524
run: async () => {
535525
const source = "src/server/typesMap.json";
536526
const target = "built/local/typesMap.json";
537-
if (needsUpdate(source, target)) {
538-
const contents = await fs.promises.readFile(source, "utf-8");
539-
JSON.parse(contents);
540-
await fs.promises.writeFile(target, contents);
541-
}
527+
const contents = await fs.promises.readFile(source, "utf-8");
528+
JSON.parse(contents); // Validates that the JSON parses.
529+
await fs.promises.writeFile(target, contents);
542530
}
543531
});
544532

@@ -557,11 +545,9 @@ const copyBuiltLocalDiagnosticMessages = task({
557545
name: "copy-built-local-diagnostic-messages",
558546
dependencies: [generateDiagnostics],
559547
run: async () => {
560-
if (needsUpdate(diagnosticMessagesGeneratedJson, builtLocalDiagnosticMessagesGeneratedJson)) {
561-
const contents = await fs.promises.readFile(diagnosticMessagesGeneratedJson, "utf-8");
562-
JSON.parse(contents);
563-
await fs.promises.writeFile(builtLocalDiagnosticMessagesGeneratedJson, contents);
564-
}
548+
const contents = await fs.promises.readFile(diagnosticMessagesGeneratedJson, "utf-8");
549+
JSON.parse(contents); // Validates that the JSON parses.
550+
await fs.promises.writeFile(builtLocalDiagnosticMessagesGeneratedJson, contents);
565551
}
566552
});
567553

0 commit comments

Comments
 (0)