PHP 8.2.30
Preview: ci.js Size: 3.63 KB
//opt/alt/alt-nodejs16/root/lib/node_modules/npm/lib/commands/ci.js

const util = require('util')
const Arborist = require('@npmcli/arborist')
const rimraf = util.promisify(require('rimraf'))
const reifyFinish = require('../utils/reify-finish.js')
const runScript = require('@npmcli/run-script')
const fs = require('fs')
const readdir = util.promisify(fs.readdir)
const log = require('../utils/log-shim.js')
const validateLockfile = require('../utils/validate-lockfile.js')

const ArboristWorkspaceCmd = require('../arborist-cmd.js')
const Install = require('./install.js')

class CI extends ArboristWorkspaceCmd {
  static description = 'Clean install a project'
  static name = 'ci'

  static params = Install.params

  async exec () {
    if (this.npm.global) {
      throw Object.assign(new Error('`npm ci` does not work for global packages'), {
        code: 'ECIGLOBAL',
      })
    }

    const where = this.npm.prefix
    const opts = {
      ...this.npm.flatOptions,
      packageLock: true, // npm ci should never skip lock files
      path: where,
      save: false, // npm ci should never modify the lockfile or package.json
      workspaces: this.workspaceNames,
    }

    const arb = new Arborist(opts)
    await arb.loadVirtual().catch(er => {
      log.verbose('loadVirtual', er.stack)
      const msg =
        'The `npm ci` command can only install with an existing package-lock.json or\n' +
        'npm-shrinkwrap.json with lockfileVersion >= 1. Run an install with npm@5 or\n' +
        'later to generate a package-lock.json file, then try again.'
      throw this.usageError(msg)
    })

    // retrieves inventory of packages from loaded virtual tree (lock file)
    const virtualInventory = new Map(arb.virtualTree.inventory)

    // build ideal tree step needs to come right after retrieving the virtual
    // inventory since it's going to erase the previous ref to virtualTree
    await arb.buildIdealTree()

    // verifies that the packages from the ideal tree will match
    // the same versions that are present in the virtual tree (lock file)
    // throws a validation error in case of mismatches
    const errors = validateLockfile(virtualInventory, arb.idealTree.inventory)
    if (errors.length) {
      throw this.usageError(
        '`npm ci` can only install packages when your package.json and ' +
        'package-lock.json or npm-shrinkwrap.json are in sync. Please ' +
        'update your lock file with `npm install` ' +
        'before continuing.\n\n' +
        errors.join('\n')
      )
    }

    // Only remove node_modules after we've successfully loaded the virtual
    // tree and validated the lockfile
    await this.npm.time('npm-ci:rm', async () => {
      const path = `${where}/node_modules`
      // get the list of entries so we can skip the glob for performance
      const entries = await readdir(path, null).catch(er => [])
      return Promise.all(entries.map(f => rimraf(`${path}/${f}`, { glob: false })))
    })

    await arb.reify(opts)

    const ignoreScripts = this.npm.config.get('ignore-scripts')
    // run the same set of scripts that `npm install` runs.
    if (!ignoreScripts) {
      const scripts = [
        'preinstall',
        'install',
        'postinstall',
        'prepublish', // XXX should we remove this finally??
        'preprepare',
        'prepare',
        'postprepare',
      ]
      const scriptShell = this.npm.config.get('script-shell') || undefined
      for (const event of scripts) {
        await runScript({
          path: where,
          args: [],
          scriptShell,
          stdio: 'inherit',
          stdioString: true,
          banner: !this.npm.silent,
          event,
        })
      }
    }
    await reifyFinish(this.npm, arb)
  }
}

module.exports = CI

Directory Contents

Dirs: 0 × Files: 68

