@@ -103,6 +103,7 @@ export default class PackageLinker {
103
103
let tree = Object . create ( null ) ;
104
104
let self = this ;
105
105
106
+ let unflattenedKeys = new Set ;
106
107
let subPairs = new Map ;
107
108
108
109
//
@@ -133,6 +134,7 @@ export default class PackageLinker {
133
134
134
135
zippedTree . push ( pair ) ;
135
136
tree [ key ] = info ;
137
+ unflattenedKeys . add ( key ) ;
136
138
137
139
let results = [ ] ;
138
140
@@ -157,6 +159,7 @@ export default class PackageLinker {
157
159
let pair = zippedTree [ i ] ;
158
160
let [ key , info ] = pair ;
159
161
162
+ let stepUp = false ;
160
163
let parts = key . split ( "#" ) ;
161
164
let stack = [ ] ; // stack of removed parts
162
165
@@ -166,9 +169,10 @@ export default class PackageLinker {
166
169
// remove redundant parts that wont collide
167
170
let name = parts . pop ( ) ;
168
171
while ( parts . length ) {
169
- let key = parts . concat ( name ) . join ( "#" ) ;
172
+ let checkKey = parts . concat ( name ) . join ( "#" ) ;
170
173
171
- let existing = tree [ key ] ;
174
+ //
175
+ let existing = tree [ checkKey ] ;
172
176
if ( existing ) {
173
177
if ( existing . loc === info . loc ) {
174
178
continue hoist ;
@@ -177,16 +181,28 @@ export default class PackageLinker {
177
181
}
178
182
}
179
183
184
+ // check if we're trying to hoist ourselves to a previously unflattened module key,
185
+ // this will result in a conflict and we'll need to move ourselves up
186
+ if ( key !== checkKey && unflattenedKeys . has ( checkKey ) ) {
187
+ stepUp = true ;
188
+ break ;
189
+ }
190
+
180
191
stack . push ( parts . pop ( ) ) ;
181
192
}
182
193
183
194
//
184
195
parts . push ( name ) ;
185
196
186
197
// we need to special case when we attempt to hoist to the top level as the `existing` logic
187
- // wont be hit in the above `while` loop
198
+ // wont be hit in the above `while` loop and we could conflict
188
199
let existing = tree [ parts . join ( "#" ) ] ;
189
200
if ( existing && existing . loc !== info . loc ) {
201
+ stepUp = true ;
202
+ }
203
+
204
+ // sometimes we need to step up to a parent module to install ourselves
205
+ if ( stepUp ) {
190
206
parts . pop ( ) ;
191
207
parts . push ( stack . pop ( ) , name ) ;
192
208
}
0 commit comments