installed-shallow.js 537 B

12345678910111213141516
  1. const { promisify } = require('util')
  2. const readdir = promisify(require('readdir-scoped-modules'))
  3. const installedShallow = async (npm, opts) => {
  4. const names = global => readdir(global ? npm.globalDir : npm.localDir)
  5. const { conf: { argv: { remain } } } = opts
  6. if (remain.length > 3)
  7. return null
  8. const { global } = npm.flatOptions
  9. const locals = global ? [] : await names(false)
  10. const globals = (await names(true)).map(n => global ? n : `${n} -g`)
  11. return [...locals, ...globals]
  12. }
  13. module.exports = installedShallow