expo 58.0.0 → 58.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (41) hide show
  1. package/android/build.gradle +2 -2
  2. package/android/proguard-rules.pro +4 -0
  3. package/android/src/main/java/expo/modules/fetch/NativeResponse.kt +5 -1
  4. package/android/src/main/java/expo/modules/fetch/OkHttpFileUrlInterceptor.kt +5 -1
  5. package/build/winter/runtime.native.js +0 -2
  6. package/build/winter/runtime.native.js.map +1 -1
  7. package/bundledNativeModules.json +76 -76
  8. package/ios/Expo/ExpoReactNativeFactory.swift +2 -2
  9. package/ios/ExpoObjC/AppDelegates/EXReactRootViewFactory.mm +16 -2
  10. package/ios/ExpoObjC/include/Expo/EXReactRootViewFactory.h +2 -1
  11. package/package.json +13 -13
  12. package/scripts/spm/README.md +0 -3
  13. package/scripts/spm/__tests__/app-target.test.js +105 -1
  14. package/scripts/spm/__tests__/autolink-gate.test.js +188 -0
  15. package/scripts/spm/__tests__/classify.test.js +17 -19
  16. package/scripts/spm/__tests__/cli.test.js +57 -1
  17. package/scripts/spm/__tests__/diagnostics.test.js +806 -183
  18. package/scripts/spm/__tests__/flavored-frameworks.test.js +9 -0
  19. package/scripts/spm/__tests__/helpers.js +88 -0
  20. package/scripts/spm/__tests__/manifests.test.js +1330 -104
  21. package/scripts/spm/__tests__/metadata.test.js +120 -0
  22. package/scripts/spm/__tests__/plugin.test.js +3304 -111
  23. package/scripts/spm/__tests__/podspec.test.js +27 -138
  24. package/scripts/spm/__tests__/spm-dependencies.test.js +344 -0
  25. package/scripts/spm/app-target.js +42 -1
  26. package/scripts/spm/autolink-gate.js +40 -0
  27. package/scripts/spm/classify.js +78 -79
  28. package/scripts/spm/cli.js +23 -9
  29. package/scripts/spm/diagnostics.js +605 -192
  30. package/scripts/spm/flavored-frameworks.js +231 -64
  31. package/scripts/spm/manifests.js +565 -196
  32. package/scripts/spm/metadata.js +152 -0
  33. package/scripts/spm/plugin.js +679 -205
  34. package/scripts/spm/podspec.js +57 -170
  35. package/src/winter/runtime.native.ts +0 -2
  36. package/template.tgz +0 -0
  37. package/build/winter/AbortSignal.d.ts +0 -3
  38. package/build/winter/AbortSignal.js +0 -96
  39. package/build/winter/AbortSignal.js.map +0 -1
  40. package/src/winter/AbortSignal.ts +0 -132
  41. package/src/winter/__tests__/AbortSignal.test.native.ts +0 -163
@@ -1,34 +1,88 @@
1
1
  'use strict';
2
2
 
3
3
  const fs = require('fs');
4
- const os = require('os');
5
4
  const path = require('path');
6
5
 
7
6
  jest.mock('../cli', () => ({
8
7
  resolveExpoModules: jest.fn(),
8
+ prebuiltMetadata: jest.fn(() => ({})),
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,
16
19
  podfilePropertiesPath: null,
17
20
  })),
18
21
  }));
22
+ // Only what touches the filesystem is faked; the pure helpers stay real, so the
23
+ // plugin is tested against the ordering and the collision check it really applies.
19
24
  jest.mock('../flavored-frameworks', () => ({
25
+ ...jest.requireActual('../flavored-frameworks'),
20
26
  resolveFlavoredFramework: jest.fn(({ frameworkName }) =>
21
27
  frameworkName === 'ExpoModulesCore' ? { id: 'ExpoModulesCore', name: 'ExpoModulesCore' } : null
22
28
  ),
29
+ resolveSpmDependencyFrameworks: jest.fn(() => []),
23
30
  prepareCompileInterfaces: jest.fn(() => '/abs/interfaces'),
24
31
  }));
32
+ // The module-root walk stays real; it is spied on so a test can assert that a
33
+ // root React Native already resolved made the walk unnecessary.
34
+ jest.mock('../classify', () => {
35
+ const actual = jest.requireActual('../classify');
36
+ return { ...actual, findModuleRoot: jest.fn(actual.findModuleRoot) };
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
+ });
25
44
 
26
- const { resolveExpoModules, generateModulesProvider, runDumpPackage } = require('../cli');
45
+ const {
46
+ resolveExpoModules,
47
+ prebuiltMetadata,
48
+ generateModulesProvider,
49
+ runDumpPackage,
50
+ } = require('../cli');
27
51
  const { resolveAppTarget } = require('../app-target');
52
+ const { findModuleRoot } = require('../classify');
28
53
  const { UnsupportedModulesError } = require('../diagnostics');
29
- const expoSpmPlugin = require('../plugin');
54
+ const { emitPureSwiftSourcePackage } = require('../manifests');
55
+ const {
56
+ artifactBaseDirs,
57
+ prepareCompileInterfaces,
58
+ resolveFlavoredFramework,
59
+ resolveSpmDependencyFrameworks,
60
+ } = require('../flavored-frameworks');
61
+ const {
62
+ captureConsole,
63
+ makeTempDir,
64
+ metadataEntry,
65
+ printed,
66
+ removeTempDirs,
67
+ runPlugin,
68
+ spec,
69
+ thrownBy,
70
+ } = require('./helpers');
71
+
72
+ afterAll(removeTempDirs);
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
+ }
30
84
 
31
- const spec = (...body) => ['Pod::Spec.new do |s|', ...body, 'end', ''].join('\n');
85
+ const coreAt = (podspecDir) => ['expo-modules-core', [['ExpoModulesCore', podspecDir]]];
32
86
 
