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
@@ -10,11 +10,23 @@ const { runDumpPackage } = require('../cli');
10
10
  const {
11
11
  parseDumpedManifest,
12
12
  renderSourceManifest,
13
- renderPureSwiftManifest,
13
+ pureSwiftManifest,
14
14
  emitSourceManifestPackage,
15
15
  emitPureSwiftSourcePackage,
16
+ raiseFloor,
17
+ spmPackageIdentity,
18
+ documentedPackage,
19
+ packageDeclaration,
16
20
  } = require('../manifests');
17
21
 
22
+ /** A pure-Swift module rendered the way `emitPureSwiftSourcePackage` renders it. */
23
+ const renderPureSwift = ({ frameworkSearchPath, extraSwiftFlags, ...module }) =>
24
+ renderSourceManifest({
25
+ manifest: pureSwiftManifest(module),
26
+ frameworkSearchPath,
27
+ extraSwiftFlags,
28
+ });
29
+
18
30
  describe('parseDumpedManifest', () => {
19
31
  const dumped = JSON.stringify({
20
32
  name: 'expo-file-system',
@@ -56,7 +68,7 @@ describe('parseDumpedManifest', () => {
56
68
  sources: [],
57
69
  resources: [],
58
70
  settings: [],
59
- siblingDeps: ['ExpoFileSystemObjC'],
71
+ dependencies: ['ExpoFileSystemObjC'],
60
72
  },
61
73
  {
62
74
  name: 'ExpoFileSystemObjC',
@@ -66,7 +78,7 @@ describe('parseDumpedManifest', () => {
66
78
  sources: [],
67
79
  resources: [],
68
80
  settings: [],
69
- siblingDeps: [],
81
+ dependencies: [],
70
82
  },
71
83
  ]);
72
84
  });
@@ -104,9 +116,9 @@ describe('parseDumpedManifest target dependencies', () => {
104
116
  ],
105
117
  });
106
118
 
107
- it('accepts both the .target and .byName forms and ignores product dependencies', () => {
119
+ it('accepts both the .target and .byName forms and drops a product of an undeclared package', () => {
108
120
  const [main] = parseDumpedManifest(dumped).targets;
109
- expect(main.siblingDeps).toEqual([
121
+ expect(main.dependencies).toEqual([
110
122
  'Helper',
111
123
  'Plain',
112
124
  { name: 'Conditioned', platforms: ['ios', 'macos'] },
@@ -124,22 +136,22 @@ describe('renderSourceManifest', () => {
124
136
  name: 'ExpoFileSystem',
125
137
  path: 'ios/ExpoFileSystem',
126
138
  publicHeadersPath: null,
127
- siblingDeps: ['ExpoFileSystemObjC'],
139
+ dependencies: ['ExpoFileSystemObjC'],
128
140
  },
129
141
  {
130
142
  name: 'ExpoFileSystemObjC',
131
143
  path: 'ios/ExpoFileSystemObjC',
132
144
  publicHeadersPath: 'include',
133
- siblingDeps: [],
145
+ dependencies: [],
134
146
  },
135
147
  ],
136
148
  };
137
- const out = renderSourceManifest(
149
+ const out = renderSourceManifest({
138
150
  manifest,
139
- ['.package(name: "ReactNative", path: "/abs/rn")'],
140
- ['.product(name: "ReactHeaders", package: "ReactNative")'],
141
- '/abs/interfaces'
142
- );
151
+ pkgDeps: ['.package(name: "ReactNative", path: "/abs/rn")'],
152
+ injectedTargetDeps: ['.product(name: "ReactHeaders", package: "ReactNative")'],
153
+ frameworkSearchPath: '/abs/interfaces',
154
+ });
143
155
 
144
156
  it('mirrors targets with sibling deps first, then injected deps', () => {
145
157
  expect(out).toContain('name: "ExpoFileSystem"');
@@ -169,8 +181,12 @@ describe('renderSourceManifest', () => {
169
181
  });
170
182
  });
171
183
 
172
- describe('renderPureSwiftManifest', () => {
173
- const out = renderPureSwiftManifest('ExpoAsset', 'ios', [], [], '/abs/interfaces');
184
+ describe('a rendered pure-Swift manifest', () => {
185
+ const out = renderPureSwift({
186
+ product: 'ExpoAsset',
187
+ srcRel: 'ios',
188
+ frameworkSearchPath: '/abs/interfaces',
189
+ });
174
190
 
175
191
  it('emits a single target over the source dir with the given deps', () => {
176
192
  expect(out).toContain('.library(name: "ExpoAsset", targets: ["ExpoAsset"])');
@@ -180,20 +196,121 @@ describe('renderPureSwiftManifest', () => {
180
196
  expect(out).not.toMatch(/\[\s*,\s*\]/);
181
197
  expect(out).toContain('swiftLanguageModes: [.v5],\n cxxLanguageStandard: .cxx20');
182
198
  });
199
+
200
+ it('loads no macro plugin when no macro flags are given', () => {
201
+ expect(out).not.toContain('-Xfrontend');
202
+ });
203
+ });
204
+
205
+ // Expo modules use Swift macros (@Field, @Record, @OptimizedFunction). A macro only
206
+ // expands when the compiler is handed the macro plugin executable, the same way
207
+ // `project_integrator.rb#integrate_core_macro_plugins` hands it to CocoaPods.
208
+ describe('macro plugin flags', () => {
209
+ const MACRO_FLAGS = [
210
+ '-Xfrontend',
211
+ '-load-plugin-executable',
212
+ '-Xfrontend',
213
+ '/abs/macros/ExpoModulesMacros#ExpoModulesMacros',
214
+ ];
215
+ const EXPECTED_SWIFT =
216
+ 'swiftSettings: [.unsafeFlags(["-F", "/abs/interfaces", "-Xfrontend", ' +
217
+ '"-load-plugin-executable", "-Xfrontend", ' +
218
+ '"/abs/macros/ExpoModulesMacros#ExpoModulesMacros"])]';
219
+
220
+ describe('a pure-Swift manifest', () => {
221
+ const out = renderPureSwift({
222
+ product: 'ExpoCrypto',
223
+ srcRel: 'ios',
224
+ frameworkSearchPath: '/abs/interfaces',
225
+ extraSwiftFlags: MACRO_FLAGS,
226
+ });
227
+
228
+ it('loads the macro plugin from swiftSettings', () => {
229
+ expect(out).toContain(EXPECTED_SWIFT);
230
+ });
231
+
232
+ it('never hands the Swift-only frontend flags to clang', () => {
233
+ expect(out).toContain('cSettings: [.unsafeFlags(["-F", "/abs/interfaces"])]');
234
+ expect(out).toContain('cxxSettings: [.unsafeFlags(["-F", "/abs/interfaces"])]');
235
+ });
236
+ });
237
+
238
+ describe('renderSourceManifest', () => {
239
+ const out = renderSourceManifest({
240
+ manifest: {
241
+ name: 'TestModule',
242
+ products: [{ name: 'TestModule', targets: ['Main'] }],
243
+ targets: [{ name: 'Main', path: 'Main', publicHeadersPath: null, dependencies: [] }],
244
+ },
245
+ frameworkSearchPath: '/abs/interfaces',
246
+ extraSwiftFlags: MACRO_FLAGS,
247
+ });
248
+
249
+ it('loads the macro plugin from swiftSettings', () => {
250
+ expect(out).toContain(EXPECTED_SWIFT);
251
+ });
252
+
253
+ it('never hands the Swift-only frontend flags to clang', () => {
254
+ expect(out).toContain('cSettings: [.unsafeFlags(["-F", "/abs/interfaces"])]');
255
+ expect(out).toContain('cxxSettings: [.unsafeFlags(["-F", "/abs/interfaces"])]');
256
+ });
257
+ });
258
+
259
+ // The emit functions are what the plugin actually calls, so the flags have to
260
+ // survive the whole way to the file on disk, not just the render call.
261
+ describe('the emitted file', () => {
262
+ let moduleRoot;
263
+ let outDir;
264
+
265
+ beforeEach(() => {
266
+ const tmp = fs.mkdtempSync(path.join(os.tmpdir(), 'expo-spm-macro-emit-'));
267
+ moduleRoot = path.join(tmp, 'module');
268
+ outDir = path.join(tmp, 'out');
269
+ fs.mkdirSync(path.join(moduleRoot, 'ios'), { recursive: true });
270
+ });
271
+
272
+ it('carries the flags through emitSourceManifestPackage', () => {
273
+ runDumpPackage.mockReturnValue(
274
+ JSON.stringify({
275
+ name: 'TestModule',
276
+ products: [{ name: 'TestModule', type: { library: ['automatic'] }, targets: ['Main'] }],
277
+ targets: [{ name: 'Main', type: 'regular', path: 'Main', dependencies: [] }],
278
+ })
279
+ );
280
+ emitSourceManifestPackage(moduleRoot, {
281
+ frameworkSearchPath: '/abs/interfaces',
282
+ outDir,
283
+ macroFlags: MACRO_FLAGS,
284
+ });
285
+
286
+ expect(
287
+ fs.readFileSync(path.join(outDir, 'expo-source', 'TestModule', 'Package.swift'), 'utf8')
288
+ ).toContain(EXPECTED_SWIFT);
289
+ });
290
+
291
+ it('carries the flags through emitPureSwiftSourcePackage', () => {
292
+ emitPureSwiftSourcePackage(
293
+ { moduleRoot, product: 'ExpoCrypto' },
294
+ { frameworkSearchPath: '/abs/interfaces', outDir, macroFlags: MACRO_FLAGS }
295
+ );
296
+
297
+ expect(
298
+ fs.readFileSync(path.join(outDir, 'expo-source', 'ExpoCrypto', 'Package.swift'), 'utf8')
299
+ ).toContain(EXPECTED_SWIFT);
300
+ });
301
+ });
183
302
  });
184
303
 
185
304
  describe('renderSourceManifest target dependency conditions', () => {
186
- const render = (siblingDeps) =>
187
- renderSourceManifest(
188
- {
305
+ const render = (dependencies) =>
306
+ renderSourceManifest({
307
+ manifest: {
189
308
  name: 'TestModule',
190
309
  products: [{ name: 'TestModule', targets: ['Main'] }],
191
- targets: [{ name: 'Main', path: 'Main', publicHeadersPath: null, siblingDeps }],
310
+ targets: [{ name: 'Main', path: 'Main', publicHeadersPath: null, dependencies }],
192
311
  },
193
- [],
194
- [],
195
- '/abs/interfaces'
196
- );
312
+ frameworkSearchPath: '/abs/interfaces',
313
+ });
197
314
 
198
315
  it('renders a conditioned sibling dependency with its platform condition', () => {
199
316
  expect(render([{ name: 'Helper', platforms: ['ios', 'macos'] }])).toContain(
@@ -232,7 +349,8 @@ describe('implicit target source paths', () => {
232
349
  fs.mkdirSync(outDir, { recursive: true });
233
350
  });
234
351
 
235
- const emit = () => emitSourceManifestPackage(moduleRoot, null, '/abs/interfaces', outDir, null);
352
+ const emit = () =>
353
+ emitSourceManifestPackage(moduleRoot, { frameworkSearchPath: '/abs/interfaces', outDir });
236
354
  const emittedManifest = () =>
237
355
  fs.readFileSync(path.join(outDir, 'expo-source', 'TestModule', 'Package.swift'), 'utf8');
238
356
 
@@ -244,7 +362,7 @@ describe('implicit target source paths', () => {
244
362
  fs.mkdirSync(path.join(moduleRoot, 'Sources', 'Example'), { recursive: true });
245
363
  runDumpPackage.mockReturnValue(dumpWithoutPath);
246
364
 
247
- expect(emit().packageDep).toEqual({
365
+ expect(emit().ok.packageDep).toEqual({
248
366
  name: 'TestModule',
249
367
  path: path.join(outDir, 'expo-source', 'TestModule'),
250
368
  });
@@ -267,8 +385,11 @@ describe('implicit target source paths', () => {
267
385
  runDumpPackage.mockReturnValue(dumpWithoutPath);
268
386
  const result = emit();
269
387
 
270
- expect(result.packageDep).toBeUndefined();
271
- expect(result.unresolvedTargets).toEqual(['Example']);
388
+ expect(result.ok).toBeUndefined();
389
+ expect(result.refusal).toEqual({
390
+ reason: 'unresolvable-target-path',
391
+ targetNames: ['Example'],
392
+ });
272
393
  expect(fs.existsSync(path.join(outDir, 'expo-source', 'TestModule', 'Package.swift'))).toBe(
273
394
  false
274
395
  );
@@ -276,48 +397,50 @@ describe('implicit target source paths', () => {
276
397
 
277
398
  it('refuses to render a target whose path was never resolved', () => {
278
399
  expect(() =>
279
- renderSourceManifest(
280
- {
400
+ renderSourceManifest({
401
+ manifest: {
281
402
  name: 'TestModule',
282
403
  products: [{ name: 'TestModule', targets: ['Example'] }],
283
- targets: [{ name: 'Example', path: null, publicHeadersPath: null, siblingDeps: [] }],
404
+ targets: [{ name: 'Example', path: null, publicHeadersPath: null, dependencies: [] }],
284
405
  },
285
- [],
286
- [],
287
- '/abs/interfaces'
288
- )
406
+ frameworkSearchPath: '/abs/interfaces',
407
+ })
289
408
  ).toThrow(/Example/);
290
409
  });
291
410
  });
292
411
 
293
- describe('renderPureSwiftManifest excludes', () => {
412
+ describe('pure-Swift manifest excludes', () => {
294
413
  it('excludes the directories classification ignores, in the given order', () => {
295
- const out = renderPureSwiftManifest('ExpoClipboard', 'ios', [], [], '/abs/interfaces', [
296
- 'Feature/Tests',
297
- 'Tests',
298
- ]);
414
+ const out = renderPureSwift({
415
+ product: 'ExpoClipboard',
416
+ srcRel: 'ios',
417
+ frameworkSearchPath: '/abs/interfaces',
418
+ excludes: ['Feature/Tests', 'Tests'],
419
+ });
299
420
  expect(out).toContain('path: "root/ios",\n exclude: ["Feature/Tests", "Tests"],');
300
421
  });
301
422
 
302
423
  it('emits no exclude key when nothing is ignored', () => {
303
424
  expect(
304
- renderPureSwiftManifest('ExpoAsset', 'ios', [], [], '/abs/interfaces', [])
425
+ renderPureSwift({
426
+ product: 'ExpoAsset',
427
+ srcRel: 'ios',
428
+ frameworkSearchPath: '/abs/interfaces',
429
+ excludes: [],
430
+ })
305
431
  ).not.toContain('exclude:');
306
432
  });
307
433
  });
308
434
 
309
- describe('renderPureSwiftManifest privacy manifest', () => {
435
+ describe('pure-Swift manifest privacy manifest', () => {
310
436
  it('copies the privacy manifest into the target resources, after the excludes', () => {
311
- const out = renderPureSwiftManifest(
312
- 'ExpoDevice',
313
- 'ios',
314
- [],
315
- [],
316
- '/abs/interfaces',
317
- ['Tests'],
318
- null,
319
- true
320
- );
437
+ const out = renderPureSwift({
438
+ product: 'ExpoDevice',
439
+ srcRel: 'ios',
440
+ frameworkSearchPath: '/abs/interfaces',
441
+ excludes: ['Tests'],
442
+ hasPrivacyManifest: true,
443
+ });
321
444
  expect(out).toContain(
322
445
  'exclude: ["Tests"],\n resources: [.copy("PrivacyInfo.xcprivacy")],'
323
446
  );
@@ -325,11 +448,20 @@ describe('renderPureSwiftManifest privacy manifest', () => {
325
448
 
326
449
  it('emits no resources key when the module ships no privacy manifest', () => {
327
450
  expect(
328
- renderPureSwiftManifest('ExpoAsset', 'ios', [], [], '/abs/interfaces', [], null, false)
451
+ renderPureSwift({
452
+ product: 'ExpoAsset',
453
+ srcRel: 'ios',
454
+ frameworkSearchPath: '/abs/interfaces',
455
+ hasPrivacyManifest: false,
456
+ })
457
+ ).not.toContain('resources:');
458
+ expect(
459
+ renderPureSwift({
460
+ product: 'ExpoAsset',
461
+ srcRel: 'ios',
462
+ frameworkSearchPath: '/abs/interfaces',
463
+ })
329
464
  ).not.toContain('resources:');
330
- expect(renderPureSwiftManifest('ExpoAsset', 'ios', [], [], '/abs/interfaces')).not.toContain(
331
- 'resources:'
332
- );
333
465
  });
334
466
  });
335
467
 
@@ -342,7 +474,10 @@ describe('emitPureSwiftSourcePackage', () => {
342
474
  fs.mkdirSync(path.join(moduleRoot, 'ios', '__tests__'), { recursive: true });
343
475
  fs.writeFileSync(path.join(moduleRoot, 'ios', 'A.swift'), '// swift\n');
344
476
 
345
- emitPureSwiftSourcePackage(moduleRoot, 'ExpoAsset', null, '/abs/interfaces', outDir, null);
477
+ emitPureSwiftSourcePackage(
478
+ { moduleRoot, product: 'ExpoAsset' },
479
+ { frameworkSearchPath: '/abs/interfaces', outDir }
480
+ );
346
481
  const manifest = fs.readFileSync(
347
482
  path.join(outDir, 'expo-source', 'ExpoAsset', 'Package.swift'),
348
483
  'utf8'
@@ -360,7 +495,10 @@ describe('emitPureSwiftSourcePackage', () => {
360
495
  if (withPrivacyManifest) {
361
496
  fs.writeFileSync(path.join(moduleRoot, 'ios', 'PrivacyInfo.xcprivacy'), '<plist/>\n');
362
497
  }
363
- emitPureSwiftSourcePackage(moduleRoot, 'ExpoDevice', null, '/abs/interfaces', outDir, null);
498
+ emitPureSwiftSourcePackage(
499
+ { moduleRoot, product: 'ExpoDevice' },
500
+ { frameworkSearchPath: '/abs/interfaces', outDir }
501
+ );
364
502
  return fs.readFileSync(
365
503
  path.join(outDir, 'expo-source', 'ExpoDevice', 'Package.swift'),
366
504
  'utf8'
@@ -401,13 +539,14 @@ describe('single-target packages with sources directly in a predefined directory
401
539
  fs.mkdirSync(path.dirname(target), { recursive: true });
402
540
  fs.writeFileSync(target, content);
403
541
  };
404
- const emit = () => emitSourceManifestPackage(moduleRoot, null, '/abs/interfaces', outDir, null);
542
+ const emit = () =>
543
+ emitSourceManifestPackage(moduleRoot, { frameworkSearchPath: '/abs/interfaces', outDir });
405
544
 
406
545
  it('resolves the only target to the bare predefined directory holding its sources', () => {
407
546
  write('Sources/File.swift');
408
547
  runDumpPackage.mockReturnValue(dumpTargets(['RootSrc']));
409
548
 
410
- expect(emit().unresolvedTargets).toBeUndefined();
549
+ expect(emit().refusal).toBeUndefined();
411
550
  expect(
412
551
  fs.readFileSync(path.join(outDir, 'expo-source', 'TestModule', 'Package.swift'), 'utf8')
413
552
  ).toContain('path: "root/Sources"');
@@ -428,14 +567,14 @@ describe('single-target packages with sources directly in a predefined directory
428
567
  write('Sources/File.swift');
429
568
  runDumpPackage.mockReturnValue(dumpTargets(['A', 'B']));
430
569
 
431
- expect(emit().unresolvedTargets).toEqual(['A', 'B']);
570
+ expect(emit().refusal).toEqual({ reason: 'unresolvable-target-path', targetNames: ['A', 'B'] });
432
571
  });
433
572
 
434
573
  it('accepts a predefined directory whose sources are nested below it', () => {
435
574
  write('Sources/Nested/File.swift');
436
575
  runDumpPackage.mockReturnValue(dumpTargets(['RootSrc']));
437
576
 
438
- expect(emit().unresolvedTargets).toBeUndefined();
577
+ expect(emit().refusal).toBeUndefined();
439
578
  expect(
440
579
  fs.readFileSync(path.join(outDir, 'expo-source', 'TestModule', 'Package.swift'), 'utf8')
441
580
  ).toContain('path: "root/Sources"');
@@ -445,7 +584,10 @@ describe('single-target packages with sources directly in a predefined directory
445
584
  write('Sources/Nested/README.md', '# docs\n');
446
585
  runDumpPackage.mockReturnValue(dumpTargets(['RootSrc']));
447
586
 
448
- expect(emit().unresolvedTargets).toEqual(['RootSrc']);
587
+ expect(emit().refusal).toEqual({
588
+ reason: 'unresolvable-target-path',
589
+ targetNames: ['RootSrc'],
590
+ });
449
591
  });
450
592
  });
451
593
 
@@ -472,15 +614,15 @@ describe('sibling dependencies on non-regular targets', () => {
472
614
  ],
473
615
  })
474
616
  ).targets;
475
- expect(main.siblingDeps).toEqual(['Helper']);
617
+ expect(main.dependencies).toEqual(['Helper']);
476
618
  });
477
619
  });
478
620
 
479
621
  describe('unsupported platform conditions', () => {
480
622
  it('refuses a freebsd-only condition instead of widening the dependency', () => {
481
623
  expect(() =>
482
- renderSourceManifest(
483
- {
624
+ renderSourceManifest({
625
+ manifest: {
484
626
  name: 'TestModule',
485
627
  products: [{ name: 'TestModule', targets: ['Main'] }],
486
628
  targets: [
@@ -488,14 +630,12 @@ describe('unsupported platform conditions', () => {
488
630
  name: 'Main',
489
631
  path: 'Main',
490
632
  publicHeadersPath: null,
491
- siblingDeps: [{ name: 'Helper', platforms: ['freebsd'] }],
633
+ dependencies: [{ name: 'Helper', platforms: ['freebsd'] }],
492
634
  },
493
635
  ],
494
636
  },
495
- [],
496
- [],
497
- '/abs/interfaces'
498
- )
637
+ frameworkSearchPath: '/abs/interfaces',
638
+ })
499
639
  ).toThrow(/"Helper".*freebsd/s);
500
640
  });
501
641
  });
@@ -522,7 +662,8 @@ describe('mirrored target file rules', () => {
522
662
  },
523
663
  ],
524
664
  });
525
- const render = (manifest) => renderSourceManifest(manifest, [], [], '/abs/interfaces');
665
+ const render = (manifest) =>
666
+ renderSourceManifest({ manifest, frameworkSearchPath: '/abs/interfaces' });
526
667
 
527
668
  it('carries exclude/sources/resources through parsing', () => {
528
669
  const [main] = parseDumpedManifest(dumped).targets;
@@ -620,12 +761,10 @@ describe('mirrored target build settings', () => {
620
761
  targets: [{ name: 'Main', type: 'regular', path: 'Main', dependencies: [], settings }],
621
762
  });
622
763
  const render = (settings) =>
623
- renderSourceManifest(
624
- parseDumpedManifest(dumpWithSettings(settings)),
625
- [],
626
- [],
627
- '/abs/interfaces'
628
- );
764
+ renderSourceManifest({
765
+ manifest: parseDumpedManifest(dumpWithSettings(settings)),
766
+ frameworkSearchPath: '/abs/interfaces',
767
+ });
629
768
 
630
769
  const settings = [
631
770
  { kind: { define: { _0: 'RCT_NEW_ARCH_ENABLED=1' } }, tool: 'c' },
@@ -835,7 +974,7 @@ describe('deployment target', () => {
835
974
  ])
836
975
  );
837
976
  expect(manifest.iosDeploymentTarget).toBe('16.4');
838
- const out = renderSourceManifest(manifest, [], [], '/abs/interfaces');
977
+ const out = renderSourceManifest({ manifest, frameworkSearchPath: '/abs/interfaces' });
839
978
  expect(out).toContain('platforms: [.iOS("16.4")],');
840
979
  expect(out).not.toContain('.macOS');
841
980
  });
@@ -845,29 +984,36 @@ describe('deployment target', () => {
845
984
  dumpWithPlatforms([{ options: [], platformName: 'macos', version: '13.4' }])
846
985
  );
847
986
  expect(manifest.iosDeploymentTarget).toBeNull();
848
- expect(renderSourceManifest(manifest, [], [], '/abs/interfaces')).toContain(
987
+ expect(renderSourceManifest({ manifest, frameworkSearchPath: '/abs/interfaces' })).toContain(
849
988
  'platforms: [.iOS(.v15)],'
850
989
  );
851
990
  });
852
991
 
853
992
  it('falls back to the plugin floor when the manifest declares no platforms at all', () => {
854
993
  expect(
855
- renderSourceManifest(
856
- parseDumpedManifest(dumpWithPlatforms(undefined)),
857
- [],
858
- [],
859
- '/abs/interfaces'
860
- )
994
+ renderSourceManifest({
995
+ manifest: parseDumpedManifest(dumpWithPlatforms(undefined)),
996
+ frameworkSearchPath: '/abs/interfaces',
997
+ })
861
998
  ).toContain('platforms: [.iOS(.v15)],');
862
999
  });
863
1000
 
864
- it('takes the pure-Swift floor the plugin read from the podspec', () => {
1001
+ it('takes the pure-Swift floor the plugin read from the prebuilt-metadata document', () => {
865
1002
  expect(
866
- renderPureSwiftManifest('ExpoAsset', 'ios', [], [], '/abs/interfaces', [], '16.4')
1003
+ renderPureSwift({
1004
+ product: 'ExpoAsset',
1005
+ srcRel: 'ios',
1006
+ frameworkSearchPath: '/abs/interfaces',
1007
+ iosDeploymentTarget: '16.4',
1008
+ })
867
1009
  ).toContain('platforms: [.iOS("16.4")],');
868
- expect(renderPureSwiftManifest('ExpoAsset', 'ios', [], [], '/abs/interfaces')).toContain(
869
- 'platforms: [.iOS(.v15)],'
870
- );
1010
+ expect(
1011
+ renderPureSwift({
1012
+ product: 'ExpoAsset',
1013
+ srcRel: 'ios',
1014
+ frameworkSearchPath: '/abs/interfaces',
1015
+ })
1016
+ ).toContain('platforms: [.iOS(.v15)],');
871
1017
  });
872
1018
 
873
1019
  it('emits the floor the emit layer was given, and never linker settings', () => {
@@ -878,13 +1024,8 @@ describe('deployment target', () => {
878
1024
  fs.writeFileSync(path.join(moduleRoot, 'ios', 'A.swift'), '// swift\n');
879
1025
 
880
1026
  emitPureSwiftSourcePackage(
881
- moduleRoot,
882
- 'ExpoAsset',
883
- null,
884
- '/abs/interfaces',
885
- outDir,
886
- null,
887
- '16.4'
1027
+ { moduleRoot, product: 'ExpoAsset', iosDeploymentTarget: '16.4' },
1028
+ { frameworkSearchPath: '/abs/interfaces', outDir }
888
1029
  );
889
1030
  const manifest = fs.readFileSync(
890
1031
  path.join(outDir, 'expo-source', 'ExpoAsset', 'Package.swift'),
@@ -895,6 +1036,81 @@ describe('deployment target', () => {
895
1036
  });
896
1037
  });
897
1038
 
1039
+ describe('raiseFloor', () => {
1040
+ it('keeps the higher of the two floors', () => {
1041
+ expect(raiseFloor('15.0', '16.4')).toBe('16.4');
1042
+ expect(raiseFloor('17.0', '16.4')).toBe('17.0');
1043
+ });
1044
+
1045
+ it('keeps the declared floor when both are the same', () => {
1046
+ expect(raiseFloor('16.4', '16.4')).toBe('16.4');
1047
+ });
1048
+
1049
+ it('compares components numerically, not as text', () => {
1050
+ expect(raiseFloor('16.10', '16.9')).toBe('16.10');
1051
+ expect(raiseFloor('16.9', '16.10')).toBe('16.10');
1052
+ });
1053
+
1054
+ it('reads a missing component as zero', () => {
1055
+ expect(raiseFloor('16', '16.0')).toBe('16');
1056
+ expect(raiseFloor('16', '16.4')).toBe('16.4');
1057
+ });
1058
+
1059
+ it('falls back to whichever floor is present', () => {
1060
+ expect(raiseFloor(null, '16.4')).toBe('16.4');
1061
+ expect(raiseFloor('16.4', null)).toBe('16.4');
1062
+ expect(raiseFloor(undefined, '16.4')).toBe('16.4');
1063
+ expect(raiseFloor('16.4', undefined)).toBe('16.4');
1064
+ });
1065
+
1066
+ it('has no floor to report when neither side declares one', () => {
1067
+ expect(raiseFloor(null, null)).toBeNull();
1068
+ expect(raiseFloor(undefined, undefined)).toBeNull();
1069
+ });
1070
+ });
1071
+
1072
+ describe('the minimum floor a checked-in manifest is raised to', () => {
1073
+ const dumpWithIos = (version) =>
1074
+ JSON.stringify({
1075
+ name: 'TestModule',
1076
+ platforms: [{ options: [], platformName: 'ios', version }],
1077
+ products: [{ name: 'TestModule', type: { library: ['automatic'] }, targets: ['Main'] }],
1078
+ targets: [{ name: 'Main', type: 'regular', path: 'Main', dependencies: [] }],
1079
+ });
1080
+
1081
+ let moduleRoot;
1082
+ let outDir;
1083
+
1084
+ beforeEach(() => {
1085
+ const tmp = fs.mkdtempSync(path.join(os.tmpdir(), 'expo-spm-minimum-'));
1086
+ moduleRoot = path.join(tmp, 'module');
1087
+ outDir = path.join(tmp, 'out');
1088
+ fs.mkdirSync(moduleRoot, { recursive: true });
1089
+ });
1090
+
1091
+ const emitted = (declared, minimum) => {
1092
+ runDumpPackage.mockReturnValue(dumpWithIos(declared));
1093
+ emitSourceManifestPackage(moduleRoot, {
1094
+ frameworkSearchPath: '/abs/interfaces',
1095
+ outDir,
1096
+ minimumIosDeploymentTarget: minimum,
1097
+ });
1098
+ return fs.readFileSync(path.join(outDir, 'expo-source', 'TestModule', 'Package.swift'), 'utf8');
1099
+ };
1100
+
1101
+ it('raises a module declaring less than the minimum', () => {
1102
+ expect(emitted('15.0', '16.4')).toContain('platforms: [.iOS("16.4")],');
1103
+ });
1104
+
1105
+ it('leaves a module declaring more than the minimum alone', () => {
1106
+ expect(emitted('17.0', '16.4')).toContain('platforms: [.iOS("17.0")],');
1107
+ });
1108
+
1109
+ it('keeps the declared floor when there is no minimum', () => {
1110
+ expect(emitted('16.4', null)).toContain('platforms: [.iOS("16.4")],');
1111
+ });
1112
+ });
1113
+
898
1114
  describe('dependencies on targets the generated package cannot declare', () => {
899
1115
  const dumpWithBinaryTarget = JSON.stringify({
900
1116
  name: 'TestModule',
@@ -973,10 +1189,12 @@ describe('dependencies on targets the generated package cannot declare', () => {
973
1189
  })
974
1190
  );
975
1191
  expect(unsupportedTargetDeps).toEqual([]);
976
- expect(targets[0].siblingDeps).toEqual(['EXConstantsObjC']);
1192
+ expect(targets[0].dependencies).toEqual(['EXConstantsObjC']);
977
1193
  });
978
1194
 
979
- it('says nothing about a name that is no target of this package — an external product', () => {
1195
+ // SwiftPM resolves it against the products of the packages the module declares, and
1196
+ // rendering it verbatim leaves that resolution where it belongs.
1197
+ it('renders a name that is no target of this package — an external product — verbatim', () => {
980
1198
  const { targets, unsupportedTargetDeps } = parseDumpedManifest(
981
1199
  JSON.stringify({
982
1200
  name: 'TestModule',
@@ -992,7 +1210,7 @@ describe('dependencies on targets the generated package cannot declare', () => {
992
1210
  })
993
1211
  );
994
1212
  expect(unsupportedTargetDeps).toEqual([]);
995
- expect(targets[0].siblingDeps).toEqual([]);
1213
+ expect(targets[0].dependencies).toEqual(['SomeUpstreamProduct']);
996
1214
  });
997
1215
 
998
1216
  it('skips the module instead of emitting a target whose dependency was dropped', () => {
@@ -1002,14 +1220,1022 @@ describe('dependencies on targets the generated package cannot declare', () => {
1002
1220
  fs.mkdirSync(path.join(moduleRoot, 'ios', 'Src'), { recursive: true });
1003
1221
  runDumpPackage.mockReturnValue(dumpWithBinaryTarget);
1004
1222
 
1005
- const result = emitSourceManifestPackage(moduleRoot, null, '/abs/interfaces', outDir, null);
1223
+ const result = emitSourceManifestPackage(moduleRoot, {
1224
+ frameworkSearchPath: '/abs/interfaces',
1225
+ outDir,
1226
+ });
1006
1227
 
1007
- expect(result.packageDep).toBeUndefined();
1008
- expect(result.unsupportedTargetDeps).toEqual([
1009
- { target: 'Src', dependsOn: 'Vendored', kind: 'binary' },
1010
- ]);
1228
+ expect(result.ok).toBeUndefined();
1229
+ expect(result.refusal).toEqual({
1230
+ reason: 'unsupported-target-dependency',
1231
+ dependencies: [{ target: 'Src', dependsOn: 'Vendored', kind: 'binary' }],
1232
+ });
1011
1233
  expect(fs.existsSync(path.join(outDir, 'expo-source', 'TestModule', 'Package.swift'))).toBe(
1012
1234
  false
1013
1235
  );
1014
1236
  });
1015
1237
  });
1238
+
1239
+ // A pure-Swift module's SwiftPM dependencies come from its spm.config.json, the
1240
+ // same coordinates CocoaPods resolves through the podspec. Without them
1241
+ // `import SDWebImage` names a package the generated manifest never declared.
1242
+ describe('SwiftPM package coordinates', () => {
1243
+ const sdWebImage = {
1244
+ url: 'https://github.com/SDWebImage/SDWebImage.git',
1245
+ productName: 'SDWebImage',
1246
+ version: { exact: '5.21.6' },
1247
+ };
1248
+
1249
+ describe('spmPackageIdentity', () => {
1250
+ it("takes the URL's last path component, without the .git suffix", () => {
1251
+ expect(spmPackageIdentity(sdWebImage)).toBe('SDWebImage');
1252
+ expect(
1253
+ spmPackageIdentity({ ...sdWebImage, url: 'https://github.com/SDWebImage/SDWebImage' })
1254
+ ).toBe('SDWebImage');
1255
+ });
1256
+
1257
+ // libavif-Xcode ships the `libavif` product: the identity SwiftPM resolves is
1258
+ // the repository name, not the product name.
1259
+ it('reads the repository name, not the product it ships', () => {
1260
+ expect(
1261
+ spmPackageIdentity({
1262
+ url: 'https://github.com/SDWebImage/libavif-Xcode.git',
1263
+ productName: 'libavif',
1264
+ version: { exact: '1.0.0' },
1265
+ })
1266
+ ).toBe('libavif-Xcode');
1267
+ });
1268
+
1269
+ // A URL ending in a slash has an empty last component, which would render
1270
+ // `package: ""` and fail the whole graph rather than the one declaration.
1271
+ it('ignores a trailing slash', () => {
1272
+ expect(
1273
+ spmPackageIdentity({ ...sdWebImage, url: 'https://github.com/SDWebImage/SDWebImage/' })
1274
+ ).toBe('SDWebImage');
1275
+ expect(
1276
+ spmPackageIdentity({ ...sdWebImage, url: 'https://github.com/SDWebImage/SDWebImage.git/' })
1277
+ ).toBe('SDWebImage');
1278
+ });
1279
+ });
1280
+
1281
+ describe('packageDeclaration of a documented package', () => {
1282
+ it('renders every version requirement PackageDescription declares', () => {
1283
+ const withVersion = (version) =>
1284
+ packageDeclaration(documentedPackage({ ...sdWebImage, version }));
1285
+ expect(withVersion({ exact: '5.21.6' })).toBe(
1286
+ '.package(url: "https://github.com/SDWebImage/SDWebImage.git", exact: "5.21.6")'
1287
+ );
1288
+ expect(withVersion({ from: '5.21.6' })).toBe(
1289
+ '.package(url: "https://github.com/SDWebImage/SDWebImage.git", from: "5.21.6")'
1290
+ );
1291
+ expect(withVersion({ branch: 'main' })).toBe(
1292
+ '.package(url: "https://github.com/SDWebImage/SDWebImage.git", branch: "main")'
1293
+ );
1294
+ expect(withVersion({ revision: 'c0ffee' })).toBe(
1295
+ '.package(url: "https://github.com/SDWebImage/SDWebImage.git", revision: "c0ffee")'
1296
+ );
1297
+ });
1298
+ });
1299
+
1300
+ describe('the target dependency on a documented package', () => {
1301
+ const rendered = (spmPackage) =>
1302
+ renderPureSwift({
1303
+ product: 'ExpoImage',
1304
+ srcRel: 'ios',
1305
+ frameworkSearchPath: '/abs/interfaces',
1306
+ packages: [documentedPackage(spmPackage)],
1307
+ });
1308
+
1309
+ it('names the product, resolved against its package identity', () => {
1310
+ expect(rendered(sdWebImage)).toContain('.product(name: "SDWebImage", package: "SDWebImage")');
1311
+ expect(
1312
+ rendered({
1313
+ url: 'https://github.com/SDWebImage/libavif-Xcode.git',
1314
+ productName: 'libavif',
1315
+ version: { exact: '1.0.0' },
1316
+ })
1317
+ ).toContain('.product(name: "libavif", package: "libavif-Xcode")');
1318
+ });
1319
+ });
1320
+
1321
+ describe('the emitted manifest', () => {
1322
+ const emitWith = (spmPackages, { react = null, satisfiedDependencies } = {}) => {
1323
+ const tmp = fs.mkdtempSync(path.join(os.tmpdir(), 'expo-spm-packages-emit-'));
1324
+ const moduleRoot = path.join(tmp, 'module');
1325
+ const outDir = path.join(tmp, 'out');
1326
+ fs.mkdirSync(path.join(moduleRoot, 'ios'), { recursive: true });
1327
+ fs.writeFileSync(path.join(moduleRoot, 'ios', 'A.swift'), '// swift\n');
1328
+ const result = emitPureSwiftSourcePackage(
1329
+ { moduleRoot, product: 'ExpoImage', iosDeploymentTarget: '16.4', spmPackages },
1330
+ { react, frameworkSearchPath: '/abs/interfaces', outDir, satisfiedDependencies }
1331
+ );
1332
+ const manifest = fs.readFileSync(
1333
+ path.join(outDir, 'expo-source', 'ExpoImage', 'Package.swift'),
1334
+ 'utf8'
1335
+ );
1336
+ return { result, manifest };
1337
+ };
1338
+ const emit = (spmPackages, react = null) => emitWith(spmPackages, { react }).manifest;
1339
+
1340
+ // The precompiled framework is already in the app; a source copy would duplicate it.
1341
+ it('leaves out a package whose product a precompiled framework already provides', () => {
1342
+ const { result, manifest } = emitWith(
1343
+ [
1344
+ sdWebImage,
1345
+ {
1346
+ url: 'https://github.com/SDWebImage/libavif-Xcode.git',
1347
+ productName: 'libavif',
1348
+ version: { exact: '1.0.0' },
1349
+ },
1350
+ ],
1351
+ { satisfiedDependencies: new Set(['SDWebImage']) }
1352
+ );
1353
+
1354
+ expect(manifest).not.toContain(
1355
+ '.package(url: "https://github.com/SDWebImage/SDWebImage.git"'
1356
+ );
1357
+ expect(manifest).not.toContain('.product(name: "SDWebImage"');
1358
+ expect(manifest).toContain(
1359
+ '.package(url: "https://github.com/SDWebImage/libavif-Xcode.git", exact: "1.0.0"),'
1360
+ );
1361
+ expect(manifest).toContain('.product(name: "libavif", package: "libavif-Xcode"),');
1362
+ expect(result.ok.spmProductNames).toEqual(['SDWebImage', 'libavif']);
1363
+ expect(result.ok.partlyProvidedPackages).toEqual([]);
1364
+ });
1365
+
1366
+ it('declares each package and depends the target on its product', () => {
1367
+ const manifest = emit([
1368
+ sdWebImage,
1369
+ {
1370
+ url: 'https://github.com/SDWebImage/libavif-Xcode.git',
1371
+ productName: 'libavif',
1372
+ version: { exact: '1.0.0' },
1373
+ },
1374
+ ]);
1375
+ expect(manifest).toContain(
1376
+ 'dependencies: [\n' +
1377
+ ' .package(url: "https://github.com/SDWebImage/SDWebImage.git", exact: "5.21.6"),\n' +
1378
+ ' .package(url: "https://github.com/SDWebImage/libavif-Xcode.git", exact: "1.0.0"),\n' +
1379
+ ' ],'
1380
+ );
1381
+ expect(manifest).toContain(
1382
+ 'dependencies: [\n' +
1383
+ ' .product(name: "SDWebImage", package: "SDWebImage"),\n' +
1384
+ ' .product(name: "libavif", package: "libavif-Xcode"),\n' +
1385
+ ' ],'
1386
+ );
1387
+ });
1388
+
1389
+ it('depends on its own package products before the React products', () => {
1390
+ const react = {
1391
+ packageRef: { name: 'ReactNative', path: '/abs/rn' },
1392
+ products: [{ name: 'React', package: 'ReactNative' }],
1393
+ };
1394
+ expect(emit([sdWebImage], react)).toContain(
1395
+ 'dependencies: [\n' +
1396
+ ' .product(name: "SDWebImage", package: "SDWebImage"),\n' +
1397
+ ' .product(name: "React", package: "ReactNative"),\n' +
1398
+ ' ],'
1399
+ );
1400
+ });
1401
+
1402
+ // A pure-Swift module renders in the format of a mirrored checked-in manifest:
1403
+ // no trailing comma after the last product or target.
1404
+ it('renders a module with no packages in the checked-in manifest format', () => {
1405
+ const expected =
1406
+ '// swift-tools-version: 6.0\n' +
1407
+ '// AUTO-GENERATED by expo/scripts/spm/plugin.js \u2014 do not edit.\n' +
1408
+ '// Pure-Swift source consumption package for "ExpoImage".\n' +
1409
+ 'import PackageDescription\n' +
1410
+ '\n' +
1411
+ 'let package = Package(\n' +
1412
+ ' name: "ExpoImage",\n' +
1413
+ ' platforms: [.iOS("16.4")],\n' +
1414
+ ' products: [\n' +
1415
+ ' .library(name: "ExpoImage", targets: ["ExpoImage"])\n' +
1416
+ ' ],\n' +
1417
+ ' dependencies: [],\n' +
1418
+ ' targets: [\n' +
1419
+ ' .target(\n' +
1420
+ ' name: "ExpoImage",\n' +
1421
+ ' dependencies: [],\n' +
1422
+ ' path: "root/ios",\n' +
1423
+ ' cSettings: [.unsafeFlags(["-F", "/abs/interfaces"])],\n' +
1424
+ ' cxxSettings: [.unsafeFlags(["-F", "/abs/interfaces"])],\n' +
1425
+ ' swiftSettings: [.unsafeFlags(["-F", "/abs/interfaces"])],\n' +
1426
+ ' )\n' +
1427
+ ' ],\n' +
1428
+ ' swiftLanguageModes: [.v5],\n' +
1429
+ ' cxxLanguageStandard: .cxx20\n' +
1430
+ ')\n';
1431
+ expect(emit([])).toBe(expected);
1432
+ expect(emit(undefined)).toBe(expected);
1433
+ });
1434
+ });
1435
+ });
1436
+
1437
+ // A module that ships a checked-in Package.swift may declare third-party SwiftPM
1438
+ // packages of its own. The generated consumption package has to mirror them, or its
1439
+ // sources fail to compile with "no such module".
1440
+ describe('mirrored package dependencies', () => {
1441
+ // Verbatim shapes from `swift package dump-package` (SwiftPM 6.0).
1442
+ const remote = (identity, url, requirement, extra = {}) => ({
1443
+ sourceControl: [
1444
+ {
1445
+ identity,
1446
+ location: { remote: [{ urlString: url }] },
1447
+ productFilter: null,
1448
+ requirement,
1449
+ traits: [{ name: 'default' }],
1450
+ ...extra,
1451
+ },
1452
+ ],
1453
+ });
1454
+
1455
+ const SDWEB_IMAGE = remote('sdwebimage', 'https://github.com/SDWebImage/SDWebImage.git', {
1456
+ exact: ['5.21.6'],
1457
+ });
1458
+ // `.package(url:from:)` dumps as a range — the renderer never sees a `from` form.
1459
+ const LIBAVIF = remote('libavif-xcode', 'https://github.com/SDWebImage/libavif-Xcode.git', {
1460
+ range: [{ lowerBound: '0.11.0', upperBound: '1.0.0' }],
1461
+ });
1462
+ const ALL_REQUIREMENT_FORMS = [
1463
+ SDWEB_IMAGE,
1464
+ remote('branchy', 'https://github.com/acme/branchy.git', { branch: ['main'] }),
1465
+ remote('pinned', 'https://github.com/acme/pinned.git', { revision: ['0123456789abcdef'] }),
1466
+ LIBAVIF,
1467
+ ];
1468
+
1469
+ const dumpWith = ({ dependencies = [], targetDeps = [] }) =>
1470
+ JSON.stringify({
1471
+ name: 'TestModule',
1472
+ dependencies,
1473
+ products: [{ name: 'TestModule', type: { library: ['automatic'] }, targets: ['Main'] }],
1474
+ targets: [
1475
+ { name: 'Main', type: 'regular', path: 'ios/Main', dependencies: targetDeps },
1476
+ { name: 'Helper', type: 'regular', path: 'ios/Helper', dependencies: [] },
1477
+ ],
1478
+ });
1479
+
1480
+ const render = (dump, injectedNames = []) =>
1481
+ renderSourceManifest({
1482
+ manifest: parseDumpedManifest(dump, injectedNames),
1483
+ pkgDeps: ['.package(name: "ReactNative", path: "/abs/rn")'],
1484
+ injectedTargetDeps: ['.product(name: "React", package: "ReactNative")'],
1485
+ frameworkSearchPath: '/abs/interfaces',
1486
+ });
1487
+
1488
+ const unsupported = (dependencies, targetDeps) =>
1489
+ parseDumpedManifest(dumpWith({ dependencies, targetDeps })).unsupportedPackageDeps;
1490
+
1491
+ it('parses every requirement form the generated package can declare', () => {
1492
+ const { packageDeps, unsupportedPackageDeps } = parseDumpedManifest(
1493
+ dumpWith({ dependencies: ALL_REQUIREMENT_FORMS })
1494
+ );
1495
+ expect(unsupportedPackageDeps).toEqual([]);
1496
+ expect(packageDeps).toEqual([
1497
+ {
1498
+ identity: 'sdwebimage',
1499
+ url: 'https://github.com/SDWebImage/SDWebImage.git',
1500
+ requirement: { kind: 'exact', value: '5.21.6' },
1501
+ },
1502
+ {
1503
+ identity: 'branchy',
1504
+ url: 'https://github.com/acme/branchy.git',
1505
+ requirement: { kind: 'branch', value: 'main' },
1506
+ },
1507
+ {
1508
+ identity: 'pinned',
1509
+ url: 'https://github.com/acme/pinned.git',
1510
+ requirement: { kind: 'revision', value: '0123456789abcdef' },
1511
+ },
1512
+ {
1513
+ identity: 'libavif-xcode',
1514
+ url: 'https://github.com/SDWebImage/libavif-Xcode.git',
1515
+ requirement: { kind: 'range', lowerBound: '0.11.0', upperBound: '1.0.0' },
1516
+ },
1517
+ ]);
1518
+ });
1519
+
1520
+ it('declares each requirement form the way PackageDescription spells it', () => {
1521
+ const out = render(dumpWith({ dependencies: ALL_REQUIREMENT_FORMS }));
1522
+ expect(out).toContain(
1523
+ '.package(url: "https://github.com/SDWebImage/SDWebImage.git", exact: "5.21.6"),'
1524
+ );
1525
+ expect(out).toContain('.package(url: "https://github.com/acme/branchy.git", branch: "main"),');
1526
+ expect(out).toContain(
1527
+ '.package(url: "https://github.com/acme/pinned.git", revision: "0123456789abcdef"),'
1528
+ );
1529
+ expect(out).toContain(
1530
+ '.package(url: "https://github.com/SDWebImage/libavif-Xcode.git", "0.11.0"..<"1.0.0"),'
1531
+ );
1532
+ });
1533
+
1534
+ it('declares the mirrored packages after the injected ones', () => {
1535
+ expect(render(dumpWith({ dependencies: [SDWEB_IMAGE] }))).toContain(
1536
+ 'dependencies: [\n' +
1537
+ ' .package(name: "ReactNative", path: "/abs/rn"),\n' +
1538
+ ' .package(url: "https://github.com/SDWebImage/SDWebImage.git", exact: "5.21.6"),\n' +
1539
+ ' ],'
1540
+ );
1541
+ });
1542
+
1543
+ it('keeps target dependencies in their declared order, siblings and products alike', () => {
1544
+ const dump = dumpWith({
1545
+ dependencies: [SDWEB_IMAGE, LIBAVIF],
1546
+ targetDeps: [
1547
+ { product: ['SDWebImage', 'SDWebImage', null, null] },
1548
+ { byName: ['Helper', null] },
1549
+ { product: ['SDWebImageAVIFCoder', 'libavif-Xcode', null, { platformNames: ['ios'] }] },
1550
+ ],
1551
+ });
1552
+ expect(parseDumpedManifest(dump).targets[0].dependencies).toEqual([
1553
+ { product: 'SDWebImage', package: 'SDWebImage', platforms: [] },
1554
+ 'Helper',
1555
+ { product: 'SDWebImageAVIFCoder', package: 'libavif-Xcode', platforms: ['ios'] },
1556
+ ]);
1557
+ expect(render(dump)).toContain(
1558
+ [
1559
+ ' .product(name: "SDWebImage", package: "SDWebImage"),',
1560
+ ' "Helper",',
1561
+ ' .product(name: "SDWebImageAVIFCoder", package: "libavif-Xcode", condition: .when(platforms: [.iOS])),',
1562
+ ' .product(name: "React", package: "ReactNative"),',
1563
+ ].join('\n')
1564
+ );
1565
+ });
1566
+
1567
+ it('keeps a byName dependency that names a declared package', () => {
1568
+ const dump = dumpWith({
1569
+ dependencies: [
1570
+ remote('branchy', 'https://github.com/acme/branchy.git', { branch: ['main'] }),
1571
+ ],
1572
+ targetDeps: [
1573
+ { byName: ['branchy', null] },
1574
+ { byName: ['Branchy', { platformNames: ['ios'] }] },
1575
+ ],
1576
+ });
1577
+ const { targets, unsupportedPackageDeps } = parseDumpedManifest(dump);
1578
+ expect(unsupportedPackageDeps).toEqual([]);
1579
+ expect(targets[0].dependencies).toEqual(['branchy', { byName: 'Branchy', platforms: ['ios'] }]);
1580
+ expect(render(dump)).toContain(
1581
+ ' "branchy",\n' +
1582
+ ' .byName(name: "Branchy", condition: .when(platforms: [.iOS])),'
1583
+ );
1584
+ });
1585
+
1586
+ const vendored = { fileSystem: [{ identity: 'vendored', path: '/abs/vendored' }] };
1587
+ const SDWEB_PRODUCT = ['SDWebImage', 'SDWebImage'];
1588
+
1589
+ it.each([
1590
+ {
1591
+ title: 'reports a local path dependency instead of dropping it',
1592
+ dependencies: [
1593
+ { fileSystem: [{ identity: 'local-thing', path: '/abs/path', productFilter: null }] },
1594
+ ],
1595
+ expected: [{ form: 'local-path', identity: 'local-thing', target: null }],
1596
+ },
1597
+ {
1598
+ title: 'reports a registry dependency',
1599
+ dependencies: [
1600
+ { registry: [{ identity: 'acme.widgets', requirement: { exact: ['1.0.0'] } }] },
1601
+ ],
1602
+ expected: [{ form: 'registry', identity: 'acme.widgets', target: null }],
1603
+ },
1604
+ {
1605
+ title: 'reports a source-control dependency that is not a remote URL',
1606
+ dependencies: [
1607
+ {
1608
+ sourceControl: [
1609
+ {
1610
+ identity: 'local-scm',
1611
+ location: { local: [{ path: '/abs/checkout' }] },
1612
+ requirement: { branch: ['main'] },
1613
+ },
1614
+ ],
1615
+ },
1616
+ ],
1617
+ expected: [{ form: 'unsupported-location', identity: 'local-scm', target: null }],
1618
+ },
1619
+ {
1620
+ title: 'reports a requirement form it cannot render',
1621
+ dependencies: [
1622
+ remote('futured', 'https://github.com/acme/futured.git', { upToNextMajor: ['1.0.0'] }),
1623
+ ],
1624
+ expected: [{ form: 'unsupported-requirement', identity: 'futured', target: null }],
1625
+ },
1626
+ {
1627
+ title: 'reports a dependency form it does not recognize',
1628
+ dependencies: [{ sourceArchive: [{ identity: 'zipped' }] }],
1629
+ expected: [{ form: 'unknown-form', identity: 'zipped', target: null }],
1630
+ },
1631
+ {
1632
+ title: 'reports a product whose package the manifest never declared, naming the target',
1633
+ targetDeps: [{ product: [...SDWEB_PRODUCT, null, null] }],
1634
+ expected: [{ form: 'undeclared-package', identity: 'SDWebImage', target: 'Main' }],
1635
+ },
1636
+ {
1637
+ title: 'reports a product that names no package at all',
1638
+ targetDeps: [{ product: ['Vendored', null, null, null] }],
1639
+ expected: [{ form: 'undeclared-package', identity: null, target: 'Main' }],
1640
+ },
1641
+ {
1642
+ title: 'does not also call a product of an unmirrorable, declared package undeclared',
1643
+ dependencies: [vendored],
1644
+ targetDeps: [{ product: ['Vendored', 'vendored', null, null] }],
1645
+ expected: [{ form: 'local-path', identity: 'vendored', target: 'Main' }],
1646
+ },
1647
+ {
1648
+ title: 'attributes a product to an unmirrorable package declared under another name',
1649
+ dependencies: [
1650
+ {
1651
+ fileSystem: [
1652
+ {
1653
+ identity: 'libavif-xcode',
1654
+ nameForTargetDependencyResolutionOnly: 'Avif',
1655
+ path: '/abs/libavif-Xcode',
1656
+ },
1657
+ ],
1658
+ },
1659
+ ],
1660
+ targetDeps: [{ product: ['Avif', 'Avif', null, null] }],
1661
+ expected: [{ form: 'local-path', identity: 'libavif-xcode', target: 'Main' }],
1662
+ },
1663
+ {
1664
+ title: 'still reports a product whose package nothing declares',
1665
+ dependencies: [vendored],
1666
+ targetDeps: [{ product: ['Elsewhere', 'elsewhere', null, null] }],
1667
+ expected: [
1668
+ { form: 'local-path', identity: 'vendored', target: null },
1669
+ { form: 'undeclared-package', identity: 'elsewhere', target: 'Main' },
1670
+ ],
1671
+ },
1672
+ {
1673
+ title: 'reports two declared packages that answer to one name',
1674
+ dependencies: [
1675
+ remote('libavif', 'https://github.com/acme/libavif.git', { exact: ['2.0.0'] }),
1676
+ remote(
1677
+ 'libavif-xcode',
1678
+ 'https://github.com/SDWebImage/libavif-Xcode.git',
1679
+ { exact: ['1.0.0'] },
1680
+ { nameForTargetDependencyResolutionOnly: 'libavif' }
1681
+ ),
1682
+ ],
1683
+ expected: [{ form: 'ambiguous-package-name', identity: 'libavif', target: null }],
1684
+ },
1685
+ {
1686
+ title: 'reports a product dependency that renames modules with moduleAliases',
1687
+ dependencies: [SDWEB_IMAGE],
1688
+ targetDeps: [{ product: [...SDWEB_PRODUCT, { SD: 'SDWeb' }, null] }],
1689
+ expected: [{ form: 'module-aliases', identity: 'SDWebImage', target: 'Main' }],
1690
+ },
1691
+ {
1692
+ title: 'says nothing about an empty moduleAliases map',
1693
+ dependencies: [SDWEB_IMAGE],
1694
+ targetDeps: [{ product: [...SDWEB_PRODUCT, {}, null] }],
1695
+ expected: [],
1696
+ },
1697
+ {
1698
+ title: 'reports a product dependency conditioned on something other than platforms',
1699
+ dependencies: [SDWEB_IMAGE],
1700
+ targetDeps: [
1701
+ { product: [...SDWEB_PRODUCT, null, { platformNames: ['ios'], traits: ['x'] }] },
1702
+ ],
1703
+ expected: [{ form: 'unsupported-condition', identity: 'SDWebImage', target: 'Main' }],
1704
+ },
1705
+ {
1706
+ title: 'reports a sibling dependency so conditioned as a dependency, not a package',
1707
+ targetDeps: [{ byName: ['Helper', { traits: ['x'] }] }],
1708
+ expected: [{ form: 'unsupported-target-condition', identity: 'Helper', target: 'Main' }],
1709
+ },
1710
+ {
1711
+ title: 'says nothing about a condition whose only set key is the platform list',
1712
+ dependencies: [SDWEB_IMAGE],
1713
+ targetDeps: [
1714
+ {
1715
+ product: [...SDWEB_PRODUCT, null, { platformNames: ['ios'], traits: null, config: null }],
1716
+ },
1717
+ ],
1718
+ expected: [],
1719
+ },
1720
+ {
1721
+ title: 'reports a package declared with a trait set that is not the default',
1722
+ dependencies: [
1723
+ remote(
1724
+ 'traited',
1725
+ 'https://github.com/acme/traited.git',
1726
+ { exact: ['1.0.0'] },
1727
+ { traits: [{ name: 'default' }, { name: 'extras' }] }
1728
+ ),
1729
+ ],
1730
+ expected: [{ form: 'unsupported-traits', identity: 'traited', target: null }],
1731
+ },
1732
+ ])('$title', ({ dependencies = [], targetDeps = [], expected }) => {
1733
+ expect(unsupported(dependencies, targetDeps)).toEqual(expected);
1734
+ });
1735
+
1736
+ it('reports a package whose identity collides with one the injected set occupies', () => {
1737
+ const { unsupportedPackageDeps } = parseDumpedManifest(
1738
+ dumpWith({
1739
+ dependencies: [
1740
+ remote('reactnative', 'https://github.com/acme/ReactNative.git', {
1741
+ exact: ['1.0.0'],
1742
+ }),
1743
+ ],
1744
+ }),
1745
+ ['ReactNative', 'React-GeneratedCode']
1746
+ );
1747
+ expect(unsupportedPackageDeps).toEqual([
1748
+ { form: 'collides-with-injected', identity: 'reactnative', target: null },
1749
+ ]);
1750
+ });
1751
+
1752
+ it('renders a manifest without dependencies byte for byte', () => {
1753
+ const dump = JSON.stringify({
1754
+ name: 'expo-constants',
1755
+ dependencies: [],
1756
+ platforms: [{ platformName: 'ios', version: '15.1' }],
1757
+ products: [
1758
+ {
1759
+ name: 'EXConstants',
1760
+ type: { library: ['automatic'] },
1761
+ targets: ['EXConstants', 'EXConstantsObjC'],
1762
+ },
1763
+ ],
1764
+ targets: [
1765
+ {
1766
+ name: 'EXConstants',
1767
+ type: 'regular',
1768
+ path: 'ios/EXConstants',
1769
+ dependencies: [{ byName: ['EXConstantsObjC', null] }],
1770
+ },
1771
+ {
1772
+ name: 'EXConstantsObjC',
1773
+ type: 'regular',
1774
+ path: 'ios/EXConstantsObjC',
1775
+ publicHeadersPath: 'include',
1776
+ dependencies: [],
1777
+ },
1778
+ ],
1779
+ });
1780
+ expect(render(dump)).toBe(`// swift-tools-version: 6.0
1781
+ // AUTO-GENERATED by expo/scripts/spm/plugin.js — do not edit.
1782
+ // Source consumption package for "expo-constants": mirrors the module's checked-in
1783
+ // Package.swift targets and injects invariant React compile dependencies.
1784
+ import PackageDescription
1785
+
1786
+ let package = Package(
1787
+ name: "expo-constants",
1788
+ platforms: [.iOS("15.1")],
1789
+ products: [
1790
+ .library(name: "EXConstants", targets: ["EXConstants", "EXConstantsObjC"])
1791
+ ],
1792
+ dependencies: [
1793
+ .package(name: "ReactNative", path: "/abs/rn"),
1794
+ ],
1795
+ targets: [
1796
+ .target(
1797
+ name: "EXConstants",
1798
+ dependencies: [
1799
+ "EXConstantsObjC",
1800
+ .product(name: "React", package: "ReactNative"),
1801
+ ],
1802
+ path: "root/ios/EXConstants",
1803
+ cSettings: [.unsafeFlags(["-F", "/abs/interfaces"])],
1804
+ cxxSettings: [.unsafeFlags(["-F", "/abs/interfaces"])],
1805
+ swiftSettings: [.unsafeFlags(["-F", "/abs/interfaces"])],
1806
+ ),
1807
+ .target(
1808
+ name: "EXConstantsObjC",
1809
+ dependencies: [
1810
+ .product(name: "React", package: "ReactNative"),
1811
+ ],
1812
+ path: "root/ios/EXConstantsObjC",
1813
+ publicHeadersPath: "include",
1814
+ cSettings: [.unsafeFlags(["-F", "/abs/interfaces"])],
1815
+ cxxSettings: [.unsafeFlags(["-F", "/abs/interfaces"])],
1816
+ swiftSettings: [.unsafeFlags(["-F", "/abs/interfaces"])],
1817
+ )
1818
+ ],
1819
+ swiftLanguageModes: [.v5],
1820
+ cxxLanguageStandard: .cxx20
1821
+ )
1822
+ `);
1823
+ });
1824
+
1825
+ // SwiftPM resolves a `.byName` that is no target of this package against the products
1826
+ // of the packages it declares, which a dumped manifest does not enumerate.
1827
+ it('renders a byName that names no target verbatim rather than dropping it', () => {
1828
+ const dump = dumpWith({
1829
+ dependencies: [LIBAVIF],
1830
+ targetDeps: [
1831
+ { byName: ['libavif', null] },
1832
+ { byName: ['SVGKit', { platformNames: ['ios'] }] },
1833
+ ],
1834
+ });
1835
+ const { targets, unsupportedPackageDeps } = parseDumpedManifest(dump);
1836
+ expect(unsupportedPackageDeps).toEqual([]);
1837
+ expect(targets[0].dependencies).toEqual(['libavif', { byName: 'SVGKit', platforms: ['ios'] }]);
1838
+ expect(render(dump)).toContain(
1839
+ ' "libavif",\n' +
1840
+ ' .byName(name: "SVGKit", condition: .when(platforms: [.iOS])),'
1841
+ );
1842
+ });
1843
+
1844
+ // `.package(name:url:)` is deprecated but legal, and the manifest then names the
1845
+ // package by that name rather than by the identity SwiftPM derives from the URL.
1846
+ it('matches a product against the name the manifest gave the package', () => {
1847
+ const named = remote(
1848
+ 'libavif-xcode',
1849
+ 'https://github.com/SDWebImage/libavif-Xcode.git',
1850
+ { range: [{ lowerBound: '1.0.0', upperBound: '2.0.0' }] },
1851
+ { nameForTargetDependencyResolutionOnly: 'libavif' }
1852
+ );
1853
+ const dump = dumpWith({
1854
+ dependencies: [named],
1855
+ targetDeps: [{ product: ['libavif', 'libavif', null, null] }],
1856
+ });
1857
+ expect(parseDumpedManifest(dump).unsupportedPackageDeps).toEqual([]);
1858
+ // The mirrored declaration carries no `name:`, so the product has to name the identity.
1859
+ expect(render(dump)).toContain('.product(name: "libavif", package: "libavif-xcode"),');
1860
+ });
1861
+
1862
+ it('escapes a conditioned sibling target name like every other dependency', () => {
1863
+ const out = renderSourceManifest({
1864
+ manifest: {
1865
+ name: 'TestModule',
1866
+ products: [{ name: 'TestModule', targets: ['Main'] }],
1867
+ targets: [
1868
+ {
1869
+ name: 'Main',
1870
+ path: 'Main',
1871
+ publicHeadersPath: null,
1872
+ dependencies: [{ name: 'We"ird', platforms: ['ios'] }],
1873
+ },
1874
+ ],
1875
+ },
1876
+ frameworkSearchPath: '/abs/interfaces',
1877
+ });
1878
+ expect(out).toContain('.target(name: "We\\"ird", condition: .when(platforms: [.iOS]))');
1879
+ });
1880
+
1881
+ describe('emitting a module that declares packages', () => {
1882
+ let moduleRoot;
1883
+ let outDir;
1884
+
1885
+ beforeEach(() => {
1886
+ const tmp = fs.mkdtempSync(path.join(os.tmpdir(), 'expo-spm-pkg-deps-'));
1887
+ moduleRoot = path.join(tmp, 'module');
1888
+ outDir = path.join(tmp, 'out');
1889
+ fs.mkdirSync(path.join(moduleRoot, 'ios', 'Main'), { recursive: true });
1890
+ fs.mkdirSync(path.join(moduleRoot, 'ios', 'Helper'), { recursive: true });
1891
+ });
1892
+
1893
+ const emittedManifestPath = () =>
1894
+ path.join(outDir, 'expo-source', 'TestModule', 'Package.swift');
1895
+ const emittedManifest = () => fs.readFileSync(emittedManifestPath(), 'utf8');
1896
+ const emit = (dump, react, satisfiedDependencies) => {
1897
+ runDumpPackage.mockReturnValue(dump);
1898
+ return emitSourceManifestPackage(moduleRoot, {
1899
+ react,
1900
+ frameworkSearchPath: '/abs/interfaces',
1901
+ outDir,
1902
+ satisfiedDependencies,
1903
+ });
1904
+ };
1905
+
1906
+ // A package can export several products; only the ones a precompiled framework
1907
+ // provides go, and the package stays while anything still depends on it.
1908
+ it('leaves out the products a precompiled framework already provides', () => {
1909
+ const result = emit(
1910
+ dumpWith({
1911
+ dependencies: [SDWEB_IMAGE, LIBAVIF],
1912
+ targetDeps: [
1913
+ { product: ['SDWebImage', 'SDWebImage', null, null] },
1914
+ { product: ['SDWebImageMapKit', 'SDWebImage', null, null] },
1915
+ { product: ['libavif', 'libavif-Xcode', null, null] },
1916
+ ],
1917
+ }),
1918
+ null,
1919
+ new Set(['SDWebImage', 'libavif'])
1920
+ );
1921
+
1922
+ expect(result.refusal).toBeUndefined();
1923
+ const manifest = emittedManifest();
1924
+ expect(manifest).not.toContain('.product(name: "SDWebImage"');
1925
+ expect(manifest).toContain('.product(name: "SDWebImageMapKit", package: "SDWebImage"),');
1926
+ expect(manifest).toContain(
1927
+ '.package(url: "https://github.com/SDWebImage/SDWebImage.git", exact: "5.21.6"),'
1928
+ );
1929
+ expect(manifest).not.toContain('.product(name: "libavif"');
1930
+ expect(manifest).not.toContain('libavif-Xcode.git');
1931
+ expect(result.ok.spmProductNames).toEqual(['SDWebImage', 'SDWebImageMapKit', 'libavif']);
1932
+ expect(result.ok.partlyProvidedPackages).toEqual([
1933
+ {
1934
+ url: 'https://github.com/SDWebImage/SDWebImage.git',
1935
+ providedProducts: ['SDWebImage'],
1936
+ keptProducts: ['SDWebImageMapKit'],
1937
+ },
1938
+ ]);
1939
+ });
1940
+
1941
+ it('leaves out a provided product in every target, keeping the package another uses', () => {
1942
+ const result = emit(
1943
+ JSON.stringify({
1944
+ name: 'TestModule',
1945
+ dependencies: [SDWEB_IMAGE],
1946
+ products: [{ name: 'TestModule', type: { library: ['automatic'] }, targets: ['Main'] }],
1947
+ targets: [
1948
+ {
1949
+ name: 'Main',
1950
+ type: 'regular',
1951
+ path: 'ios/Main',
1952
+ dependencies: [{ product: ['SDWebImage', 'SDWebImage', null, null] }],
1953
+ },
1954
+ {
1955
+ name: 'Helper',
1956
+ type: 'regular',
1957
+ path: 'ios/Helper',
1958
+ dependencies: [
1959
+ { product: ['SDWebImage', 'SDWebImage', null, null] },
1960
+ { product: ['SDWebImageMapKit', 'SDWebImage', null, null] },
1961
+ ],
1962
+ },
1963
+ ],
1964
+ }),
1965
+ null,
1966
+ new Set(['SDWebImage'])
1967
+ );
1968
+
1969
+ const manifest = emittedManifest();
1970
+ expect(manifest).not.toContain('.product(name: "SDWebImage"');
1971
+ expect(manifest).toContain('.product(name: "SDWebImageMapKit", package: "SDWebImage"),');
1972
+ expect(manifest).toContain(
1973
+ '.package(url: "https://github.com/SDWebImage/SDWebImage.git", exact: "5.21.6"),'
1974
+ );
1975
+ expect(result.ok.partlyProvidedPackages).toEqual([
1976
+ {
1977
+ url: 'https://github.com/SDWebImage/SDWebImage.git',
1978
+ providedProducts: ['SDWebImage'],
1979
+ keptProducts: ['SDWebImageMapKit'],
1980
+ },
1981
+ ]);
1982
+ });
1983
+
1984
+ it('leaves out a package once every product taken from it is provided', () => {
1985
+ const result = emit(
1986
+ dumpWith({
1987
+ dependencies: [SDWEB_IMAGE],
1988
+ targetDeps: [{ product: ['SDWebImage', 'SDWebImage', null, null] }],
1989
+ }),
1990
+ null,
1991
+ new Set(['SDWebImage'])
1992
+ );
1993
+
1994
+ expect(emittedManifest()).not.toContain('SDWebImage.git');
1995
+ expect(emittedManifest()).not.toContain('.product(name: "SDWebImage"');
1996
+ expect(result.ok.partlyProvidedPackages).toEqual([]);
1997
+ });
1998
+
1999
+ it('leaves out a byName dependency on a product a precompiled framework provides', () => {
2000
+ const result = emit(
2001
+ dumpWith({
2002
+ dependencies: [SDWEB_IMAGE],
2003
+ targetDeps: [
2004
+ { byName: ['SDWebImage', null] },
2005
+ { byName: ['SDWebImage', { platformNames: ['ios'] }] },
2006
+ ],
2007
+ }),
2008
+ null,
2009
+ new Set(['SDWebImage'])
2010
+ );
2011
+
2012
+ expect(emittedManifest()).not.toContain('"SDWebImage"');
2013
+ expect(emittedManifest()).not.toContain('SDWebImage.git');
2014
+ expect(result.ok.spmProductNames).toEqual(['SDWebImage']);
2015
+ expect(result.ok.partlyProvidedPackages).toEqual([]);
2016
+ });
2017
+
2018
+ // Which package a bare name comes from is unknown, so its loss names no package.
2019
+ it('reports a skipped byName dependency once, with every package still declared', () => {
2020
+ const result = emit(
2021
+ dumpWith({
2022
+ dependencies: [SDWEB_IMAGE, LIBAVIF],
2023
+ targetDeps: [
2024
+ { byName: ['SDWebImage', null] },
2025
+ { product: ['libavif', 'libavif-Xcode', null, null] },
2026
+ ],
2027
+ }),
2028
+ null,
2029
+ new Set(['SDWebImage'])
2030
+ );
2031
+
2032
+ expect(emittedManifest()).not.toContain('"SDWebImage"');
2033
+ expect(emittedManifest()).not.toContain('SDWebImage.git');
2034
+ expect(emittedManifest()).toContain('libavif-Xcode.git');
2035
+ expect(result.ok.partlyProvidedPackages).toEqual([
2036
+ {
2037
+ providedProducts: ['SDWebImage'],
2038
+ keptPackages: ['https://github.com/SDWebImage/libavif-Xcode.git'],
2039
+ },
2040
+ ]);
2041
+ });
2042
+
2043
+ // A bare name does not say which package it comes from, so it keeps them all.
2044
+ it('keeps a package a remaining byName dependency may take a product from', () => {
2045
+ const result = emit(
2046
+ dumpWith({
2047
+ dependencies: [SDWEB_IMAGE],
2048
+ targetDeps: [
2049
+ { product: ['SDWebImage', 'SDWebImage', null, null] },
2050
+ { byName: ['SDWebImageMapKit', null] },
2051
+ ],
2052
+ }),
2053
+ null,
2054
+ new Set(['SDWebImage'])
2055
+ );
2056
+
2057
+ expect(emittedManifest()).not.toContain('.product(name: "SDWebImage"');
2058
+ expect(emittedManifest()).toContain('"SDWebImageMapKit",');
2059
+ expect(emittedManifest()).toContain(
2060
+ '.package(url: "https://github.com/SDWebImage/SDWebImage.git", exact: "5.21.6"),'
2061
+ );
2062
+ expect(result.ok.partlyProvidedPackages).toEqual([
2063
+ {
2064
+ url: 'https://github.com/SDWebImage/SDWebImage.git',
2065
+ providedProducts: ['SDWebImage'],
2066
+ keptProducts: [],
2067
+ unattributedNames: ['SDWebImageMapKit'],
2068
+ },
2069
+ ]);
2070
+ });
2071
+
2072
+ it('does not attribute a remaining byName dependency to a package that lost a product', () => {
2073
+ const LOTTIE = remote('lottie-spm', 'https://github.com/airbnb/lottie-spm.git', {
2074
+ exact: ['4.5.0'],
2075
+ });
2076
+ const result = emit(
2077
+ dumpWith({
2078
+ dependencies: [SDWEB_IMAGE, LOTTIE],
2079
+ targetDeps: [
2080
+ { product: ['SDWebImage', 'SDWebImage', null, null] },
2081
+ { byName: ['Lottie', null] },
2082
+ ],
2083
+ }),
2084
+ null,
2085
+ new Set(['SDWebImage'])
2086
+ );
2087
+
2088
+ expect(emittedManifest()).toContain('SDWebImage.git');
2089
+ expect(emittedManifest()).toContain('lottie-spm.git');
2090
+ expect(result.ok.partlyProvidedPackages).toEqual([
2091
+ {
2092
+ url: 'https://github.com/SDWebImage/SDWebImage.git',
2093
+ providedProducts: ['SDWebImage'],
2094
+ keptProducts: [],
2095
+ unattributedNames: ['Lottie'],
2096
+ },
2097
+ ]);
2098
+ });
2099
+
2100
+ it('keeps the packages for a remaining byName dependency with a condition', () => {
2101
+ emit(
2102
+ dumpWith({
2103
+ dependencies: [SDWEB_IMAGE],
2104
+ targetDeps: [
2105
+ { product: ['SDWebImage', 'SDWebImage', null, null] },
2106
+ { byName: ['SDWebImageMapKit', { platformNames: ['ios'] }] },
2107
+ ],
2108
+ }),
2109
+ null,
2110
+ new Set(['SDWebImage'])
2111
+ );
2112
+
2113
+ expect(emittedManifest()).not.toContain('.product(name: "SDWebImage"');
2114
+ expect(emittedManifest()).toContain('.byName(name: "SDWebImageMapKit", condition:');
2115
+ expect(emittedManifest()).toContain(
2116
+ '.package(url: "https://github.com/SDWebImage/SDWebImage.git", exact: "5.21.6"),'
2117
+ );
2118
+ });
2119
+
2120
+ it('keeps a dependency on a sibling target named like a provided product', () => {
2121
+ emit(dumpWith({ targetDeps: [{ byName: ['Helper', null] }] }), null, new Set(['Helper']));
2122
+
2123
+ expect(emittedManifest()).toContain(
2124
+ 'dependencies: [\n "Helper",\n ],'
2125
+ );
2126
+ });
2127
+
2128
+ it('carries the module packages and their products into the emitted manifest', () => {
2129
+ const result = emit(
2130
+ dumpWith({
2131
+ dependencies: [SDWEB_IMAGE],
2132
+ targetDeps: [{ product: ['SDWebImage', 'SDWebImage', null, null] }],
2133
+ })
2134
+ );
2135
+
2136
+ expect(result.refusal).toBeUndefined();
2137
+ expect(emittedManifest()).toContain(
2138
+ '.package(url: "https://github.com/SDWebImage/SDWebImage.git", exact: "5.21.6"),'
2139
+ );
2140
+ expect(emittedManifest()).toContain('.product(name: "SDWebImage", package: "SDWebImage"),');
2141
+ expect(result.ok.partlyProvidedPackages).toEqual([]);
2142
+ });
2143
+
2144
+ it('skips the module instead of emitting a manifest missing a package it declares', () => {
2145
+ const result = emit(
2146
+ dumpWith({ dependencies: [{ fileSystem: [{ identity: 'local-thing', path: '/abs' }] }] })
2147
+ );
2148
+
2149
+ expect(result.ok).toBeUndefined();
2150
+ expect(result.refusal).toEqual({
2151
+ reason: 'unsupported-package-dependency',
2152
+ dependencies: [{ form: 'local-path', identity: 'local-thing', target: null }],
2153
+ });
2154
+ expect(fs.existsSync(emittedManifestPath())).toBe(false);
2155
+ });
2156
+
2157
+ // `unmappedPodDependencies` subtracts these from the pods the module's podspec
2158
+ // names, matching a pod against the PRODUCT name, not the package identity.
2159
+ it('names the third-party products it mirrored, and no sibling target', () => {
2160
+ const result = emit(
2161
+ JSON.stringify({
2162
+ name: 'TestModule',
2163
+ dependencies: [
2164
+ SDWEB_IMAGE,
2165
+ LIBAVIF,
2166
+ remote('branchy', 'https://github.com/acme/branchy.git', { branch: ['main'] }),
2167
+ ],
2168
+ products: [{ name: 'TestModule', type: { library: ['automatic'] }, targets: ['Main'] }],
2169
+ targets: [
2170
+ {
2171
+ name: 'Main',
2172
+ type: 'regular',
2173
+ path: 'ios/Main',
2174
+ dependencies: [
2175
+ { byName: ['Helper', null] },
2176
+ { product: ['SDWebImage', 'SDWebImage', null, null] },
2177
+ { byName: ['branchy', null] },
2178
+ ],
2179
+ },
2180
+ {
2181
+ name: 'Helper',
2182
+ type: 'regular',
2183
+ path: 'ios/Helper',
2184
+ dependencies: [
2185
+ { product: ['libavif', 'libavif-Xcode', null, { platformNames: ['ios'] }] },
2186
+ { product: ['SDWebImage', 'SDWebImage', null, null] },
2187
+ ],
2188
+ },
2189
+ ],
2190
+ })
2191
+ );
2192
+
2193
+ expect(result.ok.spmProductNames).toEqual(['SDWebImage', 'branchy', 'libavif']);
2194
+ });
2195
+
2196
+ it('counts a byName that names no target as a product it mirrored', () => {
2197
+ const result = emit(
2198
+ dumpWith({
2199
+ dependencies: [LIBAVIF],
2200
+ targetDeps: [{ byName: ['Helper', null] }, { byName: ['libavif', null] }],
2201
+ })
2202
+ );
2203
+
2204
+ expect(result.ok.spmProductNames).toEqual(['libavif']);
2205
+ });
2206
+
2207
+ // A path package's SwiftPM identity is its directory name, whatever `name:` calls it.
2208
+ it('occupies the identity of a path-based React package, not only its name', () => {
2209
+ const result = emit(
2210
+ dumpWith({
2211
+ dependencies: [remote('rn', 'https://github.com/acme/rn.git', { exact: ['1.0.0'] })],
2212
+ }),
2213
+ { packageRef: { name: 'ReactNative', path: '/abs/checkout/rn' }, products: [] }
2214
+ );
2215
+
2216
+ expect(result.refusal).toEqual({
2217
+ reason: 'unsupported-package-dependency',
2218
+ dependencies: [{ form: 'collides-with-injected', identity: 'rn', target: null }],
2219
+ });
2220
+ });
2221
+
2222
+ it('takes the identities the injected set occupies from the React descriptor', () => {
2223
+ const result = emit(
2224
+ dumpWith({
2225
+ dependencies: [
2226
+ remote('reactnative', 'https://github.com/acme/ReactNative.git', { exact: ['1.0.0'] }),
2227
+ ],
2228
+ }),
2229
+ {
2230
+ packageRef: { name: 'ReactNative', path: '/abs/rn' },
2231
+ products: [{ name: 'React', package: 'ReactNative' }],
2232
+ }
2233
+ );
2234
+
2235
+ expect(result.refusal).toEqual({
2236
+ reason: 'unsupported-package-dependency',
2237
+ dependencies: [{ form: 'collides-with-injected', identity: 'reactnative', target: null }],
2238
+ });
2239
+ });
2240
+ });
2241
+ });