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.
@@ -18,7 +18,9 @@ const {
18
18
  renderRootConflictWarning,
19
19
  renderPartlyProvidedPackageWarning,
20
20
  renderExtraPodsWarning,
21
+ renderBuildFromSourceFallbackWarning,
21
22
  } = require('../diagnostics');
23
+ const { spmUpdateCommand } = require('../commands');
22
24
  const { resolvePodIdentities, uncoveredPod } = require('../plugin');
23
25
  const { podspecDependencies } = require('../podspec');
24
26
 
@@ -164,6 +166,198 @@ describe('diagnostic priority order', () => {
164
166
  });
165
167
  });
166
168
 
169
+ describe('a pod buildFromSource names that cannot be built from source', () => {
170
+ const subject = { podName: 'ExpoBad', packageName: 'expo-bad', moduleRoot: '/m/expo-bad' };
171
+ const forced = (refusal, hasSources = true) => ({
172
+ ...pendingPod({
173
+ ...subject,
174
+ hasSources,
175
+ prebuildProduct: { name: 'ExpoBad', sourceOnly: false },
176
+ refusal,
177
+ }),
178
+ buildFromSourceEntry: 'expo-b.*',
179
+ });
180
+ const classify = (pod) => classifyUnsupported({ pending: [pod], coreAvailable: true });
181
+ const podspecLinkage = {
182
+ reason: 'needs-manifest-for-linkage',
183
+ file: '/m/expo-bad/ios/ExpoBad.podspec',
184
+ line: 19,
185
+ snippet: "s.frameworks = 'Photos'",
186
+ };
187
+
188
+ it('is refused for buildFromSource, with what blocks the source build as the cause', () => {
189
+ expect(classify(forced(null))).toEqual([
190
+ {
191
+ ...subject,
192
+ reason: 'build-from-source-unsupported',
193
+ buildFromSourceEntry: 'expo-b.*',
194
+ cause: { reason: 'mixed-no-manifest', productName: 'ExpoBad' },
195
+ },
196
+ ]);
197
+ });
198
+
199
+ it('takes the most specific cause', () => {
200
+ expect(classify(forced(podspecLinkage))[0].cause).toEqual(podspecLinkage);
201
+ });
202
+
203
+ const report = (refusal, hasSources) =>
204
+ renderUnsupportedReport(classify(forced(refusal, hasSources)));
205
+
206
+ it('says what failed, and how to use the precompiled XCFramework instead', () => {
207
+ const text = report(null);
208
+ expect(text).toContain(
209
+ 'error: Expo module "expo-bad" (pod ExpoBad) is listed in buildFromSource, but Swift Package Manager cannot build it from source.'
210
+ );
211
+ expect(text).toContain(
212
+ `Remove "expo-b.*" from \`"expo": { "autolinking": { "buildFromSource": [...] } }\` (or its \`"ios"\` section) in your package.json, or narrow it so it no longer matches ExpoBad or expo-bad. The module's precompiled XCFramework is then used. Then run \`${spmUpdateCommand()}\` from your app directory again.`
213
+ );
214
+ expect(text).toContain('Module path: /m/expo-bad');
215
+ expect(text).not.toContain('prebuild');
216
+ });
217
+
218
+ it.each([
219
+ [
220
+ 'mixed sources and no manifest',
221
+ null,
222
+ true,
223
+ 'It mixes Swift and Objective-C/C++ sources and ships no Package.swift, and Swift Package Manager can build such a module only from a manifest that splits the two languages into separate targets.',
224
+ ],
225
+ [
226
+ 'no sources',
227
+ null,
228
+ false,
229
+ 'It has no `ios` or `apple` source directory for Swift Package Manager to compile.',
230
+ ],
231
+ [
232
+ 'linkage in its podspec',
233
+ podspecLinkage,
234
+ true,
235
+ 'Its podspec declares native linkage at /m/expo-bad/ios/ExpoBad.podspec:19, and it ships no Package.swift stating that linkage, so a package built from its sources would link less than CocoaPods does.',
236
+ ],
237
+ [
238
+ 'a manifest target dependency',
239
+ {
240
+ reason: 'unsupported-target-dependency',
241
+ dependencies: [{ target: 'ExpoBad', dependsOn: 'VendoredKit', kind: 'binary' }],
242
+ },
243
+ true,
244
+ 'Its Package.swift has targets depending on "VendoredKit", which the package generated from it cannot declare.',
245
+ ],
246
+ [
247
+ 'a manifest package dependency',
248
+ { reason: 'unsupported-package-dependency', dependencies: [] },
249
+ true,
250
+ 'Its Package.swift declares Swift packages the package generated from it cannot declare.',
251
+ ],
252
+ [
253
+ 'manifest targets without sources',
254
+ { reason: 'unresolvable-target-path', targetNames: ['Main', 'Extras'] },
255
+ true,
256
+ 'Its Package.swift names targets with no sources on disk: "Main", "Extras".',
257
+ ],
258
+ [
259
+ 'a manifest that does not export the product',
260
+ { reason: 'not-exported-by-manifest', productName: 'ExpoBad', exportedProducts: [] },
261
+ true,
262
+ 'Its Package.swift exports no "ExpoBad" library product.',
263
+ ],
264
+ [
265
+ 'precompiled sibling pods',
266
+ {
267
+ reason: 'partially-precompiled',
268
+ precompiledSiblings: ['ExpoGood'],
269
+ precompiledProducts: ['ExpoGood'],
270
+ artifactDirs: [],
271
+ },
272
+ true,
273
+ 'Other pods of the module are linked precompiled (ExpoGood), and building the module from source would link them a second time.',
274
+ ],
275
+ ])('names the cause: %s', (_, refusal, hasSources, why) => {
276
+ expect(report(refusal, hasSources)).toContain(why);
277
+ });
278
+
279
+ it('gives a cause it has no description for a generic line, naming the reason', () => {
280
+ const text = renderUnsupportedReport([
281
+ {
282
+ ...subject,
283
+ reason: 'build-from-source-unsupported',
284
+ buildFromSourceEntry: 'ExpoBad',
285
+ cause: { reason: 'some-future-reason' },
286
+ },
287
+ ]);
288
+ expect(text).toContain(
289
+ 'The plugin found no way to build it from source with Swift Package Manager (reason: some-future-reason).'
290
+ );
291
+ expect(text).toContain('Remove "ExpoBad" from');
292
+ });
293
+
294
+ describe('when a pattern links it precompiled and its XCFramework is incomplete', () => {
295
+ const incomplete = { ...forced(null), precompiledIncomplete: true };
296
+
297
+ it('is refused naming the entry, with what blocks the source build as the cause', () => {
298
+ expect(classify(incomplete)).toEqual([
299
+ {
300
+ ...subject,
301
+ reason: 'build-from-source-fallback-incomplete',
302
+ buildFromSourceEntry: 'expo-b.*',
303
+ cause: { reason: 'mixed-no-manifest', productName: 'ExpoBad' },
304
+ },
305
+ ]);
306
+ });
307
+
308
+ it('says what failed, why, and how to complete the XCFramework', () => {
309
+ expect(renderUnsupportedReport(classify(incomplete))).toBe(
310
+ [
311
+ 'error: The buildFromSource entry "expo-b.*" matches Expo module "expo-bad" (pod ExpoBad), which Swift Package Manager cannot build from source, and its precompiled XCFramework is incomplete, so it cannot be linked precompiled either.',
312
+ ' It mixes Swift and Objective-C/C++ sources and ships no Package.swift, and Swift Package Manager can build such a module only from a manifest that splits the two languages into separate targets.',
313
+ ' A buildFromSource pattern links a module precompiled when Swift Package Manager cannot build it from source, and the plugin links a precompiled XCFramework only when both its Debug and Release flavors are present.',
314
+ ` Reinstall expo-bad so it ships both flavors, or, in the Expo repository, from its root, build both with \`node tools/bin/expotools.js prebuild expo-bad\`. Then run \`${spmUpdateCommand()}\` from your app directory again.`,
315
+ ' Module path: /m/expo-bad',
316
+ ].join('\n')
317
+ );
318
+ });
319
+ });
320
+
321
+ it('counts the pod once', () => {
322
+ expect(new UnsupportedModulesError(classify(forced(null))).message).toMatch(
323
+ /^1 Expo native module /
324
+ );
325
+ });
326
+ });
327
+
328
+ describe('modules a buildFromSource pattern matches that are linked precompiled instead', () => {
329
+ const option =
330
+ '`"expo": { "autolinking": { "buildFromSource": [...] } }` (or its `"ios"` section) in your package.json';
331
+ const core = { podName: 'ExpoModulesCore', packageName: 'expo-modules-core', entry: '.*' };
332
+
333
+ it('renders nothing when no module fell back', () => {
334
+ expect(renderBuildFromSourceFallbackWarning([])).toBe('');
335
+ });
336
+
337
+ it('names the module and the entry that matched it', () => {
338
+ expect(renderBuildFromSourceFallbackWarning([core])).toBe(
339
+ 'warning: buildFromSource matches 1 Expo module that Swift Package Manager cannot build from source, so it is linked precompiled instead: ExpoModulesCore (expo-modules-core, matched by ".*"). ' +
340
+ 'A buildFromSource pattern links a module precompiled when Swift Package Manager cannot build that module from source; an entry that names a module exactly fails the sync instead. ' +
341
+ `To see what blocks a module's source build, list it by its exact pod or npm package name in ${option}: the sync then fails and names the cause. ` +
342
+ `To keep it precompiled without this warning, narrow ".*" so that no entry matches this module. Then run \`${spmUpdateCommand()}\` from your app directory again.`
343
+ );
344
+ });
345
+
346
+ it('names every module, and each entry once', () => {
347
+ const text = renderBuildFromSourceFallbackWarning([
348
+ core,
349
+ { podName: 'ExpoMixed', packageName: 'expo-mixed', entry: 'expo-.*' },
350
+ { podName: 'ExpoOther', packageName: 'expo-other', entry: 'expo-.*' },
351
+ ]);
352
+ expect(text).toContain(
353
+ 'buildFromSource matches 3 Expo modules that Swift Package Manager cannot build from source, so they are linked precompiled instead: ExpoModulesCore (expo-modules-core, matched by ".*"), ExpoMixed (expo-mixed, matched by "expo-.*"), ExpoOther (expo-other, matched by "expo-.*").'
354
+ );
355
+ expect(text).toContain(
356
+ 'To keep them precompiled without this warning, narrow ".*", "expo-.*" so that no entry matches these modules.'
357
+ );
358
+ });
359
+ });
360
+
167
361
  describe('linkage declared in a podspec', () => {
168
362
  const podspecLinkage = {
169
363
  file: '/m/expo-bad/ios/ExpoBad.podspec',
@@ -305,7 +499,7 @@ describe('renderUnsupportedReport', () => {
305
499
  expect(text.split('\n').filter((l) => l.startsWith('error: '))).toHaveLength(2);
306
500
  });
307
501
 
308
- it('tells a prebuildable module to run et prebuild, not to write a manifest', () => {
502
+ it('tells a prebuildable module to run the prebuild command, not to write a manifest', () => {
309
503
  const text = renderUnsupportedReport([
310
504
  {
311
505
  reason: 'prebuild-available',
@@ -316,14 +510,15 @@ describe('renderUnsupportedReport', () => {
316
510
  },
317
511
  ]);
318
512
  expect(text).toContain('error: ');
319
- // `et prebuild` builds both flavors when --flavor is omitted, and the plugin
513
+ // The prebuild command builds both flavors when --flavor is omitted, and the plugin
320
514
  // requires a complete pair — so the message must not suggest a single flavor.
321
- expect(text).toContain('et prebuild expo-audio');
515
+ expect(text).toContain('node tools/bin/expotools.js prebuild expo-audio');
516
+ expect(text).toMatch(/in the Expo repository, from its root/i);
322
517
  expect(text).not.toContain('-f Debug');
323
518
  expect(text).not.toContain('patch-package');
324
519
  });
325
520
 
326
- it('names the scoped package verbatim, which et prebuild accepts', () => {
521
+ it('names the scoped package verbatim, which the prebuild command accepts', () => {
327
522
  const text = renderUnsupportedReport([
328
523
  {
329
524
  reason: 'prebuild-available',
@@ -333,7 +528,7 @@ describe('renderUnsupportedReport', () => {
333
528
  productName: 'ExpoUI',
334
529
  },
335
530
  ]);
336
- expect(text).toContain('et prebuild @expo/ui');
531
+ expect(text).toContain('node tools/bin/expotools.js prebuild @expo/ui');
337
532
  });
338
533
 
339
534
  it('offers spm.config.json as a route for a module that has none', () => {
@@ -349,7 +544,13 @@ describe('renderUnsupportedReport', () => {
349
544
  ]);
350
545
  expect(text).toContain('error: ');
351
546
  expect(text).toContain('ExpoModulesCore');
352
- expect(text).toContain('et prebuild');
547
+ expect(text).toContain(
548
+ 'node tools/bin/expotools.js prebuild -f Debug expo-modules-core expo-modules-jsi'
549
+ );
550
+ expect(text).toContain(
551
+ 'node tools/bin/expotools.js prebuild -f Release expo-modules-core expo-modules-jsi'
552
+ );
553
+ expect(text).toMatch(/in the Expo repository, from its root/i);
353
554
  expect(text).not.toContain('patch-package');
354
555
  });
355
556
 
@@ -763,6 +964,7 @@ describe('a module installed twice', () => {
763
964
  expect(report).toContain('/app/node_modules/some-lib/node_modules/expo-camera');
764
965
  expect(report).toContain('npm ls expo-camera');
765
966
  expect(report).toContain('dedupe');
967
+ expect(report).toContain(spmUpdateCommand());
766
968
  expect(report).toContain("your app's JavaScript imports the second");
767
969
  expect(report).toContain('usually surfaces at runtime');
768
970
  expect(report).toContain('can fail the build');
@@ -1209,7 +1411,8 @@ describe('a module with only some pods precompiled', () => {
1209
1411
  expect(report).toMatch(/^error: Expo module "expo-dual" \(pod ExpoDualExtras\)/);
1210
1412
  expect(report).toContain('ExpoDual ');
1211
1413
  expect(report).toContain('twice');
1212
- expect(report).toContain('et prebuild expo-dual');
1414
+ expect(report).toContain('node tools/bin/expotools.js prebuild expo-dual');
1415
+ expect(report).toMatch(/in the Expo repository, from its root/i);
1213
1416
  expect(report).toContain('spm.config.json');
1214
1417
  expect(report).toContain('"exclude": ["expo-dual"]');
1215
1418
  expect(report).toContain('Module path: /node_modules/expo-dual');
@@ -1248,7 +1451,7 @@ describe('a module with only some pods precompiled', () => {
1248
1451
  entries({ prebuildProduct: { name: 'ExpoDualExtras', sourceOnly: false } })
1249
1452
  );
1250
1453
  expect(report).toContain('already declares "ExpoDualExtras"');
1251
- expect(report).toContain('et prebuild expo-dual');
1454
+ expect(report).toContain('node tools/bin/expotools.js prebuild expo-dual');
1252
1455
  });
1253
1456
 
1254
1457
  it('does not promise an XCFramework for a source-only product', () => {
@@ -1256,7 +1459,7 @@ describe('a module with only some pods precompiled', () => {
1256
1459
  entries({ prebuildProduct: { name: 'ExpoDualExtras', sourceOnly: true } })
1257
1460
  );
1258
1461
  expect(report).toContain('sourceOnly');
1259
- expect(report).not.toContain('et prebuild');
1462
+ expect(report).not.toContain('expotools.js prebuild');
1260
1463
  expect(report).toMatch(/^ {2}1\. To build it from source instead/m);
1261
1464
  });
1262
1465
  });
@@ -0,0 +1,387 @@
1
+ 'use strict';
2
+
3
+ const fs = require('fs');
4
+ const os = require('os');
5
+ const path = require('path');
6
+
7
+ jest.mock('../cli', () => ({
8
+ runDumpPackage: jest.fn(() =>
9
+ JSON.stringify({ name: 'ExpoHaptics', products: [{ name: 'ExpoHaptics' }] })
10
+ ),
11
+ }));
12
+
13
+ const { runDumpPackage } = require('../cli');
14
+ const {
15
+ dependsOnCoreHeaders,
16
+ dumpModuleManifest,
17
+ emitDirectPackage,
18
+ prepareDirectWatchPaths,
19
+ } = require('../direct');
20
+ const { rerunSpmUpdate, thrownBy } = require('./helpers');
21
+
22
+ const hapticsManifest = {
23
+ name: 'expo-haptics',
24
+ products: [{ name: 'ExpoHaptics' }, { name: 'ExpoHapticsExtras' }],
25
+ };
26
+
27
+ /** A dumped manifest whose one target depends on `dependencies`. */
28
+ const manifestDependingOn = (...dependencies) => ({
29
+ name: 'expo-haptics',
30
+ products: [{ name: 'ExpoHaptics' }],
31
+ targets: [{ name: 'ExpoHaptics', type: 'regular', dependencies }],
32
+ });
33
+
34
+ describe('dependsOnCoreHeaders', () => {
35
+ // Verbatim shape from `swift package dump-package` (Swift 6.4) of a manifest with
36
+ // `.product(name: "ExpoModulesCoreHeaders", package: "ExpoModulesCoreHeaders")`.
37
+ const coreHeadersProduct = {
38
+ product: ['ExpoModulesCoreHeaders', 'ExpoModulesCoreHeaders', null, null],
39
+ };
40
+
41
+ it('is true when a target depends on the ExpoModulesCoreHeaders product', () => {
42
+ expect(
43
+ dependsOnCoreHeaders({
44
+ ...manifestDependingOn(),
45
+ targets: [
46
+ { name: 'ExpoHapticsObjC', type: 'regular', dependencies: [] },
47
+ { name: 'ExpoHaptics', type: 'regular', dependencies: [coreHeadersProduct] },
48
+ ],
49
+ })
50
+ ).toBe(true);
51
+ });
52
+
53
+ // `.byName(name:)` and a bare string both dump as `byName`; SwiftPM resolves the name to
54
+ // a product of a package dependency when no target has it.
55
+ it.each([
56
+ ['without a condition', { byName: ['ExpoModulesCoreHeaders', null] }],
57
+ ['with a condition', { byName: ['ExpoModulesCoreHeaders', { platformNames: ['ios'] }] }],
58
+ ])('is true for a dependency by name %s', (_, dependency) => {
59
+ expect(dependsOnCoreHeaders(manifestDependingOn(dependency))).toBe(true);
60
+ });
61
+
62
+ it.each([
63
+ ['no target dependencies', manifestDependingOn()],
64
+ ['a dependency on another name', manifestDependingOn({ byName: ['ExpoModulesCore', null] })],
65
+ [
66
+ 'another product',
67
+ manifestDependingOn({ product: ['ExpoModulesCore', 'ExpoModulesCore', null, null] }),
68
+ ],
69
+ ['a target of that name', manifestDependingOn({ target: ['ExpoModulesCoreHeaders', null] })],
70
+ [
71
+ 'only a package dependency',
72
+ {
73
+ ...manifestDependingOn(),
74
+ dependencies: [{ fileSystem: [{ identity: 'expomodulescoreheaders' }] }],
75
+ },
76
+ ],
77
+ ['no targets', { name: 'expo-haptics', products: [] }],
78
+ ])('is false for a manifest with %s', (_, manifest) => {
79
+ expect(dependsOnCoreHeaders(manifest)).toBe(false);
80
+ });
81
+ });
82
+
83
+ describe('dumpModuleManifest', () => {
84
+ const moduleRoot = path.join(os.tmpdir(), 'expo-haptics');
85
+ const dump = () => dumpModuleManifest(moduleRoot, 'expo-haptics');
86
+
87
+ it('returns the JSON the tool printed and its parse', () => {
88
+ const json = JSON.stringify(hapticsManifest);
89
+ runDumpPackage.mockReturnValueOnce(json);
90
+ expect(dump()).toEqual({ json, manifest: hapticsManifest });
91
+ expect(runDumpPackage).toHaveBeenLastCalledWith(moduleRoot);
92
+ });
93
+
94
+ describe('when the Package.swift cannot be evaluated', () => {
95
+ const failWith = (error) =>
96
+ runDumpPackage.mockImplementationOnce(() => {
97
+ throw error;
98
+ });
99
+
100
+ it('names the package, the first line the tool printed, and how to fix it', () => {
101
+ const error = Object.assign(new Error('Command failed: swift package dump-package'), {
102
+ status: 1,
103
+ stderr: '\nerror: Invalid manifest\nPackage.swift:3:1: error: expected expression\n',
104
+ });
105
+ failWith(error);
106
+ const thrown = thrownBy(dump);
107
+ expect(thrown.message).toContain(
108
+ "expo-haptics's Package.swift could not be evaluated: error: Invalid manifest."
109
+ );
110
+ expect(thrown.message).toContain('`swift package dump-package`');
111
+ expect(thrown.message).toContain(moduleRoot);
112
+ expect(thrown.message).toContain('xcode-select');
113
+ expect(thrown.message).toContain(rerunSpmUpdate);
114
+ expect(thrown.cause).toBe(error);
115
+ });
116
+
117
+ it('says the swift command was not found when it is missing', () => {
118
+ failWith(Object.assign(new Error('spawnSync swift ENOENT'), { code: 'ENOENT' }));
119
+ expect(thrownBy(dump).message).toContain(
120
+ "expo-haptics's Package.swift could not be evaluated: the swift command was not found."
121
+ );
122
+ });
123
+
124
+ it('says what the tool printed is not a manifest', () => {
125
+ runDumpPackage.mockReturnValueOnce('warning: not JSON');
126
+ const thrown = thrownBy(dump);
127
+ expect(thrown.message).toContain("expo-haptics's Package.swift could not be evaluated:");
128
+ expect(thrown.cause).toBeInstanceOf(SyntaxError);
129
+ });
130
+ });
131
+ });
132
+
133
+ describe('emitDirectPackage', () => {
134
+ const savedBuildDir = process.env.BUILD_DIR;
135
+ let root;
136
+ let outDir;
137
+ let pkgDir;
138
+ let coreHeadersXCFramework;
139
+ let jsiHeadersPkgPath;
140
+
141
+ const emit = () =>
142
+ emitDirectPackage({
143
+ moduleRoot: path.join(root, 'expo-haptics'),
144
+ packageName: 'expo-haptics',
145
+ outDir,
146
+ coreHeadersXCFramework,
147
+ jsiHeadersPkgPath,
148
+ macroTool: path.join(root, 'ExpoModulesMacros'),
149
+ manifest: hapticsManifest,
150
+ });
151
+ const manifest = () => fs.readFileSync(path.join(pkgDir, 'Package.swift'), 'utf8');
152
+
153
+ beforeEach(() => {
154
+ delete process.env.BUILD_DIR;
155
+ root = fs.mkdtempSync(path.join(os.tmpdir(), 'direct-emit-'));
156
+ outDir = path.join(root, 'out');
157
+ pkgDir = path.join(outDir, 'direct', 'ExpoModulesCoreHeaders');
158
+ jsiHeadersPkgPath = path.join(outDir, 'ExpoModulesJSIHeaders');
159
+ fs.mkdirSync(path.join(root, 'expo-haptics'));
160
+ coreHeadersXCFramework = path.join(
161
+ root,
162
+ 'expo-modules-core',
163
+ 'headers',
164
+ 'ExpoModulesCoreHeaders.xcframework'
165
+ );
166
+ fs.mkdirSync(coreHeadersXCFramework, { recursive: true });
167
+ fs.writeFileSync(path.join(coreHeadersXCFramework, 'Info.plist'), '<plist/>');
168
+ });
169
+
170
+ afterEach(() => {
171
+ fs.rmSync(root, { recursive: true, force: true });
172
+ if (savedBuildDir === undefined) {
173
+ delete process.env.BUILD_DIR;
174
+ } else {
175
+ process.env.BUILD_DIR = savedBuildDir;
176
+ }
177
+ });
178
+
179
+ it('declares one product over the ExpoModulesCore headers binary target', () => {
180
+ emit();
181
+ expect(manifest().match(/\.binaryTarget\(/g)).toHaveLength(1);
182
+ expect(manifest()).toContain(
183
+ '.binaryTarget(name: "ExpoModulesCoreHeaders", path: "ExpoModulesCoreHeaders.xcframework")'
184
+ );
185
+ expect(manifest().match(/\.library\(/g)).toHaveLength(1);
186
+ expect(manifest()).toMatch(
187
+ /\.library\(name: "ExpoModulesCoreHeaders", targets: \["ExpoModulesCoreHeaders"/
188
+ );
189
+ });
190
+
191
+ // The ExpoModulesJSI headers package declares that target too, and SwiftPM rejects a
192
+ // graph with two targets of one name.
193
+ it('declares no ExpoModulesJSIHeaders target, and depends on the JSI headers package by path', () => {
194
+ emit();
195
+ expect(manifest()).not.toMatch(/\.(binaryTarget|target)\(name: "ExpoModulesJSIHeaders"/);
196
+ expect(manifest()).toContain(
197
+ '.package(name: "ExpoModulesJSIHeaders", path: "../../ExpoModulesJSIHeaders")'
198
+ );
199
+ expect(manifest()).toContain(
200
+ '.product(name: "ExpoModulesJSIHeaders", package: "ExpoModulesJSIHeaders")'
201
+ );
202
+ });
203
+
204
+ it('fails, writing no package, when there is no JSI headers package', () => {
205
+ jsiHeadersPkgPath = null;
206
+ expect(emit).toThrow(
207
+ 'expo-haptics is built from its own Package.swift and needs the ExpoModulesJSI headers, but expo-modules-jsi is not autolinked.'
208
+ );
209
+ expect(emit).toThrow('re-export ExpoModulesJSI');
210
+ expect(emit).toThrow('"expo": { "autolinking": { "exclude": [...] } }');
211
+ expect(emit).toThrow(rerunSpmUpdate);
212
+ expect(fs.existsSync(path.join(outDir, 'direct'))).toBe(false);
213
+ });
214
+
215
+ it('places the ExpoModulesCore headers xcframework in the package by link', () => {
216
+ emit();
217
+ const link = path.join(pkgDir, 'ExpoModulesCoreHeaders.xcframework');
218
+ expect(fs.lstatSync(link).isSymbolicLink()).toBe(true);
219
+ expect(fs.realpathSync(link)).toBe(fs.realpathSync(coreHeadersXCFramework));
220
+ expect(fs.existsSync(path.join(pkgDir, 'ExpoModulesJSIHeaders.xcframework'))).toBe(false);
221
+ });
222
+
223
+ it('replaces the xcframework an earlier plugin generated in the package', () => {
224
+ const generated = path.join(pkgDir, 'ExpoModulesCoreHeaders.xcframework');
225
+ fs.mkdirSync(path.join(generated, 'ios-arm64'), { recursive: true });
226
+ emit();
227
+ expect(fs.realpathSync(generated)).toBe(fs.realpathSync(coreHeadersXCFramework));
228
+ });
229
+
230
+ it('removes the stubs directory an earlier plugin generated in the package', () => {
231
+ const stubs = path.join(pkgDir, '.stubs');
232
+ fs.mkdirSync(path.join(stubs, 'ExpoModulesCore'), { recursive: true });
233
+ emit();
234
+ expect(fs.existsSync(stubs)).toBe(false);
235
+ });
236
+
237
+ it('moves the xcframework link when the ExpoModulesCore headers come from another path', () => {
238
+ emit();
239
+ coreHeadersXCFramework = path.join(root, 'other', 'ExpoModulesCoreHeaders.xcframework');
240
+ fs.mkdirSync(coreHeadersXCFramework, { recursive: true });
241
+ emit();
242
+ const link = path.join(pkgDir, 'ExpoModulesCoreHeaders.xcframework');
243
+ expect(fs.realpathSync(link)).toBe(fs.realpathSync(coreHeadersXCFramework));
244
+ });
245
+
246
+ it('links a scoped package under its scope directory', () => {
247
+ const moduleRoot = path.join(root, 'node_modules', '@acme', 'widgets');
248
+ fs.mkdirSync(moduleRoot, { recursive: true });
249
+ const { ok } = emitDirectPackage({
250
+ moduleRoot,
251
+ packageName: '@acme/widgets',
252
+ outDir,
253
+ coreHeadersXCFramework,
254
+ jsiHeadersPkgPath,
255
+ macroTool: path.join(root, 'ExpoModulesMacros'),
256
+ manifest: hapticsManifest,
257
+ });
258
+ const link = path.join(outDir, 'direct', '@acme', 'widgets');
259
+ expect(ok.packageDep.path).toBe(link);
260
+ expect(fs.realpathSync(link)).toBe(fs.realpathSync(moduleRoot));
261
+ });
262
+
263
+ // That package is written under its SwiftPM package name, which need not be the npm name.
264
+ it('removes the package an earlier sync generated from the manifest', () => {
265
+ const generated = path.join(outDir, 'expo-source', 'ExpoHapticsPackage');
266
+ fs.mkdirSync(generated, { recursive: true });
267
+ fs.writeFileSync(path.join(generated, 'Package.swift'), '// generated\n');
268
+ emitDirectPackage({
269
+ moduleRoot: path.join(root, 'expo-haptics'),
270
+ packageName: 'expo-haptics',
271
+ outDir,
272
+ coreHeadersXCFramework,
273
+ jsiHeadersPkgPath,
274
+ macroTool: path.join(root, 'ExpoModulesMacros'),
275
+ manifest: { ...hapticsManifest, name: 'ExpoHapticsPackage' },
276
+ });
277
+ expect(fs.existsSync(generated)).toBe(false);
278
+ });
279
+
280
+ it('links the products of the manifest it is given, without dumping it again', () => {
281
+ runDumpPackage.mockClear();
282
+ const { ok } = emit();
283
+ expect(runDumpPackage).not.toHaveBeenCalled();
284
+ expect(ok.packageDep).toEqual({
285
+ name: 'expo-haptics',
286
+ path: path.join(outDir, 'direct', 'expo-haptics'),
287
+ });
288
+ expect(ok.productDeps).toEqual([
289
+ { name: 'ExpoHaptics', package: 'expo-haptics' },
290
+ { name: 'ExpoHapticsExtras', package: 'expo-haptics' },
291
+ ]);
292
+ });
293
+
294
+ it('changes no file in the package when emitted again with the same inputs', () => {
295
+ emit();
296
+ const snapshot = () =>
297
+ fs
298
+ .readdirSync(pkgDir, { recursive: true })
299
+ .sort()
300
+ .map((entry) => {
301
+ const stat = fs.lstatSync(path.join(pkgDir, entry), { bigint: true });
302
+ return [entry, stat.ino, stat.mtimeNs];
303
+ });
304
+ const first = snapshot();
305
+ emit();
306
+ expect(snapshot()).toEqual(first);
307
+ });
308
+ });
309
+
310
+ describe('prepareDirectWatchPaths', () => {
311
+ const savedBuildDir = process.env.BUILD_DIR;
312
+ let outDir;
313
+ beforeEach(() => {
314
+ outDir = fs.mkdtempSync(path.join(os.tmpdir(), 'direct-watch-'));
315
+ });
316
+ afterEach(() => {
317
+ fs.rmSync(outDir, { recursive: true, force: true });
318
+ if (savedBuildDir === undefined) {
319
+ delete process.env.BUILD_DIR;
320
+ } else {
321
+ process.env.BUILD_DIR = savedBuildDir;
322
+ }
323
+ });
324
+
325
+ // Clean Build Folder deletes the macro plugin link while RN's sync stamp survives.
326
+ // A watched path that has vanished makes RN re-sync then.
327
+ it('watches the macro plugin link when a direct module is emitted', () => {
328
+ process.env.BUILD_DIR = '/tmp/Build/Products';
329
+ expect(prepareDirectWatchPaths(['expo-haptics'], outDir)).toEqual([
330
+ path.join('/tmp/Build/Products', 'ExpoModulesMacros'),
331
+ ]);
332
+ });
333
+
334
+ it('watches nothing when no direct module is emitted', () => {
335
+ process.env.BUILD_DIR = '/tmp/Build/Products';
336
+ expect(prepareDirectWatchPaths([], outDir)).toEqual([]);
337
+ delete process.env.BUILD_DIR;
338
+ expect(prepareDirectWatchPaths([], outDir)).toEqual([]);
339
+ });
340
+
341
+ // A command-line sync has no BUILD_DIR, so it cannot create the link, yet it writes a
342
+ // fresh stamp. RN keeps only watched paths that exist and re-syncs when one is newer
343
+ // than the stamp, so the marker must exist and stay newer than any later stamp.
344
+ it('forces the next build to sync when sync runs outside a build', () => {
345
+ delete process.env.BUILD_DIR;
346
+ const watched = prepareDirectWatchPaths(['expo-haptics'], outDir);
347
+ expect(watched).toHaveLength(1);
348
+ expect(fs.existsSync(watched[0])).toBe(true);
349
+ expect(fs.statSync(watched[0]).mtimeMs).toBeGreaterThan(Date.now() + 365 * 24 * 3600 * 1000);
350
+ });
351
+
352
+ it('leaves the marker untouched when a later sync outside a build finds it in place', () => {
353
+ delete process.env.BUILD_DIR;
354
+ prepareDirectWatchPaths(['expo-haptics'], outDir);
355
+ const writes = [jest.spyOn(fs, 'writeFileSync'), jest.spyOn(fs, 'utimesSync')];
356
+ try {
357
+ prepareDirectWatchPaths(['expo-haptics'], outDir);
358
+ for (const write of writes) expect(write).not.toHaveBeenCalled();
359
+ } finally {
360
+ for (const write of writes) write.mockRestore();
361
+ }
362
+ });
363
+
364
+ it('dates the marker in the future again when its date has changed', () => {
365
+ delete process.env.BUILD_DIR;
366
+ const [marker] = prepareDirectWatchPaths(['expo-haptics'], outDir);
367
+ const now = new Date();
368
+ fs.utimesSync(marker, now, now);
369
+ prepareDirectWatchPaths(['expo-haptics'], outDir);
370
+ expect(fs.statSync(marker).mtimeMs).toBeGreaterThan(Date.now() + 365 * 24 * 3600 * 1000);
371
+ });
372
+
373
+ it('removes the marker once no direct module is emitted', () => {
374
+ delete process.env.BUILD_DIR;
375
+ const [marker] = prepareDirectWatchPaths(['expo-haptics'], outDir);
376
+ prepareDirectWatchPaths([], outDir);
377
+ expect(fs.existsSync(marker)).toBe(false);
378
+ });
379
+
380
+ it('removes the marker once a sync runs inside a build', () => {
381
+ delete process.env.BUILD_DIR;
382
+ const [marker] = prepareDirectWatchPaths(['expo-haptics'], outDir);
383
+ process.env.BUILD_DIR = '/tmp/Build/Products';
384
+ prepareDirectWatchPaths(['expo-haptics'], outDir);
385
+ expect(fs.existsSync(marker)).toBe(false);
386
+ });
387
+ });