33
87
  function pureSwiftModule(root, podName, podspec) {
34
88
  const podspecDir = path.join(root, 'ios');
@@ -39,13 +93,86 @@ function pureSwiftModule(root, podName, podspec) {
39
93
  return podspecDir;
40
94
  }
41
95
 
96
+ /** A module SwiftPM cannot build from source: ObjC++ sources and no manifest. */
97
+ function mixedModule(root, podName) {
98
+ const podspecDir = path.join(root, 'ios');
99
+ fs.mkdirSync(podspecDir, { recursive: true });
100
+ fs.writeFileSync(path.join(root, 'package.json'), '{"name":"module"}');
101
+ fs.writeFileSync(path.join(podspecDir, `${podName}.mm`), '// objc++\n');
102
+ fs.writeFileSync(path.join(podspecDir, `${podName}.podspec`), spec());
103
+ return podspecDir;
104
+ }
105
+
106
+ /** A podspec outside any npm package: the module-root walk has nothing to find. */
107
+ function podspecOnly(tmp, podName) {
108
+ const dir = path.join(tmp, 'podspecs', podName);
109
+ fs.mkdirSync(dir, { recursive: true });
110
+ fs.writeFileSync(path.join(dir, `${podName}.podspec`), spec());
111
+ return dir;
112
+ }
113
+
114
+ /** Makes the registry generator write a non-empty provider under `outDir`. */
115
+ function providerWrittenTo(outDir) {
116
+ generateModulesProvider.mockReset();
117
+ generateModulesProvider.mockImplementation(() => {
118
+ const providerPath = path.join(outDir, 'expo', 'ExpoModulesProvider.swift');
119
+ fs.mkdirSync(path.dirname(providerPath), { recursive: true });
120
+ fs.writeFileSync(providerPath, 'ExpoModulesCore.self\n');
121
+ return providerPath;
122
+ });
123
+ }
124
+
125
+ /** Returns the module-level mocks to the defaults every describe starts from. */
126
+ function restoreModuleMocks() {
127
+ prebuiltMetadata.mockReturnValue({});
128
+ generateModulesProvider.mockReset();
129
+ generateModulesProvider.mockReturnValue(null);
130
+ resolveFlavoredFramework.mockImplementation(({ frameworkName }) =>
131
+ frameworkName === 'ExpoModulesCore' ? { id: 'ExpoModulesCore', name: 'ExpoModulesCore' } : null
132
+ );
133
+ resolveSpmDependencyFrameworks.mockReset();
134
+ resolveSpmDependencyFrameworks.mockReturnValue([]);
135
+ prepareCompileInterfaces.mockImplementation(() => '/abs/interfaces');
136
+ }
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
+
163
+ /** The arguments the framework resolver was called with for one package. */
164
+ const resolvedFor = (packageName) =>
165
+ resolveFlavoredFramework.mock.calls
166
+ .map(([args]) => args)
167
+ .find((args) => args.packageName === packageName);
168
+
42
169
  describe('the pure-Swift branch', () => {
43
- let logs;
170
+ const logs = captureConsole();
44
171
  let outDir;
45
172
  let thrown;
46
173
 
47
174
  beforeAll(() => {
48
- const tmp = fs.mkdtempSync(path.join(os.tmpdir(), 'expo-spm-plugin-'));
175
+ const tmp = makeTempDir('expo-spm-plugin-');
49
176
  outDir = path.join(tmp, 'out');
50
177
  const dirs = {
51
178
  core: pureSwiftModule(path.join(tmp, 'expo-modules-core'), 'ExpoModulesCore', spec()),
@@ -75,47 +202,20 @@ describe('the pure-Swift branch', () => {
75
202
  pureSwiftModule(
76
203
  path.join(tmp, 'expo-localization'),
77
204
  'ExpoLocalization',
78
- spec(" s.platforms = { :ios => '16.4' }")
205
+ spec(' s.pod_target_xcconfig = {', " 'OTHER_LDFLAGS' => '$(inherited) -lc++'", ' }')
79
206
  );
80
- resolveExpoModules.mockReturnValue([
81
- {
82
- packageName: 'expo-modules-core',
83
- pods: [{ podName: 'ExpoModulesCore', podspecDir: dirs.core }],
84
- },
85
- { packageName: 'expo-asset', pods: [{ podName: 'ExpoAsset', podspecDir: dirs.good }] },
86
- {
87
- packageName: 'expo-media-library',
88
- pods: [{ podName: 'ExpoMediaLibrary', podspecDir: dirs.linked }],
89
- },
90
- {
91
- packageName: 'expo-screen-capture',
92
- pods: [{ podName: 'ExpoScreenCapture', podspecDir: dirs.xcconfig }],
93
- },
94
- {
95
- packageName: 'expo-localization',
96
- pods: [{ podName: 'ExpoLocalization', podspecDir: dirs.rootPodspecDir }],
97
- },
98
- ]);
99
- logs = {
100
- error: jest.spyOn(console, 'error').mockImplementation(() => {}),
101
- warn: jest.spyOn(console, 'warn').mockImplementation(() => {}),
102
- log: jest.spyOn(console, 'log').mockImplementation(() => {}),
103
- };
104
- try {
105
- expoSpmPlugin({
106
- react: null,
107
- outputDir: outDir,
108
- appRoot: path.join(tmp, 'app', 'ios'),
109
- projectRoot: path.join(tmp, 'app'),
110
- });
111
- thrown = null;
112
- } catch (error) {
113
- thrown = error;
114
- }
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
+ );
216
+ thrown = thrownBy(() => runPlugin(tmp));
115
217
  });
116
218
 
117
- afterAll(() => Object.values(logs).forEach((spy) => spy.mockRestore()));
118
-
119
219
  it('fails the sync for a module whose linkage only its podspec declares', () => {
120
220
  expect(thrown).toBeInstanceOf(UnsupportedModulesError);
121
221
  expect(thrown.unsupported).toEqual([
@@ -126,7 +226,7 @@ describe('the pure-Swift branch', () => {
126
226
  snippet: "s.frameworks = 'Photos', 'PhotosUI'",
127
227
  }),
128
228
  ]);
129
- const report = logs.error.mock.calls.map(([text]) => text).join('\n');
229
+ const report = printed(logs.error);
130
230
  expect(report).toContain('ExpoMediaLibrary.podspec:3');
131
231
  expect(report).toContain('linkerSettings');
132
232
  });
@@ -134,20 +234,19 @@ describe('the pure-Swift branch', () => {
134
234
  it('emits no package for it, while the modules around it still render', () => {
135
235
  const emitted = (product) => path.join(outDir, 'expo', 'expo-source', product, 'Package.swift');
136
236
  expect(fs.existsSync(emitted('ExpoMediaLibrary'))).toBe(false);
137
- expect(fs.readFileSync(emitted('ExpoAsset'), 'utf8')).toContain('platforms: [.iOS("16.4")],');
237
+ expect(fs.existsSync(emitted('ExpoAsset'))).toBe(true);
138
238
  });
139
239
 
140
240
  it('finds the podspec under ios/ when the pod points at the module root', () => {
241
+ const report = printed(logs.warn);
242
+ expect(report).toContain('ExpoLocalization.podspec:3');
141
243
  expect(
142
- fs.readFileSync(
143
- path.join(outDir, 'expo', 'expo-source', 'ExpoLocalization', 'Package.swift'),
144
- 'utf8'
145
- )
146
- ).toContain('platforms: [.iOS("16.4")],');
244
+ fs.existsSync(path.join(outDir, 'expo', 'expo-source', 'ExpoLocalization', 'Package.swift'))
245
+ ).toBe(true);
147
246
  });
148
247
 
149
248
  it('emits a module that links through its xcconfig, and warns about the flags', () => {
150
- const report = logs.warn.mock.calls.map(([text]) => text).join('\n');
249
+ const report = printed(logs.warn);
151
250
  expect(report).toContain('warning: Expo module "expo-screen-capture"');
152
251
  expect(report).toContain('ExpoScreenCapture.podspec:4');
153
252
  expect(report).toContain('-lc++');
@@ -158,17 +257,12 @@ describe('the pure-Swift branch', () => {
158
257
  });
159
258
 
160
259
  describe('the module registry', () => {
161
- let logs;
260
+ const logs = captureConsole({ each: true });
261
+ let tmp;
162
262
  let outDir;
163
263
  let appIosDir;
164
264
 
165
- const run = () =>
166
- expoSpmPlugin({
167
- react: null,
168
- outputDir: outDir,
169
- appRoot: appIosDir,
170
- projectRoot: path.dirname(appIosDir),
171
- });
265
+ const run = () => runPlugin(tmp);
172
266
 
173
267
  const writesProvider = (body) => () => {
174
268
  const providerPath = path.join(outDir, 'expo', 'ExpoModulesProvider.swift');
@@ -178,18 +272,13 @@ describe('the module registry', () => {
178
272
  };
179
273
 
180
274
  beforeEach(() => {
181
- const tmp = fs.mkdtempSync(path.join(os.tmpdir(), 'expo-spm-provider-'));
275
+ tmp = makeTempDir('expo-spm-provider-');
182
276
  outDir = path.join(tmp, 'out');
183
277
  appIosDir = path.join(tmp, 'app', 'ios');
184
278
  // ExpoModulesCore is the only pod the framework resolver mock covers, so it
185
279
  // is emitted as precompiled and nothing is left unsupported.
186
280
  const core = pureSwiftModule(path.join(tmp, 'expo-modules-core'), 'ExpoModulesCore', spec());
187
- resolveExpoModules.mockReturnValue([
188
- {
189
- packageName: 'expo-modules-core',
190
- pods: [{ podName: 'ExpoModulesCore', podspecDir: core }],
191
- },
192
- ]);
281
+ resolveExpoModules.mockReturnValue(modulesOf([coreAt(core)]));
193
282
  generateModulesProvider.mockReset();
194
283
  generateModulesProvider.mockImplementation(writesProvider('ExpoModulesCore.self\n'));
195
284
  resolveAppTarget.mockReset();
@@ -198,15 +287,8 @@ describe('the module registry', () => {
198
287
  entitlementPath: null,
199
288
  podfilePropertiesPath: null,
200
289
  });
201
- logs = {
202
- error: jest.spyOn(console, 'error').mockImplementation(() => {}),
203
- warn: jest.spyOn(console, 'warn').mockImplementation(() => {}),
204
- log: jest.spyOn(console, 'log').mockImplementation(() => {}),
205
- };
206
290
  });
207
291
 
208
- afterEach(() => Object.values(logs).forEach((spy) => spy.mockRestore()));
209
-
210
292
  it('generates the provider for the app target that compiles it', () => {
211
293
  resolveAppTarget.mockReturnValue({
212
294
  targetName: 'minimalswiftpm',
@@ -238,9 +320,7 @@ describe('the module registry', () => {
238
320
  expect(run).toThrow(/ExpoModulesProvider\.swift/);
239
321
  expect(run).toThrow(/expo-modules-autolinking exited with code 1/);
240
322
  expect(run).toThrow(/react-native spm/);
241
- expect(logs.warn.mock.calls.map(([text]) => text).join('\n')).not.toContain(
242
- 'ExpoModulesProvider'
243
- );
323
+ expect(printed(logs.warn)).not.toContain('ExpoModulesProvider');
244
324
  });
245
325
 
246
326
  it('fails the sync when generation writes no provider although modules resolved', () => {
@@ -277,7 +357,7 @@ describe('the module registry', () => {
277
357
 
278
358
  // Excluding every Expo module is a legitimate configuration, not a failure.
279
359
  it('generates nothing, and fails nothing, when no modules are autolinked', () => {
280
- resolveExpoModules.mockReturnValue([]);
360
+ resolveExpoModules.mockReturnValue(modulesOf([]));
281
361
  generateModulesProvider.mockReturnValue(null);
282
362
 
283
363
  expect(run().generatedSources).toEqual([]);
@@ -288,19 +368,530 @@ describe('the module registry', () => {
288
368
  generateModulesProvider.mockImplementation(writesProvider('// no modules\n'));
289
369
 
290
370
  expect(run).not.toThrow();
291
- expect(logs.warn.mock.calls.map(([text]) => text).join('\n')).toContain(
292
- 'ExpoModulesProvider.swift is EMPTY'
371
+ expect(printed(logs.warn)).toContain('ExpoModulesProvider.swift is EMPTY');
372
+ });
373
+ });
374
+
375
+ // The metadata document (`expo-modules-autolinking prebuilt-metadata`) publishes
376
+ // the pod → npm package → product join. The plugin reads identity from it
377
+ // instead of re-deriving it from the filesystem.
378
+ describe('module identity from the prebuilt-metadata document', () => {
379
+ captureConsole();
380
+ let thrown;
381
+ let dirs;
382
+
383
+ beforeAll(() => {
384
+ const tmp = makeTempDir('expo-spm-identity-');
385
+ dirs = {
386
+ core: pureSwiftModule(path.join(tmp, 'expo-modules-core'), 'ExpoModulesCore', spec()),
387
+ // The podspec sits outside the npm package, so only the document knows its root.
388
+ skiaPodspecs: path.join(tmp, 'podspecs', 'skia'),
389
+ skiaPackage: path.join(tmp, 'node_modules', '@shopify', 'react-native-skia'),
390
+ adapter: mixedModule(path.join(tmp, 'expo-worklets-adapter'), 'ExpoModulesWorkletsAdapter'),
391
+ legacy: mixedModule(path.join(tmp, 'expo-legacy'), 'ExpoLegacy'),
392
+ stale: mixedModule(path.join(tmp, 'expo-stale'), 'ExpoStale'),
393
+ vanished: path.join(tmp, 'vanished'),
394
+ };
395
+ fs.mkdirSync(dirs.skiaPodspecs, { recursive: true });
396
+ fs.writeFileSync(path.join(dirs.skiaPodspecs, 'react-native-skia.podspec'), spec());
397
+ mixedModule(dirs.skiaPackage, 'RNSkia');
398
+
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
+ );
408
+ prebuiltMetadata.mockReturnValue({
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
+ });
417
+ resolveFlavoredFramework.mockClear();
418
+ thrown = thrownBy(() => runPlugin(tmp));
419
+ });
420
+
421
+ afterAll(restoreModuleMocks);
422
+
423
+ // The artifact is named after the PRODUCT: react-native-skia ships RNSkia.xcframework.
424
+ it('looks the xcframework up under the product name, not the pod name', () => {
425
+ expect(resolvedFor('@shopify/react-native-skia')).toMatchObject({ frameworkName: 'RNSkia' });
426
+ });
427
+
428
+ it('takes the module root from the document', () => {
429
+ expect(resolvedFor('@shopify/react-native-skia')).toMatchObject({
430
+ moduleRoot: dirs.skiaPackage,
431
+ });
432
+ });
433
+
434
+ it('falls back to the nearest package.json for a pod the document does not cover', () => {
435
+ expect(resolvedFor('expo-legacy')).toMatchObject({
436
+ frameworkName: 'ExpoLegacy',
437
+ moduleRoot: path.dirname(dirs.legacy),
438
+ });
439
+ });
440
+
441
+ // A document entry pointing at a directory that is gone is not identity.
442
+ it('falls back when the documented package root does not exist', () => {
443
+ expect(resolvedFor('expo-stale')).toMatchObject({ moduleRoot: path.dirname(dirs.stale) });
444
+ });
445
+
446
+ it('reports a documented product as prebuildable, against the documented root', () => {
447
+ expect(thrown).toBeInstanceOf(UnsupportedModulesError);
448
+ expect(thrown.unsupported).toContainEqual(
449
+ expect.objectContaining({
450
+ reason: 'prebuild-available',
451
+ podName: 'react-native-skia',
452
+ productName: 'RNSkia',
453
+ moduleRoot: dirs.skiaPackage,
454
+ })
455
+ );
456
+ });
457
+
458
+ // A source-only product never becomes an artifact, so it is no prebuild remedy.
459
+ it('does not offer a prebuild for a source-only product', () => {
460
+ expect(thrown.unsupported).toContainEqual(
461
+ expect.objectContaining({
462
+ reason: 'mixed-no-manifest',
463
+ podName: 'ExpoModulesWorkletsAdapter',
464
+ productName: 'ExpoModulesWorkletsAdapter',
465
+ })
466
+ );
467
+ });
468
+
469
+ it('offers no product for a pod the document does not cover', () => {
470
+ expect(thrown.unsupported).toContainEqual(
471
+ expect.objectContaining({
472
+ reason: 'mixed-no-manifest',
473
+ podName: 'ExpoLegacy',
474
+ productName: null,
475
+ })
476
+ );
477
+ });
478
+ });
479
+
480
+ describe('the watched module roots', () => {
481
+ captureConsole();
482
+ let watchPaths;
483
+ let packageRoot;
484
+
485
+ beforeAll(() => {
486
+ const tmp = makeTempDir('expo-spm-watch-');
487
+ const outDir = path.join(tmp, 'out');
488
+ const podspecDir = pureSwiftModule(path.join(tmp, 'podspecs'), 'ExpoModulesCore', spec());
489
+ packageRoot = path.join(tmp, 'node_modules', 'expo-modules-core');
490
+ fs.mkdirSync(packageRoot, { recursive: true });
491
+ fs.writeFileSync(path.join(packageRoot, 'package.json'), '{"name":"expo-modules-core"}');
492
+ fs.writeFileSync(path.join(packageRoot, 'expo-module.config.json'), '{}');
493
+ resolveExpoModules.mockReturnValue(modulesOf([coreAt(podspecDir)]));
494
+ prebuiltMetadata.mockReturnValue({
495
+ ExpoModulesCore: metadataEntry(packageRoot, 'ExpoModulesCore'),
496
+ });
497
+ providerWrittenTo(outDir);
498
+ ({ watchPaths } = runPlugin(tmp));
499
+ });
500
+
501
+ afterAll(restoreModuleMocks);
502
+
503
+ it('watches the staleness inputs under the documented package root', () => {
504
+ expect(watchPaths).toContain(path.join(packageRoot, 'expo-module.config.json'));
505
+ });
506
+ });
507
+
508
+ // The product name has to reach the artifact declaration, not just the resolver
509
+ // call: react-native-skia ships RNSkia.xcframework.
510
+ describe('a precompiled product whose name differs from its pod name', () => {
511
+ captureConsole();
512
+ let result;
513
+
514
+ beforeAll(() => {
515
+ const tmp = makeTempDir('expo-spm-product-');
516
+ const outDir = path.join(tmp, 'out');
517
+ const core = pureSwiftModule(path.join(tmp, 'expo-modules-core'), 'ExpoModulesCore', spec());
518
+ const skiaPodspecDir = path.join(tmp, 'podspecs', 'skia');
519
+ const skiaPackage = path.join(tmp, 'node_modules', '@shopify', 'react-native-skia');
520
+ fs.mkdirSync(skiaPodspecDir, { recursive: true });
521
+ fs.writeFileSync(path.join(skiaPodspecDir, 'react-native-skia.podspec'), spec());
522
+ mixedModule(skiaPackage, 'RNSkia');
523
+
524
+ resolveExpoModules.mockReturnValue(
525
+ modulesOf([
526
+ coreAt(core),
527
+ ['@shopify/react-native-skia', [['react-native-skia', skiaPodspecDir]]],
528
+ ])
529
+ );
530
+ prebuiltMetadata.mockReturnValue({
531
+ 'react-native-skia': metadataEntry(skiaPackage, 'RNSkia'),
532
+ });
533
+ resolveFlavoredFramework.mockImplementation(({ frameworkName }) =>
534
+ frameworkName === 'ExpoModulesCore' || frameworkName === 'RNSkia'
535
+ ? { id: frameworkName.toLowerCase(), frameworkName }
536
+ : null
537
+ );
538
+ providerWrittenTo(outDir);
539
+ result = runPlugin(tmp);
540
+ });
541
+
542
+ afterAll(restoreModuleMocks);
543
+
544
+ it('declares the framework under the product name', () => {
545
+ expect(result.flavoredFrameworks.map((f) => f.frameworkName)).toEqual([
546
+ 'ExpoModulesCore',
547
+ 'RNSkia',
548
+ ]);
549
+ });
550
+ });
551
+
552
+ describe('the source-emit pass', () => {
553
+ captureConsole();
554
+ let outDir;
555
+ let packageRoot;
556
+ let thrown;
557
+
558
+ beforeAll(() => {
559
+ const tmp = makeTempDir('expo-spm-source-root-');
560
+ outDir = path.join(tmp, 'out');
561
+ const core = pureSwiftModule(path.join(tmp, 'expo-modules-core'), 'ExpoModulesCore', spec());
562
+ // The Swift sources live in the npm package; the pod points elsewhere, so
563
+ // only the document leads to a root the emit can work from.
564
+ packageRoot = path.join(tmp, 'node_modules', 'expo-remote');
565
+ pureSwiftModule(packageRoot, 'ExpoRemote', spec(" s.platforms = { :ios => '16.4' }"));
566
+ const podspecDir = path.join(tmp, 'podspecs', 'remote');
567
+ fs.mkdirSync(podspecDir, { recursive: true });
568
+ fs.writeFileSync(
569
+ path.join(podspecDir, 'ExpoRemote.podspec'),
570
+ spec(" s.platforms = { :ios => '16.4' }")
571
+ );
572
+
573
+ resolveExpoModules.mockReturnValue(
574
+ modulesOf([coreAt(core), ['expo-remote', [['ExpoRemote', podspecDir]]]])
575
+ );
576
+ prebuiltMetadata.mockReturnValue({ ExpoRemote: metadataEntry(packageRoot, 'ExpoRemote') });
577
+ providerWrittenTo(outDir);
578
+ thrown = thrownBy(() => runPlugin(tmp));
579
+ });
580
+
581
+ afterAll(restoreModuleMocks);
582
+
583
+ it('emits the pure-Swift package found at the documented root', () => {
584
+ expect(thrown).toBeNull();
585
+ const pkgDir = path.join(outDir, 'expo', 'expo-source', 'ExpoRemote');
586
+ expect(fs.readFileSync(path.join(pkgDir, 'Package.swift'), 'utf8')).toContain(
587
+ 'name: "ExpoRemote"'
588
+ );
589
+ expect(fs.realpathSync(path.join(pkgDir, 'root'))).toBe(fs.realpathSync(packageRoot));
590
+ });
591
+
592
+ // Without this flag a module using @Field or @Record compiles to "external macro
593
+ // implementation could not be found", which is the failure CocoaPods avoids in
594
+ // `project_integrator.rb#integrate_core_macro_plugins`.
595
+ it('hands the emitted package the Swift macro plugin', () => {
596
+ const out = fs.readFileSync(
597
+ path.join(outDir, 'expo', 'expo-source', 'ExpoRemote', 'Package.swift'),
598
+ 'utf8'
599
+ );
600
+ expect(out).toContain('"-Xfrontend", "-load-plugin-executable", "-Xfrontend"');
601
+ expect(out).toMatch(/expo-modules-macros\/apple\/ExpoModulesMacros#ExpoModulesMacros/);
602
+ });
603
+ });
604
+
605
+ // CocoaPods raises every Expo module to ExpoModulesCore's deployment floor, and the
606
+ // prebuilt-metadata document is the only place that floor comes from.
607
+ describe('the iOS deployment floor', () => {
608
+ captureConsole();
609
+ let outDir;
610
+ let thrown;
611
+
612
+ beforeAll(() => {
613
+ const tmp = makeTempDir('expo-spm-floor-');
614
+ outDir = path.join(tmp, 'out');
615
+ const roots = {
616
+ core: path.join(tmp, 'expo-modules-core'),
617
+ low: path.join(tmp, 'expo-low'),
618
+ high: path.join(tmp, 'expo-high'),
619
+ // Its podspec disagrees with the document, so the winner is observable.
620
+ disagreeing: path.join(tmp, 'expo-disagreeing'),
621
+ // Absent from the document entirely — the case a config-less package lands in.
622
+ absent: path.join(tmp, 'expo-absent'),
623
+ };
624
+ const dirs = {
625
+ core: pureSwiftModule(
626
+ roots.core,
627
+ 'ExpoModulesCore',
628
+ spec(" s.platforms = { :ios => '16.4' }")
629
+ ),
630
+ low: pureSwiftModule(roots.low, 'ExpoLow', spec(" s.platforms = { :ios => '15.0' }")),
631
+ high: pureSwiftModule(roots.high, 'ExpoHigh', spec(" s.platforms = { :ios => '17.0' }")),
632
+ disagreeing: pureSwiftModule(
633
+ roots.disagreeing,
634
+ 'ExpoDisagreeing',
635
+ spec(" s.platforms = { :ios => '18.0' }")
636
+ ),
637
+ absent: pureSwiftModule(
638
+ roots.absent,
639
+ 'ExpoAbsent',
640
+ spec(" s.platforms = { :ios => '18.0' }")
641
+ ),
642
+ };
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
+ );
652
+ prebuiltMetadata.mockReturnValue({
653
+ ExpoModulesCore: metadataEntry(roots.core, 'ExpoModulesCore', {
654
+ iosDeploymentTarget: '16.4',
655
+ }),
656
+ ExpoLow: metadataEntry(roots.low, 'ExpoLow', { iosDeploymentTarget: '15.0' }),
657
+ ExpoHigh: metadataEntry(roots.high, 'ExpoHigh', { iosDeploymentTarget: '17.0' }),
658
+ ExpoDisagreeing: metadataEntry(roots.disagreeing, 'ExpoDisagreeing', {
659
+ iosDeploymentTarget: '17.5',
660
+ }),
661
+ });
662
+ providerWrittenTo(outDir);
663
+ thrown = thrownBy(() => runPlugin(tmp));
664
+ });
665
+
666
+ afterAll(restoreModuleMocks);
667
+
668
+ const emitted = (product) =>
669
+ fs.readFileSync(path.join(outDir, 'expo', 'expo-source', product, 'Package.swift'), 'utf8');
670
+
671
+ it('raises a module declaring less than ExpoModulesCore to the core floor', () => {
672
+ expect(thrown).toBeNull();
673
+ expect(emitted('ExpoLow')).toContain('platforms: [.iOS("16.4")],');
674
+ });
675
+
676
+ it('leaves a module declaring more than ExpoModulesCore alone', () => {
677
+ expect(emitted('ExpoHigh')).toContain('platforms: [.iOS("17.0")],');
678
+ });
679
+
680
+ // 17.5 is neither the podspec's 18.0 nor the core floor, so only the document
681
+ // can be its source.
682
+ it('takes the floor from the document, not from the podspec', () => {
683
+ expect(emitted('ExpoDisagreeing')).toContain('platforms: [.iOS("17.5")],');
684
+ });
685
+
686
+ // Its podspec asks for 18.0 and gets 16.4: a module the document does not describe
687
+ // has no floor of its own, so it lands on the core floor every module is raised to.
688
+ it('gives a module the document omits the core floor, not its podspec floor', () => {
689
+ expect(emitted('ExpoAbsent')).toContain('platforms: [.iOS("16.4")],');
690
+ });
691
+ });
692
+
693
+ // A precompiled module links its SwiftPM packages (SDWebImage, ZXingObjC, …) as
694
+ // separate XCFrameworks. RN takes them in the same flat array as the modules.
695
+ describe('the SwiftPM packages a precompiled module links', () => {
696
+ const logs = captureConsole();
697
+ let result;
698
+ let roots;
699
+ let compiled;
700
+
701
+ beforeAll(() => {
702
+ const tmp = makeTempDir('expo-spm-deps-plugin-');
703
+ const outDir = path.join(tmp, 'out');
704
+ roots = { core: path.join(tmp, 'expo-modules-core'), image: path.join(tmp, 'expo-image') };
705
+ const core = pureSwiftModule(roots.core, 'ExpoModulesCore', spec());
706
+ const imagePodspecDir = mixedModule(roots.image, 'ExpoImage');
707
+ fs.writeFileSync(
708
+ path.join(imagePodspecDir, 'ExpoImage.podspec'),
709
+ spec(
710
+ " s.dependency 'ExpoModulesCore'",
711
+ " s.dependency 'SDWebImage'",
712
+ " s.dependency 'libavif/libdav1d'",
713
+ " s.dependency 'SomeUnmappedPod'"
714
+ )
715
+ );
716
+
717
+ resolveExpoModules.mockReturnValue(
718
+ modulesOf([coreAt(core), ['expo-image', [['ExpoImage', imagePodspecDir]]]])
719
+ );
720
+ prebuiltMetadata.mockReturnValue({
721
+ ExpoImage: {
722
+ packageRoot: roots.image,
723
+ productName: 'ExpoImage',
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
+ ],
736
+ },
737
+ });
738
+ resolveFlavoredFramework.mockImplementation(({ frameworkName }) =>
739
+ frameworkName === 'ExpoModulesCore' || frameworkName === 'ExpoImage'
740
+ ? { id: frameworkName === 'ExpoImage' ? 'expo-image' : 'expo-modules-core', frameworkName }
741
+ : null
742
+ );
743
+ resolveSpmDependencyFrameworks.mockReturnValue([
744
+ { id: 'expo-sdweb-image', frameworkName: 'SDWebImage' },
745
+ { id: 'expo-libavif', frameworkName: 'libavif' },
746
+ ]);
747
+ providerWrittenTo(outDir);
748
+ // Snapshotted at call time: the plugin hands the builder the same array it
749
+ // returns, so reading the retained argument afterwards would prove nothing
750
+ // about what the builder was given.
751
+ prepareCompileInterfaces.mockImplementation((frameworks) => {
752
+ compiled = frameworks.map((framework) => framework.frameworkName);
753
+ return '/abs/interfaces';
754
+ });
755
+ result = runPlugin(tmp);
756
+ });
757
+
758
+ afterAll(restoreModuleMocks);
759
+
760
+ it('resolves them from the product names of the spmPackages a precompiled pod declares', () => {
761
+ expect(resolveSpmDependencyFrameworks).toHaveBeenCalledWith([
762
+ expect.objectContaining({
763
+ podName: 'ExpoModulesCore',
764
+ moduleRoot: roots.core,
765
+ spmDependencies: [],
766
+ }),
767
+ expect.objectContaining({
768
+ podName: 'ExpoImage',
769
+ moduleRoot: roots.image,
770
+ spmDependencies: ['SDWebImage', 'libavif'],
771
+ }),
772
+ ]);
773
+ });
774
+
775
+ it('declares each one beside the modules, exactly once', () => {
776
+ expect(result.flavoredFrameworks).toEqual([
777
+ { id: 'expo-image', frameworkName: 'ExpoImage' },
778
+ { id: 'expo-libavif', frameworkName: 'libavif' },
779
+ { id: 'expo-modules-core', frameworkName: 'ExpoModulesCore' },
780
+ { id: 'expo-sdweb-image', frameworkName: 'SDWebImage' },
781
+ ]);
782
+ });
783
+
784
+ it('compiles their headers into the interface tree', () => {
785
+ expect(compiled).toEqual(['ExpoImage', 'libavif', 'ExpoModulesCore', 'SDWebImage']);
786
+ });
787
+
788
+ it('warns about the pods a precompiled module depends on that nothing provides', () => {
789
+ const report = printed(logs.warn);
790
+ expect(report).toContain('warning: Expo module "expo-image" (pod ExpoImage)');
791
+ expect(report).toContain('SomeUnmappedPod');
792
+ });
793
+
794
+ it('keeps the dependencies it resolved, and their subspecs, out of that warning', () => {
795
+ const report = printed(logs.warn);
796
+ expect(report).not.toContain('SDWebImage');
797
+ expect(report).not.toContain('libavif');
798
+ });
799
+ });
800
+
801
+ describe('a dependency that collides with a precompiled module', () => {
802
+ captureConsole();
803
+ let thrown;
804
+
805
+ beforeAll(() => {
806
+ const tmp = makeTempDir('expo-spm-collision-');
807
+ const core = pureSwiftModule(path.join(tmp, 'expo-modules-core'), 'ExpoModulesCore', spec());
808
+ const fooRoot = path.join(tmp, 'expo-foo');
809
+ const fooPodspecDir = mixedModule(fooRoot, 'ExpoFoo');
810
+
811
+ resolveExpoModules.mockReturnValue(
812
+ modulesOf([coreAt(core), ['expo-foo', [['ExpoFoo', fooPodspecDir]]]])
813
+ );
814
+ resolveFlavoredFramework.mockImplementation(({ frameworkName }) =>
815
+ frameworkName === 'ExpoModulesCore' || frameworkName === 'ExpoFoo'
816
+ ? {
817
+ id: frameworkName === 'ExpoFoo' ? 'expo-foo' : 'expo-modules-core',
818
+ frameworkName,
819
+ flavors: { debug: `/abs/${frameworkName}.xcframework` },
820
+ }
821
+ : null
822
+ );
823
+ // `Foo` and `ExpoFoo` are different products with the same stable id.
824
+ resolveSpmDependencyFrameworks.mockReturnValue([
825
+ { id: 'expo-foo', frameworkName: 'Foo', flavors: { debug: '/abs/Foo.xcframework' } },
826
+ ]);
827
+ thrown = thrownBy(() => runPlugin(tmp));
828
+ });
829
+
830
+ afterAll(restoreModuleMocks);
831
+
832
+ it('fails the sync naming both products, instead of handing React Native a graph it rejects', () => {
833
+ expect(thrown).not.toBeNull();
834
+ expect(thrown.message).toContain('ExpoFoo');
835
+ expect(thrown.message).toContain('Foo');
836
+ expect(thrown.message).toContain('framework id "expo-foo"');
837
+ });
838
+ });
839
+
840
+ describe('a package whose first pod alone is precompiled', () => {
841
+ const logs = captureConsole();
842
+ let thrown;
843
+
844
+ beforeAll(() => {
845
+ const tmp = makeTempDir('expo-spm-multipod-');
846
+ const core = pureSwiftModule(path.join(tmp, 'expo-modules-core'), 'ExpoModulesCore', spec());
847
+ const multiPodspecDir = mixedModule(path.join(tmp, 'expo-multi'), 'ExpoMulti');
848
+ fs.writeFileSync(
849
+ path.join(multiPodspecDir, 'ExpoMulti.podspec'),
850
+ spec(" s.dependency 'SomeUnmappedPod'")
293
851
  );
852
+
853
+ resolveExpoModules.mockReturnValue(
854
+ modulesOf([
855
+ coreAt(core),
856
+ [
857
+ 'expo-multi',
858
+ [
859
+ ['ExpoMulti', multiPodspecDir],
860
+ ['ExpoMultiHelper', multiPodspecDir],
861
+ ],
862
+ ],
863
+ ])
864
+ );
865
+ resolveFlavoredFramework.mockImplementation(({ frameworkName }) =>
866
+ frameworkName === 'ExpoModulesCore' || frameworkName === 'ExpoMulti'
867
+ ? { id: frameworkName.toLowerCase(), frameworkName }
868
+ : null
869
+ );
870
+ thrown = thrownBy(() => runPlugin(tmp));
871
+ });
872
+
873
+ afterAll(restoreModuleMocks);
874
+
875
+ // The sibling pod is buildable neither way, so the sync fails on it — as it did
876
+ // before this change. The warning is what must not double.
877
+ it('fails only on the sibling pod SwiftPM cannot build', () => {
878
+ expect(thrown).toBeInstanceOf(UnsupportedModulesError);
879
+ expect(thrown.unsupported).toEqual([expect.objectContaining({ podName: 'ExpoMultiHelper' })]);
880
+ });
881
+
882
+ it('warns about its unmapped dependencies once, not once per pass', () => {
883
+ const report = printed(logs.warn);
884
+ expect(report.match(/warning: Expo module "expo-multi"/g)).toHaveLength(1);
294
885
  });
295
886
  });
296
887
 
297
888
  describe('the checked-in manifest branch', () => {
298
- let logs;
889
+ const logs = captureConsole();
299
890
  let outDir;
300
891
  let thrown;
301
892
 
302
893
  beforeAll(() => {
303
- const tmp = fs.mkdtempSync(path.join(os.tmpdir(), 'expo-spm-plugin-manifest-'));
894
+ const tmp = makeTempDir('expo-spm-plugin-manifest-');
304
895
  outDir = path.join(tmp, 'out');
305
896
  const core = pureSwiftModule(path.join(tmp, 'expo-modules-core'), 'ExpoModulesCore', spec());
306
897
  const vendored = path.join(tmp, 'expo-vendored');
@@ -326,36 +917,12 @@ describe('the checked-in manifest branch', () => {
326
917
  ],
327
918
  })
328
919
  );
329
- resolveExpoModules.mockReturnValue([
330
- {
331
- packageName: 'expo-modules-core',
332
- pods: [{ podName: 'ExpoModulesCore', podspecDir: core }],
333
- },
334
- {
335
- packageName: 'expo-vendored',
336
- pods: [{ podName: 'ExpoVendored', podspecDir: vendoredPodspecDir }],
337
- },
338
- ]);
339
- logs = {
340
- error: jest.spyOn(console, 'error').mockImplementation(() => {}),
341
- warn: jest.spyOn(console, 'warn').mockImplementation(() => {}),
342
- log: jest.spyOn(console, 'log').mockImplementation(() => {}),
343
- };
344
- try {
345
- expoSpmPlugin({
346
- react: null,
347
- outputDir: outDir,
348
- appRoot: path.join(tmp, 'app', 'ios'),
349
- projectRoot: path.join(tmp, 'app'),
350
- });
351
- thrown = null;
352
- } catch (error) {
353
- thrown = error;
354
- }
920
+ resolveExpoModules.mockReturnValue(
921
+ modulesOf([coreAt(core), ['expo-vendored', [['ExpoVendored', vendoredPodspecDir]]]])
922
+ );
923
+ thrown = thrownBy(() => runPlugin(tmp));
355
924
  });
356
925
 
357
- afterAll(() => Object.values(logs).forEach((spy) => spy.mockRestore()));
358
-
359
926
  it('fails the sync for a manifest depending on a target it cannot declare', () => {
360
927
  expect(thrown).toBeInstanceOf(UnsupportedModulesError);
361
928
  expect(thrown.unsupported).toEqual([
@@ -365,7 +932,7 @@ describe('the checked-in manifest branch', () => {
365
932
  dependencies: [{ target: 'ExpoVendored', dependsOn: 'VendoredKit', kind: 'binary' }],
366
933
  }),
367
934
  ]);
368
- expect(logs.error.mock.calls.map(([text]) => text).join('\n')).toContain(
935
+ expect(printed(logs.error)).toContain(
369
936
  'target "ExpoVendored" depends on "VendoredKit", a binary target'
370
937
  );
371
938
  });
@@ -376,3 +943,2629 @@ describe('the checked-in manifest branch', () => {
376
943
  ).toBe(false);
377
944
  });
378
945
  });
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
+
1170
+ // React Native hands the plugin its own autolinking data (`context.autolinking`,
1171
+ // the raw autolinking.json). Its `root` is where Node resolves the package from
1172
+ // the app — a resolved answer to the question the filesystem walk guesses at.
1173
+ describe('the module root React Native autolinked', () => {
1174
+ captureConsole();
1175
+ let roots;
1176
+ let podspecDirs;
1177
+
1178
+ beforeAll(() => {
1179
+ const tmp = makeTempDir('expo-spm-autolinked-');
1180
+ const core = pureSwiftModule(path.join(tmp, 'expo-modules-core'), 'ExpoModulesCore', spec());
1181
+ roots = {
1182
+ documented: path.join(tmp, 'node_modules', 'expo-documented'),
1183
+ documentedElsewhere: path.join(tmp, 'other', 'expo-documented'),
1184
+ autolinked: path.join(tmp, 'node_modules', 'expo-autolinked'),
1185
+ fallback: path.join(tmp, 'expo-fallback'),
1186
+ gone: path.join(tmp, 'gone'),
1187
+ };
1188
+ pureSwiftModule(roots.documented, 'ExpoDocumented', spec());
1189
+ pureSwiftModule(roots.documentedElsewhere, 'ExpoDocumented', spec());
1190
+ pureSwiftModule(roots.autolinked, 'ExpoAutolinked', spec());
1191
+ podspecDirs = {
1192
+ documented: podspecOnly(tmp, 'ExpoDocumented'),
1193
+ autolinked: podspecOnly(tmp, 'ExpoAutolinked'),
1194
+ fallback: pureSwiftModule(roots.fallback, 'ExpoFallback', spec()),
1195
+ };
1196
+
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
+ );
1205
+ prebuiltMetadata.mockReturnValue({
1206
+ ExpoDocumented: metadataEntry(roots.documented, 'ExpoDocumented'),
1207
+ });
1208
+ resolveFlavoredFramework.mockClear();
1209
+ findModuleRoot.mockClear();
1210
+ providerWrittenTo(path.join(tmp, 'out'));
1211
+ runPlugin(tmp, {
1212
+ autolinking: {
1213
+ dependencies: {
1214
+ 'expo-documented': { root: roots.documentedElsewhere },
1215
+ 'expo-autolinked': { root: roots.autolinked },
1216
+ 'expo-fallback': { root: roots.gone },
1217
+ },
1218
+ },
1219
+ });
1220
+ });
1221
+
1222
+ afterAll(restoreModuleMocks);
1223
+
1224
+ it('keeps the documented root when the document and autolinking disagree', () => {
1225
+ expect(resolvedFor('expo-documented')).toMatchObject({ moduleRoot: roots.documented });
1226
+ });
1227
+
1228
+ it('takes the autolinked root for a module the document does not cover', () => {
1229
+ expect(resolvedFor('expo-autolinked')).toMatchObject({ moduleRoot: roots.autolinked });
1230
+ expect(findModuleRoot).not.toHaveBeenCalledWith(podspecDirs.autolinked);
1231
+ });
1232
+
1233
+ it('walks the filesystem when the autolinked root is not on disk', () => {
1234
+ expect(resolvedFor('expo-fallback')).toMatchObject({ moduleRoot: roots.fallback });
1235
+ expect(findModuleRoot).toHaveBeenCalledWith(podspecDirs.fallback);
1236
+ });
1237
+ });
1238
+
1239
+ // React Native passes `autolinkingData ?? {}`, so an empty object is a value of
1240
+ // the contract, not a broken call.
1241
+ describe('a sync React Native passes no autolinking data for', () => {
1242
+ captureConsole();
1243
+ let root;
1244
+ let podspecDir;
1245
+
1246
+ beforeAll(() => {
1247
+ const tmp = makeTempDir('expo-spm-no-autolinking-');
1248
+ const core = pureSwiftModule(path.join(tmp, 'expo-modules-core'), 'ExpoModulesCore', spec());
1249
+ root = path.join(tmp, 'node_modules', 'expo-walked');
1250
+ podspecDir = pureSwiftModule(root, 'ExpoWalked', spec());
1251
+
1252
+ resolveExpoModules.mockReturnValue(
1253
+ modulesOf([coreAt(core), ['expo-walked', [['ExpoWalked', podspecDir]]]])
1254
+ );
1255
+ resolveFlavoredFramework.mockClear();
1256
+ findModuleRoot.mockClear();
1257
+ providerWrittenTo(path.join(tmp, 'out'));
1258
+ runPlugin(tmp, { autolinking: {} });
1259
+ });
1260
+
1261
+ afterAll(restoreModuleMocks);
1262
+
1263
+ it('resolves every module root by walking the filesystem', () => {
1264
+ expect(resolvedFor('expo-walked')).toMatchObject({ moduleRoot: root });
1265
+ expect(findModuleRoot).toHaveBeenCalledWith(podspecDir);
1266
+ });
1267
+ });
1268
+
1269
+ // Two real copies of one package: the plugin builds the documented one while the
1270
+ // app's JavaScript imports the autolinked one.
1271
+ describe('a module installed twice', () => {
1272
+ const logs = captureConsole();
1273
+ let roots;
1274
+
1275
+ beforeAll(() => {
1276
+ const tmp = makeTempDir('expo-spm-two-copies-');
1277
+ const core = pureSwiftModule(path.join(tmp, 'expo-modules-core'), 'ExpoModulesCore', spec());
1278
+ roots = {
1279
+ linked: path.join(tmp, 'node_modules', 'expo-linked'),
1280
+ linkedThrough: path.join(tmp, 'links', 'expo-linked'),
1281
+ duplicated: path.join(tmp, 'node_modules', 'expo-duplicated'),
1282
+ duplicatedCopy: path.join(tmp, 'node_modules', 'some-lib', 'node_modules', 'expo-duplicated'),
1283
+ };
1284
+ const podspecDirs = {
1285
+ linked: pureSwiftModule(roots.linked, 'ExpoLinked', spec()),
1286
+ duplicated: pureSwiftModule(roots.duplicated, 'ExpoDuplicated', spec()),
1287
+ };
1288
+ pureSwiftModule(roots.duplicatedCopy, 'ExpoDuplicated', spec());
1289
+ fs.mkdirSync(path.join(tmp, 'links'), { recursive: true });
1290
+ fs.symlinkSync(roots.linked, roots.linkedThrough, 'dir');
1291
+
1292
+ resolveExpoModules.mockReturnValue(
1293
+ modulesOf([
1294
+ coreAt(core),
1295
+ ['expo-linked', [['ExpoLinked', podspecDirs.linked]]],
1296
+ ['expo-duplicated', [['ExpoDuplicated', podspecDirs.duplicated]]],
1297
+ ])
1298
+ );
1299
+ prebuiltMetadata.mockReturnValue({
1300
+ ExpoLinked: metadataEntry(roots.linked, 'ExpoLinked'),
1301
+ ExpoDuplicated: metadataEntry(roots.duplicated, 'ExpoDuplicated'),
1302
+ });
1303
+ providerWrittenTo(path.join(tmp, 'out'));
1304
+ runPlugin(tmp, {
1305
+ autolinking: {
1306
+ dependencies: {
1307
+ 'expo-linked': { root: roots.linkedThrough },
1308
+ 'expo-duplicated': { root: roots.duplicatedCopy },
1309
+ },
1310
+ },
1311
+ });
1312
+ });
1313
+
1314
+ afterAll(restoreModuleMocks);
1315
+
1316
+ // The module root is resolved once per pass; the warning belongs to the module.
1317
+ it('warns once, naming both directories', () => {
1318
+ expect(printed(logs.warn).match(/warning: Expo module "expo-duplicated"/g)).toHaveLength(1);
1319
+ expect(printed(logs.warn)).toContain(roots.duplicated);
1320
+ expect(printed(logs.warn)).toContain(roots.duplicatedCopy);
1321
+ });
1322
+
1323
+ it('says nothing about a root reached through a symlink', () => {
1324
+ expect(printed(logs.warn)).not.toContain('expo-linked');
1325
+ });
1326
+ });
1327
+
1328
+ // The plugin resolves a module root per POD, so a package whose second pod
1329
+ // documents a second copy is built from that copy even when its first pod
1330
+ // agrees with the root the app imports.
1331
+ describe('a module whose pods document two different copies', () => {
1332
+ const logs = captureConsole();
1333
+ let roots;
1334
+ let thrown;
1335
+
1336
+ beforeAll(() => {
1337
+ const tmp = fs.realpathSync(makeTempDir('expo-spm-pod-copies-'));
1338
+ const core = pureSwiftModule(path.join(tmp, 'expo-modules-core'), 'ExpoModulesCore', spec());
1339
+ roots = {
1340
+ multi: path.join(tmp, 'node_modules', 'expo-multi'),
1341
+ multiCopy: path.join(tmp, 'node_modules', 'some-lib', 'node_modules', 'expo-multi'),
1342
+ };
1343
+ const podspecDir = pureSwiftModule(roots.multi, 'ExpoMultiA', spec());
1344
+ fs.writeFileSync(path.join(podspecDir, 'ExpoMultiB.podspec'), spec());
1345
+ pureSwiftModule(roots.multiCopy, 'ExpoMultiB', spec());
1346
+
1347
+ resolveExpoModules.mockReturnValue(
1348
+ modulesOf([
1349
+ coreAt(core),
1350
+ [
1351
+ 'expo-multi',
1352
+ [
1353
+ ['ExpoMultiA', podspecDir],
1354
+ ['ExpoMultiB', podspecDir],
1355
+ ],
1356
+ ],
1357
+ ])
1358
+ );
1359
+ prebuiltMetadata.mockReturnValue({
1360
+ ExpoMultiA: metadataEntry(roots.multi, 'ExpoMultiA'),
1361
+ ExpoMultiB: metadataEntry(roots.multiCopy, 'ExpoMultiB'),
1362
+ });
1363
+ providerWrittenTo(path.join(tmp, 'out'));
1364
+ thrown = thrownBy(() =>
1365
+ runPlugin(tmp, { autolinking: { dependencies: { 'expo-multi': { root: roots.multi } } } })
1366
+ );
1367
+ });
1368
+
1369
+ afterAll(restoreModuleMocks);
1370
+
1371
+ // The first pod agrees with the autolinked root; only the second one does not.
1372
+ it('warns about the copy its second pod builds from', () => {
1373
+ expect(printed(logs.warn)).toContain('Expo module "expo-multi" is installed twice');
1374
+ expect(printed(logs.warn).match(/is installed twice/g)).toHaveLength(1);
1375
+ expect(printed(logs.warn)).toContain(roots.multiCopy);
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
+ });
1382
+ });
1383
+
1384
+ // `extraPods` in the app config lands in Podfile.properties.json. The plugin reads
1385
+ // that file through the autolinking CLI but installs nothing from it, so it names
1386
+ // the pods and builds on.
1387
+ describe('the extra CocoaPods dependencies an app declares', () => {
1388
+ const logs = captureConsole({ each: true });
1389
+ let outDir;
1390
+
1391
+ const run = (extraDependencies) => {
1392
+ const tmp = makeTempDir('expo-spm-extra-pods-');
1393
+ outDir = path.join(tmp, 'out');
1394
+ const core = pureSwiftModule(path.join(tmp, 'expo-modules-core'), 'ExpoModulesCore', spec());
1395
+ const podspecDir = pureSwiftModule(path.join(tmp, 'expo-extra'), 'ExpoExtra', spec());
1396
+ resolveExpoModules.mockReturnValue(
1397
+ modulesOf([coreAt(core), ['expo-extra', [['ExpoExtra', podspecDir]]]], extraDependencies)
1398
+ );
1399
+ providerWrittenTo(outDir);
1400
+ return runPlugin(tmp, { autolinking: {} });
1401
+ };
1402
+
1403
+ afterEach(restoreModuleMocks);
1404
+
1405
+ // A pod the plugin cannot install is not a reason to fail the sync: a warning
1406
+ // reports it, and every package the plugin can emit is still emitted.
1407
+ it('warns about each pod, and emits its packages anyway', () => {
1408
+ expect(() =>
1409
+ run([
1410
+ { name: 'MyLocalPod', path: '../vendor/MyLocalPod' },
1411
+ { name: 'Firebase', git: 'https://github.com/firebase/firebase-ios-sdk.git' },
1412
+ ])
1413
+ ).not.toThrow();
1414
+
1415
+ const report = printed(logs.warn);
1416
+ expect(report).toContain('MyLocalPod');
1417
+ expect(report).toContain('Firebase');
1418
+ expect(report).toContain('Podfile.properties.json');
1419
+ expect(
1420
+ fs.existsSync(path.join(outDir, 'expo', 'expo-source', 'ExpoExtra', 'Package.swift'))
1421
+ ).toBe(true);
1422
+ });
1423
+
1424
+ it('says nothing when the app declares no extra pods', () => {
1425
+ run([]);
1426
+
1427
+ expect(printed(logs.warn)).not.toContain('Podfile.properties.json');
1428
+ });
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
+ });