ci.js 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. 'use strict'
  2. const npm = require('./npm.js')
  3. const Installer = require('libcipm')
  4. const log = require('npmlog')
  5. const path = require('path')
  6. const pack = require('./pack.js')
  7. ci.usage = 'npm ci'
  8. ci.completion = (cb) => cb(null, [])
  9. module.exports = ci
  10. function ci (args, cb) {
  11. const opts = {
  12. // Add some non-npm-config opts by hand.
  13. cache: path.join(npm.config.get('cache'), '_cacache'),
  14. // NOTE: npm has some magic logic around color distinct from the config
  15. // value, so we have to override it here
  16. color: !!npm.color,
  17. hashAlgorithm: 'sha1',
  18. includeDeprecated: false,
  19. log,
  20. 'npm-session': npm.session,
  21. 'project-scope': npm.projectScope,
  22. refer: npm.referer,
  23. dmode: npm.modes.exec,
  24. fmode: npm.modes.file,
  25. umask: npm.modes.umask,
  26. npmVersion: npm.version,
  27. tmp: npm.tmp,
  28. dirPacker: pack.packGitDep
  29. }
  30. if (npm.config.get('dev')) {
  31. log.warn('ci', 'Usage of the `--dev` option is deprecated. Use `--also=dev` instead.')
  32. }
  33. for (const key in npm.config.list[0]) {
  34. if (!['log', 'cache'].includes(key)) {
  35. opts[key] = npm.config.list[0][key]
  36. }
  37. }
  38. return new Installer(opts).run().then(details => {
  39. log.disableProgress()
  40. console.log(`added ${details.pkgCount} packages in ${
  41. details.runTime / 1000
  42. }s`)
  43. }).then(() => cb(), cb)
  44. }