From 475e9b6c0c978a104dd2ee47bde22b0a031a95f9 Mon Sep 17 00:00:00 2001 From: nlf Date: Mon, 17 Oct 2022 13:26:48 -0700 Subject: feat: do not alter file ownership BREAKING CHANGE: this package no longer attempts to change file ownership automatically --- DEPENDENCIES.md | 3 - package-lock.json | 3 - workspaces/arborist/bin/lib/logging.js | 3 +- workspaces/arborist/docs/reify.md | 2 +- .../arborist/lib/arborist/build-ideal-tree.js | 4 +- workspaces/arborist/lib/arborist/reify.js | 42 +++++----- workspaces/arborist/lib/realpath.js | 5 +- workspaces/arborist/lib/shrinkwrap.js | 34 +++----- workspaces/arborist/package.json | 3 - workspaces/arborist/scripts/benchmark.js | 11 +-- .../arborist/scripts/benchmark/load-actual.js | 12 +-- workspaces/arborist/scripts/benchmark/reify.js | 12 +-- workspaces/arborist/test/arborist/reify.js | 93 ++++++++++++---------- workspaces/arborist/test/arborist/validate-path.js | 2 +- workspaces/arborist/test/shrinkwrap.js | 5 +- 15 files changed, 104 insertions(+), 130 deletions(-) diff --git a/DEPENDENCIES.md b/DEPENDENCIES.md index b65497f47..aa54179c1 100644 --- a/DEPENDENCIES.md +++ b/DEPENDENCIES.md @@ -814,8 +814,6 @@ graph LR; npmcli-arborist-->json-stringify-nice; npmcli-arborist-->minify-registry-metadata; npmcli-arborist-->minimatch; - npmcli-arborist-->mkdirp-infer-owner; - npmcli-arborist-->mkdirp; npmcli-arborist-->nock; npmcli-arborist-->nopt; npmcli-arborist-->npm-install-checks; @@ -841,7 +839,6 @@ graph LR; npmcli-arborist-->promise-call-limit; npmcli-arborist-->read-package-json-fast; npmcli-arborist-->readdir-scoped-modules; - npmcli-arborist-->rimraf; npmcli-arborist-->semver; npmcli-arborist-->ssri; npmcli-arborist-->tap; diff --git a/package-lock.json b/package-lock.json index 367080a4a..f4c108fcd 100644 --- a/package-lock.json +++ b/package-lock.json @@ -13778,8 +13778,6 @@ "json-parse-even-better-errors": "^2.3.1", "json-stringify-nice": "^1.1.4", "minimatch": "^5.1.0", - "mkdirp": "^1.0.4", - "mkdirp-infer-owner": "^2.0.0", "nopt": "^6.0.0", "npm-install-checks": "^5.0.0", "npm-package-arg": "^9.0.0", @@ -13793,7 +13791,6 @@ "promise-call-limit": "^1.0.1", "read-package-json-fast": "^2.0.2", "readdir-scoped-modules": "^1.1.0", - "rimraf": "^3.0.2", "semver": "^7.3.7", "ssri": "^9.0.0", "treeverse": "^2.0.0", diff --git a/workspaces/arborist/bin/lib/logging.js b/workspaces/arborist/bin/lib/logging.js index 8b04d6370..ffb5544b2 100644 --- a/workspaces/arborist/bin/lib/logging.js +++ b/workspaces/arborist/bin/lib/logging.js @@ -1,5 +1,4 @@ const log = require('proc-log') -const mkdirp = require('mkdirp') const fs = require('fs') const { dirname } = require('path') const os = require('os') @@ -70,7 +69,7 @@ if (options.loglevel !== 'silent') { if (options.logfile) { log.silly('logfile', options.logfile) - mkdirp.sync(dirname(options.logfile)) + fs.mkdirSync(dirname(options.logfile), { recursive: true }) const fd = fs.openSync(options.logfile, 'a') addLogListener((str) => fs.writeSync(fd, str)) } diff --git a/workspaces/arborist/docs/reify.md b/workspaces/arborist/docs/reify.md index 15b047267..ac607ef84 100644 --- a/workspaces/arborist/docs/reify.md +++ b/workspaces/arborist/docs/reify.md @@ -87,7 +87,7 @@ Fail: rename each retired `.${name}-hash` folder back to `${name}` ### step 2: create sparse tree -Now that the shallowest changing nodes are retired, `mkdirp` all leaf +Now that the shallowest changing nodes are retired, `mkdir` all leaf nodes. ``` diff --git a/workspaces/arborist/lib/arborist/build-ideal-tree.js b/workspaces/arborist/lib/arborist/build-ideal-tree.js index 4caf310d4..cc873dca9 100644 --- a/workspaces/arborist/lib/arborist/build-ideal-tree.js +++ b/workspaces/arborist/lib/arborist/build-ideal-tree.js @@ -10,9 +10,7 @@ const { resolve, dirname } = require('path') const { promisify } = require('util') const treeCheck = require('../tree-check.js') const readdir = promisify(require('readdir-scoped-modules')) -const fs = require('fs') -const lstat = promisify(fs.lstat) -const readlink = promisify(fs.readlink) +const { lstat, readlink } = require('fs/promises') const { depth } = require('treeverse') const log = require('proc-log') diff --git a/workspaces/arborist/lib/arborist/reify.js b/workspaces/arborist/lib/arborist/reify.js index 82d65daa5..03b5c378d 100644 --- a/workspaces/arborist/lib/arborist/reify.js +++ b/workspaces/arborist/lib/arborist/reify.js @@ -12,14 +12,13 @@ const log = require('proc-log') const { dirname, resolve, relative } = require('path') const { depth: dfwalk } = require('treeverse') -const fs = require('fs') -const { promisify } = require('util') -const lstat = promisify(fs.lstat) -const symlink = promisify(fs.symlink) -const mkdirp = require('mkdirp-infer-owner') -const justMkdirp = require('mkdirp') +const { + lstat, + mkdir, + rm, + symlink, +} = require('fs/promises') const moveFile = require('@npmcli/move-file') -const rimraf = promisify(require('rimraf')) const PackageJson = require('@npmcli/package-json') const packageContents = require('@npmcli/installed-package-contents') const runScript = require('@npmcli/run-script') @@ -175,7 +174,7 @@ module.exports = cls => class Reifier extends cls { // we do NOT want to set ownership on this folder, especially // recursively, because it can have other side effects to do that // in a project directory. We just want to make it if it's missing. - await justMkdirp(resolve(this.path)) + await mkdir(resolve(this.path), { recursive: true }) // do not allow the top-level node_modules to be a symlink await this[_validateNodeModules](resolve(this.path, 'node_modules')) @@ -433,10 +432,10 @@ module.exports = cls => class Reifier extends cls { // handled the most common cause of ENOENT (dir doesn't exist yet), // then just ignore any ENOENT. if (er.code === 'ENOENT') { - return didMkdirp ? null : mkdirp(dirname(to)).then(() => + return didMkdirp ? null : mkdir(dirname(to), { recursive: true }).then(() => this[_renamePath](from, to, true)) } else if (er.code === 'EEXIST') { - return rimraf(to).then(() => moveFile(from, to)) + return rm(to, { recursive: true, force: true }).then(() => moveFile(from, to)) } else { throw er } @@ -518,7 +517,7 @@ module.exports = cls => class Reifier extends cls { await this[_renamePath](d, retired) } } - const made = await mkdirp(node.path) + const made = await mkdir(node.path, { recursive: true }) this[_sparseTreeDirs].add(node.path) this[_sparseTreeRoots].add(made) })) @@ -533,7 +532,7 @@ module.exports = cls => class Reifier extends cls { const failures = [] const targets = [...roots, ...Object.keys(this[_retiredPaths])] const unlinks = targets - .map(path => rimraf(path).catch(er => failures.push([path, er]))) + .map(path => rm(path, { recursive: true, force: true }).catch(er => failures.push([path, er]))) return promiseAllRejectLate(unlinks).then(() => { // eslint-disable-next-line promise/always-return if (failures.length) { @@ -630,7 +629,7 @@ module.exports = cls => class Reifier extends cls { return } log.warn('reify', 'Removing non-directory', nm) - await rimraf(nm) + await rm(nm, { recursive: true, force: true }) } async [_extractOrLink] (node) { @@ -664,7 +663,7 @@ module.exports = cls => class Reifier extends cls { await this[_validateNodeModules](nm) if (node.isLink) { - await rimraf(node.path) + await rm(node.path, { recursive: true, force: true }) await this[_symlink](node) } else { await debug(async () => { @@ -690,7 +689,7 @@ module.exports = cls => class Reifier extends cls { const dir = dirname(node.path) const target = node.realpath const rel = relative(dir, target) - await mkdirp(dir) + await mkdir(dir, { recursive: true }) return symlink(rel, node.path, 'junction') } @@ -953,7 +952,7 @@ module.exports = cls => class Reifier extends cls { // ok! actually unpack stuff into their target locations! // The sparse tree has already been created, so we walk the diff - // kicking off each unpack job. If any fail, we rimraf the sparse + // kicking off each unpack job. If any fail, we rm the sparse // tree entirely and try to put everything back where it was. [_unpackNewModules] () { process.emit('time', 'reify:unpack') @@ -1034,7 +1033,8 @@ module.exports = cls => class Reifier extends cls { return promiseAllRejectLate(diff.unchanged.map(node => { // no need to roll back links, since we'll just delete them anyway if (node.isLink) { - return mkdirp(dirname(node.path)).then(() => this[_reifyNode](node)) + return mkdir(dirname(node.path), { recursive: true, force: true }) + .then(() => this[_reifyNode](node)) } // will have been moved/unpacked along with bundler @@ -1050,7 +1050,7 @@ module.exports = cls => class Reifier extends cls { // skip it. const bd = node.package.bundleDependencies const dir = bd && bd.length ? node.path + '/node_modules' : node.path - return mkdirp(dir).then(() => this[_moveContents](node, fromPath)) + return mkdir(dir, { recursive: true }).then(() => this[_moveContents](node, fromPath)) })) })) .then(() => process.emit('timeEnd', 'reify:unretire')) @@ -1124,15 +1124,15 @@ module.exports = cls => class Reifier extends cls { // the tree is pretty much built now, so it's cleanup time. // remove the retired folders, and any deleted nodes // If this fails, there isn't much we can do but tell the user about it. - // Thankfully, it's pretty unlikely that it'll fail, since rimraf is a tank. + // Thankfully, it's pretty unlikely that it'll fail, since rm is a node builtin. async [_removeTrash] () { process.emit('time', 'reify:trash') const promises = [] const failures = [] - const rm = path => rimraf(path).catch(er => failures.push([path, er])) + const _rm = path => rm(path, { recursive: true, force: true }).catch(er => failures.push([path, er])) for (const path of this[_trashList]) { - promises.push(rm(path)) + promises.push(_rm(path)) } await promiseAllRejectLate(promises) diff --git a/workspaces/arborist/lib/realpath.js b/workspaces/arborist/lib/realpath.js index bc4bbbce3..8dc20ab63 100644 --- a/workspaces/arborist/lib/realpath.js +++ b/workspaces/arborist/lib/realpath.js @@ -5,10 +5,7 @@ // built-in fs.realpath, because we only care about symbolic links, // so we can handle many fewer edge cases. -const fs = require('fs') -const promisify = require('util').promisify -const readlink = promisify(fs.readlink) -const lstat = promisify(fs.lstat) +const { lstat, readlink } = require('fs/promises') const { resolve, basename, dirname } = require('path') const realpathCached = (path, rpcache, stcache, depth) => { diff --git a/workspaces/arborist/lib/shrinkwrap.js b/workspaces/arborist/lib/shrinkwrap.js index 96551990b..a0fda5a4b 100644 --- a/workspaces/arborist/lib/shrinkwrap.js +++ b/workspaces/arborist/lib/shrinkwrap.js @@ -35,30 +35,14 @@ const mismatch = (a, b) => a && b && a !== b const log = require('proc-log') const YarnLock = require('./yarn-lock.js') -const { promisify } = require('util') -const rimraf = promisify(require('rimraf')) -const fs = require('fs') -const readFile = promisify(fs.readFile) -const writeFile = promisify(fs.writeFile) -const stat = promisify(fs.stat) -const readdir_ = promisify(fs.readdir) -const readlink = promisify(fs.readlink) - -// XXX remove when drop support for node v10 -const lstat = promisify(fs.lstat) -/* istanbul ignore next - version specific polyfill */ -const readdir = async (path, opt) => { - if (!opt || !opt.withFileTypes) { - return readdir_(path, opt) - } - const ents = await readdir_(path, opt) - if (typeof ents[0] === 'string') { - return Promise.all(ents.map(async ent => { - return Object.assign(await lstat(path + '/' + ent), { name: ent }) - })) - } - return ents -} +const { + readFile, + readdir, + readlink, + rm, + stat, + writeFile, +} = require('fs/promises') const { resolve, basename, relative } = require('path') const specFromLock = require('./spec-from-lock.js') @@ -1153,7 +1137,7 @@ class Shrinkwrap { // a node_modules folder, but then the lockfile is not important. // Remove the file, so that in case there WERE deps, but we just // failed to update the file for some reason, it's not out of sync. - return rimraf(this.filename) + return rm(this.filename, { recursive: true, force: true }) } throw er }), diff --git a/workspaces/arborist/package.json b/workspaces/arborist/package.json index 271d57a98..4b11b3dff 100644 --- a/workspaces/arborist/package.json +++ b/workspaces/arborist/package.json @@ -19,8 +19,6 @@ "json-parse-even-better-errors": "^2.3.1", "json-stringify-nice": "^1.1.4", "minimatch": "^5.1.0", - "mkdirp": "^1.0.4", - "mkdirp-infer-owner": "^2.0.0", "nopt": "^6.0.0", "npm-install-checks": "^5.0.0", "npm-package-arg": "^9.0.0", @@ -34,7 +32,6 @@ "promise-call-limit": "^1.0.1", "read-package-json-fast": "^2.0.2", "readdir-scoped-modules": "^1.1.0", - "rimraf": "^3.0.2", "semver": "^7.3.7", "ssri": "^9.0.0", "treeverse": "^2.0.0", diff --git a/workspaces/arborist/scripts/benchmark.js b/workspaces/arborist/scripts/benchmark.js index f4d26871b..75f32e329 100644 --- a/workspaces/arborist/scripts/benchmark.js +++ b/workspaces/arborist/scripts/benchmark.js @@ -1,14 +1,13 @@ process.env.ARBORIST_DEBUG = '0' const { Suite } = require('benchmark') const { relative, resolve } = require('path') -const rimraf = require('rimraf') +const { mkdir, rm } = require('fs/promises') const { execSync } = require('child_process') const shaCmd = 'git show --no-patch --pretty=%H HEAD' const dirty = !!String(execSync('git status -s -uno')).trim() const currentSha = String(execSync(shaCmd)).trim() + (dirty ? '-dirty' : '') const { green, red } = require('chalk') const lastBenchmark = resolve(__dirname, 'benchmark/saved/last-benchmark.json') -const mkdirp = require('mkdirp') const { linkSync, writeFileSync, readdirSync } = require('fs') const registryServer = require('../test/fixtures/registry-mocks/server.js') @@ -152,8 +151,8 @@ const suite = new Suite({ }, async onComplete () { - rimraf.sync(lastBenchmark) - mkdirp.sync(resolve(__dirname, 'benchmark/saved')) + await rm(lastBenchmark, { recursive: true, force: true }) + await mkdir(resolve(__dirname, 'benchmark/saved'), { recursive: true }) // always save with sha const saveThis = resolve(__dirname, `benchmark/saved/${this.sha}.json`) const data = JSON.stringify(this.reduce((acc, bench) => { @@ -171,9 +170,7 @@ const suite = new Suite({ await teardown() await Promise.all([ registryServer.stop(), - new Promise((res, rej) => { - rimraf(this.cache, er => er ? rej(er) : res()) - }), + rm(this.cache, { recursive: true, force: true }), ]) }, }) diff --git a/workspaces/arborist/scripts/benchmark/load-actual.js b/workspaces/arborist/scripts/benchmark/load-actual.js index fc15dd24d..6194098fa 100644 --- a/workspaces/arborist/scripts/benchmark/load-actual.js +++ b/workspaces/arborist/scripts/benchmark/load-actual.js @@ -1,14 +1,16 @@ const Arborist = require('../..') const { resolve, basename } = require('path') const { writeFileSync } = require('fs') -const mkdirp = require('mkdirp') +const { + mkdir, + rm, +} = require('fs/promises') const dir = resolve(__dirname, basename(__filename, '.js')) -const rimraf = require('rimraf') const suite = async (suite, { registry, cache }) => { // setup two folders, one with a hidden lockfile, one without - await mkdirp(resolve(dir, 'with-hidden-lockfile')) - await mkdirp(resolve(dir, 'no-hidden-lockfile')) + await mkdir(resolve(dir, 'with-hidden-lockfile'), { recursive: true }) + await mkdir(resolve(dir, 'no-hidden-lockfile'), { recursive: true }) const dependencies = { 'flow-parser': '0.114.0', @@ -43,7 +45,7 @@ const suite = async (suite, { registry, cache }) => { dependencies, })) promises.push(await arb.reify().then(() => - rimraf.sync(resolve(arb.path, 'node_modules', '.package-lock.json')))) + rm(resolve(arb.path, 'node_modules', '.package-lock.json'), { recursive: true, force: true }))) } await Promise.all(promises) diff --git a/workspaces/arborist/scripts/benchmark/reify.js b/workspaces/arborist/scripts/benchmark/reify.js index f477cfbd1..84c7ab4b0 100644 --- a/workspaces/arborist/scripts/benchmark/reify.js +++ b/workspaces/arborist/scripts/benchmark/reify.js @@ -1,9 +1,9 @@ const Arborist = require('../..') const { resolve, basename } = require('path') const { writeFileSync } = require('fs') -const mkdirp = require('mkdirp') +const { mkdir } = require('fs/promises') +const { rmSync } = require('fs') const dir = resolve(__dirname, basename(__filename, '.js')) -const rimraf = require('rimraf') // these are not arbitrary, the empty/full and no-* bits matter const folders = [ @@ -19,7 +19,7 @@ const folders = [ const suite = async (suite, { registry, cache }) => { // setup two folders, one with a hidden lockfile, one without - await Promise.all(folders.map(f => mkdirp(f))) + await Promise.all(folders.map(f => mkdir(f, { recursive: true }))) const dependencies = { 'flow-parser': '0.114.0', @@ -86,13 +86,13 @@ const suite = async (suite, { registry, cache }) => { defer: true, setup () { if (/no-lockfile/.test(path)) { - rimraf.sync(resolve(path, 'package-lock.json')) + rmSync(resolve(path, 'package-lock.json'), { recursive: true, force: true }) } if (/empty/.test(path)) { - rimraf.sync(resolve(path, 'node_modules')) + rmSync(resolve(path, 'node_modules'), { recursive: true, force: true }) } if (/no-cache/.test(path)) { - rimraf.sync(resolve(path, 'cache')) + rmSync(resolve(path, 'cache'), { recursive: true, force: true }) } }, async fn (d) { diff --git a/workspaces/arborist/test/arborist/reify.js b/workspaces/arborist/test/arborist/reify.js index 399031abb..d3c9fa12b 100644 --- a/workspaces/arborist/test/arborist/reify.js +++ b/workspaces/arborist/test/arborist/reify.js @@ -4,36 +4,22 @@ const runScript = require('@npmcli/run-script') const localeCompare = require('@isaacs/string-locale-compare')('en') const tnock = require('../fixtures/tnock') -// mock rimraf so we can make it fail in rollback tests -const realRimraf = require('rimraf') -let failRimraf = false -const rimrafMock = (...args) => { - if (!failRimraf) { - return realRimraf(...args) - } else { - return args.pop()(new Error('rimraf fail')) - } -} -rimrafMock.sync = (...args) => { - if (!failRimraf) { - return realRimraf.sync(...args) - } else { - throw new Error('rimraf fail') - } -} const fs = require('fs') + +let failRm = false let failRename = null let failRenameOnce = null let failMkdir = null -const { rename: realRename, mkdir: realMkdir } = fs +const { rename: realRename, rm: realRm, mkdir: realMkdir } = fs const fsMock = { ...fs, mkdir (...args) { if (failMkdir) { process.nextTick(() => args.pop()(failMkdir)) + return } - realMkdir(...args) + return realMkdir(...args) }, rename (...args) { if (failRename) { @@ -43,13 +29,37 @@ const fsMock = { failRenameOnce = null process.nextTick(() => args.pop()(er)) } else { - realRename(...args) + return realRename(...args) } }, + rm (...args) { + if (failRm) { + process.nextTick(() => args.pop()(new Error('rm fail'))) + return + } + + realRm(...args) + }, } const mocks = { fs: fsMock, - rimraf: rimrafMock, + 'fs/promises': { + ...fs.promises, + mkdir: async (...args) => { + if (failMkdir) { + throw failMkdir + } + + return fs.promises.mkdir(...args) + }, + rm: async (...args) => { + if (failRm) { + throw new Error('rm fail') + } + + return fs.promises.rm(...args) + }, + }, } const oldLockfileWarning = [ @@ -66,10 +76,6 @@ This is a one-time fix-up, please be patient... // need this to be injected so that it doesn't pull from main cache const moveFile = t.mock('@npmcli/move-file', { fs: fsMock }) mocks['@npmcli/move-file'] = moveFile -const mkdirp = t.mock('mkdirp', mocks) -mocks.mkdirp = mkdirp -const mkdirpInferOwner = t.mock('mkdirp-infer-owner', mocks) -mocks['mkdirp-infer-owner'] = mkdirpInferOwner // track the warnings that are emitted. returns a function that removes // the listener and provides the list of what it saw. @@ -430,7 +436,7 @@ t.test('tracks changes of shrinkwrapped dep correctly', async t => { t.match(install2, update2, 'update maintains the same correct tree') // delete a dependency that was installed as part of the shrinkwrap - realRimraf.sync(resolve(path, 'node_modules/@nlf/shrinkwrapped-dep-updates-a/node_modules/@nlf/shrinkwrapped-dep-updates-b')) + fs.rmSync(resolve(path, 'node_modules/@nlf/shrinkwrapped-dep-updates-a/node_modules/@nlf/shrinkwrapped-dep-updates-b'), { recursive: true, force: true }) const repair = await printReified(path) t.match(repair, install2, 'tree got repaired') }) @@ -623,7 +629,7 @@ t.test('rollbacks', { buffered: false }, t => { }), expect).then(() => t.equal(rolledBack, true, 'rolled back')) }) - t.test('fail retiring nodes because rimraf fails after eexist', t => { + t.test('fail retiring nodes because rm fails after eexist', t => { const path = fixture(t, 'testing-bundledeps-3') const a = newArb({ path, legacyBundling: true }) const eexist = new Error('rename fail') @@ -633,7 +639,7 @@ t.test('rollbacks', { buffered: false }, t => { a[kRenamePath] = (from, to) => { a[kRenamePath] = renamePath failRename = eexist - failRimraf = true + failRm = true return a[kRenamePath](from, to) } const kRollback = Symbol.for('rollbackRetireShallowNodes') @@ -642,8 +648,8 @@ t.test('rollbacks', { buffered: false }, t => { a[kRollback] = er => { rolledBack = true failRename = new Error('some other error') - failRimraf = false - t.match(er, new Error('rimraf fail')) + failRm = false + t.match(er, new Error('rm fail')) a[kRollback] = rollbackRetireShallowNodes return a[kRollback](er).then(er => { failRename = null @@ -656,11 +662,11 @@ t.test('rollbacks', { buffered: false }, t => { return t.rejects(a.reify({ update: ['@isaacs/testing-bundledeps-parent'], - }), new Error('rimraf fail')) + }), new Error('rm fail')) .then(() => t.equal(rolledBack, true, 'rolled back')) }) - t.test('fail retiring node, but then rimraf fixes it', t => { + t.test('fail retiring node, but then rm fixes it', async t => { const path = fixture(t, 'testing-bundledeps-3') const a = newArb({ path, legacyBundling: true }) const eexist = new Error('rename fail') @@ -680,10 +686,11 @@ t.test('rollbacks', { buffered: false }, t => { return a[kRollback](er) } - return t.resolveMatchSnapshot(a.reify({ + const tree = await a.reify({ update: ['@isaacs/testing-bundledeps-parent'], save: false, - }).then(printTree)) + }) + return printTree(tree) }) t.test('fail creating sparse tree', t => { @@ -712,7 +719,7 @@ t.test('rollbacks', { buffered: false }, t => { t.test('fail rolling back from creating sparse tree', t => { failMkdir = null - failRimraf = null + failRm = null const path = fixture(t, 'testing-bundledeps-3') const a = newArb({ path, legacyBundling: true }) @@ -722,7 +729,7 @@ t.test('rollbacks', { buffered: false }, t => { a[kRetireShallowNodes] = async () => { a[kRetireShallowNodes] = retireShallowNodes await a[kRetireShallowNodes]() - failRimraf = true + failRm = true } const createSparseTree = a[kCreateST] t.teardown(() => failMkdir = null) @@ -753,11 +760,11 @@ t.test('rollbacks', { buffered: false }, t => { 'warn', 'cleanup', 'Failed to remove some directories', - [[String, new Error('rimraf fail')]], + [[String, new Error('rm fail')]], ], ]) }) - .then(() => failRimraf = false) + .then(() => failRm = false) }) t.test('fail loading shrinkwraps and updating trees', t => { @@ -856,7 +863,7 @@ t.test('rollbacks', { buffered: false }, t => { const kRemove = Symbol.for('removeTrash') const removeRetiredAndDeletedNodes = a[kRemove] a[kRemove] = () => { - failRimraf = true + failRm = true a[kRemove] = removeRetiredAndDeletedNodes return a[kRemove]() } @@ -875,11 +882,11 @@ t.test('rollbacks', { buffered: false }, t => { 'warn', 'cleanup', 'Failed to remove some directories', - [[String, new Error('rimraf fail')]], + [[String, new Error('rm fail')]], ], ]) }) - .then(() => failRimraf = false) + .then(() => failRm = false) }) t.end() @@ -1477,7 +1484,7 @@ t.test('rollback if process is terminated during reify process', async t => { // ensure that we end up with the same thing we started with, // if it was something other than we're installing const a = resolve(path, 'node_modules/abbrev') - mkdirp.sync(a) + fs.mkdirSync(a, { recursive: true }) const pj = resolve(a, 'package.json') fs.writeFileSync(pj, JSON.stringify({ name: 'abbrev', @@ -2337,7 +2344,7 @@ t.test('never unpack into anything other than a real directory', async t => { const wrappy = resolve(path, 'node_modules/once/node_modules/wrappy') arb[kUnpack] = () => { // will have already created it - realRimraf.sync(wrappy) + fs.rmSync(wrappy, { recursive: true, force: true }) const target = resolve(path, 'target') fs.symlinkSync(target, wrappy, 'junction') arb[kUnpack] = unpackNewModules diff --git a/workspaces/arborist/test/arborist/validate-path.js b/workspaces/arborist/test/arborist/validate-path.js index 503e3c094..e5155d27d 100644 --- a/workspaces/arborist/test/arborist/validate-path.js +++ b/workspaces/arborist/test/arborist/validate-path.js @@ -1,4 +1,4 @@ -// Arborist should be mkdirping the path, but not +// Arborist should be mkdir-ing the path, but not // changing its ownership in that case. // https://github.com/npm/arborist/issues/252 // This test has to club a lot of stuff, and provides no coverage, diff --git a/workspaces/arborist/test/shrinkwrap.js b/workspaces/arborist/test/shrinkwrap.js index 28e4167d3..b5303f900 100644 --- a/workspaces/arborist/test/shrinkwrap.js +++ b/workspaces/arborist/test/shrinkwrap.js @@ -4,7 +4,6 @@ const Link = require('../lib/link.js') const calcDepFlags = require('../lib/calc-dep-flags.js') const fs = require('fs') const Arborist = require('../lib/arborist/index.js') -const rimraf = require('rimraf') const t = require('tap') @@ -893,8 +892,8 @@ t.test('hidden lockfile only used if up to date', async t => { // make the lockfile newer, but missing a folder from node_modules { - rimraf.sync(resolve(path, 'node_modules/abbrev')) - rimraf.sync(resolve(path, 'node_modules/xyz')) + fs.rmSync(resolve(path, 'node_modules/abbrev'), { recursive: true, force: true }) + fs.rmSync(resolve(path, 'node_modules/xyz'), { recursive: true, force: true }) const later = Date.now() + 10000 fs.utimesSync(resolve(path, hidden), new Date(later), new Date(later)) const s = await Shrinkwrap.load({ path, hiddenLockfile: true }) -- cgit v1.2.3