Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions workspaces/arborist/lib/arborist/load-actual.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// mix-in implementing the loadActual method

const { dirname, join, normalize, relative, resolve, sep } = require('node:path')
const { readFile } = require('node:fs/promises')

const PackageJson = require('@npmcli/package-json')
const { readdirScoped } = require('@npmcli/fs')
Expand Down Expand Up @@ -160,6 +161,7 @@ module.exports = cls => class ActualLoader extends cls {
}

await this.#loadFSTree(this.#actualTree)
await this.#recoverHiddenLockfile(this.#actualTree)
await this[_setWorkspaces](this.#actualTree)

// if there are workspace targets without Link nodes created, load
Expand Down Expand Up @@ -555,4 +557,24 @@ module.exports = cls => class ActualLoader extends cls {
await Promise.all(depPromises)
}
}


async #recoverHiddenLockfile(tree) {
if (tree.meta?.loadedFromDisk) return
const hiddenLockfile = resolve(this.path, 'node_modules/.package-lock.json')
try {
const data = JSON.parse(await readFile(hiddenLockfile, 'utf8'))
if (!data.packages) return
for (const [loc, pkg] of Object.entries(data.packages)) {
if (!loc || (!pkg.resolved && !pkg.integrity)) continue
const nodePath = resolve(this.path, loc)
const node = this.#cache.get(nodePath)
if (node) {
if (pkg.resolved && !node.resolved) node.resolved = pkg.resolved
if (pkg.integrity && !node.integrity) node.integrity = pkg.integrity
}
}
} catch {}
}

}