diff options
Diffstat (limited to 'workspaces/arborist')
-rw-r--r-- | workspaces/arborist/lib/arborist/build-ideal-tree.js | 6 | ||||
-rw-r--r-- | workspaces/arborist/lib/arborist/load-actual.js | 9 | ||||
-rw-r--r-- | workspaces/arborist/lib/arborist/reify.js | 2 | ||||
-rw-r--r-- | workspaces/arborist/package.json | 3 | ||||
-rw-r--r-- | workspaces/arborist/test/arborist/reify.js | 54 |
5 files changed, 42 insertions, 32 deletions
diff --git a/workspaces/arborist/lib/arborist/build-ideal-tree.js b/workspaces/arborist/lib/arborist/build-ideal-tree.js index afcb67903..d64bdd7e4 100644 --- a/workspaces/arborist/lib/arborist/build-ideal-tree.js +++ b/workspaces/arborist/lib/arborist/build-ideal-tree.js @@ -7,9 +7,8 @@ const cacache = require('cacache') const promiseCallLimit = require('promise-call-limit') const realpath = require('../../lib/realpath.js') const { resolve, dirname } = require('path') -const { promisify } = require('util') const treeCheck = require('../tree-check.js') -const readdir = promisify(require('readdir-scoped-modules')) +const { readdirScoped } = require('@npmcli/fs') const { lstat, readlink } = require('fs/promises') const { depth } = require('treeverse') const log = require('proc-log') @@ -447,7 +446,8 @@ module.exports = cls => class IdealTreeBuilder extends cls { const globalExplicitUpdateNames = [] if (this[_global] && (this[_updateAll] || this[_updateNames].length)) { const nm = resolve(this.path, 'node_modules') - for (const name of await readdir(nm).catch(() => [])) { + const paths = await readdirScoped(nm).catch(() => []) + for (const name of paths.map((p) => p.replace(/\\/g, '/'))) { tree.package.dependencies = tree.package.dependencies || {} const updateName = this[_updateNames].includes(name) if (this[_updateAll] || updateName) { diff --git a/workspaces/arborist/lib/arborist/load-actual.js b/workspaces/arborist/lib/arborist/load-actual.js index bb813806e..6c3f917c6 100644 --- a/workspaces/arborist/lib/arborist/load-actual.js +++ b/workspaces/arborist/lib/arborist/load-actual.js @@ -3,8 +3,7 @@ const { relative, dirname, resolve, join, normalize } = require('path') const rpj = require('read-package-json-fast') -const { promisify } = require('util') -const readdir = promisify(require('readdir-scoped-modules')) +const { readdirScoped } = require('@npmcli/fs') const walkUp = require('walk-up-path') const ancestorPath = require('common-ancestor-path') const treeCheck = require('../tree-check.js') @@ -362,7 +361,7 @@ module.exports = cls => class ActualLoader extends cls { async [_loadFSChildren] (node) { const nm = resolve(node.realpath, 'node_modules') try { - const kids = await readdir(nm) + const kids = await readdirScoped(nm).then(paths => paths.map(p => p.replace(/\\/g, '/'))) return Promise.all( // ignore . dirs and retired scoped package folders kids.filter(kid => !/^(@[^/]+\/)?\./.test(kid)) @@ -411,8 +410,8 @@ module.exports = cls => class ActualLoader extends cls { break } - const entries = nmContents.get(p) || - await readdir(p + '/node_modules').catch(() => []) + const entries = nmContents.get(p) || await readdirScoped(p + '/node_modules') + .catch(() => []).then(paths => paths.map(p => p.replace(/\\/g, '/'))) nmContents.set(p, entries) if (!entries.includes(name)) { continue diff --git a/workspaces/arborist/lib/arborist/reify.js b/workspaces/arborist/lib/arborist/reify.js index c3cbf02b3..36aabd6f0 100644 --- a/workspaces/arborist/lib/arborist/reify.js +++ b/workspaces/arborist/lib/arborist/reify.js @@ -19,7 +19,7 @@ const { rm, symlink, } = require('fs/promises') -const moveFile = require('@npmcli/move-file') +const { moveFile } = require('@npmcli/fs') const PackageJson = require('@npmcli/package-json') const packageContents = require('@npmcli/installed-package-contents') const runScript = require('@npmcli/run-script') diff --git a/workspaces/arborist/package.json b/workspaces/arborist/package.json index d739aa26a..68d0d1e50 100644 --- a/workspaces/arborist/package.json +++ b/workspaces/arborist/package.json @@ -4,10 +4,10 @@ "description": "Manage node_modules trees", "dependencies": { "@isaacs/string-locale-compare": "^1.1.0", + "@npmcli/fs": "^3.1.0", "@npmcli/installed-package-contents": "^2.0.0", "@npmcli/map-workspaces": "^3.0.0", "@npmcli/metavuln-calculator": "^5.0.0", - "@npmcli/move-file": "^3.0.0", "@npmcli/name-from-folder": "^1.0.1", "@npmcli/node-gyp": "^3.0.0", "@npmcli/package-json": "^3.0.0", @@ -32,7 +32,6 @@ "promise-all-reject-late": "^1.0.0", "promise-call-limit": "^1.0.1", "read-package-json-fast": "^3.0.1", - "readdir-scoped-modules": "^1.1.0", "semver": "^7.3.7", "ssri": "^10.0.0", "treeverse": "^3.0.0", diff --git a/workspaces/arborist/test/arborist/reify.js b/workspaces/arborist/test/arborist/reify.js index 257fcb4cb..7c250a34d 100644 --- a/workspaces/arborist/test/arborist/reify.js +++ b/workspaces/arborist/test/arborist/reify.js @@ -3,8 +3,9 @@ const t = require('tap') const runScript = require('@npmcli/run-script') const localeCompare = require('@isaacs/string-locale-compare')('en') const tnock = require('../fixtures/tnock') - const fs = require('fs') +const fsp = require('fs/promises') +const npmFs = require('@npmcli/fs') let failRm = false let failRename = null @@ -41,26 +42,41 @@ const fsMock = { realRm(...args) }, } -const mocks = { - fs: fsMock, - 'fs/promises': { - ...fs.promises, - mkdir: async (...args) => { - if (failMkdir) { - throw failMkdir - } +const fspMock = { + ...fsp, + mkdir: async (...args) => { + if (failMkdir) { + throw failMkdir + } - return fs.promises.mkdir(...args) - }, - rm: async (...args) => { - if (failRm) { - throw new Error('rm fail') - } + return fsp.mkdir(...args) + }, + rename: async (...args) => { + if (failRename) { + throw failRename + } else if (failRenameOnce) { + const er = failRenameOnce + failRenameOnce = null + throw er + } else { + return fsp.rename(...args) + } + }, + rm: async (...args) => { + if (failRm) { + throw new Error('rm fail') + } - return fs.promises.rm(...args) - }, + return fsp.rm(...args) }, } +// need this to be injected so that it doesn't pull from main cache +const { moveFile } = t.mock('@npmcli/fs', { 'fs/promises': fspMock }) +const mocks = { + fs: fsMock, + 'fs/promises': fspMock, + '@npmcli/fs': { ...npmFs, moveFile }, +} const oldLockfileWarning = [ 'warn', @@ -73,10 +89,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 - // track the warnings that are emitted. returns a function that removes // the listener and provides the list of what it saw. const warningTracker = () => { |