Skip to content

Commit d9dc70c

Browse files
authored
* evaluate all patterns before throwing EDUPLICATEWORKSPACE
1 parent fbdb431 commit d9dc70c

File tree

4 files changed

+56
-37
lines changed

4 files changed

+56
-37
lines changed

node_modules/@npmcli/map-workspaces/lib/index.js

+41-17
Original file line numberDiff line numberDiff line change
@@ -117,28 +117,52 @@ async function mapWorkspaces (opts = {}) {
117117

118118
const name = getPackageName(pkg, packagePathname)
119119

120+
let seenPackagePathnames = seen.get(name)
121+
if (!seenPackagePathnames) {
122+
seenPackagePathnames = new Set()
123+
seen.set(name, seenPackagePathnames)
124+
}
120125
if (item.negate) {
121-
results.delete(packagePathname, name)
126+
seenPackagePathnames.delete(packagePathname)
122127
} else {
123-
if (seen.has(name) && seen.get(name) !== packagePathname) {
124-
throw getError({
125-
Type: Error,
126-
message: [
127-
'must not have multiple workspaces with the same name',
128-
`package '${name}' has conflicts in the following paths:`,
129-
' ' + seen.get(name),
130-
' ' + packagePathname,
131-
].join('\n'),
132-
code: 'EDUPLICATEWORKSPACE',
133-
})
134-
}
135-
136-
seen.set(name, packagePathname)
137-
results.set(packagePathname, name)
128+
seenPackagePathnames.add(packagePathname)
138129
}
139130
}
140131
}
141-
return reverseResultMap(results)
132+
133+
const errorMessageArray = ['must not have multiple workspaces with the same name']
134+
for (const [packageName, seenPackagePathnames] of seen) {
135+
if (seenPackagePathnames.size === 0) {
136+
continue
137+
}
138+
if (seenPackagePathnames.size > 1) {
139+
addDuplicateErrorMessages(errorMessageArray, packageName, seenPackagePathnames)
140+
} else {
141+
results.set(packageName, seenPackagePathnames.values().next().value)
142+
}
143+
}
144+
145+
if (errorMessageArray.length > 1) {
146+
throw getError({
147+
Type: Error,
148+
message: errorMessageArray.join('\n'),
149+
code: 'EDUPLICATEWORKSPACE',
150+
})
151+
}
152+
153+
return results
154+
}
155+
156+
function addDuplicateErrorMessages (messageArray, packageName, packagePathnames) {
157+
messageArray.push(
158+
`package '${packageName}' has conflicts in the following paths:`
159+
)
160+
161+
for (const packagePathname of packagePathnames) {
162+
messageArray.push(
163+
' ' + packagePathname
164+
)
165+
}
142166
}
143167

144168
mapWorkspaces.virtual = function (opts = {}) {

node_modules/@npmcli/map-workspaces/package.json

+5-10
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@npmcli/map-workspaces",
3-
"version": "2.0.1",
3+
"version": "2.0.2",
44
"main": "lib/index.js",
55
"files": [
66
"bin",
@@ -37,23 +37,18 @@
3737
"tap": {
3838
"check-coverage": true
3939
},
40-
"standard": {
41-
"ignore": [
42-
"/tap-snapshots/"
43-
]
44-
},
4540
"devDependencies": {
46-
"@npmcli/template-oss": "^2.7.1",
47-
"eslint": "^8.9.0",
41+
"@npmcli/template-oss": "^2.9.2",
42+
"eslint": "^8.10.0",
4843
"tap": "^15.1.6"
4944
},
5045
"dependencies": {
5146
"@npmcli/name-from-folder": "^1.0.1",
5247
"glob": "^7.2.0",
53-
"minimatch": "^5.0.0",
48+
"minimatch": "^5.0.1",
5449
"read-package-json-fast": "^2.0.3"
5550
},
5651
"templateOSS": {
57-
"version": "2.7.1"
52+
"version": "2.9.2"
5853
}
5954
}

package-lock.json

+9-9
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@
9090
"@npmcli/arborist": "^5.0.1",
9191
"@npmcli/ci-detect": "^2.0.0",
9292
"@npmcli/config": "^4.0.1",
93-
"@npmcli/map-workspaces": "^2.0.0",
93+
"@npmcli/map-workspaces": "^2.0.2",
9494
"@npmcli/package-json": "^1.0.1",
9595
"@npmcli/run-script": "^3.0.1",
9696
"abbrev": "~1.1.1",
@@ -923,14 +923,14 @@
923923
}
924924
},
925925
"node_modules/@npmcli/map-workspaces": {
926-
"version": "2.0.1",
927-
"resolved": "https://registry.npmjs.org/@npmcli/map-workspaces/-/map-workspaces-2.0.1.tgz",
928-
"integrity": "sha512-awwkB/tSWWaCD8F0IbawBdmoPFlbXMaEPN9LyTuJcyJz404/QhB4B/vhQntpk6uxOAkM+bxR7qWMJghYg0tcYQ==",
926+
"version": "2.0.2",
927+
"resolved": "https://registry.npmjs.org/@npmcli/map-workspaces/-/map-workspaces-2.0.2.tgz",
928+
"integrity": "sha512-ED54EslGsHFWBPN5x8JAOszuWywuoXYSi9E3HQRsgVkWnqsdTBJDSM4IFMRwmmBUbCHAxmP3wGLu1WMm4fhrOw==",
929929
"inBundle": true,
930930
"dependencies": {
931931
"@npmcli/name-from-folder": "^1.0.1",
932932
"glob": "^7.2.0",
933-
"minimatch": "^5.0.0",
933+
"minimatch": "^5.0.1",
934934
"read-package-json-fast": "^2.0.3"
935935
},
936936
"engines": {
@@ -11451,13 +11451,13 @@
1145111451
}
1145211452
},
1145311453
"@npmcli/map-workspaces": {
11454-
"version": "2.0.1",
11455-
"resolved": "https://registry.npmjs.org/@npmcli/map-workspaces/-/map-workspaces-2.0.1.tgz",
11456-
"integrity": "sha512-awwkB/tSWWaCD8F0IbawBdmoPFlbXMaEPN9LyTuJcyJz404/QhB4B/vhQntpk6uxOAkM+bxR7qWMJghYg0tcYQ==",
11454+
"version": "2.0.2",
11455+
"resolved": "https://registry.npmjs.org/@npmcli/map-workspaces/-/map-workspaces-2.0.2.tgz",
11456+
"integrity": "sha512-ED54EslGsHFWBPN5x8JAOszuWywuoXYSi9E3HQRsgVkWnqsdTBJDSM4IFMRwmmBUbCHAxmP3wGLu1WMm4fhrOw==",
1145711457
"requires": {
1145811458
"@npmcli/name-from-folder": "^1.0.1",
1145911459
"glob": "^7.2.0",
11460-
"minimatch": "^5.0.0",
11460+
"minimatch": "^5.0.1",
1146111461
"read-package-json-fast": "^2.0.3"
1146211462
},
1146311463
"dependencies": {

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@
5858
"@npmcli/arborist": "^5.0.1",
5959
"@npmcli/ci-detect": "^2.0.0",
6060
"@npmcli/config": "^4.0.1",
61-
"@npmcli/map-workspaces": "^2.0.0",
61+
"@npmcli/map-workspaces": "^2.0.2",
6262
"@npmcli/package-json": "^1.0.1",
6363
"@npmcli/run-script": "^3.0.1",
6464
"abbrev": "~1.1.1",

0 commit comments

Comments
 (0)