Installing dependencies.
This commit is contained in:
+45
@@ -0,0 +1,45 @@
|
||||
const { resolve } = require('path')
|
||||
const Arborist = require('@npmcli/arborist')
|
||||
const localeCompare = require('@isaacs/string-locale-compare')('en')
|
||||
|
||||
const installedDeep = async (npm) => {
|
||||
const {
|
||||
depth,
|
||||
global,
|
||||
prefix,
|
||||
workspacesEnabled,
|
||||
} = npm.flatOptions
|
||||
|
||||
const getValues = (tree) =>
|
||||
[...tree.inventory.values()]
|
||||
.filter(i => i.location !== '' && !i.isRoot)
|
||||
.map(i => {
|
||||
return i
|
||||
})
|
||||
.filter(i => (i.depth - 1) <= depth)
|
||||
.sort((a, b) => (a.depth - b.depth) || localeCompare(a.name, b.name))
|
||||
|
||||
const res = new Set()
|
||||
const gArb = new Arborist({
|
||||
global: true,
|
||||
path: resolve(npm.globalDir, '..'),
|
||||
workspacesEnabled,
|
||||
})
|
||||
const gTree = await gArb.loadActual({ global: true })
|
||||
|
||||
for (const node of getValues(gTree)) {
|
||||
res.add(global ? node.name : [node.name, '-g'])
|
||||
}
|
||||
|
||||
if (!global) {
|
||||
const arb = new Arborist({ global: false, path: prefix, workspacesEnabled })
|
||||
const tree = await arb.loadActual()
|
||||
for (const node of getValues(tree)) {
|
||||
res.add(node.name)
|
||||
}
|
||||
}
|
||||
|
||||
return [...res]
|
||||
}
|
||||
|
||||
module.exports = installedDeep
|
||||
+17
@@ -0,0 +1,17 @@
|
||||
const { promisify } = require('util')
|
||||
const readdir = promisify(require('readdir-scoped-modules'))
|
||||
|
||||
const installedShallow = async (npm, opts) => {
|
||||
const names = global => readdir(global ? npm.globalDir : npm.localDir)
|
||||
const { conf: { argv: { remain } } } = opts
|
||||
if (remain.length > 3) {
|
||||
return null
|
||||
}
|
||||
|
||||
const { global } = npm.flatOptions
|
||||
const locals = global ? [] : await names(false)
|
||||
const globals = (await names(true)).map(n => global ? n : `${n} -g`)
|
||||
return [...locals, ...globals]
|
||||
}
|
||||
|
||||
module.exports = installedShallow
|
||||
Reference in New Issue
Block a user