trilium/scripts/wipe-node-modules.mts
Elian Doran 081de8d0ad
Some checks are pending
Checks / main (push) Waiting to run
CodeQL Advanced / Analyze (${{ matrix.language }}) (none, actions) (push) Waiting to run
CodeQL Advanced / Analyze (${{ matrix.language }}) (none, javascript-typescript) (push) Waiting to run
Dev / Detect affected suites (push) Waiting to run
Dev / Test development (push) Waiting to run
Dev / Test server (push) Blocked by required conditions
Dev / Test standalone (push) Blocked by required conditions
Dev / Test CKEditor 5 (shard ${{ matrix.shard }}) (1) (push) Blocked by required conditions
Dev / Test CKEditor 5 (shard ${{ matrix.shard }}) (2) (push) Blocked by required conditions
Dev / CKEditor 5 coverage gate (push) Blocked by required conditions
Dev / Build Docker image (push) Waiting to run
Dev / Check Docker build (Dockerfile) (push) Blocked by required conditions
Dev / Check Docker build (Dockerfile.alpine) (push) Blocked by required conditions
playwright / E2E tests on ${{ matrix.name }} (arm64, linux-arm64, ubuntu-24.04-arm) (push) Waiting to run
playwright / E2E tests on ${{ matrix.name }} (x64, linux-x64, ubuntu-22.04) (push) Waiting to run
playwright / PDF viewer E2E tests (push) Waiting to run
playwright / Standalone E2E tests on ${{ matrix.name }} (linux-arm64, ubuntu-24.04-arm) (push) Waiting to run
playwright / Standalone E2E tests on ${{ matrix.name }} (linux-x64, ubuntu-22.04) (push) Waiting to run
fix(scripts): wipe node_modules without glob
`glob` is not a dependency of the repo, so the import resolved to a
phantom hoisted glob@7.2.3 pulled in by @electron/asar, archiver-utils
and rimraf. That version takes a single string pattern and a callback,
so the array of patterns threw `TypeError: invalid pattern` out of
minimatch, and an awaited call would have yielded undefined anyway.

Three fixed patterns of depth two do not need a glob library, and its
version would keep shifting with the lockfile. Enumerate the workspace
directories with readdir instead, matching scripts/build-utils.ts.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
2026-08-26 22:51:23 +03:00

30 lines
1.0 KiB
TypeScript

import { existsSync } from "fs";
import { readdir, rm } from "fs/promises";
import path from "path";
const root = path.resolve(import.meta.dirname, "..");
const dirs = [
path.join(root, "node_modules"),
...await workspaceNodeModules("apps"),
...await workspaceNodeModules("packages")
].filter((dir) => existsSync(dir));
if (dirs.length === 0) {
console.log("No node_modules directories found.");
} else {
for (const dir of dirs) {
console.log(`Removing ${path.relative(root, dir)}`);
await rm(dir, { recursive: true, force: true });
}
console.log(`Done. Removed ${dirs.length} node_modules director${dirs.length === 1 ? "y" : "ies"}.`);
}
/** Returns the `node_modules` path of every workspace directly under `group` (`apps` or `packages`). */
async function workspaceNodeModules(group: string) {
const entries = await readdir(path.join(root, group), { withFileTypes: true });
return entries
.filter((entry) => entry.isDirectory())
.map((entry) => path.join(root, group, entry.name, "node_modules"));
}