@@ -121,7 +121,7 @@ export function applyPatchesForApp({
121
121
details . sort ( ( a , b ) => {
122
122
return ( a . sequenceNumber ?? 0 ) - ( b . sequenceNumber ?? 0 )
123
123
} )
124
- packageLoop: for ( const packageDetails of details ) {
124
+ packageLoop: for ( const patchDetails of details ) {
125
125
try {
126
126
const {
127
127
name,
@@ -130,7 +130,7 @@ export function applyPatchesForApp({
130
130
pathSpecifier,
131
131
isDevOnly,
132
132
patchFilename,
133
- } = packageDetails
133
+ } = patchDetails
134
134
135
135
const installedPackageVersion = getInstalledPackageVersion ( {
136
136
appPath,
@@ -140,7 +140,10 @@ export function applyPatchesForApp({
140
140
isDevOnly ||
141
141
// check for direct-dependents in prod
142
142
( process . env . NODE_ENV === "production" &&
143
- packageIsDevDependency ( { appPath, packageDetails } ) ) ,
143
+ packageIsDevDependency ( {
144
+ appPath,
145
+ patchDetails,
146
+ } ) ) ,
144
147
patchFilename,
145
148
} )
146
149
if ( ! installedPackageVersion ) {
@@ -157,7 +160,7 @@ export function applyPatchesForApp({
157
160
applyPatch ( {
158
161
patchFilePath : resolve ( patchesDirectory , patchFilename ) as string ,
159
162
reverse,
160
- packageDetails ,
163
+ patchDetails ,
161
164
patchDir,
162
165
} )
163
166
) {
@@ -175,10 +178,10 @@ export function applyPatchesForApp({
175
178
)
176
179
}
177
180
const sequenceString =
178
- packageDetails . sequenceNumber != null
179
- ? ` (${ packageDetails . sequenceNumber } ${
180
- packageDetails . sequenceName
181
- ? " " + packageDetails . sequenceName
181
+ patchDetails . sequenceNumber != null
182
+ ? ` (${ patchDetails . sequenceNumber } ${
183
+ patchDetails . sequenceName
184
+ ? " " + patchDetails . sequenceName
182
185
: ""
183
186
} )`
184
187
: ""
@@ -198,6 +201,9 @@ export function applyPatchesForApp({
198
201
path,
199
202
} ) ,
200
203
)
204
+ // in case the package has multiple patches, we need to break out of this inner loop
205
+ // because we don't want to apply more patches on top of the broken state
206
+ break packageLoop
201
207
} else {
202
208
errors . push (
203
209
createPatchApplicationFailureError ( {
@@ -209,21 +215,24 @@ export function applyPatchesForApp({
209
215
pathSpecifier,
210
216
} ) ,
211
217
)
218
+ // in case the package has multiple patches, we need to break out of this inner loop
219
+ // because we don't want to apply more patches on top of the broken state
220
+ break packageLoop
212
221
}
213
222
} catch ( error ) {
214
223
if ( error instanceof PatchApplicationError ) {
215
224
errors . push ( error . message )
216
225
} else {
217
226
errors . push (
218
227
createUnexpectedError ( {
219
- filename : packageDetails . patchFilename ,
228
+ filename : patchDetails . patchFilename ,
220
229
error : error as Error ,
221
230
} ) ,
222
231
)
223
232
}
224
- if ( details . length > 0 ) {
225
- continue packageLoop
226
- }
233
+ // in case the package has multiple patches, we need to break out of this inner loop
234
+ // because we don't want to apply more patches on top of the broken state
235
+ break packageLoop
227
236
}
228
237
}
229
238
}
@@ -265,15 +274,19 @@ export function applyPatchesForApp({
265
274
export function applyPatch ( {
266
275
patchFilePath,
267
276
reverse,
268
- packageDetails ,
277
+ patchDetails ,
269
278
patchDir,
270
279
} : {
271
280
patchFilePath : string
272
281
reverse : boolean
273
- packageDetails : PackageDetails
282
+ patchDetails : PackageDetails
274
283
patchDir : string
275
284
} ) : boolean {
276
- const patch = readPatch ( { patchFilePath, packageDetails, patchDir } )
285
+ const patch = readPatch ( {
286
+ patchFilePath,
287
+ patchDetails,
288
+ patchDir,
289
+ } )
277
290
try {
278
291
executeEffects ( reverse ? reversePatch ( patch ) : patch , { dryRun : false } )
279
292
} catch ( e ) {
0 commit comments