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.
@@ -27,7 +27,14 @@ jest.mock('../flavored-frameworks', () => ({
27
27
  frameworkName === 'ExpoModulesCore' ? { id: 'ExpoModulesCore', name: 'ExpoModulesCore' } : null
28
28
  ),
29
29
  resolveSpmDependencyFrameworks: jest.fn(() => []),
30
+ hasPrecompiledArtifact: jest.fn(() => false),
31
+ resolveHeadersXCFramework: jest.fn(() => null),
30
32
  prepareCompileInterfaces: jest.fn(() => '/abs/interfaces'),
33
+ frameworkSource: jest.fn(() => null),
34
+ resolveHeadersXCFrameworkWithSource: jest.fn(({ productName }) => ({
35
+ xcframework: `/abs/${productName}Headers.xcframework`,
36
+ source: null,
37
+ })),
31
38
  }));
32
39
  // The module-root walk stays real; it is spied on so a test can assert that a
33
40
  // root React Native already resolved made the walk unnecessary.
@@ -41,6 +48,11 @@ jest.mock('../manifests', () => {
41
48
  const actual = jest.requireActual('../manifests');
42
49
  return { ...actual, emitPureSwiftSourcePackage: jest.fn(actual.emitPureSwiftSourcePackage) };
43
50
  });
51
+ // The real direct emitter builds a compile-only xcframework with xcrun.
52
+ jest.mock('../direct', () => ({
53
+ ...jest.requireActual('../direct'),
54
+ emitDirectPackage: jest.fn(),
55
+ }));
44
56
 
