From 510a9db3f4b9b5b18211d405213edec0f83c6753 Mon Sep 17 00:00:00 2001 From: Gar Date: Thu, 10 Mar 2022 10:02:52 -0800 Subject: [PATCH] deps: map-workspaces@2.0.2 * evaluate all patterns before throwing EDUPLICATEWORKSPACE --- .../@npmcli/map-workspaces/lib/index.js | 58 +++++++++++++------ .../@npmcli/map-workspaces/package.json | 15 ++--- package-lock.json | 18 +++--- package.json | 2 +- 4 files changed, 56 insertions(+), 37 deletions(-) diff --git a/node_modules/@npmcli/map-workspaces/lib/index.js b/node_modules/@npmcli/map-workspaces/lib/index.js index a2401b565b335..3ac545e9c15c4 100644 --- a/node_modules/@npmcli/map-workspaces/lib/index.js +++ b/node_modules/@npmcli/map-workspaces/lib/index.js @@ -117,28 +117,52 @@ async function mapWorkspaces (opts = {}) { const name = getPackageName(pkg, packagePathname) + let seenPackagePathnames = seen.get(name) + if (!seenPackagePathnames) { + seenPackagePathnames = new Set() + seen.set(name, seenPackagePathnames) + } if (item.negate) { - results.delete(packagePathname, name) + seenPackagePathnames.delete(packagePathname) } else { - if (seen.has(name) && seen.get(name) !== packagePathname) { - throw getError({ - Type: Error, - message: [ - 'must not have multiple workspaces with the same name', - `package '${name}' has conflicts in the following paths:`, - ' ' + seen.get(name), - ' ' + packagePathname, - ].join('\n'), - code: 'EDUPLICATEWORKSPACE', - }) - } - - seen.set(name, packagePathname) - results.set(packagePathname, name) + seenPackagePathnames.add(packagePathname) } } } - return reverseResultMap(results) + + 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 { + results.set(packageName, seenPackagePathnames.values().next().value) + } + } + + if (errorMessageArray.length > 1) { + throw getError({ + Type: Error, + message: errorMessageArray.join('\n'), + code: 'EDUPLICATEWORKSPACE', + }) + } + + return results +} + +function addDuplicateErrorMessages (messageArray, packageName, packagePathnames) { + messageArray.push( + `package '${packageName}' has conflicts in the following paths:` + ) + + for (const packagePathname of packagePathnames) { + messageArray.push( + ' ' + packagePathname + ) + } } mapWorkspaces.virtual = function (opts = {}) { diff --git a/node_modules/@npmcli/map-workspaces/package.json b/node_modules/@npmcli/map-workspaces/package.json index aa46ad0f42f2d..8ae823cf3e9b7 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": "2.0.1", + "version": "2.0.2", "main": "lib/index.js", "files": [ "bin", @@ -37,23 +37,18 @@ "tap": { "check-coverage": true }, - "standard": { - "ignore": [ - "/tap-snapshots/" - ] - }, "devDependencies": { - "@npmcli/template-oss": "^2.7.1", - "eslint": "^8.9.0", + "@npmcli/template-oss": "^2.9.2", + "eslint": "^8.10.0", "tap": "^15.1.6" }, "dependencies": { "@npmcli/name-from-folder": "^1.0.1", "glob": "^7.2.0", - "minimatch": "^5.0.0", + "minimatch": "^5.0.1", "read-package-json-fast": "^2.0.3" }, "templateOSS": { - "version": "2.7.1" + "version": "2.9.2" } } diff --git a/package-lock.json b/package-lock.json index f0859279ccc9c..9df8b7c9443bd 100644 --- a/package-lock.json +++ b/package-lock.json @@ -90,7 +90,7 @@ "@npmcli/arborist": "^5.0.1", "@npmcli/ci-detect": "^2.0.0", "@npmcli/config": "^4.0.1", - "@npmcli/map-workspaces": "^2.0.0", + "@npmcli/map-workspaces": "^2.0.2", "@npmcli/package-json": "^1.0.1", "@npmcli/run-script": "^3.0.1", "abbrev": "~1.1.1", @@ -923,14 +923,14 @@ } }, "node_modules/@npmcli/map-workspaces": { - "version": "2.0.1", - "resolved": "https://registry.npmjs.org/@npmcli/map-workspaces/-/map-workspaces-2.0.1.tgz", - "integrity": "sha512-awwkB/tSWWaCD8F0IbawBdmoPFlbXMaEPN9LyTuJcyJz404/QhB4B/vhQntpk6uxOAkM+bxR7qWMJghYg0tcYQ==", + "version": "2.0.2", + "resolved": "https://registry.npmjs.org/@npmcli/map-workspaces/-/map-workspaces-2.0.2.tgz", + "integrity": "sha512-ED54EslGsHFWBPN5x8JAOszuWywuoXYSi9E3HQRsgVkWnqsdTBJDSM4IFMRwmmBUbCHAxmP3wGLu1WMm4fhrOw==", "inBundle": true, "dependencies": { "@npmcli/name-from-folder": "^1.0.1", "glob": "^7.2.0", - "minimatch": "^5.0.0", + "minimatch": "^5.0.1", "read-package-json-fast": "^2.0.3" }, "engines": { @@ -11451,13 +11451,13 @@ } }, "@npmcli/map-workspaces": { - "version": "2.0.1", - "resolved": "https://registry.npmjs.org/@npmcli/map-workspaces/-/map-workspaces-2.0.1.tgz", - "integrity": "sha512-awwkB/tSWWaCD8F0IbawBdmoPFlbXMaEPN9LyTuJcyJz404/QhB4B/vhQntpk6uxOAkM+bxR7qWMJghYg0tcYQ==", + "version": "2.0.2", + "resolved": "https://registry.npmjs.org/@npmcli/map-workspaces/-/map-workspaces-2.0.2.tgz", + "integrity": "sha512-ED54EslGsHFWBPN5x8JAOszuWywuoXYSi9E3HQRsgVkWnqsdTBJDSM4IFMRwmmBUbCHAxmP3wGLu1WMm4fhrOw==", "requires": { "@npmcli/name-from-folder": "^1.0.1", "glob": "^7.2.0", - "minimatch": "^5.0.0", + "minimatch": "^5.0.1", "read-package-json-fast": "^2.0.3" }, "dependencies": { diff --git a/package.json b/package.json index 567ce9cf54f63..83c0cb2d8610f 100644 --- a/package.json +++ b/package.json @@ -58,7 +58,7 @@ "@npmcli/arborist": "^5.0.1", "@npmcli/ci-detect": "^2.0.0", "@npmcli/config": "^4.0.1", - "@npmcli/map-workspaces": "^2.0.0", + "@npmcli/map-workspaces": "^2.0.2", "@npmcli/package-json": "^1.0.1", "@npmcli/run-script": "^3.0.1", "abbrev": "~1.1.1",