diff --git a/node_modules/@npmcli/map-workspaces/lib/index.js b/node_modules/@npmcli/map-workspaces/lib/index.js index 501dad870a2b7..b20bf5de5d631 100644 --- a/node_modules/@npmcli/map-workspaces/lib/index.js +++ b/node_modules/@npmcli/map-workspaces/lib/index.js @@ -5,23 +5,49 @@ const { minimatch } = require('minimatch') const rpj = require('read-package-json-fast') const { glob } = require('glob') -function appendNegatedPatterns (patterns) { - const results = [] - for (let pattern of patterns) { +function appendNegatedPatterns (allPatterns) { + const patterns = [] + const negatedPatterns = [] + for (let pattern of allPatterns) { const excl = pattern.match(/^!+/) if (excl) { pattern = pattern.slice(excl[0].length) } - // strip off any / from the start of the pattern. /foo => foo - pattern = pattern.replace(/^\/+/, '') + // strip off any / or ./ from the start of the pattern. /foo => foo + pattern = pattern.replace(/^\.?\/+/, '') // an odd number of ! means a negated pattern. !!foo ==> foo const negate = excl && excl[0].length % 2 === 1 - results.push({ pattern, negate }) + if (negate) { + negatedPatterns.push(pattern) + } else { + // remove negated patterns that appeared before this pattern to avoid + // ignoring paths that were matched afterwards + // e.g: ['packages/**', '!packages/b/**', 'packages/b/a'] + // in the above list, the last pattern overrides the negated pattern + // right before it. In effect, the above list would become: + // ['packages/**', 'packages/b/a'] + // The order matters here which is why we must do it inside the loop + // as opposed to doing it all together at the end. + for (let i = 0; i < negatedPatterns.length; ++i) { + const negatedPattern = negatedPatterns[i] + if (minimatch(pattern, negatedPattern)) { + negatedPatterns.splice(i, 1) + } + } + patterns.push(pattern) + } } - return results + // use the negated patterns to eagerly remove all the patterns that + // can be removed to avoid unnecessary crawling + for (const negated of negatedPatterns) { + for (const pattern of minimatch.match(patterns, negated)) { + patterns.splice(patterns.indexOf(pattern), 1) + } + } + return { patterns, negatedPatterns } } function getPatterns (workspaces) { @@ -77,11 +103,11 @@ async function mapWorkspaces (opts = {}) { } const { workspaces = [] } = opts.pkg - const patterns = getPatterns(workspaces) + const { patterns, negatedPatterns } = getPatterns(workspaces) const results = new Map() const seen = new Map() - if (!patterns.length) { + if (!patterns.length && !negatedPatterns.length) { return results } @@ -89,52 +115,54 @@ async function mapWorkspaces (opts = {}) { ...opts, ignore: [ ...opts.ignore || [], - ...['**/node_modules/**'], + '**/node_modules/**', + // just ignore the negated patterns to avoid unnecessary crawling + ...negatedPatterns, ], }) const getPackagePathname = pkgPathmame(opts) - for (const item of patterns) { - let matches = await glob(getGlobPattern(item.pattern), getGlobOpts()) - // preserves glob@8 behavior - matches = matches.sort((a, b) => a.localeCompare(b, 'en')) - - for (const match of matches) { - let pkg - const packageJsonPathname = getPackagePathname(match, 'package.json') - const packagePathname = path.dirname(packageJsonPathname) - - try { - pkg = await rpj(packageJsonPathname) - } catch (err) { - if (err.code === 'ENOENT') { - continue - } else { - throw err - } - } + let matches = await glob(patterns.map((p) => getGlobPattern(p)), getGlobOpts()) + // preserves glob@8 behavior + matches = matches.sort((a, b) => a.localeCompare(b, 'en')) + + // we must preserve the order of results according to the given list of + // workspace patterns + const orderedMatches = [] + for (const pattern of patterns) { + orderedMatches.push(...matches.filter((m) => { + return minimatch(m, pattern, { partial: true, windowsPathsNoEscape: true }) + })) + } - const name = getPackageName(pkg, packagePathname) + for (const match of orderedMatches) { + let pkg + const packageJsonPathname = getPackagePathname(match, 'package.json') - let seenPackagePathnames = seen.get(name) - if (!seenPackagePathnames) { - seenPackagePathnames = new Set() - seen.set(name, seenPackagePathnames) - } - if (item.negate) { - seenPackagePathnames.delete(packagePathname) + try { + pkg = await rpj(packageJsonPathname) + } catch (err) { + if (err.code === 'ENOENT') { + continue } else { - seenPackagePathnames.add(packagePathname) + throw err } } + + const packagePathname = path.dirname(packageJsonPathname) + const name = getPackageName(pkg, packagePathname) + + let seenPackagePathnames = seen.get(name) + if (!seenPackagePathnames) { + seenPackagePathnames = new Set() + seen.set(name, seenPackagePathnames) + } + seenPackagePathnames.add(packagePathname) } const errorMessageArray = ['must not have multiple workspaces with the same name'] for (const [packageName, seenPackagePathnames] of seen) { - if (seenPackagePathnames.size === 0) { - continue - } if (seenPackagePathnames.size > 1) { addDuplicateErrorMessages(errorMessageArray, packageName, seenPackagePathnames) } else { @@ -177,30 +205,25 @@ mapWorkspaces.virtual = function (opts = {}) { const { workspaces = [] } = packages[''] || {} // uses a pathname-keyed map in order to negate the exact items const results = new Map() - const patterns = getPatterns(workspaces) - if (!patterns.length) { + const { patterns, negatedPatterns } = getPatterns(workspaces) + if (!patterns.length && !negatedPatterns.length) { return results } - patterns.push({ pattern: '**/node_modules/**', negate: true }) - - const getPackagePathname = pkgPathmame(opts) + negatedPatterns.push('**/node_modules/**') - for (const packageKey of Object.keys(packages)) { - if (packageKey === '') { - continue + const packageKeys = Object.keys(packages) + for (const pattern of negatedPatterns) { + for (const packageKey of minimatch.match(packageKeys, pattern)) { + packageKeys.splice(packageKeys.indexOf(packageKey), 1) } + } - for (const item of patterns) { - if (minimatch(packageKey, item.pattern)) { - const packagePathname = getPackagePathname(packageKey) - const name = getPackageName(packages[packageKey], packagePathname) - - if (item.negate) { - results.delete(packagePathname) - } else { - results.set(packagePathname, name) - } - } + const getPackagePathname = pkgPathmame(opts) + for (const pattern of patterns) { + for (const packageKey of minimatch.match(packageKeys, pattern)) { + const packagePathname = getPackagePathname(packageKey) + const name = getPackageName(packages[packageKey], packagePathname) + results.set(packagePathname, name) } } diff --git a/node_modules/@npmcli/map-workspaces/package.json b/node_modules/@npmcli/map-workspaces/package.json index 64cb7f9d3f117..e6292b06bd2b4 100644 --- a/node_modules/@npmcli/map-workspaces/package.json +++ b/node_modules/@npmcli/map-workspaces/package.json @@ -1,6 +1,6 @@ { "name": "@npmcli/map-workspaces", - "version": "3.0.4", + "version": "3.0.6", "main": "lib/index.js", "files": [ "bin/", @@ -25,7 +25,7 @@ "author": "GitHub Inc.", "license": "ISC", "scripts": { - "lint": "eslint \"**/*.js\"", + "lint": "eslint \"**/*.{js,cjs,ts,mjs,jsx,tsx}\"", "pretest": "npm run lint", "test": "tap", "snap": "tap", @@ -43,7 +43,7 @@ }, "devDependencies": { "@npmcli/eslint-config": "^4.0.0", - "@npmcli/template-oss": "4.14.1", + "@npmcli/template-oss": "4.21.3", "tap": "^16.0.1" }, "dependencies": { @@ -54,7 +54,7 @@ }, "templateOSS": { "//@npmcli/template-oss": "This file is partially managed by @npmcli/template-oss. Edits may be overwritten.", - "version": "4.14.1", + "version": "4.21.3", "publish": "true" } } diff --git a/node_modules/@npmcli/package-json/lib/normalize.js b/node_modules/@npmcli/package-json/lib/normalize.js index 0c7dc80ef9d1c..350b3f3d7cb8f 100644 --- a/node_modules/@npmcli/package-json/lib/normalize.js +++ b/node_modules/@npmcli/package-json/lib/normalize.js @@ -1,10 +1,30 @@ const valid = require('semver/functions/valid') const clean = require('semver/functions/clean') const fs = require('fs/promises') -const { glob } = require('glob') const path = require('path') const log = require('proc-log') -const hostedGitInfo = require('hosted-git-info') + +/** + * @type {import('hosted-git-info')} + */ +let _hostedGitInfo +function lazyHostedGitInfo () { + if (!_hostedGitInfo) { + _hostedGitInfo = require('hosted-git-info') + } + return _hostedGitInfo +} + +/** + * @type {import('glob').glob} + */ +let _glob +function lazyLoadGlob () { + if (!_glob) { + _glob = require('glob').glob + } + return _glob +} // used to be npm-normalize-package-bin function normalizePackageBin (pkg, changes) { @@ -206,7 +226,7 @@ const normalize = async (pkg, { strict, steps, root, changes, allowLegacyCase }) // add "install" attribute if any "*.gyp" files exist if (steps.includes('gypfile')) { if (!scripts.install && !scripts.preinstall && data.gypfile !== false) { - const files = await glob('*.gyp', { cwd: pkg.path }) + const files = await lazyLoadGlob()('*.gyp', { cwd: pkg.path }) if (files.length) { scripts.install = 'node-gyp rebuild' data.scripts = scripts @@ -273,7 +293,11 @@ const normalize = async (pkg, { strict, steps, root, changes, allowLegacyCase }) // populate "readme" attribute if (steps.includes('readme') && !data.readme) { const mdre = /\.m?a?r?k?d?o?w?n?$/i - const files = await glob('{README,README.*}', { cwd: pkg.path, nocase: true, mark: true }) + const files = await lazyLoadGlob()('{README,README.*}', { + cwd: pkg.path, + nocase: true, + mark: true, + }) let readmeFile for (const file of files) { // don't accept directories. @@ -304,7 +328,7 @@ const normalize = async (pkg, { strict, steps, root, changes, allowLegacyCase }) if (steps.includes('mans') && !data.man && data.directories?.man) { const manDir = data.directories.man const cwd = path.resolve(pkg.path, manDir) - const files = await glob('**/*.[0-9]', { cwd }) + const files = await lazyLoadGlob()('**/*.[0-9]', { cwd }) data.man = files.map(man => path.relative(pkg.path, path.join(cwd, man)).split(path.sep).join('/') ) @@ -317,7 +341,7 @@ const normalize = async (pkg, { strict, steps, root, changes, allowLegacyCase }) // expand "directories.bin" if (steps.includes('binDir') && data.directories?.bin && !data.bin) { const binsDir = path.resolve(pkg.path, path.join('.', path.join('/', data.directories.bin))) - const bins = await glob('**', { cwd: binsDir }) + const bins = await lazyLoadGlob()('**', { cwd: binsDir }) data.bin = bins.reduce((acc, binFile) => { if (binFile && !binFile.startsWith('.')) { const binName = path.basename(binFile) @@ -445,7 +469,7 @@ const normalize = async (pkg, { strict, steps, root, changes, allowLegacyCase }) } } if (data.repository.url) { - const hosted = hostedGitInfo.fromUrl(data.repository.url) + const hosted = lazyHostedGitInfo().fromUrl(data.repository.url) let r if (hosted) { if (hosted.getDefaultRepresentation() === 'shortcut') { @@ -505,7 +529,7 @@ const normalize = async (pkg, { strict, steps, root, changes, allowLegacyCase }) changes?.push(`Removed invalid "${deps}.${d}"`) delete data[deps][d] } - const hosted = hostedGitInfo.fromUrl(data[deps][d])?.toString() + const hosted = lazyHostedGitInfo().fromUrl(data[deps][d])?.toString() if (hosted && hosted !== data[deps][d]) { changes?.push(`Normalized git reference to "${deps}.${d}"`) data[deps][d] = hosted.toString() diff --git a/node_modules/@npmcli/package-json/package.json b/node_modules/@npmcli/package-json/package.json index 0632b175308ed..4f7a29d2e4c59 100644 --- a/node_modules/@npmcli/package-json/package.json +++ b/node_modules/@npmcli/package-json/package.json @@ -1,6 +1,6 @@ { "name": "@npmcli/package-json", - "version": "5.0.1", + "version": "5.0.2", "description": "Programmatic API to update package.json", "main": "lib/index.js", "files": [ diff --git a/node_modules/socks/build/common/helpers.js b/node_modules/socks/build/common/helpers.js index 65bd95bdc6221..1ae44e4159a15 100644 --- a/node_modules/socks/build/common/helpers.js +++ b/node_modules/socks/build/common/helpers.js @@ -152,7 +152,11 @@ function ipToBuffer(ip) { else if (net.isIPv6(ip)) { // Handle IPv6 addresses const address = new ip_address_1.Address6(ip); - return Buffer.from(address.toByteArray()); + return Buffer.from(address + .canonicalForm() + .split(':') + .map((segment) => segment.padStart(4, '0')) + .join(''), 'hex'); } else { throw new Error('Invalid IP address format'); diff --git a/node_modules/socks/package.json b/node_modules/socks/package.json index 2c89eb578b47b..5cc2a6836072e 100644 --- a/node_modules/socks/package.json +++ b/node_modules/socks/package.json @@ -1,7 +1,7 @@ { "name": "socks", "private": false, - "version": "2.8.2", + "version": "2.8.3", "description": "Fully featured SOCKS proxy client supporting SOCKSv4, SOCKSv4a, and SOCKSv5. Includes Bind and Associate functionality.", "main": "build/index.js", "typings": "typings/index.d.ts", diff --git a/package-lock.json b/package-lock.json index 0b0e4c3c1c24c..11974eb0c1629 100644 --- a/package-lock.json +++ b/package-lock.json @@ -93,8 +93,8 @@ "@npmcli/arborist": "^7.2.1", "@npmcli/config": "^8.0.2", "@npmcli/fs": "^3.1.0", - "@npmcli/map-workspaces": "^3.0.4", - "@npmcli/package-json": "^5.0.1", + "@npmcli/map-workspaces": "^3.0.6", + "@npmcli/package-json": "^5.0.2", "@npmcli/promise-spawn": "^7.0.1", "@npmcli/redact": "^1.1.0", "@npmcli/run-script": "^7.0.4", @@ -1736,9 +1736,9 @@ } }, "node_modules/@npmcli/map-workspaces": { - "version": "3.0.4", - "resolved": "https://registry.npmjs.org/@npmcli/map-workspaces/-/map-workspaces-3.0.4.tgz", - "integrity": "sha512-Z0TbvXkRbacjFFLpVpV0e2mheCh+WzQpcqL+4xp49uNJOxOnIAPZyXtUxZ5Qn3QBTGKA11Exjd9a5411rBrhDg==", + "version": "3.0.6", + "resolved": "https://registry.npmjs.org/@npmcli/map-workspaces/-/map-workspaces-3.0.6.tgz", + "integrity": "sha512-tkYs0OYnzQm6iIRdfy+LcLBjcKuQCeE5YLb8KnrIlutJfheNaPvPpgoFEyEFgbjzl5PLZ3IA/BWAwRU0eHuQDA==", "inBundle": true, "dependencies": { "@npmcli/name-from-folder": "^2.0.0", @@ -1805,9 +1805,9 @@ } }, "node_modules/@npmcli/package-json": { - "version": "5.0.1", - "resolved": "https://registry.npmjs.org/@npmcli/package-json/-/package-json-5.0.1.tgz", - "integrity": "sha512-WdwGsRP/do+94IXEgfD/oGGVn0VDS+wYM8MoXU5tJ+02Ke8ePSobMwnfcCHAfcvU/pFwZxyZYWaJdOBsqXRAbA==", + "version": "5.0.2", + "resolved": "https://registry.npmjs.org/@npmcli/package-json/-/package-json-5.0.2.tgz", + "integrity": "sha512-LmW+tueGSK+FCM3OpcKtwKKo3igpefh6HHiw23sGd8OdJ8l0GrfGfVdGOFVtJRMaXVnvI1RUdEPlB9VUln5Wbw==", "inBundle": true, "dependencies": { "@npmcli/git": "^5.0.0", @@ -12163,9 +12163,9 @@ } }, "node_modules/socks": { - "version": "2.8.2", - "resolved": "https://registry.npmjs.org/socks/-/socks-2.8.2.tgz", - "integrity": "sha512-5Hvyu6Md91ooZzdrN/bSn/zlulFaRHrk2/6IY6qQNa3oVHTiG+CKxBV5PynKCGf31ar+3/hyPvlHFAYaBEOa3A==", + "version": "2.8.3", + "resolved": "https://registry.npmjs.org/socks/-/socks-2.8.3.tgz", + "integrity": "sha512-l5x7VUUWbjVFbafGLxPWkYsHIhEvmF85tbIeFZWc8ZPtoMyybuEhL7Jye/ooC4/d48FgOjSJXgsF/AJPYCW8Zw==", "inBundle": true, "dependencies": { "ip-address": "^9.0.5", diff --git a/package.json b/package.json index 5393af5559753..81ef962bc4220 100644 --- a/package.json +++ b/package.json @@ -55,8 +55,8 @@ "@npmcli/arborist": "^7.2.1", "@npmcli/config": "^8.0.2", "@npmcli/fs": "^3.1.0", - "@npmcli/map-workspaces": "^3.0.4", - "@npmcli/package-json": "^5.0.1", + "@npmcli/map-workspaces": "^3.0.6", + "@npmcli/package-json": "^5.0.2", "@npmcli/promise-spawn": "^7.0.1", "@npmcli/redact": "^1.1.0", "@npmcli/run-script": "^7.0.4",