Name Size Perms Modified Actions
5.45 KB lrw-r--r-- 2026-03-17 06:55:03
Edit Download
2.20 KB lrw-r--r-- 2026-03-17 06:55:03
Edit Download
11.95 KB lrw-r--r-- 2026-03-17 06:55:03
Edit Download
729 B lrw-r--r-- 2026-03-17 06:55:03
Edit Download
508 B lrw-r--r-- 2026-03-17 06:55:03
Edit Download
815 B lrw-r--r-- 2026-03-17 06:55:03
Edit Download
7.08 KB lrw-r--r-- 2026-03-17 06:55:03
Edit Download
3.63 KB lrw-r--r-- 2026-03-17 06:55:03
Edit Download
8.91 KB lrw-r--r-- 2026-03-17 06:55:03
Edit Download
8.11 KB lrw-r--r-- 2026-03-17 06:55:03
Edit Download
1.37 KB lrw-r--r-- 2026-03-17 06:55:03
Edit Download
2.06 KB lrw-r--r-- 2026-03-17 06:55:03
Edit Download
8.10 KB lrw-r--r-- 2026-03-17 06:55:03
Edit Download
5.47 KB lrw-r--r-- 2026-03-17 06:55:03
Edit Download
447 B lrw-r--r-- 2026-03-17 06:55:03
Edit Download
9.22 KB lrw-r--r-- 2026-03-17 06:55:03
Edit Download
2.00 KB lrw-r--r-- 2026-03-17 06:55:03
Edit Download
2.44 KB lrw-r--r-- 2026-03-17 06:55:03
Edit Download
3.55 KB lrw-r--r-- 2026-03-17 06:55:03
Edit Download
2.33 KB lrw-r--r-- 2026-03-17 06:55:03
Edit Download
602 B lrw-r--r-- 2026-03-17 06:55:03
Edit Download
6.37 KB lrw-r--r-- 2026-03-17 06:55:03
Edit Download
524 B lrw-r--r-- 2026-03-17 06:55:03
Edit Download
5.62 KB lrw-r--r-- 2026-03-17 06:55:03
Edit Download
4.53 KB lrw-r--r-- 2026-03-17 06:55:03
Edit Download
3.93 KB lrw-r--r-- 2026-03-17 06:55:03
Edit Download
6.81 KB lrw-r--r-- 2026-03-17 06:55:03
Edit Download
377 B lrw-r--r-- 2026-03-17 06:55:03
Edit Download
374 B lrw-r--r-- 2026-03-17 06:55:03
Edit Download
5.11 KB lrw-r--r-- 2026-03-17 06:55:03
Edit Download
5.02 KB lrw-r--r-- 2026-03-17 06:55:03
Edit Download
234 B lrw-r--r-- 2026-03-17 06:55:03
Edit Download
1.34 KB lrw-r--r-- 2026-03-17 06:55:03
Edit Download
16.94 KB lrw-r--r-- 2026-03-17 06:55:03
Edit Download
4.20 KB lrw-r--r-- 2026-03-17 06:55:03
Edit Download
8.84 KB lrw-r--r-- 2026-03-17 06:55:03
Edit Download
5.88 KB lrw-r--r-- 2026-03-17 06:55:03
Edit Download
2.36 KB lrw-r--r-- 2026-03-17 06:55:03
Edit Download
874 B lrw-r--r-- 2026-03-17 06:55:03
Edit Download
3.47 KB lrw-r--r-- 2026-03-17 06:55:03
Edit Download
343 B lrw-r--r-- 2026-03-17 06:55:03
Edit Download
11.25 KB lrw-r--r-- 2026-03-17 06:55:03
Edit Download
779 B lrw-r--r-- 2026-03-17 06:55:03
Edit Download
6.33 KB lrw-r--r-- 2026-03-17 06:55:03
Edit Download
2.81 KB lrw-r--r-- 2026-03-17 06:55:03
Edit Download
2.16 KB lrw-r--r-- 2026-03-17 06:55:03
Edit Download
1.24 KB lrw-r--r-- 2026-03-17 06:55:03
Edit Download
351 B lrw-r--r-- 2026-03-17 06:55:03
Edit Download
298 B lrw-r--r-- 2026-03-17 06:55:03
Edit Download
6.90 KB lrw-r--r-- 2026-03-17 06:55:03
Edit Download
2.72 KB lrw-r--r-- 2026-03-17 06:55:03
Edit Download
2.63 KB lrw-r--r-- 2026-03-17 06:55:03
Edit Download
572 B lrw-r--r-- 2026-03-17 06:55:03
Edit Download
2.64 KB lrw-r--r-- 2026-03-17 06:55:03
Edit Download
1.87 KB lrw-r--r-- 2026-03-17 06:55:03
Edit Download
1.03 KB lrw-r--r-- 2026-03-17 06:55:03
Edit Download
341 B lrw-r--r-- 2026-03-17 06:55:03
Edit Download
336 B lrw-r--r-- 2026-03-17 06:55:03
Edit Download
4.44 KB lrw-r--r-- 2026-03-17 06:55:03
Edit Download
336 B lrw-r--r-- 2026-03-17 06:55:03
Edit Download
6.79 KB lrw-r--r-- 2026-03-17 06:55:03
Edit Download
1.52 KB lrw-r--r-- 2026-03-17 06:55:03
Edit Download
4.51 KB lrw-r--r-- 2026-03-17 06:55:03
Edit Download
182 B lrw-r--r-- 2026-03-17 06:55:03
Edit Download
1.70 KB lrw-r--r-- 2026-03-17 06:55:03
Edit Download
3.60 KB lrw-r--r-- 2026-03-17 06:55:03
Edit Download
14.38 KB lrw-r--r-- 2026-03-17 06:55:03
Edit Download
514 B lrw-r--r-- 2026-03-17 06:55:03
Edit Download

If ZipArchive is unavailable, a .tar will be created (no compression).