expo 58.0.0 → 58.0.1

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 (31) 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 +21 -21
  8. package/package.json +7 -7
  9. package/scripts/spm/README.md +0 -3
  10. package/scripts/spm/__tests__/cli.test.js +57 -1
  11. package/scripts/spm/__tests__/diagnostics.test.js +181 -131
  12. package/scripts/spm/__tests__/flavored-frameworks.test.js +9 -0
  13. package/scripts/spm/__tests__/helpers.js +88 -0
  14. package/scripts/spm/__tests__/manifests.test.js +289 -74
  15. package/scripts/spm/__tests__/plugin.test.js +1101 -111
  16. package/scripts/spm/__tests__/podspec.test.js +27 -138
  17. package/scripts/spm/__tests__/spm-dependencies.test.js +344 -0
  18. package/scripts/spm/classify.js +28 -6
  19. package/scripts/spm/cli.js +23 -9
  20. package/scripts/spm/diagnostics.js +111 -91
  21. package/scripts/spm/flavored-frameworks.js +233 -21
  22. package/scripts/spm/manifests.js +85 -34
  23. package/scripts/spm/plugin.js +214 -55
  24. package/scripts/spm/podspec.js +10 -160
  25. package/src/winter/runtime.native.ts +0 -2
  26. package/template.tgz +0 -0
  27. package/build/winter/AbortSignal.d.ts +0 -3
  28. package/build/winter/AbortSignal.js +0 -96
  29. package/build/winter/AbortSignal.js.map +0 -1
  30. package/src/winter/AbortSignal.ts +0 -132
  31. package/src/winter/__tests__/AbortSignal.test.native.ts +0 -163
@@ -1,11 +1,11 @@
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
  }));
@@ -16,19 +16,49 @@ jest.mock('../app-target', () => ({
16
16
  podfilePropertiesPath: null,
17
17
  })),
18
18
  }));
19
+ // Only what touches the filesystem is faked; the pure helpers stay real, so the
20
+ // plugin is tested against the ordering and the collision check it really applies.
19
21
  jest.mock('../flavored-frameworks', () => ({
22
+ ...jest.requireActual('../flavored-frameworks'),
20
23
  resolveFlavoredFramework: jest.fn(({ frameworkName }) =>
21
24
  frameworkName === 'ExpoModulesCore' ? { id: 'ExpoModulesCore', name: 'ExpoModulesCore' } : null
22
25
  ),
26
+ resolveSpmDependencyFrameworks: jest.fn(() => []),
23
27
  prepareCompileInterfaces: jest.fn(() => '/abs/interfaces'),
24
28
  }));
29
+ // The module-root walk stays real; it is spied on so a test can assert that a
30
+ // root React Native already resolved made the walk unnecessary.
31
+ jest.mock('../classify', () => {
32
+ const actual = jest.requireActual('../classify');
33
+ return { ...actual, findModuleRoot: jest.fn(actual.findModuleRoot) };
34
+ });
25
35
 
26
- const { resolveExpoModules, generateModulesProvider, runDumpPackage } = require('../cli');
36
+ const {
37
+ resolveExpoModules,
38
+ prebuiltMetadata,
39
+ generateModulesProvider,
40
+ runDumpPackage,
41
+ } = require('../cli');
27
42
  const { resolveAppTarget } = require('../app-target');
43
+ const { findModuleRoot } = require('../classify');
28
44
  const { UnsupportedModulesError } = require('../diagnostics');
29
- const expoSpmPlugin = require('../plugin');
45
+ const {
46
+ prepareCompileInterfaces,
47
+ resolveFlavoredFramework,
48
+ resolveSpmDependencyFrameworks,
49
+ } = require('../flavored-frameworks');
50
+ const {
51
+ captureConsole,
52
+ makeTempDir,
53
+ metadataEntry,
54
+ printed,
55
+ removeTempDirs,
56
+ runPlugin,
57
+ spec,
58
+ thrownBy,
59
+ } = require('./helpers');
30
60
 
31
- const spec = (...body) => ['Pod::Spec.new do |s|', ...body, 'end', ''].join('\n');
61
+ afterAll(removeTempDirs);
32
62
 
