expo 58.0.0 → 58.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (41) hide show
  1. package/android/build.gradle +2 -2
  2. package/android/proguard-rules.pro +4 -0
  3. package/android/src/main/java/expo/modules/fetch/NativeResponse.kt +5 -1
  4. package/android/src/main/java/expo/modules/fetch/OkHttpFileUrlInterceptor.kt +5 -1
  5. package/build/winter/runtime.native.js +0 -2
  6. package/build/winter/runtime.native.js.map +1 -1
  7. package/bundledNativeModules.json +76 -76
  8. package/ios/Expo/ExpoReactNativeFactory.swift +2 -2
  9. package/ios/ExpoObjC/AppDelegates/EXReactRootViewFactory.mm +16 -2
  10. package/ios/ExpoObjC/include/Expo/EXReactRootViewFactory.h +2 -1
  11. package/package.json +13 -13
  12. package/scripts/spm/README.md +0 -3
  13. package/scripts/spm/__tests__/app-target.test.js +105 -1
  14. package/scripts/spm/__tests__/autolink-gate.test.js +188 -0
  15. package/scripts/spm/__tests__/classify.test.js +17 -19
  16. package/scripts/spm/__tests__/cli.test.js +57 -1
  17. package/scripts/spm/__tests__/diagnostics.test.js +806 -183
  18. package/scripts/spm/__tests__/flavored-frameworks.test.js +9 -0
  19. package/scripts/spm/__tests__/helpers.js +88 -0
  20. package/scripts/spm/__tests__/manifests.test.js +1330 -104
  21. package/scripts/spm/__tests__/metadata.test.js +120 -0
  22. package/scripts/spm/__tests__/plugin.test.js +3304 -111
  23. package/scripts/spm/__tests__/podspec.test.js +27 -138
  24. package/scripts/spm/__tests__/spm-dependencies.test.js +344 -0
  25. package/scripts/spm/app-target.js +42 -1
  26. package/scripts/spm/autolink-gate.js +40 -0
  27. package/scripts/spm/classify.js +78 -79
  28. package/scripts/spm/cli.js +23 -9
  29. package/scripts/spm/diagnostics.js +605 -192
  30. package/scripts/spm/flavored-frameworks.js +231 -64
  31. package/scripts/spm/manifests.js +565 -196
  32. package/scripts/spm/metadata.js +152 -0
  33. package/scripts/spm/plugin.js +679 -205
  34. package/scripts/spm/podspec.js +57 -170
  35. package/src/winter/runtime.native.ts +0 -2
  36. package/template.tgz +0 -0
  37. package/build/winter/AbortSignal.d.ts +0 -3
  38. package/build/winter/AbortSignal.js +0 -96
  39. package/build/winter/AbortSignal.js.map +0 -1
  40. package/src/winter/AbortSignal.ts +0 -132
  41. package/src/winter/__tests__/AbortSignal.test.native.ts +0 -163
@@ -25,9 +25,13 @@
25
25
  * NOTE: RN invokes the plugin SYNCHRONOUSLY (`plugin(context)`, no await), so
26
26
  * everything shells out via `execFileSync` (see cli.js) rather than awaiting.
27
27
  *
28
- * The logic is split across sibling modules — cli.js (I/O), classify.js
29
- * (discovery), react-descriptor.js + manifests.js (rendering) — with unit tests
30
- * in __tests__/. This file is just the orchestrator.
28
+ * The logic is split across sibling modules — cli.js (I/O), metadata.js (the
29
+ * prebuilt-metadata document), classify.js (discovery), app-target.js (the app's
30
+ * Xcode target), flavored-frameworks.js (precompiled frameworks),
31
+ * react-descriptor.js + manifests.js (rendering),
32
+ * podspec.js (podspec reading), autolink-gate.js (`autolinkWhen` gates),
33
+ * script-phases.js (build script phases), diagnostics.js (errors and
34
+ * warnings) — with unit tests in __tests__/. This file is just the orchestrator.
31
35
  */
32
36
 
33
37
  'use strict';
@@ -35,24 +39,577 @@
35
39
  const fs = require('fs');
36
40
  const path = require('path');
37
41
 
38
- const { resolveAppTarget } = require('./app-target');
42
+ const { readPodfileProperties, resolveAppTarget } = require('./app-target');
43
+ const {
44
+ autolinkConditionKey,
45
+ autolinkConditionLabel,
46
+ autolinkConditionMet,
47
+ } = require('./autolink-gate');
39
48
  const { resolveExpoModules, generateModulesProvider } = require('./cli');
40
- const { collectWatchPaths, findModuleRoot, moduleNeedsReact, isPureSwift } = require('./classify');
49
+ const {
50
+ collectWatchPaths,
51
+ documentedPackageRoot,
52
+ findModuleRoot,
53
+ moduleNeedsReact,
54
+ scanAppleSources,
55
+ } = require('./classify');
41
56
  const {
42
57
  classifyUnsupported,
43
- collectUnmappedDependencies,
58
+ collectDuplicatePods,
59
+ collectRootConflicts,
60
+ pluginError,
61
+ realPathOrSelf,
62
+ renderExtraPodsWarning,
63
+ renderLeftOutCompanionWarning,
64
+ renderPartlyProvidedPackageWarning,
65
+ renderRootConflictWarning,
44
66
  renderUnmappedDependencyWarning,
45
67
  renderXcconfigLinkerWarning,
46
68
  reportUnsupported,
47
- spmConfigProduct,
69
+ unmappedPodDependencies,
48
70
  } = require('./diagnostics');
49
- const { prepareCompileInterfaces, resolveFlavoredFramework } = require('./flavored-frameworks');
71
+ const {
72
+ artifactBaseDirs,
73
+ assertDistinctFlavoredFrameworks,
74
+ byteOrder,
75
+ prepareCompileInterfaces,
76
+ resolveFlavoredFramework,
77
+ resolveSpmDependencyFrameworks,
78
+ } = require('./flavored-frameworks');
50
79
  const { emitSourceManifestPackage, emitPureSwiftSourcePackage } = require('./manifests');
51
- const { PodspecSyntaxError, readPodspecs } = require('./podspec');
80
+ const { readPrebuiltMetadata } = require('./metadata');
81
+ const { readPodspecFacts } = require('./podspec');
52
82
  const { scriptPhasesForModules } = require('./script-phases');
