Prune packaged runtime safely
This commit is contained in:
@@ -10,7 +10,7 @@ const workspaceNodeModulesDir = resolve(workspaceDir, "node_modules");
|
|||||||
const manifestPath = resolve(workspaceDir, ".runtime-manifest.json");
|
const manifestPath = resolve(workspaceDir, ".runtime-manifest.json");
|
||||||
const workspacePackageJsonPath = resolve(workspaceDir, "package.json");
|
const workspacePackageJsonPath = resolve(workspaceDir, "package.json");
|
||||||
const workspaceArchivePath = resolve(feynmanDir, "runtime-workspace.tgz");
|
const workspaceArchivePath = resolve(feynmanDir, "runtime-workspace.tgz");
|
||||||
const PRUNE_VERSION = 1;
|
const PRUNE_VERSION = 3;
|
||||||
|
|
||||||
function readPackageSpecs() {
|
function readPackageSpecs() {
|
||||||
const settings = JSON.parse(readFileSync(settingsPath, "utf8"));
|
const settings = JSON.parse(readFileSync(settingsPath, "utf8"));
|
||||||
|
|||||||
@@ -4,25 +4,12 @@ import { basename, join, resolve } from "node:path";
|
|||||||
const root = resolve(process.argv[2] ?? ".");
|
const root = resolve(process.argv[2] ?? ".");
|
||||||
const nodeModulesDir = resolve(root, "node_modules");
|
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 = [
|
const STRIP_FILE_PATTERNS = [
|
||||||
/\.map$/i,
|
/\.map$/i,
|
||||||
/\.d\.cts$/i,
|
/\.d\.cts$/i,
|
||||||
/\.d\.ts$/i,
|
/\.d\.ts$/i,
|
||||||
/^README(\..+)?$/i,
|
/^README(\..+)?\.md$/i,
|
||||||
/^CHANGELOG(\..+)?$/i,
|
/^CHANGELOG(\..+)?\.md$/i,
|
||||||
];
|
];
|
||||||
|
|
||||||
function safeStat(path) {
|
function safeStat(path) {
|
||||||
@@ -47,11 +34,6 @@ function walkAndPrune(dir) {
|
|||||||
const isFile = entry.isFile() || stats?.isFile();
|
const isFile = entry.isFile() || stats?.isFile();
|
||||||
|
|
||||||
if (isDirectory) {
|
if (isDirectory) {
|
||||||
if (STRIP_DIR_NAMES.has(entry.name)) {
|
|
||||||
removePath(path);
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
walkAndPrune(path);
|
walkAndPrune(path);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
@@ -127,6 +109,14 @@ function prunePiCodingAgent(nodeModulesRoot) {
|
|||||||
removePath(join(pkgRoot, "examples"));
|
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)) {
|
if (!existsSync(nodeModulesDir)) {
|
||||||
process.exit(0);
|
process.exit(0);
|
||||||
}
|
}
|
||||||
@@ -136,5 +126,6 @@ pruneKoffi(nodeModulesDir);
|
|||||||
pruneBetterSqlite3(nodeModulesDir);
|
pruneBetterSqlite3(nodeModulesDir);
|
||||||
pruneLiteparse(nodeModulesDir);
|
pruneLiteparse(nodeModulesDir);
|
||||||
prunePiCodingAgent(nodeModulesDir);
|
prunePiCodingAgent(nodeModulesDir);
|
||||||
|
pruneMermaid(nodeModulesDir);
|
||||||
|
|
||||||
console.log(`[feynman] pruned runtime deps in ${basename(root)}`);
|
console.log(`[feynman] pruned runtime deps in ${basename(root)}`);
|
||||||
|
|||||||
Reference in New Issue
Block a user