@_linked/cli 1.43.0 → 1.44.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +21 -0
- package/README.md +11 -8
- package/defaults/package/package.json +4 -0
- package/lib/esm/cli.js +4 -10
- package/lib/esm/cli.js.map +1 -1
- package/lib/esm/client-dep-includes.d.ts +9 -3
- package/lib/esm/client-dep-includes.d.ts.map +1 -1
- package/lib/esm/client-dep-includes.js +10 -4
- package/lib/esm/client-dep-includes.js.map +1 -1
- package/lib/esm/commands/localize.d.ts +1 -1
- package/lib/esm/commands/localize.d.ts.map +1 -1
- package/lib/esm/commands/localize.js +15 -2
- package/lib/esm/commands/localize.js.map +1 -1
- package/lib/esm/localize/ensure.d.ts +4 -2
- package/lib/esm/localize/ensure.d.ts.map +1 -1
- package/lib/esm/localize/ensure.js +26 -41
- package/lib/esm/localize/ensure.js.map +1 -1
- package/lib/esm/localize/list.d.ts +2 -0
- package/lib/esm/localize/list.d.ts.map +1 -1
- package/lib/esm/localize/list.js +35 -1
- package/lib/esm/localize/list.js.map +1 -1
- package/lib/esm/localize/localize.d.ts.map +1 -1
- package/lib/esm/localize/localize.js +1 -1
- package/lib/esm/localize/localize.js.map +1 -1
- package/lib/esm/localize/manifest.d.ts +9 -0
- package/lib/esm/localize/manifest.d.ts.map +1 -1
- package/lib/esm/localize/manifest.js +2 -2
- package/lib/esm/localize/manifest.js.map +1 -1
- package/lib/esm/localize/one-copy-hook.d.ts +16 -0
- package/lib/esm/localize/one-copy-hook.d.ts.map +1 -0
- package/lib/esm/localize/one-copy-hook.js +20 -0
- package/lib/esm/localize/one-copy-hook.js.map +1 -0
- package/lib/esm/localize/prune.d.ts +115 -8
- package/lib/esm/localize/prune.d.ts.map +1 -1
- package/lib/esm/localize/prune.js +355 -126
- package/lib/esm/localize/prune.js.map +1 -1
- package/lib/esm/localize/relink.d.ts +3 -1
- package/lib/esm/localize/relink.d.ts.map +1 -1
- package/lib/esm/localize/relink.js +10 -5
- package/lib/esm/localize/relink.js.map +1 -1
- package/package.json +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"prune.js","sourceRoot":"","sources":["../../../src/localize/prune.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6DG;AACH,OAAO,EAAE,MAAM,SAAS,CAAC;AACzB,OAAO,IAAI,MAAM,WAAW,CAAC;AAE7B,OAAO,EAAC,QAAQ,EAAE,SAAS,EAAE,QAAQ,EAAC,MAAM,YAAY,CAAC;AACzD,OAAO,MAAM,MAAM,QAAQ,CAAC;AAC5B,OAAO,EAAC,gBAAgB,EAAC,MAAM,eAAe,CAAC;AA0B/C,yEAAyE;AACzE,MAAM,UAAU,aAAa,CAC3B,OAAsC,EACtC,IAA2B;IAE3B,MAAM,IAAI,GAAG,gBAAgB,CAAC,IAAI,CAAC,OAAO,EAAE,MAAM,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC,CAAC;IAClE,OAAO;QACL,KAAK,EAAE,IAAI,GAAG,CAAC,CAAC,GAAG,IAAI,CAAC,KAAK,EAAE,GAAG,MAAM,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC,CAAC;QACxD,OAAO,EAAE,IAAI,GAAG,CAAC,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC,CAAC,CAAC,CAAC;KACvD,CAAC;AACJ,CAAC;AAED;;;;;;;;;;GAUG;AACH,MAAM,UAAU,SAAS,CAAC,OAAe,EAAE,KAAa;IACtD,IAAI,OAAO,OAAO,KAAK,QAAQ,IAAI,OAAO,KAAK,KAAK,QAAQ;QAAE,OAAO,IAAI,CAAC;IAC1E,IAAI,MAAM,CAAC,KAAK,CAAC,OAAO,CAAC,KAAK,IAAI;QAAE,OAAO,IAAI,CAAC;IA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AC,CAAS;IAClC,IAAI,CAAC;QACH,OAAO,EAAE,CAAC,YAAY,CAAC,CAAC,CAAC,CAAC;IAC5B,CAAC;IAAC,WAAM,CAAC;QACP,OAAO,CAAC,CAAC;IACX,CAAC;AACH,CAAC","sourcesContent":["/**\n * Pruning -- stop a checkout's own `node_modules` holding a second copy of\n * something the app already provides. On by default after every install in a\n * checkout and on every `--relink`; `--no-prune` (`{prune: false}`) skips it.\n *\n * `shouldPrune(opts)` is the one place that default lives.\n *\n * Why it is needed. `npm install` inside a checkout (localize.ts, step 3)\n * installs what the CHECKOUT's lockfile says: its own copy of every\n * dependency, often older than the app's. Node resolves a module from the\n * importer's REAL path and takes the first `node_modules` it meets going up,\n * so a localized `A` that imports `B` gets `A/node_modules/B` -- a registry\n * copy -- and never the localized `B`; and a framework package that holds a\n * registry of classes (or React) loads once per copy. Measured with three\n * localized `@_linked/*` packages: plain Node and `tsx` loaded three copies of\n * the same core.\n *\n * What it does. For every localized checkout, each package at the top of its\n * `node_modules` that is a CANDIDATE (below) is removed when the app provides\n * it -- `<appRoot>/node_modules/<name>` exists -- at a version that satisfies\n * every range that resolves to that copy: the checkout's own declaration and\n * that of every installed package that would load it. Node's upward search\n * then finds the app's copy instead. Nothing else in the checkout moves.\n *\n * The candidates are `providedPackages` (provided.ts) -- the one rule the\n * run-time check and Vite's dedupe use too -- over the entries being pruned:\n *\n * - a **localized sibling** -- always counts as provided, whatever the range,\n * because the live checkout is the point of localizing it. A range it does\n * not satisfy is said out loud, never acted on;\n * - a **runtime dependency** (`dependencies`, `peerDependencies`,\n * `optionalDependencies`) of any localized checkout that the app has at a\n * version satisfying every localized checkout's range for it;\n * - `react` and `react-dom`.\n *\n * Nothing else is touched -- a devDependency the app happens to have too\n * stays, so the checkout's tooling does not come to depend on the app's. A\n * runtime dependency the rule leaves out because a localized range misses the\n * app's version is kept and said out loud, like any other copy kept below.\n *\n * Never removed, candidate or not:\n *\n * - a copy whose ranges the app's version does not satisfy -- kept, with a\n * warning naming the package, the range and the app's version;\n * - anything in a checkout that is not under the app root, because then the\n * upward search never reaches the app's `node_modules` and the removed\n * package would simply be missing.\n *\n * A package with a `bin` is NOT exempt. Measured in a checkout under an app\n * root with its own `@_linked/cli` removed: `npx linked build`,\n * `npm exec linked -- --help`, a script running `npm exec linked` and a script\n * running a bare `linked` all resolved `linked` to the app root's copy,\n * because npm puts every ancestor's `node_modules/.bin` on the PATH. The\n * removed package's links in the checkout's `node_modules/.bin` are removed\n * with it, so nothing dangles.\n *\n * It never runs npm and never touches the checkout's `package.json` or\n * `package-lock.json`. `npm install` in the checkout puts the copies back;\n * `ensure` (ensure.ts) is the install-then-prune step every in-checkout\n * install goes through, and the run-time check (`checkOneCopy`) takes them out\n * again before `linked start` and friends.\n */\nimport fs from 'node:fs';\nimport path from 'node:path';\n\nimport {isInside, isSymlink, readJson} from './fsops.js';\nimport semver from 'semver';\nimport {providedPackages} from './provided.js';\nimport type {ProvidedSkip} from './provided.js';\n\nimport type {ManifestEntry} from './manifest.js';\nimport type {Deps} from './run.js';\n\n/** What pruning reads from a command's options. */\nexport interface PruneOptions {\n /** On unless explicitly false. */\n prune?: boolean;\n}\n\n/** Limit a prune to some checkouts and/or some dependency names. */\nexport interface PruneScope {\n /** Only these localized packages' checkouts. */\n owners?: string[];\n /** Only these dependency names. */\n deps?: string[];\n}\n\n/** What pruning may remove: the rule's names plus every localized sibling, and what the rule skipped. */\nexport interface Candidates {\n names: Set<string>;\n skipped: Map<string, ProvidedSkip>;\n}\n\n/** The candidates for `entries`, by `providedPackages` (provided.ts). */\nexport function candidatesFor(\n entries: Record<string, ManifestEntry>,\n deps: Pick<Deps, 'appRoot'>,\n): Candidates {\n const rule = providedPackages(deps.appRoot, Object.keys(entries));\n return {\n names: new Set([...rule.names, ...Object.keys(entries)]),\n skipped: new Map(rule.skipped.map((s) => [s.name, s])),\n };\n}\n\n/**\n * Does the app's installed `version` satisfy `range`? `null` means \"cannot\n * tell\" -- a dist-tag, `file:`, `npm:`, `workspace:`, a git URL, or a version\n * that is not one -- and every caller then keeps the copy. The failure mode is\n * therefore always the safe one: a copy kept that could have gone, never a\n * copy removed that was needed.\n *\n * npm's own `semver` decides, so prereleases follow npm's rule: `1.3.0-beta.1`\n * satisfies a range only when one of its comparators names a prerelease on\n * the same `major.minor.patch`.\n */\nexport function satisfies(version: string, range: string): boolean | null {\n if (typeof version !== 'string' || typeof range !== 'string') return null;\n if (semver.valid(version) === null) return null;\n if (semver.validRange(range) === null) return null;\n return semver.satisfies(version, range);\n}\n\n/** Pruning is on unless a caller says `{prune: false}`. */\nexport function shouldPrune(opts: PruneOptions = {}): boolean {\n return opts.prune !== false;\n}\n\nconst REQUIRE_FIELDS = [\n 'dependencies',\n 'peerDependencies',\n 'optionalDependencies',\n];\nconst DECLARE_FIELDS = [\n 'dependencies',\n 'devDependencies',\n 'peerDependencies',\n 'optionalDependencies',\n];\n\n/**\n * @param entries the localized packages: every one counts as a sibling\n * @param opts unused beyond `prune`, which callers check with `shouldPrune`\n * @param deps `{appRoot, log, warn}`\n * @param scope prune only some checkouts / names (the run-time check)\n */\nexport function pruneProvided(\n entries: Record<string, ManifestEntry>,\n opts: PruneOptions,\n deps: Pick<Deps, 'appRoot' | 'log' | 'warn'>,\n scope: PruneScope = {},\n): {removed: any[]; kept: any[]} {\n const removed: any[] = [];\n const kept: any[] = [];\n const appRoot = realOrSelf(deps.appRoot);\n const candidates = candidatesFor(entries, deps);\n const only = scope.deps ? new Set(scope.deps) : null;\n\n for (const [name, entry] of Object.entries(entries)) {\n if (scope.owners && !scope.owners.includes(name)) continue;\n const pkgDir = path.join(deps.appRoot, entry.path);\n if (!fs.existsSync(path.join(pkgDir, 'package.json'))) continue;\n if (!isInside(realOrSelf(pkgDir), appRoot)) {\n deps.log(\n `[localize] ${name}: ${entry.path} is outside the app root, so Node cannot reach the app's ` +\n `node_modules from it — its own dependencies are left as they are.`,\n );\n continue;\n }\n const ctx = {\n name,\n entry,\n pkgDir,\n pkg: readJson(path.join(pkgDir, 'package.json')) ?? {},\n entries,\n candidates,\n only,\n deps,\n };\n for (const nm of nodeModulesRoots(pkgDir, entry)) {\n const result = pruneOne(nm, ctx);\n removed.push(...result.removed);\n kept.push(...result.kept);\n }\n }\n\n report(removed, kept, deps);\n return {removed, kept};\n}\n\n/**\n * Is `dep` -- declared by a checkout at `range` -- something the app provides,\n * so that its absence from the checkout's own `node_modules` is not a\n * dependency gone missing? `--relink` asks this before reinstalling a\n * checkout, so a copy pruned on purpose does not trigger a reinstall on every\n * postinstall.\n */\nexport function isProvidedByApp(\n dep: string,\n range: string | undefined,\n entries: Record<string, ManifestEntry>,\n candidates: Candidates,\n deps: Pick<Deps, 'appRoot'>,\n): boolean {\n const app = appCopy(dep, deps);\n if (!app) return false;\n if (entries[dep]) return true;\n if (!candidates.names.has(dep)) return false;\n return range === undefined || satisfies(app.version, range) === true;\n}\n\nfunction pruneOne(nm, ctx) {\n const removed = [];\n const kept = [];\n const {name: owner, entry, pkg, entries, candidates, only, deps} = ctx;\n\n for (const dep of topLevelPackages(nm)) {\n if (dep === owner) continue;\n if (only && !only.has(dep)) continue;\n const skip = candidates.skipped.get(dep);\n if (!candidates.names.has(dep) && !skip) continue;\n const dir = path.join(nm, dep);\n const nested = readJson(path.join(dir, 'package.json'));\n if (!nested) continue;\n const app = appCopy(dep, deps);\n if (!app) continue; // the app does not provide it, so this copy is the only one\n if (realOrSelf(dir) === app.real) continue; // already the app's copy\n\n const where = path.relative(deps.appRoot, dir);\n if (!candidates.names.has(dep)) {\n // The rule leaves it out: a localized checkout asks a range the app\n // misses. Said for a checkout that declares it; a copy it only has\n // transitively is none of its business.\n if (declared(pkg, DECLARE_FIELDS, dep) === undefined) continue;\n kept.push({\n where,\n dep,\n version: nested.version,\n app: app.version,\n unmet: skip!.asks,\n owner: entry.path,\n });\n continue;\n }\n const sibling = Boolean(entries[dep]);\n const ranges = rangesResolvingTo(nm, dep, pkg, owner);\n\n if (!sibling) {\n const unmet = ranges.filter(\n (r) => satisfies(app.version, r.range) !== true,\n );\n if (unmet.length) {\n kept.push({\n where,\n dep,\n version: nested.version,\n app: app.version,\n unmet,\n owner: entry.path,\n });\n continue;\n }\n }\n\n fs.rmSync(dir, {recursive: true, force: true});\n removeEmptyScope(nm, dep);\n removeBinLinksInto(nm, dir);\n removed.push({\n owner: entry.path,\n dep,\n version: nested.version,\n app: app.version,\n sibling,\n drift: sibling\n ? ranges.filter((r) => satisfies(app.version, r.range) === false)\n : [],\n });\n }\n return {removed, kept};\n}\n\nfunction report(removed, kept, deps) {\n const byOwner = new Map();\n for (const r of removed)\n byOwner.set(r.owner, [...(byOwner.get(r.owner) ?? []), r]);\n for (const [owner, list] of byOwner) {\n deps.log(\n `[localize] ${owner}: removed its own copies of what the app provides — ` +\n list\n .map(\n (r) =>\n `${r.dep}@${r.version} (app: ${r.sibling ? `localized, ${r.app}` : r.app})`,\n )\n .join(', '),\n );\n for (const r of list) {\n for (const d of r.drift) {\n deps.warn(\n `[localize] ${owner}: ${d.from} asks ${r.dep}@${d.range}; the localized checkout is ${r.app}. ` +\n `It is used anyway — that is what localizing it means — but the range is now fiction.`,\n );\n }\n }\n }\n for (const k of kept) {\n deps.warn(\n `[localize] kept ${k.where}@${k.version}: ` +\n k.unmet.map((u) => `${u.from} asks ${k.dep}@${u.range}`).join(', ') +\n `, and the app has ${k.dep}@${k.app}${\n k.unmet.some((u) => satisfies(k.app, u.range) === null)\n ? ' (or the range is one localize cannot read)'\n : ''\n }. ` +\n `${k.owner} loads its own copy, so the app loads two. Align the ranges, or update the app's ${k.dep}.`,\n );\n }\n}\n\n/**\n * Every range that resolves to `<nm>/<dep>`: the checkout's own declaration,\n * plus each installed package under `nm` that requires `dep` and has no copy\n * of its own between itself and `nm`.\n */\nfunction rangesResolvingTo(nm, dep, checkoutPkg, owner) {\n const out = [];\n const own = declared(checkoutPkg, DECLARE_FIELDS, dep);\n if (own !== undefined) out.push({from: owner, range: own});\n\n const walk = (dir, chain) => {\n for (const name of topLevelPackages(dir)) {\n const pkgDir = path.join(dir, name);\n if (isSymlink(pkgDir)) continue; // resolves from its real path, which is not here\n const pkg = readJson(path.join(pkgDir, 'package.json'));\n const range =\n pkg && name !== dep ? declared(pkg, REQUIRE_FIELDS, dep) : undefined;\n const inner = path.join(pkgDir, 'node_modules');\n const shadowed = [...chain, inner].some((d) =>\n fs.existsSync(path.join(d, dep)),\n );\n if (range !== undefined && !shadowed)\n out.push({from: `${name}@${pkg.version}`, range});\n if (fs.existsSync(inner)) walk(inner, [...chain, inner]);\n }\n };\n walk(nm, []);\n return out;\n}\n\nfunction declared(pkg, fields, dep) {\n for (const f of fields) if (pkg[f]?.[dep] !== undefined) return pkg[f][dep];\n return undefined;\n}\n\n/** The app's own copy of `dep`: `<appRoot>/node_modules/<dep>`, followed through a link. */\nfunction appCopy(dep, deps) {\n const dir = path.join(deps.appRoot, 'node_modules', dep);\n const pkg = readJson(path.join(dir, 'package.json'));\n if (!pkg?.version) return null;\n return {version: pkg.version, real: realOrSelf(dir)};\n}\n\n/** The package dir's `node_modules`, and the clone root's when the package is a monorepo subdir. */\nexport function nodeModulesRoots(pkgDir, entry) {\n const roots = [path.join(pkgDir, 'node_modules')];\n if (entry.subdir) {\n const rel = path.normalize(entry.subdir);\n if (pkgDir.endsWith(path.sep + rel))\n roots.push(path.join(pkgDir.slice(0, -(rel.length + 1)), 'node_modules'));\n }\n return roots.filter((d) => fs.existsSync(d));\n}\n\n/** Package names directly under a `node_modules`, scoped ones as `@scope/name`. */\nfunction topLevelPackages(nm) {\n const out = [];\n let items;\n try {\n items = fs.readdirSync(nm, {withFileTypes: true});\n } catch {\n return out;\n }\n for (const item of items) {\n if (item.name.startsWith('.')) continue;\n if (item.name.startsWith('@')) {\n let inner = [];\n try {\n inner = fs.readdirSync(path.join(nm, item.name));\n } catch {\n /* not a directory */\n }\n for (const sub of inner)\n if (!sub.startsWith('.')) out.push(`${item.name}/${sub}`);\n } else {\n out.push(item.name);\n }\n }\n return out;\n}\n\n/** Links in `<nm>/.bin` that pointed into a package just removed: dangling now. */\nfunction removeBinLinksInto(nm, removedDir) {\n const bin = path.join(nm, '.bin');\n let names;\n try {\n names = fs.readdirSync(bin);\n } catch {\n return;\n }\n for (const name of names) {\n const link = path.join(bin, name);\n if (!isSymlink(link)) continue;\n const target = path.resolve(bin, fs.readlinkSync(link));\n if (isInside(target, removedDir)) fs.unlinkSync(link);\n }\n}\n\nfunction removeEmptyScope(nm, dep) {\n if (!dep.startsWith('@')) return;\n const scope = path.join(nm, dep.split('/')[0]);\n try {\n if (!fs.readdirSync(scope).length) fs.rmdirSync(scope);\n } catch {\n /* already gone */\n }\n}\n\nexport function realOrSelf(p: string): string {\n try {\n return fs.realpathSync(p);\n } catch {\n return p;\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"prune.js","sourceRoot":"","sources":["../../../src/localize/prune.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAyEG;AACH,OAAO,EAAE,MAAM,SAAS,CAAC;AACzB,OAAO,IAAI,MAAM,WAAW,CAAC;AAE7B,OAAO,EAAC,QAAQ,EAAE,SAAS,EAAE,QAAQ,EAAC,MAAM,YAAY,CAAC;AACzD,OAAO,MAAM,MAAM,QAAQ,CAAC;AAC5B,OAAO,EAAC,gBAAgB,EAAC,MAAM,eAAe,CAAC;AA0B/C,6FAA6F;AAC7F,MAAM,UAAU,aAAa,CAC3B,OAAsC,EACtC,IAA2B;IAE3B,MAAM,IAAI,GAAG,gBAAgB,CAAC,IAAI,CAAC,OAAO,EAAE,MAAM,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC,CAAC;IAClE,OAAO;QACL,KAAK,EAAE,IAAI,GAAG,CAAC,CAAC,GAAG,IAAI,CAAC,KAAK,EAAE,GAAG,MAAM,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC,CAAC;QACxD,OAAO,EAAE,IAAI,GA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AAG,EAAE,CAAC,WAAW,CAAC,GAAG,CAAC,CAAC;IAC9B,CAAC;IAAC,WAAM,CAAC;QACP,OAAO;IACT,CAAC;IACD,KAAK,MAAM,IAAI,IAAI,KAAK,EAAE,CAAC;QACzB,MAAM,IAAI,GAAG,IAAI,CAAC,IAAI,CAAC,GAAG,EAAE,IAAI,CAAC,CAAC;QAClC,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC;YAAE,SAAS;QAC/B,MAAM,MAAM,GAAG,IAAI,CAAC,OAAO,CAAC,GAAG,EAAE,EAAE,CAAC,YAAY,CAAC,IAAI,CAAC,CAAC,CAAC;QACxD,IAAI,QAAQ,CAAC,MAAM,EAAE,UAAU,CAAC;YAAE,EAAE,CAAC,UAAU,CAAC,IAAI,CAAC,CAAC;IACxD,CAAC;AACH,CAAC;AAED,SAAS,gBAAgB,CAAC,EAAE,EAAE,GAAG;IAC/B,IAAI,CAAC,GAAG,CAAC,UAAU,CAAC,GAAG,CAAC;QAAE,OAAO;IACjC,MAAM,KAAK,GAAG,IAAI,CAAC,IAAI,CAAC,EAAE,EAAE,GAAG,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;IAC/C,IAAI,CAAC;QACH,IAAI,CAAC,EAAE,CAAC,WAAW,CAAC,KAAK,CAAC,CAAC,MAAM;YAAE,EAAE,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC;IACzD,CAAC;IAAC,WAAM,CAAC;QACP,kBAAkB;IACpB,CAAC;AACH,CAAC;AAED,MAAM,UAAU,UAAU,CAAC,CAAS;IAClC,IAAI,CAAC;QACH,OAAO,EAAE,CAAC,YAAY,CAAC,CAAC,CAAC,CAAC;IAC5B,CAAC;IAAC,WAAM,CAAC;QACP,OAAO,CAAC,CAAC;IACX,CAAC;AACH,CAAC","sourcesContent":["/**\n * Pruning -- stop a checkout's own `node_modules` holding a second copy of\n * something the app already provides. On by default after every install in a\n * checkout and on every `--relink`; `--no-prune` (`{prune: false}`) skips it.\n *\n * `shouldPrune(opts)` is the one place that default lives.\n *\n * Why it is needed. `npm install` inside a checkout (localize.ts, step 3)\n * installs what the CHECKOUT's lockfile says: its own copy of every\n * dependency, often older than the app's. Node resolves a module from the\n * importer's REAL path and takes the first `node_modules` it meets going up,\n * so a localized `A` that imports `B` gets `A/node_modules/B` -- a registry\n * copy -- and never the localized `B`; and a framework package that holds a\n * registry of classes (or React) loads once per copy. Measured with three\n * localized `@_linked/*` packages: plain Node and `tsx` loaded three copies of\n * the same core.\n *\n * What it does. For every localized checkout, each package at the top of its\n * `node_modules` that is a CANDIDATE in that checkout (below) is removed when\n * the app provides it -- `<appRoot>/node_modules/<name>` exists -- at a\n * version that satisfies every range that resolves to that copy: the\n * checkout's own declaration and that of every installed package that would\n * load it. Node's upward search then finds the app's copy instead. Nothing\n * else in the checkout moves.\n *\n * The candidates start from `providedPackages` (provided.ts) -- the one rule\n * the run-time check and Vite's dedupe use too -- and are taken PER CHECKOUT:\n *\n * - a **localized sibling** -- always counts as provided, whatever the range,\n * because the live checkout is the point of localizing it. A range it does\n * not satisfy is said out loud, never acted on;\n * - one of **this checkout's own runtime dependencies** (`dependencies`,\n * `peerDependencies`, `optionalDependencies`) that the rule provides -- the\n * app has it at a version satisfying every localized checkout's range;\n * - `react` and `react-dom`.\n *\n * Nothing else is touched -- this checkout's devDependency stays even when\n * another checkout depends on the same package at runtime, so the checkout's\n * tooling does not come to depend on the app's. A runtime dependency the rule\n * leaves out because a localized range misses the app's version is kept and\n * reported, like any other copy kept below.\n *\n * Never removed, candidate or not:\n *\n * - a copy whose ranges the app's version does not satisfy;\n * - a copy whose own dependencies would resolve to something else from the\n * app's copy than they do from the checkout (`contextChange` below): the\n * checkout keeps its own copies of whatever failed the guard, and removing\n * the copy would mix the two -- measured as a checkout's `tsc` seeing two\n * React type sets;\n * - anything in a checkout that is not under the app root, because then the\n * upward search never reaches the app's `node_modules` and the removed\n * package would simply be missing;\n * - anything in a checkout recorded with `prune: false` (localized with\n * `--no-prune`).\n *\n * Kept copies are reported once per checkout, as a summary; `--list` gives\n * each one's reason. A removal can make another copy removable, so a prune\n * repeats until a pass removes nothing.\n *\n * A package with a `bin` is NOT exempt. Measured in a checkout under an app\n * root with its own `@_linked/cli` removed: `npx linked build`,\n * `npm exec linked -- --help`, a script running `npm exec linked` and a script\n * running a bare `linked` all resolved `linked` to the app root's copy,\n * because npm puts every ancestor's `node_modules/.bin` on the PATH. The\n * removed package's links in the checkout's `node_modules/.bin` are removed\n * with it, so nothing dangles.\n *\n * It never runs npm and never touches the checkout's `package.json` or\n * `package-lock.json`. `npm install` in the checkout puts the copies back;\n * `ensure` (ensure.ts) is the install-then-prune step every in-checkout\n * install goes through, and the run-time check (`checkOneCopy`) takes them out\n * again before `linked start` and friends.\n */\nimport fs from 'node:fs';\nimport path from 'node:path';\n\nimport {isInside, isSymlink, readJson} from './fsops.js';\nimport semver from 'semver';\nimport {providedPackages} from './provided.js';\nimport type {ProvidedSkip} from './provided.js';\n\nimport type {ManifestEntry} from './manifest.js';\nimport type {Deps} from './run.js';\n\n/** What pruning reads from a command's options. */\nexport interface PruneOptions {\n /** On unless explicitly false. */\n prune?: boolean;\n}\n\n/** Limit a prune to some checkouts and/or some dependency names. */\nexport interface PruneScope {\n /** Only these localized packages' checkouts. */\n owners?: string[];\n /** Only these dependency names (the first pass; later passes take every candidate of `owners`). */\n deps?: string[];\n}\n\n/** The rule's names (every localized sibling among them) and what the rule skipped. */\nexport interface Candidates {\n names: Set<string>;\n skipped: Map<string, ProvidedSkip>;\n}\n\n/** The rule (`providedPackages`, provided.ts) over `entries`, plus every entry (sibling). */\nexport function candidatesFor(\n entries: Record<string, ManifestEntry>,\n deps: Pick<Deps, 'appRoot'>,\n): Candidates {\n const rule = providedPackages(deps.appRoot, Object.keys(entries));\n return {\n names: new Set([...rule.names, ...Object.keys(entries)]),\n skipped: new Map(rule.skipped.map((s) => [s.name, s])),\n };\n}\n\n/**\n * Does the app's installed `version` satisfy `range`? `null` means \"cannot\n * tell\" -- a dist-tag, `file:`, `npm:`, `workspace:`, a git URL, or a version\n * that is not one -- and every caller then keeps the copy. The failure mode is\n * therefore always the safe one: a copy kept that could have gone, never a\n * copy removed that was needed.\n *\n * npm's own `semver` decides, so prereleases follow npm's rule: `1.3.0-beta.1`\n * satisfies a range only when one of its comparators names a prerelease on\n * the same `major.minor.patch`.\n */\nexport function satisfies(version: string, range: string): boolean | null {\n if (typeof version !== 'string' || typeof range !== 'string') return null;\n if (semver.valid(version) === null) return null;\n if (semver.validRange(range) === null) return null;\n return semver.satisfies(version, range);\n}\n\n/** Pruning is on unless a caller says `{prune: false}`. */\nexport function shouldPrune(opts: PruneOptions = {}): boolean {\n return opts.prune !== false;\n}\n\n/** Is pruning on for this recorded checkout? `--no-prune` at localize/adopt records `prune: false`. */\nexport function prunesEntry(entry: Pick<ManifestEntry, 'prune'>): boolean {\n return entry.prune !== false;\n}\n\nconst REQUIRE_FIELDS = [\n 'dependencies',\n 'peerDependencies',\n 'optionalDependencies',\n];\nconst DECLARE_FIELDS = [\n 'dependencies',\n 'devDependencies',\n 'peerDependencies',\n 'optionalDependencies',\n];\n/** Candidates in every checkout, declared or not: a second React breaks hooks whoever loads it. */\nconst ALWAYS_CANDIDATES = new Set(['react', 'react-dom']);\n/** prune repeats until a pass removes nothing, at most this many passes. */\nexport const MAX_PRUNE_PASSES = 5;\n\n/** A range that resolves to a copy: who asks, and what. */\ninterface Ask {\n from: string;\n range: string;\n}\n\n/** One copy in a checkout's `node_modules`, and what pruning decides about it. */\nexport interface PruneDecision {\n /** The localized package whose checkout holds the copy. */\n ownerName: string;\n /** Its checkout, relative to the app root. */\n owner: string;\n dep: string;\n /** `<nm>/<dep>`, absolute. */\n dir: string;\n /** `dir` relative to the app root. */\n where: string;\n nm: string;\n version: string;\n /** The app's version. */\n app: string;\n sibling: boolean;\n action: 'remove' | 'keep';\n /**\n * Why a copy stays: `range` -- a range that loads it is one the app's\n * version misses (or one that cannot be read); `context` -- removing it\n * would change what its own dependencies resolve to.\n */\n reason?: 'range' | 'context';\n /** The ranges the app's version does not satisfy (`range`), or a sibling's drift (`remove`). */\n unmet: Ask[];\n /** `context`: the dependency that would resolve elsewhere, and both versions. */\n context?: {dep: string; here: string; app: string | null};\n}\n\n/** What a plan found, without touching anything. */\nexport interface PrunePlan {\n remove: PruneDecision[];\n keep: PruneDecision[];\n /** Checkouts left alone because they are not under the app root. */\n outside: {name: string; path: string}[];\n}\n\n/**\n * Per-call caches: a requirement index per `node_modules` (built once, see\n * `RequirementIndex`) and the package.json files read along the way.\n */\nexport interface PruneCache {\n indexes: Map<string, RequirementIndex>;\n /** How many indexes were built -- each is one read of a whole tree. */\n builds: number;\n}\n\nexport function newPruneCache(): PruneCache {\n return {indexes: new Map(), builds: 0};\n}\n\n/**\n * Decide, for every recorded checkout and every candidate copy in its\n * `node_modules`, whether pruning removes it -- without removing anything.\n * `pruneProvided` applies it; the run-time check (`checkOneCopy`) and\n * `--list` call it on its own, which is why it has to be cheap: a copy whose\n * checkout's own range rules it out is decided from that `package.json`\n * alone, and every other range comes from one requirement index per\n * `node_modules`, built at most once per call.\n *\n * Candidates are PER OWNER: a copy is a candidate in checkout O when the rule\n * provides it AND it is a localized sibling, `react`/`react-dom`, or one of\n * O's own runtime dependencies (`dependencies`, `peerDependencies`,\n * `optionalDependencies`). O's devDependencies are O's tooling, whatever\n * another checkout declares at runtime.\n */\nexport function planPrune(\n entries: Record<string, ManifestEntry>,\n deps: Pick<Deps, 'appRoot'>,\n scope: PruneScope = {},\n cache: PruneCache = newPruneCache(),\n candidates: Candidates = candidatesFor(entries, deps),\n): PrunePlan {\n const plan: PrunePlan = {remove: [], keep: [], outside: []};\n const appRoot = realOrSelf(deps.appRoot);\n const only = scope.deps ? new Set(scope.deps) : null;\n\n for (const [name, entry] of Object.entries(entries)) {\n if (scope.owners && !scope.owners.includes(name)) continue;\n if (!prunesEntry(entry)) continue;\n const pkgDir = path.join(deps.appRoot, entry.path);\n if (!fs.existsSync(path.join(pkgDir, 'package.json'))) continue;\n if (!isInside(realOrSelf(pkgDir), appRoot)) {\n plan.outside.push({name, path: entry.path});\n continue;\n }\n const pkg = readJson(path.join(pkgDir, 'package.json')) ?? {};\n const runtime = new Set(\n REQUIRE_FIELDS.flatMap((f) => Object.keys(pkg[f] ?? {})),\n );\n // The names that can be a decision here, looked up directly rather than\n // by listing node_modules (thousands of entries per checkout): this\n // checkout's candidates, and what the rule skipped that it declares.\n const names = new Set<string>();\n for (const n of candidates.names) {\n if (entries[n] || ALWAYS_CANDIDATES.has(n) || runtime.has(n))\n names.add(n);\n }\n for (const n of candidates.skipped.keys()) {\n if (declared(pkg, DECLARE_FIELDS, n) !== undefined) names.add(n);\n }\n names.delete(name);\n const ctx = {name, entry, pkg, names, entries, candidates, only, deps};\n for (const nm of nodeModulesRoots(pkgDir, entry)) {\n for (const d of decideIn(nm, ctx, cache)) {\n (d.action === 'remove' ? plan.remove : plan.keep).push(d);\n }\n }\n }\n return plan;\n}\n\n/**\n * @param entries the localized packages: every one counts as a sibling\n * @param opts unused beyond `prune`, which callers check with `shouldPrune`\n * @param deps `{appRoot, log, warn}`\n * @param scope prune only some checkouts / names (the run-time check)\n *\n * A removal can make another copy removable -- the copy that went was the one\n * asking a range the app misses, or the one a sibling copy's dependency\n * resolved to -- so it plans and removes again until a pass removes nothing\n * (at most `MAX_PRUNE_PASSES`): one call converges. A checkout recorded with\n * `prune: false` is never touched.\n */\nexport function pruneProvided(\n entries: Record<string, ManifestEntry>,\n opts: PruneOptions,\n deps: Pick<Deps, 'appRoot' | 'log' | 'warn'>,\n scope: PruneScope = {},\n cache: PruneCache = newPruneCache(),\n): {removed: PruneDecision[]; kept: PruneDecision[]} {\n const removed: PruneDecision[] = [];\n let kept: PruneDecision[] = [];\n const candidates = candidatesFor(entries, deps);\n\n for (let pass = 0; pass < MAX_PRUNE_PASSES; pass++) {\n const passScope = pass === 0 ? scope : {owners: scope.owners};\n const plan = planPrune(entries, deps, passScope, cache, candidates);\n if (pass === 0) {\n for (const o of plan.outside) {\n deps.log(\n `[localize] ${o.name}: ${o.path} is outside the app root, so Node cannot reach the app's ` +\n `node_modules from it — its own dependencies are left as they are.`,\n );\n }\n }\n for (const d of plan.remove) {\n fs.rmSync(d.dir, {recursive: true, force: true});\n removeEmptyScope(d.nm, d.dep);\n removeBinLinksInto(d.nm, d.dir);\n removed.push(d);\n }\n kept = plan.keep;\n if (!plan.remove.length) break;\n }\n\n report(removed, kept, deps);\n return {removed, kept};\n}\n\n/**\n * Is `dep` -- declared by a checkout at `range` -- something the app provides,\n * so that its absence from the checkout's own `node_modules` is not a\n * dependency gone missing? `--relink` asks this before reinstalling a\n * checkout, so a copy pruned on purpose does not trigger a reinstall on every\n * postinstall. `pkg` is the checkout's `package.json`: only what would be a\n * candidate in THAT checkout counts.\n */\nexport function isProvidedByApp(\n dep: string,\n range: string | undefined,\n entries: Record<string, ManifestEntry>,\n candidates: Candidates,\n deps: Pick<Deps, 'appRoot'>,\n pkg?: any,\n): boolean {\n const app = appCopy(dep, deps);\n if (!app) return false;\n if (entries[dep]) return true;\n if (!candidates.names.has(dep)) return false;\n if (\n pkg &&\n !ALWAYS_CANDIDATES.has(dep) &&\n declared(pkg, REQUIRE_FIELDS, dep) === undefined\n )\n return false;\n return range === undefined || satisfies(app.version, range) === true;\n}\n\nfunction decideIn(nm: string, ctx, cache: PruneCache): PruneDecision[] {\n const out: PruneDecision[] = [];\n const {name: owner, entry, pkg, names, entries, candidates, only, deps} = ctx;\n\n for (const dep of [...names].sort()) {\n if (only && !only.has(dep)) continue;\n const skip = candidates.skipped.get(dep);\n const inRule = candidates.names.has(dep);\n const sibling = Boolean(entries[dep]);\n const dir = path.join(nm, dep);\n const nested = readJson(path.join(dir, 'package.json'));\n if (!nested) continue;\n const app = appCopy(dep, deps);\n if (!app) continue; // the app does not provide it, so this copy is the only one\n if (realOrSelf(dir) === app.real) continue; // already the app's copy\n\n const base = {\n ownerName: owner,\n owner: entry.path,\n dep,\n dir,\n where: path.relative(deps.appRoot, dir),\n nm,\n version: nested.version,\n app: app.version,\n sibling,\n };\n\n if (!inRule) {\n // The rule leaves it out: a localized checkout asks a range the app\n // misses. Said for a checkout that declares it; a copy it only has\n // transitively is none of its business.\n if (declared(pkg, DECLARE_FIELDS, dep) === undefined) continue;\n out.push({...base, action: 'keep', reason: 'range', unmet: skip!.asks});\n continue;\n }\n\n const own = declared(pkg, DECLARE_FIELDS, dep);\n const ownAsk = own === undefined ? [] : [{from: owner, range: own}];\n if (sibling) {\n // Always removed: the live checkout is the point of localizing it. A\n // range it misses is drift, said out loud and never acted on.\n const ranges = [...ownAsk, ...requirementIndex(nm, cache).asks(dep)];\n out.push({\n ...base,\n action: 'remove',\n unmet: ranges.filter((r) => satisfies(app.version, r.range) === false),\n });\n continue;\n }\n\n // The checkout's own range first: when it rules the copy out, no index is needed.\n if (own !== undefined && satisfies(app.version, own) !== true) {\n out.push({...base, action: 'keep', reason: 'range', unmet: ownAsk});\n continue;\n }\n const unmet = requirementIndex(nm, cache)\n .asks(dep)\n .filter((r) => satisfies(app.version, r.range) !== true);\n if (unmet.length) {\n out.push({...base, action: 'keep', reason: 'range', unmet});\n continue;\n }\n const context = contextChange(dir, app.real, nested);\n if (context) {\n out.push({\n ...base,\n action: 'keep',\n reason: 'context',\n unmet: [],\n context,\n });\n continue;\n }\n out.push({...base, action: 'remove', unmet: []});\n }\n return out;\n}\n\n/**\n * Would removing the copy at `copyDir` change what ITS OWN dependencies\n * resolve to? Removing it hands its importers the app's copy, which resolves\n * its dependencies from the app root -- while the checkout keeps its own copy\n * of everything that failed the guard. Measured: a checkout kept its\n * `react`/`@types/react` 18 (its range), lost `prism-react-renderer` (in\n * range), and the app's copy of that resolved `react` -- and with it the\n * types -- to the app's 19: the checkout's own `tsc` saw both React type sets\n * and failed. So the copy stays when any of its `dependencies`,\n * `peerDependencies` or `optionalDependencies` (and the `@types/` package\n * TypeScript would take for it) resolves, from the copy's place in the\n * checkout, to a different package than from the app's copy: a different real\n * path that is not the same `name@version`, or nothing at all from the app's.\n * The same version at another path is the same code, so it does not count; a\n * dependency the checkout cannot resolve either is no change.\n */\nfunction contextChange(\n copyDir: string,\n appReal: string,\n pkg: any,\n): PruneDecision['context'] | undefined {\n const names = new Set<string>();\n for (const f of REQUIRE_FIELDS) {\n for (const d of Object.keys(pkg[f] ?? {})) {\n names.add(d);\n names.add(typesPackageFor(d));\n }\n }\n for (const d of names) {\n const here = resolveFrom(copyDir, d);\n if (!here) continue;\n const there = resolveFrom(appReal, d);\n if (!there) return {dep: d, here: here.version, app: null};\n if (here.real !== there.real && here.version !== there.version)\n return {dep: d, here: here.version, app: there.version};\n }\n return undefined;\n}\n\n/** `react` → `@types/react`; `@scope/name` → `@types/scope__name`; an `@types/` name is itself. */\nfunction typesPackageFor(name: string): string {\n if (name.startsWith('@types/')) return name;\n return `@types/${name.startsWith('@') ? name.slice(1).replace('/', '__') : name}`;\n}\n\n/** Node's upward search for `name` from the directory `from`: the first `node_modules/<name>`. */\nfunction resolveFrom(\n from: string,\n name: string,\n): {real: string; version: string} | null {\n for (let dir = from; ;) {\n if (path.basename(dir) !== 'node_modules') {\n const candidate = path.join(dir, 'node_modules', name);\n const pkg = readJson(path.join(candidate, 'package.json'));\n if (pkg)\n return {real: realOrSelf(candidate), version: String(pkg.version)};\n }\n const parent = path.dirname(dir);\n if (parent === dir) return null;\n dir = parent;\n }\n}\n\n/**\n * Every range that would load a copy at the top of one `node_modules`: the\n * requirements (`dependencies`, `peerDependencies`, `optionalDependencies`) of\n * every installed package under it, read ONCE per `node_modules`, then asked\n * per name. A package counts for `<nm>/<dep>` when nothing between it and\n * `nm` holds its own `dep` -- Node would load the top-level copy.\n *\n * Read from npm's hidden lockfile (`node_modules/.package-lock.json`, which\n * npm rewrites on every install in that tree) when there is one: measured\n * over 21 checkouts, parsing all of them took ~45 ms where walking the same\n * 16,800 package.json files took 0.8 s warm and 3.4 s cold. Without one (a\n * tree npm did not write) the tree is walked, once. Either way a requirer is\n * checked against the disk when asked about -- what an earlier prune removed\n * asks nothing, and a copy is shadowed only by a directory that exists.\n */\nexport interface RequirementIndex {\n asks(dep: string): Ask[];\n}\n\n/** An installed package under a `node_modules`, located only when asked about. */\ninterface Installed {\n name: string;\n version: string;\n /** Its path below `nm`, `/`-separated: `a/node_modules/@s/b`. */\n rel: string;\n located?: {dir: string; between: string[]};\n}\n\ninterface Requirer {\n installed: Installed;\n range: string;\n}\n\n/** The package's directory, and the `node_modules` directories between `nm` and it (its own included). */\nfunction locate(nm: string, i: Installed): {dir: string; between: string[]} {\n if (!i.located) {\n const segs = i.rel.split('/');\n const dir = path.join(nm, ...segs);\n const between = [path.join(dir, 'node_modules')];\n for (let k = 0; k < segs.length; k++) {\n if (segs[k] === 'node_modules')\n between.push(path.join(nm, ...segs.slice(0, k + 1)));\n }\n i.located = {dir, between};\n }\n return i.located;\n}\n\nfunction requirementIndex(nm: string, cache: PruneCache): RequirementIndex {\n let index = cache.indexes.get(nm);\n if (!index) {\n cache.builds++;\n const byDep = fromHiddenLockfile(nm) ?? fromWalk(nm);\n index = {\n asks(dep) {\n const out: Ask[] = [];\n for (const {installed, range} of byDep.get(dep) ?? []) {\n if (installed.name === dep) continue;\n const {dir, between} = locate(nm, installed);\n if (!fs.existsSync(path.join(dir, 'package.json'))) continue;\n if (between.some((d) => fs.existsSync(path.join(d, dep)))) continue;\n out.push({from: `${installed.name}@${installed.version}`, range});\n }\n return out;\n },\n };\n cache.indexes.set(nm, index);\n }\n return index;\n}\n\n/** Record what the package at `rel` (below `nm`) requires. */\nfunction addRequirer(\n byDep: Map<string, Requirer[]>,\n rel: string,\n pkg: any,\n): void {\n const at = rel.lastIndexOf('/node_modules/');\n const installed: Installed = {\n name: at === -1 ? rel : rel.slice(at + '/node_modules/'.length),\n version: pkg.version,\n rel,\n };\n const seen = new Set<string>();\n for (const f of REQUIRE_FIELDS) {\n for (const [dep, range] of Object.entries<any>(pkg[f] ?? {})) {\n if (typeof range !== 'string' || seen.has(dep)) continue;\n seen.add(dep);\n let list = byDep.get(dep);\n if (!list) byDep.set(dep, (list = []));\n list.push({installed, range});\n }\n }\n}\n\nconst NODE_MODULES_PREFIX = 'node_modules/';\n\nfunction fromHiddenLockfile(nm: string): Map<string, Requirer[]> | null {\n const lock = readJson(path.join(nm, '.package-lock.json'));\n if (!lock?.packages || typeof lock.packages !== 'object') return null;\n const byDep = new Map<string, Requirer[]>();\n for (const [key, meta] of Object.entries<any>(lock.packages)) {\n if (!key.startsWith(NODE_MODULES_PREFIX) || !meta || meta.link) continue;\n addRequirer(byDep, key.slice(NODE_MODULES_PREFIX.length), meta);\n }\n return byDep;\n}\n\nfunction fromWalk(nm: string): Map<string, Requirer[]> {\n const byDep = new Map<string, Requirer[]>();\n const walk = (dir: string, prefix: string) => {\n for (const name of topLevelPackages(dir)) {\n const pkgDir = path.join(dir, name);\n if (isSymlink(pkgDir)) continue; // resolves from its real path, which is not here\n const rel = prefix + name;\n const pkg = readJson(path.join(pkgDir, 'package.json'));\n if (pkg) addRequirer(byDep, rel, pkg);\n const inner = path.join(pkgDir, 'node_modules');\n if (fs.existsSync(inner)) walk(inner, `${rel}/node_modules/`);\n }\n };\n walk(nm, '');\n return byDep;\n}\n\nfunction report(removed: PruneDecision[], kept: PruneDecision[], deps) {\n const byOwner = new Map<string, PruneDecision[]>();\n for (const r of removed)\n byOwner.set(r.owner, [...(byOwner.get(r.owner) ?? []), r]);\n for (const [owner, list] of byOwner) {\n deps.log(\n `[localize] ${owner}: removed its own copies of what the app provides — ` +\n list\n .map(\n (r) =>\n `${r.dep}@${r.version} (app: ${r.sibling ? `localized, ${r.app}` : r.app})`,\n )\n .join(', '),\n );\n for (const r of list) {\n for (const d of r.unmet) {\n deps.warn(\n `[localize] ${owner}: ${d.from} asks ${r.dep}@${d.range}; the localized checkout is ${r.app}. ` +\n `It is used anyway — that is what localizing it means — but the range is now fiction.`,\n );\n }\n }\n }\n const keptBy = new Map<string, PruneDecision[]>();\n for (const k of kept)\n keptBy.set(k.owner, [...(keptBy.get(k.owner) ?? []), k]);\n for (const [owner, list] of keptBy) {\n const one = list.length === 1;\n deps.warn(\n `[localize] ${owner}: kept ${list.length} own ${one ? 'copy' : 'copies'} the app's cannot ` +\n `replace: ${summarizeKept(list)} — so the app loads ${one ? 'it' : 'them'} twice. ` +\n `\\`linked localize --list\\` says why.`,\n );\n }\n}\n\nconst SUMMARY_LIMIT = 8;\n\n/** `react@18.3.1 (app 19.2.0), prism-react-renderer@2.4.1 (its react would change), … and 4 more` */\nexport function summarizeKept(list: PruneDecision[]): string {\n const shown = list.slice(0, SUMMARY_LIMIT).map(keptShort);\n const more = list.length - shown.length;\n return shown.join(', ') + (more > 0 ? `, … and ${more} more` : '');\n}\n\nfunction keptShort(k: PruneDecision): string {\n return k.reason === 'context'\n ? `${k.dep}@${k.version} (its ${k.context!.dep} would change)`\n : `${k.dep}@${k.version} (app ${k.app})`;\n}\n\n/** The full reason a copy stays, for `--list`. */\nexport function explainKept(k: PruneDecision): string {\n if (k.reason === 'context') {\n const c = k.context!;\n return (\n `${k.where}@${k.version}: from the checkout its ${c.dep} is ${c.here}, from the app's copy ` +\n `${c.app === null ? 'nothing' : c.app} — removing it would change what it loads`\n );\n }\n return (\n `${k.where}@${k.version}: ` +\n k.unmet.map((u) => `${u.from} asks ${k.dep}@${u.range}`).join(', ') +\n `, and the app has ${k.dep}@${k.app}` +\n (k.unmet.some((u) => satisfies(k.app, u.range) === null)\n ? ' (or the range is one localize cannot read)'\n : '')\n );\n}\n\nfunction declared(pkg, fields, dep) {\n for (const f of fields) if (pkg[f]?.[dep] !== undefined) return pkg[f][dep];\n return undefined;\n}\n\n/** The app's own copy of `dep`: `<appRoot>/node_modules/<dep>`, followed through a link. */\nfunction appCopy(dep, deps) {\n const dir = path.join(deps.appRoot, 'node_modules', dep);\n const pkg = readJson(path.join(dir, 'package.json'));\n if (!pkg?.version) return null;\n return {version: pkg.version, real: realOrSelf(dir)};\n}\n\n/** The package dir's `node_modules`, and the clone root's when the package is a monorepo subdir. */\nexport function nodeModulesRoots(pkgDir, entry) {\n const roots = [path.join(pkgDir, 'node_modules')];\n if (entry.subdir) {\n const rel = path.normalize(entry.subdir);\n if (pkgDir.endsWith(path.sep + rel))\n roots.push(path.join(pkgDir.slice(0, -(rel.length + 1)), 'node_modules'));\n }\n return roots.filter((d) => fs.existsSync(d));\n}\n\n/** Package names directly under a `node_modules`, scoped ones as `@scope/name`. */\nfunction topLevelPackages(nm) {\n const out = [];\n let items;\n try {\n items = fs.readdirSync(nm, {withFileTypes: true});\n } catch {\n return out;\n }\n for (const item of items) {\n if (item.name.startsWith('.')) continue;\n if (item.name.startsWith('@')) {\n let inner = [];\n try {\n inner = fs.readdirSync(path.join(nm, item.name));\n } catch {\n /* not a directory */\n }\n for (const sub of inner)\n if (!sub.startsWith('.')) out.push(`${item.name}/${sub}`);\n } else {\n out.push(item.name);\n }\n }\n return out;\n}\n\n/** Links in `<nm>/.bin` that pointed into a package just removed: dangling now. */\nfunction removeBinLinksInto(nm, removedDir) {\n const bin = path.join(nm, '.bin');\n let names;\n try {\n names = fs.readdirSync(bin);\n } catch {\n return;\n }\n for (const name of names) {\n const link = path.join(bin, name);\n if (!isSymlink(link)) continue;\n const target = path.resolve(bin, fs.readlinkSync(link));\n if (isInside(target, removedDir)) fs.unlinkSync(link);\n }\n}\n\nfunction removeEmptyScope(nm, dep) {\n if (!dep.startsWith('@')) return;\n const scope = path.join(nm, dep.split('/')[0]);\n try {\n if (!fs.readdirSync(scope).length) fs.rmdirSync(scope);\n } catch {\n /* already gone */\n }\n}\n\nexport function realOrSelf(p: string): string {\n try {\n return fs.realpathSync(p);\n } catch {\n return p;\n }\n}\n"]}
|
|
@@ -5,7 +5,9 @@ import type { Deps } from './run.js';
|
|
|
5
5
|
* @param {{prune?: boolean}} [opts] unless `prune` is
|
|
6
6
|
* false, every checkout's own copies of what the app provides are removed
|
|
7
7
|
* after relinking (see prune.ts), and a dependency missing from a checkout
|
|
8
|
-
* because it was pruned is not mistaken for one a root install took.
|
|
8
|
+
* because it was pruned is not mistaken for one a root install took. A
|
|
9
|
+
* checkout recorded with `prune: false` (localized with `--no-prune`) is
|
|
10
|
+
* neither pruned nor excused.
|
|
9
11
|
*/
|
|
10
12
|
export declare function relink(deps: Deps, opts?: PruneOptions): number;
|
|
11
13
|
//# sourceMappingURL=relink.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"relink.d.ts","sourceRoot":"","sources":["../../../src/localize/relink.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"relink.d.ts","sourceRoot":"","sources":["../../../src/localize/relink.ts"],"names":[],"mappings":"AAuCA,OAAO,KAAK,EAAC,YAAY,EAAC,MAAM,YAAY,CAAC;AAC7C,OAAO,KAAK,EAAC,IAAI,EAAC,MAAM,UAAU,CAAC;AAEnC;;;;;;;;GAQG;AACH,wBAAgB,MAAM,CAAC,IAAI,EAAE,IAAI,EAAE,IAAI,GAAE,YAAiB,GAAG,MAAM,CAiElE"}
|
|
@@ -28,14 +28,16 @@ import path from 'node:path';
|
|
|
28
28
|
import { readManifest } from './manifest.js';
|
|
29
29
|
import { isSymlink, readJson, writeLink } from './fsops.js';
|
|
30
30
|
import { declaredRange } from './localize.js';
|
|
31
|
-
import { candidatesFor, isProvidedByApp, pruneProvided, shouldPrune, } from './prune.js';
|
|
31
|
+
import { candidatesFor, isProvidedByApp, pruneProvided, prunesEntry, shouldPrune, } from './prune.js';
|
|
32
32
|
import { ensure } from './ensure.js';
|
|
33
33
|
/**
|
|
34
34
|
* @param {object} deps
|
|
35
35
|
* @param {{prune?: boolean}} [opts] unless `prune` is
|
|
36
36
|
* false, every checkout's own copies of what the app provides are removed
|
|
37
37
|
* after relinking (see prune.ts), and a dependency missing from a checkout
|
|
38
|
-
* because it was pruned is not mistaken for one a root install took.
|
|
38
|
+
* because it was pruned is not mistaken for one a root install took. A
|
|
39
|
+
* checkout recorded with `prune: false` (localized with `--no-prune`) is
|
|
40
|
+
* neither pruned nor excused.
|
|
39
41
|
*/
|
|
40
42
|
export function relink(deps, opts = {}) {
|
|
41
43
|
let manifest;
|
|
@@ -99,10 +101,13 @@ export function relink(deps, opts = {}) {
|
|
|
99
101
|
*/
|
|
100
102
|
function reinstallIfPruned(name, entry, entries, opts, deps) {
|
|
101
103
|
const checkout = path.join(deps.appRoot, entry.path);
|
|
102
|
-
// When pruning, a dependency the app provides is absent on purpose
|
|
103
|
-
|
|
104
|
+
// When pruning, a dependency the app provides is absent on purpose -- unless
|
|
105
|
+
// this checkout was localized with `--no-prune`, when nothing is.
|
|
106
|
+
const candidates = shouldPrune(opts) && prunesEntry(entry)
|
|
107
|
+
? candidatesFor(entries, deps)
|
|
108
|
+
: null;
|
|
104
109
|
const provided = candidates
|
|
105
|
-
? (dep, range) => isProvidedByApp(dep, range, entries, candidates, deps)
|
|
110
|
+
? (dep, range, pkg) => isProvidedByApp(dep, range, entries, candidates, deps, pkg)
|
|
106
111
|
: () => false;
|
|
107
112
|
const missing = missingDependencies(checkout, cloneRootOf(entry, deps), provided);
|
|
108
113
|
if (!missing.length)
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"relink.js","sourceRoot":"","sources":["../../../src/localize/relink.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AACH,OAAO,EAAE,MAAM,SAAS,CAAC;AACzB,OAAO,IAAI,MAAM,WAAW,CAAC;AAE7B,OAAO,EAAC,YAAY,EAAC,MAAM,eAAe,CAAC;AAC3C,OAAO,EAAC,SAAS,EAAE,QAAQ,EAAE,SAAS,EAAC,MAAM,YAAY,CAAC;AAC1D,OAAO,EAAC,aAAa,EAAC,MAAM,eAAe,CAAC;AAC5C,OAAO,EACL,aAAa,EACb,eAAe,EACf,aAAa,EACb,WAAW,GACZ,MAAM,YAAY,CAAC;AACpB,OAAO,EAAC,MAAM,EAAC,MAAM,aAAa,CAAC;AAInC;;;;;;GAMG;AAC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a,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC;IAC3C,MAAM,OAAO,GAAG,MAAA,QAAQ,CAAC,IAAI,CAAC,IAAI,CAAC,QAAQ,EAAE,cAAc,CAAC,CAAC,0CAAE,OAAO,CAAC;IACvE,IAAI,CAAC,QAAQ,IAAI,CAAC,OAAO;QAAE,OAAO;IAClC,IACE,SAAS,CAAC,OAAO,EAAE,QAAQ,CAAC;QAC5B,CAAC,CAAC,KAAK,CAAC,KAAK,IAAI,KAAK,CAAC,KAAK,KAAK,QAAQ,CAAC;QAE1C,OAAO;IACT,IAAI,CAAC,IAAI,CACP,cAAc,IAAI,iBAAiB,OAAO,uBAAuB,QAAQ,EAAE;QACzE,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC,CAAC,cAAc,KAAK,CAAC,KAAK,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC;QACjD,oDAAoD,CACvD,CAAC;AACJ,CAAC;AAED;;;;GAIG;AACH,SAAS,SAAS,CAAC,OAAO,EAAE,KAAK;IAC/B,MAAM,CAAC,GAAG,gBAAgB,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;IACvC,IAAI,CAAC,CAAC;QAAE,OAAO,IAAI,CAAC;IACpB,OAAO,OAAO,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC;AACxC,CAAC","sourcesContent":["/**\n * `--relink` -- the `postinstall` hook. Recreate every recorded symlink after\n * an install removed it (`npm ci` deletes `node_modules` and exits 0).\n *\n * Three rules, each of which is the difference between a useful hook and one\n * everybody disables:\n *\n * - **It always exits 0.** A postinstall that fails an install because of a\n * developer's private state is worse than the problem it solves.\n * - **With no manifest it produces NO output at all.** That is the CI case and\n * the fresh-clone case. Any output there and people learn to ignore this\n * hook's output, which is the one thing it can never become.\n * - **It never runs npm at the consumer root.** A postinstall that installs\n * the root, recurses. A test asserts it.\n *\n * It DOES run `npm install` inside a checkout whose dependencies are gone, and\n * only then. Measured on npm 11: a root `npm install` treats a linked checkout\n * that sits under the root as part of the root's tree, marks its dependencies\n * `extraneous` and prunes them -- for a localized published dependency as\n * much as for an undeclared one. Putting the link back without the\n * dependencies leaves a checkout that cannot build. That install runs in the\n * checkout, never at the root, so it cannot re-enter this hook; and it runs\n * only when a declared dependency is missing, so an ordinary install stays\n * silent and fast.\n */\nimport fs from 'node:fs';\nimport path from 'node:path';\n\nimport {readManifest} from './manifest.js';\nimport {isSymlink, readJson, writeLink} from './fsops.js';\nimport {declaredRange} from './localize.js';\nimport {\n candidatesFor,\n isProvidedByApp,\n pruneProvided,\n shouldPrune,\n} from './prune.js';\nimport {ensure} from './ensure.js';\nimport type {PruneOptions} from './prune.js';\nimport type {Deps} from './run.js';\n\n/**\n * @param {object} deps\n * @param {{prune?: boolean}} [opts] unless `prune` is\n * false, every checkout's own copies of what the app provides are removed\n * after relinking (see prune.ts), and a dependency missing from a checkout\n * because it was pruned is not mistaken for one a root install took.\n */\nexport function relink(deps: Deps, opts: PruneOptions = {}): number {\n let manifest;\n try {\n manifest = readManifest(deps.appRoot, deps);\n } catch (e) {\n // Even a refusal is only a warning here: never fail an install.\n deps.warn(`[localize] ${e.message}`);\n return 0;\n }\n\n if (!manifest.exists) return 0;\n const names = Object.keys(manifest.entries);\n if (!names.length) return 0;\n\n let relinked = 0;\n for (const name of names) {\n const entry = manifest.entries[name];\n const checkout = path.join(deps.appRoot, entry.path);\n\n if (!fs.existsSync(checkout)) {\n deps.warn(\n `[localize] ${name} is recorded as local but ${entry.path} is gone — using the registry ` +\n `copy. ` +\n (entry.repo\n ? `\\`linked localize ${name}\\` to re-clone.`\n : `It has no recorded repository, so restore the checkout by hand, then ` +\n `\\`linked localize ${name} --adopt\\`.`),\n );\n continue;\n }\n\n reinstallIfPruned(name, entry, manifest.entries, opts, deps);\n\n if (isSymlink(path.join(deps.appRoot, 'node_modules', name))) {\n // Already linked; rewriting it would be noise on every install.\n const existing = fs.realpathSync(\n path.join(deps.appRoot, 'node_modules', name),\n );\n if (existing === fs.realpathSync(checkout)) continue;\n }\n\n writeLink(deps.appRoot, name, checkout);\n relinked++;\n deps.log(\n `[localize] relinked ${name} -> ${entry.path} (branch ${entry.branch})`,\n );\n warnRangeDrift(name, entry, checkout, deps);\n }\n\n if (relinked) {\n deps.log(\n `[localize] ${relinked} local package${relinked === 1 ? '' : 's'} relinked. ` +\n '`linked localize --list` for detail.',\n );\n }\n\n if (shouldPrune(opts)) {\n try {\n pruneProvided(manifest.entries, opts, deps);\n } catch (e) {\n // Never fail an install over it.\n deps.warn(`[localize] pruning failed: ${e.message}`);\n }\n }\n return 0;\n}\n\n/**\n * Restore a checkout's own `node_modules` when a root install pruned it: any\n * declared dependency (or devDependency -- the checkout's build needs those)\n * missing from it. A failure warns; the hook still exits 0.\n */\nfunction reinstallIfPruned(name, entry, entries, opts, deps) {\n const checkout = path.join(deps.appRoot, entry.path);\n // When pruning, a dependency the app provides is absent on purpose.\n const candidates = shouldPrune(opts) ? candidatesFor(entries, deps) : null;\n const provided = candidates\n ? (dep, range) => isProvidedByApp(dep, range, entries, candidates, deps)\n : () => false;\n const missing = missingDependencies(\n checkout,\n cloneRootOf(entry, deps),\n provided,\n );\n if (!missing.length) return;\n deps.log(\n `[localize] ${name}: ${missing.length} of its dependencies are gone from ${entry.path}/node_modules ` +\n `(a root install prunes a checkout under the root) — reinstalling it`,\n );\n try {\n ensure(entry, deps, opts);\n } catch (e) {\n deps.warn(\n `[localize] ${name}: ${e.message}\\n` +\n `Retry with \\`linked localize --reinstall ${name}\\`.`,\n );\n }\n}\n\n/**\n * Declared dependency names found in neither the checkout's own `node_modules`\n * nor, for a package inside a monorepo, the clone root's -- where a workspaces\n * install hoists them. Checking only the package directory there would find\n * every hoisted dependency \"missing\" and reinstall on every postinstall.\n */\nfunction missingDependencies(\n checkout: string,\n cloneRoot: string,\n provided: (dep: string, range: string, pkg: any) => boolean = () => false,\n): string[] {\n const pkg = readJson(path.join(checkout, 'package.json'));\n if (!pkg) return [];\n const declared = {...pkg.devDependencies, ...pkg.dependencies};\n const roots = cloneRoot === checkout ? [checkout] : [checkout, cloneRoot];\n return Object.keys(declared).filter(\n (dep) =>\n !roots.some((root) =>\n fs.existsSync(path.join(root, 'node_modules', dep)),\n ) && !provided(dep, declared[dep], pkg),\n );\n}\n\n/** The clone a `subdir` entry lives in: its path with the subdir taken off the end. */\nfunction cloneRootOf(entry, deps) {\n const pkgDir = path.join(deps.appRoot, entry.path);\n if (!entry.subdir) return pkgDir;\n const rel = path.normalize(entry.subdir);\n return pkgDir.endsWith(path.sep + rel)\n ? pkgDir.slice(0, -(rel.length + 1))\n : pkgDir;\n}\n\n/**\n * npm matches a link by NAME and never checks the range, so a checkout at\n * 2.0.99 silently satisfies `^3.0.0` and `npm ls` does not flag it. This warns\n * and never errors, and the range is never used to decide whether a checkout\n * is usable -- only to say out loud that the declared range is now fiction.\n */\nfunction warnRangeDrift(name, entry, checkout, deps) {\n const declared = declaredRange(name, deps);\n const version = readJson(path.join(checkout, 'package.json'))?.version;\n if (!declared || !version) return;\n if (\n sameMajor(version, declared) &&\n (!entry.range || entry.range === declared)\n )\n return;\n deps.warn(\n `[localize] ${name}: checkout is ${version}, package.json asks ${declared}` +\n (entry.range ? ` (recorded ${entry.range})` : '') +\n ` — the symlink wins; npm does NOT check the range.`,\n );\n}\n\n/**\n * Deliberately crude: enough to spot obvious drift for a warning, never used\n * to gate anything. Real semver (`satisfies` in prune.ts) here would invite\n * someone to treat the answer as a constraint.\n */\nfunction sameMajor(version, range) {\n const m = /^[\\^~]?(\\d+)\\./.exec(range);\n if (!m) return true;\n return version.split('.')[0] === m[1];\n}\n"]}
|
|
1
|
+
{"version":3,"file":"relink.js","sourceRoot":"","sources":["../../../src/localize/relink.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AACH,OAAO,EAAE,MAAM,SAAS,CAAC;AACzB,OAAO,IAAI,MAAM,WAAW,CAAC;AAE7B,OAAO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,CAAC,CAAC;AACxC,CAAC","sourcesContent":["/**\n * `--relink` -- the `postinstall` hook. Recreate every recorded symlink after\n * an install removed it (`npm ci` deletes `node_modules` and exits 0).\n *\n * Three rules, each of which is the difference between a useful hook and one\n * everybody disables:\n *\n * - **It always exits 0.** A postinstall that fails an install because of a\n * developer's private state is worse than the problem it solves.\n * - **With no manifest it produces NO output at all.** That is the CI case and\n * the fresh-clone case. Any output there and people learn to ignore this\n * hook's output, which is the one thing it can never become.\n * - **It never runs npm at the consumer root.** A postinstall that installs\n * the root, recurses. A test asserts it.\n *\n * It DOES run `npm install` inside a checkout whose dependencies are gone, and\n * only then. Measured on npm 11: a root `npm install` treats a linked checkout\n * that sits under the root as part of the root's tree, marks its dependencies\n * `extraneous` and prunes them -- for a localized published dependency as\n * much as for an undeclared one. Putting the link back without the\n * dependencies leaves a checkout that cannot build. That install runs in the\n * checkout, never at the root, so it cannot re-enter this hook; and it runs\n * only when a declared dependency is missing, so an ordinary install stays\n * silent and fast.\n */\nimport fs from 'node:fs';\nimport path from 'node:path';\n\nimport {readManifest} from './manifest.js';\nimport {isSymlink, readJson, writeLink} from './fsops.js';\nimport {declaredRange} from './localize.js';\nimport {\n candidatesFor,\n isProvidedByApp,\n pruneProvided,\n prunesEntry,\n shouldPrune,\n} from './prune.js';\nimport {ensure} from './ensure.js';\nimport type {PruneOptions} from './prune.js';\nimport type {Deps} from './run.js';\n\n/**\n * @param {object} deps\n * @param {{prune?: boolean}} [opts] unless `prune` is\n * false, every checkout's own copies of what the app provides are removed\n * after relinking (see prune.ts), and a dependency missing from a checkout\n * because it was pruned is not mistaken for one a root install took. A\n * checkout recorded with `prune: false` (localized with `--no-prune`) is\n * neither pruned nor excused.\n */\nexport function relink(deps: Deps, opts: PruneOptions = {}): number {\n let manifest;\n try {\n manifest = readManifest(deps.appRoot, deps);\n } catch (e) {\n // Even a refusal is only a warning here: never fail an install.\n deps.warn(`[localize] ${e.message}`);\n return 0;\n }\n\n if (!manifest.exists) return 0;\n const names = Object.keys(manifest.entries);\n if (!names.length) return 0;\n\n let relinked = 0;\n for (const name of names) {\n const entry = manifest.entries[name];\n const checkout = path.join(deps.appRoot, entry.path);\n\n if (!fs.existsSync(checkout)) {\n deps.warn(\n `[localize] ${name} is recorded as local but ${entry.path} is gone — using the registry ` +\n `copy. ` +\n (entry.repo\n ? `\\`linked localize ${name}\\` to re-clone.`\n : `It has no recorded repository, so restore the checkout by hand, then ` +\n `\\`linked localize ${name} --adopt\\`.`),\n );\n continue;\n }\n\n reinstallIfPruned(name, entry, manifest.entries, opts, deps);\n\n if (isSymlink(path.join(deps.appRoot, 'node_modules', name))) {\n // Already linked; rewriting it would be noise on every install.\n const existing = fs.realpathSync(\n path.join(deps.appRoot, 'node_modules', name),\n );\n if (existing === fs.realpathSync(checkout)) continue;\n }\n\n writeLink(deps.appRoot, name, checkout);\n relinked++;\n deps.log(\n `[localize] relinked ${name} -> ${entry.path} (branch ${entry.branch})`,\n );\n warnRangeDrift(name, entry, checkout, deps);\n }\n\n if (relinked) {\n deps.log(\n `[localize] ${relinked} local package${relinked === 1 ? '' : 's'} relinked. ` +\n '`linked localize --list` for detail.',\n );\n }\n\n if (shouldPrune(opts)) {\n try {\n pruneProvided(manifest.entries, opts, deps);\n } catch (e) {\n // Never fail an install over it.\n deps.warn(`[localize] pruning failed: ${e.message}`);\n }\n }\n return 0;\n}\n\n/**\n * Restore a checkout's own `node_modules` when a root install pruned it: any\n * declared dependency (or devDependency -- the checkout's build needs those)\n * missing from it. A failure warns; the hook still exits 0.\n */\nfunction reinstallIfPruned(name, entry, entries, opts, deps) {\n const checkout = path.join(deps.appRoot, entry.path);\n // When pruning, a dependency the app provides is absent on purpose -- unless\n // this checkout was localized with `--no-prune`, when nothing is.\n const candidates =\n shouldPrune(opts) && prunesEntry(entry)\n ? candidatesFor(entries, deps)\n : null;\n const provided = candidates\n ? (dep, range, pkg) =>\n isProvidedByApp(dep, range, entries, candidates, deps, pkg)\n : () => false;\n const missing = missingDependencies(\n checkout,\n cloneRootOf(entry, deps),\n provided,\n );\n if (!missing.length) return;\n deps.log(\n `[localize] ${name}: ${missing.length} of its dependencies are gone from ${entry.path}/node_modules ` +\n `(a root install prunes a checkout under the root) — reinstalling it`,\n );\n try {\n ensure(entry, deps, opts);\n } catch (e) {\n deps.warn(\n `[localize] ${name}: ${e.message}\\n` +\n `Retry with \\`linked localize --reinstall ${name}\\`.`,\n );\n }\n}\n\n/**\n * Declared dependency names found in neither the checkout's own `node_modules`\n * nor, for a package inside a monorepo, the clone root's -- where a workspaces\n * install hoists them. Checking only the package directory there would find\n * every hoisted dependency \"missing\" and reinstall on every postinstall.\n */\nfunction missingDependencies(\n checkout: string,\n cloneRoot: string,\n provided: (dep: string, range: string, pkg: any) => boolean = () => false,\n): string[] {\n const pkg = readJson(path.join(checkout, 'package.json'));\n if (!pkg) return [];\n const declared = {...pkg.devDependencies, ...pkg.dependencies};\n const roots = cloneRoot === checkout ? [checkout] : [checkout, cloneRoot];\n return Object.keys(declared).filter(\n (dep) =>\n !roots.some((root) =>\n fs.existsSync(path.join(root, 'node_modules', dep)),\n ) && !provided(dep, declared[dep], pkg),\n );\n}\n\n/** The clone a `subdir` entry lives in: its path with the subdir taken off the end. */\nfunction cloneRootOf(entry, deps) {\n const pkgDir = path.join(deps.appRoot, entry.path);\n if (!entry.subdir) return pkgDir;\n const rel = path.normalize(entry.subdir);\n return pkgDir.endsWith(path.sep + rel)\n ? pkgDir.slice(0, -(rel.length + 1))\n : pkgDir;\n}\n\n/**\n * npm matches a link by NAME and never checks the range, so a checkout at\n * 2.0.99 silently satisfies `^3.0.0` and `npm ls` does not flag it. This warns\n * and never errors, and the range is never used to decide whether a checkout\n * is usable -- only to say out loud that the declared range is now fiction.\n */\nfunction warnRangeDrift(name, entry, checkout, deps) {\n const declared = declaredRange(name, deps);\n const version = readJson(path.join(checkout, 'package.json'))?.version;\n if (!declared || !version) return;\n if (\n sameMajor(version, declared) &&\n (!entry.range || entry.range === declared)\n )\n return;\n deps.warn(\n `[localize] ${name}: checkout is ${version}, package.json asks ${declared}` +\n (entry.range ? ` (recorded ${entry.range})` : '') +\n ` — the symlink wins; npm does NOT check the range.`,\n );\n}\n\n/**\n * Deliberately crude: enough to spot obvious drift for a warning, never used\n * to gate anything. Real semver (`satisfies` in prune.ts) here would invite\n * someone to treat the answer as a constraint.\n */\nfunction sameMajor(version, range) {\n const m = /^[\\^~]?(\\d+)\\./.exec(range);\n if (!m) return true;\n return version.split('.')[0] === m[1];\n}\n"]}
|