45
57
  const {
46
58
  resolveExpoModules,
@@ -50,13 +62,19 @@ const {
50
62
  } = require('../cli');
51
63
  const { resolveAppTarget } = require('../app-target');
52
64
  const { findModuleRoot } = require('../classify');
53
- const { UnsupportedModulesError } = require('../diagnostics');
65
+ const { spmUpdateCommand } = require('../commands');
66
+ const { UnsupportedModulesError, renderBuildFromSourceFallbackWarning } = require('../diagnostics');
67
+ const { emitDirectPackage } = require('../direct');
54
68
  const { emitPureSwiftSourcePackage } = require('../manifests');
55
69
  const {
56
70
  artifactBaseDirs,
71
+ frameworkSource,
57
72
  prepareCompileInterfaces,
58
73
  resolveFlavoredFramework,
74
+ resolveHeadersXCFramework,
75
+ resolveHeadersXCFrameworkWithSource,
59
76
  resolveSpmDependencyFrameworks,
77
+ hasPrecompiledArtifact,
60
78
  } = require('../flavored-frameworks');
61
79
  const {
62
80
  captureConsole,
@@ -64,6 +82,7 @@ const {
64
82
  metadataEntry,
65
83
  printed,
66
84
  removeTempDirs,
85
+ rerunSpmUpdate,
67
86
  runPlugin,
68
87
  spec,
69
88
  thrownBy,
@@ -93,6 +112,36 @@ function pureSwiftModule(root, podName, podspec) {
93
112
  return podspecDir;
94
113
  }
95
114
 
115
+ /** Writes `spm.config.json` at a module root: an object as JSON, or raw text. */
116
+ function writeSpmConfig(root, config) {
117
+ fs.writeFileSync(
118
+ path.join(root, 'spm.config.json'),
119
+ typeof config === 'string' ? config : JSON.stringify(config)
120
+ );
121
+ }
122
+
123
+ /**
124
+ * `swift package dump-package` JSON for a checked-in manifest exporting `product`, whose
125
+ * target depends on the ExpoModulesCoreHeaders product when `onCoreHeaders` is set.
126
+ */
127
+ function dumpedManifest(name, product, { onCoreHeaders }) {
128
+ return JSON.stringify({
129
+ name,
130
+ dependencies: onCoreHeaders ? [{ fileSystem: [{ identity: 'expomodulescoreheaders' }] }] : [],
131
+ products: [{ name: product, type: { library: ['automatic'] }, targets: [product] }],
132
+ targets: [
133
+ {
134
+ name: product,
135
+ type: 'regular',
136
+ path: 'ios',
137
+ dependencies: onCoreHeaders
138
+ ? [{ product: ['ExpoModulesCoreHeaders', 'ExpoModulesCoreHeaders', null, null] }]
139
+ : [],
140
+ },
141
+ ],
142
+ });
143
+ }
144
+
96
145
  /** A module SwiftPM cannot build from source: ObjC++ sources and no manifest. */
97
146
  function mixedModule(root, podName) {
98
147
  const podspecDir = path.join(root, 'ios');
@@ -132,7 +181,16 @@ function restoreModuleMocks() {
132
181
  );
133
182
  resolveSpmDependencyFrameworks.mockReset();
134
183
  resolveSpmDependencyFrameworks.mockReturnValue([]);
184
+ hasPrecompiledArtifact.mockReset();
185
+ hasPrecompiledArtifact.mockReturnValue(false);
186
+ resolveHeadersXCFramework.mockReset();
187
+ resolveHeadersXCFramework.mockReturnValue(null);
135
188
  prepareCompileInterfaces.mockImplementation(() => '/abs/interfaces');
189
+ frameworkSource.mockImplementation(() => null);
190
+ resolveHeadersXCFrameworkWithSource.mockImplementation(({ productName }) => ({
191
+ xcframework: `/abs/${productName}Headers.xcframework`,
192
+ source: null,
193
+ }));
136
194
  }
137
195
 
138
196
  const barcodeGate = {
@@ -160,6 +218,16 @@ function withPodfileProperties(tmp, properties) {
160
218
  });
161
219
  }
162
220
 
221
+ /** The warnings naming modules a buildFromSource pattern matched that were linked precompiled. */
222
+ const fallbackWarnings = (logs) =>
223
+ logs.warn.mock.calls.map(([text]) => text).filter((text) => text.includes('buildFromSource'));
224
+
225
+ const coreFallback = (entry) => ({
226
+ podName: 'ExpoModulesCore',
227
+ packageName: 'expo-modules-core',
228
+ entry,
229
+ });
230
+
163
231
  /** The arguments the framework resolver was called with for one package. */
164
232
  const resolvedFor = (packageName) =>
165
233
  resolveFlavoredFramework.mock.calls
@@ -319,10 +387,46 @@ describe('the module registry', () => {
319
387
 
320
388
  expect(run).toThrow(/ExpoModulesProvider\.swift/);
321
389
  expect(run).toThrow(/expo-modules-autolinking exited with code 1/);
322
- expect(run).toThrow(/react-native spm/);
390
+ expect(run).toThrow(spmUpdateCommand());
323
391
  expect(printed(logs.warn)).not.toContain('ExpoModulesProvider');
324
392
  });
325
393
 
394
+ // Workspaces hoist react-native above the app, where node_modules/react-native is missing.
395
+ it("names the update command through the app's react-native, relative to the app root", () => {
396
+ generateModulesProvider.mockImplementation(() => {
397
+ throw new Error('expo-modules-autolinking exited with code 1');
398
+ });
399
+ const hoistedApp = () =>
400
+ runPlugin(tmp, {
401
+ projectRoot: path.join(tmp, 'apps', 'mobile'),
402
+ appRoot: path.join(tmp, 'apps', 'mobile', 'ios'),
403
+ reactNativeRoot: path.join(tmp, 'node_modules', 'react-native'),
404
+ });
405
+
406
+ expect(hoistedApp).toThrow(
407
+ '`node ../../node_modules/react-native/scripts/setup-apple-spm.js update`'
408
+ );
409
+ });
410
+
411
+ it('resolves a hoisted react-native from the app root when the context names none', () => {
412
+ generateModulesProvider.mockImplementation(() => {
413
+ throw new Error('expo-modules-autolinking exited with code 1');
414
+ });
415
+ const reactNativeRoot = path.join(tmp, 'node_modules', 'react-native');
416
+ fs.mkdirSync(reactNativeRoot, { recursive: true });
417
+ fs.writeFileSync(path.join(reactNativeRoot, 'package.json'), '{"name":"react-native"}');
418
+ const hoistedApp = () =>
419
+ runPlugin(tmp, {
420
+ projectRoot: path.join(tmp, 'apps', 'mobile'),
421
+ appRoot: path.join(tmp, 'apps', 'mobile', 'ios'),
422
+ reactNativeRoot: undefined,
423
+ });
424
+
425
+ expect(hoistedApp).toThrow(
426
+ '`node ../../node_modules/react-native/scripts/setup-apple-spm.js update`'
427
+ );
428
+ });
429
+
326
430
  it('fails the sync when generation writes no provider although modules resolved', () => {
327
431
  generateModulesProvider.mockReturnValue(null);
328
432
 
@@ -490,6 +594,7 @@ describe('the watched module roots', () => {
490
594
  fs.mkdirSync(packageRoot, { recursive: true });
491
595
  fs.writeFileSync(path.join(packageRoot, 'package.json'), '{"name":"expo-modules-core"}');
492
596
  fs.writeFileSync(path.join(packageRoot, 'expo-module.config.json'), '{}');
597
+ writeSpmConfig(packageRoot, {});
493
598
  resolveExpoModules.mockReturnValue(modulesOf([coreAt(podspecDir)]));
494
599
  prebuiltMetadata.mockReturnValue({
495
600
  ExpoModulesCore: metadataEntry(packageRoot, 'ExpoModulesCore'),
@@ -503,6 +608,11 @@ describe('the watched module roots', () => {
503
608
  it('watches the staleness inputs under the documented package root', () => {
504
609
  expect(watchPaths).toContain(path.join(packageRoot, 'expo-module.config.json'));
505
610
  });
611
+
612
+ // It declares the products the plugin links precompiled.
613
+ it('watches spm.config.json', () => {
614
+ expect(watchPaths).toContain(path.join(packageRoot, 'spm.config.json'));
615
+ });
506
616
  });
507
617
 
508
618
  // The product name has to reach the artifact declaration, not just the resolver
@@ -872,34 +982,805 @@ describe('a package whose first pod alone is precompiled', () => {
872
982
 
873
983
  afterAll(restoreModuleMocks);
874
984
 
875
- // The sibling pod is buildable neither way, so the sync fails on it — as it did
876
- // before this change. The warning is what must not double.
877
- it('fails only on the sibling pod SwiftPM cannot build', () => {
878
- expect(thrown).toBeInstanceOf(UnsupportedModulesError);
879
- expect(thrown.unsupported).toEqual([expect.objectContaining({ podName: 'ExpoMultiHelper' })]);
985
+ // The sibling pod is buildable neither way, so the sync fails on it — as it did
986
+ // before this change. The warning is what must not double.
987
+ it('fails only on the sibling pod SwiftPM cannot build', () => {
988
+ expect(thrown).toBeInstanceOf(UnsupportedModulesError);
989
+ expect(thrown.unsupported).toEqual([expect.objectContaining({ podName: 'ExpoMultiHelper' })]);
990
+ });
991
+
992
+ it('warns about its unmapped dependencies once, not once per pass', () => {
993
+ const report = printed(logs.warn);
994
+ expect(report.match(/warning: Expo module "expo-multi"/g)).toHaveLength(1);
995
+ });
996
+ });
997
+
998
+ describe('the checked-in manifest branch', () => {
999
+ const logs = captureConsole();
1000
+ let outDir;
1001
+ let thrown;
1002
+
1003
+ beforeAll(() => {
1004
+ const tmp = makeTempDir('expo-spm-plugin-manifest-');
1005
+ outDir = path.join(tmp, 'out');
1006
+ const core = pureSwiftModule(path.join(tmp, 'expo-modules-core'), 'ExpoModulesCore', spec());
1007
+ const vendored = path.join(tmp, 'expo-vendored');
1008
+ const vendoredPodspecDir = pureSwiftModule(vendored, 'ExpoVendored', spec());
1009
+ fs.writeFileSync(
1010
+ path.join(vendored, 'Package.swift'),
1011
+ '// swift-tools-version: 6.0\n// checked in by the module\n'
1012
+ );
1013
+ runDumpPackage.mockReturnValue(
1014
+ JSON.stringify({
1015
+ name: 'ExpoVendored',
1016
+ products: [
1017
+ { name: 'ExpoVendored', type: { library: ['automatic'] }, targets: ['ExpoVendored'] },
1018
+ ],
1019
+ targets: [
1020
+ {
1021
+ name: 'ExpoVendored',
1022
+ type: 'regular',
1023
+ path: 'ios',
1024
+ dependencies: [{ byName: ['VendoredKit', null] }],
1025
+ },
1026
+ { name: 'VendoredKit', type: 'binary', path: 'ios/VendoredKit.xcframework' },
1027
+ ],
1028
+ })
1029
+ );
1030
+ resolveExpoModules.mockReturnValue(
1031
+ modulesOf([coreAt(core), ['expo-vendored', [['ExpoVendored', vendoredPodspecDir]]]])
1032
+ );
1033
+ thrown = thrownBy(() => runPlugin(tmp));
1034
+ });
1035
+
1036
+ it('fails the sync for a manifest depending on a target it cannot declare', () => {
1037
+ expect(thrown).toBeInstanceOf(UnsupportedModulesError);
1038
+ expect(thrown.unsupported).toEqual([
1039
+ expect.objectContaining({
1040
+ reason: 'unsupported-target-dependency',
1041
+ podName: 'ExpoVendored',
1042
+ dependencies: [{ target: 'ExpoVendored', dependsOn: 'VendoredKit', kind: 'binary' }],
1043
+ }),
1044
+ ]);
1045
+ expect(printed(logs.error)).toContain(
1046
+ 'target "ExpoVendored" depends on "VendoredKit", a binary target'
1047
+ );
1048
+ });
1049
+
1050
+ it('emits no package for it', () => {
1051
+ expect(
1052
+ fs.existsSync(path.join(outDir, 'expo', 'expo-source', 'ExpoVendored', 'Package.swift'))
1053
+ ).toBe(false);
1054
+ });
1055
+ });
1056
+
1057
+ describe('a module with a checked-in manifest', () => {
1058
+ const logs = captureConsole({ each: true });
1059
+
1060
+ afterEach(() => {
1061
+ emitDirectPackage.mockReset();
1062
+ runDumpPackage.mockReset();
1063
+ restoreModuleMocks();
1064
+ });
1065
+
1066
+ /**
1067
+ * Syncs expo-haptics (pod ExpoHaptics) with a checked-in manifest that depends on the
1068
+ * ExpoModulesCore headers when `onCoreHeaders`, an artifact when `precompiled`, the app's
1069
+ * `buildFromSource` patterns, and `spmConfig` as its spm.config.json.
1070
+ */
1071
+ function sync({ onCoreHeaders, precompiled, buildFromSource, spmConfig }) {
1072
+ const tmp = makeTempDir('expo-spm-direct-rule-');
1073
+ const core = pureSwiftModule(path.join(tmp, 'expo-modules-core'), 'ExpoModulesCore', spec());
1074
+ const moduleRoot = path.join(tmp, 'expo-haptics');
1075
+ const podspecDir = pureSwiftModule(moduleRoot, 'ExpoHaptics', spec());
1076
+ fs.writeFileSync(path.join(moduleRoot, 'Package.swift'), '// swift-tools-version: 6.0\n');
1077
+ if (spmConfig != null) writeSpmConfig(moduleRoot, spmConfig);
1078
+ runDumpPackage.mockReturnValue(
1079
+ dumpedManifest('expo-haptics', 'ExpoHaptics', { onCoreHeaders })
1080
+ );
1081
+ resolveExpoModules.mockReturnValue({
1082
+ ...modulesOf([coreAt(core), ['expo-haptics', [['ExpoHaptics', podspecDir]]]]),
1083
+ ...(buildFromSource != null ? { buildFromSource } : {}),
1084
+ });
1085
+ resolveFlavoredFramework.mockImplementation(({ frameworkName }) =>
1086
+ frameworkName === 'ExpoModulesCore' || (precompiled && frameworkName === 'ExpoHaptics')
1087
+ ? { id: frameworkName, frameworkName }
1088
+ : null
1089
+ );
1090
+ emitDirectPackage.mockReturnValue({
1091
+ ok: {
1092
+ packageDep: { name: 'expo-haptics', path: moduleRoot },
1093
+ productDeps: [{ name: 'ExpoHaptics', package: 'expo-haptics' }],
1094
+ spmProductNames: [],
1095
+ partlyProvidedPackages: [],
1096
+ },
1097
+ });
1098
+ const outDir = path.join(tmp, 'out');
1099
+ providerWrittenTo(outDir);
1100
+ let result = null;
1101
+ const thrown = thrownBy(() => {
1102
+ result = runPlugin(tmp);
1103
+ });
1104
+ return {
1105
+ thrown,
1106
+ moduleRoot,
1107
+ generatedManifest: path.join(outDir, 'expo', 'expo-source', 'expo-haptics', 'Package.swift'),
1108
+ frameworks: result?.flavoredFrameworks.map((f) => f.frameworkName).sort(),
1109
+ };
1110
+ }
1111
+
1112
+ const linkedPrecompiled = ({ thrown, frameworks }) => {
1113
+ expect(thrown).toBeNull();
1114
+ expect(frameworks).toEqual(['ExpoHaptics', 'ExpoModulesCore']);
1115
+ expect(emitDirectPackage).not.toHaveBeenCalled();
1116
+ };
1117
+
1118
+ const builtDirect = ({ thrown, frameworks, moduleRoot }) => {
1119
+ expect(thrown).toBeNull();
1120
+ expect(frameworks).toEqual(['ExpoModulesCore']);
1121
+ expect(emitDirectPackage).toHaveBeenCalledTimes(1);
1122
+ expect(emitDirectPackage).toHaveBeenCalledWith(
1123
+ expect.objectContaining({
1124
+ moduleRoot,
1125
+ packageName: 'expo-haptics',
1126
+ manifest: expect.objectContaining({ name: 'expo-haptics' }),
1127
+ })
1128
+ );
1129
+ expect(printed(logs.log)).toContain('source via direct checked-in manifest (1): expo-haptics');
1130
+ };
1131
+
1132
+ it('links its artifact, though the manifest depends on the ExpoModulesCore headers', () => {
1133
+ linkedPrecompiled(sync({ onCoreHeaders: true, precompiled: true }));
1134
+ });
1135
+
1136
+ it('never evaluates the manifest of a module linked precompiled', () => {
1137
+ sync({ onCoreHeaders: true, precompiled: true });
1138
+ expect(runDumpPackage).not.toHaveBeenCalled();
1139
+ });
1140
+
1141
+ it('is built from a manifest that depends on the ExpoModulesCore headers when it has no artifact', () => {
1142
+ builtDirect(sync({ onCoreHeaders: true, precompiled: false }));
1143
+ });
1144
+
1145
+ it('is built from a generated package, though it has an artifact, when buildFromSource lists it and its manifest does not depend on the ExpoModulesCore headers', () => {
1146
+ const { thrown, frameworks, generatedManifest } = sync({
1147
+ onCoreHeaders: false,
1148
+ precompiled: true,
1149
+ buildFromSource: ['expo-haptics'],
1150
+ });
1151
+ expect(thrown).toBeNull();
1152
+ expect(frameworks).toEqual(['ExpoModulesCore']);
1153
+ expect(emitDirectPackage).not.toHaveBeenCalled();
1154
+ expect(fs.existsSync(generatedManifest)).toBe(true);
1155
+ expect(printed(logs.log)).toContain('source via checked-in manifest (1): expo-haptics');
1156
+ });
1157
+
1158
+ it('is built from a generated package when its manifest does not depend on the ExpoModulesCore headers', () => {
1159
+ const { thrown, generatedManifest } = sync({ onCoreHeaders: false, precompiled: false });
1160
+ expect(thrown).toBeNull();
1161
+ expect(emitDirectPackage).not.toHaveBeenCalled();
1162
+ expect(fs.existsSync(generatedManifest)).toBe(true);
1163
+ expect(printed(logs.log)).toContain('source via checked-in manifest (1): expo-haptics');
1164
+ expect(printed(logs.log)).toContain('source via direct checked-in manifest (0): —');
1165
+ });
1166
+
1167
+ it.each([
1168
+ ['as it stands', true],
1169
+ ['through a generated package', false],
1170
+ ])('evaluates its manifest once when it is built %s', (_, onCoreHeaders) => {
1171
+ sync({ onCoreHeaders, precompiled: false });
1172
+ expect(runDumpPackage).toHaveBeenCalledTimes(1);
1173
+ });
1174
+
1175
+ // CocoaPods matches each entry as `^entry$` against the pod name and the npm package name:
1176
+ // precompiled_modules.rb#build_from_source?.
1177
+ it.each([
1178
+ ['its pod name', ['ExpoHaptics']],
1179
+ ['its npm package name', ['expo-haptics']],
1180
+ ['a pattern matching its npm package name', ['expo-hap.*']],
1181
+ ['a pattern matching its pod name', ['Expo(Haptics|Camera)']],
1182
+ ['one of several entries', ['expo-camera', 'ExpoHap.*']],
1183
+ ])(
1184
+ 'is built from source, though it has an artifact, when buildFromSource lists %s',
1185
+ (_, buildFromSource) => {
1186
+ builtDirect(sync({ onCoreHeaders: true, precompiled: true, buildFromSource }));
1187
+ }
1188
+ );
1189
+
1190
+ it.each([['Haptics'], ['expo-hap'], ['Expo'], ['xExpoHaptics']])(
1191
+ 'links its artifact when buildFromSource lists %s, which matches only part of a name',
1192
+ (entry) => {
1193
+ linkedPrecompiled(sync({ onCoreHeaders: true, precompiled: true, buildFromSource: [entry] }));
1194
+ }
1195
+ );
1196
+
1197
+ it('fails the sync naming a buildFromSource entry that is not a regular expression', () => {
1198
+ const { thrown } = sync({
1199
+ onCoreHeaders: true,
1200
+ precompiled: true,
1201
+ buildFromSource: ['expo-(haptics'],
1202
+ });
1203
+ expect(thrown?.message).toContain('"expo-(haptics"');
1204
+ expect(thrown.message).toContain('buildFromSource');
1205
+ expect(thrown.message).toContain('regular expression');
1206
+ expect(thrown.message).toContain(rerunSpmUpdate);
1207
+ expect(thrown.cause).toBeInstanceOf(SyntaxError);
1208
+ });
1209
+
1210
+ it('is built from source when a pattern matches every module, and only ExpoModulesCore is named as linked precompiled', () => {
1211
+ builtDirect(sync({ onCoreHeaders: true, precompiled: true, buildFromSource: ['.*'] }));
1212
+ expect(fallbackWarnings(logs)).toEqual([
1213
+ renderBuildFromSourceFallbackWarning([coreFallback('.*')]),
1214
+ ]);
1215
+ });
1216
+
1217
+ // The plugin decides from the manifest alone; the flag an earlier preview read means nothing.
1218
+ it('ignores a "directManifest" flag left in its spm.config.json', () => {
1219
+ linkedPrecompiled(
1220
+ sync({ onCoreHeaders: false, precompiled: true, spmConfig: { directManifest: true } })
1221
+ );
1222
+ });
1223
+
1224
+ it('is not built from its manifest as it stands because of a "directManifest" flag', () => {
1225
+ const { thrown, generatedManifest } = sync({
1226
+ onCoreHeaders: false,
1227
+ precompiled: false,
1228
+ spmConfig: { directManifest: true },
1229
+ });
1230
+ expect(thrown).toBeNull();
1231
+ expect(emitDirectPackage).not.toHaveBeenCalled();
1232
+ expect(fs.existsSync(generatedManifest)).toBe(true);
1233
+ });
1234
+
1235
+ it('syncs when its spm.config.json is not valid JSON', () => {
1236
+ const { thrown } = sync({
1237
+ onCoreHeaders: true,
1238
+ precompiled: false,
1239
+ spmConfig: '{ "directManifest": true,',
1240
+ });
1241
+ expect(thrown).toBeNull();
1242
+ expect(emitDirectPackage).toHaveBeenCalledTimes(1);
1243
+ });
1244
+ });
1245
+
1246
+ /**
1247
+ * Syncs ExpoMixed (pod) with `sources` of 'mixed', 'pure-swift' or 'pure-swift with podspec
1248
+ * linkage' and no checked-in manifest, listed by each of `packageNames` (default
1249
+ * expo-mixed) at one module root; an artifact when `precompiled`; and `buildFromSource`.
1250
+ */
1251
+ function syncWithoutManifest(
1252
+ tmp,
1253
+ { sources, precompiled, buildFromSource, packageNames = ['expo-mixed'] }
1254
+ ) {
1255
+ const core = pureSwiftModule(path.join(tmp, 'expo-modules-core'), 'ExpoModulesCore', spec());
1256
+ const moduleRoot = path.join(tmp, 'expo-mixed');
1257
+ const podspecs = {
1258
+ mixed: () => mixedModule(moduleRoot, 'ExpoMixed'),
1259
+ 'pure-swift': () => pureSwiftModule(moduleRoot, 'ExpoMixed', spec()),
1260
+ 'pure-swift with podspec linkage': () =>
1261
+ pureSwiftModule(moduleRoot, 'ExpoMixed', spec(" s.frameworks = 'Photos'")),
1262
+ };
1263
+ const podspecDir = podspecs[sources]();
1264
+ resolveExpoModules.mockReturnValue({
1265
+ ...modulesOf([
1266
+ coreAt(core),
1267
+ ...packageNames.map((packageName) => [packageName, [['ExpoMixed', podspecDir]]]),
1268
+ ]),
1269
+ buildFromSource,
1270
+ });
1271
+ prebuiltMetadata.mockReturnValue({ ExpoMixed: metadataEntry(moduleRoot, 'ExpoMixed') });
1272
+ const hasArtifact = (frameworkName) =>
1273
+ frameworkName === 'ExpoModulesCore' || (precompiled && frameworkName === 'ExpoMixed');
1274
+ hasPrecompiledArtifact.mockImplementation(({ frameworkName }) => hasArtifact(frameworkName));
1275
+ resolveFlavoredFramework.mockImplementation(({ frameworkName }) =>
1276
+ hasArtifact(frameworkName) ? { id: frameworkName, frameworkName } : null
1277
+ );
1278
+ resolveFlavoredFramework.mockClear();
1279
+ providerWrittenTo(path.join(tmp, 'out'));
1280
+ let result = null;
1281
+ const thrown = thrownBy(() => {
1282
+ result = runPlugin(tmp);
1283
+ });
1284
+ return {
1285
+ thrown,
1286
+ moduleRoot,
1287
+ frameworks: result?.flavoredFrameworks.map((f) => f.frameworkName).sort(),
1288
+ };
1289
+ }
1290
+
1291
+ describe('a module without a checked-in manifest that buildFromSource names', () => {
1292
+ const logs = captureConsole({ each: true });
1293
+
1294
+ afterEach(restoreModuleMocks);
1295
+
1296
+ const sync = (options) => syncWithoutManifest(makeTempDir('expo-spm-forced-source-'), options);
1297
+
1298
+ it('is built from a generated pure-Swift package, though it has an artifact', () => {
1299
+ const { thrown, frameworks } = sync({
1300
+ sources: 'pure-swift',
1301
+ precompiled: true,
1302
+ buildFromSource: ['ExpoMixed'],
1303
+ });
1304
+ expect(thrown).toBeNull();
1305
+ expect(frameworks).toEqual(['ExpoModulesCore']);
1306
+ expect(printed(logs.log)).toContain('source pure-Swift (1): ExpoMixed');
1307
+ });
1308
+
1309
+ it('fails the sync naming buildFromSource, not the missing prebuild', () => {
1310
+ const { thrown, moduleRoot } = sync({
1311
+ sources: 'mixed',
1312
+ precompiled: true,
1313
+ buildFromSource: ['expo-mixed'],
1314
+ });
1315
+ expect(thrown).toBeInstanceOf(UnsupportedModulesError);
1316
+ expect(thrown.unsupported).toEqual([
1317
+ {
1318
+ reason: 'build-from-source-unsupported',
1319
+ podName: 'ExpoMixed',
1320
+ packageName: 'expo-mixed',
1321
+ moduleRoot,
1322
+ buildFromSourceEntry: 'expo-mixed',
1323
+ cause: { reason: 'mixed-no-manifest', productName: 'ExpoMixed' },
1324
+ },
1325
+ ]);
1326
+ expect(printed(logs.error)).toContain(
1327
+ 'error: Expo module "expo-mixed" (pod ExpoMixed) is listed in buildFromSource, but Swift Package Manager cannot build it from source.'
1328
+ );
1329
+ expect(hasPrecompiledArtifact).toHaveBeenCalledWith(
1330
+ expect.objectContaining({ packageName: 'expo-mixed', frameworkName: 'ExpoMixed' })
1331
+ );
1332
+ expect(resolveFlavoredFramework).not.toHaveBeenCalledWith(
1333
+ expect.objectContaining({ frameworkName: 'ExpoMixed' })
1334
+ );
1335
+ });
1336
+
1337
+ it('names the podspec linkage of a pure-Swift module as the cause', () => {
1338
+ const { thrown } = sync({
1339
+ sources: 'pure-swift with podspec linkage',
1340
+ precompiled: true,
1341
+ buildFromSource: ['ExpoMixed'],
1342
+ });
1343
+ expect(thrown?.unsupported).toEqual([
1344
+ expect.objectContaining({
1345
+ reason: 'build-from-source-unsupported',
1346
+ cause: expect.objectContaining({ reason: 'needs-manifest-for-linkage' }),
1347
+ }),
1348
+ ]);
1349
+ });
1350
+
1351
+ // Taking the entry out would not help: there is no XCFramework to fall back to.
1352
+ it('reports what it would report without buildFromSource when there is no artifact', () => {
1353
+ const { thrown } = sync({
1354
+ sources: 'mixed',
1355
+ precompiled: false,
1356
+ buildFromSource: ['ExpoMixed'],
1357
+ });
1358
+ expect(thrown?.unsupported).toEqual([
1359
+ expect.objectContaining({ reason: 'prebuild-available', podName: 'ExpoMixed' }),
1360
+ ]);
1361
+ });
1362
+ });
1363
+
1364
+ describe('a module without a checked-in manifest that a buildFromSource pattern matches', () => {
1365
+ const logs = captureConsole({ each: true });
1366
+
1367
+ afterEach(restoreModuleMocks);
1368
+
1369
+ const sync = (options) => syncWithoutManifest(makeTempDir('expo-spm-pattern-source-'), options);
1370
+ const mixedFallback = (entry) => ({ podName: 'ExpoMixed', packageName: 'expo-mixed', entry });
1371
+
1372
+ it('is linked precompiled, as ExpoModulesCore is, when it cannot be built from source', () => {
1373
+ const { thrown, frameworks } = sync({
1374
+ sources: 'mixed',
1375
+ precompiled: true,
1376
+ buildFromSource: ['.*'],
1377
+ });
1378
+ expect(thrown).toBeNull();
1379
+ expect(frameworks).toEqual(['ExpoMixed', 'ExpoModulesCore']);
1380
+ expect(printed(logs.log)).toContain(
1381
+ 'paired runtime frameworks (2): ExpoModulesCore, ExpoMixed'
1382
+ );
1383
+ expect(resolveSpmDependencyFrameworks).toHaveBeenLastCalledWith(
1384
+ expect.arrayContaining([expect.objectContaining({ podName: 'ExpoMixed' })])
1385
+ );
1386
+ expect(prepareCompileInterfaces).toHaveBeenLastCalledWith(
1387
+ expect.arrayContaining([expect.objectContaining({ frameworkName: 'ExpoMixed' })]),
1388
+ expect.any(String)
1389
+ );
1390
+ expect(fallbackWarnings(logs)).toEqual([
1391
+ renderBuildFromSourceFallbackWarning([coreFallback('.*'), mixedFallback('.*')]),
1392
+ ]);
1393
+ });
1394
+
1395
+ it('is linked precompiled whatever blocks its source build', () => {
1396
+ const { thrown, frameworks } = sync({
1397
+ sources: 'pure-swift with podspec linkage',
1398
+ precompiled: true,
1399
+ buildFromSource: ['ExpoMix.*'],
1400
+ });
1401
+ expect(thrown).toBeNull();
1402
+ expect(frameworks).toEqual(['ExpoMixed', 'ExpoModulesCore']);
1403
+ expect(fallbackWarnings(logs)).toEqual([
1404
+ renderBuildFromSourceFallbackWarning([mixedFallback('ExpoMix.*')]),
1405
+ ]);
1406
+ });
1407
+
1408
+ it('is built from source when it can be, and is not named as linked precompiled', () => {
1409
+ const { thrown, frameworks } = sync({
1410
+ sources: 'pure-swift',
1411
+ precompiled: true,
1412
+ buildFromSource: ['.*'],
1413
+ });
1414
+ expect(thrown).toBeNull();
1415
+ expect(frameworks).toEqual(['ExpoModulesCore']);
1416
+ expect(printed(logs.log)).toContain('source pure-Swift (1): ExpoMixed');
1417
+ expect(fallbackWarnings(logs)).toEqual([
1418
+ renderBuildFromSourceFallbackWarning([coreFallback('.*')]),
1419
+ ]);
1420
+ });
1421
+
1422
+ it('fails the sync for an entry naming it exactly, though a pattern matches it too', () => {
1423
+ const { thrown } = sync({
1424
+ sources: 'mixed',
1425
+ precompiled: true,
1426
+ buildFromSource: ['.*', 'ExpoMixed'],
1427
+ });
1428
+ expect(thrown?.unsupported).toEqual([
1429
+ expect.objectContaining({
1430
+ reason: 'build-from-source-unsupported',
1431
+ podName: 'ExpoMixed',
1432
+ buildFromSourceEntry: 'ExpoMixed',
1433
+ }),
1434
+ ]);
1435
+ });
1436
+
1437
+ // There is no XCFramework to fall back to.
1438
+ it('reports what it would report without buildFromSource when there is no artifact', () => {
1439
+ const { thrown } = sync({
1440
+ sources: 'mixed',
1441
+ precompiled: false,
1442
+ buildFromSource: ['expo-mix.*'],
1443
+ });
1444
+ expect(thrown?.unsupported).toEqual([
1445
+ expect.objectContaining({ reason: 'prebuild-available', podName: 'ExpoMixed' }),
1446
+ ]);
1447
+ });
1448
+
1449
+ it('warns about nothing when no module was linked precompiled in its place', () => {
1450
+ const { thrown } = sync({
1451
+ sources: 'pure-swift',
1452
+ precompiled: true,
1453
+ buildFromSource: ['ExpoMix.*'],
1454
+ });
1455
+ expect(thrown).toBeNull();
1456
+ expect(fallbackWarnings(logs)).toEqual([]);
1457
+ });
1458
+ });
1459
+
1460
+ /**
1461
+ * Syncs `modules` (`[packageName, [podName, …], kind]`, kind 'mixed' or 'pure-swift'; the pods
1462
+ * share one module root) beside ExpoModulesCore with `buildFromSource: ['.*']`, and an artifact
1463
+ * for each pod `artifacts` names. The resolver links none of the pods `incomplete` names, though
1464
+ * an artifact is found for them.
1465
+ */
1466
+ function syncWithPattern(tmp, modules, artifacts, incomplete = []) {
1467
+ const core = pureSwiftModule(path.join(tmp, 'expo-modules-core'), 'ExpoModulesCore', spec());
1468
+ const listed = modules.map(([packageName, podNames, kind]) => {
1469
+ const root = path.join(tmp, packageName);
1470
+ const podspecDir =
1471
+ kind === 'mixed'
1472
+ ? mixedModule(root, podNames[0])
1473
+ : pureSwiftModule(root, podNames[0], spec());
1474
+ return [packageName, podNames.map((podName) => [podName, podspecDir])];
1475
+ });
1476
+ resolveExpoModules.mockReturnValue({
1477
+ ...modulesOf([coreAt(core), ...listed]),
1478
+ buildFromSource: ['.*'],
1479
+ });
1480
+ const hasArtifact = (frameworkName) =>
1481
+ frameworkName === 'ExpoModulesCore' || artifacts.includes(frameworkName);
1482
+ hasPrecompiledArtifact.mockImplementation(({ frameworkName }) => hasArtifact(frameworkName));
1483
+ resolveFlavoredFramework.mockImplementation(({ frameworkName }) =>
1484
+ hasArtifact(frameworkName) && !incomplete.includes(frameworkName)
1485
+ ? { id: frameworkName, frameworkName }
1486
+ : null
1487
+ );
1488
+ providerWrittenTo(path.join(tmp, 'out'));
1489
+ let result = null;
1490
+ const thrown = thrownBy(() => {
1491
+ result = runPlugin(tmp);
1492
+ });
1493
+ return {
1494
+ thrown,
1495
+ result,
1496
+ frameworks: result?.flavoredFrameworks.map((f) => f.frameworkName).sort(),
1497
+ };
1498
+ }
1499
+
1500
+ describe('modules linked precompiled because a buildFromSource pattern matched them', () => {
1501
+ const logs = captureConsole({ each: true });
1502
+
1503
+ afterEach(() => {
1504
+ emitPureSwiftSourcePackage.mockClear();
1505
+ restoreModuleMocks();
1506
+ });
1507
+
1508
+ it('are what a source module compiles against', () => {
1509
+ const lottie = { id: 'Lottie', frameworkName: 'Lottie' };
1510
+ resolveSpmDependencyFrameworks.mockImplementation((modules) =>
1511
+ modules.some((m) => m.podName === 'ExpoMixed') ? [lottie] : []
1512
+ );
1513
+ const { thrown, frameworks } = syncWithPattern(
1514
+ makeTempDir('expo-spm-pattern-dependent-'),
1515
+ [
1516
+ ['expo-mixed', ['ExpoMixed'], 'mixed'],
1517
+ ['expo-swift', ['ExpoSwift'], 'pure-swift'],
1518
+ ],
1519
+ ['ExpoMixed']
1520
+ );
1521
+ expect(thrown).toBeNull();
1522
+ expect(frameworks).toEqual(['ExpoMixed', 'ExpoModulesCore', 'Lottie']);
1523
+ expect(printed(logs.log)).toContain('source pure-Swift (1): ExpoSwift');
1524
+ const [emitted, emitContext] = emitPureSwiftSourcePackage.mock.lastCall;
1525
+ expect(emitted.product).toBe('ExpoSwift');
1526
+ expect([...emitContext.satisfiedDependencies]).toEqual(['Lottie']);
1527
+ expect(prepareCompileInterfaces).toHaveBeenLastCalledWith(
1528
+ expect.arrayContaining([expect.objectContaining({ frameworkName: 'ExpoMixed' })]),
1529
+ expect.any(String)
1530
+ );
1531
+ });
1532
+
1533
+ // Building the first pod from source beside its precompiled sibling would link the
1534
+ // sibling twice, so the first pod has no source build left either.
1535
+ it('take a sibling pod along, rather than leave it built from source', () => {
1536
+ const { thrown, frameworks, result } = syncWithPattern(
1537
+ makeTempDir('expo-spm-pattern-siblings-'),
1538
+ [['expo-multi', ['ExpoMultiA', 'ExpoMultiB'], 'pure-swift']],
1539
+ ['ExpoMultiA', 'ExpoMultiB']
1540
+ );
1541
+ expect(thrown).toBeNull();
1542
+ expect(frameworks).toEqual(['ExpoModulesCore', 'ExpoMultiA', 'ExpoMultiB']);
1543
+ expect(result.packageDependencies).toEqual([]);
1544
+ expect(printed(logs.log)).toContain('source pure-Swift (0): —');
1545
+ expect(fallbackWarnings(logs)).toEqual([
1546
+ renderBuildFromSourceFallbackWarning([
1547
+ coreFallback('.*'),
1548
+ { podName: 'ExpoMultiA', packageName: 'expo-multi', entry: '.*' },
1549
+ { podName: 'ExpoMultiB', packageName: 'expo-multi', entry: '.*' },
1550
+ ]),
1551
+ ]);
1552
+ });
1553
+
1554
+ it('fail the sync naming the entry when the precompiled XCFramework cannot be linked', () => {
1555
+ const tmp = makeTempDir('expo-spm-pattern-incomplete-');
1556
+ const { thrown } = syncWithPattern(
1557
+ tmp,
1558
+ [['expo-mixed', ['ExpoMixed'], 'mixed']],
1559
+ ['ExpoMixed'],
1560
+ ['ExpoMixed']
1561
+ );
1562
+ expect(thrown).toBeInstanceOf(UnsupportedModulesError);
1563
+ expect(thrown.unsupported).toEqual([
1564
+ {
1565
+ reason: 'build-from-source-fallback-incomplete',
1566
+ podName: 'ExpoMixed',
1567
+ packageName: 'expo-mixed',
1568
+ moduleRoot: path.join(tmp, 'expo-mixed'),
1569
+ buildFromSourceEntry: '.*',
1570
+ cause: expect.objectContaining({ reason: 'mixed-no-manifest' }),
1571
+ },
1572
+ ]);
1573
+ expect(printed(logs.error)).toContain(
1574
+ 'error: The buildFromSource entry ".*" matches Expo module "expo-mixed" (pod ExpoMixed), which Swift Package Manager cannot build from source, and its precompiled XCFramework is incomplete, so it cannot be linked precompiled either.'
1575
+ );
1576
+ });
1577
+ });
1578
+
1579
+ describe('what a discarded round of the passes emitted', () => {
1580
+ captureConsole({ each: true });
1581
+
1582
+ afterEach(() => {
1583
+ emitDirectPackage.mockReset();
1584
+ runDumpPackage.mockReset();
1585
+ restoreModuleMocks();
1586
+ });
1587
+
1588
+ const expoSource = (tmp, name) => path.join(tmp, 'out', 'expo', 'expo-source', name);
1589
+
1590
+ it('is removed, and what the last round emitted is kept', () => {
1591
+ const tmp = makeTempDir('expo-spm-pattern-orphan-');
1592
+ fs.mkdirSync(expoSource(tmp, 'ExpoOther'), { recursive: true });
1593
+ const { thrown } = syncWithPattern(
1594
+ tmp,
1595
+ [
1596
+ ['expo-multi', ['ExpoMultiA', 'ExpoMultiB'], 'pure-swift'],
1597
+ ['expo-swift', ['ExpoSwift'], 'pure-swift'],
1598
+ ],
1599
+ ['ExpoMultiA', 'ExpoMultiB']
1600
+ );
1601
+ expect(thrown).toBeNull();
1602
+ expect(fs.existsSync(expoSource(tmp, 'ExpoMultiA'))).toBe(false);
1603
+ expect(fs.existsSync(path.join(expoSource(tmp, 'ExpoSwift'), 'Package.swift'))).toBe(true);
1604
+ expect(fs.existsSync(expoSource(tmp, 'ExpoOther'))).toBe(true);
1605
+ });
1606
+
1607
+ it('is removed when it is a link to a checked-in manifest, and the module stays', () => {
1608
+ const tmp = makeTempDir('expo-spm-pattern-orphan-direct-');
1609
+ const core = pureSwiftModule(path.join(tmp, 'expo-modules-core'), 'ExpoModulesCore', spec());
1610
+ const moduleRoot = path.join(tmp, 'expo-multi');
1611
+ const podspecDir = pureSwiftModule(moduleRoot, 'ExpoMultiA', spec());
1612
+ fs.writeFileSync(path.join(moduleRoot, 'Package.swift'), '// swift-tools-version: 6.0\n');
1613
+ runDumpPackage.mockReturnValue(
1614
+ dumpedManifest('expo-multi', 'ExpoMultiA', { onCoreHeaders: true })
1615
+ );
1616
+ resolveExpoModules.mockReturnValue({
1617
+ ...modulesOf([
1618
+ coreAt(core),
1619
+ [
1620
+ 'expo-multi',
1621
+ [
1622
+ ['ExpoMultiA', podspecDir],
1623
+ ['ExpoMultiB', podspecDir],
1624
+ ],
1625
+ ],
1626
+ ]),
1627
+ buildFromSource: ['.*'],
1628
+ });
1629
+ hasPrecompiledArtifact.mockReturnValue(true);
1630
+ resolveFlavoredFramework.mockImplementation(({ frameworkName }) => ({
1631
+ id: frameworkName,
1632
+ frameworkName,
1633
+ }));
1634
+ const link = path.join(tmp, 'out', 'expo', 'direct', 'expo-multi');
1635
+ emitDirectPackage.mockImplementation(() => {
1636
+ fs.mkdirSync(path.dirname(link), { recursive: true });
1637
+ fs.symlinkSync(moduleRoot, link);
1638
+ return {
1639
+ ok: {
1640
+ packageDep: { name: 'expo-multi', path: link },
1641
+ productDeps: [{ name: 'ExpoMultiA', package: 'expo-multi' }],
1642
+ spmProductNames: [],
1643
+ partlyProvidedPackages: [],
1644
+ },
1645
+ };
1646
+ });
1647
+ providerWrittenTo(path.join(tmp, 'out'));
1648
+ const thrown = thrownBy(() => runPlugin(tmp));
1649
+ expect(thrown).toBeNull();
1650
+ expect(emitDirectPackage).toHaveBeenCalled();
1651
+ expect(() => fs.lstatSync(link)).toThrow();
1652
+ expect(fs.existsSync(path.join(moduleRoot, 'Package.swift'))).toBe(true);
1653
+ });
1654
+ });
1655
+
1656
+ // A pod is one pod whichever package lists it: buildFromSource naming any of them decides.
1657
+ describe.each([
1658
+ ['the named package first', ['alias-one', 'alias-two']],
1659
+ ['the named package second', ['alias-two', 'alias-one']],
1660
+ ])('a pod two packages list, buildFromSource naming one of them, %s', (_, packageNames) => {
1661
+ const logs = captureConsole({ each: true });
1662
+
1663
+ afterEach(restoreModuleMocks);
1664
+
1665
+ const sync = (sources) =>
1666
+ syncWithoutManifest(makeTempDir('expo-spm-forced-alias-'), {
1667
+ sources,
1668
+ precompiled: true,
1669
+ buildFromSource: ['alias-one'],
1670
+ packageNames,
1671
+ });
1672
+
1673
+ it('is built from source, not linked precompiled through the other package', () => {
1674
+ const { thrown, frameworks } = sync('pure-swift');
1675
+ expect(thrown).toBeNull();
1676
+ expect(frameworks).toEqual(['ExpoModulesCore']);
1677
+ expect(resolveFlavoredFramework).not.toHaveBeenCalledWith(
1678
+ expect.objectContaining({ frameworkName: 'ExpoMixed' })
1679
+ );
1680
+ expect(printed(logs.log)).toContain('source pure-Swift (1): ExpoMixed');
1681
+ });
1682
+
1683
+ it('is refused for buildFromSource when it cannot be built from source', () => {
1684
+ const { thrown } = sync('mixed');
1685
+ expect(thrown?.unsupported).toEqual([
1686
+ expect.objectContaining({
1687
+ reason: 'build-from-source-unsupported',
1688
+ podName: 'ExpoMixed',
1689
+ buildFromSourceEntry: 'alias-one',
1690
+ cause: expect.objectContaining({ reason: 'mixed-no-manifest' }),
1691
+ }),
1692
+ ]);
1693
+ });
1694
+
1695
+ it('is refused for an entry naming one package exactly, though a pattern matches the other', () => {
1696
+ const { thrown } = syncWithoutManifest(makeTempDir('expo-spm-forced-alias-'), {
1697
+ sources: 'mixed',
1698
+ precompiled: true,
1699
+ buildFromSource: ['alias-t.*', 'alias-one'],
1700
+ packageNames,
1701
+ });
1702
+ expect(thrown?.unsupported).toEqual([
1703
+ expect.objectContaining({
1704
+ reason: 'build-from-source-unsupported',
1705
+ podName: 'ExpoMixed',
1706
+ buildFromSourceEntry: 'alias-one',
1707
+ }),
1708
+ ]);
1709
+ });
1710
+ });
1711
+
1712
+ describe('a buildFromSource entry matching ExpoModulesCore', () => {
1713
+ const logs = captureConsole({ each: true });
1714
+
1715
+ afterAll(restoreModuleMocks);
1716
+
1717
+ function sync(buildFromSource) {
1718
+ const tmp = makeTempDir('expo-spm-forced-core-');
1719
+ const core = pureSwiftModule(path.join(tmp, 'expo-modules-core'), 'ExpoModulesCore', spec());
1720
+ resolveExpoModules.mockReturnValue({ ...modulesOf([coreAt(core)]), buildFromSource });
1721
+ resolveFlavoredFramework.mockClear();
1722
+ providerWrittenTo(path.join(tmp, 'out'));
1723
+ let result = null;
1724
+ const thrown = thrownBy(() => {
1725
+ result = runPlugin(tmp);
1726
+ });
1727
+ return { thrown, result };
1728
+ }
1729
+
1730
+ it.each([
1731
+ ['its pod name', 'ExpoModulesCore', ['ExpoModulesCore']],
1732
+ ['its npm package name', 'expo-modules-core', ['expo-modules-core']],
1733
+ [
1734
+ 'its name, beside a pattern matching it',
1735
+ 'expo-modules-core',
1736
+ ['Expo.*', 'expo-modules-core'],
1737
+ ],
1738
+ ])('fails the sync up front when it names %s', (_, entry, buildFromSource) => {
1739
+ const { thrown } = sync(buildFromSource);
1740
+ expect(thrown).not.toBeInstanceOf(UnsupportedModulesError);
1741
+ expect(thrown?.message).toBe(
1742
+ `[expo-spm-plugin] The buildFromSource entry "${entry}" in your app's Expo autolinking options matches ExpoModulesCore (expo-modules-core), which Swift Package Manager cannot build from source. ` +
1743
+ 'Under Swift Package Manager, ExpoModulesCore is always linked precompiled: every Expo module built from source compiles against its precompiled interface. ' +
1744
+ `Remove "${entry}" from \`"expo": { "autolinking": { "buildFromSource": [...] } }\` (or its \`"ios"\` section) in your package.json, or narrow it so it no longer matches ExpoModulesCore or expo-modules-core. ${rerunSpmUpdate}`
1745
+ );
1746
+ expect(resolveFlavoredFramework).not.toHaveBeenCalled();
880
1747
  });
881
1748
 
882
- it('warns about its unmapped dependencies once, not once per pass', () => {
883
- const report = printed(logs.warn);
884
- expect(report.match(/warning: Expo module "expo-multi"/g)).toHaveLength(1);
1749
+ it('links it precompiled when only a pattern matches it, and says so', () => {
1750
+ const { thrown, result } = sync(['Expo.*']);
1751
+ expect(thrown).toBeNull();
1752
+ expect(result.flavoredFrameworks).toEqual([
1753
+ expect.objectContaining({ name: 'ExpoModulesCore' }),
1754
+ ]);
1755
+ expect(fallbackWarnings(logs)).toEqual([
1756
+ renderBuildFromSourceFallbackWarning([coreFallback('Expo.*')]),
1757
+ ]);
885
1758
  });
886
1759
  });
887
1760
 
888
- describe('the checked-in manifest branch', () => {
889
- const logs = captureConsole();
890
- let outDir;
1761
+ // A refused manifest links no pod, so the second package listing its root reaches it again.
1762
+ describe.each([
1763
+ ['through one path', false],
1764
+ ['through two symlinks', true],
1765
+ ])('a refused checked-in manifest two packages list %s', (_, symlinked) => {
1766
+ captureConsole();
891
1767
  let thrown;
892
1768
 
893
1769
  beforeAll(() => {
894
- const tmp = makeTempDir('expo-spm-plugin-manifest-');
895
- outDir = path.join(tmp, 'out');
1770
+ const tmp = makeTempDir('expo-spm-dump-once-');
896
1771
  const core = pureSwiftModule(path.join(tmp, 'expo-modules-core'), 'ExpoModulesCore', spec());
897
- const vendored = path.join(tmp, 'expo-vendored');
898
- const vendoredPodspecDir = pureSwiftModule(vendored, 'ExpoVendored', spec());
899
- fs.writeFileSync(
900
- path.join(vendored, 'Package.swift'),
901
- '// swift-tools-version: 6.0\n// checked in by the module\n'
902
- );
1772
+ const shared = path.join(tmp, 'shared');
1773
+ pureSwiftModule(shared, 'ExpoVendored', spec());
1774
+ fs.writeFileSync(path.join(shared, 'Package.swift'), '// swift-tools-version: 6.0\n');
1775
+ const listedRoot = (name) => {
1776
+ if (!symlinked) return shared;
1777
+ const link = path.join(tmp, name);
1778
+ fs.symlinkSync(shared, link);
1779
+ return link;
1780
+ };
1781
+ const podspecDirOne = path.join(listedRoot('link-one'), 'ios');
1782
+ const podspecDirTwo = path.join(listedRoot('link-two'), 'ios');
1783
+ runDumpPackage.mockReset();
903
1784
  runDumpPackage.mockReturnValue(
904
1785
  JSON.stringify({
905
1786
  name: 'ExpoVendored',
@@ -918,29 +1799,353 @@ describe('the checked-in manifest branch', () => {
918
1799
  })
919
1800
  );
920
1801
  resolveExpoModules.mockReturnValue(
921
- modulesOf([coreAt(core), ['expo-vendored', [['ExpoVendored', vendoredPodspecDir]]]])
1802
+ modulesOf([
1803
+ coreAt(core),
1804
+ ['alias-one', [['ExpoVendored', podspecDirOne]]],
1805
+ ['alias-two', [['ExpoVendored', podspecDirTwo]]],
1806
+ ])
922
1807
  );
1808
+ providerWrittenTo(path.join(tmp, 'out'));
923
1809
  thrown = thrownBy(() => runPlugin(tmp));
924
1810
  });
925
1811
 
926
- it('fails the sync for a manifest depending on a target it cannot declare', () => {
1812
+ afterAll(() => {
1813
+ runDumpPackage.mockReset();
1814
+ restoreModuleMocks();
1815
+ });
1816
+
1817
+ it('evaluates the manifest once', () => {
927
1818
  expect(thrown).toBeInstanceOf(UnsupportedModulesError);
928
- expect(thrown.unsupported).toEqual([
929
- expect.objectContaining({
930
- reason: 'unsupported-target-dependency',
931
- podName: 'ExpoVendored',
932
- dependencies: [{ target: 'ExpoVendored', dependsOn: 'VendoredKit', kind: 'binary' }],
933
- }),
1819
+ expect(runDumpPackage).toHaveBeenCalledTimes(1);
1820
+ });
1821
+ });
1822
+
1823
+ describe('where precompiled modules and headers come from', () => {
1824
+ const logs = captureConsole({ each: true });
1825
+ const packageOf = {
1826
+ ExpoModulesCore: 'expo-modules-core',
1827
+ ExpoModulesJSI: 'expo-modules-jsi',
1828
+ ExpoFont: 'expo-font',
1829
+ };
1830
+ const sourceAt = (kind, frameworkName) => ({
1831
+ kind,
1832
+ dir: path.join('/', kind, packageOf[frameworkName], 'output'),
1833
+ });
1834
+ const jsiHeadersXCFramework = '/abs/ExpoModulesJSIHeaders.xcframework';
1835
+
1836
+ afterEach(() => {
1837
+ emitDirectPackage.mockReset();
1838
+ runDumpPackage.mockReset();
1839
+ restoreModuleMocks();
1840
+ });
1841
+
1842
+ /**
1843
+ * Syncs an app with expo-modules-jsi autolinked, the `frameworks` precompiled from the
1844
+ * given kinds of place, and a direct module when `headers` says where the
1845
+ * ExpoModulesCore headers come from (null for headers that are not found).
1846
+ */
1847
+ function sync({ frameworks, headers }) {
1848
+ const tmp = makeTempDir('expo-spm-plugin-sources-');
1849
+ const listed = Object.keys({ ...frameworks, ExpoModulesJSI: null }).map((frameworkName) => [
1850
+ packageOf[frameworkName],
1851
+ [
1852
+ [
1853
+ frameworkName,
1854
+ pureSwiftModule(path.join(tmp, packageOf[frameworkName]), frameworkName, spec()),
1855
+ ],
1856
+ ],
934
1857
  ]);
935
- expect(printed(logs.error)).toContain(
936
- 'target "ExpoVendored" depends on "VendoredKit", a binary target'
1858
+ if (headers != null) {
1859
+ const haptics = path.join(tmp, 'expo-haptics');
1860
+ const podspecDir = pureSwiftModule(haptics, 'ExpoHaptics', spec());
1861
+ fs.writeFileSync(path.join(haptics, 'Package.swift'), '// swift-tools-version: 6.0\n');
1862
+ runDumpPackage.mockReturnValue(
1863
+ dumpedManifest('expo-haptics', 'ExpoHaptics', { onCoreHeaders: true })
1864
+ );
1865
+ listed.push(['expo-haptics', [['ExpoHaptics', podspecDir]]]);
1866
+ resolveHeadersXCFrameworkWithSource.mockImplementation(({ productName }) =>
1867
+ headers[productName] == null
1868
+ ? null
1869
+ : {
1870
+ xcframework: `/abs/${productName}Headers.xcframework`,
1871
+ source: sourceAt(headers[productName], productName),
1872
+ }
1873
+ );
1874
+ emitDirectPackage.mockReturnValue({
1875
+ ok: {
1876
+ packageDep: { name: 'ExpoHaptics', path: haptics },
1877
+ productDeps: [{ name: 'ExpoHaptics', package: 'ExpoHaptics' }],
1878
+ spmProductNames: [],
1879
+ partlyProvidedPackages: [],
1880
+ },
1881
+ });
1882
+ }
1883
+ resolveExpoModules.mockReturnValue(modulesOf(listed));
1884
+ resolveFlavoredFramework.mockImplementation(({ frameworkName }) =>
1885
+ frameworkName in frameworks ? { id: frameworkName, frameworkName } : null
1886
+ );
1887
+ frameworkSource.mockImplementation(({ frameworkName }) =>
1888
+ sourceAt(frameworks[frameworkName], frameworkName)
1889
+ );
1890
+ resolveHeadersXCFramework.mockReturnValue(jsiHeadersXCFramework);
1891
+ const outDir = path.join(tmp, 'out');
1892
+ providerWrittenTo(outDir);
1893
+ let result = null;
1894
+ const thrown = thrownBy(() => {
1895
+ result = runPlugin(tmp);
1896
+ });
1897
+ return {
1898
+ thrown,
1899
+ result,
1900
+ jsiHeadersPkgPath: path.join(outDir, 'expo', 'ExpoModulesJSIHeaders'),
1901
+ };
1902
+ }
1903
+
1904
+ it('warns, and syncs, when a precompiled module comes from a different place than ExpoModulesCore', () => {
1905
+ const { thrown, result } = sync({
1906
+ frameworks: { ExpoModulesCore: 'env', ExpoFont: 'bundled' },
1907
+ });
1908
+ expect(thrown).toBeNull();
1909
+ expect(result.flavoredFrameworks).toHaveLength(2);
1910
+ const warning = printed(logs.warn);
1911
+ expect(warning).toContain('[expo-spm-plugin] WARNING: ExpoFont (expo-font)');
1912
+ expect(warning).toContain(sourceAt('bundled', 'ExpoFont').dir);
1913
+ expect(warning).toContain(sourceAt('env', 'ExpoModulesCore').dir);
1914
+ expect(warning).toContain('EXPO_PRECOMPILED_MODULES_PATH');
1915
+ expect(warning).toContain('can crash the app');
1916
+ expect(warning).toContain(rerunSpmUpdate);
1917
+ expect(warning).toContain(
1918
+ 'from the Expo repository root, build the packages into the same place as ExpoModulesCore with `node tools/bin/expotools.js prebuild expo-font`'
937
1919
  );
938
1920
  });
939
1921
 
940
- it('emits no package for it', () => {
941
- expect(
942
- fs.existsSync(path.join(outDir, 'expo', 'expo-source', 'ExpoVendored', 'Package.swift'))
943
- ).toBe(false);
1922
+ it('warns, and emits the direct module, when another precompiled module comes from a different place', () => {
1923
+ const { thrown } = sync({
1924
+ frameworks: { ExpoModulesCore: 'env', ExpoFont: 'bundled' },
1925
+ headers: { ExpoModulesCore: 'env' },
1926
+ });
1927
+ expect(thrown).toBeNull();
1928
+ expect(printed(logs.warn)).toContain('[expo-spm-plugin] WARNING: ExpoFont (expo-font)');
1929
+ expect(emitDirectPackage).toHaveBeenCalled();
1930
+ });
1931
+
1932
+ it('does not warn when every precompiled module comes from the place ExpoModulesCore comes from', () => {
1933
+ const { thrown } = sync({
1934
+ frameworks: { ExpoModulesCore: 'env', ExpoFont: 'env' },
1935
+ headers: { ExpoModulesCore: 'env' },
1936
+ });
1937
+ expect(thrown).toBeNull();
1938
+ expect(printed(logs.warn)).not.toContain('comes from');
1939
+ });
1940
+
1941
+ it('never requires an ExpoModulesJSI binary from the place ExpoModulesCore comes from', () => {
1942
+ const { thrown, result } = sync({
1943
+ frameworks: { ExpoModulesCore: 'monorepo', ExpoModulesJSI: 'env', ExpoFont: 'monorepo' },
1944
+ });
1945
+ expect(thrown).toBeNull();
1946
+ expect(result.flavoredFrameworks.map((f) => f.frameworkName)).toEqual([
1947
+ 'ExpoFont',
1948
+ 'ExpoModulesCore',
1949
+ ]);
1950
+ });
1951
+
1952
+ it('accepts modules from different directories of the same kind of place', () => {
1953
+ const { thrown, result } = sync({
1954
+ frameworks: { ExpoModulesCore: 'bundled', ExpoFont: 'bundled' },
1955
+ });
1956
+ expect(thrown).toBeNull();
1957
+ expect(result.flavoredFrameworks).toHaveLength(2);
1958
+ });
1959
+
1960
+ it.each([
1961
+ ['bundled', 'env'],
1962
+ ['bundled', 'monorepo'],
1963
+ ['monorepo', 'env'],
1964
+ ])(
1965
+ 'fails when ExpoModulesCore comes from %s and its headers from %s, a place tried before it',
1966
+ (coreKind, headersKind) => {
1967
+ const { thrown } = sync({
1968
+ frameworks: { ExpoModulesCore: coreKind },
1969
+ headers: { ExpoModulesCore: headersKind },
1970
+ });
1971
+ expect(thrown?.message).toContain('ExpoModulesCoreHeaders.xcframework (expo-modules-core)');
1972
+ expect(thrown.message).toContain(sourceAt(headersKind, 'ExpoModulesCore').dir);
1973
+ expect(thrown.message).toContain(sourceAt(coreKind, 'ExpoModulesCore').dir);
1974
+ expect(emitDirectPackage).not.toHaveBeenCalled();
1975
+ }
1976
+ );
1977
+
1978
+ const prebuildCoreHint =
1979
+ 'From the Expo repository root, run `node tools/bin/expotools.js prebuild expo-modules-core expo-modules-jsi`';
1980
+
1981
+ // The lookup tries EXPO_PRECOMPILED_MODULES_PATH, then the monorepo, then npm, so headers
1982
+ // found past the place ExpoModulesCore comes from mean that place has none.
1983
+ it.each([
1984
+ ['env', 'monorepo'],
1985
+ ['env', 'bundled'],
1986
+ ['env', null],
1987
+ ['monorepo', 'bundled'],
1988
+ ['monorepo', null],
1989
+ ])(
1990
+ 'fails naming the missing headers when ExpoModulesCore comes from %s and its headers from %s',
1991
+ (coreKind, headersKind) => {
1992
+ const { thrown } = sync({
1993
+ frameworks: { ExpoModulesCore: coreKind },
1994
+ headers: { ExpoModulesCore: headersKind },
1995
+ });
1996
+ const coreDir = sourceAt(coreKind, 'ExpoModulesCore').dir;
1997
+ expect(thrown?.message).toContain(
1998
+ `ExpoModulesCoreHeaders.xcframework is missing under ${coreDir}`
1999
+ );
2000
+ expect(thrown.message).not.toContain('but ExpoModulesCore comes from');
2001
+ expect(thrown.message).toContain(rerunSpmUpdate);
2002
+ // The prebuild writes to the monorepo output, never to EXPO_PRECOMPILED_MODULES_PATH.
2003
+ if (coreKind === 'env') {
2004
+ expect(thrown.message).toContain('Unset EXPO_PRECOMPILED_MODULES_PATH');
2005
+ expect(thrown.message).not.toContain(prebuildCoreHint);
2006
+ } else {
2007
+ expect(thrown.message).toContain(prebuildCoreHint);
2008
+ expect(thrown.message).not.toContain('EXPO_PRECOMPILED_MODULES_PATH');
2009
+ }
2010
+ expect(emitDirectPackage).not.toHaveBeenCalled();
2011
+ }
2012
+ );
2013
+
2014
+ it('hands a direct module the ExpoModulesCore headers and the ExpoModulesJSI headers package', () => {
2015
+ const { thrown, jsiHeadersPkgPath } = sync({
2016
+ frameworks: { ExpoModulesCore: 'env' },
2017
+ headers: { ExpoModulesCore: 'env' },
2018
+ });
2019
+ expect(thrown).toBeNull();
2020
+ expect(emitDirectPackage).toHaveBeenCalledWith(
2021
+ expect.objectContaining({
2022
+ coreHeadersXCFramework: '/abs/ExpoModulesCoreHeaders.xcframework',
2023
+ jsiHeadersPkgPath,
2024
+ })
2025
+ );
2026
+ expect(resolveHeadersXCFrameworkWithSource).not.toHaveBeenCalledWith(
2027
+ expect.objectContaining({ productName: 'ExpoModulesJSI' })
2028
+ );
2029
+ });
2030
+
2031
+ it('emits the ExpoModulesJSI headers package when the only source package is a direct one', () => {
2032
+ emitPureSwiftSourcePackage.mockClear();
2033
+ const { thrown, jsiHeadersPkgPath } = sync({
2034
+ frameworks: { ExpoModulesCore: 'env' },
2035
+ headers: { ExpoModulesCore: 'env' },
2036
+ });
2037
+ expect(thrown).toBeNull();
2038
+ expect(emitPureSwiftSourcePackage).not.toHaveBeenCalled();
2039
+ expect(fs.readlinkSync(path.join(jsiHeadersPkgPath, 'ExpoModulesJSIHeaders.xcframework'))).toBe(
2040
+ jsiHeadersXCFramework
2041
+ );
2042
+ expect(fs.existsSync(path.join(jsiHeadersPkgPath, 'Package.swift'))).toBe(true);
2043
+ });
2044
+
2045
+ // A broken copy further down the lookup is not what the user has to fix: reinstalling or
2046
+ // rebuilding it cannot repair an EXPO_PRECOMPILED_MODULES_PATH build without headers.
2047
+ it('names the missing headers, not an incomplete npm copy, when ExpoModulesCore comes from EXPO_PRECOMPILED_MODULES_PATH', () => {
2048
+ const tmp = makeTempDir('expo-spm-plugin-env-headers-');
2049
+ const envDir = path.join(tmp, 'precompiled');
2050
+ fs.mkdirSync(envDir);
2051
+ const coreRoot = path.join(tmp, 'expo-modules-core');
2052
+ const corePodspecDir = pureSwiftModule(coreRoot, 'ExpoModulesCore', spec());
2053
+ fs.mkdirSync(
2054
+ path.join(
2055
+ coreRoot,
2056
+ 'prebuilds',
2057
+ 'output',
2058
+ 'headers',
2059
+ 'xcframeworks',
2060
+ 'ExpoModulesCoreHeaders.xcframework'
2061
+ ),
2062
+ { recursive: true }
2063
+ );
2064
+ const jsiPodspecDir = pureSwiftModule(
2065
+ path.join(tmp, 'expo-modules-jsi'),
2066
+ 'ExpoModulesJSI',
2067
+ spec()
2068
+ );
2069
+ const haptics = path.join(tmp, 'expo-haptics');
2070
+ const hapticsPodspecDir = pureSwiftModule(haptics, 'ExpoHaptics', spec());
2071
+ fs.writeFileSync(path.join(haptics, 'Package.swift'), '// swift-tools-version: 6.0\n');
2072
+ runDumpPackage.mockReturnValue(
2073
+ dumpedManifest('expo-haptics', 'ExpoHaptics', { onCoreHeaders: true })
2074
+ );
2075
+ resolveExpoModules.mockReturnValue(
2076
+ modulesOf([
2077
+ coreAt(corePodspecDir),
2078
+ ['expo-modules-jsi', [['ExpoModulesJSI', jsiPodspecDir]]],
2079
+ ['expo-haptics', [['ExpoHaptics', hapticsPodspecDir]]],
2080
+ ])
2081
+ );
2082
+ const coreDir = path.join(envDir, 'expo-modules-core', 'output');
2083
+ resolveFlavoredFramework.mockImplementation(({ frameworkName }) =>
2084
+ frameworkName === 'ExpoModulesCore' ? { id: frameworkName, frameworkName } : null
2085
+ );
2086
+ frameworkSource.mockImplementation(({ frameworkName }) =>
2087
+ frameworkName === 'ExpoModulesCore' ? { kind: 'env', dir: coreDir } : null
2088
+ );
2089
+ resolveHeadersXCFramework.mockReturnValue(jsiHeadersXCFramework);
2090
+ resolveHeadersXCFrameworkWithSource.mockImplementation(
2091
+ jest.requireActual('../flavored-frameworks').resolveHeadersXCFrameworkWithSource
2092
+ );
2093
+ providerWrittenTo(path.join(tmp, 'out'));
2094
+ const previous = process.env.EXPO_PRECOMPILED_MODULES_PATH;
2095
+ process.env.EXPO_PRECOMPILED_MODULES_PATH = envDir;
2096
+ try {
2097
+ const thrown = thrownBy(() => runPlugin(tmp));
2098
+ expect(thrown?.message).toContain(
2099
+ `ExpoModulesCoreHeaders.xcframework is missing under ${coreDir}`
2100
+ );
2101
+ expect(thrown.message).toContain('Unset EXPO_PRECOMPILED_MODULES_PATH');
2102
+ expect(thrown.message).not.toContain('Info.plist');
2103
+ expect(emitDirectPackage).not.toHaveBeenCalled();
2104
+ } finally {
2105
+ if (previous === undefined) {
2106
+ delete process.env.EXPO_PRECOMPILED_MODULES_PATH;
2107
+ } else {
2108
+ process.env.EXPO_PRECOMPILED_MODULES_PATH = previous;
2109
+ }
2110
+ }
2111
+ });
2112
+
2113
+ it('fails when a direct module exists and the ExpoModulesCore headers are missing', () => {
2114
+ const previous = process.env.EXPO_PRECOMPILED_MODULES_PATH;
2115
+ process.env.EXPO_PRECOMPILED_MODULES_PATH = '/precompiled';
2116
+ try {
2117
+ const { thrown } = sync({
2118
+ frameworks: { ExpoModulesCore: 'bundled' },
2119
+ headers: { ExpoModulesCore: null },
2120
+ });
2121
+ expect(thrown?.message).toContain('ExpoModulesCoreHeaders.xcframework');
2122
+ const { headersXCFrameworkSearchPaths } = jest.requireActual('../flavored-frameworks');
2123
+ const searched = headersXCFrameworkSearchPaths({
2124
+ packageName: 'expo-modules-core',
2125
+ moduleRoot: null,
2126
+ productName: 'ExpoModulesCore',
2127
+ });
2128
+ expect(searched.length).toBeGreaterThan(0);
2129
+ for (const candidate of searched) expect(thrown.message).toContain(candidate);
2130
+ expect(thrown.message).toContain(
2131
+ 'From the Expo repository root, run `node tools/bin/expotools.js prebuild expo-modules-core`'
2132
+ );
2133
+ expect(thrown.message).toContain(rerunSpmUpdate);
2134
+ expect(emitDirectPackage).not.toHaveBeenCalled();
2135
+ } finally {
2136
+ if (previous === undefined) {
2137
+ delete process.env.EXPO_PRECOMPILED_MODULES_PATH;
2138
+ } else {
2139
+ process.env.EXPO_PRECOMPILED_MODULES_PATH = previous;
2140
+ }
2141
+ }
2142
+ });
2143
+
2144
+ it('looks for no headers when no direct module is emitted', () => {
2145
+ resolveHeadersXCFrameworkWithSource.mockClear();
2146
+ const { thrown } = sync({ frameworks: { ExpoModulesCore: 'env', ExpoFont: 'env' } });
2147
+ expect(thrown).toBeNull();
2148
+ expect(resolveHeadersXCFrameworkWithSource).not.toHaveBeenCalled();
944
2149
  });
945
2150
  });
946
2151
 
@@ -3569,3 +4774,188 @@ describe('a gated pod linked where its autolinkWhen condition is not checked', (
3569
4774
  expect(report).toContain('"ExpoScanner"');
3570
4775
  });
3571
4776
  });
4777
+
4778
+ // npm never ships the ExpoModulesJSI binary: it must be compiled against the app's
4779
+ // React Native. Source packages compile against its headers XCFramework, and an app
4780
+ // build phase builds, links and embeds the real framework.
4781
+ describe('ExpoModulesJSI', () => {
4782
+ captureConsole();
4783
+
4784
+ /**
4785
+ * Writes the expo-modules-jsi `versions`: `headers` into the headers' stamp, `autolinked`
4786
+ * into the autolinked package, and `built` into the copy the build phase's launcher reaches
4787
+ * through expo and expo-modules-core. Returns that copy's directory.
4788
+ */
4789
+ function writeJsiVersions(tmp, headersXCFramework, { headers, autolinked, built }) {
4790
+ const writePackage = (dir, name, version) => {
4791
+ fs.mkdirSync(dir, { recursive: true });
4792
+ fs.writeFileSync(path.join(dir, 'package.json'), JSON.stringify({ name, version }));
4793
+ return dir;
4794
+ };
4795
+ fs.writeFileSync(
4796
+ path.join(headersXCFramework, 'expo-package.json'),
4797
+ JSON.stringify({ name: 'expo-modules-jsi', version: headers })
4798
+ );
4799
+ writePackage(path.join(tmp, 'expo-modules-jsi'), 'expo-modules-jsi', autolinked);
4800
+ const expo = writePackage(path.join(tmp, 'app', 'node_modules', 'expo'), 'expo', '1.0.0');
4801
+ const core = writePackage(
4802
+ path.join(expo, 'node_modules', 'expo-modules-core'),
4803
+ 'expo-modules-core',
4804
+ '1.0.0'
4805
+ );
4806
+ return writePackage(
4807
+ path.join(core, 'node_modules', 'expo-modules-jsi'),
4808
+ 'expo-modules-jsi',
4809
+ built
4810
+ );
4811
+ }
4812
+
4813
+ /**
4814
+ * Runs the plugin for core, expo-asset and, with `withJsi`, expo-modules-jsi. `versions`
4815
+ * stamps the headers and installs versions as `writeJsiVersions` describes.
4816
+ */
4817
+ function syncApp({ withJsi = true, headers = 'resolved', versions } = {}) {
4818
+ const tmp = makeTempDir('expo-spm-jsi-');
4819
+ const outDir = path.join(tmp, 'out');
4820
+ const headersXCFramework = path.join(tmp, 'npm', 'ExpoModulesJSIHeaders.xcframework');
4821
+ fs.mkdirSync(headersXCFramework, { recursive: true });
4822
+ fs.writeFileSync(path.join(headersXCFramework, 'Info.plist'), '<plist/>');
4823
+ const core = pureSwiftModule(path.join(tmp, 'expo-modules-core'), 'ExpoModulesCore', spec());
4824
+ const jsi = pureSwiftModule(path.join(tmp, 'expo-modules-jsi'), 'ExpoModulesJSI', spec());
4825
+ const asset = pureSwiftModule(path.join(tmp, 'expo-asset'), 'ExpoAsset', spec());
4826
+ const builtJsiRoot =
4827
+ versions == null ? null : writeJsiVersions(tmp, headersXCFramework, versions);
4828
+ resolveExpoModules.mockReturnValue(
4829
+ modulesOf([
4830
+ coreAt(core),
4831
+ ...(withJsi ? [['expo-modules-jsi', [['ExpoModulesJSI', jsi]]]] : []),
4832
+ ['expo-asset', [['ExpoAsset', asset]]],
4833
+ ])
4834
+ );
4835
+ // A Debug/Release JSI pair exists, as in a monorepo prebuild or an older package.
4836
+ resolveFlavoredFramework.mockImplementation(({ frameworkName }) =>
4837
+ ['ExpoModulesCore', 'ExpoModulesJSI'].includes(frameworkName)
4838
+ ? { id: frameworkName, frameworkName }
4839
+ : null
4840
+ );
4841
+ resolveHeadersXCFramework.mockReset();
4842
+ resolveHeadersXCFramework.mockReturnValue(headers === 'resolved' ? headersXCFramework : null);
4843
+ providerWrittenTo(outDir);
4844
+ let result = null;
4845
+ const thrown = thrownBy(() => {
4846
+ result = runPlugin(tmp);
4847
+ });
4848
+ const assetManifest = () =>
4849
+ fs.readFileSync(
4850
+ path.join(outDir, 'expo', 'expo-source', 'ExpoAsset', 'Package.swift'),
4851
+ 'utf8'
4852
+ );
4853
+ return { tmp, outDir, headersXCFramework, builtJsiRoot, result, thrown, assetManifest };
4854
+ }
4855
+
4856
+ afterAll(restoreModuleMocks);
4857
+
4858
+ describe('when expo-modules-jsi is autolinked', () => {
4859
+ let app;
4860
+
4861
+ beforeAll(() => {
4862
+ app = syncApp();
4863
+ });
4864
+
4865
+ it('never links it as a precompiled framework, even when a Debug/Release pair exists', () => {
4866
+ expect(app.thrown).toBeNull();
4867
+ expect(app.result.flavoredFrameworks.map((f) => f.frameworkName)).toEqual([
4868
+ 'ExpoModulesCore',
4869
+ ]);
4870
+ expect(resolvedFor('expo-modules-jsi')).toBeUndefined();
4871
+ });
4872
+
4873
+ it("looks the headers up from the package's own lookup bases, into the plugin cache", () => {
4874
+ expect(resolveHeadersXCFramework).toHaveBeenCalledWith({
4875
+ packageName: 'expo-modules-jsi',
4876
+ moduleRoot: path.join(app.tmp, 'expo-modules-jsi'),
4877
+ productName: 'ExpoModulesJSI',
4878
+ cacheDir: path.join(app.tmp, 'app', 'ios', 'build', 'expo-xcframeworks'),
4879
+ });
4880
+ });
4881
+
4882
+ it('emits the headers package over the resolved XCFramework', () => {
4883
+ const pkgDir = path.join(app.outDir, 'expo', 'ExpoModulesJSIHeaders');
4884
+ expect(fs.readFileSync(path.join(pkgDir, 'Package.swift'), 'utf8')).toContain(
4885
+ '.linkedFramework("ExpoModulesJSI")'
4886
+ );
4887
+ expect(fs.readlinkSync(path.join(pkgDir, 'ExpoModulesJSIHeaders.xcframework'))).toBe(
4888
+ app.headersXCFramework
4889
+ );
4890
+ });
4891
+
4892
+ it('makes every emitted source package depend on the headers package', () => {
4893
+ const pkgDir = path.join(app.outDir, 'expo', 'ExpoModulesJSIHeaders');
4894
+ expect(app.assetManifest()).toContain(
4895
+ `.package(name: "ExpoModulesJSIHeaders", path: "${pkgDir}")`
4896
+ );
4897
+ expect(app.assetManifest()).toContain(
4898
+ '.product(name: "ExpoModulesJSIHeaders", package: "ExpoModulesJSIHeaders")'
4899
+ );
4900
+ });
4901
+
4902
+ it('adds the build phase', () => {
4903
+ expect(app.result.scriptPhases.map((p) => p.id)).toContain('expo-modules-jsi.build');
4904
+ });
4905
+ });
4906
+
4907
+ describe('when its headers are missing everywhere', () => {
4908
+ it('fails the sync, saying what is missing, why it is needed and how to get it', () => {
4909
+ const { thrown } = syncApp({ headers: 'missing' });
4910
+ expect(thrown).toBeInstanceOf(Error);
4911
+ expect(thrown.message).toContain('ExpoModulesJSIHeaders');
4912
+ expect(thrown.message).toMatch(/only the headers/);
4913
+ expect(thrown.message).toMatch(/reinstall/i);
4914
+ expect(thrown.message).toContain(
4915
+ 'From the Expo repository root, build the headers with `node tools/bin/expotools.js prebuild expo-modules-jsi`'
4916
+ );
4917
+ });
4918
+ });
4919
+
4920
+ // The build phase compiles the framework from the installed sources, so headers of another
4921
+ // version leave a source package referencing a symbol the framework lacks.
4922
+ describe('when its headers are stamped with a version', () => {
4923
+ it('fails the sync when the autolinked expo-modules-jsi is another version', () => {
4924
+ const app = syncApp({ versions: { headers: '2.0.0', autolinked: '1.0.0', built: '2.0.0' } });
4925
+ expect(app.thrown).toBeInstanceOf(Error);
4926
+ for (const part of [app.headersXCFramework, '2.0.0', '1.0.0']) {
4927
+ expect(app.thrown.message).toContain(part);
4928
+ }
4929
+ expect(app.thrown.message).toContain(path.join(app.tmp, 'expo-modules-jsi'));
4930
+ expect(app.thrown.message).toMatch(/et prebuild expo-modules-jsi/);
4931
+ });
4932
+
4933
+ it('fails the sync when the copy the build phase builds is another version', () => {
4934
+ const app = syncApp({ versions: { headers: '1.0.0', autolinked: '1.0.0', built: '1.1.0' } });
4935
+ expect(app.thrown).toBeInstanceOf(Error);
4936
+ expect(app.thrown.message).toContain(app.builtJsiRoot);
4937
+ expect(app.thrown.message).toContain('1.1.0');
4938
+ });
4939
+
4940
+ it('syncs when every copy is that version', () => {
4941
+ const app = syncApp({ versions: { headers: '1.0.0', autolinked: '1.0.0', built: '1.0.0' } });
4942
+ expect(app.thrown).toBeNull();
4943
+ });
4944
+ });
4945
+
4946
+ describe('when expo-modules-jsi is not autolinked', () => {
4947
+ let app;
4948
+
4949
+ beforeAll(() => {
4950
+ app = syncApp({ withJsi: false });
4951
+ });
4952
+
4953
+ it('adds no headers package, no dependency on one and no build phase', () => {
4954
+ expect(app.thrown).toBeNull();
4955
+ expect(resolveHeadersXCFramework).not.toHaveBeenCalled();
4956
+ expect(fs.existsSync(path.join(app.outDir, 'expo', 'ExpoModulesJSIHeaders'))).toBe(false);
4957
+ expect(app.assetManifest()).not.toContain('ExpoModulesJSIHeaders');
4958
+ expect(app.result.scriptPhases.map((p) => p.id)).not.toContain('expo-modules-jsi.build');
4959
+ });
4960
+ });
4961
+ });