expo 58.0.26 → 58.1.0

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.
@@ -1825,6 +1825,7 @@ describe('where precompiled modules and headers come from', () => {
1825
1825
  const packageOf = {
1826
1826
  ExpoModulesCore: 'expo-modules-core',
1827
1827
  ExpoModulesJSI: 'expo-modules-jsi',
1828
+ ExpoModulesWorklets: 'expo-modules-core',
1828
1829
  ExpoFont: 'expo-font',
1829
1830
  };
1830
1831
  const sourceAt = (kind, frameworkName) => ({
@@ -1842,16 +1843,30 @@ describe('where precompiled modules and headers come from', () => {
1842
1843
  /**
1843
1844
  * Syncs an app with expo-modules-jsi autolinked, the `frameworks` precompiled from the
1844
1845
  * 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
+ * headers of each product come from (null for headers that are not found). The direct
1847
+ * module's manifest is `manifest`, by default one depending on the ExpoModulesCore headers.
1848
+ * The products in `mixed` have Objective-C sources, and `buildFromSource` is the app's option.
1846
1849
  */
1847
- function sync({ frameworks, headers, react = null }) {
1850
+ function sync({
1851
+ frameworks,
1852
+ headers,
1853
+ manifest = dumpedManifest('expo-haptics', 'ExpoHaptics', { onCoreHeaders: true }),
1854
+ mixed = [],
1855
+ buildFromSource,
1856
+ react = null,
1857
+ }) {
1848
1858
  const tmp = makeTempDir('expo-spm-plugin-sources-');
1849
1859
  const listed = Object.keys({ ...frameworks, ExpoModulesJSI: null }).map((frameworkName) => [
1850
1860
  packageOf[frameworkName],
1851
1861
  [
1852
1862
  [
1853
1863
  frameworkName,
1854
- pureSwiftModule(path.join(tmp, packageOf[frameworkName]), frameworkName, spec()),
1864
+ mixed.includes(frameworkName)
1865
+ ? mixedModule(
1866
+ path.join(tmp, `${packageOf[frameworkName]}-${frameworkName}`),
1867
+ frameworkName
1868
+ )
1869
+ : pureSwiftModule(path.join(tmp, packageOf[frameworkName]), frameworkName, spec()),
1855
1870
  ],
1856
1871
  ],
1857
1872
  ]);
@@ -1859,9 +1874,7 @@ describe('where precompiled modules and headers come from', () => {
1859
1874
  const haptics = path.join(tmp, 'expo-haptics');
1860
1875
  const podspecDir = pureSwiftModule(haptics, 'ExpoHaptics', spec());
1861
1876
  fs.writeFileSync(path.join(haptics, 'Package.swift'), '// swift-tools-version: 6.0\n');
1862
- runDumpPackage.mockReturnValue(
1863
- dumpedManifest('expo-haptics', 'ExpoHaptics', { onCoreHeaders: true })
1864
- );
1877
+ runDumpPackage.mockReturnValue(manifest);
1865
1878
  listed.push(['expo-haptics', [['ExpoHaptics', podspecDir]]]);
1866
1879
  resolveHeadersXCFrameworkWithSource.mockImplementation(({ productName }) =>
1867
1880
  headers[productName] == null
@@ -1880,7 +1893,10 @@ describe('where precompiled modules and headers come from', () => {
1880
1893
  },
1881
1894
  });
1882
1895
  }
1883
- resolveExpoModules.mockReturnValue(modulesOf(listed));
1896
+ resolveExpoModules.mockReturnValue({
1897
+ ...modulesOf(listed),
1898
+ ...(buildFromSource != null ? { buildFromSource } : {}),
1899
+ });
1884
1900
  resolveFlavoredFramework.mockImplementation(({ frameworkName }) =>
1885
1901
  frameworkName in frameworks ? { id: frameworkName, frameworkName } : null
1886
1902
  );
@@ -2023,7 +2039,9 @@ describe('where precompiled modules and headers come from', () => {
2023
2039
  expect(thrown).toBeNull();
2024
2040
  expect(emitDirectPackage).toHaveBeenCalledWith(
2025
2041
  expect.objectContaining({
2026
- coreHeadersXCFramework: '/abs/ExpoModulesCoreHeaders.xcframework',
2042
+ headersXCFrameworks: {
2043
+ ExpoModulesCoreHeaders: '/abs/ExpoModulesCoreHeaders.xcframework',
2044
+ },
2027
2045
  jsiHeadersPkgPath,
2028
2046
  macrosPackageRoot: expect.any(String),
2029
2047
  })
@@ -2168,6 +2186,159 @@ describe('where precompiled modules and headers come from', () => {
2168
2186
  expect(thrown).toBeNull();
2169
2187
  expect(resolveHeadersXCFrameworkWithSource).not.toHaveBeenCalled();
2170
2188
  });
2189
+
2190
+ describe('for a direct module depending only on the ExpoModulesWorklets headers', () => {
2191
+ const workletsManifest = JSON.stringify({
2192
+ name: 'expo-haptics',
2193
+ dependencies: [{ fileSystem: [{ identity: 'expomodulesworkletsheaders' }] }],
2194
+ products: [
2195
+ { name: 'ExpoHaptics', type: { library: ['automatic'] }, targets: ['ExpoHaptics'] },
2196
+ ],
2197
+ targets: [
2198
+ {
2199
+ name: 'ExpoHaptics',
2200
+ type: 'regular',
2201
+ path: 'ios',
2202
+ dependencies: [
2203
+ { product: ['ExpoModulesWorkletsHeaders', 'ExpoModulesWorkletsHeaders', null, null] },
2204
+ ],
2205
+ },
2206
+ ],
2207
+ });
2208
+ /** The ExpoModulesWorklets binary comes from where ExpoModulesCore does unless `frameworks` says. */
2209
+ const syncWorklets = (frameworks, headers) =>
2210
+ sync({
2211
+ frameworks: { ExpoModulesWorklets: frameworks.ExpoModulesCore, ...frameworks },
2212
+ headers,
2213
+ manifest: workletsManifest,
2214
+ });
2215
+
2216
+ it('hands it the ExpoModulesWorklets headers and the ExpoModulesCore headers they depend on', () => {
2217
+ resolveHeadersXCFrameworkWithSource.mockClear();
2218
+ const { thrown, jsiHeadersPkgPath } = syncWorklets(
2219
+ { ExpoModulesCore: 'env' },
2220
+ { ExpoModulesCore: 'env', ExpoModulesWorklets: 'env' }
2221
+ );
2222
+ expect(thrown).toBeNull();
2223
+ expect(emitDirectPackage).toHaveBeenCalledWith(
2224
+ expect.objectContaining({
2225
+ headersXCFrameworks: {
2226
+ ExpoModulesCoreHeaders: '/abs/ExpoModulesCoreHeaders.xcframework',
2227
+ ExpoModulesWorkletsHeaders: '/abs/ExpoModulesWorkletsHeaders.xcframework',
2228
+ },
2229
+ jsiHeadersPkgPath,
2230
+ })
2231
+ );
2232
+ const lookups = resolveHeadersXCFrameworkWithSource.mock.calls.map(([lookup]) => lookup);
2233
+ const coreLookup = lookups.find((lookup) => lookup.productName === 'ExpoModulesCore');
2234
+ expect(lookups.find((lookup) => lookup.productName === 'ExpoModulesWorklets')).toEqual({
2235
+ ...coreLookup,
2236
+ productName: 'ExpoModulesWorklets',
2237
+ });
2238
+ });
2239
+
2240
+ it('fails naming the ExpoModulesWorklets headers when they are missing everywhere', () => {
2241
+ const { thrown } = syncWorklets(
2242
+ { ExpoModulesCore: 'bundled' },
2243
+ { ExpoModulesCore: 'bundled', ExpoModulesWorklets: null }
2244
+ );
2245
+ expect(thrown?.message).toContain(
2246
+ 'Expo modules built from their own Package.swift compile against ExpoModulesWorkletsHeaders.xcframework, which was not found'
2247
+ );
2248
+ expect(thrown.message).toContain('prebuild expo-modules-core');
2249
+ expect(thrown.message).toContain(rerunSpmUpdate);
2250
+ expect(emitDirectPackage).not.toHaveBeenCalled();
2251
+ });
2252
+
2253
+ it('fails naming the ExpoModulesWorklets headers when the local ExpoModulesWorklets build has none', () => {
2254
+ const { thrown } = syncWorklets(
2255
+ { ExpoModulesCore: 'monorepo' },
2256
+ { ExpoModulesCore: 'monorepo', ExpoModulesWorklets: 'bundled' }
2257
+ );
2258
+ expect(thrown?.message).toContain(
2259
+ `ExpoModulesWorkletsHeaders.xcframework is missing under ${sourceAt('monorepo', 'ExpoModulesWorklets').dir}, where ExpoModulesWorklets comes from`
2260
+ );
2261
+ expect(emitDirectPackage).not.toHaveBeenCalled();
2262
+ });
2263
+
2264
+ it('fails when the ExpoModulesWorklets headers come from another place than the ExpoModulesWorklets binary they belong to', () => {
2265
+ const { thrown } = syncWorklets(
2266
+ { ExpoModulesCore: 'bundled' },
2267
+ { ExpoModulesCore: 'bundled', ExpoModulesWorklets: 'env' }
2268
+ );
2269
+ expect(thrown?.message).toContain(
2270
+ 'ExpoModulesWorkletsHeaders.xcframework (expo-modules-core) comes from'
2271
+ );
2272
+ expect(emitDirectPackage).not.toHaveBeenCalled();
2273
+ });
2274
+
2275
+ it('fails when the ExpoModulesWorklets headers come from another place than the ExpoModulesWorklets binary', () => {
2276
+ const { thrown } = syncWorklets(
2277
+ { ExpoModulesCore: 'env', ExpoModulesWorklets: 'bundled' },
2278
+ { ExpoModulesCore: 'env', ExpoModulesWorklets: 'env' }
2279
+ );
2280
+ expect(thrown?.message).toContain(
2281
+ `ExpoModulesWorkletsHeaders.xcframework (expo-modules-core) comes from EXPO_PRECOMPILED_MODULES_PATH (${sourceAt('env', 'ExpoModulesWorklets').dir}), but ExpoModulesWorklets comes from its npm package (${sourceAt('bundled', 'ExpoModulesWorklets').dir}).`
2282
+ );
2283
+ expect(thrown.message).toContain(rerunSpmUpdate);
2284
+ expect(emitDirectPackage).not.toHaveBeenCalled();
2285
+ });
2286
+
2287
+ const syncWorkletsBuildingFromSource = (buildFromSource) => {
2288
+ hasPrecompiledArtifact.mockImplementation(
2289
+ ({ frameworkName }) => frameworkName !== 'ExpoHaptics'
2290
+ );
2291
+ return sync({
2292
+ frameworks: { ExpoModulesCore: 'env', ExpoModulesWorklets: 'env' },
2293
+ headers: { ExpoModulesCore: 'env', ExpoModulesWorklets: 'env' },
2294
+ manifest: workletsManifest,
2295
+ mixed: ['ExpoModulesWorklets'],
2296
+ buildFromSource,
2297
+ });
2298
+ };
2299
+
2300
+ it('links ExpoModulesWorklets precompiled when a buildFromSource pattern matches it', () => {
2301
+ const { thrown, result } = syncWorkletsBuildingFromSource(['.*']);
2302
+ expect(thrown).toBeNull();
2303
+ expect(result.flavoredFrameworks.map((f) => f.frameworkName)).toContain(
2304
+ 'ExpoModulesWorklets'
2305
+ );
2306
+ expect(emitDirectPackage).toHaveBeenCalledWith(
2307
+ expect.objectContaining({
2308
+ headersXCFrameworks: {
2309
+ ExpoModulesCoreHeaders: '/abs/ExpoModulesCoreHeaders.xcframework',
2310
+ ExpoModulesWorkletsHeaders: '/abs/ExpoModulesWorkletsHeaders.xcframework',
2311
+ },
2312
+ })
2313
+ );
2314
+ });
2315
+
2316
+ it('fails naming the cause when buildFromSource names ExpoModulesWorklets exactly', () => {
2317
+ const { thrown } = syncWorkletsBuildingFromSource(['ExpoModulesWorklets']);
2318
+ expect(thrown?.message).toContain(
2319
+ 'but no precompiled ExpoModulesWorklets (expo-modules-core) is linked'
2320
+ );
2321
+ expect(thrown.message).toContain(
2322
+ 'a buildFromSource entry names ExpoModulesWorklets or expo-modules-core exactly'
2323
+ );
2324
+ expect(thrown.message).not.toContain('not autolinked');
2325
+ expect(emitDirectPackage).not.toHaveBeenCalled();
2326
+ });
2327
+
2328
+ it('fails when ExpoModulesWorklets is not linked precompiled', () => {
2329
+ const { thrown } = sync({
2330
+ frameworks: { ExpoModulesCore: 'env' },
2331
+ headers: { ExpoModulesCore: 'env', ExpoModulesWorklets: 'env' },
2332
+ manifest: workletsManifest,
2333
+ });
2334
+ expect(thrown?.message).toContain(
2335
+ 'compile against ExpoModulesWorkletsHeaders.xcframework, but no precompiled ExpoModulesWorklets (expo-modules-core) is linked'
2336
+ );
2337
+ expect(thrown.message).toContain('prebuild expo-modules-core');
2338
+ expect(thrown.message).toContain(rerunSpmUpdate);
2339
+ expect(emitDirectPackage).not.toHaveBeenCalled();
2340
+ });
2341
+ });
2171
2342
  });
2172
2343
 
2173
2344
  describe.each([
@@ -3,7 +3,7 @@
3
3
  const fs = require('fs');
4
4
  const path = require('path');
5
5
 
6
- const { dependsOnCoreHeaders, dumpModuleManifest, emitDirectPackage } = require('../direct');
6
+ const { dumpModuleManifest, emitDirectPackage, headersStandInsOf } = require('../direct');
7
7
  const { makeTempDir, removeTempDirs } = require('./helpers');
8
8
 
9
9
  const REPO_ROOT = path.resolve(__dirname, '../../../../..');
@@ -76,7 +76,7 @@ it.each(DIRECT_MANIFESTS)(
76
76
  expect(fs.existsSync(path.join(moduleRoot, 'ios', 'Tests'))).toBe(false);
77
77
 
78
78
  const { manifest } = dumpModuleManifest(moduleRoot, packageName);
79
- expect(dependsOnCoreHeaders(manifest)).toBe(true);
79
+ expect(headersStandInsOf(manifest)).toEqual(['ExpoModulesCoreHeaders']);
80
80
 
81
81
  const outDir = path.join(tmp, 'out');
82
82
  const coreHeadersXCFramework = path.join(tmp, 'headers', 'ExpoModulesCoreHeaders.xcframework');
@@ -92,7 +92,7 @@ it.each(DIRECT_MANIFESTS)(
92
92
  moduleRoot,
93
93
  packageName,
94
94
  outDir,
95
- coreHeadersXCFramework,
95
+ headersXCFrameworks: { ExpoModulesCoreHeaders: coreHeadersXCFramework },
96
96
  jsiHeadersPkgPath: path.join(outDir, 'ExpoModulesJSIHeaders'),
97
97
  macrosPackageRoot,
98
98
  manifest,
@@ -1,15 +1,14 @@
1
1
  /**
2
- * Links a module whose checked-in Package.swift depends on the ExpoModulesCoreHeaders
3
- * product through that manifest instead of a generated one. It names its Expo dependencies by
4
- * paths relative to `<outDir>/direct/<package>`, so this writes those neighbours:
2
+ * Links a module whose checked-in Package.swift depends on a headers stand-in, such as the
3
+ * ExpoModulesCoreHeaders product, through that manifest instead of a generated one. It names
4
+ * its Expo dependencies by paths relative to `<outDir>/direct/<package>`, so this writes those
5
+ * neighbours:
5
6
  *
6
- * direct/<package> → relative symlink to the module root
7
- * direct/ExpoModulesCoreHeaders → compile-only ExpoModulesCore: a relative symlink to its
8
- * prebuilt headers xcframework, plus dependencies on the
9
- * ExpoModulesJSI headers package the plugin emits and on
10
- * the expo-modules-macros package, whose macro plugin
11
- * SwiftPM builds and loads into every dependent, and on
12
- * React Native's header products
7
+ * direct/<package> → relative symlink to the module root
8
+ * direct/<stand-in> → compile-only Expo product: a relative symlink to its prebuilt
9
+ * headers xcframework, plus dependencies on the packages its
10
+ * interface needs, as HEADERS_STAND_INS lists them, and, when its
11
+ * entry sets `reactHeaders`, on React Native's header products
13
12
  */
14
13
 
15
14
  'use strict';
@@ -21,70 +20,110 @@ const { runDumpPackage } = require('./cli');
21
20
  const { pluginError, rerunSpmUpdate } = require('./diagnostics');
22
21
  const { reactPackageDeclarations, reactProductDependencies } = require('./react-descriptor');
23
22
 
24
- const CORE_HEADERS = 'ExpoModulesCoreHeaders';
25
23
  const JSI_HEADERS = 'ExpoModulesJSIHeaders';
26
24
  const MACROS_PACKAGE = 'expo-modules-macros';
27
- const MACROS_PRODUCT = 'ExpoModulesMacrosPlugin';
28
- // A binary target cannot have dependencies, so this source target carries them.
29
- const CORE_HEADERS_DEPENDENCIES = 'ExpoModulesCoreHeadersDependencies';
30
25
  // Written into the package by an earlier generator; nothing reads it now.
31
26
  const LEGACY_STUBS_DIR = '.stubs';
32
27
 
33
28
  /**
34
- * Whether a dumped manifest compiles against ExpoModulesCoreHeaders, which only a manifest
35
- * written to be built as it stands can name. A `byName` dependency counts: SwiftPM resolves
29
+ * The headers stand-ins a checked-in manifest can depend on, by package and product name. Each
30
+ * is compile-only `productName` of the npm package `packageName`, over its prebuilt
31
+ * `<productName>Headers.xcframework`, and depends on the stand-ins in `standIns` and on the
32
+ * packages in `packages`, whose paths `emitDirectPackage` is given. A stand-in with
33
+ * `reactHeaders` also depends on React Native's header products, so a module that imports
34
+ * React gets them through it, as does a stand-in that depends on it.
35
+ *
36
+ * ExpoModulesCore's interface re-exports ExpoModulesJSI, so its stand-in brings the JSI
37
+ * headers package along; it must not declare a JSI headers target of its own, because SwiftPM
38
+ * rejects two targets of one name in a graph. SwiftPM loads the macro plugin into every target
39
+ * that depends, at any depth, on a target that depends on the plugin's product, so module
40
+ * manifests need no flags to load it.
41
+ */
42
+ const HEADERS_STAND_INS = {
43
+ ExpoModulesCoreHeaders: {
44
+ packageName: 'expo-modules-core',
45
+ productName: 'ExpoModulesCore',
46
+ standIns: [],
47
+ packages: [
48
+ { name: JSI_HEADERS, product: JSI_HEADERS },
49
+ { name: MACROS_PACKAGE, product: 'ExpoModulesMacrosPlugin' },
50
+ ],
51
+ reactHeaders: true,
52
+ },
53
+ ExpoModulesWorkletsHeaders: {
54
+ packageName: 'expo-modules-core',
55
+ productName: 'ExpoModulesWorklets',
56
+ standIns: ['ExpoModulesCoreHeaders'],
57
+ packages: [],
58
+ reactHeaders: false,
59
+ },
60
+ };
61
+
62
+ /**
63
+ * The headers stand-ins a dumped manifest compiles against, with the stand-ins they depend on,
64
+ * each once and after its dependencies. Only a manifest written to be built as it stands can
65
+ * name one, so the list is empty for any other. A `byName` dependency counts: SwiftPM resolves
36
66
  * it to that product when no target of the package has the name.
37
67
  */
38
- function dependsOnCoreHeaders(manifest) {
39
- return (manifest.targets ?? []).some((target) =>
40
- (target.dependencies ?? []).some(
41
- (dependency) => (dependency.product ?? dependency.byName)?.[0] === CORE_HEADERS
42
- )
43
- );
68
+ function headersStandInsOf(manifest) {
69
+ const standIns = new Set();
70
+ const add = (name) => {
71
+ if (standIns.has(name)) return;
72
+ HEADERS_STAND_INS[name].standIns.forEach(add);
73
+ standIns.add(name);
74
+ };
75
+ const targets = manifest.targets ?? [];
76
+ const targetNames = new Set(targets.map((target) => target.name));
77
+ for (const target of targets) {
78
+ for (const dependency of target.dependencies ?? []) {
79
+ const name = dependency.product?.[0] ?? dependency.byName?.[0];
80
+ if (dependency.byName != null && targetNames.has(name)) continue;
81
+ if (Object.hasOwn(HEADERS_STAND_INS, name)) add(name);
82
+ }
83
+ }
84
+ return [...standIns];
44
85
  }
45
86
 
46
87
  /**
47
- * Module manifests depend on the product, so it keeps the package's name. ExpoModulesCore's
48
- * interface re-exports ExpoModulesJSI, so the product brings the JSI headers package along;
49
- * it must not declare a JSI headers target of its own, because SwiftPM rejects two targets
50
- * of one name in a graph. SwiftPM loads the macro plugin into every target that depends, at
51
- * any depth, on a target that depends on the plugin's product, so module manifests need no
52
- * flags to load it.
88
+ * Module manifests depend on the product, so it keeps the package's name. A binary target
89
+ * cannot have dependencies, so the `<name>Dependencies` source target carries them.
90
+ *
91
+ * @param dependencies `{ name, product, path }` for each package the stand-in depends on, `path`
92
+ * relative to the stand-in.
93
+ * @param reactDependencies `{ packages, products }`: React Native's package declarations and
94
+ * product dependencies, as `react-descriptor.js` writes them, empty for no React headers.
53
95
  */
54
- function coreHeadersManifest(
55
- jsiHeadersPkgRelativePath,
56
- macrosPkgRelativePath,
57
- react,
58
- codegenPkgPath
59
- ) {
60
- const lines = (dependencies, indent) =>
61
- dependencies.map((dependency) => `${indent}${dependency},\n`).join('');
62
- const reactPackages = react != null ? reactPackageDeclarations(react, codegenPkgPath) : [];
63
- const reactProducts = react != null ? reactProductDependencies(react) : [];
96
+ function standInManifest(name, productName, dependencies, reactDependencies) {
97
+ const dependenciesTarget = `${name}Dependencies`;
98
+ const lines = (indent, entries) => entries.map((entry) => `${indent}${entry},\n`).join('');
99
+ const packages = [
100
+ ...dependencies.map((d) => `.package(name: "${d.name}", path: "${d.path}")`),
101
+ ...reactDependencies.packages,
102
+ ];
103
+ const products = [
104
+ ...dependencies.map((d) => `.product(name: "${d.product}", package: "${d.name}")`),
105
+ ...reactDependencies.products,
106
+ ];
64
107
  return `// swift-tools-version: 6.0
65
108
  // AUTO-GENERATED by expo/scripts/spm/direct.js — do not edit.
66
- // Compile-only ExpoModulesCore. The runtime framework is linked and embedded by React
109
+ // Compile-only ${productName}. The runtime framework is linked and embedded by React
67
110
  // Native outside SwiftPM.
68
111
  import PackageDescription
69
112
 
70
113
  let package = Package(
71
- name: "${CORE_HEADERS}",
114
+ name: "${name}",
72
115
  products: [
73
- .library(name: "${CORE_HEADERS}", targets: ["${CORE_HEADERS}", "${CORE_HEADERS_DEPENDENCIES}"]),
116
+ .library(name: "${name}", targets: ["${name}", "${dependenciesTarget}"]),
74
117
  ],
75
118
  dependencies: [
76
- .package(name: "${JSI_HEADERS}", path: "${jsiHeadersPkgRelativePath}"),
77
- .package(name: "${MACROS_PACKAGE}", path: "${macrosPkgRelativePath}"),
78
- ${lines(reactPackages, ' ')} ],
119
+ ${lines(' ', packages)} ],
79
120
  targets: [
80
- .binaryTarget(name: "${CORE_HEADERS}", path: "${CORE_HEADERS}.xcframework"),
121
+ .binaryTarget(name: "${name}", path: "${name}.xcframework"),
81
122
  .target(
82
- name: "${CORE_HEADERS_DEPENDENCIES}",
123
+ name: "${dependenciesTarget}",
83
124
  dependencies: [
84
- .product(name: "${JSI_HEADERS}", package: "${JSI_HEADERS}"),
85
- .product(name: "${MACROS_PRODUCT}", package: "${MACROS_PACKAGE}"),
86
- ${lines(reactProducts, ' ')} ],
87
- path: "${CORE_HEADERS_DEPENDENCIES}"
125
+ ${lines(' ', products)} ],
126
+ path: "${dependenciesTarget}"
88
127
  ),
89
128
  ]
90
129
  )
@@ -106,29 +145,29 @@ function writeIfChanged(file, contents) {
106
145
  fs.writeFileSync(file, contents);
107
146
  }
108
147
 
109
- function emitCoreHeadersPackage(
110
- directDir,
111
- coreHeadersXCFramework,
112
- jsiHeadersPkgPath,
113
- macrosPackageRoot,
114
- react,
115
- codegenPkgPath
116
- ) {
117
- const pkgDir = path.join(directDir, CORE_HEADERS);
148
+ /** @param packageRoots the directory of each package in `HEADERS_STAND_INS[name].packages`. */
149
+ function emitStandInPackage(directDir, name, headersXCFramework, packageRoots, reactDependencies) {
150
+ const { productName, standIns, packages, reactHeaders } = HEADERS_STAND_INS[name];
151
+ const pkgDir = path.join(directDir, name);
118
152
  fs.mkdirSync(pkgDir, { recursive: true });
119
153
  fs.rmSync(path.join(pkgDir, LEGACY_STUBS_DIR), { recursive: true, force: true });
120
- relativeSymlink(coreHeadersXCFramework, path.join(pkgDir, `${CORE_HEADERS}.xcframework`));
121
- writeIfChanged(
122
- path.join(pkgDir, CORE_HEADERS_DEPENDENCIES, `${CORE_HEADERS_DEPENDENCIES}.swift`),
123
- ''
124
- );
154
+ relativeSymlink(headersXCFramework, path.join(pkgDir, `${name}.xcframework`));
155
+ writeIfChanged(path.join(pkgDir, `${name}Dependencies`, `${name}Dependencies.swift`), '');
156
+ const dependencies = [
157
+ ...standIns.map((standIn) => ({
158
+ name: standIn,
159
+ product: standIn,
160
+ root: path.join(directDir, standIn),
161
+ })),
162
+ ...packages.map((dependency) => ({ ...dependency, root: packageRoots[dependency.name] })),
163
+ ].map(({ root, ...dependency }) => ({ ...dependency, path: path.relative(pkgDir, root) }));
125
164
  writeIfChanged(
126
165
  path.join(pkgDir, 'Package.swift'),
127
- coreHeadersManifest(
128
- path.relative(pkgDir, jsiHeadersPkgPath),
129
- path.relative(pkgDir, macrosPackageRoot),
130
- react,
131
- codegenPkgPath
166
+ standInManifest(
167
+ name,
168
+ productName,
169
+ dependencies,
170
+ reactHeaders ? reactDependencies : { packages: [], products: [] }
132
171
  )
133
172
  );
134
173
  }
@@ -137,6 +176,8 @@ function emitCoreHeadersPackage(
137
176
  * Wire one module through its own checked-in manifest. Returns the emission shape
138
177
  * `manifests.js#emitPackage` returns, so the plugin links it like any manifest package.
139
178
  *
179
+ * @param headersXCFrameworks the headers xcframework of each stand-in to emit, by stand-in
180
+ * name: every one `headersStandInsOf(manifest)` lists.
140
181
  * @param jsiHeadersPkgPath the ExpoModulesJSI headers package the plugin emits, or null when
141
182
  * expo-modules-jsi is not autolinked.
142
183
  * @param macrosPackageRoot the expo-modules-macros package that expo-modules-core resolves.
@@ -148,21 +189,30 @@ function emitDirectPackage({
148
189
  moduleRoot,
149
190
  packageName,
150
191
  outDir,
151
- coreHeadersXCFramework,
192
+ headersXCFrameworks,
152
193
  jsiHeadersPkgPath,
153
194
  macrosPackageRoot,
154
195
  react,
155
196
  codegenPkgPath,
156
197
  manifest,
157
198
  }) {
158
- if (jsiHeadersPkgPath == null) {
199
+ const standIns = Object.keys(headersXCFrameworks);
200
+ const packages = new Set(
201
+ standIns.flatMap((name) =>
202
+ HEADERS_STAND_INS[name].packages.map((dependency) => dependency.name)
203
+ )
204
+ );
205
+ if (packages.has(JSI_HEADERS) && jsiHeadersPkgPath == null) {
159
206
  throw pluginError({
160
207
  what: `${packageName} is built from its own Package.swift and needs the ExpoModulesJSI headers, but expo-modules-jsi is not autolinked.`,
161
208
  why: 'The ExpoModulesCore headers it compiles against re-export ExpoModulesJSI.',
162
209
  how: `expo-modules-core depends on expo-modules-jsi, so reinstall your JavaScript dependencies, and remove expo-modules-jsi from \`"expo": { "autolinking": { "exclude": [...] } }\` in your package.json if it is listed there. ${rerunSpmUpdate()}`,
163
210
  });
164
211
  }
165
- if (!fs.existsSync(path.join(macrosPackageRoot, 'Package.swift'))) {
212
+ if (
213
+ packages.has(MACROS_PACKAGE) &&
214
+ !fs.existsSync(path.join(macrosPackageRoot, 'Package.swift'))
215
+ ) {
166
216
  throw pluginError({
167
217
  what: `${packageName} is built from its own Package.swift and needs the Expo Swift macros as a Swift package, but ${MACROS_PACKAGE} at ${macrosPackageRoot} has no Package.swift.`,
168
218
  why: `SwiftPM builds the macro plugin from that package, and versions of ${MACROS_PACKAGE} before 0.29.0 ship it only as a prebuilt binary.`,
@@ -171,14 +221,14 @@ function emitDirectPackage({
171
221
  }
172
222
  const directDir = path.join(outDir, 'direct');
173
223
  fs.mkdirSync(directDir, { recursive: true });
174
- emitCoreHeadersPackage(
175
- directDir,
176
- coreHeadersXCFramework,
177
- jsiHeadersPkgPath,
178
- macrosPackageRoot,
179
- react,
180
- codegenPkgPath
181
- );
224
+ const packageRoots = { [JSI_HEADERS]: jsiHeadersPkgPath, [MACROS_PACKAGE]: macrosPackageRoot };
225
+ const reactDependencies = {
226
+ packages: react != null ? reactPackageDeclarations(react, codegenPkgPath) : [],
227
+ products: react != null ? reactProductDependencies(react) : [],
228
+ };
229
+ for (const name of standIns) {
230
+ emitStandInPackage(directDir, name, headersXCFrameworks[name], packageRoots, reactDependencies);
231
+ }
182
232
  const link = path.join(directDir, packageName);
183
233
  fs.mkdirSync(path.dirname(link), { recursive: true });
184
234
  relativeSymlink(moduleRoot, link);
@@ -222,7 +272,8 @@ function dumpFailureDetail(error) {
222
272
  }
223
273
 
224
274
  module.exports = {
225
- dependsOnCoreHeaders,
275
+ HEADERS_STAND_INS,
226
276
  dumpModuleManifest,
227
277
  emitDirectPackage,
278
+ headersStandInsOf,
228
279
  };