Prune packaged runtime safely

This commit is contained in:
Advait Paliwal
2026-03-24 14:25:50 -07:00
parent b624921bad
commit 771b39cbba
2 changed files with 12 additions and 21 deletions

View File

@@ -10,7 +10,7 @@ const workspaceNodeModulesDir = resolve(workspaceDir, "node_modules");
const manifestPath = resolve(workspaceDir, ".runtime-manifest.json");
const workspacePackageJsonPath = resolve(workspaceDir, "package.json");
const workspaceArchivePath = resolve(feynmanDir, "runtime-workspace.tgz");
const PRUNE_VERSION = 1;
const PRUNE_VERSION = 3;
function readPackageSpecs() {
const settings = JSON.parse(readFileSync(settingsPath, "utf8"));

View File

@@ -4,25 +4,12 @@ import { basename, join, resolve } from "node:path";
const root = resolve(process.argv[2] ?? ".");
const nodeModulesDir = resolve(root, "node_modules");
const STRIP_DIR_NAMES = new Set([
".github",
"__mocks__",
"__tests__",
"coverage",
"doc",
"docs",
"example",
"examples",
"test",
"tests",
]);
const STRIP_FILE_PATTERNS = [
/\.map$/i,
/\.d\.cts$/i,
/\.d\.ts$/i,
/^README(\..+)?$/i,
/^CHANGELOG(\..+)?$/i,
/^README(\..+)?\.md$/i,
/^CHANGELOG(\..+)?\.md$/i,
];
function safeStat(path) {
@@ -47,11 +34,6 @@ function walkAndPrune(dir) {
const isFile = entry.isFile() || stats?.isFile();
if (isDirectory) {
if (STRIP_DIR_NAMES.has(entry.name)) {
removePath(path);
continue;
}
walkAndPrune(path);
continue;
}
@@ -127,6 +109,14 @@ function prunePiCodingAgent(nodeModulesRoot) {
removePath(join(pkgRoot, "examples"));
}
function pruneMermaid(nodeModulesRoot) {
const pkgRoot = join(nodeModulesRoot, "mermaid", "dist");
if (!existsSync(pkgRoot)) return;
removePath(join(pkgRoot, "docs"));
removePath(join(pkgRoot, "tests"));
removePath(join(pkgRoot, "__mocks__"));
}
if (!existsSync(nodeModulesDir)) {
process.exit(0);
}
@@ -136,5 +126,6 @@ pruneKoffi(nodeModulesDir);
pruneBetterSqlite3(nodeModulesDir);
pruneLiteparse(nodeModulesDir);
prunePiCodingAgent(nodeModulesDir);
pruneMermaid(nodeModulesDir);
console.log(`[feynman] pruned runtime deps in ${basename(root)}`);