expo 58.0.16 → 58.0.19

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.
@@ -7,12 +7,18 @@ const path = require('path');
7
7
 
8
8
  const {
9
9
  FLAVORS,
10
+ assertHeadersMatchSources,
10
11
  byteOrder,
12
+ hasPrecompiledArtifact,
13
+ headersXCFrameworkDirs,
11
14
  prepareCompileInterfaces,
12
15
  resolveFlavoredFramework,
16
+ resolveHeadersXCFramework,
17
+ resolveHeadersXCFrameworkWithSource,
13
18
  stableFrameworkId,
14
19
  validateFlavoredFramework,
15
20
  } = require('../flavored-frameworks');
21
+ const { thrownBy } = require('./helpers');
16
22
 
17
23
  // GNU tar reads the `C:` in a Windows path as a remote hostname and fails to connect.
18
24
  const itNotWindows = process.platform === 'win32' ? it.skip : it;
@@ -55,6 +61,52 @@ function declaration(frameworkName, debug, release, overrides = {}) {
55
61
  };
56
62
  }
57
63
 
64
+ describe('hasPrecompiledArtifact', () => {
65
+ const savedEnvPath = process.env.EXPO_PRECOMPILED_MODULES_PATH;
66
+ let moduleRoot;
67
+ const lookup = () =>
68
+ hasPrecompiledArtifact({
69
+ packageName: '@expo-spm-test/no-monorepo-build',
70
+ moduleRoot,
71
+ frameworkName: 'ExpoProbe',
72
+ });
73
+ const xcframeworksDir = (flavor) =>
74
+ path.join(moduleRoot, 'prebuilds', 'output', flavor, 'xcframeworks');
75
+
76
+ beforeEach(() => {
77
+ delete process.env.EXPO_PRECOMPILED_MODULES_PATH;
78
+ moduleRoot = fs.mkdtempSync(path.join(os.tmpdir(), 'has-artifact-'));
79
+ });
80
+
81
+ afterEach(() => {
82
+ fs.rmSync(moduleRoot, { recursive: true, force: true });
83
+ if (savedEnvPath === undefined) {
84
+ delete process.env.EXPO_PRECOMPILED_MODULES_PATH;
85
+ } else {
86
+ process.env.EXPO_PRECOMPILED_MODULES_PATH = savedEnvPath;
87
+ }
88
+ });
89
+
90
+ it('is false when no flavor of the framework exists', () => {
91
+ expect(lookup()).toBe(false);
92
+ });
93
+
94
+ it('is true for an xcframework of either flavor', () => {
95
+ fs.mkdirSync(path.join(xcframeworksDir('release'), 'ExpoProbe.xcframework'), {
96
+ recursive: true,
97
+ });
98
+ expect(lookup()).toBe(true);
99
+ });
100
+
101
+ // The pair is not validated or extracted: nothing is linked from it.
102
+ it('is true for a tarball, leaving it unextracted', () => {
103
+ fs.mkdirSync(xcframeworksDir('debug'), { recursive: true });
104
+ fs.writeFileSync(path.join(xcframeworksDir('debug'), 'ExpoProbe.tar.gz'), 'not a tarball');
105
+ expect(lookup()).toBe(true);
106
+ expect(fs.readdirSync(xcframeworksDir('debug'))).toEqual(['ExpoProbe.tar.gz']);
107
+ });
108
+ });
109
+
58
110
  describe('byteOrder', () => {
59
111
  // The compile-interface merge and the declaration order both run through it,
60
112
  // and a locale-aware comparison would order these the other way around.
@@ -326,6 +378,59 @@ describe('artifact preparation', () => {
326
378
  ).toThrow('is not part of an .xcframework');
327
379
  });
328
380
 
381
+ it('returns a headers xcframework directory where it lies', () => {
382
+ const headers = path.join(root, 'expo-modules-core', 'output', 'headers', 'xcframeworks');
383
+ const xcframework = makeXcframework(headers, 'ExpoModulesCoreHeaders', '.');
384
+
385
+ expect(
386
+ resolveHeadersXCFrameworkWithSource({
387
+ packageName: 'expo-modules-core',
388
+ moduleRoot: path.join(root, 'module'),
389
+ productName: 'ExpoModulesCore',
390
+ cacheDir: path.join(root, 'cache'),
391
+ })
392
+ ).toEqual({
393
+ xcframework,
394
+ source: { kind: 'env', dir: path.join(root, 'expo-modules-core', 'output') },
395
+ });
396
+ });
397
+
398
+ itNotWindows('expands a bundled headers tarball into the cache', () => {
399
+ const source = path.join(root, 'source');
400
+ makeXcframework(source, 'ExpoModulesCoreHeaders', 'headers');
401
+ const moduleRoot = path.join(root, 'module');
402
+ packTarball(
403
+ path.join(source, 'headers'),
404
+ path.join(
405
+ moduleRoot,
406
+ 'prebuilds',
407
+ 'output',
408
+ 'headers',
409
+ 'xcframeworks',
410
+ 'ExpoModulesCoreHeaders.tar.gz'
411
+ ),
412
+ ['ExpoModulesCoreHeaders.xcframework']
413
+ );
414
+
415
+ const result = resolveHeadersXCFrameworkWithSource({
416
+ packageName: 'expo-spm-headers-fixture',
417
+ moduleRoot,
418
+ productName: 'ExpoModulesCore',
419
+ cacheDir: path.join(root, 'cache'),
420
+ });
421
+ expect(result).toEqual({
422
+ xcframework: path.join(
423
+ root,
424
+ 'cache',
425
+ 'expo-modules-core-headers',
426
+ 'headers',
427
+ 'ExpoModulesCoreHeaders.xcframework'
428
+ ),
429
+ source: { kind: 'bundled', dir: path.join(moduleRoot, 'prebuilds', 'output') },
430
+ });
431
+ expect(fs.existsSync(path.join(result.xcframework, 'Info.plist'))).toBe(true);
432
+ });
433
+
329
434
  it('produces byte-identical compile interfaces regardless of declaration order', () => {
330
435
  const aDebug = makeXcframework(root, 'ExpoA', 'a-debug', 'a');
331
436
  const aRelease = makeXcframework(root, 'ExpoA', 'a-release', 'a');
@@ -348,3 +453,210 @@ describe('artifact preparation', () => {
348
453
  expect(second).toEqual(first);
349
454
  });
350
455
  });
456
+
457
+ describe('resolveHeadersXCFramework', () => {
458
+ let root;
459
+ let oldOverride;
460
+ let moduleRoot;
461
+
462
+ /** `<output>/headers/xcframeworks/ExpoPairHeaders.xcframework`, the layout the prebuild writes. */
463
+ const headersIn = (output) =>
464
+ makeXcframework(path.join(output, 'headers'), 'ExpoPairHeaders', 'xcframeworks');
465
+ const resolve = () =>
466
+ resolveHeadersXCFramework({
467
+ packageName: 'test-package',
468
+ moduleRoot,
469
+ productName: 'ExpoPair',
470
+ cacheDir: path.join(root, 'cache'),
471
+ });
472
+
473
+ beforeEach(() => {
474
+ root = fs.mkdtempSync(path.join(os.tmpdir(), 'expo-spm-headers-'));
475
+ moduleRoot = path.join(root, 'module');
476
+ oldOverride = process.env.EXPO_PRECOMPILED_MODULES_PATH;
477
+ process.env.EXPO_PRECOMPILED_MODULES_PATH = path.join(root, 'override');
478
+ });
479
+
480
+ afterEach(() => {
481
+ if (oldOverride == null) {
482
+ delete process.env.EXPO_PRECOMPILED_MODULES_PATH;
483
+ } else {
484
+ process.env.EXPO_PRECOMPILED_MODULES_PATH = oldOverride;
485
+ }
486
+ fs.rmSync(root, { recursive: true, force: true });
487
+ });
488
+
489
+ it('returns null when no lookup base has the headers', () => {
490
+ expect(resolve()).toBeNull();
491
+ });
492
+
493
+ it('names the directories it searches, in lookup order', () => {
494
+ expect(headersXCFrameworkDirs('test-package', moduleRoot)).toEqual([
495
+ path.join(root, 'override', 'test-package', 'output', 'headers', 'xcframeworks'),
496
+ path.resolve(
497
+ __dirname,
498
+ '..',
499
+ '..',
500
+ '..',
501
+ '..',
502
+ 'precompile',
503
+ '.build',
504
+ 'test-package',
505
+ 'output',
506
+ 'headers',
507
+ 'xcframeworks'
508
+ ),
509
+ path.join(moduleRoot, 'prebuilds', 'output', 'headers', 'xcframeworks'),
510
+ ]);
511
+ });
512
+
513
+ it('finds the headers the installed package ships under prebuilds/output', () => {
514
+ const shipped = headersIn(path.join(moduleRoot, 'prebuilds', 'output'));
515
+ expect(resolve()).toBe(shipped);
516
+ });
517
+
518
+ it('prefers EXPO_PRECOMPILED_MODULES_PATH over the installed package', () => {
519
+ headersIn(path.join(moduleRoot, 'prebuilds', 'output'));
520
+ const override = headersIn(path.join(root, 'override', 'test-package', 'output'));
521
+ expect(resolve()).toBe(override);
522
+ });
523
+
524
+ itNotWindows('expands a bundled tarball into the cache', () => {
525
+ const source = path.join(root, 'source');
526
+ headersIn(source);
527
+ packTarball(
528
+ path.join(source, 'headers', 'xcframeworks'),
529
+ path.join(
530
+ moduleRoot,
531
+ 'prebuilds',
532
+ 'output',
533
+ 'headers',
534
+ 'xcframeworks',
535
+ 'ExpoPairHeaders.tar.gz'
536
+ ),
537
+ ['ExpoPairHeaders.xcframework']
538
+ );
539
+
540
+ const resolved = resolve();
541
+ expect(resolved).toBe(
542
+ path.join(root, 'cache', 'expo-pair-headers', 'headers', 'ExpoPairHeaders.xcframework')
543
+ );
544
+ expect(fs.existsSync(path.join(resolved, 'Info.plist'))).toBe(true);
545
+ });
546
+
547
+ const rebuildHint =
548
+ 'Reinstall test-package, or from the Expo repository root run `node tools/bin/expotools.js prebuild test-package`. Then run `node node_modules/react-native/scripts/setup-apple-spm.js update` from your app directory again.';
549
+
550
+ it('rejects an expanded XCFramework with no Info.plist', () => {
551
+ const shipped = headersIn(path.join(moduleRoot, 'prebuilds', 'output'));
552
+ fs.rmSync(path.join(shipped, 'Info.plist'));
553
+ expect(resolve).toThrow(`${shipped} has no Info.plist`);
554
+ expect(resolve).toThrow('its build or its extraction did not finish');
555
+ expect(resolve).toThrow(rebuildHint);
556
+ });
557
+
558
+ itNotWindows('rejects a tarball whose XCFramework has no Info.plist', () => {
559
+ const source = path.join(root, 'source');
560
+ fs.rmSync(path.join(headersIn(source), 'Info.plist'));
561
+ const tarball = packTarball(
562
+ path.join(source, 'headers', 'xcframeworks'),
563
+ path.join(
564
+ moduleRoot,
565
+ 'prebuilds',
566
+ 'output',
567
+ 'headers',
568
+ 'xcframeworks',
569
+ 'ExpoPairHeaders.tar.gz'
570
+ ),
571
+ ['ExpoPairHeaders.xcframework']
572
+ );
573
+
574
+ expect(resolve).toThrow(`${tarball} holds ExpoPairHeaders.xcframework with no Info.plist`);
575
+ expect(resolve).toThrow('its build or its extraction did not finish');
576
+ expect(resolve).toThrow(rebuildHint);
577
+ });
578
+ });
579
+
580
+ describe('assertHeadersMatchSources', () => {
581
+ let root;
582
+ let headers;
583
+
584
+ const writeJson = (file, value) => {
585
+ fs.mkdirSync(path.dirname(file), { recursive: true });
586
+ fs.writeFileSync(file, JSON.stringify(value));
587
+ };
588
+ const stampHeaders = (version) =>
589
+ writeJson(path.join(headers, 'expo-package.json'), { name: 'test-package', version });
590
+ const installed = (name, version) => {
591
+ const dir = path.join(root, name);
592
+ writeJson(path.join(dir, 'package.json'), { name: 'test-package', version });
593
+ return dir;
594
+ };
595
+ const check = (sourceRoots) =>
596
+ assertHeadersMatchSources(headers, {
597
+ packageName: 'test-package',
598
+ productName: 'ExpoPair',
599
+ sourceRoots,
600
+ });
601
+
602
+ beforeEach(() => {
603
+ root = fs.mkdtempSync(path.join(os.tmpdir(), 'expo-spm-headers-version-'));
604
+ headers = path.join(root, 'ExpoPairHeaders.xcframework');
605
+ fs.mkdirSync(headers);
606
+ });
607
+
608
+ afterEach(() => {
609
+ fs.rmSync(root, { recursive: true, force: true });
610
+ });
611
+
612
+ // Headers published before the stamp existed carry none.
613
+ it('accepts headers without a version stamp', () => {
614
+ expect(() => check([installed('module', '1.0.0')])).not.toThrow();
615
+ });
616
+
617
+ it('accepts headers of the same version as every source', () => {
618
+ stampHeaders('1.0.0');
619
+ expect(() => check([installed('module', '1.0.0'), installed('built', '1.0.0')])).not.toThrow();
620
+ });
621
+
622
+ it('rejects headers of another version, naming both versions, both paths, why and how', () => {
623
+ stampHeaders('2.0.0');
624
+ const moduleRoot = installed('module', '1.0.0');
625
+ const { message } = thrownBy(() => check([moduleRoot]));
626
+ for (const part of [headers, '2.0.0', moduleRoot, '1.0.0']) {
627
+ expect(message).toContain(part);
628
+ }
629
+ expect(message).toContain('"Build ExpoPair" phase builds the framework from the installed');
630
+ expect(message).toContain('et prebuild test-package');
631
+ expect(message).toContain('EXPO_PRECOMPILED_MODULES_PATH');
632
+ });
633
+
634
+ it('rejects headers that differ from any one source', () => {
635
+ stampHeaders('1.0.0');
636
+ const built = installed('built', '1.1.0');
637
+ expect(() => check([installed('module', '1.0.0'), built])).toThrow(built);
638
+ });
639
+
640
+ it('names a stamp it cannot parse instead of surfacing the JSON error', () => {
641
+ const stampPath = path.join(headers, 'expo-package.json');
642
+ fs.writeFileSync(stampPath, '{ not json');
643
+ const { message } = thrownBy(() => check([installed('module', '1.0.0')]));
644
+ expect(message).toContain(`[expo-spm-plugin] ${stampPath}`);
645
+ expect(message).toContain('et prebuild test-package');
646
+ expect(message).not.toMatch(/SyntaxError|Unexpected token/);
647
+ });
648
+
649
+ it('names a stamp without a version', () => {
650
+ const stampPath = path.join(headers, 'expo-package.json');
651
+ writeJson(stampPath, { name: 'test-package' });
652
+ expect(() => check([installed('module', '1.0.0')])).toThrow(`[expo-spm-plugin] ${stampPath}`);
653
+ });
654
+
655
+ it('names an installed package.json without a version', () => {
656
+ stampHeaders('1.0.0');
657
+ const moduleRoot = installed('module', undefined);
658
+ const { message } = thrownBy(() => check([moduleRoot]));
659
+ expect(message).toContain(`[expo-spm-plugin] ${path.join(moduleRoot, 'package.json')}`);
660
+ expect(message).not.toContain('undefined');
661
+ });
662
+ });
@@ -4,6 +4,8 @@ const fs = require('fs');
4
4
  const os = require('os');
5
5
  const path = require('path');
6
6
 
7
+ const { spmUpdateCommand } = require('../commands');
8
+
7
9
  /** A podspec with the given body lines. */
8
10
  const spec = (...body) => ['Pod::Spec.new do |s|', ...body, 'end', ''].join('\n');
9
11
 
@@ -14,6 +16,9 @@ const metadataEntry = (packageRoot, productName, fields = {}) => ({
14
16
  ...fields,
15
17
  });
16
18
 
19
+ /** How an error asks the user to update the app's packages; Expo apps have no `react-native` CLI. */
20
+ const rerunSpmUpdate = `Then run \`${spmUpdateCommand()}\` from your app directory again.`;
21
+
17
22
  const tempDirs = [];
18
23
 
19
24
  /** A new directory under the OS temp dir, removed by `removeTempDirs`. */
@@ -62,6 +67,9 @@ function runPlugin(tmp, context = {}) {
62
67
  outputDir: path.join(tmp, 'out'),
63
68
  appRoot: path.join(tmp, 'app', 'ios'),
64
69
  projectRoot: path.join(tmp, 'app'),
70
+ // Fixtures that link real packages would otherwise resolve the repository's react-native, and
71
+ // the update command in every error would name that path.
72
+ reactNativeRoot: path.join(tmp, 'app', 'node_modules', 'react-native'),
65
73
  ...context,
66
74
  });
