expo 58.0.0 → 58.0.1
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.
- package/android/build.gradle +2 -2
- package/android/proguard-rules.pro +4 -0
- package/android/src/main/java/expo/modules/fetch/NativeResponse.kt +5 -1
- package/android/src/main/java/expo/modules/fetch/OkHttpFileUrlInterceptor.kt +5 -1
- package/build/winter/runtime.native.js +0 -2
- package/build/winter/runtime.native.js.map +1 -1
- package/bundledNativeModules.json +21 -21
- package/package.json +7 -7
- package/scripts/spm/README.md +0 -3
- package/scripts/spm/__tests__/cli.test.js +57 -1
- package/scripts/spm/__tests__/diagnostics.test.js +181 -131
- package/scripts/spm/__tests__/flavored-frameworks.test.js +9 -0
- package/scripts/spm/__tests__/helpers.js +88 -0
- package/scripts/spm/__tests__/manifests.test.js +289 -74
- package/scripts/spm/__tests__/plugin.test.js +1101 -111
- package/scripts/spm/__tests__/podspec.test.js +27 -138
- package/scripts/spm/__tests__/spm-dependencies.test.js +344 -0
- package/scripts/spm/classify.js +28 -6
- package/scripts/spm/cli.js +23 -9
- package/scripts/spm/diagnostics.js +111 -91
- package/scripts/spm/flavored-frameworks.js +233 -21
- package/scripts/spm/manifests.js +85 -34
- package/scripts/spm/plugin.js +214 -55
- package/scripts/spm/podspec.js +10 -160
- package/src/winter/runtime.native.ts +0 -2
- package/template.tgz +0 -0
- package/build/winter/AbortSignal.d.ts +0 -3
- package/build/winter/AbortSignal.js +0 -96
- package/build/winter/AbortSignal.js.map +0 -1
- package/src/winter/AbortSignal.ts +0 -132
- package/src/winter/__tests__/AbortSignal.test.native.ts +0 -163
|
@@ -66,24 +66,6 @@ class UnsupportedModulesError extends Error {
|
|
|
66
66
|
}
|
|
67
67
|
}
|
|
68
68
|
|
|
69
|
-
/**
|
|
70
|
-
* The `spm.config.json` product declaring `podName`, or null. A module with one
|
|
71
|
-
* can be built into an XCFramework by the Expo prebuild pipeline, which compiles
|
|
72
|
-
* mixed Swift/ObjC/C++ targets — so it needs no SwiftPM manifest at all. A
|
|
73
|
-
* `sourceOnly` product declares the opposite: it never produces an artifact.
|
|
74
|
-
*/
|
|
75
|
-
function spmConfigProduct(moduleRoot, podName) {
|
|
76
|
-
let config;
|
|
77
|
-
try {
|
|
78
|
-
config = JSON.parse(fs.readFileSync(path.join(moduleRoot, 'spm.config.json'), 'utf8'));
|
|
79
|
-
} catch {
|
|
80
|
-
return null;
|
|
81
|
-
}
|
|
82
|
-
const product = (config.products ?? []).find((p) => (p.podName ?? p.name) === podName);
|
|
83
|
-
if (product == null) return null;
|
|
84
|
-
return { name: product.name, sourceOnly: product.sourceOnly === true };
|
|
85
|
-
}
|
|
86
|
-
|
|
87
69
|
/**
|
|
88
70
|
* Why each uncovered pod is uncovered. A missing interface tree is a single
|
|
89
71
|
* project-level fault that would otherwise be reported once per module, so it
|
|
@@ -95,64 +77,28 @@ function classifyUnsupported({ pending, coreAvailable }) {
|
|
|
95
77
|
return [{ reason: 'core-unavailable', pods: pending.map((p) => p.podName) }];
|
|
96
78
|
}
|
|
97
79
|
return pending.map((p) => {
|
|
80
|
+
const subject = { podName: p.podName, packageName: p.packageName, moduleRoot: p.moduleRoot };
|
|
98
81
|
const prebuildable = p.prebuildProduct != null && !p.prebuildProduct.sourceOnly;
|
|
99
82
|
if (prebuildable) {
|
|
100
|
-
return {
|
|
101
|
-
reason: 'prebuild-available',
|
|
102
|
-
podName: p.podName,
|
|
103
|
-
packageName: p.packageName,
|
|
104
|
-
moduleRoot: p.moduleRoot,
|
|
105
|
-
productName: p.prebuildProduct.name,
|
|
106
|
-
};
|
|
107
|
-
}
|
|
108
|
-
if (p.podspecError != null) {
|
|
109
|
-
const { file, line, snippet, reason } = p.podspecError;
|
|
110
|
-
return {
|
|
111
|
-
reason: 'unsupported-podspec-syntax',
|
|
112
|
-
podName: p.podName,
|
|
113
|
-
packageName: p.packageName,
|
|
114
|
-
moduleRoot: p.moduleRoot,
|
|
115
|
-
file,
|
|
116
|
-
line,
|
|
117
|
-
snippet,
|
|
118
|
-
problem: reason,
|
|
119
|
-
};
|
|
83
|
+
return { reason: 'prebuild-available', ...subject, productName: p.prebuildProduct.name };
|
|
120
84
|
}
|
|
121
85
|
if (p.podspecLinkage != null) {
|
|
122
86
|
const { file, line, snippet } = p.podspecLinkage;
|
|
123
|
-
return {
|
|
124
|
-
reason: 'needs-manifest-for-linkage',
|
|
125
|
-
podName: p.podName,
|
|
126
|
-
packageName: p.packageName,
|
|
127
|
-
moduleRoot: p.moduleRoot,
|
|
128
|
-
file,
|
|
129
|
-
line,
|
|
130
|
-
snippet,
|
|
131
|
-
};
|
|
87
|
+
return { reason: 'needs-manifest-for-linkage', ...subject, file, line, snippet };
|
|
132
88
|
}
|
|
133
89
|
if (p.unsupportedTargetDeps?.length) {
|
|
134
90
|
return {
|
|
135
91
|
reason: 'unsupported-target-dependency',
|
|
136
|
-
|
|
137
|
-
packageName: p.packageName,
|
|
138
|
-
moduleRoot: p.moduleRoot,
|
|
92
|
+
...subject,
|
|
139
93
|
dependencies: p.unsupportedTargetDeps,
|
|
140
94
|
};
|
|
141
95
|
}
|
|
142
96
|
if (p.unresolvedTargets?.length) {
|
|
143
|
-
return {
|
|
144
|
-
reason: 'unresolvable-target-path',
|
|
145
|
-
podName: p.podName,
|
|
146
|
-
packageName: p.packageName,
|
|
147
|
-
moduleRoot: p.moduleRoot,
|
|
148
|
-
targetNames: p.unresolvedTargets,
|
|
149
|
-
};
|
|
97
|
+
return { reason: 'unresolvable-target-path', ...subject, targetNames: p.unresolvedTargets };
|
|
150
98
|
}
|
|
151
99
|
return {
|
|
152
100
|
reason: p.hasSources === false ? 'no-apple-sources' : 'mixed-no-manifest',
|
|
153
|
-
|
|
154
|
-
packageName: p.packageName,
|
|
155
|
-
moduleRoot: p.moduleRoot,
|
|
101
|
+
...subject,
|
|
156
102
|
productName: p.prebuildProduct?.name ?? null,
|
|
157
103
|
};
|
|
158
104
|
});
|
|
@@ -168,17 +114,23 @@ function podspecDependencies(text) {
|
|
|
168
114
|
return deps;
|
|
169
115
|
}
|
|
170
116
|
|
|
171
|
-
/**
|
|
172
|
-
|
|
117
|
+
/**
|
|
118
|
+
* The subset of pod dependencies with no SwiftPM counterpart. `satisfied` holds
|
|
119
|
+
* the SwiftPM packages already declared as frameworks, matched on the root of the
|
|
120
|
+
* pod name so that a subspec (`libavif/libdav1d`) is covered by its package —
|
|
121
|
+
* the match CocoaPods makes in `precompiled_modules.rb#strip_matching_dependencies`.
|
|
122
|
+
*/
|
|
123
|
+
function unmappedPodDependencies(deps, satisfied = new Set()) {
|
|
173
124
|
return deps.filter(
|
|
174
125
|
(dep) =>
|
|
175
126
|
!UNMAPPED_POD_ALLOWLIST.has(dep) &&
|
|
127
|
+
!satisfied.has(dep.split('/')[0]) &&
|
|
176
128
|
!COVERED_POD_PREFIXES.some((prefix) => dep.startsWith(prefix))
|
|
177
129
|
);
|
|
178
130
|
}
|
|
179
131
|
|
|
180
132
|
/** Pods outside the SwiftPM graph that `podspecDir`'s podspecs depend on. */
|
|
181
|
-
function collectUnmappedDependencies(podspecDir) {
|
|
133
|
+
function collectUnmappedDependencies(podspecDir, satisfied) {
|
|
182
134
|
let entries = [];
|
|
183
135
|
try {
|
|
184
136
|
entries = fs.readdirSync(podspecDir).filter((f) => f.endsWith('.podspec'));
|
|
@@ -193,11 +145,45 @@ function collectUnmappedDependencies(podspecDir) {
|
|
|
193
145
|
} catch {
|
|
194
146
|
continue;
|
|
195
147
|
}
|
|
196
|
-
unmappedPodDependencies(podspecDependencies(text)).forEach((d) => deps.add(d));
|
|
148
|
+
unmappedPodDependencies(podspecDependencies(text), satisfied).forEach((d) => deps.add(d));
|
|
197
149
|
}
|
|
198
150
|
return [...deps];
|
|
199
151
|
}
|
|
200
152
|
|
|
153
|
+
/**
|
|
154
|
+
* Two paths that name different real directories. A path that cannot be resolved
|
|
155
|
+
* — a broken symlink, an unreadable parent — counts as no difference: a symlinked
|
|
156
|
+
* layout is the normal case here, and a diagnostic is never worth failing on.
|
|
157
|
+
*/
|
|
158
|
+
function resolveToDifferentDirectories(left, right) {
|
|
159
|
+
try {
|
|
160
|
+
return fs.realpathSync(left) !== fs.realpathSync(right);
|
|
161
|
+
} catch {
|
|
162
|
+
return false;
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
/**
|
|
167
|
+
* Modules whose documented package root and autolinked root are two different
|
|
168
|
+
* real directories: the package is installed twice, and the plugin builds the
|
|
169
|
+
* copy the app's JavaScript does not import. One directory reached by two paths
|
|
170
|
+
* — the routine pnpm and monorepo case — is not a conflict.
|
|
171
|
+
*
|
|
172
|
+
* @param identities every pod's identity, from `plugin.js#resolvePodIdentities`.
|
|
173
|
+
*/
|
|
174
|
+
function collectRootConflicts(identities) {
|
|
175
|
+
const conflicts = new Map();
|
|
176
|
+
// A root is resolved per POD, so the module conflicts as soon as ANY pod
|
|
177
|
+
// documents another copy, not only the first pod that documents one.
|
|
178
|
+
for (const { packageName, documentedRoot, autolinkedRoot } of identities.values()) {
|
|
179
|
+
if (conflicts.has(packageName) || documentedRoot == null || autolinkedRoot == null) continue;
|
|
180
|
+
if (resolveToDifferentDirectories(documentedRoot, autolinkedRoot)) {
|
|
181
|
+
conflicts.set(packageName, { packageName, moduleRoot: documentedRoot, autolinkedRoot });
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
return [...conflicts.values()];
|
|
185
|
+
}
|
|
186
|
+
|
|
201
187
|
function renderMixedNoManifest({ podName, packageName, moduleRoot }) {
|
|
202
188
|
return [
|
|
203
189
|
`error: Expo module "${packageName}" (pod ${podName}) mixes Swift and Objective-C/C++ sources but ships neither a Package.swift nor an spm.config.json, so it cannot be built with Swift Package Manager.`,
|
|
@@ -284,31 +270,6 @@ function renderUnsupportedTargetDependency({ podName, packageName, moduleRoot, d
|
|
|
284
270
|
].join('\n');
|
|
285
271
|
}
|
|
286
272
|
|
|
287
|
-
/**
|
|
288
|
-
* The floor the podspec states is not an exact literal. Reading a computed one means
|
|
289
|
-
* running Ruby, and a guessed floor builds the module against APIs the deployment
|
|
290
|
-
* target may not have — so the module is skipped and the line is quoted back.
|
|
291
|
-
*/
|
|
292
|
-
function renderUnsupportedPodspecSyntax({
|
|
293
|
-
podName,
|
|
294
|
-
packageName,
|
|
295
|
-
moduleRoot,
|
|
296
|
-
file,
|
|
297
|
-
line,
|
|
298
|
-
snippet,
|
|
299
|
-
problem,
|
|
300
|
-
}) {
|
|
301
|
-
return [
|
|
302
|
-
`error: Expo module "${packageName}" (pod ${podName}) states its iOS deployment floor in a form the Swift Package Manager plugin cannot read, so it was skipped.`,
|
|
303
|
-
` ${file}:${line} states it as ${problem}:`,
|
|
304
|
-
` ${snippet}`,
|
|
305
|
-
` The plugin reads the floor as text, and only as an exact literal: \`s.platforms = { :ios => '16.4' }\` or \`s.ios.deployment_target = '16.4'\`. Anything computed would need the podspec to be run, and a guessed floor compiles the module against APIs the deployment target may not have.`,
|
|
306
|
-
` Write the floor as a literal, or declare it in a Package.swift for the module — \`platforms: [.iOS("16.4")]\` — which the plugin mirrors.`,
|
|
307
|
-
` If you do not own ${packageName}, persist the edit with \`npx patch-package ${packageName}\` and commit the patch — node_modules is not committed, so without it this error returns on every fresh install and in CI.`,
|
|
308
|
-
` Module path: ${moduleRoot}`,
|
|
309
|
-
].join('\n');
|
|
310
|
-
}
|
|
311
|
-
|
|
312
273
|
function renderNeedsManifestForLinkage({ podName, packageName, moduleRoot, file, line, snippet }) {
|
|
313
274
|
return [
|
|
314
275
|
`error: Expo module "${packageName}" (pod ${podName}) declares native linkage in its podspec, which the Swift Package Manager plugin does not read, so it was skipped.`,
|
|
@@ -338,7 +299,6 @@ const RENDERERS = {
|
|
|
338
299
|
'no-apple-sources': renderNoAppleSources,
|
|
339
300
|
'unresolvable-target-path': renderUnresolvableTargetPath,
|
|
340
301
|
'unsupported-target-dependency': renderUnsupportedTargetDependency,
|
|
341
|
-
'unsupported-podspec-syntax': renderUnsupportedPodspecSyntax,
|
|
342
302
|
'needs-manifest-for-linkage': renderNeedsManifestForLinkage,
|
|
343
303
|
'core-unavailable': renderCoreUnavailable,
|
|
344
304
|
};
|
|
@@ -385,6 +345,64 @@ function renderXcconfigLinkerWarning(entries) {
|
|
|
385
345
|
.join('\n\n');
|
|
386
346
|
}
|
|
387
347
|
|
|
348
|
+
/**
|
|
349
|
+
* Two installed copies of one module. The sync does not fail: the plugin builds
|
|
350
|
+
* one copy while the app imports the other, so the warning is the only place the
|
|
351
|
+
* mismatch is visible.
|
|
352
|
+
*/
|
|
353
|
+
function renderRootConflictWarning(entries) {
|
|
354
|
+
if (!entries.length) return '';
|
|
355
|
+
return entries
|
|
356
|
+
.map(({ packageName, moduleRoot, autolinkedRoot }) =>
|
|
357
|
+
[
|
|
358
|
+
`warning: Expo module "${packageName}" is installed twice, so its native code and your JavaScript can come from different copies of the package:`,
|
|
359
|
+
` built by this plugin: ${moduleRoot}`,
|
|
360
|
+
` imported by your app: ${autolinkedRoot}`,
|
|
361
|
+
` Both are real directories, not one directory reached through a symlink, so the copies can be different versions. The plugin builds the first one; your app's JavaScript imports the second. When the two disagree it usually surfaces at runtime, as a missing method or "Cannot find native module" — and two copies of different versions can fail the build instead.`,
|
|
362
|
+
` Run \`npm ls ${packageName}\` (or \`yarn why\` / \`pnpm why\`) to find what pulls in the second copy, deduplicate it with \`npm dedupe\` (or \`yarn dedupe\` / \`pnpm dedupe\`), then re-run \`npx react-native spm update\`.`,
|
|
363
|
+
].join('\n')
|
|
364
|
+
)
|
|
365
|
+
.join('\n\n');
|
|
366
|
+
}
|
|
367
|
+
|
|
368
|
+
// Most specific ref first: CocoaPods accepts only one, and a pod that somehow
|
|
369
|
+
// carries two is best described by the one that pins a single commit.
|
|
370
|
+
const GIT_REFS = ['commit', 'tag', 'branch'];
|
|
371
|
+
|
|
372
|
+
// A pod's `source` is a custom spec repo, not the CocoaPods trunk. A git pod is
|
|
373
|
+
// identified by its ref rather than a version, and a local path pod by neither:
|
|
374
|
+
// CocoaPods takes that directory as it is.
|
|
375
|
+
function extraPodOrigin(pod) {
|
|
376
|
+
const versioned = (origin) =>
|
|
377
|
+
pod.version != null ? `${origin}, version ${pod.version}` : origin;
|
|
378
|
+
if (pod.path != null) return `local path: ${pod.path}`;
|
|
379
|
+
if (pod.git != null) {
|
|
380
|
+
const ref = GIT_REFS.find((key) => pod[key] != null);
|
|
381
|
+
return ref != null ? `git: ${pod.git}, ${ref} ${pod[ref]}` : versioned(`git: ${pod.git}`);
|
|
382
|
+
}
|
|
383
|
+
if (pod.podspec != null) return versioned(`podspec: ${pod.podspec}`);
|
|
384
|
+
if (pod.source != null) return versioned(`spec repo: ${pod.source}`);
|
|
385
|
+
return versioned('published pod');
|
|
386
|
+
}
|
|
387
|
+
|
|
388
|
+
/**
|
|
389
|
+
* Pods the app adds for CocoaPods — `extraPods` in its config, which
|
|
390
|
+
* expo-build-properties writes into Podfile.properties.json. `pod install`
|
|
391
|
+
* installs them and this plugin does not, so this names them before the compile,
|
|
392
|
+
* link or runtime failure that would otherwise be their first sign.
|
|
393
|
+
*/
|
|
394
|
+
function renderExtraPodsWarning(pods) {
|
|
395
|
+
if (!pods.length) return '';
|
|
396
|
+
const one = pods.length === 1;
|
|
397
|
+
return [
|
|
398
|
+
`warning: This app declares ${pods.length} extra CocoaPods ${one ? 'dependency' : 'dependencies'}, and the Swift Package Manager plugin does not install ${one ? 'it' : 'them'}:`,
|
|
399
|
+
...pods.map((pod) => ` ${pod.name} (${extraPodOrigin(pod)})`),
|
|
400
|
+
` ${one ? 'It comes' : 'They come'} from \`extraPods\` in your app config, which expo-build-properties writes into ios/Podfile.properties.json. The plugin reads that file — that is how ${one ? 'the pod is' : 'these pods are'} named here — but it contributes no CocoaPods dependency to the Swift Package Manager graph, whatever ${one ? 'it is' : 'they are'} installed from.`,
|
|
401
|
+
` Native code that imports ${one ? 'it' : 'one of them'} fails to compile or link. Code that reaches a pod at runtime instead — a class looked up by name, an Objective-C category, a bundled resource — builds and then fails on device, so a pod nothing imports is not necessarily unused.`,
|
|
402
|
+
` There is no Swift Package Manager route for ${one ? 'it' : 'them'} today. Add a Swift package providing the same code to your Xcode project and drop the \`extraPods\` entry, or keep this app on CocoaPods.`,
|
|
403
|
+
].join('\n');
|
|
404
|
+
}
|
|
405
|
+
|
|
388
406
|
/** Print the report and return the error to throw, or null when nothing is uncovered. */
|
|
389
407
|
function reportUnsupported(entries) {
|
|
390
408
|
if (!entries.length) return null;
|
|
@@ -397,12 +415,14 @@ module.exports = {
|
|
|
397
415
|
COVERED_POD_PREFIXES,
|
|
398
416
|
UNMAPPED_POD_ALLOWLIST,
|
|
399
417
|
classifyUnsupported,
|
|
400
|
-
spmConfigProduct,
|
|
401
418
|
podspecDependencies,
|
|
402
419
|
unmappedPodDependencies,
|
|
403
420
|
collectUnmappedDependencies,
|
|
421
|
+
collectRootConflicts,
|
|
404
422
|
renderUnsupportedReport,
|
|
405
423
|
renderUnmappedDependencyWarning,
|
|
406
424
|
renderXcconfigLinkerWarning,
|
|
425
|
+
renderRootConflictWarning,
|
|
426
|
+
renderExtraPodsWarning,
|
|
407
427
|
reportUnsupported,
|
|
408
428
|
};
|
|
@@ -17,6 +17,13 @@ const path = require('path');
|
|
|
17
17
|
|
|
18
18
|
const FLAVORS = ['debug', 'release'];
|
|
19
19
|
|
|
20
|
+
/**
|
|
21
|
+
* Byte order, the order CocoaPods sorts in. Declaration order reaches the build:
|
|
22
|
+
* it decides which contributor a colliding artifact is taken from, so it must not
|
|
23
|
+
* vary with the machine's locale.
|
|
24
|
+
*/
|
|
25
|
+
const byteOrder = (a, b) => (a < b ? -1 : a > b ? 1 : 0);
|
|
26
|
+
|
|
20
27
|
function stableFrameworkId(frameworkName) {
|
|
21
28
|
const kebab = frameworkName
|
|
22
29
|
.replace(/([a-z0-9])([A-Z])/g, '$1-$2')
|
|
@@ -45,18 +52,28 @@ function existingArtifactSource(baseDir, flavor, frameworkName) {
|
|
|
45
52
|
return null;
|
|
46
53
|
}
|
|
47
54
|
|
|
48
|
-
|
|
55
|
+
/**
|
|
56
|
+
* Candidate directories for precompiled output, in lookup order: the path
|
|
57
|
+
* override, the monorepo prebuild output, then the copy bundled into the npm
|
|
58
|
+
* package at `moduleRoot`. `buildPath` is relative to a prebuild output root,
|
|
59
|
+
* `bundledPath` to the package's `prebuilds` directory.
|
|
60
|
+
*/
|
|
61
|
+
function precompiledBaseDirs(buildPath, moduleRoot, bundledPath) {
|
|
49
62
|
const bases = [];
|
|
50
63
|
if (process.env.EXPO_PRECOMPILED_MODULES_PATH) {
|
|
51
|
-
bases.push(path.resolve(process.env.EXPO_PRECOMPILED_MODULES_PATH,
|
|
64
|
+
bases.push(path.resolve(process.env.EXPO_PRECOMPILED_MODULES_PATH, ...buildPath));
|
|
52
65
|
}
|
|
53
66
|
bases.push(
|
|
54
|
-
path.resolve(__dirname, '..', '..', '..', 'precompile', '.build',
|
|
55
|
-
path.join(moduleRoot, 'prebuilds',
|
|
67
|
+
path.resolve(__dirname, '..', '..', '..', 'precompile', '.build', ...buildPath),
|
|
68
|
+
path.join(moduleRoot, 'prebuilds', ...bundledPath)
|
|
56
69
|
);
|
|
57
70
|
return Array.from(new Set(bases));
|
|
58
71
|
}
|
|
59
72
|
|
|
73
|
+
function artifactBaseDirs(packageName, moduleRoot) {
|
|
74
|
+
return precompiledBaseDirs([packageName, 'output'], moduleRoot, ['output']);
|
|
75
|
+
}
|
|
76
|
+
|
|
60
77
|
/**
|
|
61
78
|
* A flavor tarball holds one xcframework root per product the prebuild packed:
|
|
62
79
|
* the module itself plus any SwiftPM dependency bundled with it (for example
|
|
@@ -127,10 +144,7 @@ function extractTarball(sourcePath, frameworkName, cacheDir, flavor) {
|
|
|
127
144
|
} catch {}
|
|
128
145
|
|
|
129
146
|
validateTarEntries(sourcePath, frameworkName);
|
|
130
|
-
|
|
131
|
-
fs.rmSync(temp, { recursive: true, force: true });
|
|
132
|
-
fs.mkdirSync(temp, { recursive: true });
|
|
133
|
-
try {
|
|
147
|
+
replaceDirectory(destination, (temp) => {
|
|
134
148
|
execFileSync('tar', ['-xzf', sourcePath, '-C', temp], { stdio: 'pipe' });
|
|
135
149
|
const extracted = path.join(temp, `${frameworkName}.xcframework`);
|
|
136
150
|
if (!fs.existsSync(path.join(extracted, 'Info.plist'))) {
|
|
@@ -139,13 +153,26 @@ function extractTarball(sourcePath, frameworkName, cacheDir, flavor) {
|
|
|
139
153
|
);
|
|
140
154
|
}
|
|
141
155
|
fs.writeFileSync(path.join(temp, '.source.json'), stamp, 'utf8');
|
|
156
|
+
});
|
|
157
|
+
return xcframeworkPath;
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
/**
|
|
161
|
+
* Fills a sibling temp directory with `fill(temp)` and only then swaps it in for
|
|
162
|
+
* `destination`, so a fill that throws leaves the previous contents untouched.
|
|
163
|
+
*/
|
|
164
|
+
function replaceDirectory(destination, fill) {
|
|
165
|
+
const temp = `${destination}.tmp-${process.pid}`;
|
|
166
|
+
fs.rmSync(temp, { recursive: true, force: true });
|
|
167
|
+
fs.mkdirSync(temp, { recursive: true });
|
|
168
|
+
try {
|
|
169
|
+
fill(temp);
|
|
142
170
|
fs.rmSync(destination, { recursive: true, force: true });
|
|
143
171
|
fs.mkdirSync(path.dirname(destination), { recursive: true });
|
|
144
172
|
fs.renameSync(temp, destination);
|
|
145
173
|
} finally {
|
|
146
174
|
fs.rmSync(temp, { recursive: true, force: true });
|
|
147
175
|
}
|
|
148
|
-
return xcframeworkPath;
|
|
149
176
|
}
|
|
150
177
|
|
|
151
178
|
function prepareArtifactSource(source, frameworkName, cacheDir, flavor) {
|
|
@@ -238,6 +265,196 @@ function resolveFlavoredFramework({ packageName, moduleRoot, frameworkName, cach
|
|
|
238
265
|
return null;
|
|
239
266
|
}
|
|
240
267
|
|
|
268
|
+
/**
|
|
269
|
+
* Candidate parents (each holding `<flavor>/<Dep>.xcframework`) for a SwiftPM
|
|
270
|
+
* package a precompiled module links. The bundled copy lives in the npm package
|
|
271
|
+
* of the module that links it.
|
|
272
|
+
*/
|
|
273
|
+
function spmDependencyBaseDirs(depName, ownerModuleRoot) {
|
|
274
|
+
return precompiledBaseDirs(['.spm-deps', depName], ownerModuleRoot, ['spm-deps', depName]);
|
|
275
|
+
}
|
|
276
|
+
|
|
277
|
+
/**
|
|
278
|
+
* A dependency copied verbatim from an upstream `.binaryTarget` can be a static
|
|
279
|
+
* library, and one built from a package whose product is named differently ships
|
|
280
|
+
* a differently named framework. Both reach RN and the interface tree as a slice
|
|
281
|
+
* that is not `<Dep>.framework`, and fail there with a message naming neither the
|
|
282
|
+
* dependency nor the module that pulled it in — so they are rejected here.
|
|
283
|
+
*/
|
|
284
|
+
function readXcframeworkPlist(plistPath) {
|
|
285
|
+
try {
|
|
286
|
+
return JSON.parse(
|
|
287
|
+
execFileSync('plutil', ['-convert', 'json', '-o', '-', plistPath], { encoding: 'utf8' })
|
|
288
|
+
);
|
|
289
|
+
} catch (error) {
|
|
290
|
+
throw new Error(
|
|
291
|
+
`[expo-spm-plugin] ${plistPath} could not be read as a property list: ${error.message}. ` +
|
|
292
|
+
'An XCFramework keeps the list of what it holds there, so this one is damaged or was ' +
|
|
293
|
+
'never an XCFramework. Delete it and rebuild the dependency with the Expo prebuild ' +
|
|
294
|
+
'pipeline, or reinstall the package that ships it.',
|
|
295
|
+
{ cause: error }
|
|
296
|
+
);
|
|
297
|
+
}
|
|
298
|
+
}
|
|
299
|
+
|
|
300
|
+
function assertEmbeddableFramework(depName, xcframeworkPath) {
|
|
301
|
+
const plistPath = path.join(xcframeworkPath, 'Info.plist');
|
|
302
|
+
const plist = readXcframeworkPlist(plistPath);
|
|
303
|
+
if (plist.AvailableLibraries != null && !Array.isArray(plist.AvailableLibraries)) {
|
|
304
|
+
throw new Error(
|
|
305
|
+
`[expo-spm-plugin] ${plistPath} lists AvailableLibraries as something other than a list of ` +
|
|
306
|
+
'slices, so the plugin cannot tell what the XCFramework holds. The artifact is damaged. ' +
|
|
307
|
+
'Delete it and rebuild the dependency with the Expo prebuild pipeline, or reinstall the ' +
|
|
308
|
+
'package that ships it.'
|
|
309
|
+
);
|
|
310
|
+
}
|
|
311
|
+
const libraries = plist.AvailableLibraries ?? [];
|
|
312
|
+
const expected = `${depName}.framework`;
|
|
313
|
+
const unusable = libraries
|
|
314
|
+
.map((library) => library?.LibraryPath)
|
|
315
|
+
.filter((libraryPath) => libraryPath !== expected);
|
|
316
|
+
if (libraries.length === 0 || unusable.length > 0) {
|
|
317
|
+
const found =
|
|
318
|
+
unusable.map((libraryPath) => libraryPath ?? 'a slice with no LibraryPath').join(', ') ||
|
|
319
|
+
'no library slices';
|
|
320
|
+
throw new Error(
|
|
321
|
+
`[expo-spm-plugin] ${depName} does not ship a ${expected}: ${xcframeworkPath} holds ` +
|
|
322
|
+
`${found}. React Native links and embeds Expo's precompiled dependencies as dynamic ` +
|
|
323
|
+
'frameworks named after the product, so a static library, a differently named framework ' +
|
|
324
|
+
'and an XCFramework without slices are all unusable. Rebuild the dependency with the ' +
|
|
325
|
+
"Expo prebuild pipeline, or exclude the Expo module that links it in your app's " +
|
|
326
|
+
'package.json: "expo": { "autolinking": { "exclude": [...] } }.'
|
|
327
|
+
);
|
|
328
|
+
}
|
|
329
|
+
}
|
|
330
|
+
|
|
331
|
+
/**
|
|
332
|
+
* XCFrameworks are directories; a stale file of the same name is not one. Only an
|
|
333
|
+
* absent path counts as "not built here" — swallowing every error would make an
|
|
334
|
+
* unreadable one look identical to a missing artifact, and the app would be built
|
|
335
|
+
* without a dependency it links.
|
|
336
|
+
*/
|
|
337
|
+
function isDirectory(candidate) {
|
|
338
|
+
try {
|
|
339
|
+
return fs.statSync(candidate).isDirectory();
|
|
340
|
+
} catch (error) {
|
|
341
|
+
if (error.code === 'ENOENT' || error.code === 'ENOTDIR') {
|
|
342
|
+
return false;
|
|
343
|
+
}
|
|
344
|
+
throw new Error(
|
|
345
|
+
`[expo-spm-plugin] ${candidate} could not be read: ${error.message}. The plugin cannot ` +
|
|
346
|
+
'tell whether a precompiled dependency is there, and it will not silently build an app ' +
|
|
347
|
+
'without one. Make that path readable — or delete it and rebuild the dependency with ' +
|
|
348
|
+
'the Expo prebuild pipeline — then run `npx react-native spm update` again.',
|
|
349
|
+
{ cause: error }
|
|
350
|
+
);
|
|
351
|
+
}
|
|
352
|
+
}
|
|
353
|
+
|
|
354
|
+
/**
|
|
355
|
+
* RN embeds every flavored framework into the app bundle, so it rejects the whole
|
|
356
|
+
* autolinking result when two declarations share an id or a framework name. Two
|
|
357
|
+
* distinct products can collide after `stableFrameworkId` (Foo and ExpoFoo both
|
|
358
|
+
* become expo-foo), and a dependency can carry the name of a module, so the check
|
|
359
|
+
* belongs on the combined array rather than on either source.
|
|
360
|
+
*/
|
|
361
|
+
function assertDistinctFlavoredFrameworks(frameworks) {
|
|
362
|
+
const describe = (framework) =>
|
|
363
|
+
framework.flavors?.debug != null
|
|
364
|
+
? `${framework.frameworkName} (${framework.flavors.debug})`
|
|
365
|
+
: framework.frameworkName;
|
|
366
|
+
for (const [key, label] of [
|
|
367
|
+
['id', 'framework id'],
|
|
368
|
+
['frameworkName', 'framework name'],
|
|
369
|
+
]) {
|
|
370
|
+
const seen = new Map();
|
|
371
|
+
for (const framework of frameworks) {
|
|
372
|
+
const previous = seen.get(framework[key]);
|
|
373
|
+
if (previous != null) {
|
|
374
|
+
throw new Error(
|
|
375
|
+
`[expo-spm-plugin] ${describe(previous)} and ${describe(framework)} both declare the ` +
|
|
376
|
+
`${label} "${framework[key]}". React Native embeds each flavored framework once and ` +
|
|
377
|
+
'rejects the whole autolinking graph over a collision, so no Expo module would ' +
|
|
378
|
+
'build. ' +
|
|
379
|
+
"Exclude the Expo module that brings in one of the two in your app's package.json: " +
|
|
380
|
+
'"expo": { "autolinking": { "exclude": [...] } }, and report the pair at ' +
|
|
381
|
+
'https://github.com/expo/expo/issues — one of the two products has to be renamed.'
|
|
382
|
+
);
|
|
383
|
+
}
|
|
384
|
+
seen.set(framework[key], framework);
|
|
385
|
+
}
|
|
386
|
+
}
|
|
387
|
+
}
|
|
388
|
+
|
|
389
|
+
/**
|
|
390
|
+
* Returns null when the dependency has no artifact anywhere. Each flavor walks
|
|
391
|
+
* the full candidate list on its own, so a partial monorepo build cannot shadow
|
|
392
|
+
* a complete bundled copy — CocoaPods resolves it the same way in
|
|
393
|
+
* `expo-modules-autolinking/scripts/ios/precompiled_modules.rb`.
|
|
394
|
+
*/
|
|
395
|
+
function resolveSpmDependencyFramework(depName, ownerModuleRoot) {
|
|
396
|
+
const bases = spmDependencyBaseDirs(depName, ownerModuleRoot);
|
|
397
|
+
const flavors = {};
|
|
398
|
+
for (const flavor of FLAVORS) {
|
|
399
|
+
const base = bases.find((dir) => isDirectory(path.join(dir, flavor, `${depName}.xcframework`)));
|
|
400
|
+
if (base != null) flavors[flavor] = path.join(base, flavor, `${depName}.xcframework`);
|
|
401
|
+
}
|
|
402
|
+
const resolved = FLAVORS.filter((flavor) => flavors[flavor] != null);
|
|
403
|
+
if (resolved.length === 0) {
|
|
404
|
+
return null;
|
|
405
|
+
}
|
|
406
|
+
for (const flavor of FLAVORS) {
|
|
407
|
+
if (flavors[flavor] == null) {
|
|
408
|
+
throw new Error(
|
|
409
|
+
`[expo-spm-plugin] ${depName} has no ${flavor} XCFramework, although its ` +
|
|
410
|
+
`${resolved[0]} one resolved. Expo declares its precompiled dependencies as immutable ` +
|
|
411
|
+
'pairs, so half a pair would link in one configuration and fail to launch in the other ' +
|
|
412
|
+
`with dyld "Library not loaded: @rpath/${depName}.framework/${depName}". Build the ` +
|
|
413
|
+
'dependency for both flavors with the Expo prebuild pipeline, or install a package ' +
|
|
414
|
+
`that ships both. Searched: ${bases.join(', ')}.`
|
|
415
|
+
);
|
|
416
|
+
}
|
|
417
|
+
}
|
|
418
|
+
const framework = validateFlavoredFramework({
|
|
419
|
+
id: stableFrameworkId(depName),
|
|
420
|
+
frameworkName: depName,
|
|
421
|
+
linkage: 'dynamic',
|
|
422
|
+
flavors,
|
|
423
|
+
});
|
|
424
|
+
for (const flavor of FLAVORS) {
|
|
425
|
+
assertEmbeddableFramework(depName, framework.flavors[flavor]);
|
|
426
|
+
}
|
|
427
|
+
return framework;
|
|
428
|
+
}
|
|
429
|
+
|
|
430
|
+
/**
|
|
431
|
+
* The SwiftPM packages the precompiled modules link (SDWebImage, ZXingObjC, …),
|
|
432
|
+
* each shipped as its own XCFramework beside the module.
|
|
433
|
+
*
|
|
434
|
+
* Two modules can link the same package, and RN's flavored frameworks are a flat
|
|
435
|
+
* app-wide array that rejects a repeated id or framework name, so each dependency
|
|
436
|
+
* is declared exactly once. Its owner — the first consuming pod name in byte
|
|
437
|
+
* order, as CocoaPods' `ensure_shared_spm_deps` picks it — is also the npm
|
|
438
|
+
* package searched for a bundled copy, so the two installers must order names
|
|
439
|
+
* identically. The other consumers need nothing: one declaration serves the whole
|
|
440
|
+
* app.
|
|
441
|
+
*/
|
|
442
|
+
function resolveSpmDependencyFrameworks(consumers) {
|
|
443
|
+
const owners = new Map();
|
|
444
|
+
for (const consumer of consumers) {
|
|
445
|
+
for (const depName of consumer.spmDependencies ?? []) {
|
|
446
|
+
const owner = owners.get(depName);
|
|
447
|
+
if (owner == null || consumer.podName < owner.podName) {
|
|
448
|
+
owners.set(depName, consumer);
|
|
449
|
+
}
|
|
450
|
+
}
|
|
451
|
+
}
|
|
452
|
+
return [...owners.keys()]
|
|
453
|
+
.sort()
|
|
454
|
+
.map((depName) => resolveSpmDependencyFramework(depName, owners.get(depName).moduleRoot))
|
|
455
|
+
.filter((framework) => framework != null);
|
|
456
|
+
}
|
|
457
|
+
|
|
241
458
|
function copyFileIfLarger(source, destination) {
|
|
242
459
|
let shouldCopy = true;
|
|
243
460
|
try {
|
|
@@ -253,7 +470,7 @@ function mergeDirectory(source, destination) {
|
|
|
253
470
|
if (!fs.existsSync(source)) return;
|
|
254
471
|
for (const entry of fs
|
|
255
472
|
.readdirSync(source, { withFileTypes: true })
|
|
256
|
-
.sort((a, b) => a.name
|
|
473
|
+
.sort((a, b) => byteOrder(a.name, b.name))) {
|
|
257
474
|
const src = path.join(source, entry.name);
|
|
258
475
|
const dst = path.join(destination, entry.name);
|
|
259
476
|
if (entry.isDirectory()) {
|
|
@@ -271,11 +488,8 @@ function mergeDirectory(source, destination) {
|
|
|
271
488
|
* RN owns all runtime linking and embedding of the flavored binaries.
|
|
272
489
|
*/
|
|
273
490
|
function prepareCompileInterfaces(frameworks, destination) {
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
fs.mkdirSync(temp, { recursive: true });
|
|
277
|
-
try {
|
|
278
|
-
for (const framework of [...frameworks].sort((a, b) => a.id.localeCompare(b.id))) {
|
|
491
|
+
replaceDirectory(destination, (temp) => {
|
|
492
|
+
for (const framework of [...frameworks].sort((a, b) => byteOrder(a.id, b.id))) {
|
|
279
493
|
const source = framework.flavors.debug;
|
|
280
494
|
const sliceFrameworks = fs
|
|
281
495
|
.readdirSync(source, { withFileTypes: true })
|
|
@@ -297,20 +511,18 @@ function prepareCompileInterfaces(frameworks, destination) {
|
|
|
297
511
|
}
|
|
298
512
|
}
|
|
299
513
|
}
|
|
300
|
-
|
|
301
|
-
fs.mkdirSync(path.dirname(destination), { recursive: true });
|
|
302
|
-
fs.renameSync(temp, destination);
|
|
303
|
-
} finally {
|
|
304
|
-
fs.rmSync(temp, { recursive: true, force: true });
|
|
305
|
-
}
|
|
514
|
+
});
|
|
306
515
|
return destination;
|
|
307
516
|
}
|
|
308
517
|
|
|
309
518
|
module.exports = {
|
|
310
519
|
FLAVORS,
|
|
311
520
|
artifactBaseDirs,
|
|
521
|
+
assertDistinctFlavoredFrameworks,
|
|
522
|
+
byteOrder,
|
|
312
523
|
prepareCompileInterfaces,
|
|
313
524
|
resolveFlavoredFramework,
|
|
525
|
+
resolveSpmDependencyFrameworks,
|
|
314
526
|
stableFrameworkId,
|
|
315
527
|
validateFlavoredFramework,
|
|
316
528
|
};
|