53
83
 
84
+ const CORE_POD = 'ExpoModulesCore';
85
+
86
+ /** npm name → autolinked root, only for roots still on disk. */
87
+ function collectAutolinkedRoots(autolinking) {
88
+ const roots = new Map();
89
+ for (const [packageName, dependency] of Object.entries(autolinking?.dependencies ?? {})) {
90
+ if (dependency?.root != null && fs.existsSync(dependency.root)) {
91
+ roots.set(packageName, dependency.root);
92
+ }
93
+ }
94
+ return roots;
95
+ }
96
+
97
+ /**
98
+ * Root: documented (if on disk) → autolinked → walk. The product name can differ from
99
+ * the pod name (react-native-skia → RNSkia).
100
+ *
101
+ * `declaringRoot` is the root of the package that lists the pod: the document is keyed
102
+ * by pod name, so it documents only one of two packages that list the same pod. A
103
+ * podspec dir that is gone is its own declaring root, or two missing packages would
104
+ * walk up to one ancestor and pass for one.
105
+ */
106
+ function podIdentity(record, pod, packageName, autolinkedRoot, scanSources) {
107
+ const documentedRoot = documentedPackageRoot(record);
108
+ const walkedRoot = autolinkedRoot ?? findModuleRoot(pod.podspecDir);
109
+ const declaringRoot =
110
+ autolinkedRoot == null && !fs.existsSync(pod.podspecDir) ? pod.podspecDir : walkedRoot;
111
+ const moduleRoot = documentedRoot ?? walkedRoot;
112
+ return {
113
+ podName: pod.podName,
114
+ packageName,
115
+ documentedRoot,
116
+ autolinkedRoot,
117
+ declaringRoot,
118
+ moduleRoot,
119
+ productName: record?.productName ?? pod.podName,
120
+ prebuildProduct:
121
+ record != null ? { name: record.productName, sourceOnly: record.sourceOnly } : null,
122
+ iosDeploymentTarget: record?.iosDeploymentTarget ?? null,
123
+ spmPackages: record?.spmPackages ?? [],
124
+ autolinkWhen: record?.autolinkWhen ?? null,
125
+ sources: scanSources(moduleRoot),
126
+ podspec: readPodspecFacts({ podName: pod.podName, podspecDir: pod.podspecDir, moduleRoot }),
127
+ };
128
+ }
129
+
130
+ /**
131
+ * Every pod's identity, keyed by the pod, resolved once so every pass agrees on it.
132
+ *
133
+ * @param metadata `readPrebuiltMetadata()`: records by pod name.
134
+ */
135
+ function resolvePodIdentities(modules, metadata, autolinkedRoots) {
136
+ const sourceScans = new Map();
137
+ const scanSources = (moduleRoot) =>
138
+ sourceScans.get(moduleRoot) ??
139
+ sourceScans.set(moduleRoot, scanAppleSources(moduleRoot)).get(moduleRoot);
140
+ const identities = new Map();
141
+ for (const mod of modules) {
142
+ for (const pod of mod.pods ?? []) {
143
+ identities.set(
144
+ pod,
145
+ podIdentity(
146
+ metadata.get(pod.podName),
147
+ pod,
148
+ mod.packageName,
149
+ autolinkedRoots.get(mod.packageName),
150
+ scanSources
151
+ )
152
+ );
153
+ }
154
+ }
155
+ return identities;
156
+ }
157
+
158
+ /**
159
+ * `autolinkWhen` by package root, then product name (first entry wins). Read from the
160
+ * document: autolinking never resolves a companion pod such as expo-camera's barcode scanner.
161
+ */
162
+ function indexAutolinkConditions(metadata) {
163
+ const byRoot = new Map();
164
+ for (const { packageRoot, productName, autolinkWhen } of metadata.values()) {
165
+ if (packageRoot == null) continue;
166
+ const root = path.resolve(packageRoot);
167
+ const products = byRoot.get(root) ?? new Map();
168
+ byRoot.set(root, products);
169
+ if (!products.has(productName)) products.set(productName, autolinkWhen);
170
+ }
171
+ return byRoot;
172
+ }
173
+
174
+ /**
175
+ * The gate for one product of the module at `moduleRoot`, or null when it declares
176
+ * none. A product no entry matches stays ungated: withholding one because a path
177
+ * failed to line up would drop a module with no diagnostic at all.
178
+ */
179
+ function productAutolinkCondition(autolinkConditions, moduleRoot, productName) {
180
+ return autolinkConditions.get(path.resolve(moduleRoot))?.get(productName) ?? null;
181
+ }
182
+
183
+ /**
184
+ * The gated products autolinking never resolves as a pod, by package root: companions
185
+ * such as expo-camera's barcode scanner, which only a checked-in manifest links.
186
+ */
187
+ function indexGatedCompanions(metadata, records) {
188
+ const byRoot = new Map();
189
+ for (const [podName, { packageRoot, productName, autolinkWhen }] of metadata) {
190
+ if (autolinkWhen == null || packageRoot == null || records.has(podName)) continue;
191
+ const root = path.resolve(packageRoot);
192
+ byRoot.set(root, [...(byRoot.get(root) ?? []), { podName, productName, autolinkWhen }]);
193
+ }
194
+ return byRoot;
195
+ }
196
+
197
+ /**
198
+ * Only a checked-in manifest's products have their autolinkWhen checked. A gated pod
199
+ * linked any other way fails the sync whichever way its condition falls. Its module's
200
+ * gated companions are left out, which differs from CocoaPods only where a companion's
201
+ * condition is met. Such a companion fails the sync only when a Podfile property
202
+ * decides it, because the app can switch that off; a pod or npm package condition is
203
+ * met by what the app installs for its own reasons, so refusing it would block the app.
204
+ *
205
+ * @param linked the precompiled and pure-Swift records, in pass order.
206
+ * @returns the `refusals` that fail the sync, and the `leftOutCompanions` to warn about.
207
+ */
208
+ function uncheckedAutolinkConditions(linked, { gatedCompanions, manifestRoots, autolinkGate }) {
209
+ const companionRootsSeen = new Set();
210
+ const refusals = [];
211
+ const leftOutCompanions = [];
212
+ for (const { identity, linkedAs } of linked) {
213
+ const { podName, packageName, moduleRoot, productName, autolinkWhen } = identity;
214
+ const subject = { packageName, moduleRoot, precompiled: linkedAs === 'precompiled' };
215
+ const refusal = { reason: 'unchecked-autolink-condition', ...subject };
216
+ if (autolinkWhen != null) refusals.push({ ...refusal, podName, productName });
217
+ const root = path.resolve(moduleRoot);
218
+ if (manifestRoots.has(root) || companionRootsSeen.has(root)) continue;
219
+ companionRootsSeen.add(root);
220
+ for (const companion of gatedCompanions.get(root) ?? []) {
221
+ if (!autolinkConditionMet(companion.autolinkWhen, autolinkGate)) continue;
222
+ if (autolinkConditionKey(companion.autolinkWhen) === 'podfileProperty') {
223
+ refusals.push({ ...refusal, ...companion, linkedThrough: podName });
224
+ } else {
225
+ leftOutCompanions.push({ ...subject, ...companion, linkedThrough: podName });
226
+ }
227
+ }
228
+ }
229
+ return { refusals, leftOutCompanions };
230
+ }
231
+
232
+ /**
233
+ * The gated companions a checked-in manifest does not export, where their condition
234
+ * is met: there CocoaPods would link them. Matched by real path, because a companion's
235
+ * documented root and its module's root can reach one directory through different
236
+ * symlinks.
237
+ */
238
+ function companionsNotExportedByManifests(emitted, { gatedCompanions, autolinkGate }) {
239
+ const companionsByRealRoot = new Map();
240
+ for (const [root, companions] of gatedCompanions) {
241
+ const realRoot = realPathOrSelf(root);
242
+ companionsByRealRoot.set(realRoot, [
243
+ ...(companionsByRealRoot.get(realRoot) ?? []),
244
+ ...companions,
245
+ ]);
246
+ }
247
+ return emitted
248
+ .filter((r) => r.linkedAs === 'manifest')
249
+ .flatMap(({ identity: { packageName, moduleRoot }, emission }) => {
250
+ const exported = new Set(emission.productDeps.map((dep) => dep.name));
251
+ return (companionsByRealRoot.get(realPathOrSelf(moduleRoot)) ?? [])
252
+ .filter(
253
+ (companion) =>
254
+ !exported.has(companion.productName) &&
255
+ autolinkConditionMet(companion.autolinkWhen, autolinkGate)
256
+ )
257
+ .map((companion) => ({
258
+ reason: 'companion-not-exported-by-manifest',
259
+ packageName,
260
+ moduleRoot,
261
+ ...companion,
262
+ }));
263
+ });
264
+ }
265
+
266
+ /**
267
+ * A pod nothing covers, with every refusal that applies to it: those recorded at
268
+ * its module root, if any, and what its identity alone says. `classifyUnsupported`
269
+ * reports the most specific of them.
270
+ */
271
+ function uncoveredPod(identity, ...refusals) {
272
+ const { podName, packageName, moduleRoot, prebuildProduct, sources } = identity;
273
+ const productName = prebuildProduct?.name ?? null;
274
+ const prebuildable = prebuildProduct != null && !prebuildProduct.sourceOnly;
275
+ const ownReport = {
276
+ reason: sources.hasSources ? 'mixed-no-manifest' : 'no-apple-sources',
277
+ productName,
278
+ };
279
+ const candidates = [
280
+ ...refusals,
281
+ prebuildable ? { reason: 'prebuild-available', productName } : null,
282
+ ownReport,
283
+ ];
284
+ return { podName, packageName, moduleRoot, refusals: candidates.filter((r) => r != null) };
285
+ }
286
+
287
+ /**
288
+ * What the passes decided for each pod, keyed by pod name: CocoaPods pod names are
289
+ * unique, so a name two packages list is one pod. `linkedAs` is `'precompiled'`,
290
+ * `'manifest'`, `'pure-swift'` or null. A precompiled record carries its
291
+ * `framework`.
292
+ */
293
+ function podRecords(identities) {
294
+ const records = new Map();
295
+ for (const identity of identities.values()) {
296
+ if (!records.has(identity.podName)) {
297
+ records.set(identity.podName, { identity, linkedAs: null });
298
+ }
299
+ }
300
+ return records;
301
+ }
302
+
303
+ /**
304
+ * Pass 1 — precompiled runtime frameworks. The declaration is all-or-nothing:
305
+ * once one flavor exists, the resolver requires and prepares both before RN
306
+ * receives the plugin result. No runtime binary enters the SwiftPM graph.
307
+ * A pod name several packages list is looked up from each of them, in order,
308
+ * until one has an artifact. Returns the records it linked, in that order.
309
+ */
310
+ function linkPrecompiledPods(identities, records, cacheDir) {
311
+ const linked = [];
312
+ for (const identity of identities.values()) {
313
+ const record = records.get(identity.podName);
314
+ if (record.linkedAs != null) continue;
315
+ const framework = resolveFlavoredFramework({
316
+ packageName: identity.packageName,
317
+ moduleRoot: identity.moduleRoot,
318
+ frameworkName: identity.productName,
319
+ cacheDir,
320
+ });
321
+ if (framework == null) continue;
322
+ Object.assign(record, { identity, linkedAs: 'precompiled', framework });
323
+ linked.push(record);
324
+ }
325
+ return linked;
326
+ }
327
+
328
+ /**
329
+ * Emits the source package of the module whose first pod is `identity`: its
330
+ * checked-in manifest mirrored, or else one Swift target over its sources. A
331
+ * pure-Swift module is refused when its podspec declares linkage, because the
332
+ * emitted package would link less than the podspec does. Returns null for a module
333
+ * with no sources: the pod's own `no-apple-sources` report covers it.
334
+ */
335
+ function emitSourceModule(identity, hasManifest, emitContext) {
336
+ const { moduleRoot, podName, iosDeploymentTarget, spmPackages, sources, podspec } = identity;
337
+ if (hasManifest) return emitSourceManifestPackage(moduleRoot, emitContext);
338
+ if (podspec.linkage != null) {
339
+ return { refusal: { reason: 'needs-manifest-for-linkage', ...podspec.linkage } };
340
+ }
341
+ if (!sources.hasSources) return null;
342
+ return emitPureSwiftSourcePackage(
343
+ { moduleRoot, product: podName, iosDeploymentTarget, spmPackages, sources },
344
+ emitContext
345
+ );
346
+ }
347
+
348
+ /**
349
+ * Pass 2 — invariant source modules. They compile against the generated
350
+ * headers/module-interface tree and leave runtime linking entirely to RN.
351
+ *
352
+ * @param emitContext what every emitted package is generated against.
353
+ * @returns `emitted`, one `{ identity, linkedAs, emission }` per package it emitted, in
354
+ * emission order, `identity` being the pod it was emitted for; and `refusals`, by
355
+ * module root and then reason, each a function from an uncovered pod's identity to
356
+ * its refusal.
357
+ */
358
+ function linkSourceModules(modules, identities, records, emitContext) {
359
+ const emitted = [];
360
+ const refusals = new Map();
361
+ // What the branches below read comes from the first pod's module root, so a
362
+ // refusal they record applies to every uncovered pod at that root, whichever
363
+ // package lists it.
364
+ const refuse = (root, reason, refusalFor) =>
365
+ refusals.set(root, (refusals.get(root) ?? new Map()).set(reason, refusalFor));
366
+ const linkedAs = (identity) => records.get(identity.podName).linkedAs;
367
+ const manifestProductsByRoot = new Map();
368
+ for (const mod of modules) {
369
+ const pods = (mod.pods ?? []).map((pod) => identities.get(pod));
370
+ if (!pods.length || pods.every(linkedAs)) continue;
371
+
372
+ const [first] = pods;
373
+ const { moduleRoot, sources } = first;
374
+ const hasManifest = fs.existsSync(path.join(moduleRoot, 'Package.swift'));
375
+
376
+ const precompiledSiblings = pods.filter((p) => linkedAs(p) === 'precompiled');
377
+ if (precompiledSiblings.length > 0 && (hasManifest || sources.pureSwift)) {
378
+ // Both source branches build the whole module, so emitting it would link
379
+ // the precompiled pods a second time, from source.
380
+ const siblings = {
381
+ precompiledSiblings: precompiledSiblings.map((p) => p.podName),
382
+ precompiledProducts: precompiledSiblings.map((p) => p.productName),
383
+ artifactDirs: artifactBaseDirs(mod.packageName, moduleRoot),
384
+ };
385
+ refuse(moduleRoot, 'partially-precompiled', (p) => ({
386
+ reason: 'partially-precompiled',
387
+ ...siblings,
388
+ prebuildProduct: p.prebuildProduct,
389
+ }));
390
+ continue;
391
+ }
392
+ // A manifest is emitted once, by whichever listing reaches it first; every listing
393
+ // then links the pods whose product it exports, so the order they come in decides
394
+ // nothing.
395
+ const realRoot = hasManifest ? fs.realpathSync(moduleRoot) : null;
396
+ let manifestProducts = manifestProductsByRoot.get(realRoot);
397
+ if (manifestProducts == null) {
398
+ // Only this pod is built; siblings must stay pending to be diagnosed.
399
+ const covered = hasManifest ? pods : [first];
400
+ if (covered.some(linkedAs)) continue;
401
+ // A module with no sources at all scans as pure Swift too, so it reaches
402
+ // emitSourceModule for the podspec linkage check that outranks it.
403
+ if (!hasManifest && !sources.pureSwift) continue;
404
+
405
+ const emission = emitSourceModule(first, hasManifest, emitContext);
406
+ if (emission == null) continue;
407
+ const { refusal, ok } = emission;
408
+ if (refusal != null) {
409
+ refuse(moduleRoot, refusal.reason, () => refusal);
410
+ continue;
411
+ }
412
+ const kind = hasManifest ? 'manifest' : 'pure-swift';
413
+ emitted.push({ identity: first, linkedAs: kind, emission: ok });
414
+ if (!hasManifest) {
415
+ Object.assign(records.get(first.podName), { identity: first, linkedAs: kind });
416
+ continue;
417
+ }
418
+ manifestProducts = new Set(ok.productDeps.map((dep) => dep.name));
419
+ manifestProductsByRoot.set(realRoot, manifestProducts);
420
+ }
421
+ for (const p of pods) {
422
+ if (linkedAs(p)) continue;
423
+ if (manifestProducts.has(p.productName)) {
424
+ Object.assign(records.get(p.podName), { identity: p, linkedAs: 'manifest' });
425
+ } else {
426
+ refuse(moduleRoot, 'not-exported-by-manifest', (u) => ({
427
+ reason: 'not-exported-by-manifest',
428
+ productName: u.productName,
429
+ exportedProducts: [...manifestProducts],
430
+ }));
431
+ }
432
+ }
433
+ }
434
+ return { emitted, refusals };
435
+ }
436
+
437
+ /**
438
+ * The emitted products React Native links, and a label for each one an unmet
439
+ * `autolinkWhen` condition withholds. Only a checked-in manifest's products are
440
+ * checked: its emitted package keeps every target, and a withheld product is simply
441
+ * never depended on, so SwiftPM never builds it.
442
+ */
443
+ function gateProducts(emitted, autolinkConditions, autolinkGate) {
444
+ const productDependencies = [];
445
+ const gatedOffProducts = [];
446
+ for (const { identity, linkedAs, emission } of emitted) {
447
+ for (const dep of emission.productDeps) {
448
+ const condition =
449
+ linkedAs === 'manifest'
450
+ ? productAutolinkCondition(autolinkConditions, identity.moduleRoot, dep.name)
451
+ : null;
452
+ if (condition != null && !autolinkConditionMet(condition, autolinkGate)) {
453
+ gatedOffProducts.push(
454
+ `${dep.name} (${autolinkConditionLabel(condition) ?? 'unrecognized condition'})`
455
+ );
456
+ } else {
457
+ productDependencies.push(dep);
458
+ }
459
+ }
460
+ }
461
+ return { productDependencies, gatedOffProducts };
462
+ }
463
+
464
+ /**
465
+ * Everything that follows from the pod records once both passes ran: the source
466
+ * packages and products React Native links, the pods nothing covers, the
467
+ * diagnostics, and what each pass linked. Each check runs once per pod, in pass
468
+ * order — the precompiled pods, then the modules pass 2 emitted. `precompiled` is
469
+ * what `linkPrecompiledPods` returned; `emitted` and `refusals` are what
470
+ * `linkSourceModules` returned; `gatedCompanions` is what `indexGatedCompanions` returned.
471
+ *
472
+ * @param satisfiedDependencies the SwiftPM packages already declared as frameworks.
473
+ */
474
+ function summarizeRecords(
475
+ records,
476
+ {
477
+ precompiled,
478
+ emitted,
479
+ refusals,
480
+ react,
481
+ satisfiedDependencies,
482
+ autolinkConditions,
483
+ gatedCompanions,
484
+ autolinkGate,
485
+ }
486
+ ) {
487
+ const pureSwift = emitted.filter((r) => r.linkedAs === 'pure-swift');
488
+ const refusalsFor = (identity) =>
489
+ [...(refusals.get(identity.moduleRoot)?.values() ?? [])].map((refusalFor) =>
490
+ refusalFor(identity)
491
+ );
492
+ const pending = [...records.values()]
493
+ .filter((r) => r.linkedAs == null)
494
+ .map(({ identity }) => uncoveredPod(identity, ...refusalsFor(identity)));
495
+
496
+ // What the resolved dependencies already carry is not uncovered, their subspecs
497
+ // included.
498
+ const unmappedDeps = [...precompiled, ...emitted]
499
+ .map((record) => ({
500
+ packageName: record.identity.packageName,
501
+ podName: record.identity.podName,
502
+ pods: unmappedPodDependencies(
503
+ record.identity.podspec.dependencies,
504
+ new Set([...satisfiedDependencies, ...(record.emission?.spmProductNames ?? [])])
505
+ ),
506
+ }))
507
+ .filter((entry) => entry.pods.length > 0);
508
+ const unchecked = uncheckedAutolinkConditions([...precompiled, ...pureSwift], {
509
+ gatedCompanions,
510
+ manifestRoots: new Set(
511
+ emitted
512
+ .filter((r) => r.linkedAs === 'manifest')
513
+ .map((r) => path.resolve(r.identity.moduleRoot))
514
+ ),
515
+ autolinkGate,
516
+ });
517
+ const unexportedCompanions = companionsNotExportedByManifests(emitted, {
518
+ gatedCompanions,
519
+ autolinkGate,
520
+ });
521
+ const xcconfigLinkage = pureSwift
522
+ .filter(({ identity }) => identity.podspec.linkerFlags != null)
523
+ .map(({ identity }) => ({
524
+ packageName: identity.packageName,
525
+ podName: identity.podName,
526
+ ...identity.podspec.linkerFlags,
527
+ }));
528
+
529
+ const reactWired = [
530
+ ...precompiled.filter(({ identity }) => moduleNeedsReact(identity.podName, identity.sources)),
531
+ ...(react != null ? emitted : []),
532
+ ];
533
+ const podNames = (list) => list.map((r) => r.identity.podName);
534
+
535
+ return {
536
+ packageDependencies: emitted.map((r) => r.emission.packageDep),
537
+ ...gateProducts(emitted, autolinkConditions, autolinkGate),
538
+ pending,
539
+ uncheckedConditions: unchecked.refusals,
540
+ leftOutCompanions: unchecked.leftOutCompanions,
541
+ unexportedCompanions,
542
+ unmappedDeps,
543
+ partlyProvidedPackages: emitted.flatMap(({ identity: { packageName, moduleRoot }, emission }) =>
544
+ emission.partlyProvidedPackages.map((pkg) => ({ packageName, moduleRoot, ...pkg }))
545
+ ),
546
+ xcconfigLinkage,
547
+ precompiledPods: podNames(precompiled),
548
+ manifestPackages: emitted
549
+ .filter((r) => r.linkedAs === 'manifest')
550
+ .map((r) => r.identity.packageName),
551
+ pureSwiftPods: podNames(pureSwift),
552
+ reactWiredPods: podNames(reactWired),
553
+ };
554
+ }
555
+
556
+ /**
557
+ * The staleness inputs (`watchPaths` plugin contract) whose edits must trip RN's
558
+ * in-build re-sync: each module's checked-in Package.swift and
559
+ * expo-module.config.json, which drive the generated packages and module
560
+ * resolution; and the registry's app-target inputs — app groups come from the
561
+ * entitlements file, inline-module registration from Podfile.properties.json.
562
+ * Known gap: repointing CODE_SIGN_ENTITLEMENTS at a different file is not noticed,
563
+ * because that would mean watching project.pbxproj — which RN rewrites during the
564
+ * sync itself.
565
+ */
566
+ function watchPaths(identities, { entitlementPath, podfilePropertiesPath }) {
567
+ const moduleRoots = new Set([...identities.values()].map((identity) => identity.moduleRoot));
568
+ return [
569
+ ...collectWatchPaths([...moduleRoots]),
570
+ ...[entitlementPath, podfilePropertiesPath].filter((p) => p != null),
571
+ ];
572
+ }
573
+
574
+ // Swift macros need the prebuilt plugin executable; mirrors
575
+ // project_integrator.rb#resolve_macros_plugin_dir.
576
+ // It declares no SwiftPM products, so it travels as a compiler flag, not a dependency.
577
+ function macroPluginFlags(coreModuleRoot) {
578
+ const macroPluginFault = (
579
+ what,
580
+ missing,
581
+ how = 'Reinstall your JavaScript dependencies and build again.'
582
+ ) => ({
583
+ what,
584
+ why: `Expo modules are compiled from source here, and their Swift macros cannot expand without ${missing} — the build would fail with "external macro implementation could not be found".`,
585
+ how,
586
+ });
587
+ let pkgJsonPath;
588
+ try {
589
+ pkgJsonPath = require.resolve('expo-modules-macros/package.json', {
590
+ paths: [coreModuleRoot],
591
+ });
592
+ } catch (error) {
593
+ throw pluginError(
594
+ macroPluginFault(
595
+ `Could not resolve "expo-modules-macros" from ${coreModuleRoot}.`,
596
+ 'this plugin',
597
+ '"expo-modules-core" must be a version that depends on "expo-modules-macros", the new name of "@expo/expo-modules-macros-plugin". Run `npx expo install --fix` to align the Expo package versions, then build again.'
598
+ ),
599
+ { cause: error }
600
+ );
601
+ }
602
+ const tool = path.join(path.dirname(pkgJsonPath), 'apple', 'ExpoModulesMacros');
603
+ if (!fs.existsSync(tool)) {
604
+ throw pluginError(
605
+ macroPluginFault(`The Expo Swift macro plugin is missing its executable at ${tool}.`, 'it')
606
+ );
607
+ }
608
+ return ['-Xfrontend', '-load-plugin-executable', '-Xfrontend', `${tool}#ExpoModulesMacros`];
609
+ }
610
+
54
611
  module.exports = function expoSpmPlugin(context) {
55
- const { react, outputDir } = context;
612
+ const { autolinking, react, outputDir } = context;
56
613
  // `context.appRoot` is the Xcode project dir (`<app>/ios`); the autolinking
57
614
  // CLI's --app-root must be the app PACKAGE root, because
58
615
  // `generate-modules-provider` filters modules against that dir's package.json
@@ -60,7 +617,30 @@ module.exports = function expoSpmPlugin(context) {
60
617
  // provider, with no Expo modules registering at runtime. RN's contract hands
61
618
  // us that root directly.
62
619
  const appRoot = context.projectRoot;
63
- const modules = resolveExpoModules(appRoot);
620
+ const { modules, extraDependencies } = resolveExpoModules(appRoot);
621
+ const metadata = readPrebuiltMetadata(appRoot);
622
+ const autolinkedRoots = collectAutolinkedRoots(autolinking);
623
+ const identities = resolvePodIdentities(modules, metadata, autolinkedRoots);
624
+ // Before either pass: which copy of a pod the passes reached first depends on the
625
+ // order the packages were autolinked in, so linking any of them would too.
626
+ const duplicatePods = reportUnsupported(collectDuplicatePods(identities));
627
+ if (duplicatePods != null) {
628
+ throw duplicatePods;
629
+ }
630
+ const autolinkConditions = indexAutolinkConditions(metadata);
631
+ // Read once so gating and registry agree.
632
+ const appTarget = resolveAppTarget(context.appRoot);
633
+ const autolinkGate = {
634
+ // Every pod the install DECLARES, not the ones linked: a declared pod
635
+ // CocoaPods links is a satisfied condition here too.
636
+ declaredPodNames: new Set(metadata.keys()),
637
+ // CocoaPods counts React Native's autolinked packages by key, root on disk or not.
638
+ autolinkedPackages: new Set([
639
+ ...modules.map((m) => m.packageName),
640
+ ...Object.keys(autolinking?.dependencies ?? {}),
641
+ ]),
642
+ podfileProperties: readPodfileProperties(appTarget.podfilePropertiesPath),
643
+ };
64
644
  const outDir = path.join(outputDir, 'expo');
65
645
  // The old contract generated mutable binaryTarget packages here. They are
66
646
  // invalid under automatic configuration selection and must never survive a
@@ -74,184 +654,89 @@ module.exports = function expoSpmPlugin(context) {
74
654
  ? codegenCandidate
75
655
  : null;
76
656
 
77
- const packageDependencies = [];
78
- const productDependencies = [];
79
- const emitted = new Set(); // pod names already contributed
80
- const reactWired = []; // pods that got React wired (for logging)
81
- const sourceManifest = []; // packages emitted from a checked-in manifest
82
- const pureSwiftSource = []; // packages emitted from a pure-Swift descriptor
83
- const unmappedDeps = []; // emitted pods depending on pods with no SwiftPM counterpart
84
- const xcconfigLinkage = []; // emitted pods whose podspec xcconfig sets linker flags
85
- const unresolvedTargets = new Map(); // module root → manifest targets with no sources on disk
86
- const unsupportedTargetDeps = new Map(); // module root → deps the generated package cannot declare
87
- const podspecErrors = new Map(); // module root → podspec line the reader refused
88
- const podspecLinkage = new Map(); // module root → podspec line declaring native linkage
89
-
90
- // Pass 1 — precompiled runtime frameworks. The declaration is all-or-nothing:
91
- // once one flavor exists, the resolver requires and prepares both before RN
92
- // receives the plugin result. No runtime binary enters the SwiftPM graph.
93
- const precompiledFrameworks = new Map();
94
- const flavoredFrameworks = [];
95
- for (const mod of modules) {
96
- for (const pod of mod.pods ?? []) {
97
- if (emitted.has(pod.podName)) continue;
98
- const moduleRoot = findModuleRoot(pod.podspecDir);
99
- const needsReact = moduleNeedsReact(pod.podName, moduleRoot);
100
- const framework = resolveFlavoredFramework({
101
- packageName: mod.packageName,
102
- moduleRoot,
103
- frameworkName: pod.podName,
104
- cacheDir: artifactCacheDir,
105
- });
106
- if (framework != null) {
107
- precompiledFrameworks.set(pod.podName, framework);
108
- flavoredFrameworks.push(framework);
109
- emitted.add(pod.podName);
110
- if (needsReact) reactWired.push(pod.podName);
111
- }
112
- }
113
- }
114
- flavoredFrameworks.sort((a, b) => a.id.localeCompare(b.id));
657
+ const records = podRecords(identities);
658
+ const precompiled = linkPrecompiledPods(identities, records, artifactCacheDir);
659
+ // The SwiftPM packages those modules link ship as their own XCFrameworks, and
660
+ // RN takes them in the same flat array. They join before the interface tree is
661
+ // built, so source modules compile against their headers too.
662
+ const dependencyFrameworks = resolveSpmDependencyFrameworks(
663
+ precompiled.map(({ identity: { podName, moduleRoot, spmPackages } }) => ({
664
+ podName,
665
+ moduleRoot,
666
+ spmDependencies: spmPackages.map((pkg) => pkg.productName),
667
+ }))
668
+ );
669
+ const flavoredFrameworks = [...precompiled.map((r) => r.framework), ...dependencyFrameworks].sort(
670
+ (a, b) => byteOrder(a.id, b.id)
671
+ );
672
+ assertDistinctFlavoredFrameworks(flavoredFrameworks);
673
+ const satisfiedDependencies = new Set(dependencyFrameworks.map((f) => f.frameworkName));
115
674
  const frameworkSearchPath =
116
- precompiledFrameworks.size > 0
675
+ precompiled.length > 0
117
676
  ? prepareCompileInterfaces(flavoredFrameworks, path.join(outDir, 'compile-interfaces'))
118
677
  : null;
119
678
 
120
- // Pass 2 — invariant source modules. They compile against the generated
121
- // headers/module-interface tree and leave runtime linking entirely to RN.
122
- const coreAvailable = precompiledFrameworks.has('ExpoModulesCore') && frameworkSearchPath != null;
679
+ const core = precompiled.find((r) => r.identity.podName === CORE_POD)?.identity ?? null;
680
+ const coreAvailable = core != null && frameworkSearchPath != null;
681
+ let sourceModules = { emitted: [], refusals: new Map() };
123
682
  if (coreAvailable) {
124
- for (const mod of modules) {
125
- const pods = mod.pods ?? [];
126
- if (!pods.length || pods.every((p) => emitted.has(p.podName))) continue;
127
- const pod = pods[0];
128
- const moduleRoot = findModuleRoot(pod.podspecDir);
129
-
130
- if (fs.existsSync(path.join(moduleRoot, 'Package.swift'))) {
131
- // (A) module ships a checked-in Package.swift → mirror its targets + inject deps.
132
- const e = emitSourceManifestPackage(
133
- moduleRoot,
134
- react,
135
- frameworkSearchPath,
136
- outDir,
137
- codegenPkgPath
138
- );
139
- if (e.unsupportedTargetDeps != null) {
140
- unsupportedTargetDeps.set(moduleRoot, e.unsupportedTargetDeps);
141
- } else if (e.unresolvedTargets != null) {
142
- unresolvedTargets.set(moduleRoot, e.unresolvedTargets);
143
- } else {
144
- packageDependencies.push(e.packageDep);
145
- productDependencies.push(...e.productDeps);
146
- pods.forEach((p) => emitted.add(p.podName));
147
- sourceManifest.push(mod.packageName);
148
- if (react != null) reactWired.push(pod.podName);
149
- }
150
- } else if (isPureSwift(moduleRoot)) {
151
- // Pure-Swift module → single Swift target over its ios sources. Its podspec
152
- // supplies nothing but the deployment floor: a module whose linkage only the
153
- // podspec declares is skipped and diagnosed, never emitted half-linked.
154
- let podspecs = null;
155
- try {
156
- podspecs = readPodspecs(
157
- pod.podName,
158
- [
159
- pod.podspecDir,
160
- path.join(moduleRoot, 'ios'),
161
- path.join(moduleRoot, 'apple'),
162
- moduleRoot,
163
- ].filter(Boolean)
164
- );
165
- } catch (error) {
166
- if (!(error instanceof PodspecSyntaxError)) throw error;
167
- podspecErrors.set(moduleRoot, error);
168
- }
169
- if (podspecs?.linkage != null) podspecLinkage.set(moduleRoot, podspecs.linkage);
170
- const e =
171
- podspecs == null || podspecs.linkage != null
172
- ? null
173
- : emitPureSwiftSourcePackage(
174
- moduleRoot,
175
- pod.podName,
176
- react,
177
- frameworkSearchPath,
178
- outDir,
179
- codegenPkgPath,
180
- podspecs.iosDeploymentTarget
181
- );
182
- if (e != null) {
183
- packageDependencies.push(e.packageDep);
184
- productDependencies.push(e.productDep);
185
- pods.forEach((p) => emitted.add(p.podName));
186
- pureSwiftSource.push(pod.podName);
187
- if (react != null) reactWired.push(pod.podName);
188
- if (podspecs.linkerFlags != null) {
189
- xcconfigLinkage.push({
190
- packageName: mod.packageName,
191
- podName: pod.podName,
192
- ...podspecs.linkerFlags,
193
- });
194
- }
195
- }
196
- }
197
-
198
- if (emitted.has(pod.podName)) {
199
- const unmapped = collectUnmappedDependencies(pod.podspecDir);
200
- if (unmapped.length > 0) {
201
- unmappedDeps.push({
202
- packageName: mod.packageName,
203
- podName: pod.podName,
204
- pods: unmapped,
205
- });
206
- }
207
- }
208
- }
683
+ let resolvedMacroFlags = null;
684
+ sourceModules = linkSourceModules(modules, identities, records, {
685
+ react,
686
+ frameworkSearchPath,
687
+ outDir,
688
+ codegenPkgPath,
689
+ minimumIosDeploymentTarget: core.iosDeploymentTarget,
690
+ satisfiedDependencies,
691
+ // Every emitted target may use the macros (CocoaPods' "is core or depends on core" gate).
692
+ // Lazy: an install that emits no source package needs no macro plugin.
693
+ get macroFlags() {
694
+ return (resolvedMacroFlags ??= macroPluginFlags(core.moduleRoot));
695
+ },
696
+ });
209
697
  }
210
698
 
211
699
  // Anything still uncovered has no xcframework and no way to be built from
212
- // source. Collect the facts each diagnostic needs, then report and fail —
213
- // dropping a module here would surface as a runtime "Cannot find native
214
- // module" instead of a build error.
215
- const pending = [];
216
- for (const mod of modules) {
217
- for (const pod of mod.pods ?? []) {
218
- if (emitted.has(pod.podName)) continue;
219
- const moduleRoot = findModuleRoot(pod.podspecDir);
220
- pending.push({
221
- podName: pod.podName,
222
- packageName: mod.packageName,
223
- moduleRoot,
224
- pureSwift: isPureSwift(moduleRoot),
225
- hasSources: ['ios', 'apple'].some((s) => fs.existsSync(path.join(moduleRoot, s))),
226
- unsupportedTargetDeps: unsupportedTargetDeps.get(moduleRoot) ?? null,
227
- unresolvedTargets: unresolvedTargets.get(moduleRoot) ?? null,
228
- podspecError: podspecErrors.get(moduleRoot) ?? null,
229
- podspecLinkage: podspecLinkage.get(moduleRoot) ?? null,
230
- prebuildProduct: spmConfigProduct(moduleRoot, pod.podName),
231
- });
232
- }
233
- }
234
-
235
- console.log(
236
- `[expo-spm-plugin] paired runtime frameworks (${precompiledFrameworks.size}): ${[...precompiledFrameworks.keys()].join(', ') || '—'}`
237
- );
238
- console.log(
239
- `[expo-spm-plugin] source via checked-in manifest (${sourceManifest.length}): ${sourceManifest.join(', ') || '—'}`
240
- );
241
- console.log(
242
- `[expo-spm-plugin] source pure-Swift (${pureSwiftSource.length}): ${pureSwiftSource.join(', ') || '—'}`
243
- );
244
- console.log(
245
- `[expo-spm-plugin] React wired into (${reactWired.length}): ${reactWired.join(', ') || '—'}`
700
+ // source. Report it and fail — dropping a module here would surface as a
701
+ // runtime "Cannot find native module" instead of a build error.
702
+ const summary = summarizeRecords(records, {
703
+ precompiled,
704
+ ...sourceModules,
705
+ react,
706
+ satisfiedDependencies,
707
+ autolinkConditions,
708
+ gatedCompanions: indexGatedCompanions(metadata, records),
709
+ autolinkGate,
710
+ });
711
+ const logListed = (label, names) =>
712
+ console.log(`[expo-spm-plugin] ${label} (${names.length}): ${names.join(', ') || '—'}`);
713
+ logListed('paired runtime frameworks', summary.precompiledPods);
714
+ logListed('source via checked-in manifest', summary.manifestPackages);
715
+ logListed('source pure-Swift', summary.pureSwiftPods);
716
+ logListed('React wired into', summary.reactWiredPods);
717
+ logListed('gated off', summary.gatedOffProducts);
718
+ logListed(
719
+ 'not supported',
720
+ summary.pending.map((p) => p.podName)
246
721
  );
247
- console.log(
248
- `[expo-spm-plugin] not supported (${pending.length}): ${pending.map((p) => p.podName).join(', ') || '—'}`
249
- );
250
- if (unmappedDeps.length > 0) {
251
- console.warn(renderUnmappedDependencyWarning(unmappedDeps));
722
+ if (summary.unmappedDeps.length > 0) {
723
+ console.warn(renderUnmappedDependencyWarning(summary.unmappedDeps));
724
+ }
725
+ if (summary.partlyProvidedPackages.length > 0) {
726
+ console.warn(renderPartlyProvidedPackageWarning(summary.partlyProvidedPackages));
727
+ }
728
+ if (summary.xcconfigLinkage.length > 0) {
729
+ console.warn(renderXcconfigLinkerWarning(summary.xcconfigLinkage));
730
+ }
731
+ if (summary.leftOutCompanions.length > 0) {
732
+ console.warn(renderLeftOutCompanionWarning(summary.leftOutCompanions));
733
+ }
734
+ const rootConflicts = collectRootConflicts(identities);
735
+ if (rootConflicts.length > 0) {
736
+ console.warn(renderRootConflictWarning(rootConflicts));
252
737
  }
253
- if (xcconfigLinkage.length > 0) {
254
- console.warn(renderXcconfigLinkerWarning(xcconfigLinkage));
738
+ if (extraDependencies.length > 0) {
739
+ console.warn(renderExtraPodsWarning(extraDependencies));
255
740
  }
256
741
  if (react == null) {
257
742
  console.warn(
@@ -259,7 +744,11 @@ module.exports = function expoSpmPlugin(context) {
259
744
  );
260
745
  }
261
746
 
262
- const unsupported = reportUnsupported(classifyUnsupported({ pending, coreAvailable }));
747
+ const unsupported = reportUnsupported([
748
+ ...classifyUnsupported({ pending: summary.pending, coreAvailable }),
749
+ ...summary.uncheckedConditions,
750
+ ...summary.unexportedCompanions,
751
+ ]);
263
752
  if (unsupported != null) {
264
753
  throw unsupported;
265
754
  }
@@ -272,14 +761,15 @@ module.exports = function expoSpmPlugin(context) {
272
761
  // empty. In the app's main module the class always registers, matching CocoaPods
273
762
  // `use_expo_modules!` (which adds ExpoModulesProvider.swift to the app target).
274
763
  const generatedSources = [];
275
- const appTarget = resolveAppTarget(context.appRoot);
276
764
  let providerPath;
277
765
  try {
278
766
  providerPath = generateModulesProvider({
279
767
  appRoot,
280
768
  outDir,
281
769
  moduleNames: modules.map((m) => m.packageName),
282
- ...appTarget,
770
+ targetName: appTarget.targetName,
771
+ entitlementPath: appTarget.entitlementPath,
772
+ podfilePropertiesPath: appTarget.podfilePropertiesPath,
283
773
  });
284
774
  } catch (error) {
285
775
  throw new Error(
@@ -314,26 +804,6 @@ module.exports = function expoSpmPlugin(context) {
314
804
  console.log(`[expo-spm-plugin] generated ExpoModulesProvider.swift → ${providerPath}`);
315
805
  }
316
806
 
317
- // Staleness inputs (`watchPaths` plugin contract): each module's checked-in
318
- // Package.swift and expo-module.config.json. Editing either must trip RN's
319
- // in-build re-sync — the manifests drive the generated wrapper packages, the
320
- // configs drive module resolution.
321
- const moduleRoots = new Set();
322
- for (const mod of modules) {
323
- for (const pod of mod.pods ?? []) {
324
- moduleRoots.add(findModuleRoot(pod.podspecDir));
325
- }
326
- }
327
- // The registry's other inputs: app groups come from the entitlements file and
328
- // inline-module registration from Podfile.properties.json, so editing either
329
- // must trip the re-sync as well. Known gap: repointing CODE_SIGN_ENTITLEMENTS
330
- // at a different file is not noticed, because that would mean watching
331
- // project.pbxproj — which RN rewrites during the sync itself.
332
- const watchPaths = [
333
- ...collectWatchPaths([...moduleRoots]),
334
- ...[appTarget.entitlementPath, appTarget.podfilePropertiesPath].filter((p) => p != null),
335
- ];
336
-
337
807
  const scriptPhases = scriptPhasesForModules(modules.map((m) => m.packageName));
338
808
  if (scriptPhases.length > 0) {
339
809
  console.log(
@@ -342,11 +812,15 @@ module.exports = function expoSpmPlugin(context) {
342
812
  }
343
813
 
344
814
  return {
345
- packageDependencies,
346
- productDependencies,
815
+ packageDependencies: summary.packageDependencies,
816
+ productDependencies: summary.productDependencies,
347
817
  generatedSources,
348
818
  flavoredFrameworks,
349
- watchPaths,
819
+ watchPaths: watchPaths(identities, appTarget),
350
820
  scriptPhases,
351
821
  };
352
822
  };
823
+
824
+ module.exports.macroPluginFlags = macroPluginFlags;
825
+ module.exports.resolvePodIdentities = resolvePodIdentities;
826
+ module.exports.uncoveredPod = uncoveredPod;