Repository navigation
Expand file tree
/
Copy pathengine.js
More file actions
641 lines (601 loc) · 23.1 KB
/
Copy pathengine.js
File metadata and controls
641 lines (601 loc) · 23.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
"use strict";
const fs = require("node:fs");
const path = require("node:path");
const {
PATCH_STATUS_APPLIED,
PATCH_STATUS_FAILED_INTEGRITY,
PATCH_STATUS_FAILED_REQUIRED,
PATCH_STATUS_SKIPPED_DISABLED,
PATCH_STATUS_SKIPPED_OPTIONAL,
PATCH_STATUS_SKIPPED_TARGET,
captureWarnings,
isCriticalPolicy,
patchStatusFromChange,
recordPatch,
} = require("../lib/patch-report.js");
const {
isPatchIntegrityError,
} = require("./integrity-error.js");
const {
linuxTargetSummary,
} = require("../lib/linux-target-context.js");
const {
listWebviewScriptAssets,
patchAssetFiles,
patchUniqueAssetFile,
} = require("./lib/assets.js");
const {
CI_POLICIES,
PHASE_EXTRACTED_APP_POST_WEBVIEW,
PHASE_EXTRACTED_APP_PRE_WEBVIEW,
PHASE_MAIN_BUNDLE,
PHASE_WEBVIEW_ASSET,
PATCH_PHASES,
} = require("./descriptor.js");
const {
drainStrategies,
} = require("./strategy-telemetry.js");
const REQUIRED_UPSTREAM = "required-upstream";
const OPTIONAL = "optional";
const OPT_IN = "opt-in";
function descriptorId(descriptor) {
return descriptor.id ?? descriptor.name;
}
function normalizeDescriptor(descriptor, sourcePath = null, index = 0) {
if (descriptor == null || typeof descriptor !== "object") {
throw new Error(`Invalid patch descriptor from ${sourcePath ?? "inline descriptor"}`);
}
const id = descriptorId(descriptor);
if (typeof id !== "string" || id.length === 0) {
throw new Error(`Patch descriptor from ${sourcePath ?? "inline descriptor"} must have id or name`);
}
if (typeof descriptor.apply !== "function") {
throw new Error(`Patch descriptor '${id}' must export an apply function`);
}
if (descriptor.assetMatch != null && typeof descriptor.assetMatch !== "function") {
throw new Error(`Patch descriptor '${id}' assetMatch must be a function`);
}
const ciPolicy = descriptor.ciPolicy ?? OPTIONAL;
if (!CI_POLICIES.has(ciPolicy)) {
throw new Error(
`Patch descriptor '${id}' has unsupported ciPolicy '${ciPolicy}' in ${sourcePath ?? "inline descriptor"}`,
);
}
if (descriptor.enforceWhenEnabled != null && typeof descriptor.enforceWhenEnabled !== "boolean") {
throw new Error(
`Patch descriptor '${id}' enforceWhenEnabled must be a boolean in ${sourcePath ?? "inline descriptor"}`,
);
}
if (descriptor.enforceWhenEnabled === false && ciPolicy !== OPTIONAL) {
throw new Error(
`Patch descriptor '${id}' can disable enabled-feature enforcement only with ciPolicy 'optional'`,
);
}
const normalized = {
...descriptor,
ciPolicy,
enforceWhenEnabled: descriptor.enforceWhenEnabled ?? true,
id,
name: descriptor.name ?? id,
phase: descriptor.phase ?? PHASE_MAIN_BUNDLE,
sourceKind: descriptor.sourceKind ?? (descriptor.featureId != null ? "feature" : "core"),
order: descriptor.order ?? 10_000 + index,
sourcePath,
};
if (!PATCH_PHASES.has(normalized.phase)) {
throw new Error(
`Patch descriptor '${id}' has unsupported phase '${normalized.phase}' in ${sourcePath ?? "inline descriptor"}`,
);
}
if (normalized.composesPatches != null) {
throw new Error(`Patch descriptor '${id}' uses removed composesPatches support`);
}
return normalized;
}
function descriptorListFromExports(moduleExports, sourcePath) {
const exported = moduleExports?.descriptors ??
moduleExports;
const descriptors = Array.isArray(exported) ? exported : [exported];
return descriptors.map((descriptor, index) => normalizeDescriptor(descriptor, sourcePath, index));
}
function discoverPatchFiles(root) {
if (!root || !fs.existsSync(root)) {
return [];
}
const files = [];
const walk = (dir) => {
for (const name of fs.readdirSync(dir).sort()) {
const filePath = path.join(dir, name);
const stat = fs.statSync(filePath);
if (stat.isDirectory()) {
walk(filePath);
} else if (name === "patch.js") {
files.push(filePath);
}
}
};
walk(root);
return files;
}
function discoverCorePatchDescriptors(options = {}) {
const root = options.root ?? path.join(__dirname, "core");
return sortPatchDescriptors(
discoverPatchFiles(root).flatMap((filePath) => descriptorListFromExports(require(filePath), filePath)),
);
}
function sortPatchDescriptors(descriptors) {
return [...descriptors].sort((left, right) => {
if (left.order !== right.order) {
return left.order - right.order;
}
return `${left.sourcePath ?? ""}:${left.id}`.localeCompare(`${right.sourcePath ?? ""}:${right.id}`);
});
}
function assertUniquePatchIds(descriptors) {
const seen = new Map();
for (const descriptor of descriptors) {
const previous = seen.get(descriptor.id);
if (previous != null) {
throw new Error(
`Duplicate patch descriptor id '${descriptor.id}' in ${descriptor.sourcePath ?? "inline descriptor"} and ${previous}`,
);
}
seen.set(descriptor.id, descriptor.sourcePath ?? "inline descriptor");
}
}
function normalizePatchDescriptors(descriptors) {
const normalized = descriptors.map((descriptor, index) =>
normalizeDescriptor(descriptor, descriptor.sourcePath ?? null, index),
);
assertUniquePatchIds(normalized);
return sortPatchDescriptors(normalized);
}
function patchTargetSummary(descriptor, context) {
if (typeof descriptor.targetSummary === "function") {
return descriptor.targetSummary(context);
}
if (typeof descriptor.targetSummary === "string") {
return descriptor.targetSummary;
}
if (descriptor.appliesTo == null) {
return "all-linux";
}
return context?.linux == null
? "conditional-linux"
: `conditional-linux:${linuxTargetSummary(context.linux)}`;
}
function descriptorFailureStatus(descriptor) {
return isCriticalPolicy(descriptor.ciPolicy) ? PATCH_STATUS_FAILED_REQUIRED : PATCH_STATUS_SKIPPED_OPTIONAL;
}
function describePatchError(descriptor, error) {
const message = error instanceof Error ? error.message : String(error);
if (isPatchIntegrityError(error)) {
return `Patch '${descriptor.id}' integrity failure: ${message}`;
}
return `Patch '${descriptor.id}' threw: ${message}`;
}
// Runs a descriptor's apply function so ordinary errors can follow ciPolicy.
// PatchIntegrityError is recorded by the caller and then rethrown because the
// patch could not prove that a failed mutation restored the original bytes.
// Strategy telemetry recorded during the apply is drained into the result so
// it can be attributed to this descriptor's report entry.
function runDescriptorApply(descriptor, fn, fallbackValue) {
drainStrategies(); // discard stale entries from direct helper calls
const captured = captureWarnings(() => {
try {
return { ok: true, value: fn() };
} catch (error) {
return { ok: false, error, value: fallbackValue };
}
});
const outcome = captured.value;
return {
value: outcome.value,
warnings: captured.warnings,
error: outcome.ok ? null : outcome.error,
strategies: drainStrategies(),
};
}
function patchStatusFromDescriptorChange(descriptor, changed, warnings) {
return patchStatusFromChange(changed, warnings, descriptor.ciPolicy);
}
function normalizeDescriptorStatus(descriptor, status) {
if (isCriticalPolicy(descriptor.ciPolicy) && status === PATCH_STATUS_SKIPPED_OPTIONAL) {
return PATCH_STATUS_FAILED_REQUIRED;
}
return status;
}
function recordDescriptorPatch(report, descriptor, status, reason, context, extraMetadata = null) {
const warnings = Array.isArray(context?.reportWarnings) && context.reportWarnings.length > 0
? { warnings: [...context.reportWarnings] }
: {};
recordPatch(report, descriptor.id, normalizeDescriptorStatus(descriptor, status), reason, {
phase: descriptor.phase,
targetSummary: patchTargetSummary(descriptor, context),
ciPolicy: descriptor.ciPolicy ?? "optional",
sourceKind: descriptor.sourceKind ?? "core",
...(descriptor.featureId != null ? { featureId: descriptor.featureId } : {}),
...(descriptor.sourceKind === "feature"
? { enforceWhenEnabled: descriptor.enforceWhenEnabled !== false }
: {}),
...(extraMetadata ?? {}),
...warnings,
});
}
function strategyMetadata(strategies) {
return Array.isArray(strategies) && strategies.length > 0 ? { strategies } : null;
}
function recordDescriptorError(report, descriptor, error, context, strategies = null) {
recordDescriptorPatch(
report,
descriptor,
isPatchIntegrityError(error)
? PATCH_STATUS_FAILED_INTEGRITY
: descriptorFailureStatus(descriptor),
describePatchError(descriptor, error),
context,
{ error: true, ...(strategyMetadata(strategies) ?? {}) },
);
}
function recordUnavailablePhasePatchDescriptors(descriptors, phase, context, report, reason) {
for (const descriptor of descriptors.filter((patch) => patch.phase === phase)) {
if (!descriptorAppliesTo(descriptor, context)) {
recordDescriptorPatch(report, descriptor, PATCH_STATUS_SKIPPED_TARGET, null, context);
continue;
}
if (!descriptorEnabled(descriptor, context)) {
recordDescriptorPatch(report, descriptor, PATCH_STATUS_SKIPPED_DISABLED, null, context);
continue;
}
recordDescriptorPatch(
report,
descriptor,
descriptorFailureStatus(descriptor),
reason,
context,
{ unavailable: true },
);
}
}
function rethrowPatchIntegrityError(error) {
if (isPatchIntegrityError(error)) {
throw error;
}
}
function descriptorAppliesTo(descriptor, context) {
if (descriptor.appliesTo == null) {
return true;
}
return descriptor.appliesTo(context) !== false;
}
function descriptorEnabled(descriptor, context) {
if (descriptor.enabled == null) {
return true;
}
return descriptor.enabled(context) !== false;
}
function applyMainBundlePatchDescriptors(source, descriptors, context, report) {
let patched = source;
const warnings = [];
const coreWarnings = [];
const requiredCoreWarnings = [];
for (const descriptor of descriptors.filter((patch) => patch.phase === PHASE_MAIN_BUNDLE)) {
if (!descriptorAppliesTo(descriptor, context)) {
recordDescriptorPatch(report, descriptor, PATCH_STATUS_SKIPPED_TARGET, null, context);
continue;
}
if (!descriptorEnabled(descriptor, context)) {
recordDescriptorPatch(report, descriptor, PATCH_STATUS_SKIPPED_DISABLED, null, context);
continue;
}
const before = patched;
const result = runDescriptorApply(descriptor, () => descriptor.apply(patched, context), before);
patched = result.value;
if (result.error != null) {
result.warnings.push(`WARN: ${describePatchError(descriptor, result.error)}`);
}
warnings.push(...result.warnings);
if ((descriptor.sourceKind ?? "core") === "core") {
coreWarnings.push(...result.warnings);
if (descriptor.ciPolicy === REQUIRED_UPSTREAM) {
requiredCoreWarnings.push(...result.warnings);
}
}
context.reportWarnings = result.warnings;
if (result.error != null) {
recordDescriptorError(report, descriptor, result.error, context, result.strategies);
delete context.reportWarnings;
rethrowPatchIntegrityError(result.error);
} else {
recordDescriptorPatch(
report,
descriptor,
patchStatusFromDescriptorChange(descriptor, patched !== before, result.warnings),
result.warnings[0] ?? null,
context,
strategyMetadata(result.strategies),
);
}
delete context.reportWarnings;
}
return { patchedSource: patched, warnings, coreWarnings, requiredCoreWarnings };
}
// Applies main-process descriptors to the rspack chunk set. Each descriptor
// is tried against every chunk; only the chunks it actually changes keep the
// result. A descriptor that changes no chunk reports the diagnostics of the
// chunks it tried, so a moved or removed anchor still fails closed.
function applyMainProcessChunkPatchDescriptors(chunks, descriptors, context, report) {
const sources = chunks.map(({ name, source }) => ({ name, source }));
for (const descriptor of descriptors.filter((patch) => patch.phase === PHASE_MAIN_BUNDLE)) {
if (!descriptorAppliesTo(descriptor, context)) {
recordDescriptorPatch(report, descriptor, PATCH_STATUS_SKIPPED_TARGET, null, context);
continue;
}
if (!descriptorEnabled(descriptor, context)) {
recordDescriptorPatch(report, descriptor, PATCH_STATUS_SKIPPED_DISABLED, null, context);
continue;
}
// Collect each chunk's warnings silently; only the outcome's warnings are
// printed below, so a miss on unrelated chunks does not flood build logs.
const attempts = sources.map((chunk) => {
const originalWarn = console.warn;
console.warn = () => {};
let result;
try {
result = runDescriptorApply(
descriptor,
() => descriptor.apply(chunk.source, context),
chunk.source,
);
} finally {
console.warn = originalWarn;
}
return { chunk, result, changed: result.error == null && result.value !== chunk.source };
});
const changed = attempts.filter((attempt) => attempt.changed);
if (changed.length > 0) {
const warnings = changed.flatMap((attempt) => attempt.result.warnings);
for (const warning of warnings) console.warn(warning);
for (const attempt of changed) {
attempt.chunk.source = attempt.result.value;
}
context.reportWarnings = warnings;
recordDescriptorPatch(
report,
descriptor,
patchStatusFromDescriptorChange(descriptor, true, warnings),
warnings[0] ?? null,
context,
{
...(strategyMetadata(changed.flatMap((attempt) => attempt.result.strategies)) ?? {}),
chunks: changed.map((attempt) => attempt.chunk.name),
},
);
delete context.reportWarnings;
continue;
}
// Nothing changed. A clean no-op on some chunk means the contract is
// already satisfied; otherwise report the first diagnostic.
if (attempts.some((attempt) => attempt.result.error == null && attempt.result.warnings.length === 0)) {
recordDescriptorPatch(
report,
descriptor,
patchStatusFromDescriptorChange(descriptor, false, []),
null,
context,
);
continue;
}
const integrity = attempts.find((attempt) => isPatchIntegrityError(attempt.result.error));
const failed = integrity ?? attempts.find((attempt) => attempt.result.error != null);
const warnings = attempts.flatMap((attempt) => attempt.result.warnings);
if (failed != null && warnings.length === 0) {
console.warn(`WARN: ${describePatchError(descriptor, failed.result.error)}`);
context.reportWarnings = [`WARN: ${describePatchError(descriptor, failed.result.error)}`];
recordDescriptorError(report, descriptor, failed.result.error, context, failed.result.strategies);
delete context.reportWarnings;
rethrowPatchIntegrityError(failed.result.error);
continue;
}
const reason = `${descriptor.id} matched no main-process chunk` +
(warnings[0] == null ? "" : `: ${warnings[0].replace(/^WARN:\s*/, "")}`);
console.warn(`WARN: ${reason}`);
context.reportWarnings = [`WARN: ${reason}`];
recordDescriptorPatch(report, descriptor, descriptorFailureStatus(descriptor), reason, context);
delete context.reportWarnings;
}
return sources;
}
function defaultWebviewMissingWarning(extractedDir, descriptor) {
const missingDescription = descriptor.missingDescription ?? "webview asset bundle";
const skipDescription = descriptor.skipDescription ?? descriptor.id;
return `WARN: Could not find ${missingDescription} in ${path.join(extractedDir, "webview", "assets")} — skipping ${skipDescription}`;
}
function defaultWebviewAmbiguousWarning(extractedDir, descriptor) {
const missingDescription = descriptor.missingDescription ?? "webview asset bundle";
const skipDescription = descriptor.skipDescription ?? descriptor.id;
return `WARN: Found multiple ${missingDescription} contracts in ${path.join(extractedDir, "webview", "assets")} — skipping ${skipDescription}`;
}
function assetPatchMetadata(patchResult, strategies) {
return {
...(patchResult.assetName == null ? {} : { assetName: patchResult.assetName }),
...(strategyMetadata(strategies) ?? {}),
};
}
function recordAssetDescriptorPatch(report, descriptor, patchResult, warnings, context, strategies = null) {
if (patchResult.matched === 0) {
recordDescriptorPatch(
report,
descriptor,
descriptorFailureStatus(descriptor),
warnings[0] ?? "no matching bundle found",
context,
assetPatchMetadata(patchResult, strategies),
);
return;
}
recordDescriptorPatch(
report,
descriptor,
patchStatusFromDescriptorChange(descriptor, patchResult.changed > 0, warnings),
warnings[0] ?? null,
context,
assetPatchMetadata(patchResult, strategies),
);
}
// Indexes which webview script assets contain each needle, reading every
// asset once per patch run instead of once per descriptor. Files rewritten
// by a descriptor are re-indexed before the next descriptor runs.
function createWebviewNeedleIndex(extractedDir, needles) {
const assetsDir = path.join(extractedDir, "webview", "assets");
const unique = [...new Set(needles)];
const hits = new Map(unique.map((needle) => [needle, new Set()]));
const indexAsset = (assetName) => {
const source = fs.readFileSync(path.join(assetsDir, assetName), "utf8");
for (const needle of unique) {
if (source.includes(needle)) hits.get(needle).add(assetName);
else hits.get(needle).delete(assetName);
}
};
if (unique.length > 0) {
for (const assetName of listWebviewScriptAssets(extractedDir)) indexAsset(assetName);
}
return {
candidates(descriptorNeedles) {
const [first, ...rest] = descriptorNeedles;
return [...hits.get(first)].filter((assetName) => rest.every((needle) => hits.get(needle).has(assetName)));
},
refresh(assetNames) {
if (unique.length === 0) return;
for (const assetName of assetNames ?? []) indexAsset(assetName);
},
};
}
function applyWebviewAssetPatchDescriptors(extractedDir, descriptors, context, report) {
const webviewDescriptors = descriptors.filter((patch) => patch.phase === PHASE_WEBVIEW_ASSET);
const active = webviewDescriptors.filter((descriptor) =>
descriptorAppliesTo(descriptor, context) && descriptorEnabled(descriptor, context));
const index = createWebviewNeedleIndex(
extractedDir,
active.flatMap((descriptor) => descriptor.assetNeedles ?? []),
);
for (const descriptor of webviewDescriptors) {
if (!descriptorAppliesTo(descriptor, context)) {
recordDescriptorPatch(report, descriptor, PATCH_STATUS_SKIPPED_TARGET, null, context);
continue;
}
if (!descriptorEnabled(descriptor, context)) {
recordDescriptorPatch(report, descriptor, PATCH_STATUS_SKIPPED_DISABLED, null, context);
continue;
}
const pattern = descriptor.assetPattern ?? descriptor.pattern ?? null;
const needles = descriptor.assetNeedles ?? null;
if (pattern == null && needles == null) {
throw new Error(`Webview asset patch '${descriptor.id}' must define assetNeedles, assetPattern or pattern`);
}
const candidates = needles == null
? null
: index.candidates(needles).filter((assetName) =>
pattern == null || patternMatchesAsset(pattern, assetName));
const missingWarning = descriptor.missingWarning ??
defaultWebviewMissingWarning(extractedDir, descriptor);
const ambiguousWarning = descriptor.ambiguousWarning ??
defaultWebviewAmbiguousWarning(extractedDir, descriptor);
const { value: result, warnings, error, strategies } = runDescriptorApply(
descriptor,
() => descriptor.assetMatch == null
? patchAssetFiles(
extractedDir,
pattern,
(source) => descriptor.apply(source, context),
missingWarning,
candidates,
)
: patchUniqueAssetFile(
extractedDir,
pattern,
(source, assetName) => descriptor.assetMatch(source, assetName, context),
(source) => descriptor.apply(source, context),
missingWarning,
ambiguousWarning,
candidates,
),
{ matched: 0, changed: 0, assetName: null, changedAssets: [] },
);
index.refresh(result?.changedAssets);
context.reportWarnings = warnings;
if (error != null) {
warnings.push(`WARN: ${describePatchError(descriptor, error)}`);
recordDescriptorError(report, descriptor, error, context, strategies);
delete context.reportWarnings;
rethrowPatchIntegrityError(error);
} else {
recordAssetDescriptorPatch(report, descriptor, result, warnings, context, strategies);
}
delete context.reportWarnings;
}
}
function patternMatchesAsset(pattern, assetName) {
pattern.lastIndex = 0;
return pattern.test(assetName.slice(assetName.lastIndexOf("/") + 1));
}
function applyExtractedAppPatchDescriptors(extractedDir, descriptors, context, report, phase) {
if (phase !== PHASE_EXTRACTED_APP_PRE_WEBVIEW && phase !== PHASE_EXTRACTED_APP_POST_WEBVIEW) {
throw new Error(`Unsupported extracted-app patch phase '${phase}'`);
}
for (const descriptor of descriptors.filter((patch) => patch.phase === phase)) {
if (!descriptorAppliesTo(descriptor, context)) {
recordDescriptorPatch(report, descriptor, PATCH_STATUS_SKIPPED_TARGET, null, context);
continue;
}
if (!descriptorEnabled(descriptor, context)) {
recordDescriptorPatch(report, descriptor, PATCH_STATUS_SKIPPED_DISABLED, null, context);
continue;
}
const { value: result, warnings, error, strategies } = runDescriptorApply(
descriptor,
() => descriptor.apply(extractedDir, context),
null,
);
context.reportWarnings = warnings;
if (error != null) {
warnings.push(`WARN: ${describePatchError(descriptor, error)}`);
recordDescriptorError(report, descriptor, error, context, strategies);
delete context.reportWarnings;
rethrowPatchIntegrityError(error);
continue;
}
const statusResult = typeof descriptor.status === "function"
? descriptor.status(result, warnings, context)
: result?.changed != null
? patchStatusFromChange(Boolean(result.changed), warnings, descriptor.ciPolicy)
: PATCH_STATUS_APPLIED;
const status = typeof statusResult === "object" && statusResult != null
? statusResult.status
: statusResult;
const reason = typeof statusResult === "object" && statusResult != null
? statusResult.reason
: result?.reason ?? warnings[0] ?? null;
recordDescriptorPatch(report, descriptor, status, reason, context, strategyMetadata(strategies));
delete context.reportWarnings;
}
}
module.exports = {
SKIPPED_DISABLED: PATCH_STATUS_SKIPPED_DISABLED,
SKIPPED_TARGET: PATCH_STATUS_SKIPPED_TARGET,
applyExtractedAppPatchDescriptors,
applyMainBundlePatchDescriptors,
applyMainProcessChunkPatchDescriptors,
applyWebviewAssetPatchDescriptors,
assertUniquePatchIds,
descriptorAppliesTo,
descriptorEnabled,
descriptorId,
discoverCorePatchDescriptors,
discoverPatchFiles,
normalizeDescriptor,
normalizePatchDescriptors,
patchTargetSummary,
recordUnavailablePhasePatchDescriptors,
sortPatchDescriptors,
};