@@ -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
144168mapWorkspaces . virtual = function ( opts = { } ) {
0 commit comments