67
75
  }
@@ -82,6 +90,7 @@ module.exports = {
82
90
  metadataEntry,
83
91
  printed,
84
92
  removeTempDirs,
93
+ rerunSpmUpdate,
85
94
  runPlugin,
86
95
  spec,
87
96
  thrownBy,
@@ -4,15 +4,13 @@ const fs = require('fs');
4
4
  const os = require('os');
5
5
  const path = require('path');
6
6
 
7
- jest.mock('../cli', () => ({ runDumpPackage: jest.fn() }));
8
- const { runDumpPackage } = require('../cli');
9
-
10
7
  const {
11
8
  parseDumpedManifest,
12
9
  renderSourceManifest,
13
10
  pureSwiftManifest,
14
11
  emitSourceManifestPackage,
15
12
  emitPureSwiftSourcePackage,
13
+ emitExpoModulesJSIHeadersPackage,
16
14
  raiseFloor,
17
15
  spmPackageIdentity,
18
16
  documentedPackage,
@@ -270,18 +268,15 @@ describe('macro plugin flags', () => {
270
268
  });
271
269
 
272
270
  it('carries the flags through emitSourceManifestPackage', () => {
273
- runDumpPackage.mockReturnValue(
271
+ emitSourceManifestPackage(
272
+ moduleRoot,
273
+ { frameworkSearchPath: '/abs/interfaces', outDir, macroFlags: MACRO_FLAGS },
274
274
  JSON.stringify({
275
275
  name: 'TestModule',
276
276
  products: [{ name: 'TestModule', type: { library: ['automatic'] }, targets: ['Main'] }],
277
277
  targets: [{ name: 'Main', type: 'regular', path: 'Main', dependencies: [] }],
278
278
  })
279
279
  );
280
- emitSourceManifestPackage(moduleRoot, {
281
- frameworkSearchPath: '/abs/interfaces',
282
- outDir,
283
- macroFlags: MACRO_FLAGS,
284
- });
285
280
 
286
281
  expect(
287
282
  fs.readFileSync(path.join(outDir, 'expo-source', 'TestModule', 'Package.swift'), 'utf8')
@@ -349,8 +344,8 @@ describe('implicit target source paths', () => {
349
344
  fs.mkdirSync(outDir, { recursive: true });
350
345
  });
351
346
 
352
- const emit = () =>
353
- emitSourceManifestPackage(moduleRoot, { frameworkSearchPath: '/abs/interfaces', outDir });
347
+ const emit = (dump) =>
348
+ emitSourceManifestPackage(moduleRoot, { frameworkSearchPath: '/abs/interfaces', outDir }, dump);
354
349
  const emittedManifest = () =>
355
350
  fs.readFileSync(path.join(outDir, 'expo-source', 'TestModule', 'Package.swift'), 'utf8');
356
351
 
@@ -360,9 +355,8 @@ describe('implicit target source paths', () => {
360
355
 
361
356
  it('resolves a target with no explicit path to its predefined source directory', () => {
362
357
  fs.mkdirSync(path.join(moduleRoot, 'Sources', 'Example'), { recursive: true });
363
- runDumpPackage.mockReturnValue(dumpWithoutPath);
364
358
 
365
- expect(emit().ok.packageDep).toEqual({
359
+ expect(emit(dumpWithoutPath).ok.packageDep).toEqual({
366
360
  name: 'TestModule',
367
361
  path: path.join(outDir, 'expo-source', 'TestModule'),
368
362
  });
@@ -370,20 +364,18 @@ describe('implicit target source paths', () => {
370
364
  });
371
365
 
372
366
  it('leaves an explicit path untouched', () => {
373
- runDumpPackage.mockReturnValue(
367
+ emit(
374
368
  JSON.stringify({
375
369
  name: 'TestModule',
376
370
  products: [{ name: 'TestModule', type: { library: ['automatic'] }, targets: ['Example'] }],
377
371
  targets: [{ name: 'Example', type: 'regular', path: 'ios/Example', dependencies: [] }],
378
372
  })
379
373
  );
380
- emit();
381
374
  expect(emittedManifest()).toContain('path: "root/ios/Example"');
382
375
  });
383
376
 
384
377
  it('skips the module and names the unresolved targets instead of emitting root/undefined', () => {
385
- runDumpPackage.mockReturnValue(dumpWithoutPath);
386
- const result = emit();
378
+ const result = emit(dumpWithoutPath);
387
379
 
388
380
  expect(result.ok).toBeUndefined();
389
381
  expect(result.refusal).toEqual({
@@ -539,14 +531,17 @@ describe('single-target packages with sources directly in a predefined directory
539
531
  fs.mkdirSync(path.dirname(target), { recursive: true });
540
532
  fs.writeFileSync(target, content);
541
533
  };
542
- const emit = () =>
543
- emitSourceManifestPackage(moduleRoot, { frameworkSearchPath: '/abs/interfaces', outDir });
534
+ const emit = (targetNames) =>
535
+ emitSourceManifestPackage(
536
+ moduleRoot,
537
+ { frameworkSearchPath: '/abs/interfaces', outDir },
538
+ dumpTargets(targetNames)
539
+ );
544
540
 
545
541
  it('resolves the only target to the bare predefined directory holding its sources', () => {
546
542
  write('Sources/File.swift');
547
- runDumpPackage.mockReturnValue(dumpTargets(['RootSrc']));
548
543
 
549
- expect(emit().refusal).toBeUndefined();
544
+ expect(emit(['RootSrc']).refusal).toBeUndefined();
550
545
  expect(
551
546
  fs.readFileSync(path.join(outDir, 'expo-source', 'TestModule', 'Package.swift'), 'utf8')
552
547
  ).toContain('path: "root/Sources"');
@@ -555,9 +550,8 @@ describe('single-target packages with sources directly in a predefined directory
555
550
  it('prefers Sources/<target name> over the bare directory', () => {
556
551
  write('Sources/File.swift');
557
552
  write('Sources/RootSrc/File.swift');
558
- runDumpPackage.mockReturnValue(dumpTargets(['RootSrc']));
559
553
 
560
- emit();
554
+ emit(['RootSrc']);
561
555
  expect(
562
556
  fs.readFileSync(path.join(outDir, 'expo-source', 'TestModule', 'Package.swift'), 'utf8')
563
557
  ).toContain('path: "root/Sources/RootSrc"');
@@ -565,16 +559,17 @@ describe('single-target packages with sources directly in a predefined directory
565
559
 
566
560
  it('never resolves the targets of a multi-target package to the shared bare directory', () => {
567
561
  write('Sources/File.swift');
568
- runDumpPackage.mockReturnValue(dumpTargets(['A', 'B']));
569
562
 
570
- expect(emit().refusal).toEqual({ reason: 'unresolvable-target-path', targetNames: ['A', 'B'] });
563
+ expect(emit(['A', 'B']).refusal).toEqual({
564
+ reason: 'unresolvable-target-path',
565
+ targetNames: ['A', 'B'],
566
+ });
571
567
  });
572
568
 
573
569
  it('accepts a predefined directory whose sources are nested below it', () => {
574
570
  write('Sources/Nested/File.swift');
575
- runDumpPackage.mockReturnValue(dumpTargets(['RootSrc']));
576
571
 
577
- expect(emit().refusal).toBeUndefined();
572
+ expect(emit(['RootSrc']).refusal).toBeUndefined();
578
573
  expect(
579
574
  fs.readFileSync(path.join(outDir, 'expo-source', 'TestModule', 'Package.swift'), 'utf8')
580
575
  ).toContain('path: "root/Sources"');
@@ -582,9 +577,8 @@ describe('single-target packages with sources directly in a predefined directory
582
577
 
583
578
  it('ignores a predefined directory with no source files at any depth', () => {
584
579
  write('Sources/Nested/README.md', '# docs\n');
585
- runDumpPackage.mockReturnValue(dumpTargets(['RootSrc']));
586
580
 
587
- expect(emit().refusal).toEqual({
581
+ expect(emit(['RootSrc']).refusal).toEqual({
588
582
  reason: 'unresolvable-target-path',
589
583
  targetNames: ['RootSrc'],
590
584
  });
@@ -1089,12 +1083,11 @@ describe('the minimum floor a checked-in manifest is raised to', () => {
1089
1083
  });
1090
1084
 
1091
1085
  const emitted = (declared, minimum) => {
1092
- runDumpPackage.mockReturnValue(dumpWithIos(declared));
1093
- emitSourceManifestPackage(moduleRoot, {
1094
- frameworkSearchPath: '/abs/interfaces',
1095
- outDir,
1096
- minimumIosDeploymentTarget: minimum,
1097
- });
1086
+ emitSourceManifestPackage(
1087
+ moduleRoot,
1088
+ { frameworkSearchPath: '/abs/interfaces', outDir, minimumIosDeploymentTarget: minimum },
1089
+ dumpWithIos(declared)
1090
+ );
1098
1091
  return fs.readFileSync(path.join(outDir, 'expo-source', 'TestModule', 'Package.swift'), 'utf8');
1099
1092
  };
1100
1093
 
@@ -1218,12 +1211,11 @@ describe('dependencies on targets the generated package cannot declare', () => {
1218
1211
  const moduleRoot = path.join(tmp, 'module');
1219
1212
  const outDir = path.join(tmp, 'out');
1220
1213
  fs.mkdirSync(path.join(moduleRoot, 'ios', 'Src'), { recursive: true });
1221
- runDumpPackage.mockReturnValue(dumpWithBinaryTarget);
1222
-
1223
- const result = emitSourceManifestPackage(moduleRoot, {
1224
- frameworkSearchPath: '/abs/interfaces',
1225
- outDir,
1226
- });
1214
+ const result = emitSourceManifestPackage(
1215
+ moduleRoot,
1216
+ { frameworkSearchPath: '/abs/interfaces', outDir },
1217
+ dumpWithBinaryTarget
1218
+ );
1227
1219
 
1228
1220
  expect(result.ok).toBeUndefined();
1229
1221
  expect(result.refusal).toEqual({
@@ -1893,15 +1885,12 @@ let package = Package(
1893
1885
  const emittedManifestPath = () =>
1894
1886
  path.join(outDir, 'expo-source', 'TestModule', 'Package.swift');
1895
1887
  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
- };
1888
+ const emit = (dump, react, satisfiedDependencies) =>
1889
+ emitSourceManifestPackage(
1890
+ moduleRoot,
1891
+ { react, frameworkSearchPath: '/abs/interfaces', outDir, satisfiedDependencies },
1892
+ dump
1893
+ );
1905
1894
 
1906
1895
  // A package can export several products; only the ones a precompiled framework
1907
1896
  // provides go, and the package stays while anything still depends on it.
@@ -2239,3 +2228,106 @@ let package = Package(
2239
2228
  });
2240
2229
  });
2241
2230
  });
2231
+
2232
+ describe('emitExpoModulesJSIHeadersPackage', () => {
2233
+ let tmp;
2234
+ let outDir;
2235
+
2236
+ const xcframeworkAt = (name) => {
2237
+ const xcframework = path.join(tmp, name, 'ExpoModulesJSIHeaders.xcframework');
2238
+ fs.mkdirSync(xcframework, { recursive: true });
2239
+ fs.writeFileSync(path.join(xcframework, 'Info.plist'), '<plist/>');
2240
+ return xcframework;
2241
+ };
2242
+
2243
+ beforeEach(() => {
2244
+ tmp = fs.mkdtempSync(path.join(os.tmpdir(), 'expo-spm-jsi-headers-'));
2245
+ outDir = path.join(tmp, 'out');
2246
+ });
2247
+
2248
+ afterEach(() => {
2249
+ fs.rmSync(tmp, { recursive: true, force: true });
2250
+ });
2251
+
2252
+ it('declares the headers as a binary target beside a target that links the real framework', () => {
2253
+ const headers = xcframeworkAt('npm');
2254
+ const pkgDir = emitExpoModulesJSIHeadersPackage(headers, outDir);
2255
+
2256
+ expect(pkgDir).toBe(path.join(outDir, 'ExpoModulesJSIHeaders'));
2257
+ const manifest = fs.readFileSync(path.join(pkgDir, 'Package.swift'), 'utf8');
2258
+ expect(manifest).toContain('name: "ExpoModulesJSIHeaders"');
2259
+ expect(manifest).toContain(
2260
+ '.library(name: "ExpoModulesJSIHeaders", targets: ["ExpoModulesJSIHeaders", "ExpoModulesJSILink"])'
2261
+ );
2262
+ expect(manifest).toContain(
2263
+ '.binaryTarget(name: "ExpoModulesJSIHeaders", path: "ExpoModulesJSIHeaders.xcframework")'
2264
+ );
2265
+ expect(manifest).toMatch(
2266
+ /\.target\(\s*name: "ExpoModulesJSILink",\s*path: "ExpoModulesJSILink",\s*linkerSettings: \[\.linkedFramework\("ExpoModulesJSI"\)\]\s*\)/
2267
+ );
2268
+ expect(fs.readlinkSync(path.join(pkgDir, 'ExpoModulesJSIHeaders.xcframework'))).toBe(headers);
2269
+ expect(
2270
+ fs.readFileSync(path.join(pkgDir, 'ExpoModulesJSILink', 'ExpoModulesJSILink.swift'), 'utf8')
2271
+ ).toBe('');
2272
+ });
2273
+
2274
+ it('replaces the previous emission on a re-run, leaving no stale files', () => {
2275
+ emitExpoModulesJSIHeadersPackage(xcframeworkAt('first'), outDir);
2276
+ const pkgDir = path.join(outDir, 'ExpoModulesJSIHeaders');
2277
+ fs.writeFileSync(path.join(pkgDir, 'stale.txt'), 'left by an older plugin');
2278
+ const second = xcframeworkAt('second');
2279
+
2280
+ emitExpoModulesJSIHeadersPackage(second, outDir);
2281
+
2282
+ expect(fs.readlinkSync(path.join(pkgDir, 'ExpoModulesJSIHeaders.xcframework'))).toBe(second);
2283
+ expect(fs.readdirSync(pkgDir).sort()).toEqual([
2284
+ 'ExpoModulesJSIHeaders.xcframework',
2285
+ 'ExpoModulesJSILink',
2286
+ 'Package.swift',
2287
+ ]);
2288
+ // The old symlink target is untouched: removing the link must not follow it.
2289
+ expect(
2290
+ fs.existsSync(path.join(tmp, 'first', 'ExpoModulesJSIHeaders.xcframework', 'Info.plist'))
2291
+ ).toBe(true);
2292
+ });
2293
+ });
2294
+
2295
+ describe('the ExpoModulesJSIHeaders dependency of emitted source packages', () => {
2296
+ let tmp;
2297
+ let moduleRoot;
2298
+ let outDir;
2299
+
2300
+ const emitted = (emitContext) => {
2301
+ emitPureSwiftSourcePackage(
2302
+ { moduleRoot, product: 'ExpoAsset' },
2303
+ { frameworkSearchPath: '/abs/interfaces', outDir, ...emitContext }
2304
+ );
2305
+ return fs.readFileSync(path.join(outDir, 'expo-source', 'ExpoAsset', 'Package.swift'), 'utf8');
2306
+ };
2307
+
2308
+ beforeEach(() => {
2309
+ tmp = fs.mkdtempSync(path.join(os.tmpdir(), 'expo-spm-jsi-dep-'));
2310
+ moduleRoot = path.join(tmp, 'module');
2311
+ outDir = path.join(tmp, 'out');
2312
+ fs.mkdirSync(path.join(moduleRoot, 'ios'), { recursive: true });
2313
+ fs.writeFileSync(path.join(moduleRoot, 'ios', 'A.swift'), '// swift\n');
2314
+ });
2315
+
2316
+ afterEach(() => {
2317
+ fs.rmSync(tmp, { recursive: true, force: true });
2318
+ });
2319
+
2320
+ it('is declared on the package and every target when the headers package exists', () => {
2321
+ const manifest = emitted({ jsiHeadersPkgPath: '/abs/out/ExpoModulesJSIHeaders' });
2322
+ expect(manifest).toContain(
2323
+ '.package(name: "ExpoModulesJSIHeaders", path: "/abs/out/ExpoModulesJSIHeaders")'
2324
+ );
2325
+ expect(manifest).toContain(
2326
+ '.product(name: "ExpoModulesJSIHeaders", package: "ExpoModulesJSIHeaders")'
2327
+ );
2328
+ });
2329
+
2330
+ it('is absent when there is no headers package', () => {
2331
+ expect(emitted({})).not.toContain('ExpoModulesJSIHeaders');
2332
+ });
2333
+ });