expo 58.0.1 → 58.0.3

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 (33) hide show
  1. package/android/build.gradle +2 -2
  2. package/build/winter/runtime.native.js +0 -2
  3. package/build/winter/runtime.native.js.map +1 -1
  4. package/bundledNativeModules.json +77 -77
  5. package/ios/Expo/ExpoReactNativeFactory.swift +2 -2
  6. package/ios/ExpoObjC/AppDelegates/EXReactRootViewFactory.mm +16 -2
  7. package/ios/ExpoObjC/include/Expo/EXReactRootViewFactory.h +2 -1
  8. package/package.json +17 -18
  9. package/scripts/spm/__tests__/app-target.test.js +105 -1
  10. package/scripts/spm/__tests__/autolink-gate.test.js +188 -0
  11. package/scripts/spm/__tests__/classify.test.js +17 -19
  12. package/scripts/spm/__tests__/diagnostics.test.js +705 -132
  13. package/scripts/spm/__tests__/manifests.test.js +1086 -75
  14. package/scripts/spm/__tests__/metadata.test.js +120 -0
  15. package/scripts/spm/__tests__/plugin.test.js +2549 -346
  16. package/scripts/spm/app-target.js +44 -1
  17. package/scripts/spm/autolink-gate.js +40 -0
  18. package/scripts/spm/classify.js +54 -77
  19. package/scripts/spm/diagnostics.js +540 -147
  20. package/scripts/spm/flavored-frameworks.js +80 -125
  21. package/scripts/spm/manifests.js +523 -205
  22. package/scripts/spm/metadata.js +152 -0
  23. package/scripts/spm/plugin.js +592 -277
  24. package/scripts/spm/podspec.js +56 -19
  25. package/src/async-require/__tests__/loadBundle.test.ios.ts +2 -2
  26. package/src/winter/__tests__/{TextDecoderStream.test.ios.ts → TextDecoderStream.test.native.ts} +23 -2
  27. package/src/winter/runtime.native.ts +0 -2
  28. package/template.tgz +0 -0
  29. package/build/winter/TextDecoder.d.ts +0 -13
  30. package/build/winter/TextDecoder.js +0 -357
  31. package/build/winter/TextDecoder.js.map +0 -1
  32. package/src/winter/TextDecoder.ts +0 -427
  33. package/src/winter/__tests__/TextDecoder.test.native.ts +0 -549
@@ -9,7 +9,10 @@ jest.mock('../cli', () => ({
9
9
  generateModulesProvider: jest.fn(() => null),
10
10
  runDumpPackage: jest.fn(),
11
11
  }));
