MCPcopy Create free account
hub / github.com/OpenHands/OpenHands / pruneUnusedFiles

Function pruneUnusedFiles

scripts/download-node.mjs:209–261  ·  view source on GitHub ↗

* Drop pieces of the Node distribution that are only useful when building * native modules from source or for human-readable documentation. Stripping * these shrinks the bundled Node from ~170 MB → ~115 MB on Linux x64 (the * Node binary itself is the bulk of what remains and can't be reduced).

(dir, platform)

Source from the content-addressed store, hash-verified

207 * LICENSE — required by the BSD-style Node license
208 */
209function pruneUnusedFiles(dir, platform) {
210 // IMPORTANT: every entry that points into a directory we delete must also
211 // delete any symlink/shim that targets into it, otherwise electron-builder
212 // hits ENOENT trying to stat() the dangling symlink while copying the
213 // extraResource into the .app bundle.
214 //
215 // Example: Node's POSIX tarball ships `bin/corepack` as a symlink to
216 // `../lib/node_modules/corepack/dist/corepack.js`. If we drop the corepack
217 // module under lib/ but leave the symlink, `electron-builder` fails with
218 // ENOENT: ... Resources/node/bin/corepack
219 const candidates =
220 platform === "win32"
221 ? [
222 // Windows Node zip lays out npm directly under node_modules/, not lib/.
223 // Strip docs, headers, and node_modules/corepack (the npm runtime
224 // doesn't need corepack to run, and we don't ship yarn/pnpm).
225 "CHANGELOG.md",
226 "README.md",
227 "node_modules/corepack",
228 // Windows ships corepack as both a Bash wrapper and a cmd.exe wrapper
229 // at the distribution root; both proxy into node_modules/corepack.
230 "corepack",
231 "corepack.cmd",
232 ]
233 : [
234 // POSIX layout — keep bin/ and lib/node_modules/npm; drop the rest.
235 "include",
236 "share",
237 "CHANGELOG.md",
238 "README.md",
239 "lib/node_modules/corepack",
240 // Symlink in bin/ targets the corepack we just deleted.
241 "bin/corepack",
242 ];
243 for (const rel of candidates) {
244 const p = join(dir, rel);
245 // `rmSync(force: true)` resolves the path through symlinks, so once the
246 // corepack target directory is deleted the now-dangling `bin/corepack`
247 // link reads as "already gone" and silently survives — the exact ENOENT
248 // trap failOnDanglingSymlinks() exists to catch. Remove files/symlinks
249 // with `unlinkSync` (lstat semantics, works on dangling links) first and
250 // fall back to `rmSync` for directories.
251 try {
252 unlinkSync(p);
253 } catch {
254 try {
255 rmSync(p, { recursive: true, force: true });
256 } catch {
257 // best-effort
258 }
259 }
260 }
261}
262
263// ── Dangling-symlink check ───────────────────────────────────────────────────
264

Callers 1

mainFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected