diff options
author | isaacs <i@izs.me> | 2021-01-29 20:40:03 +0300 |
---|---|---|
committer | isaacs <i@izs.me> | 2021-02-01 23:00:32 +0300 |
commit | a8e77f2b163e64328b12f4a824292cfac097ecea (patch) | |
tree | b54b389d4fc54cddd9c6ec7e0305ca0759bcb3d4 /lib/ci.js | |
parent | 0ea134e4190f322138299c51672eab5387ec41bb (diff) |
wrap a timer around the rimraf call in npm-ciisaacs/ci-rm-timer
Fix: https://github.com/npm/arborist/issues/207
PR-URL: https://github.com/npm/cli/pull/2573
Credit: @isaacs
Close: #2573
Reviewed-by: @nlf
Diffstat (limited to 'lib/ci.js')
-rw-r--r-- | lib/ci.js | 14 |
1 files changed, 13 insertions, 1 deletions
@@ -3,6 +3,8 @@ 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('npmlog') const npm = require('./npm.js') @@ -13,6 +15,16 @@ const completion = require('./utils/completion/none.js') const cmd = (args, cb) => ci().then(() => cb()).catch(cb) +const removeNodeModules = async where => { + const rimrafOpts = { glob: false } + process.emit('time', 'npm-ci:rm') + 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 => []) + await Promise.all(entries.map(f => rimraf(`${path}/${f}`, rimrafOpts))) + process.emit('timeEnd', 'npm-ci:rm') +} + const ci = async () => { if (npm.flatOptions.global) { const err = new Error('`npm ci` does not work for global packages') @@ -33,7 +45,7 @@ const ci = async () => { 'later to generate a package-lock.json file, then try again.' throw new Error(msg) }), - rimraf(`${where}/node_modules/*`, { glob: { dot: true, nosort: true, silent: true } }), + removeNodeModules(where), ]) // npm ci should never modify the lockfile or package.json await arb.reify({ ...npm.flatOptions, save: false }) |