12
+ // The properties reader stays real, so a gated product is decided by a file on
13
+ // disk rather than by a stand-in for it.
12
14
  jest.mock('../app-target', () => ({
15
+ ...jest.requireActual('../app-target'),
13
16
  resolveAppTarget: jest.fn(() => ({
14
17
  targetName: null,
15
18
  entitlementPath: null,
@@ -32,6 +35,12 @@ jest.mock('../classify', () => {
32
35
  const actual = jest.requireActual('../classify');
33
36
  return { ...actual, findModuleRoot: jest.fn(actual.findModuleRoot) };
34
37
  });
38
+ // The pure-Swift emitter stays real; it is spied on so a test can count its calls
39
+ // or stand in an outcome the real emitter has no fixture for.
40
+ jest.mock('../manifests', () => {
41
+ const actual = jest.requireActual('../manifests');
42
+ return { ...actual, emitPureSwiftSourcePackage: jest.fn(actual.emitPureSwiftSourcePackage) };
43
+ });
35
44
 
36
45
  const {
37
46
  resolveExpoModules,
@@ -42,7 +51,9 @@ const {
42
51
  const { resolveAppTarget } = require('../app-target');
43
52
  const { findModuleRoot } = require('../classify');
44
53
  const { UnsupportedModulesError } = require('../diagnostics');
54
+ const { emitPureSwiftSourcePackage } = require('../manifests');
45
55
  const {
56
+ artifactBaseDirs,
46
57
  prepareCompileInterfaces,
47
58
  resolveFlavoredFramework,
48
59
  resolveSpmDependencyFrameworks,
@@ -60,6 +71,19 @@ const {
60
71
 
61
72
  afterAll(removeTempDirs);
62
73
 
74
+ /** A `resolve` result from `[packageName, [[podName, podspecDir], …]]` per module. */
75
+ function modulesOf(modules, extraDependencies = []) {
76
+ return {
77
+ modules: modules.map(([packageName, pods]) => ({
78
+ packageName,
79
+ pods: pods.map(([podName, podspecDir]) => ({ podName, podspecDir })),
80
+ })),
81
+ extraDependencies,
82
+ };
83
+ }
84
+
85
+ const coreAt = (podspecDir) => ['expo-modules-core', [['ExpoModulesCore', podspecDir]]];
86
+
63
87
  function pureSwiftModule(root, podName, podspec) {
64
88
  const podspecDir = path.join(root, 'ios');
65
89
  fs.mkdirSync(podspecDir, { recursive: true });
@@ -111,6 +135,31 @@ function restoreModuleMocks() {
111
135
  prepareCompileInterfaces.mockImplementation(() => '/abs/interfaces');
112
136
  }
113
137
 
138
+ const barcodeGate = {
139
+ podfileProperty: 'expo.camera.barcode-scanner-enabled',
140
+ disabledValue: 'false',
141
+ };
142
+
143
+ /** Points the app target at a real Podfile.properties.json (an object, or raw text), or none. */
144
+ function withPodfileProperties(tmp, properties) {
145
+ const appIosDir = path.join(tmp, 'app', 'ios');
146
+ fs.mkdirSync(appIosDir, { recursive: true });
147
+ let podfilePropertiesPath = null;
148
+ if (properties != null) {
149
+ podfilePropertiesPath = path.join(appIosDir, 'Podfile.properties.json');
150
+ fs.writeFileSync(
151
+ podfilePropertiesPath,
152
+ typeof properties === 'string' ? properties : JSON.stringify(properties)
153
+ );
154
+ }
155
+ resolveAppTarget.mockReset();
156
+ resolveAppTarget.mockReturnValue({
157
+ targetName: null,
158
+ entitlementPath: null,
159
+ podfilePropertiesPath,
160
+ });
161
+ }
162
+
114
163
  /** The arguments the framework resolver was called with for one package. */
115
164
  const resolvedFor = (packageName) =>
116
165
  resolveFlavoredFramework.mock.calls
@@ -155,28 +204,15 @@ describe('the pure-Swift branch', () => {
155
204
  'ExpoLocalization',
156
205
  spec(' s.pod_target_xcconfig = {', " 'OTHER_LDFLAGS' => '$(inherited) -lc++'", ' }')
157
206
  );
158
- resolveExpoModules.mockReturnValue({
159
- modules: [
160
- {
161
- packageName: 'expo-modules-core',
162
- pods: [{ podName: 'ExpoModulesCore', podspecDir: dirs.core }],
163
- },
164
- { packageName: 'expo-asset', pods: [{ podName: 'ExpoAsset', podspecDir: dirs.good }] },
165
- {
166
- packageName: 'expo-media-library',
167
- pods: [{ podName: 'ExpoMediaLibrary', podspecDir: dirs.linked }],
168
- },
169
- {
170
- packageName: 'expo-screen-capture',
171
- pods: [{ podName: 'ExpoScreenCapture', podspecDir: dirs.xcconfig }],
172
- },
173
- {
174
- packageName: 'expo-localization',
175
- pods: [{ podName: 'ExpoLocalization', podspecDir: dirs.rootPodspecDir }],
176
- },
177
- ],
178
- extraDependencies: [],
179
- });
207
+ resolveExpoModules.mockReturnValue(
208
+ modulesOf([
209
+ coreAt(dirs.core),
210
+ ['expo-asset', [['ExpoAsset', dirs.good]]],
211
+ ['expo-media-library', [['ExpoMediaLibrary', dirs.linked]]],
212
+ ['expo-screen-capture', [['ExpoScreenCapture', dirs.xcconfig]]],
213
+ ['expo-localization', [['ExpoLocalization', dirs.rootPodspecDir]]],
214
+ ])
215
+ );
180
216
  thrown = thrownBy(() => runPlugin(tmp));
181
217
  });
182
218
 
@@ -242,15 +278,7 @@ describe('the module registry', () => {
242
278
  // ExpoModulesCore is the only pod the framework resolver mock covers, so it
243
279
  // is emitted as precompiled and nothing is left unsupported.
244
280
  const core = pureSwiftModule(path.join(tmp, 'expo-modules-core'), 'ExpoModulesCore', spec());
245
- resolveExpoModules.mockReturnValue({
246
- modules: [
247
- {
248
- packageName: 'expo-modules-core',
249
- pods: [{ podName: 'ExpoModulesCore', podspecDir: core }],
250
- },
251
- ],
252
- extraDependencies: [],
253
- });
281
+ resolveExpoModules.mockReturnValue(modulesOf([coreAt(core)]));
254
282
  generateModulesProvider.mockReset();
255
283
  generateModulesProvider.mockImplementation(writesProvider('ExpoModulesCore.self\n'));
256
284
  resolveAppTarget.mockReset();
@@ -329,10 +357,7 @@ describe('the module registry', () => {
329
357
 
330
358
  // Excluding every Expo module is a legitimate configuration, not a failure.
331
359
  it('generates nothing, and fails nothing, when no modules are autolinked', () => {
332
- resolveExpoModules.mockReturnValue({
333
- modules: [],
334
- extraDependencies: [],
335
- });
360
+ resolveExpoModules.mockReturnValue(modulesOf([]));
336
361
  generateModulesProvider.mockReturnValue(null);
337
362
 
338
363
  expect(run().generatedSources).toEqual([]);
@@ -371,48 +396,23 @@ describe('module identity from the prebuilt-metadata document', () => {
371
396
  fs.writeFileSync(path.join(dirs.skiaPodspecs, 'react-native-skia.podspec'), spec());
372
397
  mixedModule(dirs.skiaPackage, 'RNSkia');
373
398
 
374
- resolveExpoModules.mockReturnValue({
375
- modules: [
376
- {
377
- packageName: 'expo-modules-core',
378
- pods: [{ podName: 'ExpoModulesCore', podspecDir: dirs.core }],
379
- },
380
- {
381
- packageName: '@shopify/react-native-skia',
382
- pods: [{ podName: 'react-native-skia', podspecDir: dirs.skiaPodspecs }],
383
- },
384
- {
385
- packageName: 'expo-worklets-adapter',
386
- pods: [{ podName: 'ExpoModulesWorkletsAdapter', podspecDir: dirs.adapter }],
387
- },
388
- { packageName: 'expo-legacy', pods: [{ podName: 'ExpoLegacy', podspecDir: dirs.legacy }] },
389
- { packageName: 'expo-stale', pods: [{ podName: 'ExpoStale', podspecDir: dirs.stale }] },
390
- ],
391
- extraDependencies: [],
392
- });
399
+ resolveExpoModules.mockReturnValue(
400
+ modulesOf([
401
+ coreAt(dirs.core),
402
+ ['@shopify/react-native-skia', [['react-native-skia', dirs.skiaPodspecs]]],
403
+ ['expo-worklets-adapter', [['ExpoModulesWorkletsAdapter', dirs.adapter]]],
404
+ ['expo-legacy', [['ExpoLegacy', dirs.legacy]]],
405
+ ['expo-stale', [['ExpoStale', dirs.stale]]],
406
+ ])
407
+ );
393
408
  prebuiltMetadata.mockReturnValue({
394
- 'react-native-skia': {
395
- type: 'external',
396
- npmPackage: '@shopify/react-native-skia',
397
- packageRoot: dirs.skiaPackage,
398
- podspecDir: dirs.skiaPackage,
399
- productName: 'RNSkia',
400
- },
401
- ExpoModulesWorkletsAdapter: {
402
- type: 'internal',
403
- npmPackage: 'expo-worklets-adapter',
404
- packageRoot: path.dirname(dirs.adapter),
405
- podspecDir: dirs.adapter,
406
- productName: 'ExpoModulesWorkletsAdapter',
407
- sourceOnly: true,
408
- },
409
- ExpoStale: {
410
- type: 'internal',
411
- npmPackage: 'expo-stale',
412
- packageRoot: dirs.vanished,
413
- podspecDir: dirs.vanished,
414
- productName: 'ExpoStale',
415
- },
409
+ 'react-native-skia': metadataEntry(dirs.skiaPackage, 'RNSkia'),
410
+ ExpoModulesWorkletsAdapter: metadataEntry(
411
+ path.dirname(dirs.adapter),
412
+ 'ExpoModulesWorkletsAdapter',
413
+ { sourceOnly: true }
414
+ ),
415
+ ExpoStale: metadataEntry(dirs.vanished, 'ExpoStale'),
416
416
  });
417
417
  resolveFlavoredFramework.mockClear();
418
418
  thrown = thrownBy(() => runPlugin(tmp));
@@ -490,28 +490,11 @@ describe('the watched module roots', () => {
490
490
  fs.mkdirSync(packageRoot, { recursive: true });
491
491
  fs.writeFileSync(path.join(packageRoot, 'package.json'), '{"name":"expo-modules-core"}');
492
492
  fs.writeFileSync(path.join(packageRoot, 'expo-module.config.json'), '{}');
493
- resolveExpoModules.mockReturnValue({
494
- modules: [
495
- { packageName: 'expo-modules-core', pods: [{ podName: 'ExpoModulesCore', podspecDir }] },
496
- ],
497
- extraDependencies: [],
498
- });
493
+ resolveExpoModules.mockReturnValue(modulesOf([coreAt(podspecDir)]));
499
494
  prebuiltMetadata.mockReturnValue({
500
- ExpoModulesCore: {
501
- type: 'internal',
502
- npmPackage: 'expo-modules-core',
503
- packageRoot,
504
- podspecDir,
505
- productName: 'ExpoModulesCore',
506
- },
507
- });
508
- generateModulesProvider.mockReset();
509
- generateModulesProvider.mockImplementation(() => {
510
- const providerPath = path.join(outDir, 'expo', 'ExpoModulesProvider.swift');
511
- fs.mkdirSync(path.dirname(providerPath), { recursive: true });
512
- fs.writeFileSync(providerPath, 'ExpoModulesCore.self\n');
513
- return providerPath;
495
+ ExpoModulesCore: metadataEntry(packageRoot, 'ExpoModulesCore'),
514
496
  });
497
+ providerWrittenTo(outDir);
515
498
  ({ watchPaths } = runPlugin(tmp));
516
499
  });
517
500
 
@@ -538,40 +521,21 @@ describe('a precompiled product whose name differs from its pod name', () => {
538
521
  fs.writeFileSync(path.join(skiaPodspecDir, 'react-native-skia.podspec'), spec());
539
522
  mixedModule(skiaPackage, 'RNSkia');
540
523
 
541
- resolveExpoModules.mockReturnValue({
542
- modules: [
543
- {
544
- packageName: 'expo-modules-core',
545
- pods: [{ podName: 'ExpoModulesCore', podspecDir: core }],
546
- },
547
- {
548
- packageName: '@shopify/react-native-skia',
549
- pods: [{ podName: 'react-native-skia', podspecDir: skiaPodspecDir }],
550
- },
551
- ],
552
- extraDependencies: [],
553
- });
524
+ resolveExpoModules.mockReturnValue(
525
+ modulesOf([
526
+ coreAt(core),
527
+ ['@shopify/react-native-skia', [['react-native-skia', skiaPodspecDir]]],
528
+ ])
529
+ );
554
530
  prebuiltMetadata.mockReturnValue({
555
- 'react-native-skia': {
556
- type: 'external',
557
- npmPackage: '@shopify/react-native-skia',
558
- packageRoot: skiaPackage,
559
- podspecDir: skiaPackage,
560
- productName: 'RNSkia',
561
- },
531
+ 'react-native-skia': metadataEntry(skiaPackage, 'RNSkia'),
562
532
  });
563
533
  resolveFlavoredFramework.mockImplementation(({ frameworkName }) =>
564
534
  frameworkName === 'ExpoModulesCore' || frameworkName === 'RNSkia'
565
535
  ? { id: frameworkName.toLowerCase(), frameworkName }
566
536
  : null
567
537
  );
568
- generateModulesProvider.mockReset();
569
- generateModulesProvider.mockImplementation(() => {
570
- const providerPath = path.join(outDir, 'expo', 'ExpoModulesProvider.swift');
571
- fs.mkdirSync(path.dirname(providerPath), { recursive: true });
572
- fs.writeFileSync(providerPath, 'ExpoModulesCore.self\n');
573
- return providerPath;
574
- });
538
+ providerWrittenTo(outDir);
575
539
  result = runPlugin(tmp);
576
540
  });
577
541
 
@@ -606,32 +570,11 @@ describe('the source-emit pass', () => {
606
570
  spec(" s.platforms = { :ios => '16.4' }")
607
571
  );
608
572
 
609
- resolveExpoModules.mockReturnValue({
610
- modules: [
611
- {
612
- packageName: 'expo-modules-core',
613
- pods: [{ podName: 'ExpoModulesCore', podspecDir: core }],
614
- },
615
- { packageName: 'expo-remote', pods: [{ podName: 'ExpoRemote', podspecDir }] },
616
- ],
617
- extraDependencies: [],
618
- });
619
- prebuiltMetadata.mockReturnValue({
620
- ExpoRemote: {
621
- type: 'internal',
622
- npmPackage: 'expo-remote',
623
- packageRoot,
624
- podspecDir,
625
- productName: 'ExpoRemote',
626
- },
627
- });
628
- generateModulesProvider.mockReset();
629
- generateModulesProvider.mockImplementation(() => {
630
- const providerPath = path.join(outDir, 'expo', 'ExpoModulesProvider.swift');
631
- fs.mkdirSync(path.dirname(providerPath), { recursive: true });
632
- fs.writeFileSync(providerPath, 'ExpoModulesCore.self\n');
633
- return providerPath;
634
- });
573
+ resolveExpoModules.mockReturnValue(
574
+ modulesOf([coreAt(core), ['expo-remote', [['ExpoRemote', podspecDir]]]])
575
+ );
576
+ prebuiltMetadata.mockReturnValue({ ExpoRemote: metadataEntry(packageRoot, 'ExpoRemote') });
577
+ providerWrittenTo(outDir);
635
578
  thrown = thrownBy(() => runPlugin(tmp));
636
579
  });
637
580
 
@@ -697,22 +640,15 @@ describe('the iOS deployment floor', () => {
697
640
  spec(" s.platforms = { :ios => '18.0' }")
698
641
  ),
699
642
  };
700
- resolveExpoModules.mockReturnValue({
701
- modules: [
702
- {
703
- packageName: 'expo-modules-core',
704
- pods: [{ podName: 'ExpoModulesCore', podspecDir: dirs.core }],
705
- },
706
- { packageName: 'expo-low', pods: [{ podName: 'ExpoLow', podspecDir: dirs.low }] },
707
- { packageName: 'expo-high', pods: [{ podName: 'ExpoHigh', podspecDir: dirs.high }] },
708
- {
709
- packageName: 'expo-disagreeing',
710
- pods: [{ podName: 'ExpoDisagreeing', podspecDir: dirs.disagreeing }],
711
- },
712
- { packageName: 'expo-absent', pods: [{ podName: 'ExpoAbsent', podspecDir: dirs.absent }] },
713
- ],
714
- extraDependencies: [],
715
- });
643
+ resolveExpoModules.mockReturnValue(
644
+ modulesOf([
645
+ coreAt(dirs.core),
646
+ ['expo-low', [['ExpoLow', dirs.low]]],
647
+ ['expo-high', [['ExpoHigh', dirs.high]]],
648
+ ['expo-disagreeing', [['ExpoDisagreeing', dirs.disagreeing]]],
649
+ ['expo-absent', [['ExpoAbsent', dirs.absent]]],
650
+ ])
651
+ );
716
652
  prebuiltMetadata.mockReturnValue({
717
653
  ExpoModulesCore: metadataEntry(roots.core, 'ExpoModulesCore', {
718
654
  iosDeploymentTarget: '16.4',
@@ -723,13 +659,7 @@ describe('the iOS deployment floor', () => {
723
659
  iosDeploymentTarget: '17.5',
724
660
  }),
725
661
  });
726
- generateModulesProvider.mockReset();
727
- generateModulesProvider.mockImplementation(() => {
728
- const providerPath = path.join(outDir, 'expo', 'ExpoModulesProvider.swift');
729
- fs.mkdirSync(path.dirname(providerPath), { recursive: true });
730
- fs.writeFileSync(providerPath, 'ExpoModulesCore.self\n');
731
- return providerPath;
732
- });
662
+ providerWrittenTo(outDir);
733
663
  thrown = thrownBy(() => runPlugin(tmp));
734
664
  });
735
665
 
@@ -784,27 +714,25 @@ describe('the SwiftPM packages a precompiled module links', () => {
784
714
  )
785
715
  );
786
716
 
787
- resolveExpoModules.mockReturnValue({
788
- modules: [
789
- {
790
- packageName: 'expo-modules-core',
791
- pods: [{ podName: 'ExpoModulesCore', podspecDir: core }],
792
- },
793
- {
794
- packageName: 'expo-image',
795
- pods: [{ podName: 'ExpoImage', podspecDir: imagePodspecDir }],
796
- },
797
- ],
798
- extraDependencies: [],
799
- });
717
+ resolveExpoModules.mockReturnValue(
718
+ modulesOf([coreAt(core), ['expo-image', [['ExpoImage', imagePodspecDir]]]])
719
+ );
800
720
  prebuiltMetadata.mockReturnValue({
801
721
  ExpoImage: {
802
- type: 'internal',
803
- npmPackage: 'expo-image',
804
722
  packageRoot: roots.image,
805
- podspecDir: imagePodspecDir,
806
723
  productName: 'ExpoImage',
807
- spmDependencies: ['SDWebImage', 'libavif'],
724
+ spmPackages: [
725
+ {
726
+ url: 'https://github.com/SDWebImage/SDWebImage.git',
727
+ productName: 'SDWebImage',
728
+ version: { exact: '5.21.6' },
729
+ },
730
+ {
731
+ url: 'https://github.com/SDWebImage/libavif-Xcode.git',
732
+ productName: 'libavif',
733
+ version: { exact: '1.0.0' },
734
+ },
735
+ ],
808
736
  },
809
737
  });
810
738
  resolveFlavoredFramework.mockImplementation(({ frameworkName }) =>
@@ -816,13 +744,7 @@ describe('the SwiftPM packages a precompiled module links', () => {
816
744
  { id: 'expo-sdweb-image', frameworkName: 'SDWebImage' },
817
745
  { id: 'expo-libavif', frameworkName: 'libavif' },
818
746
  ]);
819
- generateModulesProvider.mockReset();
820
- generateModulesProvider.mockImplementation(() => {
821
- const providerPath = path.join(outDir, 'expo', 'ExpoModulesProvider.swift');
822
- fs.mkdirSync(path.dirname(providerPath), { recursive: true });
823
- fs.writeFileSync(providerPath, 'ExpoModulesCore.self\n');
824
- return providerPath;
825
- });
747
+ providerWrittenTo(outDir);
826
748
  // Snapshotted at call time: the plugin hands the builder the same array it
827
749
  // returns, so reading the retained argument afterwards would prove nothing
828
750
  // about what the builder was given.
@@ -835,12 +757,12 @@ describe('the SwiftPM packages a precompiled module links', () => {
835
757
 
836
758
  afterAll(restoreModuleMocks);
837
759
 
838
- it('resolves them from the precompiled pods that declare them', () => {
760
+ it('resolves them from the product names of the spmPackages a precompiled pod declares', () => {
839
761
  expect(resolveSpmDependencyFrameworks).toHaveBeenCalledWith([
840
762
  expect.objectContaining({
841
763
  podName: 'ExpoModulesCore',
842
764
  moduleRoot: roots.core,
843
- spmDependencies: undefined,
765
+ spmDependencies: [],
844
766
  }),
845
767
  expect.objectContaining({
846
768
  podName: 'ExpoImage',
@@ -886,16 +808,9 @@ describe('a dependency that collides with a precompiled module', () => {
886
808
  const fooRoot = path.join(tmp, 'expo-foo');
887
809
  const fooPodspecDir = mixedModule(fooRoot, 'ExpoFoo');
888
810
 
889
- resolveExpoModules.mockReturnValue({
890
- modules: [
891
- {
892
- packageName: 'expo-modules-core',
893
- pods: [{ podName: 'ExpoModulesCore', podspecDir: core }],
894
- },
895
- { packageName: 'expo-foo', pods: [{ podName: 'ExpoFoo', podspecDir: fooPodspecDir }] },
896
- ],
897
- extraDependencies: [],
898
- });
811
+ resolveExpoModules.mockReturnValue(
812
+ modulesOf([coreAt(core), ['expo-foo', [['ExpoFoo', fooPodspecDir]]]])
813
+ );
899
814
  resolveFlavoredFramework.mockImplementation(({ frameworkName }) =>
900
815
  frameworkName === 'ExpoModulesCore' || frameworkName === 'ExpoFoo'
901
816
  ? {
@@ -935,22 +850,18 @@ describe('a package whose first pod alone is precompiled', () => {
935
850
  spec(" s.dependency 'SomeUnmappedPod'")
936
851
  );
937
852
 
938
- resolveExpoModules.mockReturnValue({
939
- modules: [
940
- {
941
- packageName: 'expo-modules-core',
942
- pods: [{ podName: 'ExpoModulesCore', podspecDir: core }],
943
- },
944
- {
945
- packageName: 'expo-multi',
946
- pods: [
947
- { podName: 'ExpoMulti', podspecDir: multiPodspecDir },
948
- { podName: 'ExpoMultiHelper', podspecDir: multiPodspecDir },
853
+ resolveExpoModules.mockReturnValue(
854
+ modulesOf([
855
+ coreAt(core),
856
+ [
857
+ 'expo-multi',
858
+ [
859
+ ['ExpoMulti', multiPodspecDir],
860
+ ['ExpoMultiHelper', multiPodspecDir],
949
861
  ],
950
- },
951
- ],
952
- extraDependencies: [],
953
- });
862
+ ],
863
+ ])
864
+ );
954
865
  resolveFlavoredFramework.mockImplementation(({ frameworkName }) =>
955
866
  frameworkName === 'ExpoModulesCore' || frameworkName === 'ExpoMulti'
956
867
  ? { id: frameworkName.toLowerCase(), frameworkName }
@@ -1006,19 +917,9 @@ describe('the checked-in manifest branch', () => {
1006
917
  ],
1007
918
  })
1008
919
  );
1009
- resolveExpoModules.mockReturnValue({
1010
- modules: [
1011
- {
1012
- packageName: 'expo-modules-core',
1013
- pods: [{ podName: 'ExpoModulesCore', podspecDir: core }],
1014
- },
1015
- {
1016
- packageName: 'expo-vendored',
1017
- pods: [{ podName: 'ExpoVendored', podspecDir: vendoredPodspecDir }],
1018
- },
1019
- ],
1020
- extraDependencies: [],
1021
- });
920
+ resolveExpoModules.mockReturnValue(
921
+ modulesOf([coreAt(core), ['expo-vendored', [['ExpoVendored', vendoredPodspecDir]]]])
922
+ );
1022
923
  thrown = thrownBy(() => runPlugin(tmp));
1023
924
  });
1024
925
 
@@ -1043,6 +944,229 @@ describe('the checked-in manifest branch', () => {
1043
944
  });
1044
945
  });
1045
946
 
947
+ describe.each([
948
+ ['a checked-in manifest', 'ExpoDual'],
949
+ ['a checked-in manifest', 'ExpoDualExtras'],
950
+ ['pure-Swift sources', 'ExpoDual'],
951
+ ['pure-Swift sources', 'ExpoDualExtras'],
952
+ ])('a two-pod module with %s whose only precompiled pod is %s', (kind, precompiledPod) => {
953
+ const sourcePod = precompiledPod === 'ExpoDual' ? 'ExpoDualExtras' : 'ExpoDual';
954
+ const logs = captureConsole();
955
+ let outDir;
956
+ let thrown;
957
+
958
+ beforeAll(() => {
959
+ const tmp = makeTempDir('expo-spm-plugin-partial-');
960
+ outDir = path.join(tmp, 'out');
961
+ const core = pureSwiftModule(path.join(tmp, 'expo-modules-core'), 'ExpoModulesCore', spec());
962
+ const dual = path.join(tmp, 'expo-dual');
963
+ const dualPodspecDir = pureSwiftModule(dual, 'ExpoDual', spec());
964
+ fs.writeFileSync(path.join(dualPodspecDir, 'ExpoDualExtras.podspec'), spec());
965
+ if (kind === 'a checked-in manifest') {
966
+ fs.writeFileSync(path.join(dual, 'Package.swift'), '// swift-tools-version: 6.0\n');
967
+ runDumpPackage.mockReturnValue(
968
+ JSON.stringify({
969
+ name: 'ExpoDual',
970
+ products: [{ name: 'ExpoDual', type: { library: ['automatic'] }, targets: ['ExpoDual'] }],
971
+ targets: [{ name: 'ExpoDual', type: 'regular', path: 'ios', dependencies: [] }],
972
+ })
973
+ );
974
+ }
975
+ resolveFlavoredFramework.mockImplementation(({ frameworkName }) =>
976
+ ['ExpoModulesCore', precompiledPod].includes(frameworkName)
977
+ ? { id: frameworkName, frameworkName }
978
+ : null
979
+ );
980
+ resolveExpoModules.mockReturnValue(
981
+ modulesOf([
982
+ coreAt(core),
983
+ [
984
+ 'expo-dual',
985
+ [
986
+ ['ExpoDual', dualPodspecDir],
987
+ ['ExpoDualExtras', dualPodspecDir],
988
+ ],
989
+ ],
990
+ ])
991
+ );
992
+ thrown = thrownBy(() => runPlugin(tmp));
993
+ });
994
+
995
+ afterAll(restoreModuleMocks);
996
+
997
+ it('fails the sync for the pod that is not precompiled, naming the one that is', () => {
998
+ expect(thrown).toBeInstanceOf(UnsupportedModulesError);
999
+ expect(thrown.unsupported).toEqual([
1000
+ expect.objectContaining({
1001
+ reason: 'partially-precompiled',
1002
+ podName: sourcePod,
1003
+ packageName: 'expo-dual',
1004
+ precompiledSiblings: [precompiledPod],
1005
+ }),
1006
+ ]);
1007
+ expect(printed(logs.error)).toContain(`error: Expo module "expo-dual" (pod ${sourcePod})`);
1008
+ });
1009
+
1010
+ it('emits no source package for the module, so the precompiled pod is linked once', () => {
1011
+ expect(fs.existsSync(path.join(outDir, 'expo', 'expo-source', 'ExpoDual'))).toBe(false);
1012
+ });
1013
+ });
1014
+
1015
+ describe('a partially precompiled module', () => {
1016
+ const logs = captureConsole({ each: true });
1017
+
1018
+ afterEach(restoreModuleMocks);
1019
+
1020
+ function syncPartialModule({ sources, pods, precompiled }) {
1021
+ const tmp = makeTempDir('expo-spm-plugin-partial-');
1022
+ const outDir = path.join(tmp, 'out');
1023
+ const core = pureSwiftModule(path.join(tmp, 'expo-modules-core'), 'ExpoModulesCore', spec());
1024
+ const moduleRoot = path.join(tmp, 'expo-dual');
1025
+ const podspecDir = pureSwiftModule(moduleRoot, pods[0], spec());
1026
+ for (const podName of pods.slice(1)) {
1027
+ fs.writeFileSync(path.join(podspecDir, `${podName}.podspec`), spec());
1028
+ }
1029
+ if (sources !== 'swift') {
1030
+ fs.writeFileSync(path.join(podspecDir, 'B.m'), '// objc\n');
1031
+ }
1032
+ if (sources === 'mixed with a manifest') {
1033
+ fs.writeFileSync(path.join(moduleRoot, 'Package.swift'), '// swift-tools-version: 6.0\n');
1034
+ runDumpPackage.mockReturnValue(
1035
+ JSON.stringify({
1036
+ name: 'ExpoDual',
1037
+ products: [{ name: 'ExpoDual', type: { library: ['automatic'] }, targets: ['ExpoDual'] }],
1038
+ targets: [{ name: 'ExpoDual', type: 'regular', path: 'ios', dependencies: [] }],
1039
+ })
1040
+ );
1041
+ }
1042
+ resolveFlavoredFramework.mockImplementation(({ frameworkName }) =>
1043
+ ['ExpoModulesCore', ...precompiled].includes(frameworkName)
1044
+ ? { id: frameworkName, frameworkName }
1045
+ : null
1046
+ );
1047
+ resolveExpoModules.mockReturnValue(
1048
+ modulesOf([coreAt(core), ['expo-dual', pods.map((podName) => [podName, podspecDir])]])
1049
+ );
1050
+ const thrown = thrownBy(() => runPlugin(tmp));
1051
+ const sourceDir = path.join(outDir, 'expo', 'expo-source');
1052
+ return {
1053
+ thrown,
1054
+ report: printed(logs.error),
1055
+ moduleRoot,
1056
+ sourcePackages: fs.existsSync(sourceDir) ? fs.readdirSync(sourceDir) : [],
1057
+ };
1058
+ }
1059
+
1060
+ it('is refused when a checked-in manifest covers mixed-language sources', () => {
1061
+ const { thrown, sourcePackages } = syncPartialModule({
1062
+ sources: 'mixed with a manifest',
1063
+ pods: ['ExpoDual', 'ExpoDualExtras'],
1064
+ precompiled: ['ExpoDual'],
1065
+ });
1066
+ expect(thrown.unsupported).toEqual([
1067
+ expect.objectContaining({ reason: 'partially-precompiled', podName: 'ExpoDualExtras' }),
1068
+ ]);
1069
+ expect(sourcePackages).toEqual([]);
1070
+ });
1071
+
1072
+ it('keeps the mixed-language report when it has no manifest, since it is never built from source', () => {
1073
+ const { thrown, sourcePackages } = syncPartialModule({
1074
+ sources: 'mixed',
1075
+ pods: ['ExpoDual', 'ExpoDualExtras'],
1076
+ precompiled: ['ExpoDual'],
1077
+ });
1078
+ expect(thrown.unsupported).toEqual([
1079
+ expect.objectContaining({ reason: 'mixed-no-manifest', podName: 'ExpoDualExtras' }),
1080
+ ]);
1081
+ expect(sourcePackages).toEqual([]);
1082
+ });
1083
+
1084
+ it('reports every pod that is not precompiled', () => {
1085
+ const { thrown } = syncPartialModule({
1086
+ sources: 'swift',
1087
+ pods: ['ExpoDual', 'ExpoDualExtras', 'ExpoDualKit', 'ExpoDualUI'],
1088
+ precompiled: ['ExpoDual', 'ExpoDualKit'],
1089
+ });
1090
+ expect(thrown.unsupported).toEqual([
1091
+ expect.objectContaining({
1092
+ reason: 'partially-precompiled',
1093
+ podName: 'ExpoDualExtras',
1094
+ precompiledSiblings: ['ExpoDual', 'ExpoDualKit'],
1095
+ }),
1096
+ expect.objectContaining({
1097
+ reason: 'partially-precompiled',
1098
+ podName: 'ExpoDualUI',
1099
+ precompiledSiblings: ['ExpoDual', 'ExpoDualKit'],
1100
+ }),
1101
+ ]);
1102
+ });
1103
+
1104
+ it('names every directory the artifact resolver searches, in its order', () => {
1105
+ const previous = process.env.EXPO_PRECOMPILED_MODULES_PATH;
1106
+ process.env.EXPO_PRECOMPILED_MODULES_PATH = '/precompiled';
1107
+ try {
1108
+ const { report, moduleRoot } = syncPartialModule({
1109
+ sources: 'swift',
1110
+ pods: ['ExpoDual', 'ExpoDualExtras'],
1111
+ precompiled: ['ExpoDual'],
1112
+ });
1113
+ const searched = artifactBaseDirs('expo-dual', moduleRoot);
1114
+ expect(searched).toHaveLength(3);
1115
+ const positions = searched.map((dir) => report.indexOf(dir));
1116
+ expect(positions.every((position) => position >= 0)).toBe(true);
1117
+ expect(positions).toEqual([...positions].sort((a, b) => a - b));
1118
+ } finally {
1119
+ if (previous === undefined) {
1120
+ delete process.env.EXPO_PRECOMPILED_MODULES_PATH;
1121
+ } else {
1122
+ process.env.EXPO_PRECOMPILED_MODULES_PATH = previous;
1123
+ }
1124
+ }
1125
+ });
1126
+ });
1127
+
1128
+ describe('a partially precompiled module whose precompiled product is not named after its pod', () => {
1129
+ const logs = captureConsole();
1130
+ let thrown;
1131
+
1132
+ beforeAll(() => {
1133
+ const tmp = makeTempDir('expo-spm-plugin-partial-product-');
1134
+ const core = pureSwiftModule(path.join(tmp, 'expo-modules-core'), 'ExpoModulesCore', spec());
1135
+ const skia = path.join(tmp, 'react-native-skia');
1136
+ const podspecDir = pureSwiftModule(skia, 'RNSkiaPod', spec());
1137
+ fs.writeFileSync(path.join(podspecDir, 'RNSkiaExtras.podspec'), spec());
1138
+ prebuiltMetadata.mockReturnValue({ RNSkiaPod: metadataEntry(skia, 'RNSkia') });
1139
+ resolveFlavoredFramework.mockImplementation(({ frameworkName }) =>
1140
+ ['ExpoModulesCore', 'RNSkia'].includes(frameworkName)
1141
+ ? { id: frameworkName, frameworkName }
1142
+ : null
1143
+ );
1144
+ resolveExpoModules.mockReturnValue(
1145
+ modulesOf([
1146
+ coreAt(core),
1147
+ [
1148
+ 'react-native-skia',
1149
+ [
1150
+ ['RNSkiaPod', podspecDir],
1151
+ ['RNSkiaExtras', podspecDir],
1152
+ ],
1153
+ ],
1154
+ ])
1155
+ );
1156
+ thrown = thrownBy(() => runPlugin(tmp));
1157
+ });
1158
+
1159
+ afterAll(restoreModuleMocks);
1160
+
1161
+ it('names the artifacts pass 1 looked up, under the product name', () => {
1162
+ expect(thrown).toBeInstanceOf(UnsupportedModulesError);
1163
+ const report = printed(logs.error);
1164
+ expect(report).toContain('— RNSkia.xcframework or RNSkia.tar.gz, under');
1165
+ expect(report).not.toContain('RNSkiaPod.xcframework');
1166
+ expect(report).toContain('its sibling pod RNSkiaPod does');
1167
+ });
1168
+ });
1169
+
1046
1170
  // React Native hands the plugin its own autolinking data (`context.autolinking`,
1047
1171
  // the raw autolinking.json). Its `root` is where Node resolves the package from
1048
1172
  // the app — a resolved answer to the question the filesystem walk guesses at.
@@ -1070,35 +1194,16 @@ describe('the module root React Native autolinked', () => {
1070
1194
  fallback: pureSwiftModule(roots.fallback, 'ExpoFallback', spec()),
1071
1195
  };
1072
1196
 
1073
- resolveExpoModules.mockReturnValue({
1074
- modules: [
1075
- {
1076
- packageName: 'expo-modules-core',
1077
- pods: [{ podName: 'ExpoModulesCore', podspecDir: core }],
1078
- },
1079
- {
1080
- packageName: 'expo-documented',
1081
- pods: [{ podName: 'ExpoDocumented', podspecDir: podspecDirs.documented }],
1082
- },
1083
- {
1084
- packageName: 'expo-autolinked',
1085
- pods: [{ podName: 'ExpoAutolinked', podspecDir: podspecDirs.autolinked }],
1086
- },
1087
- {
1088
- packageName: 'expo-fallback',
1089
- pods: [{ podName: 'ExpoFallback', podspecDir: podspecDirs.fallback }],
1090
- },
1091
- ],
1092
- extraDependencies: [],
1093
- });
1197
+ resolveExpoModules.mockReturnValue(
1198
+ modulesOf([
1199
+ coreAt(core),
1200
+ ['expo-documented', [['ExpoDocumented', podspecDirs.documented]]],
1201
+ ['expo-autolinked', [['ExpoAutolinked', podspecDirs.autolinked]]],
1202
+ ['expo-fallback', [['ExpoFallback', podspecDirs.fallback]]],
1203
+ ])
1204
+ );
1094
1205
  prebuiltMetadata.mockReturnValue({
1095
- ExpoDocumented: {
1096
- type: 'internal',
1097
- npmPackage: 'expo-documented',
1098
- packageRoot: roots.documented,
1099
- podspecDir: podspecDirs.documented,
1100
- productName: 'ExpoDocumented',
1101
- },
1206
+ ExpoDocumented: metadataEntry(roots.documented, 'ExpoDocumented'),
1102
1207
  });
1103
1208
  resolveFlavoredFramework.mockClear();
1104
1209
  findModuleRoot.mockClear();
@@ -1144,16 +1249,9 @@ describe('a sync React Native passes no autolinking data for', () => {
1144
1249
  root = path.join(tmp, 'node_modules', 'expo-walked');
1145
1250
  podspecDir = pureSwiftModule(root, 'ExpoWalked', spec());
1146
1251
 
1147
- resolveExpoModules.mockReturnValue({
1148
- modules: [
1149
- {
1150
- packageName: 'expo-modules-core',
1151
- pods: [{ podName: 'ExpoModulesCore', podspecDir: core }],
1152
- },
1153
- { packageName: 'expo-walked', pods: [{ podName: 'ExpoWalked', podspecDir }] },
1154
- ],
1155
- extraDependencies: [],
1156
- });
1252
+ resolveExpoModules.mockReturnValue(
1253
+ modulesOf([coreAt(core), ['expo-walked', [['ExpoWalked', podspecDir]]]])
1254
+ );
1157
1255
  resolveFlavoredFramework.mockClear();
1158
1256
  findModuleRoot.mockClear();
1159
1257
  providerWrittenTo(path.join(tmp, 'out'));
@@ -1162,7 +1260,7 @@ describe('a sync React Native passes no autolinking data for', () => {
1162
1260
 
1163
1261
  afterAll(restoreModuleMocks);
1164
1262
 
1165
- it('resolves every module root by walking the filesystem, as before', () => {
1263
+ it('resolves every module root by walking the filesystem', () => {
1166
1264
  expect(resolvedFor('expo-walked')).toMatchObject({ moduleRoot: root });
1167
1265
  expect(findModuleRoot).toHaveBeenCalledWith(podspecDir);
1168
1266
  });
@@ -1191,38 +1289,16 @@ describe('a module installed twice', () => {
1191
1289
  fs.mkdirSync(path.join(tmp, 'links'), { recursive: true });
1192
1290
  fs.symlinkSync(roots.linked, roots.linkedThrough, 'dir');
1193
1291
 
1194
- resolveExpoModules.mockReturnValue({
1195
- modules: [
1196
- {
1197
- packageName: 'expo-modules-core',
1198
- pods: [{ podName: 'ExpoModulesCore', podspecDir: core }],
1199
- },
1200
- {
1201
- packageName: 'expo-linked',
1202
- pods: [{ podName: 'ExpoLinked', podspecDir: podspecDirs.linked }],
1203
- },
1204
- {
1205
- packageName: 'expo-duplicated',
1206
- pods: [{ podName: 'ExpoDuplicated', podspecDir: podspecDirs.duplicated }],
1207
- },
1208
- ],
1209
- extraDependencies: [],
1210
- });
1292
+ resolveExpoModules.mockReturnValue(
1293
+ modulesOf([
1294
+ coreAt(core),
1295
+ ['expo-linked', [['ExpoLinked', podspecDirs.linked]]],
1296
+ ['expo-duplicated', [['ExpoDuplicated', podspecDirs.duplicated]]],
1297
+ ])
1298
+ );
1211
1299
  prebuiltMetadata.mockReturnValue({
1212
- ExpoLinked: {
1213
- type: 'internal',
1214
- npmPackage: 'expo-linked',
1215
- packageRoot: roots.linked,
1216
- podspecDir: podspecDirs.linked,
1217
- productName: 'ExpoLinked',
1218
- },
1219
- ExpoDuplicated: {
1220
- type: 'internal',
1221
- npmPackage: 'expo-duplicated',
1222
- packageRoot: roots.duplicated,
1223
- podspecDir: podspecDirs.duplicated,
1224
- productName: 'ExpoDuplicated',
1225
- },
1300
+ ExpoLinked: metadataEntry(roots.linked, 'ExpoLinked'),
1301
+ ExpoDuplicated: metadataEntry(roots.duplicated, 'ExpoDuplicated'),
1226
1302
  });
1227
1303
  providerWrittenTo(path.join(tmp, 'out'));
1228
1304
  runPlugin(tmp, {
@@ -1255,6 +1331,7 @@ describe('a module installed twice', () => {
1255
1331
  describe('a module whose pods document two different copies', () => {
1256
1332
  const logs = captureConsole();
1257
1333
  let roots;
1334
+ let thrown;
1258
1335
 
1259
1336
  beforeAll(() => {
1260
1337
  const tmp = fs.realpathSync(makeTempDir('expo-spm-pod-copies-'));
@@ -1267,40 +1344,26 @@ describe('a module whose pods document two different copies', () => {
1267
1344
  fs.writeFileSync(path.join(podspecDir, 'ExpoMultiB.podspec'), spec());
1268
1345
  pureSwiftModule(roots.multiCopy, 'ExpoMultiB', spec());
1269
1346
 
1270
- resolveExpoModules.mockReturnValue({
1271
- modules: [
1272
- {
1273
- packageName: 'expo-modules-core',
1274
- pods: [{ podName: 'ExpoModulesCore', podspecDir: core }],
1275
- },
1276
- {
1277
- packageName: 'expo-multi',
1278
- pods: [
1279
- { podName: 'ExpoMultiA', podspecDir },
1280
- { podName: 'ExpoMultiB', podspecDir },
1347
+ resolveExpoModules.mockReturnValue(
1348
+ modulesOf([
1349
+ coreAt(core),
1350
+ [
1351
+ 'expo-multi',
1352
+ [
1353
+ ['ExpoMultiA', podspecDir],
1354
+ ['ExpoMultiB', podspecDir],
1281
1355
  ],
1282
- },
1283
- ],
1284
- extraDependencies: [],
1285
- });
1356
+ ],
1357
+ ])
1358
+ );
1286
1359
  prebuiltMetadata.mockReturnValue({
1287
- ExpoMultiA: {
1288
- type: 'internal',
1289
- npmPackage: 'expo-multi',
1290
- packageRoot: roots.multi,
1291
- podspecDir,
1292
- productName: 'ExpoMultiA',
1293
- },
1294
- ExpoMultiB: {
1295
- type: 'internal',
1296
- npmPackage: 'expo-multi',
1297
- packageRoot: roots.multiCopy,
1298
- podspecDir,
1299
- productName: 'ExpoMultiB',
1300
- },
1360
+ ExpoMultiA: metadataEntry(roots.multi, 'ExpoMultiA'),
1361
+ ExpoMultiB: metadataEntry(roots.multiCopy, 'ExpoMultiB'),
1301
1362
  });
1302
1363
  providerWrittenTo(path.join(tmp, 'out'));
1303
- runPlugin(tmp, { autolinking: { dependencies: { 'expo-multi': { root: roots.multi } } } });
1364
+ thrown = thrownBy(() =>
1365
+ runPlugin(tmp, { autolinking: { dependencies: { 'expo-multi': { root: roots.multi } } } })
1366
+ );
1304
1367
  });
1305
1368
 
1306
1369
  afterAll(restoreModuleMocks);
@@ -1311,6 +1374,11 @@ describe('a module whose pods document two different copies', () => {
1311
1374
  expect(printed(logs.warn).match(/is installed twice/g)).toHaveLength(1);
1312
1375
  expect(printed(logs.warn)).toContain(roots.multiCopy);
1313
1376
  });
1377
+
1378
+ it('fails the sync on the second pod, which nothing emits', () => {
1379
+ expect(thrown).toBeInstanceOf(UnsupportedModulesError);
1380
+ expect(thrown.unsupported.map((u) => u.podName)).toEqual(['ExpoMultiB']);
1381
+ });
1314
1382
  });
1315
1383
 
1316
1384
  // `extraPods` in the app config lands in Podfile.properties.json. The plugin reads
@@ -1325,16 +1393,9 @@ describe('the extra CocoaPods dependencies an app declares', () => {
1325
1393
  outDir = path.join(tmp, 'out');
1326
1394
  const core = pureSwiftModule(path.join(tmp, 'expo-modules-core'), 'ExpoModulesCore', spec());
1327
1395
  const podspecDir = pureSwiftModule(path.join(tmp, 'expo-extra'), 'ExpoExtra', spec());
1328
- resolveExpoModules.mockReturnValue({
1329
- modules: [
1330
- {
1331
- packageName: 'expo-modules-core',
1332
- pods: [{ podName: 'ExpoModulesCore', podspecDir: core }],
1333
- },
1334
- { packageName: 'expo-extra', pods: [{ podName: 'ExpoExtra', podspecDir }] },
1335
- ],
1336
- extraDependencies,
1337
- });
1396
+ resolveExpoModules.mockReturnValue(
1397
+ modulesOf([coreAt(core), ['expo-extra', [['ExpoExtra', podspecDir]]]], extraDependencies)
1398
+ );
1338
1399
  providerWrittenTo(outDir);
1339
1400
  return runPlugin(tmp, { autolinking: {} });
1340
1401
  };
@@ -1366,3 +1427,2145 @@ describe('the extra CocoaPods dependencies an app declares', () => {
1366
1427
  expect(printed(logs.warn)).not.toContain('Podfile.properties.json');
1367
1428
  });
1368
1429
  });
1430
+
1431
+ // A source-emitted module has no XCFramework to link its SwiftPM dependencies
1432
+ // into, so the generated manifest has to declare them itself.
1433
+ describe('the SwiftPM packages a source-emitted module declares', () => {
1434
+ const logs = captureConsole();
1435
+ let manifest;
1436
+
1437
+ beforeAll(() => {
1438
+ const tmp = makeTempDir('expo-spm-source-deps-plugin-');
1439
+ const outDir = path.join(tmp, 'out');
1440
+ const core = pureSwiftModule(path.join(tmp, 'expo-modules-core'), 'ExpoModulesCore', spec());
1441
+ const imageRoot = path.join(tmp, 'expo-image');
1442
+ const image = pureSwiftModule(
1443
+ imageRoot,
1444
+ 'ExpoImage',
1445
+ spec(
1446
+ " s.dependency 'ExpoModulesCore'",
1447
+ " s.dependency 'SDWebImage'",
1448
+ " s.dependency 'libavif/libdav1d'",
1449
+ " s.dependency 'SomeUnmappedPod'"
1450
+ )
1451
+ );
1452
+
1453
+ resolveExpoModules.mockReturnValue(
1454
+ modulesOf([coreAt(core), ['expo-image', [['ExpoImage', image]]]])
1455
+ );
1456
+ prebuiltMetadata.mockReturnValue({
1457
+ ExpoImage: {
1458
+ packageRoot: imageRoot,
1459
+ productName: 'ExpoImage',
1460
+ sourceOnly: true,
1461
+ spmPackages: [
1462
+ {
1463
+ url: 'https://github.com/SDWebImage/SDWebImage.git',
1464
+ productName: 'SDWebImage',
1465
+ version: { exact: '5.21.6' },
1466
+ },
1467
+ {
1468
+ url: 'https://github.com/SDWebImage/libavif-Xcode.git',
1469
+ productName: 'libavif',
1470
+ version: { exact: '1.0.0' },
1471
+ },
1472
+ ],
1473
+ },
1474
+ });
1475
+ providerWrittenTo(outDir);
1476
+ runPlugin(tmp);
1477
+ manifest = fs.readFileSync(
1478
+ path.join(outDir, 'expo', 'expo-source', 'ExpoImage', 'Package.swift'),
1479
+ 'utf8'
1480
+ );
1481
+ });
1482
+
1483
+ afterAll(restoreModuleMocks);
1484
+
1485
+ it('declares them in the generated manifest', () => {
1486
+ expect(manifest).toContain(
1487
+ '.package(url: "https://github.com/SDWebImage/SDWebImage.git", exact: "5.21.6"),'
1488
+ );
1489
+ expect(manifest).toContain(
1490
+ '.package(url: "https://github.com/SDWebImage/libavif-Xcode.git", exact: "1.0.0"),'
1491
+ );
1492
+ expect(manifest).toContain('.product(name: "SDWebImage", package: "SDWebImage"),');
1493
+ expect(manifest).toContain('.product(name: "libavif", package: "libavif-Xcode"),');
1494
+ });
1495
+
1496
+ it('counts them as counterparts of the pods its podspec depends on', () => {
1497
+ const report = printed(logs.warn);
1498
+ expect(report).toContain('warning: Expo module "expo-image" (pod ExpoImage)');
1499
+ expect(report).toContain('SomeUnmappedPod');
1500
+ expect(report).not.toContain('SDWebImage');
1501
+ // Root-name match, as CocoaPods; SwiftPM's libavif is libaom, not dav1d (no upstream fix).
1502
+ expect(report).not.toContain('libavif');
1503
+ });
1504
+ });
1505
+
1506
+ describe('a source-emitted module depending on a package a precompiled module links', () => {
1507
+ captureConsole();
1508
+ let manifest;
1509
+ let result;
1510
+ let compiled;
1511
+
1512
+ beforeAll(() => {
1513
+ const tmp = makeTempDir('expo-spm-satisfied-deps-plugin-');
1514
+ const outDir = path.join(tmp, 'out');
1515
+ const core = pureSwiftModule(path.join(tmp, 'expo-modules-core'), 'ExpoModulesCore', spec());
1516
+ const imageRoot = path.join(tmp, 'expo-image');
1517
+ const imagePodspecDir = mixedModule(imageRoot, 'ExpoImage');
1518
+ const fooRoot = path.join(tmp, 'expo-foo');
1519
+ const foo = pureSwiftModule(fooRoot, 'ExpoFoo', spec(" s.dependency 'ExpoModulesCore'"));
1520
+ const sdWebImage = {
1521
+ url: 'https://github.com/SDWebImage/SDWebImage.git',
1522
+ productName: 'SDWebImage',
1523
+ version: { exact: '5.21.6' },
1524
+ };
1525
+ const libavif = {
1526
+ url: 'https://github.com/SDWebImage/libavif-Xcode.git',
1527
+ productName: 'libavif',
1528
+ version: { exact: '1.0.0' },
1529
+ };
1530
+
1531
+ resolveExpoModules.mockReturnValue(
1532
+ modulesOf([
1533
+ coreAt(core),
1534
+ ['expo-image', [['ExpoImage', imagePodspecDir]]],
1535
+ ['expo-foo', [['ExpoFoo', foo]]],
1536
+ ])
1537
+ );
1538
+ prebuiltMetadata.mockReturnValue({
1539
+ ExpoImage: { packageRoot: imageRoot, productName: 'ExpoImage', spmPackages: [sdWebImage] },
1540
+ ExpoFoo: {
1541
+ packageRoot: fooRoot,
1542
+ productName: 'ExpoFoo',
1543
+ sourceOnly: true,
1544
+ spmPackages: [sdWebImage, libavif],
1545
+ },
1546
+ });
1547
+ resolveFlavoredFramework.mockImplementation(({ frameworkName }) =>
1548
+ frameworkName === 'ExpoModulesCore' || frameworkName === 'ExpoImage'
1549
+ ? { id: frameworkName === 'ExpoImage' ? 'expo-image' : 'expo-modules-core', frameworkName }
1550
+ : null
1551
+ );
1552
+ resolveSpmDependencyFrameworks.mockReturnValue([
1553
+ {
1554
+ id: 'expo-sd-web-image',
1555
+ frameworkName: 'SDWebImage',
1556
+ linkage: 'dynamic',
1557
+ flavors: {
1558
+ debug: '/abs/debug/SDWebImage.xcframework',
1559
+ release: '/abs/release/SDWebImage.xcframework',
1560
+ },
1561
+ },
1562
+ ]);
1563
+ prepareCompileInterfaces.mockImplementation((frameworks) => {
1564
+ compiled = frameworks.map((framework) => framework.frameworkName);
1565
+ return '/abs/interfaces';
1566
+ });
1567
+ providerWrittenTo(outDir);
1568
+ result = runPlugin(tmp);
1569
+ manifest = fs.readFileSync(
1570
+ path.join(outDir, 'expo', 'expo-source', 'ExpoFoo', 'Package.swift'),
1571
+ 'utf8'
1572
+ );
1573
+ });
1574
+
1575
+ afterAll(restoreModuleMocks);
1576
+
1577
+ it('links the precompiled framework instead of declaring a second copy', () => {
1578
+ expect(manifest).not.toContain('SDWebImage.git');
1579
+ expect(manifest).not.toContain('.product(name: "SDWebImage"');
1580
+ expect(result.flavoredFrameworks).toContainEqual(
1581
+ expect.objectContaining({ frameworkName: 'SDWebImage' })
1582
+ );
1583
+ expect(compiled).toContain('SDWebImage');
1584
+ expect(manifest).toContain('cSettings: [.unsafeFlags(["-F", "/abs/interfaces"])],');
1585
+ expect(manifest).toContain('swiftSettings: [.unsafeFlags(["-F", "/abs/interfaces",');
1586
+ });
1587
+
1588
+ it('still declares the packages nothing precompiled provides', () => {
1589
+ expect(manifest).toContain(
1590
+ '.package(url: "https://github.com/SDWebImage/libavif-Xcode.git", exact: "1.0.0"),'
1591
+ );
1592
+ expect(manifest).toContain('.product(name: "libavif", package: "libavif-Xcode"),');
1593
+ });
1594
+ });
1595
+
1596
+ // A kept product can depend on the provided one inside its package, which the plugin
1597
+ // cannot see, so the sync warns instead of failing.
1598
+ describe('a source-emitted module keeping a package whose other product is precompiled', () => {
1599
+ const logs = captureConsole();
1600
+
1601
+ beforeAll(() => {
1602
+ const tmp = makeTempDir('expo-spm-partly-provided-plugin-');
1603
+ const outDir = path.join(tmp, 'out');
1604
+ const core = pureSwiftModule(path.join(tmp, 'expo-modules-core'), 'ExpoModulesCore', spec());
1605
+ const imageRoot = path.join(tmp, 'expo-image');
1606
+ const imagePodspecDir = mixedModule(imageRoot, 'ExpoImage');
1607
+ const mapsRoot = path.join(tmp, 'expo-maps-extra');
1608
+ const maps = pureSwiftModule(
1609
+ mapsRoot,
1610
+ 'ExpoMapsExtra',
1611
+ spec(" s.dependency 'ExpoModulesCore'")
1612
+ );
1613
+ fs.writeFileSync(
1614
+ path.join(mapsRoot, 'Package.swift'),
1615
+ '// swift-tools-version: 6.0\n// checked in by the module\n'
1616
+ );
1617
+ runDumpPackage.mockReturnValue(
1618
+ JSON.stringify({
1619
+ name: 'ExpoMapsExtra',
1620
+ dependencies: [
1621
+ {
1622
+ sourceControl: [
1623
+ {
1624
+ identity: 'sdwebimage',
1625
+ location: {
1626
+ remote: [{ urlString: 'https://github.com/SDWebImage/SDWebImage.git' }],
1627
+ },
1628
+ productFilter: null,
1629
+ requirement: { exact: ['5.21.6'] },
1630
+ },
1631
+ ],
1632
+ },
1633
+ ],
1634
+ products: [
1635
+ { name: 'ExpoMapsExtra', type: { library: ['automatic'] }, targets: ['ExpoMapsExtra'] },
1636
+ ],
1637
+ targets: [
1638
+ {
1639
+ name: 'ExpoMapsExtra',
1640
+ type: 'regular',
1641
+ path: 'ios',
1642
+ dependencies: [
1643
+ { product: ['SDWebImage', 'SDWebImage', null, null] },
1644
+ { product: ['SDWebImageMapKit', 'SDWebImage', null, null] },
1645
+ { byName: ['SDWebImage', null] },
1646
+ ],
1647
+ },
1648
+ ],
1649
+ })
1650
+ );
1651
+
1652
+ resolveExpoModules.mockReturnValue(
1653
+ modulesOf([
1654
+ coreAt(core),
1655
+ ['expo-image', [['ExpoImage', imagePodspecDir]]],
1656
+ ['expo-maps-extra', [['ExpoMapsExtra', maps]]],
1657
+ ])
1658
+ );
1659
+ prebuiltMetadata.mockReturnValue({
1660
+ ExpoImage: {
1661
+ packageRoot: imageRoot,
1662
+ productName: 'ExpoImage',
1663
+ spmPackages: [
1664
+ {
1665
+ url: 'https://github.com/SDWebImage/SDWebImage.git',
1666
+ productName: 'SDWebImage',
1667
+ version: { exact: '5.21.6' },
1668
+ },
1669
+ ],
1670
+ },
1671
+ });
1672
+ resolveFlavoredFramework.mockImplementation(({ frameworkName }) =>
1673
+ frameworkName === 'ExpoModulesCore' || frameworkName === 'ExpoImage'
1674
+ ? { id: frameworkName === 'ExpoImage' ? 'expo-image' : 'expo-modules-core', frameworkName }
1675
+ : null
1676
+ );
1677
+ resolveSpmDependencyFrameworks.mockReturnValue([
1678
+ { id: 'expo-sd-web-image', frameworkName: 'SDWebImage' },
1679
+ ]);
1680
+ providerWrittenTo(outDir);
1681
+ runPlugin(tmp);
1682
+ });
1683
+
1684
+ afterAll(restoreModuleMocks);
1685
+
1686
+ it('warns once, naming the package and its products, and the product named without one', () => {
1687
+ const warnings = logs.warn.mock.calls
1688
+ .map(([text]) => text)
1689
+ .filter((text) => text.includes('from a precompiled framework'));
1690
+ expect(warnings).toHaveLength(1);
1691
+ expect(warnings[0]).toContain(
1692
+ 'Expo module "expo-maps-extra" still declares https://github.com/SDWebImage/SDWebImage.git for "SDWebImageMapKit", while "SDWebImage" comes from a precompiled framework.'
1693
+ );
1694
+ expect(warnings[0]).toContain(
1695
+ 'Expo module "expo-maps-extra" names "SDWebImage" without a package'
1696
+ );
1697
+ expect(warnings[0]).toContain(
1698
+ 'may still build it from https://github.com/SDWebImage/SDWebImage.git, which'
1699
+ );
1700
+ });
1701
+ });
1702
+
1703
+ describe('a pod name two packages both list', () => {
1704
+ captureConsole();
1705
+ let result;
1706
+
1707
+ beforeAll(() => {
1708
+ const tmp = makeTempDir('expo-spm-duplicate-pod-');
1709
+ const core = pureSwiftModule(path.join(tmp, 'expo-modules-core'), 'ExpoModulesCore', spec());
1710
+ resolveExpoModules.mockReturnValue(
1711
+ modulesOf([coreAt(core), ['expo-core-copy', [['ExpoModulesCore', core]]]])
1712
+ );
1713
+ resolveFlavoredFramework.mockClear();
1714
+ providerWrittenTo(path.join(tmp, 'out'));
1715
+ result = runPlugin(tmp);
1716
+ });
1717
+
1718
+ afterAll(restoreModuleMocks);
1719
+
1720
+ it('is one pod, resolved and declared once', () => {
1721
+ expect(resolvedFor('expo-core-copy')).toBeUndefined();
1722
+ expect(result.flavoredFrameworks).toEqual([{ id: 'ExpoModulesCore', name: 'ExpoModulesCore' }]);
1723
+ });
1724
+ });
1725
+
1726
+ describe('a pod name two pure-Swift packages both list first', () => {
1727
+ const logs = captureConsole();
1728
+ let thrown;
1729
+
1730
+ beforeAll(() => {
1731
+ const tmp = makeTempDir('expo-spm-shared-first-pod-');
1732
+ const core = pureSwiftModule(path.join(tmp, 'expo-modules-core'), 'ExpoModulesCore', spec());
1733
+ const first = pureSwiftModule(path.join(tmp, 'expo-first'), 'ExpoShared', spec());
1734
+ fs.writeFileSync(path.join(first, 'ExpoFirstExtra.podspec'), spec());
1735
+ const second = pureSwiftModule(path.join(tmp, 'expo-second'), 'ExpoShared', spec());
1736
+ fs.writeFileSync(path.join(second, 'ExpoSecondExtra.podspec'), spec());
1737
+
1738
+ resolveExpoModules.mockReturnValue(
1739
+ modulesOf([
1740
+ coreAt(core),
1741
+ [
1742
+ 'expo-first',
1743
+ [
1744
+ ['ExpoShared', first],
1745
+ ['ExpoFirstExtra', first],
1746
+ ],
1747
+ ],
1748
+ [
1749
+ 'expo-second',
1750
+ [
1751
+ ['ExpoShared', second],
1752
+ ['ExpoSecondExtra', second],
1753
+ ],
1754
+ ],
1755
+ ])
1756
+ );
1757
+ emitPureSwiftSourcePackage.mockClear();
1758
+ resolveFlavoredFramework.mockClear();
1759
+ prepareCompileInterfaces.mockClear();
1760
+ thrown = thrownBy(() => runPlugin(tmp));
1761
+ });
1762
+
1763
+ afterAll(restoreModuleMocks);
1764
+
1765
+ it('fails the sync on the duplicate pod name before either pass', () => {
1766
+ expect(resolveFlavoredFramework).not.toHaveBeenCalled();
1767
+ expect(prepareCompileInterfaces).not.toHaveBeenCalled();
1768
+ expect(emitPureSwiftSourcePackage).not.toHaveBeenCalled();
1769
+ expect(printed(logs.log)).not.toContain('source pure-Swift');
1770
+ expect(thrown).toBeInstanceOf(UnsupportedModulesError);
1771
+ expect(thrown.unsupported).toEqual([
1772
+ {
1773
+ reason: 'duplicate-pod-name',
1774
+ podName: 'ExpoShared',
1775
+ copies: [
1776
+ expect.objectContaining({ packageName: 'expo-first' }),
1777
+ expect.objectContaining({ packageName: 'expo-second' }),
1778
+ ],
1779
+ },
1780
+ ]);
1781
+ });
1782
+ });
1783
+
1784
+ describe('a checked-in manifest package declaring a pod another package declares', () => {
1785
+ const logs = captureConsole();
1786
+ let roots;
1787
+ let thrown;
1788
+
1789
+ beforeAll(() => {
1790
+ const tmp = fs.realpathSync(makeTempDir('expo-spm-duplicate-pod-name-'));
1791
+ const core = pureSwiftModule(path.join(tmp, 'expo-modules-core'), 'ExpoModulesCore', spec());
1792
+ roots = { first: path.join(tmp, 'expo-first'), second: path.join(tmp, 'expo-second') };
1793
+ const first = pureSwiftModule(roots.first, 'ExpoShared', spec());
1794
+ const second = pureSwiftModule(roots.second, 'ExpoShared', spec());
1795
+ fs.writeFileSync(path.join(second, 'ExpoSecondExtra.podspec'), spec());
1796
+ fs.writeFileSync(path.join(roots.second, 'Package.swift'), '// swift-tools-version:6.0\n');
1797
+
1798
+ resolveExpoModules.mockReturnValue(
1799
+ modulesOf([
1800
+ coreAt(core),
1801
+ ['expo-first', [['ExpoShared', first]]],
1802
+ [
1803
+ 'expo-second',
1804
+ [
1805
+ ['ExpoShared', second],
1806
+ ['ExpoSecondExtra', second],
1807
+ ],
1808
+ ],
1809
+ ])
1810
+ );
1811
+ thrown = thrownBy(() => runPlugin(tmp));
1812
+ });
1813
+
1814
+ afterAll(restoreModuleMocks);
1815
+
1816
+ it('fails the sync naming the pod, both packages and both module roots', () => {
1817
+ expect(thrown).toBeInstanceOf(UnsupportedModulesError);
1818
+ expect(thrown.unsupported).toEqual([
1819
+ {
1820
+ reason: 'duplicate-pod-name',
1821
+ podName: 'ExpoShared',
1822
+ copies: [
1823
+ { packageName: 'expo-first', moduleRoot: roots.first },
1824
+ { packageName: 'expo-second', moduleRoot: roots.second },
1825
+ ],
1826
+ },
1827
+ ]);
1828
+ const report = printed(logs.error);
1829
+ expect(report).toContain('"expo-first"');
1830
+ expect(report).toContain(roots.first);
1831
+ expect(report).toContain(roots.second);
1832
+ expect(report).toContain('"exclude": ["expo-second"]');
1833
+ });
1834
+ });
1835
+
1836
+ /** Precompiles ExpoModulesCore, and `frameworkName` when `packageName` looks it up. */
1837
+ function precompiledFrom(packageName, frameworkName) {
1838
+ resolveFlavoredFramework.mockImplementation((args) =>
1839
+ args.frameworkName === 'ExpoModulesCore' ||
1840
+ (args.frameworkName === frameworkName && args.packageName === packageName)
1841
+ ? { id: args.frameworkName, frameworkName: args.frameworkName }
1842
+ : null
1843
+ );
1844
+ }
1845
+
1846
+ // A fork declaring the same pod is a second copy of it; linking either one would
1847
+ // silently drop the other.
1848
+ describe('a fork declaring the same pod at another root', () => {
1849
+ captureConsole();
1850
+ let roots;
1851
+ let thrown;
1852
+
1853
+ beforeAll(() => {
1854
+ const tmp = fs.realpathSync(makeTempDir('expo-spm-fork-'));
1855
+ const core = pureSwiftModule(path.join(tmp, 'expo-modules-core'), 'ExpoModulesCore', spec());
1856
+ roots = { original: path.join(tmp, 'expo-x'), fork: path.join(tmp, 'expo-x-fork') };
1857
+ const original = pureSwiftModule(roots.original, 'ExpoX', spec());
1858
+ const fork = pureSwiftModule(roots.fork, 'ExpoX', spec());
1859
+
1860
+ resolveExpoModules.mockReturnValue(
1861
+ modulesOf([
1862
+ coreAt(core),
1863
+ ['expo-x', [['ExpoX', original]]],
1864
+ ['expo-x-fork', [['ExpoX', fork]]],
1865
+ ])
1866
+ );
1867
+ providerWrittenTo(path.join(tmp, 'out'));
1868
+ thrown = thrownBy(() => runPlugin(tmp));
1869
+ });
1870
+
1871
+ afterAll(restoreModuleMocks);
1872
+
1873
+ it('fails the sync on the duplicate pod name instead of dropping the second copy', () => {
1874
+ expect(thrown).toBeInstanceOf(UnsupportedModulesError);
1875
+ expect(thrown.unsupported).toEqual([
1876
+ {
1877
+ reason: 'duplicate-pod-name',
1878
+ podName: 'ExpoX',
1879
+ copies: [
1880
+ { packageName: 'expo-x', moduleRoot: roots.original },
1881
+ { packageName: 'expo-x-fork', moduleRoot: roots.fork },
1882
+ ],
1883
+ },
1884
+ ]);
1885
+ });
1886
+ });
1887
+
1888
+ // The document places the pod at the SECOND package, so the first one's copy is
1889
+ // built from there; only the packages' own roots tell the two copies apart.
1890
+ describe('a duplicate pod name the prebuilt-metadata document places at the second package', () => {
1891
+ captureConsole();
1892
+ let roots;
1893
+ let thrown;
1894
+
1895
+ beforeAll(() => {
1896
+ const tmp = fs.realpathSync(makeTempDir('expo-spm-documented-second-'));
1897
+ const core = pureSwiftModule(path.join(tmp, 'expo-modules-core'), 'ExpoModulesCore', spec());
1898
+ roots = { a: path.join(tmp, 'expo-a'), b: path.join(tmp, 'expo-b') };
1899
+ const a = pureSwiftModule(roots.a, 'ExpoX', spec());
1900
+ const b = pureSwiftModule(roots.b, 'ExpoX', spec());
1901
+
1902
+ resolveExpoModules.mockReturnValue(
1903
+ modulesOf([coreAt(core), ['expo-a', [['ExpoX', a]]], ['expo-b', [['ExpoX', b]]]])
1904
+ );
1905
+ prebuiltMetadata.mockReturnValue({ ExpoX: metadataEntry(roots.b, 'ExpoX') });
1906
+ providerWrittenTo(path.join(tmp, 'out'));
1907
+ thrown = thrownBy(() => runPlugin(tmp));
1908
+ });
1909
+
1910
+ afterAll(restoreModuleMocks);
1911
+
1912
+ it("fails the sync, naming each package's own root", () => {
1913
+ expect(thrown).toBeInstanceOf(UnsupportedModulesError);
1914
+ expect(thrown.unsupported).toEqual([
1915
+ {
1916
+ reason: 'duplicate-pod-name',
1917
+ podName: 'ExpoX',
1918
+ copies: [
1919
+ { packageName: 'expo-a', moduleRoot: roots.a },
1920
+ { packageName: 'expo-b', moduleRoot: roots.b },
1921
+ ],
1922
+ },
1923
+ ]);
1924
+ });
1925
+ });
1926
+
1927
+ // Without ExpoModulesCore nothing can be linked, but keeping one copy is still
1928
+ // part of the fix.
1929
+ describe('a duplicate pod name in an app without ExpoModulesCore', () => {
1930
+ captureConsole();
1931
+ let roots;
1932
+ let thrown;
1933
+
1934
+ beforeAll(() => {
1935
+ const tmp = fs.realpathSync(makeTempDir('expo-spm-duplicate-no-core-'));
1936
+ roots = { a: path.join(tmp, 'expo-a'), b: path.join(tmp, 'expo-b') };
1937
+ const a = pureSwiftModule(roots.a, 'ExpoX', spec());
1938
+ const b = pureSwiftModule(roots.b, 'ExpoX', spec());
1939
+
1940
+ resolveExpoModules.mockReturnValue(
1941
+ modulesOf([
1942
+ ['expo-a', [['ExpoX', a]]],
1943
+ ['expo-b', [['ExpoX', b]]],
1944
+ ])
1945
+ );
1946
+ thrown = thrownBy(() => runPlugin(tmp));
1947
+ });
1948
+
1949
+ afterAll(restoreModuleMocks);
1950
+
1951
+ it('reports the duplicate pod name, not the missing core', () => {
1952
+ expect(thrown).toBeInstanceOf(UnsupportedModulesError);
1953
+ expect(thrown.unsupported).toEqual([
1954
+ {
1955
+ reason: 'duplicate-pod-name',
1956
+ podName: 'ExpoX',
1957
+ copies: [
1958
+ { packageName: 'expo-a', moduleRoot: roots.a },
1959
+ { packageName: 'expo-b', moduleRoot: roots.b },
1960
+ ],
1961
+ },
1962
+ ]);
1963
+ });
1964
+ });
1965
+
1966
+ describe('a pod no pass can link, listed by two packages at one module root', () => {
1967
+ captureConsole();
1968
+ let thrown;
1969
+
1970
+ beforeAll(() => {
1971
+ const tmp = makeTempDir('expo-spm-unlinkable-shared-pod-');
1972
+ const core = pureSwiftModule(path.join(tmp, 'expo-modules-core'), 'ExpoModulesCore', spec());
1973
+ const shared = mixedModule(path.join(tmp, 'expo-m'), 'ExpoM');
1974
+
1975
+ resolveExpoModules.mockReturnValue(
1976
+ modulesOf([
1977
+ coreAt(core),
1978
+ ['expo-m', [['ExpoM', shared]]],
1979
+ ['expo-m-alias', [['ExpoM', shared]]],
1980
+ ])
1981
+ );
1982
+ thrown = thrownBy(() => runPlugin(tmp));
1983
+ });
1984
+
1985
+ afterAll(restoreModuleMocks);
1986
+
1987
+ it('reports the pod once', () => {
1988
+ expect(thrown).toBeInstanceOf(UnsupportedModulesError);
1989
+ expect(thrown.unsupported.map(({ podName, reason }) => [podName, reason])).toEqual([
1990
+ ['ExpoM', 'mixed-no-manifest'],
1991
+ ]);
1992
+ });
1993
+ });
1994
+
1995
+ describe('two packages reaching one module root through a symlink', () => {
1996
+ captureConsole();
1997
+ let result;
1998
+
1999
+ beforeAll(() => {
2000
+ const tmp = fs.realpathSync(makeTempDir('expo-spm-symlinked-root-'));
2001
+ const core = pureSwiftModule(path.join(tmp, 'expo-modules-core'), 'ExpoModulesCore', spec());
2002
+ const root = path.join(tmp, 'expo-x');
2003
+ const alias = path.join(tmp, 'expo-x-alias');
2004
+ pureSwiftModule(root, 'ExpoX', spec());
2005
+ fs.symlinkSync(root, alias, 'dir');
2006
+
2007
+ resolveExpoModules.mockReturnValue(
2008
+ modulesOf([
2009
+ coreAt(core),
2010
+ ['expo-x', [['ExpoX', path.join(root, 'ios')]]],
2011
+ ['expo-x-alias', [['ExpoX', path.join(alias, 'ios')]]],
2012
+ ])
2013
+ );
2014
+ emitPureSwiftSourcePackage.mockClear();
2015
+ providerWrittenTo(path.join(tmp, 'out'));
2016
+ result = runPlugin(tmp);
2017
+ });
2018
+
2019
+ afterAll(restoreModuleMocks);
2020
+
2021
+ it('links the pod once, without a duplicate pod name', () => {
2022
+ expect(result).toBeDefined();
2023
+ const emitted = emitPureSwiftSourcePackage.mock.calls.filter(
2024
+ ([args]) => args.product === 'ExpoX'
2025
+ );
2026
+ expect(emitted).toHaveLength(1);
2027
+ });
2028
+ });
2029
+
2030
+ describe('two package names for one checked-in manifest, the second listing one more pod', () => {
2031
+ captureConsole();
2032
+ let result;
2033
+ let thrown;
2034
+
2035
+ beforeAll(() => {
2036
+ const tmp = makeTempDir('expo-spm-manifest-aliases-');
2037
+ const core = pureSwiftModule(path.join(tmp, 'expo-modules-core'), 'ExpoModulesCore', spec());
2038
+ const shared = path.join(tmp, 'shared');
2039
+ const podspecDir = pureSwiftModule(shared, 'ExpoA', spec());
2040
+ fs.writeFileSync(path.join(podspecDir, 'ExpoB.podspec'), spec());
2041
+ fs.mkdirSync(path.join(podspecDir, 'b'));
2042
+ fs.writeFileSync(path.join(podspecDir, 'b', 'B.swift'), '// swift\n');
2043
+ fs.writeFileSync(path.join(shared, 'Package.swift'), '// swift-tools-version: 6.0\n');
2044
+ runDumpPackage.mockReturnValue(
2045
+ JSON.stringify({
2046
+ name: 'ExpoShared',
2047
+ dependencies: [],
2048
+ products: [
2049
+ { name: 'ExpoA', type: { library: ['automatic'] }, targets: ['ExpoA'] },
2050
+ { name: 'ExpoB', type: { library: ['automatic'] }, targets: ['ExpoB'] },
2051
+ ],
2052
+ targets: [
2053
+ { name: 'ExpoA', type: 'regular', path: 'ios', dependencies: [] },
2054
+ { name: 'ExpoB', type: 'regular', path: 'ios/b', dependencies: [] },
2055
+ ],
2056
+ })
2057
+ );
2058
+ resolveExpoModules.mockReturnValue(
2059
+ modulesOf([
2060
+ coreAt(core),
2061
+ ['alias-one', [['ExpoA', podspecDir]]],
2062
+ [
2063
+ 'alias-two',
2064
+ [
2065
+ ['ExpoA', podspecDir],
2066
+ ['ExpoB', podspecDir],
2067
+ ],
2068
+ ],
2069
+ ])
2070
+ );
2071
+ providerWrittenTo(path.join(tmp, 'out'));
2072
+ thrown = thrownBy(() => {
2073
+ result = runPlugin(tmp);
2074
+ });
2075
+ });
2076
+
2077
+ afterAll(() => {
2078
+ runDumpPackage.mockReset();
2079
+ restoreModuleMocks();
2080
+ });
2081
+
2082
+ it("links the second listing's pod through the manifest already emitted", () => {
2083
+ expect(thrown).toBeNull();
2084
+ expect(result.productDependencies).toContainEqual({ name: 'ExpoB', package: 'ExpoShared' });
2085
+ });
2086
+
2087
+ it('declares the manifest package once', () => {
2088
+ expect(result.packageDependencies.filter((dep) => dep.name === 'ExpoShared')).toHaveLength(1);
2089
+ expect(result.productDependencies.filter((dep) => dep.name === 'ExpoB')).toHaveLength(1);
2090
+ });
2091
+ });
2092
+
2093
+ /**
2094
+ * A checked-in manifest exporting ExpoA and ExpoB, listed by two packages: `alias-one`
2095
+ * names ExpoA alone, `alias-two` names ExpoA and `secondPod`. Returns the module root.
2096
+ */
2097
+ function aliasedManifest(tmp, secondPod) {
2098
+ const core = pureSwiftModule(path.join(tmp, 'expo-modules-core'), 'ExpoModulesCore', spec());
2099
+ const shared = path.join(tmp, 'shared');
2100
+ const podspecDir = pureSwiftModule(shared, 'ExpoA', spec());
2101
+ fs.writeFileSync(path.join(podspecDir, `${secondPod}.podspec`), spec());
2102
+ fs.mkdirSync(path.join(podspecDir, 'b'));
2103
+ fs.writeFileSync(path.join(podspecDir, 'b', 'B.swift'), '// swift\n');
2104
+ fs.writeFileSync(path.join(shared, 'Package.swift'), '// swift-tools-version: 6.0\n');
2105
+ runDumpPackage.mockReturnValue(
2106
+ JSON.stringify({
2107
+ name: 'ExpoShared',
2108
+ dependencies: [],
2109
+ products: [
2110
+ { name: 'ExpoA', type: { library: ['automatic'] }, targets: ['ExpoA'] },
2111
+ { name: 'ExpoB', type: { library: ['automatic'] }, targets: ['ExpoB'] },
2112
+ ],
2113
+ targets: [
2114
+ { name: 'ExpoA', type: 'regular', path: 'ios', dependencies: [] },
2115
+ { name: 'ExpoB', type: 'regular', path: 'ios/b', dependencies: [] },
2116
+ ],
2117
+ })
2118
+ );
2119
+ resolveExpoModules.mockReturnValue(
2120
+ modulesOf([
2121
+ coreAt(core),
2122
+ ['alias-one', [['ExpoA', podspecDir]]],
2123
+ [
2124
+ 'alias-two',
2125
+ [
2126
+ ['ExpoA', podspecDir],
2127
+ [secondPod, podspecDir],
2128
+ ],
2129
+ ],
2130
+ ])
2131
+ );
2132
+ providerWrittenTo(path.join(tmp, 'out'));
2133
+ return shared;
2134
+ }
2135
+
2136
+ describe('a second package name listing a pod its checked-in manifest does not export', () => {
2137
+ const logs = captureConsole();
2138
+ let thrown;
2139
+
2140
+ beforeAll(() => {
2141
+ const tmp = makeTempDir('expo-spm-manifest-unexported-');
2142
+ aliasedManifest(tmp, 'ExpoC');
2143
+ thrown = thrownBy(() => runPlugin(tmp));
2144
+ });
2145
+
2146
+ afterAll(() => {
2147
+ runDumpPackage.mockReset();
2148
+ restoreModuleMocks();
2149
+ });
2150
+
2151
+ it('fails the sync saying the manifest does not export its product', () => {
2152
+ expect(thrown).toBeInstanceOf(UnsupportedModulesError);
2153
+ expect(thrown.unsupported).toEqual([
2154
+ expect.objectContaining({
2155
+ reason: 'not-exported-by-manifest',
2156
+ podName: 'ExpoC',
2157
+ packageName: 'alias-two',
2158
+ productName: 'ExpoC',
2159
+ exportedProducts: ['ExpoA', 'ExpoB'],
2160
+ }),
2161
+ ]);
2162
+ const report = printed(logs.error);
2163
+ expect(report).toContain('does not export "ExpoC"');
2164
+ expect(report).not.toContain('mixes Swift and Objective-C');
2165
+ });
2166
+ });
2167
+
2168
+ describe('listings of one checked-in manifest, in every order', () => {
2169
+ captureConsole();
2170
+ const permutations = (items) =>
2171
+ items.length <= 1
2172
+ ? [items]
2173
+ : items.flatMap((item, i) =>
2174
+ permutations([...items.slice(0, i), ...items.slice(i + 1)]).map((rest) => [item, ...rest])
2175
+ );
2176
+ const outcomes = [];
2177
+
2178
+ beforeAll(() => {
2179
+ const tmp = makeTempDir('expo-spm-manifest-orders-');
2180
+ aliasedManifest(tmp, 'ExpoC');
2181
+ const [core, ...listings] = resolveExpoModules().modules;
2182
+ const podspecDir = listings[0].pods[0].podspecDir;
2183
+ listings.push({ packageName: 'alias-three', pods: [{ podName: 'ExpoC', podspecDir }] });
2184
+ for (const order of permutations(listings)) {
2185
+ resolveExpoModules.mockReturnValue({ modules: [core, ...order], extraDependencies: [] });
2186
+ const thrown = thrownBy(() => runPlugin(tmp));
2187
+ outcomes.push({
2188
+ order: order.map((listing) => listing.packageName),
2189
+ refusals: thrown?.unsupported?.map(({ reason, podName }) => ({ reason, podName })),
2190
+ });
2191
+ }
2192
+ });
2193
+
2194
+ afterAll(() => {
2195
+ runDumpPackage.mockReset();
2196
+ restoreModuleMocks();
2197
+ });
2198
+
2199
+ it('refuses the pod the manifest does not export, whichever listing emits it', () => {
2200
+ expect(outcomes).toHaveLength(6);
2201
+ for (const { order, refusals } of outcomes) {
2202
+ expect({ order, refusals }).toEqual({
2203
+ order,
2204
+ refusals: [{ reason: 'not-exported-by-manifest', podName: 'ExpoC' }],
2205
+ });
2206
+ }
2207
+ });
2208
+ });
2209
+
2210
+ describe('a gated-off product reached through a second package name', () => {
2211
+ const logs = captureConsole();
2212
+ let result;
2213
+ let thrown;
2214
+
2215
+ beforeAll(() => {
2216
+ const tmp = makeTempDir('expo-spm-manifest-alias-gated-');
2217
+ const shared = aliasedManifest(tmp, 'ExpoB');
2218
+ const appIosDir = path.join(tmp, 'app', 'ios');
2219
+ fs.mkdirSync(appIosDir, { recursive: true });
2220
+ const podfilePropertiesPath = path.join(appIosDir, 'Podfile.properties.json');
2221
+ fs.writeFileSync(podfilePropertiesPath, JSON.stringify({ 'expo.b-enabled': 'false' }));
2222
+ resolveAppTarget.mockReturnValue({
2223
+ targetName: null,
2224
+ entitlementPath: null,
2225
+ podfilePropertiesPath,
2226
+ });
2227
+ prebuiltMetadata.mockReturnValue({
2228
+ ExpoB: metadataEntry(shared, 'ExpoB', {
2229
+ autolinkWhen: { podfileProperty: 'expo.b-enabled', disabledValue: 'false' },
2230
+ }),
2231
+ });
2232
+ thrown = thrownBy(() => {
2233
+ result = runPlugin(tmp);
2234
+ });
2235
+ });
2236
+
2237
+ afterAll(() => {
2238
+ runDumpPackage.mockReset();
2239
+ resolveAppTarget.mockReturnValue({
2240
+ targetName: null,
2241
+ entitlementPath: null,
2242
+ podfilePropertiesPath: null,
2243
+ });
2244
+ restoreModuleMocks();
2245
+ });
2246
+
2247
+ it('withholds the product, and reports it once', () => {
2248
+ expect(thrown).toBeNull();
2249
+ expect(result.productDependencies).toEqual([{ name: 'ExpoA', package: 'ExpoShared' }]);
2250
+ expect(printed(logs.log)).toContain('gated off (1): ExpoB (expo.b-enabled)');
2251
+ });
2252
+ });
2253
+
2254
+ // A podspec directory that is gone has no package of its own to find: the walk up
2255
+ // would stop at whatever ancestor has a package.json, the same one for both.
2256
+ describe('two missing packages declaring one pod name', () => {
2257
+ captureConsole();
2258
+ let roots;
2259
+ let thrown;
2260
+
2261
+ beforeAll(() => {
2262
+ const tmp = fs.realpathSync(makeTempDir('expo-spm-missing-copies-'));
2263
+ fs.writeFileSync(path.join(tmp, 'package.json'), '{"name":"app"}');
2264
+ const core = pureSwiftModule(path.join(tmp, 'expo-modules-core'), 'ExpoModulesCore', spec());
2265
+ roots = {
2266
+ a: path.join(tmp, 'node_modules', 'pkg-a', 'ios'),
2267
+ b: path.join(tmp, 'node_modules', 'pkg-b', 'ios'),
2268
+ };
2269
+
2270
+ resolveExpoModules.mockReturnValue(
2271
+ modulesOf([coreAt(core), ['pkg-a', [['Foo', roots.a]]], ['pkg-b', [['Foo', roots.b]]]])
2272
+ );
2273
+ prebuiltMetadata.mockReturnValue({
2274
+ Foo: { productName: 'Foo' },
2275
+ });
2276
+ resolveFlavoredFramework.mockImplementation(({ frameworkName }) =>
2277
+ ['ExpoModulesCore', 'Foo'].includes(frameworkName)
2278
+ ? { id: frameworkName, frameworkName }
2279
+ : null
2280
+ );
2281
+ providerWrittenTo(path.join(tmp, 'out'));
2282
+ thrown = thrownBy(() => runPlugin(tmp));
2283
+ });
2284
+
2285
+ afterAll(restoreModuleMocks);
2286
+
2287
+ it('keeps each a separate copy and fails the sync', () => {
2288
+ expect(thrown).toBeInstanceOf(UnsupportedModulesError);
2289
+ expect(thrown.unsupported).toEqual([
2290
+ {
2291
+ reason: 'duplicate-pod-name',
2292
+ podName: 'Foo',
2293
+ copies: [
2294
+ { packageName: 'pkg-a', moduleRoot: roots.a },
2295
+ { packageName: 'pkg-b', moduleRoot: roots.b },
2296
+ ],
2297
+ },
2298
+ ]);
2299
+ });
2300
+ });
2301
+
2302
+ // Whether a copy can be built must not hide the other copy: the duplicate fails
2303
+ // the sync before any copy is linked.
2304
+ describe('a duplicate pod name whose first copy cannot be built', () => {
2305
+ captureConsole();
2306
+ let roots;
2307
+ let thrown;
2308
+
2309
+ beforeAll(() => {
2310
+ const tmp = fs.realpathSync(makeTempDir('expo-spm-unbuildable-first-copy-'));
2311
+ const core = pureSwiftModule(path.join(tmp, 'expo-modules-core'), 'ExpoModulesCore', spec());
2312
+ roots = { a: path.join(tmp, 'expo-a'), b: path.join(tmp, 'expo-b') };
2313
+ const a = mixedModule(roots.a, 'ExpoX');
2314
+ const b = pureSwiftModule(roots.b, 'ExpoX', spec());
2315
+
2316
+ resolveExpoModules.mockReturnValue(
2317
+ modulesOf([coreAt(core), ['expo-a', [['ExpoX', a]]], ['expo-b', [['ExpoX', b]]]])
2318
+ );
2319
+ providerWrittenTo(path.join(tmp, 'out'));
2320
+ thrown = thrownBy(() => runPlugin(tmp));
2321
+ });
2322
+
2323
+ afterAll(restoreModuleMocks);
2324
+
2325
+ it('fails the sync naming both copies', () => {
2326
+ expect(thrown).toBeInstanceOf(UnsupportedModulesError);
2327
+ expect(thrown.unsupported).toEqual([
2328
+ {
2329
+ reason: 'duplicate-pod-name',
2330
+ podName: 'ExpoX',
2331
+ copies: [
2332
+ { packageName: 'expo-a', moduleRoot: roots.a },
2333
+ { packageName: 'expo-b', moduleRoot: roots.b },
2334
+ ],
2335
+ },
2336
+ ]);
2337
+ });
2338
+ });
2339
+
2340
+ describe('a pod whose first listing package has no artifact for it', () => {
2341
+ captureConsole();
2342
+ let result;
2343
+
2344
+ beforeAll(() => {
2345
+ const tmp = makeTempDir('expo-spm-second-artifact-');
2346
+ const core = pureSwiftModule(path.join(tmp, 'expo-modules-core'), 'ExpoModulesCore', spec());
2347
+ const shared = pureSwiftModule(path.join(tmp, 'shared'), 'ExpoX', spec());
2348
+
2349
+ resolveExpoModules.mockReturnValue(
2350
+ modulesOf([coreAt(core), ['expo-a', [['ExpoX', shared]]], ['expo-b', [['ExpoX', shared]]]])
2351
+ );
2352
+ precompiledFrom('expo-b', 'ExpoX');
2353
+ providerWrittenTo(path.join(tmp, 'out'));
2354
+ result = runPlugin(tmp);
2355
+ });
2356
+
2357
+ afterAll(restoreModuleMocks);
2358
+
2359
+ it('precompiles it from the next package that has one', () => {
2360
+ expect(result.flavoredFrameworks).toContainEqual({ id: 'ExpoX', frameworkName: 'ExpoX' });
2361
+ });
2362
+ });
2363
+
2364
+ describe('a duplicate pod name the prebuilt-metadata document places at the first package', () => {
2365
+ captureConsole();
2366
+ let roots;
2367
+ let thrown;
2368
+
2369
+ beforeAll(() => {
2370
+ const tmp = fs.realpathSync(makeTempDir('expo-spm-documented-duplicate-'));
2371
+ const core = pureSwiftModule(path.join(tmp, 'expo-modules-core'), 'ExpoModulesCore', spec());
2372
+ roots = { a: path.join(tmp, 'expo-a'), b: path.join(tmp, 'expo-b') };
2373
+ const a = pureSwiftModule(roots.a, 'ExpoX', spec());
2374
+ fs.writeFileSync(path.join(a, 'ExpoAExtra.podspec'), spec());
2375
+ const b = pureSwiftModule(roots.b, 'ExpoX', spec());
2376
+ fs.writeFileSync(path.join(b, 'ExpoBExtra.podspec'), spec());
2377
+
2378
+ resolveExpoModules.mockReturnValue(
2379
+ modulesOf([
2380
+ coreAt(core),
2381
+ [
2382
+ 'expo-a',
2383
+ [
2384
+ ['ExpoX', a],
2385
+ ['ExpoAExtra', a],
2386
+ ],
2387
+ ],
2388
+ [
2389
+ 'expo-b',
2390
+ [
2391
+ ['ExpoX', b],
2392
+ ['ExpoBExtra', b],
2393
+ ],
2394
+ ],
2395
+ ])
2396
+ );
2397
+ prebuiltMetadata.mockReturnValue({ ExpoX: metadataEntry(roots.a, 'ExpoX') });
2398
+ thrown = thrownBy(() => runPlugin(tmp));
2399
+ });
2400
+
2401
+ afterAll(restoreModuleMocks);
2402
+
2403
+ it("fails the sync, naming each package's own root", () => {
2404
+ expect(thrown).toBeInstanceOf(UnsupportedModulesError);
2405
+ expect(thrown.unsupported).toEqual([
2406
+ {
2407
+ reason: 'duplicate-pod-name',
2408
+ podName: 'ExpoX',
2409
+ copies: [
2410
+ { packageName: 'expo-a', moduleRoot: roots.a },
2411
+ { packageName: 'expo-b', moduleRoot: roots.b },
2412
+ ],
2413
+ },
2414
+ ]);
2415
+ });
2416
+ });
2417
+
2418
+ describe('a pure-Swift package listing a pod another package precompiled', () => {
2419
+ captureConsole();
2420
+ let thrown;
2421
+
2422
+ beforeAll(() => {
2423
+ const tmp = fs.realpathSync(makeTempDir('expo-spm-foreign-precompiled-'));
2424
+ const core = pureSwiftModule(path.join(tmp, 'expo-modules-core'), 'ExpoModulesCore', spec());
2425
+ const a = pureSwiftModule(path.join(tmp, 'expo-a'), 'ExpoX', spec());
2426
+ const b = pureSwiftModule(path.join(tmp, 'expo-b'), 'ExpoBOwn', spec());
2427
+ fs.writeFileSync(path.join(b, 'ExpoX.podspec'), spec());
2428
+
2429
+ resolveExpoModules.mockReturnValue(
2430
+ modulesOf([
2431
+ coreAt(core),
2432
+ ['expo-a', [['ExpoX', a]]],
2433
+ [
2434
+ 'expo-b',
2435
+ [
2436
+ ['ExpoBOwn', b],
2437
+ ['ExpoX', b],
2438
+ ],
2439
+ ],
2440
+ ])
2441
+ );
2442
+ precompiledFrom('expo-a', 'ExpoX');
2443
+ thrown = thrownBy(() => runPlugin(tmp));
2444
+ });
2445
+
2446
+ afterAll(restoreModuleMocks);
2447
+
2448
+ it('reports the duplicate pod name, not a partially precompiled module', () => {
2449
+ expect(thrown).toBeInstanceOf(UnsupportedModulesError);
2450
+ expect(thrown.unsupported).toEqual([
2451
+ expect.objectContaining({
2452
+ reason: 'duplicate-pod-name',
2453
+ podName: 'ExpoX',
2454
+ copies: [
2455
+ expect.objectContaining({ packageName: 'expo-a' }),
2456
+ expect.objectContaining({ packageName: 'expo-b' }),
2457
+ ],
2458
+ }),
2459
+ ]);
2460
+ });
2461
+ });
2462
+
2463
+ // A refusal belongs to the module root the refused module was read from, so every
2464
+ // uncovered pod at that root carries it — whichever package listed the pod.
2465
+ describe('two packages resolving to one module root', () => {
2466
+ captureConsole();
2467
+ let thrown;
2468
+
2469
+ beforeAll(() => {
2470
+ const tmp = makeTempDir('expo-spm-shared-root-');
2471
+ const core = pureSwiftModule(path.join(tmp, 'expo-modules-core'), 'ExpoModulesCore', spec());
2472
+ const shared = pureSwiftModule(path.join(tmp, 'shared'), 'ExpoSharedA', spec());
2473
+ fs.writeFileSync(path.join(shared, 'ExpoSharedB.podspec'), spec());
2474
+ fs.writeFileSync(path.join(shared, 'ExpoSharedC.podspec'), spec(" s.frameworks = 'Photos'"));
2475
+
2476
+ resolveExpoModules.mockReturnValue(
2477
+ modulesOf([
2478
+ coreAt(core),
2479
+ [
2480
+ 'expo-shared-ab',
2481
+ [
2482
+ ['ExpoSharedA', shared],
2483
+ ['ExpoSharedB', shared],
2484
+ ],
2485
+ ],
2486
+ ['expo-shared-c', [['ExpoSharedC', shared]]],
2487
+ ])
2488
+ );
2489
+ thrown = thrownBy(() => runPlugin(tmp));
2490
+ });
2491
+
2492
+ afterAll(restoreModuleMocks);
2493
+
2494
+ it('refuses every uncovered pod at that root for the linkage one module declares', () => {
2495
+ expect(thrown).toBeInstanceOf(UnsupportedModulesError);
2496
+ expect(thrown.unsupported.map(({ podName, reason }) => [podName, reason])).toEqual([
2497
+ ['ExpoSharedB', 'needs-manifest-for-linkage'],
2498
+ ['ExpoSharedC', 'needs-manifest-for-linkage'],
2499
+ ]);
2500
+ });
2501
+ });
2502
+
2503
+ /**
2504
+ * Runs the plugin over `expo-empty`, a module with a podspec at its root and no Apple
2505
+ * source directory. Returns the error it fails with and the module root.
2506
+ */
2507
+ function runWithoutSources(prefix, podspec) {
2508
+ const tmp = makeTempDir(prefix);
2509
+ const core = pureSwiftModule(path.join(tmp, 'expo-modules-core'), 'ExpoModulesCore', spec());
2510
+ const root = path.join(tmp, 'expo-empty');
2511
+ fs.mkdirSync(root, { recursive: true });
2512
+ fs.writeFileSync(path.join(root, 'package.json'), '{"name":"expo-empty"}');
2513
+ fs.writeFileSync(path.join(root, 'ExpoEmpty.podspec'), podspec);
2514
+ resolveExpoModules.mockReturnValue(
2515
+ modulesOf([coreAt(core), ['expo-empty', [['ExpoEmpty', root]]]])
2516
+ );
2517
+ prebuiltMetadata.mockReturnValue({
2518
+ ExpoEmpty: metadataEntry(root, 'ExpoEmptyProduct', { sourceOnly: true }),
2519
+ });
2520
+ return { thrown: thrownBy(() => runPlugin(tmp)), root };
2521
+ }
2522
+
2523
+ describe('a module with no Apple source directory', () => {
2524
+ captureConsole();
2525
+ let thrown;
2526
+ let root;
2527
+
2528
+ beforeAll(() => {
2529
+ ({ thrown, root } = runWithoutSources('expo-spm-no-sources-', spec()));
2530
+ });
2531
+
2532
+ afterAll(restoreModuleMocks);
2533
+
2534
+ it('fails the sync with the facts its identity gives', () => {
2535
+ expect(thrown.unsupported).toEqual([
2536
+ {
2537
+ reason: 'no-apple-sources',
2538
+ podName: 'ExpoEmpty',
2539
+ packageName: 'expo-empty',
2540
+ moduleRoot: root,
2541
+ productName: 'ExpoEmptyProduct',
2542
+ },
2543
+ ]);
2544
+ });
2545
+ });
2546
+
2547
+ describe('a module with no Apple source directory whose podspec declares linkage', () => {
2548
+ captureConsole();
2549
+ let thrown;
2550
+ let root;
2551
+
2552
+ beforeAll(() => {
2553
+ ({ thrown, root } = runWithoutSources(
2554
+ 'expo-spm-no-sources-linkage-',
2555
+ spec(" s.frameworks = 'Photos'")
2556
+ ));
2557
+ });
2558
+
2559
+ afterAll(restoreModuleMocks);
2560
+
2561
+ it('fails the sync on the linkage, which is the more specific fault', () => {
2562
+ expect(thrown.unsupported).toEqual([
2563
+ {
2564
+ reason: 'needs-manifest-for-linkage',
2565
+ podName: 'ExpoEmpty',
2566
+ packageName: 'expo-empty',
2567
+ moduleRoot: root,
2568
+ file: path.join(root, 'ExpoEmpty.podspec'),
2569
+ line: 2,
2570
+ snippet: "s.frameworks = 'Photos'",
2571
+ },
2572
+ ]);
2573
+ });
2574
+ });
2575
+
2576
+ describe('a pure-Swift emission that is refused', () => {
2577
+ const logs = captureConsole();
2578
+ let thrown;
2579
+
2580
+ beforeAll(() => {
2581
+ const tmp = makeTempDir('expo-spm-pure-swift-refusal-');
2582
+ const core = pureSwiftModule(path.join(tmp, 'expo-modules-core'), 'ExpoModulesCore', spec());
2583
+ const refused = pureSwiftModule(path.join(tmp, 'expo-refused'), 'ExpoRefused', spec());
2584
+
2585
+ resolveExpoModules.mockReturnValue(
2586
+ modulesOf([coreAt(core), ['expo-refused', [['ExpoRefused', refused]]]])
2587
+ );
2588
+ emitPureSwiftSourcePackage.mockImplementationOnce(() => ({
2589
+ refusal: { reason: 'unresolvable-target-path', targetNames: ['ExpoRefused'] },
2590
+ }));
2591
+ thrown = thrownBy(() => runPlugin(tmp));
2592
+ });
2593
+
2594
+ afterAll(restoreModuleMocks);
2595
+
2596
+ it('fails the sync with the diagnostic registered for the refusal', () => {
2597
+ expect(thrown).toBeInstanceOf(UnsupportedModulesError);
2598
+ expect(thrown.unsupported).toEqual([
2599
+ expect.objectContaining({
2600
+ reason: 'unresolvable-target-path',
2601
+ podName: 'ExpoRefused',
2602
+ targetNames: ['ExpoRefused'],
2603
+ }),
2604
+ ]);
2605
+ expect(printed(logs.error)).toContain('"ExpoRefused" declare no `path:`');
2606
+ });
2607
+ });
2608
+
2609
+ describe('a Swift macro plugin that does not resolve', () => {
2610
+ // pnpm's jest launcher sets a NODE_PATH that finds the plugin whatever `paths`
2611
+ // says, so the resolution runs in a Node process without it, from a root with no
2612
+ // node_modules above it.
2613
+ it('fails with the resolution error as its cause', () => {
2614
+ const coreRoot = makeTempDir('expo-spm-no-macros-');
2615
+ const script = `
2616
+ const { macroPluginFlags } = require(${JSON.stringify(require.resolve('../plugin'))});
2617
+ try {
2618
+ macroPluginFlags(${JSON.stringify(coreRoot)});
2619
+ } catch (error) {
2620
+ process.stdout.write(JSON.stringify({ message: error.message, cause: error.cause?.code }));
2621
+ }`;
2622
+ const { NODE_PATH: _nodePath, ...env } = process.env;
2623
+ const { message, cause } = JSON.parse(
2624
+ require('child_process').execFileSync(process.execPath, ['-e', script], {
2625
+ encoding: 'utf8',
2626
+ env,
2627
+ })
2628
+ );
2629
+ expect(message).toContain('Could not resolve "expo-modules-macros"');
2630
+ expect(cause).toBe('MODULE_NOT_FOUND');
2631
+ });
2632
+ });
2633
+
2634
+ describe('a metadata entry the plugin cannot read', () => {
2635
+ captureConsole();
2636
+
2637
+ afterAll(restoreModuleMocks);
2638
+
2639
+ it('fails the sync naming the pod and the field, before emitting anything', () => {
2640
+ const tmp = makeTempDir('expo-spm-malformed-metadata-');
2641
+ const core = pureSwiftModule(path.join(tmp, 'expo-modules-core'), 'ExpoModulesCore', spec());
2642
+ const imageRoot = path.join(tmp, 'expo-image');
2643
+ const image = pureSwiftModule(imageRoot, 'ExpoImage', spec());
2644
+ resolveExpoModules.mockReturnValue(
2645
+ modulesOf([coreAt(core), ['expo-image', [['ExpoImage', image]]]])
2646
+ );
2647
+ prebuiltMetadata.mockReturnValue({
2648
+ ExpoImage: metadataEntry(imageRoot, 'ExpoImage', {
2649
+ spmPackages: [{ productName: 'SDWebImage', version: { exact: '5.21.6' } }],
2650
+ }),
2651
+ });
2652
+ providerWrittenTo(path.join(tmp, 'out'));
2653
+
2654
+ const error = thrownBy(() => runPlugin(tmp));
2655
+
2656
+ expect(error).not.toBeInstanceOf(TypeError);
2657
+ expect(error?.message).toMatch(/^\[expo-spm-plugin\] /);
2658
+ expect(error?.message).toContain('ExpoImage');
2659
+ expect(error?.message).toContain('spmPackages[0].url');
2660
+ expect(fs.existsSync(path.join(tmp, 'out', 'expo', 'expo-source'))).toBe(false);
2661
+ });
2662
+ });
2663
+
2664
+ // A module that ships a checked-in Package.swift declares its SwiftPM packages there
2665
+ // rather than in an spm.config.json, and those cover the pods its podspec names just
2666
+ // as the pure-Swift branch's do.
2667
+ describe('the SwiftPM packages a checked-in manifest declares', () => {
2668
+ const logs = captureConsole();
2669
+ let manifest;
2670
+
2671
+ beforeAll(() => {
2672
+ const tmp = makeTempDir('expo-spm-manifest-deps-plugin-');
2673
+ const outDir = path.join(tmp, 'out');
2674
+ const core = pureSwiftModule(path.join(tmp, 'expo-modules-core'), 'ExpoModulesCore', spec());
2675
+ const imageRoot = path.join(tmp, 'expo-image');
2676
+ const image = pureSwiftModule(
2677
+ imageRoot,
2678
+ 'ExpoImage',
2679
+ spec(
2680
+ " s.dependency 'ExpoModulesCore'",
2681
+ " s.dependency 'SDWebImage'",
2682
+ " s.dependency 'libavif/libdav1d'",
2683
+ " s.dependency 'SomeUnmappedPod'"
2684
+ )
2685
+ );
2686
+ fs.writeFileSync(
2687
+ path.join(imageRoot, 'Package.swift'),
2688
+ '// swift-tools-version: 6.0\n// checked in by the module\n'
2689
+ );
2690
+ const remote = (identity, url, version) => ({
2691
+ sourceControl: [
2692
+ {
2693
+ identity,
2694
+ location: { remote: [{ urlString: url }] },
2695
+ productFilter: null,
2696
+ requirement: { exact: [version] },
2697
+ },
2698
+ ],
2699
+ });
2700
+ runDumpPackage.mockReturnValue(
2701
+ JSON.stringify({
2702
+ name: 'ExpoImage',
2703
+ dependencies: [
2704
+ remote('sdwebimage', 'https://github.com/SDWebImage/SDWebImage.git', '5.21.6'),
2705
+ remote('libavif-xcode', 'https://github.com/SDWebImage/libavif-Xcode.git', '1.0.0'),
2706
+ ],
2707
+ products: [{ name: 'ExpoImage', type: { library: ['automatic'] }, targets: ['ExpoImage'] }],
2708
+ targets: [
2709
+ {
2710
+ name: 'ExpoImage',
2711
+ type: 'regular',
2712
+ path: 'ios',
2713
+ dependencies: [
2714
+ { product: ['SDWebImage', 'SDWebImage', null, null] },
2715
+ { product: ['libavif', 'libavif-Xcode', null, null] },
2716
+ ],
2717
+ },
2718
+ ],
2719
+ })
2720
+ );
2721
+
2722
+ resolveExpoModules.mockReturnValue(
2723
+ modulesOf([coreAt(core), ['expo-image', [['ExpoImage', image]]]])
2724
+ );
2725
+ providerWrittenTo(outDir);
2726
+ runPlugin(tmp);
2727
+ manifest = fs.readFileSync(
2728
+ path.join(outDir, 'expo', 'expo-source', 'ExpoImage', 'Package.swift'),
2729
+ 'utf8'
2730
+ );
2731
+ });
2732
+
2733
+ afterAll(restoreModuleMocks);
2734
+
2735
+ it('mirrors them into the generated manifest', () => {
2736
+ expect(manifest).toContain(
2737
+ '.package(url: "https://github.com/SDWebImage/SDWebImage.git", exact: "5.21.6"),'
2738
+ );
2739
+ expect(manifest).toContain('.product(name: "libavif", package: "libavif-Xcode"),');
2740
+ });
2741
+
2742
+ it('counts them as counterparts of the pods its podspec depends on', () => {
2743
+ const report = printed(logs.warn);
2744
+ expect(report).toContain('warning: Expo module "expo-image" (pod ExpoImage)');
2745
+ expect(report).toContain('SomeUnmappedPod');
2746
+ expect(report).not.toContain('SDWebImage');
2747
+ // The podspec asks for `libavif/libdav1d` and the check matches on the root name,
2748
+ // as CocoaPods does — the mirrored product is `libavif`, whatever its package is
2749
+ // called.
2750
+ expect(report).not.toContain('libavif');
2751
+ });
2752
+ });
2753
+
2754
+ describe('a pure-Swift package shipping a companion pod', () => {
2755
+ const logs = captureConsole();
2756
+ let thrown;
2757
+
2758
+ beforeAll(() => {
2759
+ const tmp = makeTempDir('expo-spm-companion-');
2760
+ const core = pureSwiftModule(path.join(tmp, 'expo-modules-core'), 'ExpoModulesCore', spec());
2761
+ const camera = pureSwiftModule(
2762
+ path.join(tmp, 'expo-camera'),
2763
+ 'ExpoCamera',
2764
+ spec(" s.platforms = { :ios => '16.4' }")
2765
+ );
2766
+
2767
+ resolveExpoModules.mockReturnValue(
2768
+ modulesOf([
2769
+ coreAt(core),
2770
+ [
2771
+ 'expo-camera',
2772
+ [
2773
+ ['ExpoCamera', camera],
2774
+ ['ExpoCameraBarcodeScanning', camera],
2775
+ ],
2776
+ ],
2777
+ ])
2778
+ );
2779
+ thrown = thrownBy(() => runPlugin(tmp));
2780
+ });
2781
+
2782
+ afterAll(restoreModuleMocks);
2783
+
2784
+ it('emits the single target the pure-Swift branch builds', () => {
2785
+ const report = printed(logs.log);
2786
+ expect(report).toContain('source pure-Swift (1): ExpoCamera\n');
2787
+ });
2788
+
2789
+ // The branch emits one target, for the first pod. Marking the rest of the package
2790
+ // emitted too would drop the companion out of the install with no diagnostic at
2791
+ // all — it fails at runtime with "Cannot find native module" instead.
2792
+ it('reports the companion pod it does not build', () => {
2793
+ const report = printed(logs.error);
2794
+ expect(report).toContain('ExpoCameraBarcodeScanning');
2795
+ expect(thrown).toBeInstanceOf(UnsupportedModulesError);
2796
+ expect(thrown.unsupported.map((u) => u.podName)).toEqual(['ExpoCameraBarcodeScanning']);
2797
+ });
2798
+ });
2799
+
2800
+ // expo-camera is the shape: one checked-in manifest, two products, one pod. The
2801
+ // barcode scanner is a companion product autolinking never resolves as a pod, so
2802
+ // only the manifest links it.
2803
+ describe('a checked-in manifest declaring a companion product', () => {
2804
+ const logs = captureConsole();
2805
+ let manifest;
2806
+ let thrown;
2807
+
2808
+ beforeAll(() => {
2809
+ const tmp = makeTempDir('expo-spm-manifest-multipod-');
2810
+ const outDir = path.join(tmp, 'out');
2811
+ const core = pureSwiftModule(path.join(tmp, 'expo-modules-core'), 'ExpoModulesCore', spec());
2812
+ const cameraRoot = path.join(tmp, 'expo-camera');
2813
+ const camera = pureSwiftModule(cameraRoot, 'ExpoCamera', spec());
2814
+ fs.mkdirSync(path.join(camera, 'barcode-scanning'), { recursive: true });
2815
+ fs.writeFileSync(path.join(camera, 'barcode-scanning', 'Scanner.swift'), '// swift\n');
2816
+ fs.writeFileSync(
2817
+ path.join(cameraRoot, 'Package.swift'),
2818
+ '// swift-tools-version: 6.0\n// checked in by the module\n'
2819
+ );
2820
+ runDumpPackage.mockReturnValue(
2821
+ JSON.stringify({
2822
+ name: 'ExpoCamera',
2823
+ dependencies: [],
2824
+ products: [
2825
+ { name: 'ExpoCamera', type: { library: ['automatic'] }, targets: ['ExpoCamera'] },
2826
+ {
2827
+ name: 'ExpoCameraBarcodeScanning',
2828
+ type: { library: ['automatic'] },
2829
+ targets: ['ExpoCameraBarcodeScanning'],
2830
+ },
2831
+ ],
2832
+ targets: [
2833
+ { name: 'ExpoCamera', type: 'regular', path: 'ios', dependencies: [] },
2834
+ {
2835
+ name: 'ExpoCameraBarcodeScanning',
2836
+ type: 'regular',
2837
+ path: 'ios/barcode-scanning',
2838
+ dependencies: [{ byName: ['ExpoCamera', null] }],
2839
+ },
2840
+ ],
2841
+ })
2842
+ );
2843
+
2844
+ resolveExpoModules.mockReturnValue(
2845
+ modulesOf([coreAt(core), ['expo-camera', [['ExpoCamera', camera]]]])
2846
+ );
2847
+ providerWrittenTo(outDir);
2848
+ thrown = thrownBy(() => runPlugin(tmp));
2849
+ manifest = fs.readFileSync(
2850
+ path.join(outDir, 'expo', 'expo-source', 'ExpoCamera', 'Package.swift'),
2851
+ 'utf8'
2852
+ );
2853
+ });
2854
+
2855
+ afterAll(restoreModuleMocks);
2856
+
2857
+ it("mirrors a target for each of the manifest's products", () => {
2858
+ expect(manifest).toContain('name: "ExpoCamera"');
2859
+ expect(manifest).toContain('name: "ExpoCameraBarcodeScanning"');
2860
+ });
2861
+
2862
+ it('covers every pod of the package, so none is reported uncovered', () => {
2863
+ const report = printed(logs.log);
2864
+ expect(report).toContain('not supported (0): —');
2865
+ expect(logs.error).not.toHaveBeenCalled();
2866
+ expect(thrown).toBeNull();
2867
+ });
2868
+ });
2869
+
2870
+ // The gate a companion product declares in its spm.config.json. expo-camera's
2871
+ // barcode scanner is the one that ships: a second product of the same package,
2872
+ // linked only when the app's Podfile properties do not disable it.
2873
+ describe('a product gated by an autolinkWhen condition', () => {
2874
+ const logs = captureConsole({ each: true });
2875
+ let tmp;
2876
+ let cameraRoot;
2877
+
2878
+ beforeEach(() => {
2879
+ tmp = makeTempDir('expo-spm-gated-');
2880
+ const core = pureSwiftModule(path.join(tmp, 'expo-modules-core'), 'ExpoModulesCore', spec());
2881
+ cameraRoot = path.join(tmp, 'expo-camera');
2882
+ const camera = pureSwiftModule(cameraRoot, 'ExpoCamera', spec());
2883
+ fs.mkdirSync(path.join(camera, 'barcode-scanning'), { recursive: true });
2884
+ fs.writeFileSync(path.join(camera, 'barcode-scanning', 'Scanner.swift'), '// swift\n');
2885
+ fs.writeFileSync(
2886
+ path.join(cameraRoot, 'Package.swift'),
2887
+ '// swift-tools-version: 6.0\n// checked in by the module\n'
2888
+ );
2889
+ runDumpPackage.mockReturnValue(
2890
+ JSON.stringify({
2891
+ name: 'ExpoCamera',
2892
+ dependencies: [],
2893
+ products: [
2894
+ { name: 'ExpoCamera', type: { library: ['automatic'] }, targets: ['ExpoCamera'] },
2895
+ {
2896
+ name: 'ExpoCameraBarcodeScanning',
2897
+ type: { library: ['automatic'] },
2898
+ targets: ['ExpoCameraBarcodeScanning'],
2899
+ },
2900
+ ],
2901
+ targets: [
2902
+ { name: 'ExpoCamera', type: 'regular', path: 'ios', dependencies: [] },
2903
+ {
2904
+ name: 'ExpoCameraBarcodeScanning',
2905
+ type: 'regular',
2906
+ path: 'ios/barcode-scanning',
2907
+ dependencies: [{ byName: ['ExpoCamera', null] }],
2908
+ },
2909
+ ],
2910
+ })
2911
+ );
2912
+ resolveExpoModules.mockReturnValue(
2913
+ modulesOf([coreAt(core), ['expo-camera', [['ExpoCamera', camera]]]])
2914
+ );
2915
+ });
2916
+
2917
+ afterEach(() => {
2918
+ runDumpPackage.mockReset();
2919
+ restoreModuleMocks();
2920
+ });
2921
+
2922
+ /** The properties are read off a real file, through the real reader. */
2923
+ const run = ({ metadata, properties = null, autolinking }) => {
2924
+ withPodfileProperties(tmp, properties);
2925
+ prebuiltMetadata.mockReturnValue(metadata);
2926
+ providerWrittenTo(path.join(tmp, 'out'));
2927
+ const result = runPlugin(tmp, autolinking ? { autolinking } : {});
2928
+ return { result, report: printed(logs.log) };
2929
+ };
2930
+
2931
+ const cameraMetadata = (gate) => ({
2932
+ ExpoCamera: metadataEntry(cameraRoot, 'ExpoCamera'),
2933
+ ExpoCameraBarcodeScanning: metadataEntry(cameraRoot, 'ExpoCameraBarcodeScanning', {
2934
+ autolinkWhen: gate,
2935
+ }),
2936
+ });
2937
+ const enabled = { 'expo.camera.barcode-scanner-enabled': 'true' };
2938
+ const disabled = { 'expo.camera.barcode-scanner-enabled': 'false' };
2939
+ const cameraProduct = { name: 'ExpoCamera', package: 'ExpoCamera' };
2940
+ const scannerProduct = { name: 'ExpoCameraBarcodeScanning', package: 'ExpoCamera' };
2941
+ const gatedOff = (label) => `gated off (1): ExpoCameraBarcodeScanning (${label})`;
2942
+
2943
+ it.each([
2944
+ {
2945
+ title: 'wires the gated product when the condition is met',
2946
+ metadata: () => cameraMetadata(barcodeGate),
2947
+ properties: enabled,
2948
+ withheldBy: null,
2949
+ },
2950
+ {
2951
+ title: 'withholds the gated product, and reports it, when the condition is not met',
2952
+ metadata: () => cameraMetadata(barcodeGate),
2953
+ properties: disabled,
2954
+ withheldBy: 'expo.camera.barcode-scanner-enabled',
2955
+ },
2956
+ {
2957
+ title: 'fails open: wires a product no metadata entry names',
2958
+ metadata: () => ({ ExpoCamera: metadataEntry(cameraRoot, 'ExpoCamera') }),
2959
+ properties: disabled,
2960
+ withheldBy: null,
2961
+ },
2962
+ {
2963
+ title: "ignores a same-named product's gate in another package",
2964
+ metadata: () => ({
2965
+ ExpoCamera: metadataEntry(cameraRoot, 'ExpoCamera'),
2966
+ OtherBarcodeScanning: metadataEntry(
2967
+ path.join(tmp, 'other-camera'),
2968
+ 'ExpoCameraBarcodeScanning',
2969
+ { autolinkWhen: barcodeGate }
2970
+ ),
2971
+ }),
2972
+ properties: disabled,
2973
+ withheldBy: null,
2974
+ },
2975
+ {
2976
+ title: 'wires a product gated on a pod the document declares, though no module lists it',
2977
+ metadata: () => ({
2978
+ ExpoCamera: metadataEntry(cameraRoot, 'ExpoCamera'),
2979
+ ExpoCameraBarcodeScanning: metadataEntry(cameraRoot, 'ExpoCameraBarcodeScanning', {
2980
+ autolinkWhen: { podName: 'RNWorklets' },
2981
+ }),
2982
+ RNWorklets: metadataEntry(path.join(tmp, 'react-native-worklets'), 'RNWorklets'),
2983
+ }),
2984
+ properties: null,
2985
+ withheldBy: null,
2986
+ },
2987
+ {
2988
+ title: 'withholds a product gated on a pod the document does not declare',
2989
+ metadata: () => cameraMetadata({ podName: 'RNWorklets' }),
2990
+ properties: null,
2991
+ withheldBy: 'RNWorklets',
2992
+ },
2993
+ {
2994
+ title: 'wires a product gated on an npm package the app autolinks',
2995
+ metadata: () => cameraMetadata({ npmPackage: 'expo-modules-core' }),
2996
+ properties: null,
2997
+ withheldBy: null,
2998
+ },
2999
+ {
3000
+ title: 'withholds a product gated on an npm package the app does not autolink',
3001
+ metadata: () => cameraMetadata({ npmPackage: 'react-native-worklets' }),
3002
+ properties: null,
3003
+ withheldBy: 'react-native-worklets',
3004
+ },
3005
+ {
3006
+ // As CocoaPods, which reads the React Native config: the key alone counts,
3007
+ // whether or not its root is on disk.
3008
+ title: 'wires a product gated on an npm package React Native autolinks',
3009
+ metadata: () => cameraMetadata({ npmPackage: 'react-native-worklets' }),
3010
+ properties: null,
3011
+ autolinking: {
3012
+ dependencies: { 'react-native-worklets': { root: '/nonexistent/react-native-worklets' } },
3013
+ },
3014
+ withheldBy: null,
3015
+ },
3016
+ {
3017
+ title: 'matches the entry by its product name, not by its pod key',
3018
+ metadata: () => ({
3019
+ ExpoCamera: metadataEntry(cameraRoot, 'ExpoCamera'),
3020
+ ExpoCameraBarcodeScanner: metadataEntry(cameraRoot, 'ExpoCameraBarcodeScanning', {
3021
+ autolinkWhen: barcodeGate,
3022
+ }),
3023
+ }),
3024
+ properties: disabled,
3025
+ withheldBy: 'expo.camera.barcode-scanner-enabled',
3026
+ },
3027
+ {
3028
+ title: 'matches an entry naming no product by its pod key',
3029
+ metadata: () => ({
3030
+ ExpoCamera: metadataEntry(cameraRoot, 'ExpoCamera'),
3031
+ ExpoCameraBarcodeScanning: { packageRoot: cameraRoot, autolinkWhen: barcodeGate },
3032
+ }),
3033
+ properties: disabled,
3034
+ withheldBy: 'expo.camera.barcode-scanner-enabled',
3035
+ },
3036
+ {
3037
+ title: 'withholds, as CocoaPods does, a product whose condition names no recognized key',
3038
+ metadata: () => cameraMetadata({}),
3039
+ properties: null,
3040
+ withheldBy: 'unrecognized condition',
3041
+ },
3042
+ ])('$title', ({ metadata, properties, autolinking, withheldBy }) => {
3043
+ const { result, report } = run({ metadata: metadata(), properties, autolinking });
3044
+
3045
+ if (withheldBy == null) {
3046
+ expect(result.productDependencies).toEqual([cameraProduct, scannerProduct]);
3047
+ expect(report).toContain('gated off (0): —');
3048
+ } else {
3049
+ expect(result.productDependencies).toEqual([cameraProduct]);
3050
+ expect(report).toContain(gatedOff(withheldBy));
3051
+ }
3052
+ });
3053
+
3054
+ it('withholds a gated companion pod that only the document declares', () => {
3055
+ const [core, camera] = resolveExpoModules().modules;
3056
+ resolveExpoModules.mockReturnValue({
3057
+ modules: [core, { ...camera, pods: [camera.pods[0]] }],
3058
+ extraDependencies: [],
3059
+ });
3060
+ const { result, report } = run({ metadata: cameraMetadata(barcodeGate), properties: disabled });
3061
+
3062
+ expect(result.productDependencies).toEqual([cameraProduct]);
3063
+ expect(report).toContain(gatedOff('expo.camera.barcode-scanner-enabled'));
3064
+ });
3065
+
3066
+ // A withheld product is a deliberate exclusion, not a module SwiftPM cannot
3067
+ // build: its pod stays emitted, so the sync does not fail it as unsupported.
3068
+ it('does not report the withheld product as unsupported', () => {
3069
+ const { report } = run({ metadata: cameraMetadata(barcodeGate), properties: disabled });
3070
+
3071
+ expect(report).toContain('not supported (0): —');
3072
+ expect(logs.error).not.toHaveBeenCalled();
3073
+ });
3074
+
3075
+ // The manifest path evaluates the condition itself, so the refusal of a companion
3076
+ // its module links some other way does not apply here.
3077
+ it.each([
3078
+ { condition: 'met', properties: enabled },
3079
+ { condition: 'not met', properties: disabled },
3080
+ ])(
3081
+ 'does not refuse a gated companion the manifest links when the condition is $condition',
3082
+ ({ properties }) => {
3083
+ expect(thrownBy(() => run({ metadata: cameraMetadata(barcodeGate), properties }))).toBeNull();
3084
+ expect(logs.error).not.toHaveBeenCalled();
3085
+ }
3086
+ );
3087
+
3088
+ describe('when the manifest does not export the gated companion', () => {
3089
+ beforeEach(() => {
3090
+ const dumped = JSON.parse(runDumpPackage());
3091
+ const isCamera = ({ name }) => name === 'ExpoCamera';
3092
+ runDumpPackage.mockReturnValue(
3093
+ JSON.stringify({
3094
+ ...dumped,
3095
+ products: dumped.products.filter(isCamera),
3096
+ targets: dumped.targets.filter(isCamera),
3097
+ })
3098
+ );
3099
+ });
3100
+
3101
+ const refusedCompanion = expect.objectContaining({
3102
+ reason: 'companion-not-exported-by-manifest',
3103
+ podName: 'ExpoCameraBarcodeScanning',
3104
+ productName: 'ExpoCameraBarcodeScanning',
3105
+ packageName: 'expo-camera',
3106
+ });
3107
+
3108
+ // CocoaPods would link the companion here, so building without it would drop a
3109
+ // feature the app has under CocoaPods.
3110
+ it.each([
3111
+ { gate: 'a Podfile property', autolinkWhen: barcodeGate, properties: enabled },
3112
+ { gate: 'an npm package', autolinkWhen: { npmPackage: 'expo-modules-core' } },
3113
+ { gate: 'a pod', autolinkWhen: { podName: 'ExpoCamera' } },
3114
+ ])('fails the sync when its condition on $gate is met', ({ autolinkWhen, properties }) => {
3115
+ const thrown = thrownBy(() => run({ metadata: cameraMetadata(autolinkWhen), properties }));
3116
+
3117
+ expect(thrown).toBeInstanceOf(UnsupportedModulesError);
3118
+ expect(thrown.unsupported).toEqual([refusedCompanion]);
3119
+ expect(printed(logs.error)).toContain('"ExpoCameraBarcodeScanning"');
3120
+ expect(printed(logs.error)).toContain('"expo-camera"');
3121
+ });
3122
+
3123
+ it.each([
3124
+ { gate: 'a Podfile property', autolinkWhen: barcodeGate, properties: disabled },
3125
+ { gate: 'an npm package', autolinkWhen: { npmPackage: 'react-native-worklets' } },
3126
+ { gate: 'a pod', autolinkWhen: { podName: 'RNWorklets' } },
3127
+ ])(
3128
+ 'links the rest of the manifest when its condition on $gate is not met',
3129
+ ({ autolinkWhen, properties }) => {
3130
+ const { result } = run({ metadata: cameraMetadata(autolinkWhen), properties });
3131
+
3132
+ expect(result.productDependencies).toEqual([cameraProduct]);
3133
+ expect(logs.error).not.toHaveBeenCalled();
3134
+ }
3135
+ );
3136
+
3137
+ it('fails the sync when the companion documents its package through a symlink', () => {
3138
+ const alias = path.join(tmp, 'expo-camera-alias');
3139
+ fs.symlinkSync(cameraRoot, alias, 'dir');
3140
+ const metadata = {
3141
+ ExpoCamera: metadataEntry(cameraRoot, 'ExpoCamera'),
3142
+ ExpoCameraBarcodeScanning: metadataEntry(alias, 'ExpoCameraBarcodeScanning', {
3143
+ autolinkWhen: barcodeGate,
3144
+ }),
3145
+ };
3146
+
3147
+ const thrown = thrownBy(() => run({ metadata, properties: enabled }));
3148
+
3149
+ expect(thrown).toBeInstanceOf(UnsupportedModulesError);
3150
+ expect(thrown.unsupported).toEqual([refusedCompanion]);
3151
+ });
3152
+ });
3153
+
3154
+ // A properties file nobody can read leaves every gate unset, and an unset gate
3155
+ // links the product. Guessing it open would link what this app may exclude.
3156
+ it('fails instead of linking the gated product when the properties file is unusable', () => {
3157
+ expect(() =>
3158
+ run({ metadata: cameraMetadata(barcodeGate), properties: '{ "expo.camera' })
3159
+ ).toThrow(/Podfile\.properties\.json could not be read as Podfile properties/);
3160
+ });
3161
+
3162
+ // Pins a path the real document cannot reach: `prebuiltMetadata` writes
3163
+ // `packageRoot` only from a resolved package path. Read past, the gate would
3164
+ // never line up with the module and the product would link ungated.
3165
+ it('fails the sync on an entry that documents an unusable package root', () => {
3166
+ const error = thrownBy(() =>
3167
+ run({
3168
+ metadata: {
3169
+ ExpoCamera: metadataEntry(cameraRoot, 'ExpoCamera'),
3170
+ ExpoCameraBarcodeScanning: { packageRoot: 17, autolinkWhen: barcodeGate },
3171
+ },
3172
+ properties: { 'expo.camera.barcode-scanner-enabled': 'false' },
3173
+ })
3174
+ );
3175
+
3176
+ expect(error?.message).toContain(
3177
+ 'entry for pod ExpoCameraBarcodeScanning has an unusable packageRoot'
3178
+ );
3179
+ });
3180
+
3181
+ // The app target is a pure function of the app root, and generating the
3182
+ // registry against a second reading of it would let the two disagree.
3183
+ it('resolves the app target once', () => {
3184
+ run({ metadata: cameraMetadata(barcodeGate) });
3185
+
3186
+ expect(resolveAppTarget).toHaveBeenCalledTimes(1);
3187
+ });
3188
+ });
3189
+
3190
+ // The condition is checked only where a module ships a checked-in Package.swift.
3191
+ // A gated pod reaching the plugin any other way would be linked with its
3192
+ // condition ignored, so the sync refuses it whichever way the condition falls.
3193
+ describe('a gated pod linked where its autolinkWhen condition is not checked', () => {
3194
+ const logs = captureConsole({ each: true });
3195
+ let tmp;
3196
+ let modules;
3197
+
3198
+ beforeEach(() => {
3199
+ tmp = makeTempDir('expo-spm-unchecked-gate-');
3200
+ const podspecDirs = {
3201
+ ExpoModulesCore: pureSwiftModule(
3202
+ path.join(tmp, 'expo-modules-core'),
3203
+ 'ExpoModulesCore',
3204
+ spec()
3205
+ ),
3206
+ ExpoCamera: pureSwiftModule(path.join(tmp, 'expo-camera'), 'ExpoCamera', spec()),
3207
+ ExpoScanner: pureSwiftModule(path.join(tmp, 'expo-scanner'), 'ExpoScanner', spec()),
3208
+ ExpoImage: pureSwiftModule(path.join(tmp, 'expo-image'), 'ExpoImage', spec()),
3209
+ };
3210
+ modules = Object.fromEntries(
3211
+ [
3212
+ ['expo-modules-core', 'ExpoModulesCore'],
3213
+ ['expo-camera', 'ExpoCamera'],
3214
+ ['expo-scanner', 'ExpoScanner'],
3215
+ ['expo-image', 'ExpoImage'],
3216
+ ].map(([packageName, podName]) => [
3217
+ packageName,
3218
+ { packageName, pods: [{ podName, podspecDir: podspecDirs[podName] }] },
3219
+ ])
3220
+ );
3221
+ });
3222
+
3223
+ afterAll(() => {
3224
+ restoreModuleMocks();
3225
+ });
3226
+
3227
+ const documented = (packageName, productName, autolinkWhen = null) =>
3228
+ metadataEntry(path.join(tmp, packageName), productName, autolinkWhen && { autolinkWhen });
3229
+
3230
+ const run = ({ packages, metadata, precompiled = [], properties = null }) => {
3231
+ withPodfileProperties(tmp, properties);
3232
+ resolveExpoModules.mockReturnValue({
3233
+ modules: ['expo-modules-core', ...packages].map((name) => modules[name]),
3234
+ extraDependencies: [],
3235
+ });
3236
+ prebuiltMetadata.mockReturnValue(metadata);
3237
+ resolveFlavoredFramework.mockImplementation(({ frameworkName }) =>
3238
+ frameworkName === 'ExpoModulesCore' || precompiled.includes(frameworkName)
3239
+ ? { id: frameworkName.toLowerCase(), frameworkName }
3240
+ : null
3241
+ );
3242
+ providerWrittenTo(path.join(tmp, 'out'));
3243
+ let result = null;
3244
+ const thrown = thrownBy(() => {
3245
+ result = runPlugin(tmp);
3246
+ });
3247
+ return { result, thrown, report: printed(logs.error) };
3248
+ };
3249
+
3250
+ // expo-camera's real shape: `apple.podspecPath` lists ExpoCamera alone, and only the
3251
+ // document knows the barcode scanner.
3252
+ const cameraCompanion = ({ precompiled = [], autolinkWhen = barcodeGate } = {}) => ({
3253
+ packages: ['expo-camera'],
3254
+ metadata: {
3255
+ ExpoCamera: documented('expo-camera', 'ExpoCamera'),
3256
+ ExpoCameraBarcodeScanning: documented(
3257
+ 'expo-camera',
3258
+ 'ExpoCameraBarcodeScanning',
3259
+ autolinkWhen
3260
+ ),
3261
+ },
3262
+ precompiled,
3263
+ });
3264
+ const precompiledCompanion = () => cameraCompanion({ precompiled: ['ExpoCamera'] });
3265
+
3266
+ const sourceGated = (autolinkWhen = barcodeGate) => ({
3267
+ packages: ['expo-scanner'],
3268
+ metadata: { ExpoScanner: documented('expo-scanner', 'ExpoScanner', autolinkWhen) },
3269
+ });
3270
+
3271
+ const refusedPods = [
3272
+ {
3273
+ linked: 'resolved as a precompiled framework',
3274
+ gated: (autolinkWhen) => ({ ...sourceGated(autolinkWhen), precompiled: ['ExpoScanner'] }),
3275
+ podName: 'ExpoScanner',
3276
+ packageName: 'expo-scanner',
3277
+ precompiled: true,
3278
+ reported: 'precompiled',
3279
+ },
3280
+ {
3281
+ linked: 'built from source without a checked-in Package.swift',
3282
+ gated: sourceGated,
3283
+ podName: 'ExpoScanner',
3284
+ packageName: 'expo-scanner',
3285
+ precompiled: false,
3286
+ reported: 'without a checked-in Package.swift',
3287
+ },
3288
+ ];
3289
+ // Unlike a companion's, the pod's own condition is refused whatever key decides it.
3290
+ it.each(
3291
+ refusedPods.flatMap((pod) => [
3292
+ { ...pod, condition: 'met', properties: { 'expo.camera.barcode-scanner-enabled': 'true' } },
3293
+ {
3294
+ ...pod,
3295
+ condition: 'not met',
3296
+ properties: { 'expo.camera.barcode-scanner-enabled': 'false' },
3297
+ },
3298
+ { ...pod, condition: 'on a pod and not met', autolinkWhen: { podName: 'RNWorklets' } },
3299
+ {
3300
+ ...pod,
3301
+ condition: 'on an npm package and not met',
3302
+ autolinkWhen: { npmPackage: 'react-native-worklets' },
3303
+ },
3304
+ ])
3305
+ )(
3306
+ 'refuses a gated pod $linked when the condition is $condition',
3307
+ ({ gated, autolinkWhen, podName, packageName, precompiled, reported, properties }) => {
3308
+ const { result, thrown, report } = run({ ...gated(autolinkWhen), properties });
3309
+
3310
+ expect(result).toBeNull();
3311
+ expect(thrown).toBeInstanceOf(UnsupportedModulesError);
3312
+ expect(thrown.unsupported).toEqual([
3313
+ expect.objectContaining({
3314
+ reason: 'unchecked-autolink-condition',
3315
+ podName,
3316
+ packageName,
3317
+ productName: podName,
3318
+ precompiled,
3319
+ }),
3320
+ ]);
3321
+ expect(report).toContain(`"${podName}"`);
3322
+ expect(report).toContain(`"${packageName}"`);
3323
+ expect(report).toContain(reported);
3324
+ }
3325
+ );
3326
+
3327
+ it('links an ungated precompiled pod', () => {
3328
+ const { result, thrown } = run({
3329
+ packages: ['expo-image'],
3330
+ metadata: { ExpoImage: documented('expo-image', 'ExpoImage') },
3331
+ precompiled: ['ExpoImage'],
3332
+ });
3333
+
3334
+ expect(thrown).toBeNull();
3335
+ expect(result.flavoredFrameworks.map((f) => f.frameworkName)).toContain('ExpoImage');
3336
+ });
3337
+
3338
+ // Autolinking never resolves a companion as a pod, so only a checked-in manifest
3339
+ // links it. Its module linked any other way leaves it out, which is right only
3340
+ // where CocoaPods leaves it out too: where its condition is not met.
3341
+ const companionPaths = [
3342
+ {
3343
+ linked: 'resolved as a precompiled framework',
3344
+ precompiled: ['ExpoCamera'],
3345
+ reported: 'its pod ExpoCamera as a precompiled XCFramework',
3346
+ },
3347
+ {
3348
+ linked: 'built from source without a checked-in Package.swift',
3349
+ precompiled: [],
3350
+ reported: 'its pod ExpoCamera from source without a checked-in Package.swift',
3351
+ },
3352
+ ];
3353
+ const scannerEnabled = { 'expo.camera.barcode-scanner-enabled': 'true' };
3354
+ const scannerDisabled = { 'expo.camera.barcode-scanner-enabled': 'false' };
3355
+
3356
+ it.each(companionPaths)(
3357
+ 'refuses a gated companion of a module $linked when the condition is met',
3358
+ ({ precompiled, reported }) => {
3359
+ const { result, thrown, report } = run({
3360
+ ...cameraCompanion({ precompiled }),
3361
+ properties: scannerEnabled,
3362
+ });
3363
+
3364
+ expect(result).toBeNull();
3365
+ expect(thrown).toBeInstanceOf(UnsupportedModulesError);
3366
+ expect(thrown.unsupported).toEqual([
3367
+ expect.objectContaining({
3368
+ reason: 'unchecked-autolink-condition',
3369
+ podName: 'ExpoCameraBarcodeScanning',
3370
+ packageName: 'expo-camera',
3371
+ productName: 'ExpoCameraBarcodeScanning',
3372
+ precompiled: precompiled.length > 0,
3373
+ }),
3374
+ ]);
3375
+ expect(report).toContain(reported);
3376
+ expect(report).toContain('"ExpoCameraBarcodeScanning" would be left out of the app');
3377
+ expect(report).not.toContain('apple.podspecPath');
3378
+ }
3379
+ );
3380
+
3381
+ it.each(companionPaths)(
3382
+ 'omits a gated companion of a module $linked when the condition is not met',
3383
+ ({ precompiled }) => {
3384
+ const { result, thrown } = run({
3385
+ ...cameraCompanion({ precompiled }),
3386
+ properties: scannerDisabled,
3387
+ });
3388
+
3389
+ expect(thrown).toBeNull();
3390
+ expect(JSON.stringify(result)).not.toContain('ExpoCameraBarcodeScanning');
3391
+ }
3392
+ );
3393
+
3394
+ // The app cannot switch a pod or npm package gate off, so refusing such a companion
3395
+ // would block every app that installs what it names.
3396
+ it.each(
3397
+ companionPaths.flatMap((companionPath) => [
3398
+ { ...companionPath, gate: 'an npm package', autolinkWhen: { npmPackage: 'expo-camera' } },
3399
+ {
3400
+ ...companionPath,
3401
+ gate: 'a pod before a Podfile property',
3402
+ autolinkWhen: { podName: 'ExpoCamera', ...barcodeGate },
3403
+ },
3404
+ ])
3405
+ )(
3406
+ 'leaves out a companion gated on $gate of a module $linked with a warning when the condition is met',
3407
+ ({ precompiled, autolinkWhen }) => {
3408
+ const { result, thrown } = run({
3409
+ ...cameraCompanion({ precompiled, autolinkWhen }),
3410
+ properties: scannerEnabled,
3411
+ });
3412
+
3413
+ expect(thrown).toBeNull();
3414
+ expect(JSON.stringify(result)).not.toContain('ExpoCameraBarcodeScanning');
3415
+ expect(logs.error).not.toHaveBeenCalled();
3416
+ expect(printed(logs.warn)).toContain('"ExpoCameraBarcodeScanning"');
3417
+ expect(printed(logs.warn)).toContain('"expo-camera"');
3418
+ }
3419
+ );
3420
+
3421
+ it.each(
3422
+ companionPaths.flatMap((companionPath) => [
3423
+ {
3424
+ ...companionPath,
3425
+ gate: 'an npm package',
3426
+ autolinkWhen: { npmPackage: 'react-native-worklets' },
3427
+ },
3428
+ { ...companionPath, gate: 'a pod', autolinkWhen: { podName: 'RNWorklets' } },
3429
+ ])
3430
+ )(
3431
+ 'omits a companion gated on $gate of a module $linked without a warning when the condition is not met',
3432
+ ({ precompiled, autolinkWhen }) => {
3433
+ const { result, thrown } = run({ ...cameraCompanion({ precompiled, autolinkWhen }) });
3434
+
3435
+ expect(thrown).toBeNull();
3436
+ expect(JSON.stringify(result)).not.toContain('ExpoCameraBarcodeScanning');
3437
+ expect(printed(logs.warn)).not.toContain('ExpoCameraBarcodeScanning');
3438
+ }
3439
+ );
3440
+
3441
+ // expo-modules-core ships one too, and every sync precompiles that module. The
3442
+ // document declares RNWorklets whenever react-native-worklets is installed.
3443
+ describe("expo-modules-core's worklets adapter", () => {
3444
+ const adapter = () =>
3445
+ metadataEntry(path.join(tmp, 'expo-modules-core'), 'ExpoModulesWorkletsAdapter', {
3446
+ sourceOnly: true,
3447
+ autolinkWhen: { podName: 'RNWorklets' },
3448
+ });
3449
+
3450
+ it('is omitted where the app does not declare RNWorklets', () => {
3451
+ const { thrown } = run({
3452
+ packages: [],
3453
+ metadata: { ExpoModulesWorkletsAdapter: adapter() },
3454
+ });
3455
+
3456
+ expect(thrown).toBeNull();
3457
+ });
3458
+
3459
+ it('is left out with a warning where the app declares RNWorklets', () => {
3460
+ const { result, thrown } = run({
3461
+ packages: [],
3462
+ metadata: {
3463
+ ExpoModulesWorkletsAdapter: adapter(),
3464
+ RNWorklets: documented('react-native-worklets', 'RNWorklets'),
3465
+ },
3466
+ });
3467
+
3468
+ expect(thrown).toBeNull();
3469
+ expect(result.productDependencies.map((dep) => dep.name)).not.toContain(
3470
+ 'ExpoModulesWorkletsAdapter'
3471
+ );
3472
+ expect(printed(logs.warn)).toContain('"ExpoModulesWorkletsAdapter"');
3473
+ expect(printed(logs.warn)).toContain('"expo-modules-core"');
3474
+ });
3475
+
3476
+ it('is named in the same warning as every other companion left out', () => {
3477
+ const camera = cameraCompanion({ autolinkWhen: { npmPackage: 'expo-camera' } });
3478
+ const { thrown } = run({
3479
+ ...camera,
3480
+ metadata: {
3481
+ ...camera.metadata,
3482
+ ExpoModulesWorkletsAdapter: adapter(),
3483
+ RNWorklets: documented('react-native-worklets', 'RNWorklets'),
3484
+ },
3485
+ });
3486
+
3487
+ expect(thrown).toBeNull();
3488
+ const companionWarnings = logs.warn.mock.calls
3489
+ .map(([text]) => text)
3490
+ .filter(
3491
+ (text) =>
3492
+ text.includes('ExpoModulesWorkletsAdapter') ||
3493
+ text.includes('ExpoCameraBarcodeScanning')
3494
+ );
3495
+ expect(companionWarnings).toHaveLength(1);
3496
+ expect(companionWarnings[0]).toContain('"ExpoModulesWorkletsAdapter"');
3497
+ expect(companionWarnings[0]).toContain('"ExpoCameraBarcodeScanning"');
3498
+ });
3499
+
3500
+ it('is still named when a companion gated on a Podfile property fails the sync', () => {
3501
+ const camera = cameraCompanion();
3502
+ const { thrown } = run({
3503
+ ...camera,
3504
+ metadata: {
3505
+ ...camera.metadata,
3506
+ ExpoModulesWorkletsAdapter: adapter(),
3507
+ RNWorklets: documented('react-native-worklets', 'RNWorklets'),
3508
+ },
3509
+ properties: scannerEnabled,
3510
+ });
3511
+
3512
+ expect(thrown).toBeInstanceOf(UnsupportedModulesError);
3513
+ expect(thrown.unsupported).toEqual([
3514
+ expect.objectContaining({
3515
+ reason: 'unchecked-autolink-condition',
3516
+ podName: 'ExpoCameraBarcodeScanning',
3517
+ }),
3518
+ ]);
3519
+ expect(printed(logs.warn)).toContain('"ExpoModulesWorkletsAdapter"');
3520
+ expect(printed(logs.warn)).not.toContain('ExpoCameraBarcodeScanning');
3521
+ });
3522
+ });
3523
+
3524
+ // Pass 2 re-emits a package's first pod when a sibling is not precompiled.
3525
+ it('reports a precompiled gated pod once when pass 2 reaches its package again', () => {
3526
+ const [scanner] = modules['expo-scanner'].pods;
3527
+ modules['expo-scanner'].pods.push({
3528
+ podName: 'ExpoScannerExtra',
3529
+ podspecDir: scanner.podspecDir,
3530
+ });
3531
+
3532
+ const { thrown } = run({ ...sourceGated(), precompiled: ['ExpoScanner'] });
3533
+
3534
+ expect(
3535
+ thrown.unsupported.filter((entry) => entry.reason === 'unchecked-autolink-condition')
3536
+ ).toEqual([expect.objectContaining({ podName: 'ExpoScanner', precompiled: true })]);
3537
+ });
3538
+
3539
+ it('reports a gated companion of a precompiled pod once when pass 2 reaches its package again', () => {
3540
+ const [camera] = modules['expo-camera'].pods;
3541
+ modules['expo-camera'].pods.push({
3542
+ podName: 'ExpoCameraExtra',
3543
+ podspecDir: camera.podspecDir,
3544
+ });
3545
+
3546
+ const { thrown } = run({ ...precompiledCompanion() });
3547
+
3548
+ expect(
3549
+ thrown.unsupported.filter((entry) => entry.reason === 'unchecked-autolink-condition')
3550
+ ).toEqual([
3551
+ expect.objectContaining({ podName: 'ExpoCameraBarcodeScanning', precompiled: true }),
3552
+ ]);
3553
+ });
3554
+
3555
+ it('names every refused pod in one error', () => {
3556
+ const { thrown, report } = run({
3557
+ packages: ['expo-camera', 'expo-scanner'],
3558
+ metadata: { ...precompiledCompanion().metadata, ...sourceGated().metadata },
3559
+ precompiled: ['ExpoCamera'],
3560
+ });
3561
+
3562
+ expect(thrown).toBeInstanceOf(UnsupportedModulesError);
3563
+ expect(thrown.unsupported.map((entry) => entry.podName)).toEqual([
3564
+ 'ExpoCameraBarcodeScanning',
3565
+ 'ExpoScanner',
3566
+ ]);
3567
+ expect(logs.error).toHaveBeenCalledTimes(1);
3568
+ expect(report).toContain('"ExpoCameraBarcodeScanning"');
3569
+ expect(report).toContain('"ExpoScanner"');
3570
+ });
3571
+ });