33
63
  function pureSwiftModule(root, podName, podspec) {
34
64
  const podspecDir = path.join(root, 'ios');
@@ -39,13 +69,61 @@ function pureSwiftModule(root, podName, podspec) {
39
69
  return podspecDir;
40
70
  }
41
71
 
72
+ /** A module SwiftPM cannot build from source: ObjC++ sources and no manifest. */
73
+ function mixedModule(root, podName) {
74
+ const podspecDir = path.join(root, 'ios');
75
+ fs.mkdirSync(podspecDir, { recursive: true });
76
+ fs.writeFileSync(path.join(root, 'package.json'), '{"name":"module"}');
77
+ fs.writeFileSync(path.join(podspecDir, `${podName}.mm`), '// objc++\n');
78
+ fs.writeFileSync(path.join(podspecDir, `${podName}.podspec`), spec());
79
+ return podspecDir;
80
+ }
81
+
82
+ /** A podspec outside any npm package: the module-root walk has nothing to find. */
83
+ function podspecOnly(tmp, podName) {
84
+ const dir = path.join(tmp, 'podspecs', podName);
85
+ fs.mkdirSync(dir, { recursive: true });
86
+ fs.writeFileSync(path.join(dir, `${podName}.podspec`), spec());
87
+ return dir;
88
+ }
89
+
90
+ /** Makes the registry generator write a non-empty provider under `outDir`. */
91
+ function providerWrittenTo(outDir) {
92
+ generateModulesProvider.mockReset();
93
+ generateModulesProvider.mockImplementation(() => {
94
+ const providerPath = path.join(outDir, 'expo', 'ExpoModulesProvider.swift');
95
+ fs.mkdirSync(path.dirname(providerPath), { recursive: true });
96
+ fs.writeFileSync(providerPath, 'ExpoModulesCore.self\n');
97
+ return providerPath;
98
+ });
99
+ }
100
+
101
+ /** Returns the module-level mocks to the defaults every describe starts from. */
102
+ function restoreModuleMocks() {
103
+ prebuiltMetadata.mockReturnValue({});
104
+ generateModulesProvider.mockReset();
105
+ generateModulesProvider.mockReturnValue(null);
106
+ resolveFlavoredFramework.mockImplementation(({ frameworkName }) =>
107
+ frameworkName === 'ExpoModulesCore' ? { id: 'ExpoModulesCore', name: 'ExpoModulesCore' } : null
108
+ );
109
+ resolveSpmDependencyFrameworks.mockReset();
110
+ resolveSpmDependencyFrameworks.mockReturnValue([]);
111
+ prepareCompileInterfaces.mockImplementation(() => '/abs/interfaces');
112
+ }
113
+
114
+ /** The arguments the framework resolver was called with for one package. */
115
+ const resolvedFor = (packageName) =>
116
+ resolveFlavoredFramework.mock.calls
117
+ .map(([args]) => args)
118
+ .find((args) => args.packageName === packageName);
119
+
42
120
  describe('the pure-Swift branch', () => {
43
- let logs;
121
+ const logs = captureConsole();
44
122
  let outDir;
45
123
  let thrown;
46
124
 
47
125
  beforeAll(() => {
48
- const tmp = fs.mkdtempSync(path.join(os.tmpdir(), 'expo-spm-plugin-'));
126
+ const tmp = makeTempDir('expo-spm-plugin-');
49
127
  outDir = path.join(tmp, 'out');
50
128
  const dirs = {
51
129
  core: pureSwiftModule(path.join(tmp, 'expo-modules-core'), 'ExpoModulesCore', spec()),
@@ -75,47 +153,33 @@ describe('the pure-Swift branch', () => {
75
153
  pureSwiftModule(
76
154
  path.join(tmp, 'expo-localization'),
77
155
  'ExpoLocalization',
78
- spec(" s.platforms = { :ios => '16.4' }")
156
+ spec(' s.pod_target_xcconfig = {', " 'OTHER_LDFLAGS' => '$(inherited) -lc++'", ' }')
79
157
  );
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
- }
158
+ resolveExpoModules.mockReturnValue({
159
+ modules: [
160
+ {
161
+ packageName: 'expo-modules-core',
162
+ pods: [{ podName: 'ExpoModulesCore', podspecDir: dirs.core }],
163
+ },
164
+ { packageName: 'expo-asset', pods: [{ podName: 'ExpoAsset', podspecDir: dirs.good }] },
165
+ {
166
+ packageName: 'expo-media-library',
167
+ pods: [{ podName: 'ExpoMediaLibrary', podspecDir: dirs.linked }],
168
+ },
169
+ {
170
+ packageName: 'expo-screen-capture',
171
+ pods: [{ podName: 'ExpoScreenCapture', podspecDir: dirs.xcconfig }],
172
+ },
173
+ {
174
+ packageName: 'expo-localization',
175
+ pods: [{ podName: 'ExpoLocalization', podspecDir: dirs.rootPodspecDir }],
176
+ },
177
+ ],
178
+ extraDependencies: [],
179
+ });
180
+ thrown = thrownBy(() => runPlugin(tmp));
115
181
  });
116
182
 
117
- afterAll(() => Object.values(logs).forEach((spy) => spy.mockRestore()));
118
-
119
183
  it('fails the sync for a module whose linkage only its podspec declares', () => {
120
184
  expect(thrown).toBeInstanceOf(UnsupportedModulesError);
121
185
  expect(thrown.unsupported).toEqual([
@@ -126,7 +190,7 @@ describe('the pure-Swift branch', () => {
126
190
  snippet: "s.frameworks = 'Photos', 'PhotosUI'",
127
191
  }),
128
192
  ]);
129
- const report = logs.error.mock.calls.map(([text]) => text).join('\n');
193
+ const report = printed(logs.error);
130
194
  expect(report).toContain('ExpoMediaLibrary.podspec:3');
131
195
  expect(report).toContain('linkerSettings');
132
196
  });
@@ -134,20 +198,19 @@ describe('the pure-Swift branch', () => {
134
198
  it('emits no package for it, while the modules around it still render', () => {
135
199
  const emitted = (product) => path.join(outDir, 'expo', 'expo-source', product, 'Package.swift');
136
200
  expect(fs.existsSync(emitted('ExpoMediaLibrary'))).toBe(false);
137
- expect(fs.readFileSync(emitted('ExpoAsset'), 'utf8')).toContain('platforms: [.iOS("16.4")],');
201
+ expect(fs.existsSync(emitted('ExpoAsset'))).toBe(true);
138
202
  });
139
203
 
140
204
  it('finds the podspec under ios/ when the pod points at the module root', () => {
205
+ const report = printed(logs.warn);
206
+ expect(report).toContain('ExpoLocalization.podspec:3');
141
207
  expect(
142
- fs.readFileSync(
143
- path.join(outDir, 'expo', 'expo-source', 'ExpoLocalization', 'Package.swift'),
144
- 'utf8'
145
- )
146
- ).toContain('platforms: [.iOS("16.4")],');
208
+ fs.existsSync(path.join(outDir, 'expo', 'expo-source', 'ExpoLocalization', 'Package.swift'))
209
+ ).toBe(true);
147
210
  });
148
211
 
149
212
  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');
213
+ const report = printed(logs.warn);
151
214
  expect(report).toContain('warning: Expo module "expo-screen-capture"');
152
215
  expect(report).toContain('ExpoScreenCapture.podspec:4');
153
216
  expect(report).toContain('-lc++');
@@ -158,17 +221,12 @@ describe('the pure-Swift branch', () => {
158
221
  });
159
222
 
160
223
  describe('the module registry', () => {
161
- let logs;
224
+ const logs = captureConsole({ each: true });
225
+ let tmp;
162
226
  let outDir;
163
227
  let appIosDir;
164
228
 
165
- const run = () =>
166
- expoSpmPlugin({
167
- react: null,
168
- outputDir: outDir,
169
- appRoot: appIosDir,
170
- projectRoot: path.dirname(appIosDir),
171
- });
229
+ const run = () => runPlugin(tmp);
172
230
 
173
231
  const writesProvider = (body) => () => {
174
232
  const providerPath = path.join(outDir, 'expo', 'ExpoModulesProvider.swift');
@@ -178,18 +236,21 @@ describe('the module registry', () => {
178
236
  };
179
237
 
180
238
  beforeEach(() => {
181
- const tmp = fs.mkdtempSync(path.join(os.tmpdir(), 'expo-spm-provider-'));
239
+ tmp = makeTempDir('expo-spm-provider-');
182
240
  outDir = path.join(tmp, 'out');
183
241
  appIosDir = path.join(tmp, 'app', 'ios');
184
242
  // ExpoModulesCore is the only pod the framework resolver mock covers, so it
185
243
  // is emitted as precompiled and nothing is left unsupported.
186
244
  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
- ]);
245
+ resolveExpoModules.mockReturnValue({
246
+ modules: [
247
+ {
248
+ packageName: 'expo-modules-core',
249
+ pods: [{ podName: 'ExpoModulesCore', podspecDir: core }],
250
+ },
251
+ ],
252
+ extraDependencies: [],
253
+ });
193
254
  generateModulesProvider.mockReset();
194
255
  generateModulesProvider.mockImplementation(writesProvider('ExpoModulesCore.self\n'));
195
256
  resolveAppTarget.mockReset();
@@ -198,15 +259,8 @@ describe('the module registry', () => {
198
259
  entitlementPath: null,
199
260
  podfilePropertiesPath: null,
200
261
  });
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
262
  });
207
263
 
208
- afterEach(() => Object.values(logs).forEach((spy) => spy.mockRestore()));
209
-
210
264
  it('generates the provider for the app target that compiles it', () => {
211
265
  resolveAppTarget.mockReturnValue({
212
266
  targetName: 'minimalswiftpm',
@@ -238,9 +292,7 @@ describe('the module registry', () => {
238
292
  expect(run).toThrow(/ExpoModulesProvider\.swift/);
239
293
  expect(run).toThrow(/expo-modules-autolinking exited with code 1/);
240
294
  expect(run).toThrow(/react-native spm/);
241
- expect(logs.warn.mock.calls.map(([text]) => text).join('\n')).not.toContain(
242
- 'ExpoModulesProvider'
243
- );
295
+ expect(printed(logs.warn)).not.toContain('ExpoModulesProvider');
244
296
  });
245
297
 
246
298
  it('fails the sync when generation writes no provider although modules resolved', () => {
@@ -277,7 +329,10 @@ describe('the module registry', () => {
277
329
 
278
330
  // Excluding every Expo module is a legitimate configuration, not a failure.
279
331
  it('generates nothing, and fails nothing, when no modules are autolinked', () => {
280
- resolveExpoModules.mockReturnValue([]);
332
+ resolveExpoModules.mockReturnValue({
333
+ modules: [],
334
+ extraDependencies: [],
335
+ });
281
336
  generateModulesProvider.mockReturnValue(null);
282
337
 
283
338
  expect(run().generatedSources).toEqual([]);
@@ -288,19 +343,644 @@ describe('the module registry', () => {
288
343
  generateModulesProvider.mockImplementation(writesProvider('// no modules\n'));
289
344
 
290
345
  expect(run).not.toThrow();
291
- expect(logs.warn.mock.calls.map(([text]) => text).join('\n')).toContain(
292
- 'ExpoModulesProvider.swift is EMPTY'
346
+ expect(printed(logs.warn)).toContain('ExpoModulesProvider.swift is EMPTY');
347
+ });
348
+ });
349
+
350
+ // The metadata document (`expo-modules-autolinking prebuilt-metadata`) publishes
351
+ // the pod → npm package → product join. The plugin reads identity from it
352
+ // instead of re-deriving it from the filesystem.
353
+ describe('module identity from the prebuilt-metadata document', () => {
354
+ captureConsole();
355
+ let thrown;
356
+ let dirs;
357
+
358
+ beforeAll(() => {
359
+ const tmp = makeTempDir('expo-spm-identity-');
360
+ dirs = {
361
+ core: pureSwiftModule(path.join(tmp, 'expo-modules-core'), 'ExpoModulesCore', spec()),
362
+ // The podspec sits outside the npm package, so only the document knows its root.
363
+ skiaPodspecs: path.join(tmp, 'podspecs', 'skia'),
364
+ skiaPackage: path.join(tmp, 'node_modules', '@shopify', 'react-native-skia'),
365
+ adapter: mixedModule(path.join(tmp, 'expo-worklets-adapter'), 'ExpoModulesWorkletsAdapter'),
366
+ legacy: mixedModule(path.join(tmp, 'expo-legacy'), 'ExpoLegacy'),
367
+ stale: mixedModule(path.join(tmp, 'expo-stale'), 'ExpoStale'),
368
+ vanished: path.join(tmp, 'vanished'),
369
+ };
370
+ fs.mkdirSync(dirs.skiaPodspecs, { recursive: true });
371
+ fs.writeFileSync(path.join(dirs.skiaPodspecs, 'react-native-skia.podspec'), spec());
372
+ mixedModule(dirs.skiaPackage, 'RNSkia');
373
+
374
+ resolveExpoModules.mockReturnValue({
375
+ modules: [
376
+ {
377
+ packageName: 'expo-modules-core',
378
+ pods: [{ podName: 'ExpoModulesCore', podspecDir: dirs.core }],
379
+ },
380
+ {
381
+ packageName: '@shopify/react-native-skia',
382
+ pods: [{ podName: 'react-native-skia', podspecDir: dirs.skiaPodspecs }],
383
+ },
384
+ {
385
+ packageName: 'expo-worklets-adapter',
386
+ pods: [{ podName: 'ExpoModulesWorkletsAdapter', podspecDir: dirs.adapter }],
387
+ },
388
+ { packageName: 'expo-legacy', pods: [{ podName: 'ExpoLegacy', podspecDir: dirs.legacy }] },
389
+ { packageName: 'expo-stale', pods: [{ podName: 'ExpoStale', podspecDir: dirs.stale }] },
390
+ ],
391
+ extraDependencies: [],
392
+ });
393
+ prebuiltMetadata.mockReturnValue({
394
+ 'react-native-skia': {
395
+ type: 'external',
396
+ npmPackage: '@shopify/react-native-skia',
397
+ packageRoot: dirs.skiaPackage,
398
+ podspecDir: dirs.skiaPackage,
399
+ productName: 'RNSkia',
400
+ },
401
+ ExpoModulesWorkletsAdapter: {
402
+ type: 'internal',
403
+ npmPackage: 'expo-worklets-adapter',
404
+ packageRoot: path.dirname(dirs.adapter),
405
+ podspecDir: dirs.adapter,
406
+ productName: 'ExpoModulesWorkletsAdapter',
407
+ sourceOnly: true,
408
+ },
409
+ ExpoStale: {
410
+ type: 'internal',
411
+ npmPackage: 'expo-stale',
412
+ packageRoot: dirs.vanished,
413
+ podspecDir: dirs.vanished,
414
+ productName: 'ExpoStale',
415
+ },
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({
494
+ modules: [
495
+ { packageName: 'expo-modules-core', pods: [{ podName: 'ExpoModulesCore', podspecDir }] },
496
+ ],
497
+ extraDependencies: [],
498
+ });
499
+ prebuiltMetadata.mockReturnValue({
500
+ ExpoModulesCore: {
501
+ type: 'internal',
502
+ npmPackage: 'expo-modules-core',
503
+ packageRoot,
504
+ podspecDir,
505
+ productName: 'ExpoModulesCore',
506
+ },
507
+ });
508
+ generateModulesProvider.mockReset();
509
+ generateModulesProvider.mockImplementation(() => {
510
+ const providerPath = path.join(outDir, 'expo', 'ExpoModulesProvider.swift');
511
+ fs.mkdirSync(path.dirname(providerPath), { recursive: true });
512
+ fs.writeFileSync(providerPath, 'ExpoModulesCore.self\n');
513
+ return providerPath;
514
+ });
515
+ ({ watchPaths } = runPlugin(tmp));
516
+ });
517
+
518
+ afterAll(restoreModuleMocks);
519
+
520
+ it('watches the staleness inputs under the documented package root', () => {
521
+ expect(watchPaths).toContain(path.join(packageRoot, 'expo-module.config.json'));
522
+ });
523
+ });
524
+
525
+ // The product name has to reach the artifact declaration, not just the resolver
526
+ // call: react-native-skia ships RNSkia.xcframework.
527
+ describe('a precompiled product whose name differs from its pod name', () => {
528
+ captureConsole();
529
+ let result;
530
+
531
+ beforeAll(() => {
532
+ const tmp = makeTempDir('expo-spm-product-');
533
+ const outDir = path.join(tmp, 'out');
534
+ const core = pureSwiftModule(path.join(tmp, 'expo-modules-core'), 'ExpoModulesCore', spec());
535
+ const skiaPodspecDir = path.join(tmp, 'podspecs', 'skia');
536
+ const skiaPackage = path.join(tmp, 'node_modules', '@shopify', 'react-native-skia');
537
+ fs.mkdirSync(skiaPodspecDir, { recursive: true });
538
+ fs.writeFileSync(path.join(skiaPodspecDir, 'react-native-skia.podspec'), spec());
539
+ mixedModule(skiaPackage, 'RNSkia');
540
+
541
+ resolveExpoModules.mockReturnValue({
542
+ modules: [
543
+ {
544
+ packageName: 'expo-modules-core',
545
+ pods: [{ podName: 'ExpoModulesCore', podspecDir: core }],
546
+ },
547
+ {
548
+ packageName: '@shopify/react-native-skia',
549
+ pods: [{ podName: 'react-native-skia', podspecDir: skiaPodspecDir }],
550
+ },
551
+ ],
552
+ extraDependencies: [],
553
+ });
554
+ prebuiltMetadata.mockReturnValue({
555
+ 'react-native-skia': {
556
+ type: 'external',
557
+ npmPackage: '@shopify/react-native-skia',
558
+ packageRoot: skiaPackage,
559
+ podspecDir: skiaPackage,
560
+ productName: 'RNSkia',
561
+ },
562
+ });
563
+ resolveFlavoredFramework.mockImplementation(({ frameworkName }) =>
564
+ frameworkName === 'ExpoModulesCore' || frameworkName === 'RNSkia'
565
+ ? { id: frameworkName.toLowerCase(), frameworkName }
566
+ : null
567
+ );
568
+ generateModulesProvider.mockReset();
569
+ generateModulesProvider.mockImplementation(() => {
570
+ const providerPath = path.join(outDir, 'expo', 'ExpoModulesProvider.swift');
571
+ fs.mkdirSync(path.dirname(providerPath), { recursive: true });
572
+ fs.writeFileSync(providerPath, 'ExpoModulesCore.self\n');
573
+ return providerPath;
574
+ });
575
+ result = runPlugin(tmp);
576
+ });
577
+
578
+ afterAll(restoreModuleMocks);
579
+
580
+ it('declares the framework under the product name', () => {
581
+ expect(result.flavoredFrameworks.map((f) => f.frameworkName)).toEqual([
582
+ 'ExpoModulesCore',
583
+ 'RNSkia',
584
+ ]);
585
+ });
586
+ });
587
+
588
+ describe('the source-emit pass', () => {
589
+ captureConsole();
590
+ let outDir;
591
+ let packageRoot;
592
+ let thrown;
593
+
594
+ beforeAll(() => {
595
+ const tmp = makeTempDir('expo-spm-source-root-');
596
+ outDir = path.join(tmp, 'out');
597
+ const core = pureSwiftModule(path.join(tmp, 'expo-modules-core'), 'ExpoModulesCore', spec());
598
+ // The Swift sources live in the npm package; the pod points elsewhere, so
599
+ // only the document leads to a root the emit can work from.
600
+ packageRoot = path.join(tmp, 'node_modules', 'expo-remote');
601
+ pureSwiftModule(packageRoot, 'ExpoRemote', spec(" s.platforms = { :ios => '16.4' }"));
602
+ const podspecDir = path.join(tmp, 'podspecs', 'remote');
603
+ fs.mkdirSync(podspecDir, { recursive: true });
604
+ fs.writeFileSync(
605
+ path.join(podspecDir, 'ExpoRemote.podspec'),
606
+ spec(" s.platforms = { :ios => '16.4' }")
607
+ );
608
+
609
+ resolveExpoModules.mockReturnValue({
610
+ modules: [
611
+ {
612
+ packageName: 'expo-modules-core',
613
+ pods: [{ podName: 'ExpoModulesCore', podspecDir: core }],
614
+ },
615
+ { packageName: 'expo-remote', pods: [{ podName: 'ExpoRemote', podspecDir }] },
616
+ ],
617
+ extraDependencies: [],
618
+ });
619
+ prebuiltMetadata.mockReturnValue({
620
+ ExpoRemote: {
621
+ type: 'internal',
622
+ npmPackage: 'expo-remote',
623
+ packageRoot,
624
+ podspecDir,
625
+ productName: 'ExpoRemote',
626
+ },
627
+ });
628
+ generateModulesProvider.mockReset();
629
+ generateModulesProvider.mockImplementation(() => {
630
+ const providerPath = path.join(outDir, 'expo', 'ExpoModulesProvider.swift');
631
+ fs.mkdirSync(path.dirname(providerPath), { recursive: true });
632
+ fs.writeFileSync(providerPath, 'ExpoModulesCore.self\n');
633
+ return providerPath;
634
+ });
635
+ thrown = thrownBy(() => runPlugin(tmp));
636
+ });
637
+
638
+ afterAll(restoreModuleMocks);
639
+
640
+ it('emits the pure-Swift package found at the documented root', () => {
641
+ expect(thrown).toBeNull();
642
+ const pkgDir = path.join(outDir, 'expo', 'expo-source', 'ExpoRemote');
643
+ expect(fs.readFileSync(path.join(pkgDir, 'Package.swift'), 'utf8')).toContain(
644
+ 'name: "ExpoRemote"'
645
+ );
646
+ expect(fs.realpathSync(path.join(pkgDir, 'root'))).toBe(fs.realpathSync(packageRoot));
647
+ });
648
+
649
+ // Without this flag a module using @Field or @Record compiles to "external macro
650
+ // implementation could not be found", which is the failure CocoaPods avoids in
651
+ // `project_integrator.rb#integrate_core_macro_plugins`.
652
+ it('hands the emitted package the Swift macro plugin', () => {
653
+ const out = fs.readFileSync(
654
+ path.join(outDir, 'expo', 'expo-source', 'ExpoRemote', 'Package.swift'),
655
+ 'utf8'
656
+ );
657
+ expect(out).toContain('"-Xfrontend", "-load-plugin-executable", "-Xfrontend"');
658
+ expect(out).toMatch(/expo-modules-macros\/apple\/ExpoModulesMacros#ExpoModulesMacros/);
659
+ });
660
+ });
661
+
662
+ // CocoaPods raises every Expo module to ExpoModulesCore's deployment floor, and the
663
+ // prebuilt-metadata document is the only place that floor comes from.
664
+ describe('the iOS deployment floor', () => {
665
+ captureConsole();
666
+ let outDir;
667
+ let thrown;
668
+
669
+ beforeAll(() => {
670
+ const tmp = makeTempDir('expo-spm-floor-');
671
+ outDir = path.join(tmp, 'out');
672
+ const roots = {
673
+ core: path.join(tmp, 'expo-modules-core'),
674
+ low: path.join(tmp, 'expo-low'),
675
+ high: path.join(tmp, 'expo-high'),
676
+ // Its podspec disagrees with the document, so the winner is observable.
677
+ disagreeing: path.join(tmp, 'expo-disagreeing'),
678
+ // Absent from the document entirely — the case a config-less package lands in.
679
+ absent: path.join(tmp, 'expo-absent'),
680
+ };
681
+ const dirs = {
682
+ core: pureSwiftModule(
683
+ roots.core,
684
+ 'ExpoModulesCore',
685
+ spec(" s.platforms = { :ios => '16.4' }")
686
+ ),
687
+ low: pureSwiftModule(roots.low, 'ExpoLow', spec(" s.platforms = { :ios => '15.0' }")),
688
+ high: pureSwiftModule(roots.high, 'ExpoHigh', spec(" s.platforms = { :ios => '17.0' }")),
689
+ disagreeing: pureSwiftModule(
690
+ roots.disagreeing,
691
+ 'ExpoDisagreeing',
692
+ spec(" s.platforms = { :ios => '18.0' }")
693
+ ),
694
+ absent: pureSwiftModule(
695
+ roots.absent,
696
+ 'ExpoAbsent',
697
+ spec(" s.platforms = { :ios => '18.0' }")
698
+ ),
699
+ };
700
+ resolveExpoModules.mockReturnValue({
701
+ modules: [
702
+ {
703
+ packageName: 'expo-modules-core',
704
+ pods: [{ podName: 'ExpoModulesCore', podspecDir: dirs.core }],
705
+ },
706
+ { packageName: 'expo-low', pods: [{ podName: 'ExpoLow', podspecDir: dirs.low }] },
707
+ { packageName: 'expo-high', pods: [{ podName: 'ExpoHigh', podspecDir: dirs.high }] },
708
+ {
709
+ packageName: 'expo-disagreeing',
710
+ pods: [{ podName: 'ExpoDisagreeing', podspecDir: dirs.disagreeing }],
711
+ },
712
+ { packageName: 'expo-absent', pods: [{ podName: 'ExpoAbsent', podspecDir: dirs.absent }] },
713
+ ],
714
+ extraDependencies: [],
715
+ });
716
+ prebuiltMetadata.mockReturnValue({
717
+ ExpoModulesCore: metadataEntry(roots.core, 'ExpoModulesCore', {
718
+ iosDeploymentTarget: '16.4',
719
+ }),
720
+ ExpoLow: metadataEntry(roots.low, 'ExpoLow', { iosDeploymentTarget: '15.0' }),
721
+ ExpoHigh: metadataEntry(roots.high, 'ExpoHigh', { iosDeploymentTarget: '17.0' }),
722
+ ExpoDisagreeing: metadataEntry(roots.disagreeing, 'ExpoDisagreeing', {
723
+ iosDeploymentTarget: '17.5',
724
+ }),
725
+ });
726
+ generateModulesProvider.mockReset();
727
+ generateModulesProvider.mockImplementation(() => {
728
+ const providerPath = path.join(outDir, 'expo', 'ExpoModulesProvider.swift');
729
+ fs.mkdirSync(path.dirname(providerPath), { recursive: true });
730
+ fs.writeFileSync(providerPath, 'ExpoModulesCore.self\n');
731
+ return providerPath;
732
+ });
733
+ thrown = thrownBy(() => runPlugin(tmp));
734
+ });
735
+
736
+ afterAll(restoreModuleMocks);
737
+
738
+ const emitted = (product) =>
739
+ fs.readFileSync(path.join(outDir, 'expo', 'expo-source', product, 'Package.swift'), 'utf8');
740
+
741
+ it('raises a module declaring less than ExpoModulesCore to the core floor', () => {
742
+ expect(thrown).toBeNull();
743
+ expect(emitted('ExpoLow')).toContain('platforms: [.iOS("16.4")],');
744
+ });
745
+
746
+ it('leaves a module declaring more than ExpoModulesCore alone', () => {
747
+ expect(emitted('ExpoHigh')).toContain('platforms: [.iOS("17.0")],');
748
+ });
749
+
750
+ // 17.5 is neither the podspec's 18.0 nor the core floor, so only the document
751
+ // can be its source.
752
+ it('takes the floor from the document, not from the podspec', () => {
753
+ expect(emitted('ExpoDisagreeing')).toContain('platforms: [.iOS("17.5")],');
754
+ });
755
+
756
+ // Its podspec asks for 18.0 and gets 16.4: a module the document does not describe
757
+ // has no floor of its own, so it lands on the core floor every module is raised to.
758
+ it('gives a module the document omits the core floor, not its podspec floor', () => {
759
+ expect(emitted('ExpoAbsent')).toContain('platforms: [.iOS("16.4")],');
760
+ });
761
+ });
762
+
763
+ // A precompiled module links its SwiftPM packages (SDWebImage, ZXingObjC, …) as
764
+ // separate XCFrameworks. RN takes them in the same flat array as the modules.
765
+ describe('the SwiftPM packages a precompiled module links', () => {
766
+ const logs = captureConsole();
767
+ let result;
768
+ let roots;
769
+ let compiled;
770
+
771
+ beforeAll(() => {
772
+ const tmp = makeTempDir('expo-spm-deps-plugin-');
773
+ const outDir = path.join(tmp, 'out');
774
+ roots = { core: path.join(tmp, 'expo-modules-core'), image: path.join(tmp, 'expo-image') };
775
+ const core = pureSwiftModule(roots.core, 'ExpoModulesCore', spec());
776
+ const imagePodspecDir = mixedModule(roots.image, 'ExpoImage');
777
+ fs.writeFileSync(
778
+ path.join(imagePodspecDir, 'ExpoImage.podspec'),
779
+ spec(
780
+ " s.dependency 'ExpoModulesCore'",
781
+ " s.dependency 'SDWebImage'",
782
+ " s.dependency 'libavif/libdav1d'",
783
+ " s.dependency 'SomeUnmappedPod'"
784
+ )
785
+ );
786
+
787
+ resolveExpoModules.mockReturnValue({
788
+ modules: [
789
+ {
790
+ packageName: 'expo-modules-core',
791
+ pods: [{ podName: 'ExpoModulesCore', podspecDir: core }],
792
+ },
793
+ {
794
+ packageName: 'expo-image',
795
+ pods: [{ podName: 'ExpoImage', podspecDir: imagePodspecDir }],
796
+ },
797
+ ],
798
+ extraDependencies: [],
799
+ });
800
+ prebuiltMetadata.mockReturnValue({
801
+ ExpoImage: {
802
+ type: 'internal',
803
+ npmPackage: 'expo-image',
804
+ packageRoot: roots.image,
805
+ podspecDir: imagePodspecDir,
806
+ productName: 'ExpoImage',
807
+ spmDependencies: ['SDWebImage', 'libavif'],
808
+ },
809
+ });
810
+ resolveFlavoredFramework.mockImplementation(({ frameworkName }) =>
811
+ frameworkName === 'ExpoModulesCore' || frameworkName === 'ExpoImage'
812
+ ? { id: frameworkName === 'ExpoImage' ? 'expo-image' : 'expo-modules-core', frameworkName }
813
+ : null
814
+ );
815
+ resolveSpmDependencyFrameworks.mockReturnValue([
816
+ { id: 'expo-sdweb-image', frameworkName: 'SDWebImage' },
817
+ { id: 'expo-libavif', frameworkName: 'libavif' },
818
+ ]);
819
+ generateModulesProvider.mockReset();
820
+ generateModulesProvider.mockImplementation(() => {
821
+ const providerPath = path.join(outDir, 'expo', 'ExpoModulesProvider.swift');
822
+ fs.mkdirSync(path.dirname(providerPath), { recursive: true });
823
+ fs.writeFileSync(providerPath, 'ExpoModulesCore.self\n');
824
+ return providerPath;
825
+ });
826
+ // Snapshotted at call time: the plugin hands the builder the same array it
827
+ // returns, so reading the retained argument afterwards would prove nothing
828
+ // about what the builder was given.
829
+ prepareCompileInterfaces.mockImplementation((frameworks) => {
830
+ compiled = frameworks.map((framework) => framework.frameworkName);
831
+ return '/abs/interfaces';
832
+ });
833
+ result = runPlugin(tmp);
834
+ });
835
+
836
+ afterAll(restoreModuleMocks);
837
+
838
+ it('resolves them from the precompiled pods that declare them', () => {
839
+ expect(resolveSpmDependencyFrameworks).toHaveBeenCalledWith([
840
+ expect.objectContaining({
841
+ podName: 'ExpoModulesCore',
842
+ moduleRoot: roots.core,
843
+ spmDependencies: undefined,
844
+ }),
845
+ expect.objectContaining({
846
+ podName: 'ExpoImage',
847
+ moduleRoot: roots.image,
848
+ spmDependencies: ['SDWebImage', 'libavif'],
849
+ }),
850
+ ]);
851
+ });
852
+
853
+ it('declares each one beside the modules, exactly once', () => {
854
+ expect(result.flavoredFrameworks).toEqual([
855
+ { id: 'expo-image', frameworkName: 'ExpoImage' },
856
+ { id: 'expo-libavif', frameworkName: 'libavif' },
857
+ { id: 'expo-modules-core', frameworkName: 'ExpoModulesCore' },
858
+ { id: 'expo-sdweb-image', frameworkName: 'SDWebImage' },
859
+ ]);
860
+ });
861
+
862
+ it('compiles their headers into the interface tree', () => {
863
+ expect(compiled).toEqual(['ExpoImage', 'libavif', 'ExpoModulesCore', 'SDWebImage']);
864
+ });
865
+
866
+ it('warns about the pods a precompiled module depends on that nothing provides', () => {
867
+ const report = printed(logs.warn);
868
+ expect(report).toContain('warning: Expo module "expo-image" (pod ExpoImage)');
869
+ expect(report).toContain('SomeUnmappedPod');
870
+ });
871
+
872
+ it('keeps the dependencies it resolved, and their subspecs, out of that warning', () => {
873
+ const report = printed(logs.warn);
874
+ expect(report).not.toContain('SDWebImage');
875
+ expect(report).not.toContain('libavif');
876
+ });
877
+ });
878
+
879
+ describe('a dependency that collides with a precompiled module', () => {
880
+ captureConsole();
881
+ let thrown;
882
+
883
+ beforeAll(() => {
884
+ const tmp = makeTempDir('expo-spm-collision-');
885
+ const core = pureSwiftModule(path.join(tmp, 'expo-modules-core'), 'ExpoModulesCore', spec());
886
+ const fooRoot = path.join(tmp, 'expo-foo');
887
+ const fooPodspecDir = mixedModule(fooRoot, 'ExpoFoo');
888
+
889
+ resolveExpoModules.mockReturnValue({
890
+ modules: [
891
+ {
892
+ packageName: 'expo-modules-core',
893
+ pods: [{ podName: 'ExpoModulesCore', podspecDir: core }],
894
+ },
895
+ { packageName: 'expo-foo', pods: [{ podName: 'ExpoFoo', podspecDir: fooPodspecDir }] },
896
+ ],
897
+ extraDependencies: [],
898
+ });
899
+ resolveFlavoredFramework.mockImplementation(({ frameworkName }) =>
900
+ frameworkName === 'ExpoModulesCore' || frameworkName === 'ExpoFoo'
901
+ ? {
902
+ id: frameworkName === 'ExpoFoo' ? 'expo-foo' : 'expo-modules-core',
903
+ frameworkName,
904
+ flavors: { debug: `/abs/${frameworkName}.xcframework` },
905
+ }
906
+ : null
293
907
  );
908
+ // `Foo` and `ExpoFoo` are different products with the same stable id.
909
+ resolveSpmDependencyFrameworks.mockReturnValue([
910
+ { id: 'expo-foo', frameworkName: 'Foo', flavors: { debug: '/abs/Foo.xcframework' } },
911
+ ]);
912
+ thrown = thrownBy(() => runPlugin(tmp));
913
+ });
914
+
915
+ afterAll(restoreModuleMocks);
916
+
917
+ it('fails the sync naming both products, instead of handing React Native a graph it rejects', () => {
918
+ expect(thrown).not.toBeNull();
919
+ expect(thrown.message).toContain('ExpoFoo');
920
+ expect(thrown.message).toContain('Foo');
921
+ expect(thrown.message).toContain('framework id "expo-foo"');
922
+ });
923
+ });
924
+
925
+ describe('a package whose first pod alone is precompiled', () => {
926
+ const logs = captureConsole();
927
+ let thrown;
928
+
929
+ beforeAll(() => {
930
+ const tmp = makeTempDir('expo-spm-multipod-');
931
+ const core = pureSwiftModule(path.join(tmp, 'expo-modules-core'), 'ExpoModulesCore', spec());
932
+ const multiPodspecDir = mixedModule(path.join(tmp, 'expo-multi'), 'ExpoMulti');
933
+ fs.writeFileSync(
934
+ path.join(multiPodspecDir, 'ExpoMulti.podspec'),
935
+ spec(" s.dependency 'SomeUnmappedPod'")
936
+ );
937
+
938
+ resolveExpoModules.mockReturnValue({
939
+ modules: [
940
+ {
941
+ packageName: 'expo-modules-core',
942
+ pods: [{ podName: 'ExpoModulesCore', podspecDir: core }],
943
+ },
944
+ {
945
+ packageName: 'expo-multi',
946
+ pods: [
947
+ { podName: 'ExpoMulti', podspecDir: multiPodspecDir },
948
+ { podName: 'ExpoMultiHelper', podspecDir: multiPodspecDir },
949
+ ],
950
+ },
951
+ ],
952
+ extraDependencies: [],
953
+ });
954
+ resolveFlavoredFramework.mockImplementation(({ frameworkName }) =>
955
+ frameworkName === 'ExpoModulesCore' || frameworkName === 'ExpoMulti'
956
+ ? { id: frameworkName.toLowerCase(), frameworkName }
957
+ : null
958
+ );
959
+ thrown = thrownBy(() => runPlugin(tmp));
960
+ });
961
+
962
+ afterAll(restoreModuleMocks);
963
+
964
+ // The sibling pod is buildable neither way, so the sync fails on it — as it did
965
+ // before this change. The warning is what must not double.
966
+ it('fails only on the sibling pod SwiftPM cannot build', () => {
967
+ expect(thrown).toBeInstanceOf(UnsupportedModulesError);
968
+ expect(thrown.unsupported).toEqual([expect.objectContaining({ podName: 'ExpoMultiHelper' })]);
969
+ });
970
+
971
+ it('warns about its unmapped dependencies once, not once per pass', () => {
972
+ const report = printed(logs.warn);
973
+ expect(report.match(/warning: Expo module "expo-multi"/g)).toHaveLength(1);
294
974
  });
295
975
  });
296
976
 
297
977
  describe('the checked-in manifest branch', () => {
298
- let logs;
978
+ const logs = captureConsole();
299
979
  let outDir;
300
980
  let thrown;
301
981
 
302
982
  beforeAll(() => {
303
- const tmp = fs.mkdtempSync(path.join(os.tmpdir(), 'expo-spm-plugin-manifest-'));
983
+ const tmp = makeTempDir('expo-spm-plugin-manifest-');
304
984
  outDir = path.join(tmp, 'out');
305
985
  const core = pureSwiftModule(path.join(tmp, 'expo-modules-core'), 'ExpoModulesCore', spec());
306
986
  const vendored = path.join(tmp, 'expo-vendored');
@@ -326,36 +1006,22 @@ describe('the checked-in manifest branch', () => {
326
1006
  ],
327
1007
  })
328
1008
  );
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
- }
1009
+ resolveExpoModules.mockReturnValue({
1010
+ modules: [
1011
+ {
1012
+ packageName: 'expo-modules-core',
1013
+ pods: [{ podName: 'ExpoModulesCore', podspecDir: core }],
1014
+ },
1015
+ {
1016
+ packageName: 'expo-vendored',
1017
+ pods: [{ podName: 'ExpoVendored', podspecDir: vendoredPodspecDir }],
1018
+ },
1019
+ ],
1020
+ extraDependencies: [],
1021
+ });
1022
+ thrown = thrownBy(() => runPlugin(tmp));
355
1023
  });
356
1024
 
357
- afterAll(() => Object.values(logs).forEach((spy) => spy.mockRestore()));
358
-
359
1025
  it('fails the sync for a manifest depending on a target it cannot declare', () => {
360
1026
  expect(thrown).toBeInstanceOf(UnsupportedModulesError);
361
1027
  expect(thrown.unsupported).toEqual([
@@ -365,7 +1031,7 @@ describe('the checked-in manifest branch', () => {
365
1031
  dependencies: [{ target: 'ExpoVendored', dependsOn: 'VendoredKit', kind: 'binary' }],
366
1032
  }),
367
1033
  ]);
368
- expect(logs.error.mock.calls.map(([text]) => text).join('\n')).toContain(
1034
+ expect(printed(logs.error)).toContain(
369
1035
  'target "ExpoVendored" depends on "VendoredKit", a binary target'
370
1036
  );
371
1037
  });
@@ -376,3 +1042,327 @@ describe('the checked-in manifest branch', () => {
376
1042
  ).toBe(false);
377
1043
  });
378
1044
  });
1045
+
1046
+ // React Native hands the plugin its own autolinking data (`context.autolinking`,
1047
+ // the raw autolinking.json). Its `root` is where Node resolves the package from
1048
+ // the app — a resolved answer to the question the filesystem walk guesses at.
1049
+ describe('the module root React Native autolinked', () => {
1050
+ captureConsole();
1051
+ let roots;
1052
+ let podspecDirs;
1053
+
1054
+ beforeAll(() => {
1055
+ const tmp = makeTempDir('expo-spm-autolinked-');
1056
+ const core = pureSwiftModule(path.join(tmp, 'expo-modules-core'), 'ExpoModulesCore', spec());
1057
+ roots = {
1058
+ documented: path.join(tmp, 'node_modules', 'expo-documented'),
1059
+ documentedElsewhere: path.join(tmp, 'other', 'expo-documented'),
1060
+ autolinked: path.join(tmp, 'node_modules', 'expo-autolinked'),
1061
+ fallback: path.join(tmp, 'expo-fallback'),
1062
+ gone: path.join(tmp, 'gone'),
1063
+ };
1064
+ pureSwiftModule(roots.documented, 'ExpoDocumented', spec());
1065
+ pureSwiftModule(roots.documentedElsewhere, 'ExpoDocumented', spec());
1066
+ pureSwiftModule(roots.autolinked, 'ExpoAutolinked', spec());
1067
+ podspecDirs = {
1068
+ documented: podspecOnly(tmp, 'ExpoDocumented'),
1069
+ autolinked: podspecOnly(tmp, 'ExpoAutolinked'),
1070
+ fallback: pureSwiftModule(roots.fallback, 'ExpoFallback', spec()),
1071
+ };
1072
+
1073
+ resolveExpoModules.mockReturnValue({
1074
+ modules: [
1075
+ {
1076
+ packageName: 'expo-modules-core',
1077
+ pods: [{ podName: 'ExpoModulesCore', podspecDir: core }],
1078
+ },
1079
+ {
1080
+ packageName: 'expo-documented',
1081
+ pods: [{ podName: 'ExpoDocumented', podspecDir: podspecDirs.documented }],
1082
+ },
1083
+ {
1084
+ packageName: 'expo-autolinked',
1085
+ pods: [{ podName: 'ExpoAutolinked', podspecDir: podspecDirs.autolinked }],
1086
+ },
1087
+ {
1088
+ packageName: 'expo-fallback',
1089
+ pods: [{ podName: 'ExpoFallback', podspecDir: podspecDirs.fallback }],
1090
+ },
1091
+ ],
1092
+ extraDependencies: [],
1093
+ });
1094
+ prebuiltMetadata.mockReturnValue({
1095
+ ExpoDocumented: {
1096
+ type: 'internal',
1097
+ npmPackage: 'expo-documented',
1098
+ packageRoot: roots.documented,
1099
+ podspecDir: podspecDirs.documented,
1100
+ productName: 'ExpoDocumented',
1101
+ },
1102
+ });
1103
+ resolveFlavoredFramework.mockClear();
1104
+ findModuleRoot.mockClear();
1105
+ providerWrittenTo(path.join(tmp, 'out'));
1106
+ runPlugin(tmp, {
1107
+ autolinking: {
1108
+ dependencies: {
1109
+ 'expo-documented': { root: roots.documentedElsewhere },
1110
+ 'expo-autolinked': { root: roots.autolinked },
1111
+ 'expo-fallback': { root: roots.gone },
1112
+ },
1113
+ },
1114
+ });
1115
+ });
1116
+
1117
+ afterAll(restoreModuleMocks);
1118
+
1119
+ it('keeps the documented root when the document and autolinking disagree', () => {
1120
+ expect(resolvedFor('expo-documented')).toMatchObject({ moduleRoot: roots.documented });
1121
+ });
1122
+
1123
+ it('takes the autolinked root for a module the document does not cover', () => {
1124
+ expect(resolvedFor('expo-autolinked')).toMatchObject({ moduleRoot: roots.autolinked });
1125
+ expect(findModuleRoot).not.toHaveBeenCalledWith(podspecDirs.autolinked);
1126
+ });
1127
+
1128
+ it('walks the filesystem when the autolinked root is not on disk', () => {
1129
+ expect(resolvedFor('expo-fallback')).toMatchObject({ moduleRoot: roots.fallback });
1130
+ expect(findModuleRoot).toHaveBeenCalledWith(podspecDirs.fallback);
1131
+ });
1132
+ });
1133
+
1134
+ // React Native passes `autolinkingData ?? {}`, so an empty object is a value of
1135
+ // the contract, not a broken call.
1136
+ describe('a sync React Native passes no autolinking data for', () => {
1137
+ captureConsole();
1138
+ let root;
1139
+ let podspecDir;
1140
+
1141
+ beforeAll(() => {
1142
+ const tmp = makeTempDir('expo-spm-no-autolinking-');
1143
+ const core = pureSwiftModule(path.join(tmp, 'expo-modules-core'), 'ExpoModulesCore', spec());
1144
+ root = path.join(tmp, 'node_modules', 'expo-walked');
1145
+ podspecDir = pureSwiftModule(root, 'ExpoWalked', spec());
1146
+
1147
+ resolveExpoModules.mockReturnValue({
1148
+ modules: [
1149
+ {
1150
+ packageName: 'expo-modules-core',
1151
+ pods: [{ podName: 'ExpoModulesCore', podspecDir: core }],
1152
+ },
1153
+ { packageName: 'expo-walked', pods: [{ podName: 'ExpoWalked', podspecDir }] },
1154
+ ],
1155
+ extraDependencies: [],
1156
+ });
1157
+ resolveFlavoredFramework.mockClear();
1158
+ findModuleRoot.mockClear();
1159
+ providerWrittenTo(path.join(tmp, 'out'));
1160
+ runPlugin(tmp, { autolinking: {} });
1161
+ });
1162
+
1163
+ afterAll(restoreModuleMocks);
1164
+
1165
+ it('resolves every module root by walking the filesystem, as before', () => {
1166
+ expect(resolvedFor('expo-walked')).toMatchObject({ moduleRoot: root });
1167
+ expect(findModuleRoot).toHaveBeenCalledWith(podspecDir);
1168
+ });
1169
+ });
1170
+
1171
+ // Two real copies of one package: the plugin builds the documented one while the
1172
+ // app's JavaScript imports the autolinked one.
1173
+ describe('a module installed twice', () => {
1174
+ const logs = captureConsole();
1175
+ let roots;
1176
+
1177
+ beforeAll(() => {
1178
+ const tmp = makeTempDir('expo-spm-two-copies-');
1179
+ const core = pureSwiftModule(path.join(tmp, 'expo-modules-core'), 'ExpoModulesCore', spec());
1180
+ roots = {
1181
+ linked: path.join(tmp, 'node_modules', 'expo-linked'),
1182
+ linkedThrough: path.join(tmp, 'links', 'expo-linked'),
1183
+ duplicated: path.join(tmp, 'node_modules', 'expo-duplicated'),
1184
+ duplicatedCopy: path.join(tmp, 'node_modules', 'some-lib', 'node_modules', 'expo-duplicated'),
1185
+ };
1186
+ const podspecDirs = {
1187
+ linked: pureSwiftModule(roots.linked, 'ExpoLinked', spec()),
1188
+ duplicated: pureSwiftModule(roots.duplicated, 'ExpoDuplicated', spec()),
1189
+ };
1190
+ pureSwiftModule(roots.duplicatedCopy, 'ExpoDuplicated', spec());
1191
+ fs.mkdirSync(path.join(tmp, 'links'), { recursive: true });
1192
+ fs.symlinkSync(roots.linked, roots.linkedThrough, 'dir');
1193
+
1194
+ resolveExpoModules.mockReturnValue({
1195
+ modules: [
1196
+ {
1197
+ packageName: 'expo-modules-core',
1198
+ pods: [{ podName: 'ExpoModulesCore', podspecDir: core }],
1199
+ },
1200
+ {
1201
+ packageName: 'expo-linked',
1202
+ pods: [{ podName: 'ExpoLinked', podspecDir: podspecDirs.linked }],
1203
+ },
1204
+ {
1205
+ packageName: 'expo-duplicated',
1206
+ pods: [{ podName: 'ExpoDuplicated', podspecDir: podspecDirs.duplicated }],
1207
+ },
1208
+ ],
1209
+ extraDependencies: [],
1210
+ });
1211
+ prebuiltMetadata.mockReturnValue({
1212
+ ExpoLinked: {
1213
+ type: 'internal',
1214
+ npmPackage: 'expo-linked',
1215
+ packageRoot: roots.linked,
1216
+ podspecDir: podspecDirs.linked,
1217
+ productName: 'ExpoLinked',
1218
+ },
1219
+ ExpoDuplicated: {
1220
+ type: 'internal',
1221
+ npmPackage: 'expo-duplicated',
1222
+ packageRoot: roots.duplicated,
1223
+ podspecDir: podspecDirs.duplicated,
1224
+ productName: 'ExpoDuplicated',
1225
+ },
1226
+ });
1227
+ providerWrittenTo(path.join(tmp, 'out'));
1228
+ runPlugin(tmp, {
1229
+ autolinking: {
1230
+ dependencies: {
1231
+ 'expo-linked': { root: roots.linkedThrough },
1232
+ 'expo-duplicated': { root: roots.duplicatedCopy },
1233
+ },
1234
+ },
1235
+ });
1236
+ });
1237
+
1238
+ afterAll(restoreModuleMocks);
1239
+
1240
+ // The module root is resolved once per pass; the warning belongs to the module.
1241
+ it('warns once, naming both directories', () => {
1242
+ expect(printed(logs.warn).match(/warning: Expo module "expo-duplicated"/g)).toHaveLength(1);
1243
+ expect(printed(logs.warn)).toContain(roots.duplicated);
1244
+ expect(printed(logs.warn)).toContain(roots.duplicatedCopy);
1245
+ });
1246
+
1247
+ it('says nothing about a root reached through a symlink', () => {
1248
+ expect(printed(logs.warn)).not.toContain('expo-linked');
1249
+ });
1250
+ });
1251
+
1252
+ // The plugin resolves a module root per POD, so a package whose second pod
1253
+ // documents a second copy is built from that copy even when its first pod
1254
+ // agrees with the root the app imports.
1255
+ describe('a module whose pods document two different copies', () => {
1256
+ const logs = captureConsole();
1257
+ let roots;
1258
+
1259
+ beforeAll(() => {
1260
+ const tmp = fs.realpathSync(makeTempDir('expo-spm-pod-copies-'));
1261
+ const core = pureSwiftModule(path.join(tmp, 'expo-modules-core'), 'ExpoModulesCore', spec());
1262
+ roots = {
1263
+ multi: path.join(tmp, 'node_modules', 'expo-multi'),
1264
+ multiCopy: path.join(tmp, 'node_modules', 'some-lib', 'node_modules', 'expo-multi'),
1265
+ };
1266
+ const podspecDir = pureSwiftModule(roots.multi, 'ExpoMultiA', spec());
1267
+ fs.writeFileSync(path.join(podspecDir, 'ExpoMultiB.podspec'), spec());
1268
+ pureSwiftModule(roots.multiCopy, 'ExpoMultiB', spec());
1269
+
1270
+ resolveExpoModules.mockReturnValue({
1271
+ modules: [
1272
+ {
1273
+ packageName: 'expo-modules-core',
1274
+ pods: [{ podName: 'ExpoModulesCore', podspecDir: core }],
1275
+ },
1276
+ {
1277
+ packageName: 'expo-multi',
1278
+ pods: [
1279
+ { podName: 'ExpoMultiA', podspecDir },
1280
+ { podName: 'ExpoMultiB', podspecDir },
1281
+ ],
1282
+ },
1283
+ ],
1284
+ extraDependencies: [],
1285
+ });
1286
+ prebuiltMetadata.mockReturnValue({
1287
+ ExpoMultiA: {
1288
+ type: 'internal',
1289
+ npmPackage: 'expo-multi',
1290
+ packageRoot: roots.multi,
1291
+ podspecDir,
1292
+ productName: 'ExpoMultiA',
1293
+ },
1294
+ ExpoMultiB: {
1295
+ type: 'internal',
1296
+ npmPackage: 'expo-multi',
1297
+ packageRoot: roots.multiCopy,
1298
+ podspecDir,
1299
+ productName: 'ExpoMultiB',
1300
+ },
1301
+ });
1302
+ providerWrittenTo(path.join(tmp, 'out'));
1303
+ runPlugin(tmp, { autolinking: { dependencies: { 'expo-multi': { root: roots.multi } } } });
1304
+ });
1305
+
1306
+ afterAll(restoreModuleMocks);
1307
+
1308
+ // The first pod agrees with the autolinked root; only the second one does not.
1309
+ it('warns about the copy its second pod builds from', () => {
1310
+ expect(printed(logs.warn)).toContain('Expo module "expo-multi" is installed twice');
1311
+ expect(printed(logs.warn).match(/is installed twice/g)).toHaveLength(1);
1312
+ expect(printed(logs.warn)).toContain(roots.multiCopy);
1313
+ });
1314
+ });
1315
+
1316
+ // `extraPods` in the app config lands in Podfile.properties.json. The plugin reads
1317
+ // that file through the autolinking CLI but installs nothing from it, so it names
1318
+ // the pods and builds on.
1319
+ describe('the extra CocoaPods dependencies an app declares', () => {
1320
+ const logs = captureConsole({ each: true });
1321
+ let outDir;
1322
+
1323
+ const run = (extraDependencies) => {
1324
+ const tmp = makeTempDir('expo-spm-extra-pods-');
1325
+ outDir = path.join(tmp, 'out');
1326
+ const core = pureSwiftModule(path.join(tmp, 'expo-modules-core'), 'ExpoModulesCore', spec());
1327
+ const podspecDir = pureSwiftModule(path.join(tmp, 'expo-extra'), 'ExpoExtra', spec());
1328
+ resolveExpoModules.mockReturnValue({
1329
+ modules: [
1330
+ {
1331
+ packageName: 'expo-modules-core',
1332
+ pods: [{ podName: 'ExpoModulesCore', podspecDir: core }],
1333
+ },
1334
+ { packageName: 'expo-extra', pods: [{ podName: 'ExpoExtra', podspecDir }] },
1335
+ ],
1336
+ extraDependencies,
1337
+ });
1338
+ providerWrittenTo(outDir);
1339
+ return runPlugin(tmp, { autolinking: {} });
1340
+ };
1341
+
1342
+ afterEach(restoreModuleMocks);
1343
+
1344
+ // A pod the plugin cannot install is not a reason to fail the sync: a warning
1345
+ // reports it, and every package the plugin can emit is still emitted.
1346
+ it('warns about each pod, and emits its packages anyway', () => {
1347
+ expect(() =>
1348
+ run([
1349
+ { name: 'MyLocalPod', path: '../vendor/MyLocalPod' },
1350
+ { name: 'Firebase', git: 'https://github.com/firebase/firebase-ios-sdk.git' },
1351
+ ])
1352
+ ).not.toThrow();
1353
+
1354
+ const report = printed(logs.warn);
1355
+ expect(report).toContain('MyLocalPod');
1356
+ expect(report).toContain('Firebase');
1357
+ expect(report).toContain('Podfile.properties.json');
1358
+ expect(
1359
+ fs.existsSync(path.join(outDir, 'expo', 'expo-source', 'ExpoExtra', 'Package.swift'))
1360
+ ).toBe(true);
1361
+ });
1362
+
1363
+ it('says nothing when the app declares no extra pods', () => {
1364
+ run([]);
1365
+
1366
+ expect(printed(logs.warn)).not.toContain('Podfile.properties.json');
1367
+ });
1368
+ });