expo 58.0.17 → 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.
@@ -16,7 +16,7 @@ const fs = require('fs');
16
16
  const path = require('path');
17
17
 
18
18
  const { spmUpdateCommand } = require('./commands');
19
- const { pluginError } = require('./diagnostics');
19
+ const { pluginError, rerunSpmUpdate } = require('./diagnostics');
20
20
 
21
21
  const FLAVORS = ['debug', 'release'];
22
22
 
@@ -54,23 +54,32 @@ function existingArtifactSource(baseDir, flavor, frameworkName) {
54
54
  }
55
55
 
56
56
  /**
57
- * Lookup order: EXPO_PRECOMPILED_MODULES_PATH, monorepo prebuild output, the npm package's
58
- * `prebuilds/` copy.
57
+ * The kinds of place every precompiled artifact lookup tries, in order:
58
+ * EXPO_PRECOMPILED_MODULES_PATH (`env`), monorepo prebuild output (`monorepo`), and the npm
59
+ * package's `prebuilds/` copy (`bundled`, skipped without a module root).
59
60
  */
60
- function precompiledBaseDirs(buildPath, moduleRoot, bundledPath) {
61
- const bases = [];
62
- if (process.env.EXPO_PRECOMPILED_MODULES_PATH) {
63
- bases.push(path.resolve(process.env.EXPO_PRECOMPILED_MODULES_PATH, ...buildPath));
64
- }
65
- bases.push(
66
- path.resolve(__dirname, '..', '..', '..', 'precompile', '.build', ...buildPath),
67
- path.join(moduleRoot, 'prebuilds', ...bundledPath)
68
- );
69
- return Array.from(new Set(bases));
61
+ const PRECOMPILED_SOURCE_KINDS = Object.freeze(['env', 'monorepo', 'bundled']);
62
+
63
+ function precompiledBases(buildPath, moduleRoot, bundledPath) {
64
+ const envPath = process.env.EXPO_PRECOMPILED_MODULES_PATH;
65
+ const dirs = {
66
+ env: envPath ? path.resolve(envPath, ...buildPath) : null,
67
+ monorepo: path.resolve(__dirname, '..', '..', '..', 'precompile', '.build', ...buildPath),
68
+ bundled: moduleRoot != null ? path.join(moduleRoot, 'prebuilds', ...bundledPath) : null,
69
+ };
70
+ const bases = PRECOMPILED_SOURCE_KINDS.filter((kind) => dirs[kind] != null).map((kind) => ({
71
+ kind,
72
+ dir: dirs[kind],
73
+ }));
74
+ return bases.filter((base, index) => bases.findIndex((b) => b.dir === base.dir) === index);
75
+ }
76
+
77
+ function artifactBases(packageName, moduleRoot) {
78
+ return precompiledBases([packageName, 'output'], moduleRoot, ['output']);
70
79
  }
71
80
 
72
81
  function artifactBaseDirs(packageName, moduleRoot) {
73
- return precompiledBaseDirs([packageName, 'output'], moduleRoot, ['output']);
82
+ return artifactBases(packageName, moduleRoot).map((base) => base.dir);
74
83
  }
75
84
 
76
85
  /**
@@ -120,7 +129,15 @@ function validateTarEntries(tarballPath, frameworkName) {
120
129
  }
121
130
  }
122
131
 
123
- function extractTarball(sourcePath, frameworkName, cacheDir, flavor) {
132
+ function incompleteXCFrameworkError(what, packageName) {
133
+ return pluginError({
134
+ what,
135
+ why: 'The XCFramework is incomplete because its build or its extraction did not finish, or the file is damaged.',
136
+ how: `Reinstall ${packageName}, or from the Expo repository root run \`node tools/bin/expotools.js prebuild ${packageName}\`. ${rerunSpmUpdate()}`,
137
+ });
138
+ }
139
+
140
+ function extractTarball(sourcePath, packageName, frameworkName, cacheDir, flavor) {
124
141
  const stat = fs.statSync(sourcePath);
125
142
  const destination = path.join(cacheDir, stableFrameworkId(frameworkName), flavor);
126
143
  const xcframeworkPath = path.join(destination, `${frameworkName}.xcframework`);
@@ -145,9 +162,10 @@ function extractTarball(sourcePath, frameworkName, cacheDir, flavor) {
145
162
  execFileSync('tar', ['-xzf', sourcePath, '-C', temp], { stdio: 'pipe' });
146
163
  const extracted = path.join(temp, `${frameworkName}.xcframework`);
147
164
  if (!fs.existsSync(path.join(extracted, 'Info.plist'))) {
148
- throw pluginError({
149
- what: `${sourcePath} did not extract ${frameworkName}.xcframework/Info.plist`,
150
- });
165
+ throw incompleteXCFrameworkError(
166
+ `${sourcePath} holds ${frameworkName}.xcframework with no Info.plist.`,
167
+ packageName
168
+ );
151
169
  }
152
170
  fs.writeFileSync(path.join(temp, '.source.json'), stamp, 'utf8');
153
171
  });
@@ -172,9 +190,9 @@ function replaceDirectory(destination, fill) {
172
190
  }
173
191
  }
174
192
 
175
- function prepareArtifactSource(source, frameworkName, cacheDir, flavor) {
193
+ function prepareArtifactSource(source, packageName, frameworkName, cacheDir, flavor) {
176
194
  if (source.type === 'tarball') {
177
- return extractTarball(source.path, frameworkName, cacheDir, flavor);
195
+ return extractTarball(source.path, packageName, frameworkName, cacheDir, flavor);
178
196
  }
179
197
  return path.resolve(source.path);
180
198
  }
@@ -223,15 +241,21 @@ function validateFlavoredFramework(framework) {
223
241
  };
224
242
  }
225
243
 
244
+ /**
245
+ * The declaration goes to React Native as is, so where it was resolved from is kept beside
246
+ * it rather than in it.
247
+ */
248
+ const frameworkSources = new WeakMap();
249
+
226
250
  /**
227
251
  * Returns null when this module has no precompiled artifact at all. Once any
228
252
  * flavor is present, both are mandatory at the same source base; a partial
229
253
  * build must not silently degrade to a one-flavor declaration.
230
254
  */
231
255
  function resolveFlavoredFramework({ packageName, moduleRoot, frameworkName, cacheDir }) {
232
- for (const baseDir of artifactBaseDirs(packageName, moduleRoot)) {
256
+ for (const base of artifactBases(packageName, moduleRoot)) {
233
257
  const sources = Object.fromEntries(
234
- FLAVORS.map((flavor) => [flavor, existingArtifactSource(baseDir, flavor, frameworkName)])
258
+ FLAVORS.map((flavor) => [flavor, existingArtifactSource(base.dir, flavor, frameworkName)])
235
259
  );
236
260
  if (sources.debug == null && sources.release == null) {
237
261
  continue;
@@ -239,42 +263,91 @@ function resolveFlavoredFramework({ packageName, moduleRoot, frameworkName, cach
239
263
  for (const flavor of FLAVORS) {
240
264
  if (sources[flavor] == null) {
241
265
  throw pluginError({
242
- what: `${frameworkName} has an incomplete precompiled pair in ${baseDir}: missing ${flavor}.`,
266
+ what: `${frameworkName} has an incomplete precompiled pair in ${base.dir}: missing ${flavor}.`,
243
267
  how: `Run the Expo prebuild pipeline for both Debug and Release before \`${spmUpdateCommand()}\`.`,
244
268
  });
245
269
  }
246
270
  }
247
- return validateFlavoredFramework({
271
+ const framework = validateFlavoredFramework({
248
272
  id: stableFrameworkId(frameworkName),
249
273
  frameworkName,
250
274
  linkage: 'dynamic',
251
275
  flavors: {
252
- debug: prepareArtifactSource(sources.debug, frameworkName, cacheDir, 'debug'),
253
- release: prepareArtifactSource(sources.release, frameworkName, cacheDir, 'release'),
276
+ debug: prepareArtifactSource(sources.debug, packageName, frameworkName, cacheDir, 'debug'),
277
+ release: prepareArtifactSource(
278
+ sources.release,
279
+ packageName,
280
+ frameworkName,
281
+ cacheDir,
282
+ 'release'
283
+ ),
254
284
  },
255
285
  });
286
+ frameworkSources.set(framework, base);
287
+ return framework;
256
288
  }
257
289
  return null;
258
290
  }
259
291
 
292
+ /**
293
+ * Whether `resolveFlavoredFramework` would find an artifact, without validating or
294
+ * extracting it: for a pod that is not linked precompiled.
295
+ */
296
+ function hasPrecompiledArtifact({ packageName, moduleRoot, frameworkName }) {
297
+ return artifactBases(packageName, moduleRoot).some((base) =>
298
+ FLAVORS.some((flavor) => existingArtifactSource(base.dir, flavor, frameworkName) != null)
299
+ );
300
+ }
301
+
302
+ /** The `{ kind, dir }` base a `resolveFlavoredFramework` declaration came from. */
303
+ function frameworkSource(framework) {
304
+ return frameworkSources.get(framework) ?? null;
305
+ }
306
+
307
+ const HEADERS_FLAVOR = 'headers';
308
+
309
+ /** Every path `resolveHeadersXCFrameworkWithSource` tries, in its order. */
310
+ function headersXCFrameworkSearchPaths({ packageName, moduleRoot, productName }) {
311
+ return artifactBases(packageName, moduleRoot).flatMap((base) =>
312
+ Object.values(artifactCandidates(base.dir, HEADERS_FLAVOR, `${productName}Headers`))
313
+ );
314
+ }
315
+
260
316
  /**
261
317
  * The interface-only `<Product>Headers` XCFramework a product publishes in place of its
262
- * binaries, from the same bases as its flavored frameworks. Null when no base has one.
318
+ * binaries, from the first of its flavored frameworks' bases that has one, as
319
+ * `{ xcframework, source }`. Null when no base has one.
320
+ *
321
+ * @param lastKind when set, the lookup ends after the base of this kind, so a base past it
322
+ * is neither returned nor validated.
263
323
  */
264
- function resolveHeadersXCFramework({ packageName, moduleRoot, productName, cacheDir }) {
324
+ function resolveHeadersXCFrameworkWithSource({
325
+ packageName,
326
+ moduleRoot,
327
+ productName,
328
+ cacheDir,
329
+ lastKind,
330
+ }) {
265
331
  const frameworkName = `${productName}Headers`;
266
- for (const baseDir of artifactBaseDirs(packageName, moduleRoot)) {
267
- const source = existingArtifactSource(baseDir, 'headers', frameworkName);
268
- if (source == null) continue;
269
- const xcframework = prepareArtifactSource(source, frameworkName, cacheDir, 'headers');
332
+ const lastRank =
333
+ lastKind != null ? PRECOMPILED_SOURCE_KINDS.indexOf(lastKind) : PRECOMPILED_SOURCE_KINDS.length;
334
+ const bases = artifactBases(packageName, moduleRoot).filter(
335
+ (base) => PRECOMPILED_SOURCE_KINDS.indexOf(base.kind) <= lastRank
336
+ );
337
+ for (const base of bases) {
338
+ const artifact = existingArtifactSource(base.dir, HEADERS_FLAVOR, frameworkName);
339
+ if (artifact == null) continue;
340
+ const xcframework = prepareArtifactSource(
341
+ artifact,
342
+ packageName,
343
+ frameworkName,
344
+ cacheDir,
345
+ HEADERS_FLAVOR
346
+ );
270
347
  if (!fs.existsSync(path.join(xcframework, 'Info.plist'))) {
271
- throw pluginError({
272
- what: `${xcframework} has no Info.plist.`,
273
- why: 'The XCFramework is incomplete, so Swift packages cannot compile against it.',
274
- how: `Reinstall ${packageName}, or delete it and run the Expo prebuild pipeline for ${packageName} again.`,
275
- });
348
+ throw incompleteXCFrameworkError(`${xcframework} has no Info.plist.`, packageName);
276
349
  }
277
- return xcframework;
350
+ return { xcframework, source: base };
278
351
  }
279
352
  return null;
280
353
  }
@@ -319,10 +392,15 @@ function readPackageVersion(file, { packageName, productName }) {
319
392
  );
320
393
  }
321
394
 
395
+ /** `resolveHeadersXCFrameworkWithSource` without the source: the XCFramework path, or null. */
396
+ function resolveHeadersXCFramework(lookup) {
397
+ return resolveHeadersXCFrameworkWithSource(lookup)?.xcframework ?? null;
398
+ }
399
+
322
400
  /** The directories `resolveHeadersXCFramework` searches, in lookup order. */
323
401
  function headersXCFrameworkDirs(packageName, moduleRoot) {
324
402
  return artifactBaseDirs(packageName, moduleRoot).map((baseDir) =>
325
- artifactDir(baseDir, 'headers')
403
+ artifactDir(baseDir, HEADERS_FLAVOR)
326
404
  );
327
405
  }
328
406
 
@@ -332,7 +410,9 @@ function headersXCFrameworkDirs(packageName, moduleRoot) {
332
410
  * of the module that links it.
333
411
  */
334
412
  function spmDependencyBaseDirs(depName, ownerModuleRoot) {
335
- return precompiledBaseDirs(['.spm-deps', depName], ownerModuleRoot, ['spm-deps', depName]);
413
+ return precompiledBases(['.spm-deps', depName], ownerModuleRoot, ['spm-deps', depName]).map(
414
+ (base) => base.dir
415
+ );
336
416
  }
337
417
 
338
418
  function readXcframeworkPlist(plistPath) {
@@ -544,14 +624,19 @@ function prepareCompileInterfaces(frameworks, destination) {
544
624
 
545
625
  module.exports = {
546
626
  FLAVORS,
627
+ PRECOMPILED_SOURCE_KINDS,
547
628
  artifactBaseDirs,
548
629
  assertDistinctFlavoredFrameworks,
549
630
  assertHeadersMatchSources,
550
631
  byteOrder,
632
+ frameworkSource,
633
+ hasPrecompiledArtifact,
551
634
  headersXCFrameworkDirs,
635
+ headersXCFrameworkSearchPaths,
552
636
  prepareCompileInterfaces,
553
637
  resolveFlavoredFramework,
554
638
  resolveHeadersXCFramework,
639
+ resolveHeadersXCFrameworkWithSource,
555
640
  resolveSpmDependencyFrameworks,
556
641
  stableFrameworkId,
557
642
  validateFlavoredFramework,
@@ -11,7 +11,6 @@ const fs = require('fs');
11
11
  const path = require('path');
12
12
  const { appleSourceDir, scanAppleSources } = require('./classify');
13
13
  const { reactProductDependencies, reactPackageDeclarations } = require('./react-descriptor');
14
- const { runDumpPackage } = require('./cli');
15
14
  const { pluginError } = require('./diagnostics');
16
15
 
17
16
  // ---------------------------------------------------------------------------
@@ -974,10 +973,12 @@ let package = Package(
974
973
  * depends on a target or declares a Swift package the generated package cannot
975
974
  * declare, or a target's sources cannot be located — the module is then skipped and
976
975
  * diagnosed rather than emitted broken.
976
+ *
977
+ * @param dumpedJson the manifest's `swift package dump-package` output.
977
978
  */
978
- function emitSourceManifestPackage(moduleRoot, emitContext) {
979
+ function emitSourceManifestPackage(moduleRoot, emitContext, dumpedJson) {
979
980
  const { unsupportedTargetDeps, unsupportedPackageDeps, ...dumped } = parseDumpedManifest(
980
- runDumpPackage(moduleRoot),
981
+ dumpedJson,
981
982
  injectedPackageNames(emitContext.react)
982
983
  );
983
984
  if (unsupportedTargetDeps.length) {