Files
open-design/tools/pack/bin/tools-pack.mjs
T
mehmet turacandGitHub 8601dac9f4 fix(tools-pack): warn on stale dist in dev/workspace mode (#1470)
* fix(picker): improve provider group header separation in Media model picker

Added min-height and border-bottom to the sticky provider group header
to ensure it fully separates from the model content below.

Fixes #1434

* fix(tools-pack): warn on stale dist in dev/workspace mode

Detect when dist is stale relative to source and emit a warning.
This helps developers notice when they need to rebuild tools-pack
after making changes to tools/pack/src/**.

Fixes #1452

* fix(tools-pack): remove TypeScript annotation and use recursive source mtime check

Addressed review feedback:
- Remove  TypeScript annotation from .mjs file (P0)
- Use recursive source file mtime check instead of directory mtime (P1)

Fixes #1452
2026-05-13 16:28:57 +08:00

56 lines
1.5 KiB
JavaScript
Executable File

#!/usr/bin/env node
import { existsSync, readdirSync, statSync } from "node:fs";
import { dirname, resolve } from "node:path";
import { fileURLToPath, pathToFileURL } from "node:url";
const entryDir = dirname(fileURLToPath(import.meta.url));
const distEntry = resolve(entryDir, "../dist/index.mjs");
const srcDir = resolve(entryDir, "../src");
if (!existsSync(distEntry)) {
throw new Error(
`tools-pack dist entry not found at ${distEntry}. Run "pnpm --filter @open-design/tools-pack build" first.`,
);
}
// Check for stale dist in dev/workspace mode
function isStale() {
try {
const distStat = statSync(distEntry);
const distTime = distStat.mtimeMs;
// Recursively check all source files under src/
function checkDir(dir) {
try {
const entries = readdirSync(dir, { withFileTypes: true });
for (const entry of entries) {
const fullPath = resolve(dir, entry.name);
if (entry.isDirectory()) {
if (checkDir(fullPath)) return true;
} else {
const fileStat = statSync(fullPath);
if (fileStat.mtimeMs > distTime) return true;
}
}
} catch {
// Skip inaccessible directories
}
return false;
}
return checkDir(srcDir);
} catch {
return false;
}
}
if (isStale() && process.env.NODE_ENV !== "production") {
console.warn(
"[tools-pack] WARNING: dist is stale relative to source. " +
'Run "pnpm --filter @open-design/tools-pack build" to rebuild.'
);
}
await import(pathToFileURL(distEntry).href);