Skip to content

Commit 90612f2

Browse files
committed
feat: do not alter file ownership
BREAKING CHANGE: this package no longer attempts to change file ownership automatically
1 parent 32336f6 commit 90612f2

File tree

15 files changed

+104
-130
lines changed

15 files changed

+104
-130
lines changed

DEPENDENCIES.md

-3
Original file line numberDiff line numberDiff line change
@@ -814,8 +814,6 @@ graph LR;
814814
npmcli-arborist-->json-stringify-nice;
815815
npmcli-arborist-->minify-registry-metadata;
816816
npmcli-arborist-->minimatch;
817-
npmcli-arborist-->mkdirp-infer-owner;
818-
npmcli-arborist-->mkdirp;
819817
npmcli-arborist-->nock;
820818
npmcli-arborist-->nopt;
821819
npmcli-arborist-->npm-install-checks;
@@ -841,7 +839,6 @@ graph LR;
841839
npmcli-arborist-->promise-call-limit;
842840
npmcli-arborist-->read-package-json-fast;
843841
npmcli-arborist-->readdir-scoped-modules;
844-
npmcli-arborist-->rimraf;
845842
npmcli-arborist-->semver;
846843
npmcli-arborist-->ssri;
847844
npmcli-arborist-->tap;

package-lock.json

-3
Original file line numberDiff line numberDiff line change
@@ -13778,8 +13778,6 @@
1377813778
"json-parse-even-better-errors": "^2.3.1",
1377913779
"json-stringify-nice": "^1.1.4",
1378013780
"minimatch": "^5.1.0",
13781-
"mkdirp": "^1.0.4",
13782-
"mkdirp-infer-owner": "^2.0.0",
1378313781
"nopt": "^6.0.0",
1378413782
"npm-install-checks": "^5.0.0",
1378513783
"npm-package-arg": "^9.0.0",
@@ -13793,7 +13791,6 @@
1379313791
"promise-call-limit": "^1.0.1",
1379413792
"read-package-json-fast": "^2.0.2",
1379513793
"readdir-scoped-modules": "^1.1.0",
13796-
"rimraf": "^3.0.2",
1379713794
"semver": "^7.3.7",
1379813795
"ssri": "^9.0.0",
1379913796
"treeverse": "^2.0.0",

