| 245 | } |
| 246 | |
| 247 | async findVersionsByPackageName (specs) { |
| 248 | let actualTree |
| 249 | const Arborist = require('@npmcli/arborist') |
| 250 | try { |
| 251 | const opts = { |
| 252 | ...this.npm.flatOptions, |
| 253 | path: this.top, |
| 254 | } |
| 255 | const arb = new Arborist(opts) |
| 256 | actualTree = await arb.loadActual(opts) |
| 257 | } catch { |
| 258 | log.verbose('diff', 'failed to load actual install tree') |
| 259 | } |
| 260 | |
| 261 | return specs.map(i => { |
| 262 | const spec = npa(i) |
| 263 | if (spec.rawSpec !== '*') { |
| 264 | return i |
| 265 | } |
| 266 | |
| 267 | const node = actualTree |
| 268 | && actualTree.inventory.query('name', spec.name) |
| 269 | .values().next().value |
| 270 | |
| 271 | const res = !node || !node.package || !node.package.version |
| 272 | ? spec.fetchSpec |
| 273 | : `file:${node.realpath}` |
| 274 | |
| 275 | return `${spec.name}@${res}` |
| 276 | }) |
| 277 | } |
| 278 | } |
| 279 | |
| 280 | module.exports = Diff |