installed-shallow.js 583 B

12345678910111213141516171819
  1. const { readdirScoped } = require('@npmcli/fs')
  2. const installedShallow = async (npm, opts) => {
  3. const names = async global => {
  4. const paths = await readdirScoped(global ? npm.globalDir : npm.localDir)
  5. return paths.map(p => p.replace(/\\/g, '/'))
  6. }
  7. const { conf: { argv: { remain } } } = opts
  8. if (remain.length > 3) {
  9. return null
  10. }
  11. const { global } = npm.flatOptions
  12. const locals = global ? [] : await names(false)
  13. const globals = (await names(true)).map(n => global ? n : `${n} -g`)
  14. return [...locals, ...globals]
  15. }
  16. module.exports = installedShallow