workspaces/arborist/bin/lib/logging.js

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
const log = require('proc-log')
2-
const mkdirp = require('mkdirp')
32
const fs = require('fs')
43
const { dirname } = require('path')
54
const os = require('os')
@@ -70,7 +69,7 @@ if (options.loglevel !== 'silent') {
7069

7170
if (options.logfile) {
7271
log.silly('logfile', options.logfile)
73-
mkdirp.sync(dirname(options.logfile))
72+
fs.mkdirSync(dirname(options.logfile), { recursive: true })
7473
const fd = fs.openSync(options.logfile, 'a')
7574
addLogListener((str) => fs.writeSync(fd, str))
7675
}

workspaces/arborist/docs/reify.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ Fail: rename each retired `.${name}-hash` folder back to `${name}`
8787

8888
### step 2: create sparse tree
8989

90-
Now that the shallowest changing nodes are retired, `mkdirp` all leaf
90+
Now that the shallowest changing nodes are retired, `mkdir` all leaf
9191
nodes.
9292

9393
```

workspaces/arborist/lib/arborist/build-ideal-tree.js

+1-3
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,7 @@ const { resolve, dirname } = require('path')
1010
const { promisify } = require('util')
1111
const treeCheck = require('../tree-check.js')
1212
const readdir = promisify(require('readdir-scoped-modules'))
13-
const fs = require('fs')
14-
const lstat = promisify(fs.lstat)
15-
const readlink = promisify(fs.readlink)
13+
const { lstat, readlink } = require('fs/promises')
1614
const { depth } = require('treeverse')
1715
const log = require('proc-log')
1816

workspaces/arborist/lib/arborist/reify.js

+21-21
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,13 @@ const log = require('proc-log')
1212

1313
const { dirname, resolve, relative } = require('path')
1414
const { depth: dfwalk } = require('treeverse')
15-
const fs = require('fs')
16-
const { promisify } = require('util')
17-
const lstat = promisify(fs.lstat)
18-
const symlink = promisify(fs.symlink)
19-
const mkdirp = require('mkdirp-infer-owner')
20-
const justMkdirp = require('mkdirp')
15+
const {
16+
lstat,
17+
mkdir,
18+
rm,
19+
symlink,
20+
} = require('fs/promises')
2121
const moveFile = require('@npmcli/move-file')
22-
const rimraf = promisify(require('rimraf'))
2322
const PackageJson = require('@npmcli/package-json')
2423
const packageContents = require('@npmcli/installed-package-contents')
2524
const runScript = require('@npmcli/run-script')
@@ -175,7 +174,7 @@ module.exports = cls => class Reifier extends cls {
175174
// we do NOT want to set ownership on this folder, especially
176175
// recursively, because it can have other side effects to do that
177176
// in a project directory. We just want to make it if it's missing.
178-
await justMkdirp(resolve(this.path))
177+
await mkdir(resolve(this.path), { recursive: true })
179178

180179
// do not allow the top-level node_modules to be a symlink
181180
await this[_validateNodeModules](resolve(this.path, 'node_modules'))
@@ -433,10 +432,10 @@ module.exports = cls => class Reifier extends cls {
433432
// handled the most common cause of ENOENT (dir doesn't exist yet),
434433
// then just ignore any ENOENT.
435434
if (er.code === 'ENOENT') {
436-
return didMkdirp ? null : mkdirp(dirname(to)).then(() =>
435+
return didMkdirp ? null : mkdir(dirname(to), { recursive: true }).then(() =>
437436
this[_renamePath](from, to, true))
438437
} else if (er.code === 'EEXIST') {
439-
return rimraf(to).then(() => moveFile(from, to))
438+
return rm(to, { recursive: true, force: true }).then(() => moveFile(from, to))
440439
} else {
441440
throw er
442441
}
@@ -518,7 +517,7 @@ module.exports = cls => class Reifier extends cls {
518517
await this[_renamePath](d, retired)
519518
}
520519
}
521-
const made = await mkdirp(node.path)
520+
const made = await mkdir(node.path, { recursive: true })
522521
this[_sparseTreeDirs].add(node.path)
523522
this[_sparseTreeRoots].add(made)
524523
}))
@@ -533,7 +532,7 @@ module.exports = cls => class Reifier extends cls {
533532
const failures = []
534533
const targets = [...roots, ...Object.keys(this[_retiredPaths])]
535534
const unlinks = targets
536-
.map(path => rimraf(path).catch(er => failures.push([path, er])))
535+
.map(path => rm(path, { recursive: true, force: true }).catch(er => failures.push([path, er])))
537536
return promiseAllRejectLate(unlinks).then(() => {
538537
// eslint-disable-next-line promise/always-return
539538
if (failures.length) {
@@ -630,7 +629,7 @@ module.exports = cls => class Reifier extends cls {
630629
return
631630
}
632631
log.warn('reify', 'Removing non-directory', nm)
633-
await rimraf(nm)
632+
await rm(nm, { recursive: true, force: true })
634633
}
635634

636635
async [_extractOrLink] (node) {
@@ -664,7 +663,7 @@ module.exports = cls => class Reifier extends cls {
664663
await this[_validateNodeModules](nm)
665664

666665
if (node.isLink) {
667-
await rimraf(node.path)
666+
await rm(node.path, { recursive: true, force: true })
668667
await this[_symlink](node)
669668
} else {
670669
await debug(async () => {
@@ -690,7 +689,7 @@ module.exports = cls => class Reifier extends cls {
690689
const dir = dirname(node.path)
691690
const target = node.realpath
692691
const rel = relative(dir, target)
693-
await mkdirp(dir)
692+
await mkdir(dir, { recursive: true })
694693
return symlink(rel, node.path, 'junction')
695694
}
696695

@@ -953,7 +952,7 @@ module.exports = cls => class Reifier extends cls {
953952

954953
// ok! actually unpack stuff into their target locations!
955954
// The sparse tree has already been created, so we walk the diff
956-
// kicking off each unpack job. If any fail, we rimraf the sparse
955+
// kicking off each unpack job. If any fail, we rm the sparse
957956
// tree entirely and try to put everything back where it was.
958957
[_unpackNewModules] () {
959958
process.emit('time', 'reify:unpack')
@@ -1034,7 +1033,8 @@ module.exports = cls => class Reifier extends cls {
10341033
return promiseAllRejectLate(diff.unchanged.map(node => {
10351034
// no need to roll back links, since we'll just delete them anyway
10361035
if (node.isLink) {
1037-
return mkdirp(dirname(node.path)).then(() => this[_reifyNode](node))
1036+
return mkdir(dirname(node.path), { recursive: true, force: true })
1037+
.then(() => this[_reifyNode](node))
10381038
}
10391039

10401040
// will have been moved/unpacked along with bundler
@@ -1050,7 +1050,7 @@ module.exports = cls => class Reifier extends cls {
10501050
// skip it.
10511051
const bd = node.package.bundleDependencies
10521052
const dir = bd && bd.length ? node.path + '/node_modules' : node.path
1053-
return mkdirp(dir).then(() => this[_moveContents](node, fromPath))
1053+
return mkdir(dir, { recursive: true }).then(() => this[_moveContents](node, fromPath))
10541054
}))
10551055
}))
10561056
.then(() => process.emit('timeEnd', 'reify:unretire'))
@@ -1124,15 +1124,15 @@ module.exports = cls => class Reifier extends cls {
11241124
// the tree is pretty much built now, so it's cleanup time.
11251125
// remove the retired folders, and any deleted nodes
11261126
// If this fails, there isn't much we can do but tell the user about it.
1127-
// Thankfully, it's pretty unlikely that it'll fail, since rimraf is a tank.
1127+
// Thankfully, it's pretty unlikely that it'll fail, since rm is a node builtin.
11281128
async [_removeTrash] () {
11291129
process.emit('time', 'reify:trash')
11301130
const promises = []
11311131
const failures = []
1132-
const rm = path => rimraf(path).catch(er => failures.push([path, er]))
1132+
const _rm = path => rm(path, { recursive: true, force: true }).catch(er => failures.push([path, er]))
11331133

11341134
for (const path of this[_trashList]) {
1135-
promises.push(rm(path))
1135+
promises.push(_rm(path))
11361136
}
11371137

11381138
await promiseAllRejectLate(promises)

workspaces/arborist/lib/realpath.js

+1-4
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,7 @@
55
// built-in fs.realpath, because we only care about symbolic links,
66
// so we can handle many fewer edge cases.
77

8-
const fs = require('fs')
9-
const promisify = require('util').promisify
10-
const readlink = promisify(fs.readlink)
11-
const lstat = promisify(fs.lstat)
8+
const { lstat, readlink } = require('fs/promises')
129
const { resolve, basename, dirname } = require('path')
1310

1411
const realpathCached = (path, rpcache, stcache, depth) => {

workspaces/arborist/lib/shrinkwrap.js

+9-25
Original file line numberDiff line numberDiff line change
@@ -35,30 +35,14 @@ const mismatch = (a, b) => a && b && a !== b
3535

3636
const log = require('proc-log')
3737
const YarnLock = require('./yarn-lock.js')
38-
const { promisify } = require('util')
39-
const rimraf = promisify(require('rimraf'))
40-
const fs = require('fs')
41-
const readFile = promisify(fs.readFile)
42-
const writeFile = promisify(fs.writeFile)
43-
const stat = promisify(fs.stat)
44-
const readdir_ = promisify(fs.readdir)
45-
const readlink = promisify(fs.readlink)
46-
47-
// XXX remove when drop support for node v10
48-
const lstat = promisify(fs.lstat)
49-
/* istanbul ignore next - version specific polyfill */
50-
const readdir = async (path, opt) => {
51-
if (!opt || !opt.withFileTypes) {
52-
return readdir_(path, opt)
53-
}
54-
const ents = await readdir_(path, opt)
55-
if (typeof ents[0] === 'string') {
56-
return Promise.all(ents.map(async ent => {
57-
return Object.assign(await lstat(path + '/' + ent), { name: ent })
58-
}))
59-
}
60-
return ents
61-
}
38+
const {
39+
readFile,
40+
readdir,
41+
readlink,
42+
rm,
43+
stat,
44+
writeFile,
45+
} = require('fs/promises')
6246

6347
const { resolve, basename, relative } = require('path')
6448
const specFromLock = require('./spec-from-lock.js')
@@ -1153,7 +1137,7 @@ class Shrinkwrap {
11531137
// a node_modules folder, but then the lockfile is not important.
11541138
// Remove the file, so that in case there WERE deps, but we just
11551139
// failed to update the file for some reason, it's not out of sync.
1156-
return rimraf(this.filename)
1140+
return rm(this.filename, { recursive: true, force: true })
11571141
}
11581142
throw er
11591143
}),

workspaces/arborist/package.json

-3
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,6 @@
1919
"json-parse-even-better-errors": "^2.3.1",
2020
"json-stringify-nice": "^1.1.4",
2121
"minimatch": "^5.1.0",
22-
"mkdirp": "^1.0.4",
23-
"mkdirp-infer-owner": "^2.0.0",
2422
"nopt": "^6.0.0",
2523
"npm-install-checks": "^5.0.0",
2624
"npm-package-arg": "^9.0.0",
@@ -34,7 +32,6 @@
3432
"promise-call-limit": "^1.0.1",
3533
"read-package-json-fast": "^2.0.2",
3634
"readdir-scoped-modules": "^1.1.0",
37-
"rimraf": "^3.0.2",
3835
"semver": "^7.3.7",
3936
"ssri": "^9.0.0",
4037
"treeverse": "^2.0.0",

workspaces/arborist/scripts/benchmark.js

+4-7
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,13 @@
11
process.env.ARBORIST_DEBUG = '0'
22
const { Suite } = require('benchmark')
33
const { relative, resolve } = require('path')
4-
const rimraf = require('rimraf')
4+
const { mkdir, rm } = require('fs/promises')
55
const { execSync } = require('child_process')
66
const shaCmd = 'git show --no-patch --pretty=%H HEAD'
77
const dirty = !!String(execSync('git status -s -uno')).trim()
88
const currentSha = String(execSync(shaCmd)).trim() + (dirty ? '-dirty' : '')
99
const { green, red } = require('chalk')
1010
const lastBenchmark = resolve(__dirname, 'benchmark/saved/last-benchmark.json')
11-
const mkdirp = require('mkdirp')
1211
const { linkSync, writeFileSync, readdirSync } = require('fs')
1312
const registryServer = require('../test/fixtures/registry-mocks/server.js')
1413

@@ -152,8 +151,8 @@ const suite = new Suite({
152151
},
153152

154153
async onComplete () {
155-
rimraf.sync(lastBenchmark)
156-
mkdirp.sync(resolve(__dirname, 'benchmark/saved'))
154+
await rm(lastBenchmark, { recursive: true, force: true })
155+
await mkdir(resolve(__dirname, 'benchmark/saved'), { recursive: true })
157156
// always save with sha
158157
const saveThis = resolve(__dirname, `benchmark/saved/${this.sha}.json`)
159158
const data = JSON.stringify(this.reduce((acc, bench) => {
@@ -171,9 +170,7 @@ const suite = new Suite({
171170
await teardown()
172171
await Promise.all([
173172
registryServer.stop(),
174-
new Promise((res, rej) => {
175-
rimraf(this.cache, er => er ? rej(er) : res())
176-
}),
173+
rm(this.cache, { recursive: true, force: true }),
177174
])
178175
},
179176
})

workspaces/arborist/scripts/benchmark/load-actual.js

+7-5
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,16 @@
11
const Arborist = require('../..')
22
const { resolve, basename } = require('path')
33
const { writeFileSync } = require('fs')
4-
const mkdirp = require('mkdirp')
4+
const {
5+
mkdir,
6+
rm,
7+
} = require('fs/promises')
58
const dir = resolve(__dirname, basename(__filename, '.js'))
6-
const rimraf = require('rimraf')
79

810
const suite = async (suite, { registry, cache }) => {
911
// setup two folders, one with a hidden lockfile, one without
10-
await mkdirp(resolve(dir, 'with-hidden-lockfile'))
11-
await mkdirp(resolve(dir, 'no-hidden-lockfile'))
12+
await mkdir(resolve(dir, 'with-hidden-lockfile'), { recursive: true })
13+
await mkdir(resolve(dir, 'no-hidden-lockfile'), { recursive: true })
1214

1315
const dependencies = {
1416
'flow-parser': '0.114.0',
@@ -43,7 +45,7 @@ const suite = async (suite, { registry, cache }) => {
4345
dependencies,
4446
}))
4547
promises.push(await arb.reify().then(() =>
46-
rimraf.sync(resolve(arb.path, 'node_modules', '.package-lock.json'))))
48+
rm(resolve(arb.path, 'node_modules', '.package-lock.json'), { recursive: true, force: true })))
4749
}
4850
await Promise.all(promises)
4951

workspaces/arborist/scripts/benchmark/reify.js

+6-6
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
const Arborist = require('../..')
22
const { resolve, basename } = require('path')
33
const { writeFileSync } = require('fs')
4-
const mkdirp = require('mkdirp')
4+
const { mkdir } = require('fs/promises')
5+
const { rmSync } = require('fs')
56
const dir = resolve(__dirname, basename(__filename, '.js'))
6-
const rimraf = require('rimraf')
77

88
// these are not arbitrary, the empty/full and no-* bits matter
99
const folders = [
@@ -19,7 +19,7 @@ const folders = [
1919

2020
const suite = async (suite, { registry, cache }) => {
2121
// setup two folders, one with a hidden lockfile, one without
22-
await Promise.all(folders.map(f => mkdirp(f)))
22+
await Promise.all(folders.map(f => mkdir(f, { recursive: true })))
2323

2424
const dependencies = {
2525
'flow-parser': '0.114.0',
@@ -86,13 +86,13 @@ const suite = async (suite, { registry, cache }) => {
8686
defer: true,
8787
setup () {
8888
if (/no-lockfile/.test(path)) {
89-
rimraf.sync(resolve(path, 'package-lock.json'))
89+
rmSync(resolve(path, 'package-lock.json'), { recursive: true, force: true })
9090
}
9191
if (/empty/.test(path)) {
92-
rimraf.sync(resolve(path, 'node_modules'))
92+
rmSync(resolve(path, 'node_modules'), { recursive: true, force: true })
9393
}
9494
if (/no-cache/.test(path)) {
95-
rimraf.sync(resolve(path, 'cache'))
95+
rmSync(resolve(path, 'cache'), { recursive: true, force: true })
9696
}
9797
},
9898
async fn (d) {

0 commit comments

Comments
 (0)