Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion extension/scripts/build-injection-patterns.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import { readFileSync, writeFileSync } from "node:fs";
import { join, relative } from "node:path";
import { load } from "js-yaml";
import { z } from "zod";
import { fileHasContent } from "./file-has-content";

const ROOT = join(import.meta.dir, "..");
const INPUT = join(ROOT, "data", "injection-patterns.yaml");
Expand Down Expand Up @@ -100,7 +101,13 @@ export function generateInjectionPatterns(): void {
return { name: entry.name, source, flags: entry.flags };
});

writeFileSync(OUTPUT, buildOutput(entries));
// Skip the write when nothing changed: the output lives under `src/`, which
// `build.ts --watch` watches recursively, so an unconditional write would
// re-trigger the watcher and loop forever. See ./file-has-content.
const output = buildOutput(entries);
if (!fileHasContent(OUTPUT, output)) {
writeFileSync(OUTPUT, output);
}
console.log(
`Generated ${relative(ROOT, OUTPUT)} from ${entries.length} patterns.`,
);
Expand Down
9 changes: 8 additions & 1 deletion extension/scripts/build-site-data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import {
SiteFileSchema,
toEntries,
} from "../data/site-rules.schema";
import { fileHasContent } from "./file-has-content";

const ROOT = join(import.meta.dir, "..");
const SITES_DIR = join(ROOT, "data", "sites");
Expand Down Expand Up @@ -313,7 +314,13 @@ export function generateSiteData(): void {

const parsed = loadSites();
const output = buildOutput(parsed);
writeFileSync(OUTPUT, output);
// Only write when the content actually changes. The output lives inside
// `src/`, which `build.ts --watch` watches recursively; an unconditional
// write would re-trigger the watcher on every build and spin into an
// infinite rebuild loop.
if (!fileHasContent(OUTPUT, output)) {
writeFileSync(OUTPUT, output);
}
console.log(
`Generated ${relative(ROOT, OUTPUT)} from ${parsed.length} site YAML files.`,
);
Expand Down
16 changes: 16 additions & 0 deletions extension/scripts/file-has-content.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// Copyright (c) 2026 PixieBrix, Inc.
// Licensed under PolyForm Shield 1.0.0 — see LICENSE.

import { readFileSync } from "node:fs";

// Returns true when `path` already holds exactly `expected`. Codegen writes
// into `src/`, which `build.ts --watch` watches recursively; guarding each
// `writeFileSync` with this check keeps an unchanged output from re-arming the
// watcher and spinning into an infinite rebuild loop.
export function fileHasContent(path: string, expected: string): boolean {
try {
return readFileSync(path, "utf8") === expected;
} catch {
return false;
}
}
Loading