11cb0ef41Sopenharmony_ciconst { resolve } = require('path') 21cb0ef41Sopenharmony_ciconst localeCompare = require('@isaacs/string-locale-compare')('en') 31cb0ef41Sopenharmony_ci 41cb0ef41Sopenharmony_ciconst installedDeep = async (npm) => { 51cb0ef41Sopenharmony_ci const Arborist = require('@npmcli/arborist') 61cb0ef41Sopenharmony_ci const { 71cb0ef41Sopenharmony_ci depth, 81cb0ef41Sopenharmony_ci global, 91cb0ef41Sopenharmony_ci prefix, 101cb0ef41Sopenharmony_ci workspacesEnabled, 111cb0ef41Sopenharmony_ci } = npm.flatOptions 121cb0ef41Sopenharmony_ci 131cb0ef41Sopenharmony_ci const getValues = (tree) => 141cb0ef41Sopenharmony_ci [...tree.inventory.values()] 151cb0ef41Sopenharmony_ci .filter(i => i.location !== '' && !i.isRoot) 161cb0ef41Sopenharmony_ci .map(i => { 171cb0ef41Sopenharmony_ci return i 181cb0ef41Sopenharmony_ci }) 191cb0ef41Sopenharmony_ci .filter(i => (i.depth - 1) <= depth) 201cb0ef41Sopenharmony_ci .sort((a, b) => (a.depth - b.depth) || localeCompare(a.name, b.name)) 211cb0ef41Sopenharmony_ci 221cb0ef41Sopenharmony_ci const res = new Set() 231cb0ef41Sopenharmony_ci const gArb = new Arborist({ 241cb0ef41Sopenharmony_ci global: true, 251cb0ef41Sopenharmony_ci path: resolve(npm.globalDir, '..'), 261cb0ef41Sopenharmony_ci workspacesEnabled, 271cb0ef41Sopenharmony_ci }) 281cb0ef41Sopenharmony_ci const gTree = await gArb.loadActual({ global: true }) 291cb0ef41Sopenharmony_ci 301cb0ef41Sopenharmony_ci for (const node of getValues(gTree)) { 311cb0ef41Sopenharmony_ci res.add(global ? node.name : [node.name, '-g']) 321cb0ef41Sopenharmony_ci } 331cb0ef41Sopenharmony_ci 341cb0ef41Sopenharmony_ci if (!global) { 351cb0ef41Sopenharmony_ci const arb = new Arborist({ global: false, path: prefix, workspacesEnabled }) 361cb0ef41Sopenharmony_ci const tree = await arb.loadActual() 371cb0ef41Sopenharmony_ci for (const node of getValues(tree)) { 381cb0ef41Sopenharmony_ci res.add(node.name) 391cb0ef41Sopenharmony_ci } 401cb0ef41Sopenharmony_ci } 411cb0ef41Sopenharmony_ci 421cb0ef41Sopenharmony_ci return [...res] 431cb0ef41Sopenharmony_ci} 441cb0ef41Sopenharmony_ci 451cb0ef41Sopenharmony_cimodule.exports = installedDeep 46