This commit is contained in:
Raven Scott
2026-04-09 21:02:51 -04:00
parent 6b1555eea9
commit 643e93a1f9
2 changed files with 71 additions and 1 deletions
+70
View File
@@ -41,6 +41,21 @@ if (!pkgRel) {
const pkgRoot = resolve(repoRoot, pkgRel)
const rootNm = join(repoRoot, 'node_modules')
const localNm = join(pkgRoot, 'node_modules')
const normalizedPkgRel = pkgRel
.replace(/\\/g, '/')
.replace(/^\.\//, '')
.replace(/\/+$/, '')
const concreteClosureByPkgRel = new Map([
[
'packages/bare-os-booter',
[
// Pear releases have dropped the hoisted holesail symlink tree; keep a concrete copy.
'holesail'
]
]
])
function linkTo(src, dst) {
mkdirSync(dirname(dst), { recursive: true })
const abs = resolve(src)
@@ -51,6 +66,13 @@ function linkTo(src, dst) {
}
}
function packagePath(nmRoot, spec) {
const parts = String(spec || '').split('/')
return spec.startsWith('@') && parts.length >= 2
? join(nmRoot, parts[0], parts[1])
: join(nmRoot, spec)
}
if (!existsSync(rootNm)) {
console.error(
'[ensure-pear-node-modules] Missing',
@@ -124,6 +146,54 @@ function copyExternalFileDeps(pkgRoot, localNm) {
copyExternalFileDeps(pkgRoot, localNm)
function copyConcreteDependencyClosure(pkgRoot, localNm, rootNm) {
void pkgRoot
const roots = concreteClosureByPkgRel.get(normalizedPkgRel)
if (!roots || roots.length === 0) return
const seen = new Set()
const queue = [...roots]
while (queue.length) {
const spec = queue.shift()
if (!spec || seen.has(spec)) continue
seen.add(spec)
const src = packagePath(rootNm, spec)
if (!existsSync(src)) {
console.warn(
'[ensure-pear-node-modules] concrete dependency missing:',
spec,
src
)
continue
}
const dst = packagePath(localNm, spec)
rmSync(dst, { recursive: true, force: true })
mkdirSync(dirname(dst), { recursive: true })
cpSync(src, dst, { recursive: true, dereference: true })
const pkgJsonPath = join(src, 'package.json')
if (!existsSync(pkgJsonPath)) continue
let pkg
try {
pkg = JSON.parse(readFileSync(pkgJsonPath, 'utf8'))
} catch {
continue
}
const deps = {
...(pkg.optionalDependencies || {}),
...(pkg.dependencies || {})
}
for (const depName of Object.keys(deps)) queue.push(depName)
}
}
copyConcreteDependencyClosure(pkgRoot, localNm, rootNm)
const pkgJsonPath = join(pkgRoot, 'package.json')
if (existsSync(pkgJsonPath)) {
const pkg = JSON.parse(readFileSync(pkgJsonPath, 'utf8'))