Skip to content

Commit 8c2424f

Browse files
committed
deps: @npmcli/[email protected]
This also removes `readdir-scoped-modules` and `@npmcli/fs` since those are now a part of `@npmcli/fs`
1 parent b8292d8 commit 8c2424f

File tree

12 files changed

+138
-34
lines changed

12 files changed

+138
-34
lines changed

lib/utils/completion/installed-shallow.js

+2-3
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
1-
const { promisify } = require('util')
2-
const readdir = promisify(require('readdir-scoped-modules'))
1+
const { readdirScoped } = require('@npmcli/fs')
32

43
const installedShallow = async (npm, opts) => {
5-
const names = global => readdir(global ? npm.globalDir : npm.localDir)
4+
const names = global => readdirScoped(global ? npm.globalDir : npm.localDir)
65
const { conf: { argv: { remain } } } = opts
76
if (remain.length > 3) {
87
return null

node_modules/@npmcli/fs/lib/index.js

+4
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,12 @@
22

33
const cp = require('./cp/index.js')
44
const withTempDir = require('./with-temp-dir.js')
5+
const readdirScoped = require('./readdir-scoped.js')
6+
const moveFile = require('./move-file.js')
57

68
module.exports = {
79
cp,
810
withTempDir,
11+
readdirScoped,
12+
moveFile,
913
}
+78
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
const { dirname, join, resolve, relative, isAbsolute } = require('path')
2+
const fs = require('fs/promises')
3+
4+
const pathExists = async path => {
5+
try {
6+
await fs.access(path)
7+
return true
8+
} catch (er) {
9+
return er.code !== 'ENOENT'
10+
}
11+
}
12+
13+
const moveFile = async (source, destination, options = {}, root = true, symlinks = []) => {
14+
if (!source || !destination) {
15+
throw new TypeError('`source` and `destination` file required')
16+
}
17+
18+
options = {
19+
overwrite: true,
20+
...options,
21+
}
22+
23+
if (!options.overwrite && await pathExists(destination)) {
24+
throw new Error(`The destination file exists: ${destination}`)
25+
}
26+
27+
await fs.mkdir(dirname(destination), { recursive: true })
28+
29+
try {
30+
await fs.rename(source, destination)
31+
} catch (error) {
32+
if (error.code === 'EXDEV' || error.code === 'EPERM') {
33+
const sourceStat = await fs.lstat(source)
34+
if (sourceStat.isDirectory()) {
35+
const files = await fs.readdir(source)
36+
await Promise.all(files.map((file) =>
37+
moveFile(join(source, file), join(destination, file), options, false, symlinks)
38+
))
39+
} else if (sourceStat.isSymbolicLink()) {
40+
symlinks.push({ source, destination })
41+
} else {
42+
await fs.copyFile(source, destination)
43+
}
44+
} else {
45+
throw error
46+
}
47+
}
48+
49+
if (root) {
50+
await Promise.all(symlinks.map(async ({ source: symSource, destination: symDestination }) => {
51+
let target = await fs.readlink(symSource)
52+
// junction symlinks in windows will be absolute paths, so we need to
53+
// make sure they point to the symlink destination
54+
if (isAbsolute(target)) {
55+
target = resolve(symDestination, relative(symSource, target))
56+
}
57+
// try to determine what the actual file is so we can create the correct
58+
// type of symlink in windows
59+
let targetStat = 'file'
60+
try {
61+
targetStat = await fs.stat(resolve(dirname(symSource), target))
62+
if (targetStat.isDirectory()) {
63+
targetStat = 'junction'
64+
}
65+
} catch {
66+
// targetStat remains 'file'
67+
}
68+
await fs.symlink(
69+
target,
70+
symDestination,
71+
targetStat
72+
)
73+
}))
74+
await fs.rm(source, { recursive: true, force: true })
75+
}
76+
}
77+
78+
module.exports = moveFile
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
const { readdir } = require('fs/promises')
2+
const { join } = require('path')
3+
4+
const readdirScoped = async (dir) => {
5+
const results = []
6+
7+
for (const item of await readdir(dir)) {
8+
if (item.startsWith('@')) {
9+
for (const scopedItem of await readdir(join(dir, item))) {
10+
results.push(join(item, scopedItem))
11+
}
12+
} else {
13+
results.push(item)
14+
}
15+
}
16+
17+
return results
18+
}
19+
20+
module.exports = readdirScoped

node_modules/@npmcli/fs/package.json

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@npmcli/fs",
3-
"version": "3.0.0",
3+
"version": "3.1.0",
44
"description": "filesystem utilities for the npm cli",
55
"main": "lib/index.js",
66
"files": [
@@ -29,8 +29,8 @@
2929
"author": "GitHub Inc.",
3030
"license": "ISC",
3131
"devDependencies": {
32-
"@npmcli/eslint-config": "^3.0.1",
33-
"@npmcli/template-oss": "4.5.1",
32+
"@npmcli/eslint-config": "^4.0.0",
33+
"@npmcli/template-oss": "4.8.0",
3434
"tap": "^16.0.1"
3535
},
3636
"dependencies": {
@@ -41,7 +41,7 @@
4141
},
4242
"templateOSS": {
4343
"//@npmcli/template-oss": "This file is partially managed by @npmcli/template-oss. Edits may be overwritten.",
44-
"version": "4.5.1"
44+
"version": "4.8.0"
4545
},
4646
"tap": {
4747
"nyc-arg": [

package-lock.json

+9-12
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,6 @@
6666
"read",
6767
"read-package-json",
6868
"read-package-json-fast",
69-
"readdir-scoped-modules",
7069
"rimraf",
7170
"semver",
7271
"ssri",
@@ -143,7 +142,6 @@
143142
"read": "~1.0.7",
144143
"read-package-json": "^6.0.0",
145144
"read-package-json-fast": "^3.0.1",
146-
"readdir-scoped-modules": "^1.1.0",
147145
"rimraf": "^3.0.2",
148146
"semver": "^7.3.8",
149147
"ssri": "^10.0.0",
@@ -162,7 +160,7 @@
162160
"devDependencies": {
163161
"@npmcli/docs": "^1.0.0",
164162
"@npmcli/eslint-config": "^4.0.0",
165-
"@npmcli/fs": "^3.0.0",
163+
"@npmcli/fs": "^3.1.0",
166164
"@npmcli/git": "^4.0.1",
167165
"@npmcli/promise-spawn": "^6.0.1",
168166
"@npmcli/template-oss": "4.8.0",
@@ -2106,9 +2104,9 @@
21062104
}
21072105
},
21082106
"node_modules/@npmcli/fs": {
2109-
"version": "3.0.0",
2110-
"resolved": "https://registry.npmjs.org/@npmcli/fs/-/fs-3.0.0.tgz",
2111-
"integrity": "sha512-GdeVD+dnBxzMslTFvnctLX5yIqV4ZNZBWNbo1OejQ++bZpnFNQ1AjOn9Sboi+LzheQbCBU1ts1mhEVduHrcZOQ==",
2107+
"version": "3.1.0",
2108+
"resolved": "https://registry.npmjs.org/@npmcli/fs/-/fs-3.1.0.tgz",
2109+
"integrity": "sha512-7kZUAaLscfgbwBQRbvdMYaZOWyMEcPTH/tJjnyAWJ/dvvs9Ef+CERx/qJb9GExJpl1qipaDGn7KqHnFGGixd0w==",
21122110
"inBundle": true,
21132111
"dependencies": {
21142112
"semver": "^7.3.5"
@@ -2874,7 +2872,7 @@
28742872
},
28752873
"node_modules/asap": {
28762874
"version": "2.0.6",
2877-
"inBundle": true,
2875+
"dev": true,
28782876
"license": "MIT"
28792877
},
28802878
"node_modules/async-hook-domain": {
@@ -3874,7 +3872,7 @@
38743872
},
38753873
"node_modules/debuglog": {
38763874
"version": "1.0.1",
3877-
"inBundle": true,
3875+
"dev": true,
38783876
"license": "MIT",
38793877
"engines": {
38803878
"node": "*"
@@ -4035,7 +4033,7 @@
40354033
},
40364034
"node_modules/dezalgo": {
40374035
"version": "1.0.4",
4038-
"inBundle": true,
4036+
"dev": true,
40394037
"license": "ISC",
40404038
"dependencies": {
40414039
"asap": "^2.0.0",
@@ -10049,7 +10047,7 @@
1004910047
},
1005010048
"node_modules/readdir-scoped-modules": {
1005110049
"version": "1.1.0",
10052-
"inBundle": true,
10050+
"dev": true,
1005310051
"license": "ISC",
1005410052
"dependencies": {
1005510053
"debuglog": "^1.0.1",
@@ -14007,10 +14005,10 @@
1400714005
"license": "ISC",
1400814006
"dependencies": {
1400914007
"@isaacs/string-locale-compare": "^1.1.0",
14008+
"@npmcli/fs": "^3.1.0",
1401014009
"@npmcli/installed-package-contents": "^2.0.0",
1401114010
"@npmcli/map-workspaces": "^3.0.0",
1401214011
"@npmcli/metavuln-calculator": "^5.0.0",
14013-
"@npmcli/move-file": "^3.0.0",
1401414012
"@npmcli/name-from-folder": "^1.0.1",
1401514013
"@npmcli/node-gyp": "^3.0.0",
1401614014
"@npmcli/package-json": "^3.0.0",
@@ -14035,7 +14033,6 @@
1403514033
"promise-all-reject-late": "^1.0.0",
1403614034
"promise-call-limit": "^1.0.1",
1403714035
"read-package-json-fast": "^3.0.1",
14038-
"readdir-scoped-modules": "^1.1.0",
1403914036
"semver": "^7.3.7",
1404014037
"ssri": "^10.0.0",
1404114038
"treeverse": "^3.0.0",

package.json

+1-3
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,6 @@
113113
"read": "~1.0.7",
114114
"read-package-json": "^6.0.0",
115115
"read-package-json-fast": "^3.0.1",
116-
"readdir-scoped-modules": "^1.1.0",
117116
"rimraf": "^3.0.2",
118117
"semver": "^7.3.8",
119118
"ssri": "^10.0.0",
@@ -184,7 +183,6 @@
184183
"read",
185184
"read-package-json",
186185
"read-package-json-fast",
187-
"readdir-scoped-modules",
188186
"rimraf",
189187
"semver",
190188
"ssri",
@@ -199,7 +197,7 @@
199197
"devDependencies": {
200198
"@npmcli/docs": "^1.0.0",
201199
"@npmcli/eslint-config": "^4.0.0",
202-
"@npmcli/fs": "^3.0.0",
200+
"@npmcli/fs": "^3.1.0",
203201
"@npmcli/git": "^4.0.1",
204202
"@npmcli/promise-spawn": "^6.0.1",
205203
"@npmcli/template-oss": "4.8.0",

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

+2-3
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,8 @@ const cacache = require('cacache')
77
const promiseCallLimit = require('promise-call-limit')
88
const realpath = require('../../lib/realpath.js')
99
const { resolve, dirname } = require('path')
10-
const { promisify } = require('util')
1110
const treeCheck = require('../tree-check.js')
12-
const readdir = promisify(require('readdir-scoped-modules'))
11+
const { readdirScoped } = require('@npmcli/fs')
1312
const { lstat, readlink } = require('fs/promises')
1413
const { depth } = require('treeverse')
1514
const log = require('proc-log')
@@ -447,7 +446,7 @@ module.exports = cls => class IdealTreeBuilder extends cls {
447446
const globalExplicitUpdateNames = []
448447
if (this[_global] && (this[_updateAll] || this[_updateNames].length)) {
449448
const nm = resolve(this.path, 'node_modules')
450-
for (const name of await readdir(nm).catch(() => [])) {
449+
for (const name of await readdirScoped(nm).catch(() => [])) {
451450
tree.package.dependencies = tree.package.dependencies || {}
452451
const updateName = this[_updateNames].includes(name)
453452
if (this[_updateAll] || updateName) {

workspaces/arborist/lib/arborist/load-actual.js

+3-4
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,7 @@
33
const { relative, dirname, resolve, join, normalize } = require('path')
44

55
const rpj = require('read-package-json-fast')
6-
const { promisify } = require('util')
7-
const readdir = promisify(require('readdir-scoped-modules'))
6+
const { readdirScoped } = require('@npmcli/fs')
87
const walkUp = require('walk-up-path')
98
const ancestorPath = require('common-ancestor-path')
109
const treeCheck = require('../tree-check.js')
@@ -362,7 +361,7 @@ module.exports = cls => class ActualLoader extends cls {
362361
async [_loadFSChildren] (node) {
363362
const nm = resolve(node.realpath, 'node_modules')
364363
try {
365-
const kids = await readdir(nm)
364+
const kids = await readdirScoped(nm)
366365
return Promise.all(
367366
// ignore . dirs and retired scoped package folders
368367
kids.filter(kid => !/^(@[^/]+\/)?\./.test(kid))
@@ -412,7 +411,7 @@ module.exports = cls => class ActualLoader extends cls {
412411
}
413412

414413
const entries = nmContents.get(p) ||
415-
await readdir(p + '/node_modules').catch(() => [])
414+
await readdirScoped(p + '/node_modules').catch(() => [])
416415
nmContents.set(p, entries)
417416
if (!entries.includes(name)) {
418417
continue

workspaces/arborist/lib/arborist/reify.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ const {
1919
rm,
2020
symlink,
2121
} = require('fs/promises')
22-
const moveFile = require('@npmcli/move-file')
22+
const { moveFile } = require('@npmcli/fs')
2323
const PackageJson = require('@npmcli/package-json')
2424
const packageContents = require('@npmcli/installed-package-contents')
2525
const runScript = require('@npmcli/run-script')

workspaces/arborist/package.json

+1-2
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,10 @@
44
"description": "Manage node_modules trees",
55
"dependencies": {
66
"@isaacs/string-locale-compare": "^1.1.0",
7+
"@npmcli/fs": "^3.1.0",
78
"@npmcli/installed-package-contents": "^2.0.0",
89
"@npmcli/map-workspaces": "^3.0.0",
910
"@npmcli/metavuln-calculator": "^5.0.0",
10-
"@npmcli/move-file": "^3.0.0",
1111
"@npmcli/name-from-folder": "^1.0.1",
1212
"@npmcli/node-gyp": "^3.0.0",
1313
"@npmcli/package-json": "^3.0.0",
@@ -32,7 +32,6 @@
3232
"promise-all-reject-late": "^1.0.0",
3333
"promise-call-limit": "^1.0.1",
3434
"read-package-json-fast": "^3.0.1",
35-
"readdir-scoped-modules": "^1.1.0",
3635
"semver": "^7.3.7",
3736
"ssri": "^10.0.0",
3837
"treeverse": "^3.0.0",

workspaces/arborist/test/arborist/reify.js

+13-2
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,17 @@ const mocks = {
5252

5353
return fs.promises.mkdir(...args)
5454
},
55+
rename: async (...args) => {
56+
if (failRename) {
57+
throw failRename
58+
} else if (failRenameOnce) {
59+
const er = failRenameOnce
60+
failRenameOnce = null
61+
throw er
62+
} else {
63+
return fs.promises.rename(...args)
64+
}
65+
},
5566
rm: async (...args) => {
5667
if (failRm) {
5768
throw new Error('rm fail')
@@ -74,8 +85,8 @@ This is a one-time fix-up, please be patient...
7485
]
7586

7687
// need this to be injected so that it doesn't pull from main cache
77-
const moveFile = t.mock('@npmcli/move-file', { fs: fsMock })
78-
mocks['@npmcli/move-file'] = moveFile
88+
const { moveFile } = t.mock('@npmcli/fs', { 'fs/promises': mocks['fs/promises'] })
89+
mocks['@npmcli/fs'] = { moveFile }
7990

8091
// track the warnings that are emitted. returns a function that removes
8192
// the listener and provides the list of what it saw.

0 commit comments

Comments
 (0)