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.
- package/android/build.gradle +2 -2
- package/bundledNativeModules.json +15 -15
- package/package.json +11 -11
- package/scripts/spm/README.md +43 -3
- package/scripts/spm/__tests__/cli.test.js +17 -2
- package/scripts/spm/__tests__/commands.test.js +61 -0
- package/scripts/spm/__tests__/diagnostics.test.js +210 -9
- package/scripts/spm/__tests__/direct.test.js +387 -0
- package/scripts/spm/__tests__/flavored-frameworks.test.js +127 -0
- package/scripts/spm/__tests__/helpers.js +9 -0
- package/scripts/spm/__tests__/manifests.test.js +38 -50
- package/scripts/spm/__tests__/plugin.test.js +1238 -53
- package/scripts/spm/__tests__/precompiled-sources.test.js +139 -0
- package/scripts/spm/classify.js +8 -6
- package/scripts/spm/cli.js +11 -4
- package/scripts/spm/commands.js +18 -1
- package/scripts/spm/diagnostics.js +112 -8
- package/scripts/spm/direct.js +215 -0
- package/scripts/spm/flavored-frameworks.js +125 -40
- package/scripts/spm/manifests.js +4 -3
- package/scripts/spm/plugin.js +432 -82
- package/template.tgz +0 -0
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const path = require('path');
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Every path here is virtual: the monorepo base is the repository's own prebuild output, so
|
|
7
|
+
* a real-filesystem suite would resolve whatever the developer last built there. Tarball
|
|
8
|
+
* extraction needs a real `tar` and is covered in flavored-frameworks.test.js.
|
|
9
|
+
*
|
|
10
|
+
* The plugin's Jest config applies no transform, so `jest.mock` runs in place and may close
|
|
11
|
+
* over `volume`.
|
|
12
|
+
*/
|
|
13
|
+
const volume = new Set();
|
|
14
|
+
|
|
15
|
+
jest.mock('fs', () => ({ existsSync: (target) => volume.has(target) }));
|
|
16
|
+
|
|
17
|
+
const {
|
|
18
|
+
frameworkSource,
|
|
19
|
+
headersXCFrameworkSearchPaths,
|
|
20
|
+
resolveFlavoredFramework,
|
|
21
|
+
resolveHeadersXCFrameworkWithSource,
|
|
22
|
+
} = require('../flavored-frameworks');
|
|
23
|
+
|
|
24
|
+
const ENV = path.join('/virtual', 'precompiled-modules');
|
|
25
|
+
const MONOREPO = path.resolve(__dirname, '../../../../precompile/.build');
|
|
26
|
+
const MODULE_ROOT = '/virtual/node_modules/expo-modules-core';
|
|
27
|
+
const CACHE = '/virtual/cache';
|
|
28
|
+
|
|
29
|
+
const bases = {
|
|
30
|
+
env: path.join(ENV, 'expo-modules-core', 'output'),
|
|
31
|
+
monorepo: path.join(MONOREPO, 'expo-modules-core', 'output'),
|
|
32
|
+
bundled: path.join(MODULE_ROOT, 'prebuilds', 'output'),
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
const headersAt = (base, product = 'ExpoModulesCore') =>
|
|
36
|
+
path.join(base, 'headers', 'xcframeworks', `${product}Headers.xcframework`);
|
|
37
|
+
|
|
38
|
+
function addHeaders(base) {
|
|
39
|
+
volume.add(headersAt(base));
|
|
40
|
+
volume.add(path.join(headersAt(base), 'Info.plist'));
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
function addFlavoredPair(base, frameworkName) {
|
|
44
|
+
for (const flavor of ['debug', 'release']) {
|
|
45
|
+
const xcframework = path.join(base, flavor, 'xcframeworks', `${frameworkName}.xcframework`);
|
|
46
|
+
volume.add(xcframework);
|
|
47
|
+
volume.add(path.join(xcframework, 'Info.plist'));
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
const lookup = { packageName: 'expo-modules-core', moduleRoot: MODULE_ROOT, cacheDir: CACHE };
|
|
52
|
+
|
|
53
|
+
describe('precompiled source kinds', () => {
|
|
54
|
+
const savedEnv = process.env.EXPO_PRECOMPILED_MODULES_PATH;
|
|
55
|
+
|
|
56
|
+
beforeEach(() => {
|
|
57
|
+
volume.clear();
|
|
58
|
+
process.env.EXPO_PRECOMPILED_MODULES_PATH = ENV;
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
afterAll(() => {
|
|
62
|
+
if (savedEnv == null) {
|
|
63
|
+
delete process.env.EXPO_PRECOMPILED_MODULES_PATH;
|
|
64
|
+
} else {
|
|
65
|
+
process.env.EXPO_PRECOMPILED_MODULES_PATH = savedEnv;
|
|
66
|
+
}
|
|
67
|
+
});
|
|
68
|
+
|
|
69
|
+
it.each(['env', 'monorepo', 'bundled'])(
|
|
70
|
+
'records that a flavored framework came from the %s base',
|
|
71
|
+
(kind) => {
|
|
72
|
+
addFlavoredPair(bases[kind], 'ExpoModulesCore');
|
|
73
|
+
const framework = resolveFlavoredFramework({ ...lookup, frameworkName: 'ExpoModulesCore' });
|
|
74
|
+
expect(frameworkSource(framework)).toEqual({ kind, dir: bases[kind] });
|
|
75
|
+
}
|
|
76
|
+
);
|
|
77
|
+
|
|
78
|
+
it('keeps the flavored declaration React Native receives free of the source', () => {
|
|
79
|
+
addFlavoredPair(bases.env, 'ExpoModulesCore');
|
|
80
|
+
const framework = resolveFlavoredFramework({ ...lookup, frameworkName: 'ExpoModulesCore' });
|
|
81
|
+
expect(Object.keys(framework).sort()).toEqual(['flavors', 'frameworkName', 'id', 'linkage']);
|
|
82
|
+
});
|
|
83
|
+
|
|
84
|
+
it('prefers EXPO_PRECOMPILED_MODULES_PATH, then the monorepo, then the npm package', () => {
|
|
85
|
+
for (const base of Object.values(bases)) addHeaders(base);
|
|
86
|
+
const headers = () =>
|
|
87
|
+
resolveHeadersXCFrameworkWithSource({ ...lookup, productName: 'ExpoModulesCore' });
|
|
88
|
+
|
|
89
|
+
expect(headers()).toEqual({
|
|
90
|
+
xcframework: headersAt(bases.env),
|
|
91
|
+
source: { kind: 'env', dir: bases.env },
|
|
92
|
+
});
|
|
93
|
+
volume.delete(headersAt(bases.env));
|
|
94
|
+
expect(headers()).toEqual({
|
|
95
|
+
xcframework: headersAt(bases.monorepo),
|
|
96
|
+
source: { kind: 'monorepo', dir: bases.monorepo },
|
|
97
|
+
});
|
|
98
|
+
volume.delete(headersAt(bases.monorepo));
|
|
99
|
+
expect(headers()).toEqual({
|
|
100
|
+
xcframework: headersAt(bases.bundled),
|
|
101
|
+
source: { kind: 'bundled', dir: bases.bundled },
|
|
102
|
+
});
|
|
103
|
+
});
|
|
104
|
+
|
|
105
|
+
it('skips EXPO_PRECOMPILED_MODULES_PATH when it is unset', () => {
|
|
106
|
+
delete process.env.EXPO_PRECOMPILED_MODULES_PATH;
|
|
107
|
+
addHeaders(bases.monorepo);
|
|
108
|
+
expect(
|
|
109
|
+
resolveHeadersXCFrameworkWithSource({ ...lookup, productName: 'ExpoModulesCore' }).source.kind
|
|
110
|
+
).toBe('monorepo');
|
|
111
|
+
});
|
|
112
|
+
|
|
113
|
+
it('returns null when no base has the headers, and names every path it searched', () => {
|
|
114
|
+
addFlavoredPair(bases.env, 'ExpoModulesCore');
|
|
115
|
+
expect(
|
|
116
|
+
resolveHeadersXCFrameworkWithSource({ ...lookup, productName: 'ExpoModulesCore' })
|
|
117
|
+
).toBeNull();
|
|
118
|
+
const tarball = (base) =>
|
|
119
|
+
path.join(base, 'headers', 'xcframeworks', 'ExpoModulesCoreHeaders.tar.gz');
|
|
120
|
+
expect(headersXCFrameworkSearchPaths({ ...lookup, productName: 'ExpoModulesCore' })).toEqual([
|
|
121
|
+
headersAt(bases.env),
|
|
122
|
+
tarball(bases.env),
|
|
123
|
+
headersAt(bases.monorepo),
|
|
124
|
+
tarball(bases.monorepo),
|
|
125
|
+
headersAt(bases.bundled),
|
|
126
|
+
tarball(bases.bundled),
|
|
127
|
+
]);
|
|
128
|
+
});
|
|
129
|
+
|
|
130
|
+
it('searches no npm package when the package is not installed', () => {
|
|
131
|
+
const paths = headersXCFrameworkSearchPaths({
|
|
132
|
+
packageName: 'expo-modules-jsi',
|
|
133
|
+
moduleRoot: null,
|
|
134
|
+
productName: 'ExpoModulesJSI',
|
|
135
|
+
});
|
|
136
|
+
expect(paths).toHaveLength(4);
|
|
137
|
+
expect(paths.every((p) => p.startsWith(ENV) || p.startsWith(MONOREPO))).toBe(true);
|
|
138
|
+
});
|
|
139
|
+
});
|
package/scripts/spm/classify.js
CHANGED
|
@@ -57,16 +57,18 @@ function documentedPackageRoot(entry) {
|
|
|
57
57
|
|
|
58
58
|
/**
|
|
59
59
|
* Absolute paths RN should watch for autolinking staleness (the `watchPaths`
|
|
60
|
-
* plugin contract): each module's checked-in Package.swift
|
|
61
|
-
*
|
|
62
|
-
* the manifest
|
|
63
|
-
* resolution
|
|
64
|
-
*
|
|
60
|
+
* plugin contract): each module's checked-in Package.swift, expo-module.config.json
|
|
61
|
+
* and spm.config.json. Editing any of them must trip the in-build re-sync —
|
|
62
|
+
* the manifest decides how the module is built from source, expo-module.config.json drives
|
|
63
|
+
* module resolution, and spm.config.json declares the products the plugin links
|
|
64
|
+
* precompiled. Only existing paths are returned (RN
|
|
65
|
+
* warn-and-drops the rest, but a vanished path is its own staleness signal handled
|
|
66
|
+
* RN-side).
|
|
65
67
|
*/
|
|
66
68
|
function collectWatchPaths(moduleRoots) {
|
|
67
69
|
const watchPaths = [];
|
|
68
70
|
for (const root of moduleRoots) {
|
|
69
|
-
for (const name of ['Package.swift', 'expo-module.config.json']) {
|
|
71
|
+
for (const name of ['Package.swift', 'expo-module.config.json', 'spm.config.json']) {
|
|
70
72
|
const candidate = path.join(root, name);
|
|
71
73
|
if (fs.existsSync(candidate)) watchPaths.push(candidate);
|
|
72
74
|
}
|
package/scripts/spm/cli.js
CHANGED
|
@@ -30,13 +30,20 @@ function runAutolinking(appRoot, args) {
|
|
|
30
30
|
}
|
|
31
31
|
|
|
32
32
|
/**
|
|
33
|
-
* `resolve --platform apple --json`: {modules, extraDependencies},
|
|
34
|
-
* (older CLIs return the bare array).
|
|
33
|
+
* `resolve --platform apple --json`: {modules, extraDependencies, buildFromSource}, all
|
|
34
|
+
* always arrays (older CLIs return the bare array). `buildFromSource` is the app's
|
|
35
|
+
* autolinking option, read from the same output CocoaPods reads it from.
|
|
35
36
|
*/
|
|
36
37
|
function resolveExpoModules(appRoot) {
|
|
37
38
|
const parsed = runAutolinking(appRoot, ['resolve', '--platform', 'apple', '--json']);
|
|
38
|
-
if (Array.isArray(parsed))
|
|
39
|
-
|
|
39
|
+
if (Array.isArray(parsed)) {
|
|
40
|
+
return { modules: parsed, extraDependencies: [], buildFromSource: [] };
|
|
41
|
+
}
|
|
42
|
+
return {
|
|
43
|
+
modules: parsed.modules ?? [],
|
|
44
|
+
extraDependencies: parsed.extraDependencies ?? [],
|
|
45
|
+
buildFromSource: parsed.configuration?.buildFromSource ?? [],
|
|
46
|
+
};
|
|
40
47
|
}
|
|
41
48
|
|
|
42
49
|
/** `prebuilt-metadata --json`: the same pod → package → product document `pod install` reads. */
|
package/scripts/spm/commands.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
+
const fs = require('fs');
|
|
3
4
|
const path = require('path');
|
|
4
5
|
|
|
5
6
|
const DEFAULT_REACT_NATIVE_DIR = 'node_modules/react-native';
|
|
@@ -26,7 +27,23 @@ function configureSpmUpdateCommand({ appRoot, reactNativeRoot } = {}) {
|
|
|
26
27
|
reactNativeDir =
|
|
27
28
|
appRoot == null || reactNativeRoot == null
|
|
28
29
|
? DEFAULT_REACT_NATIVE_DIR
|
|
29
|
-
: path.relative(appRoot, reactNativeRoot).split(path.sep).join('/');
|
|
30
|
+
: path.relative(realPath(appRoot), realParentPath(reactNativeRoot)).split(path.sep).join('/');
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
// Resolving react-native itself would name pnpm's versioned store path instead of the link.
|
|
34
|
+
function realParentPath(dir) {
|
|
35
|
+
return path.join(realPath(path.dirname(dir)), path.basename(dir));
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
// The shell resolves `..` against the real directory, and require.resolve returns real paths, so a
|
|
39
|
+
// path relative to a symlinked app root would point elsewhere.
|
|
40
|
+
function realPath(dir) {
|
|
41
|
+
try {
|
|
42
|
+
return fs.realpathSync(dir);
|
|
43
|
+
} catch {
|
|
44
|
+
const parent = path.dirname(dir);
|
|
45
|
+
return parent === dir ? dir : path.join(realPath(parent), path.basename(dir));
|
|
46
|
+
}
|
|
30
47
|
}
|
|
31
48
|
|
|
32
49
|
module.exports = { configureSpmUpdateCommand, spmUpdateCommand };
|
|
@@ -51,6 +51,16 @@ const COVERED_POD_PREFIXES = [
|
|
|
51
51
|
*/
|
|
52
52
|
const UNMAPPED_POD_ALLOWLIST = new Set(['sqlite3']);
|
|
53
53
|
|
|
54
|
+
// Expo apps do not depend on @react-native-community/cli, which provides the
|
|
55
|
+
// `react-native spm` command; React Native's own script is always installed.
|
|
56
|
+
function rerunSpmUpdate() {
|
|
57
|
+
return `Then run \`${spmUpdateCommand()}\` from your app directory again.`;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
/** Where an app sets its `buildFromSource` autolinking option. */
|
|
61
|
+
const BUILD_FROM_SOURCE_OPTION =
|
|
62
|
+
'`"expo": { "autolinking": { "buildFromSource": [...] } }` (or its `"ios"` section) in your package.json';
|
|
63
|
+
|
|
54
64
|
/**
|
|
55
65
|
* An error the plugin fails the sync with, namespaced so the failure is
|
|
56
66
|
* attributable to it: what failed, then why and what to do next when known.
|
|
@@ -86,7 +96,15 @@ function classifyUnsupported({ pending, coreAvailable }) {
|
|
|
86
96
|
if (!coreAvailable) {
|
|
87
97
|
return [{ reason: 'core-unavailable', pods: pending.map((p) => p.podName) }];
|
|
88
98
|
}
|
|
89
|
-
return pending.map(({ refusals, ...subject }) =>
|
|
99
|
+
return pending.map(({ refusals, buildFromSourceEntry, precompiledIncomplete, ...subject }) => {
|
|
100
|
+
if (buildFromSourceEntry == null) return { ...subject, ...mostSpecific(refusals) };
|
|
101
|
+
// The artifact exists; buildFromSource is why it was not linked.
|
|
102
|
+
const cause = mostSpecific(refusals.filter((r) => r.reason !== 'prebuild-available'));
|
|
103
|
+
const reason = precompiledIncomplete
|
|
104
|
+
? 'build-from-source-fallback-incomplete'
|
|
105
|
+
: 'build-from-source-unsupported';
|
|
106
|
+
return { ...subject, reason, buildFromSourceEntry, cause };
|
|
107
|
+
});
|
|
90
108
|
}
|
|
91
109
|
|
|
92
110
|
function mostSpecific(refusals) {
|
|
@@ -239,14 +257,73 @@ function renderPrebuildAvailable({ podName, packageName, moduleRoot, productName
|
|
|
239
257
|
`error: Expo module "${packageName}" (pod ${podName}) has no prebuilt XCFramework, so it is not in the Swift Package Manager graph.`,
|
|
240
258
|
[
|
|
241
259
|
`It declares "${productName}" in its spm.config.json, so it does not need a Package.swift — the Expo prebuild pipeline builds it. The artifact is just missing.`,
|
|
242
|
-
`
|
|
243
|
-
`
|
|
260
|
+
`In the Expo repository, from its root, build it — omit --flavor so both Debug and Release are built, since the plugin declares an immutable pair and rejects a half-built one:`,
|
|
261
|
+
` node tools/bin/expotools.js prebuild ${packageName}`,
|
|
244
262
|
`Then re-run \`${spmUpdateCommand()}\`. A published ${packageName} that ships prebuilds/output/<flavor>/xcframeworks is picked up with no local build.`,
|
|
245
263
|
],
|
|
246
264
|
moduleRoot
|
|
247
265
|
);
|
|
248
266
|
}
|
|
249
267
|
|
|
268
|
+
const quotedList = (names) => names.map((name) => `"${name}"`).join(', ');
|
|
269
|
+
|
|
270
|
+
/** Why a pod cannot be built from source, by the reason it was refused. */
|
|
271
|
+
const SOURCE_BUILD_BLOCKERS = {
|
|
272
|
+
'mixed-no-manifest': () =>
|
|
273
|
+
'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.',
|
|
274
|
+
'no-apple-sources': () =>
|
|
275
|
+
'It has no `ios` or `apple` source directory for Swift Package Manager to compile.',
|
|
276
|
+
'needs-manifest-for-linkage': ({ file, line }) =>
|
|
277
|
+
`Its podspec declares native linkage at ${file}:${line}, and it ships no Package.swift stating that linkage, so a package built from its sources would link less than CocoaPods does.`,
|
|
278
|
+
'unsupported-target-dependency': ({ dependencies }) =>
|
|
279
|
+
`Its Package.swift has targets depending on ${quotedList(dependencies.map((d) => d.dependsOn))}, which the package generated from it cannot declare.`,
|
|
280
|
+
'unsupported-package-dependency': () =>
|
|
281
|
+
'Its Package.swift declares Swift packages the package generated from it cannot declare.',
|
|
282
|
+
'unresolvable-target-path': ({ targetNames }) =>
|
|
283
|
+
`Its Package.swift names targets with no sources on disk: ${quotedList(targetNames)}.`,
|
|
284
|
+
'not-exported-by-manifest': ({ productName }) =>
|
|
285
|
+
`Its Package.swift exports no "${productName}" library product.`,
|
|
286
|
+
'partially-precompiled': ({ precompiledSiblings }) =>
|
|
287
|
+
`Other pods of the module are linked precompiled (${precompiledSiblings.join(', ')}), and building the module from source would link them a second time.`,
|
|
288
|
+
};
|
|
289
|
+
|
|
290
|
+
function renderBuildFromSourceUnsupported({
|
|
291
|
+
podName,
|
|
292
|
+
packageName,
|
|
293
|
+
moduleRoot,
|
|
294
|
+
buildFromSourceEntry,
|
|
295
|
+
cause,
|
|
296
|
+
}) {
|
|
297
|
+
return renderBlock(
|
|
298
|
+
`error: Expo module "${packageName}" (pod ${podName}) is listed in buildFromSource, but Swift Package Manager cannot build it from source.`,
|
|
299
|
+
[
|
|
300
|
+
SOURCE_BUILD_BLOCKERS[cause.reason]?.(cause) ??
|
|
301
|
+
`The plugin found no way to build it from source with Swift Package Manager (reason: ${cause.reason}).`,
|
|
302
|
+
`Remove "${buildFromSourceEntry}" from ${BUILD_FROM_SOURCE_OPTION}, or narrow it so it no longer matches ${podName} or ${packageName}. The module's precompiled XCFramework is then used. ${rerunSpmUpdate()}`,
|
|
303
|
+
],
|
|
304
|
+
moduleRoot
|
|
305
|
+
);
|
|
306
|
+
}
|
|
307
|
+
|
|
308
|
+
function renderBuildFromSourceFallbackIncomplete({
|
|
309
|
+
podName,
|
|
310
|
+
packageName,
|
|
311
|
+
moduleRoot,
|
|
312
|
+
buildFromSourceEntry,
|
|
313
|
+
cause,
|
|
314
|
+
}) {
|
|
315
|
+
return renderBlock(
|
|
316
|
+
`error: The buildFromSource entry "${buildFromSourceEntry}" matches Expo module "${packageName}" (pod ${podName}), which Swift Package Manager cannot build from source, and its precompiled XCFramework is incomplete, so it cannot be linked precompiled either.`,
|
|
317
|
+
[
|
|
318
|
+
SOURCE_BUILD_BLOCKERS[cause.reason]?.(cause) ??
|
|
319
|
+
`The plugin found no way to build it from source with Swift Package Manager (reason: ${cause.reason}).`,
|
|
320
|
+
'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.',
|
|
321
|
+
`Reinstall ${packageName} so it ships both flavors, or, in the Expo repository, from its root, build both with \`node tools/bin/expotools.js prebuild ${packageName}\`. ${rerunSpmUpdate()}`,
|
|
322
|
+
],
|
|
323
|
+
moduleRoot
|
|
324
|
+
);
|
|
325
|
+
}
|
|
326
|
+
|
|
250
327
|
function renderNoAppleSources({ podName, packageName, moduleRoot }) {
|
|
251
328
|
return renderBlock(
|
|
252
329
|
`error: Expo module "${packageName}" (pod ${podName}) has no \`ios\` or \`apple\` source directory, so Swift Package Manager has nothing to compile.`,
|
|
@@ -510,8 +587,8 @@ function renderPartiallyPrecompiled({
|
|
|
510
587
|
? `add a product for ${podName} to ${packageName}'s spm.config.json, then build it`
|
|
511
588
|
: `build ${podName} too — ${packageName}'s spm.config.json already declares "${prebuildProduct.name}"`;
|
|
512
589
|
const precompile = [
|
|
513
|
-
`To precompile all of them, ${productStep}.
|
|
514
|
-
`
|
|
590
|
+
`To precompile all of them, ${productStep}. In the Expo repository, from its root, run this — omit --flavor so both Debug and Release are built, since the plugin declares an immutable pair and rejects a half-built one:`,
|
|
591
|
+
` node tools/bin/expotools.js prebuild ${packageName}`,
|
|
515
592
|
` Then re-run \`${spmUpdateCommand()}\`.`,
|
|
516
593
|
];
|
|
517
594
|
const remedies = [
|
|
@@ -601,9 +678,9 @@ function renderCoreUnavailable({ pods }) {
|
|
|
601
678
|
return [
|
|
602
679
|
`error: ExpoModulesCore has no prebuilt Debug and Release xcframework, so all ${pods.length} source-built Expo ${pods.length === 1 ? 'module' : 'modules'} were skipped.`,
|
|
603
680
|
` Every Expo source module compiles against the ExpoModulesCore framework interface tree; without both flavors the plugin cannot emit any of them.`,
|
|
604
|
-
`
|
|
605
|
-
`
|
|
606
|
-
`
|
|
681
|
+
` In the Expo repository, from its root, build the precompiled core once per flavor (the flavor name is case-sensitive):`,
|
|
682
|
+
` node tools/bin/expotools.js prebuild -f Debug expo-modules-core expo-modules-jsi`,
|
|
683
|
+
` node tools/bin/expotools.js prebuild -f Release expo-modules-core expo-modules-jsi`,
|
|
607
684
|
` Skipped: ${pods.join(', ')}`,
|
|
608
685
|
].join('\n');
|
|
609
686
|
}
|
|
@@ -626,6 +703,8 @@ function renderDuplicatePodName({ podName, copies }) {
|
|
|
626
703
|
const REFUSALS = new Map(
|
|
627
704
|
[
|
|
628
705
|
['duplicate-pod-name', { render: renderDuplicatePodName }],
|
|
706
|
+
['build-from-source-unsupported', { render: renderBuildFromSourceUnsupported }],
|
|
707
|
+
['build-from-source-fallback-incomplete', { render: renderBuildFromSourceFallbackIncomplete }],
|
|
629
708
|
['partially-precompiled', { render: renderPartiallyPrecompiled }],
|
|
630
709
|
['prebuild-available', { render: renderPrebuildAvailable }],
|
|
631
710
|
['needs-manifest-for-linkage', { render: renderNeedsManifestForLinkage }],
|
|
@@ -795,6 +874,28 @@ function renderExtraPodsWarning(pods) {
|
|
|
795
874
|
].join('\n');
|
|
796
875
|
}
|
|
797
876
|
|
|
877
|
+
/**
|
|
878
|
+
* Modules a buildFromSource pattern matched that are linked precompiled, because Swift
|
|
879
|
+
* Package Manager cannot build them from source.
|
|
880
|
+
*
|
|
881
|
+
* @param fallbacks `{ podName, packageName, entry }` per module, `entry` being the pattern.
|
|
882
|
+
*/
|
|
883
|
+
function renderBuildFromSourceFallbackWarning(fallbacks) {
|
|
884
|
+
if (!fallbacks.length) return '';
|
|
885
|
+
const one = fallbacks.length === 1;
|
|
886
|
+
const them = one ? 'it' : 'them';
|
|
887
|
+
const entries = [...new Set(fallbacks.map((f) => f.entry))];
|
|
888
|
+
const modules = fallbacks
|
|
889
|
+
.map(({ podName, packageName, entry }) => `${podName} (${packageName}, matched by "${entry}")`)
|
|
890
|
+
.join(', ');
|
|
891
|
+
return [
|
|
892
|
+
`warning: buildFromSource matches ${fallbacks.length} Expo ${one ? 'module' : 'modules'} that Swift Package Manager cannot build from source, so ${one ? 'it is' : 'they are'} linked precompiled instead: ${modules}.`,
|
|
893
|
+
'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.',
|
|
894
|
+
`To see what blocks a module's source build, list it by its exact pod or npm package name in ${BUILD_FROM_SOURCE_OPTION}: the sync then fails and names the cause.`,
|
|
895
|
+
`To keep ${them} precompiled without this warning, narrow ${entries.map((e) => `"${e}"`).join(', ')} so that no entry matches ${one ? 'this module' : 'these modules'}. ${rerunSpmUpdate()}`,
|
|
896
|
+
].join(' ');
|
|
897
|
+
}
|
|
898
|
+
|
|
798
899
|
/** Print the report and return the error to throw, or null when nothing is uncovered. */
|
|
799
900
|
function reportUnsupported(entries) {
|
|
800
901
|
if (!entries.length) return null;
|
|
@@ -804,6 +905,8 @@ function reportUnsupported(entries) {
|
|
|
804
905
|
|
|
805
906
|
module.exports = {
|
|
806
907
|
pluginError,
|
|
908
|
+
BUILD_FROM_SOURCE_OPTION,
|
|
909
|
+
rerunSpmUpdate,
|
|
807
910
|
UnsupportedModulesError,
|
|
808
911
|
COVERED_POD_PREFIXES,
|
|
809
912
|
UNMAPPED_POD_ALLOWLIST,
|
|
@@ -819,5 +922,6 @@ module.exports = {
|
|
|
819
922
|
renderRootConflictWarning,
|
|
820
923
|
renderPartlyProvidedPackageWarning,
|
|
821
924
|
renderExtraPodsWarning,
|
|
925
|
+
renderBuildFromSourceFallbackWarning,
|
|
822
926
|
reportUnsupported,
|
|
823
927
|
};
|
|
@@ -0,0 +1,215 @@
|
|
|
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:
|
|
5
|
+
*
|
|
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 a dependency on the
|
|
9
|
+
* ExpoModulesJSI headers package the plugin emits
|
|
10
|
+
* $BUILD_DIR/ExpoModulesMacros → relative symlink to the prebuilt macro plugin; the
|
|
11
|
+
* manifest names it as `${BUILD_DIR}/ExpoModulesMacros`
|
|
12
|
+
*/
|
|
13
|
+
|
|
14
|
+
'use strict';
|
|
15
|
+
|
|
16
|
+
const fs = require('fs');
|
|
17
|
+
const path = require('path');
|
|
18
|
+
|
|
19
|
+
const { runDumpPackage } = require('./cli');
|
|
20
|
+
const { pluginError, rerunSpmUpdate } = require('./diagnostics');
|
|
21
|
+
|
|
22
|
+
const CORE_HEADERS = 'ExpoModulesCoreHeaders';
|
|
23
|
+
const JSI_HEADERS = 'ExpoModulesJSIHeaders';
|
|
24
|
+
// A binary target cannot have dependencies, so this source target carries the JSI one.
|
|
25
|
+
const CORE_HEADERS_DEPENDENCIES = 'ExpoModulesCoreHeadersDependencies';
|
|
26
|
+
// Written into the package by an earlier generator; nothing reads it now.
|
|
27
|
+
const LEGACY_STUBS_DIR = '.stubs';
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* Whether a dumped manifest compiles against ExpoModulesCoreHeaders, which only a manifest
|
|
31
|
+
* written to be built as it stands can name. A `byName` dependency counts: SwiftPM resolves
|
|
32
|
+
* it to that product when no target of the package has the name.
|
|
33
|
+
*/
|
|
34
|
+
function dependsOnCoreHeaders(manifest) {
|
|
35
|
+
return (manifest.targets ?? []).some((target) =>
|
|
36
|
+
(target.dependencies ?? []).some(
|
|
37
|
+
(dependency) => (dependency.product ?? dependency.byName)?.[0] === CORE_HEADERS
|
|
38
|
+
)
|
|
39
|
+
);
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* Module manifests depend on the product, so it keeps the package's name. ExpoModulesCore's
|
|
44
|
+
* interface re-exports ExpoModulesJSI, so the product brings the JSI headers package along;
|
|
45
|
+
* it must not declare a JSI headers target of its own, because SwiftPM rejects two targets
|
|
46
|
+
* of one name in a graph.
|
|
47
|
+
*/
|
|
48
|
+
function coreHeadersManifest(jsiHeadersPkgRelativePath) {
|
|
49
|
+
return `// swift-tools-version: 6.0
|
|
50
|
+
// AUTO-GENERATED by expo/scripts/spm/direct.js — do not edit.
|
|
51
|
+
// Compile-only ExpoModulesCore. The runtime framework is linked and embedded by React
|
|
52
|
+
// Native outside SwiftPM.
|
|
53
|
+
import PackageDescription
|
|
54
|
+
|
|
55
|
+
let package = Package(
|
|
56
|
+
name: "${CORE_HEADERS}",
|
|
57
|
+
products: [
|
|
58
|
+
.library(name: "${CORE_HEADERS}", targets: ["${CORE_HEADERS}", "${CORE_HEADERS_DEPENDENCIES}"]),
|
|
59
|
+
],
|
|
60
|
+
dependencies: [
|
|
61
|
+
.package(name: "${JSI_HEADERS}", path: "${jsiHeadersPkgRelativePath}"),
|
|
62
|
+
],
|
|
63
|
+
targets: [
|
|
64
|
+
.binaryTarget(name: "${CORE_HEADERS}", path: "${CORE_HEADERS}.xcframework"),
|
|
65
|
+
.target(
|
|
66
|
+
name: "${CORE_HEADERS_DEPENDENCIES}",
|
|
67
|
+
dependencies: [.product(name: "${JSI_HEADERS}", package: "${JSI_HEADERS}")],
|
|
68
|
+
path: "${CORE_HEADERS_DEPENDENCIES}"
|
|
69
|
+
),
|
|
70
|
+
]
|
|
71
|
+
)
|
|
72
|
+
`;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
function relativeSymlink(target, link) {
|
|
76
|
+
const relative = path.relative(path.dirname(link), target);
|
|
77
|
+
try {
|
|
78
|
+
if (fs.readlinkSync(link) === relative) return;
|
|
79
|
+
} catch {}
|
|
80
|
+
fs.rmSync(link, { recursive: true, force: true });
|
|
81
|
+
fs.symlinkSync(relative, link);
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
function writeIfChanged(file, contents) {
|
|
85
|
+
if (fs.existsSync(file) && fs.readFileSync(file, 'utf8') === contents) return;
|
|
86
|
+
fs.mkdirSync(path.dirname(file), { recursive: true });
|
|
87
|
+
fs.writeFileSync(file, contents);
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
function emitCoreHeadersPackage(directDir, coreHeadersXCFramework, jsiHeadersPkgPath) {
|
|
91
|
+
const pkgDir = path.join(directDir, CORE_HEADERS);
|
|
92
|
+
fs.mkdirSync(pkgDir, { recursive: true });
|
|
93
|
+
fs.rmSync(path.join(pkgDir, LEGACY_STUBS_DIR), { recursive: true, force: true });
|
|
94
|
+
relativeSymlink(coreHeadersXCFramework, path.join(pkgDir, `${CORE_HEADERS}.xcframework`));
|
|
95
|
+
writeIfChanged(
|
|
96
|
+
path.join(pkgDir, CORE_HEADERS_DEPENDENCIES, `${CORE_HEADERS_DEPENDENCIES}.swift`),
|
|
97
|
+
''
|
|
98
|
+
);
|
|
99
|
+
writeIfChanged(
|
|
100
|
+
path.join(pkgDir, 'Package.swift'),
|
|
101
|
+
coreHeadersManifest(path.relative(pkgDir, jsiHeadersPkgPath))
|
|
102
|
+
);
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
/**
|
|
106
|
+
* Wire one module through its own checked-in manifest. Returns the emission shape
|
|
107
|
+
* `manifests.js#emitPackage` returns, so the plugin links it like any manifest package.
|
|
108
|
+
*
|
|
109
|
+
* @param jsiHeadersPkgPath the ExpoModulesJSI headers package the plugin emits, or null when
|
|
110
|
+
* expo-modules-jsi is not autolinked.
|
|
111
|
+
* @param manifest the module's manifest, as `dumpModuleManifest` parsed it.
|
|
112
|
+
*/
|
|
113
|
+
function emitDirectPackage({
|
|
114
|
+
moduleRoot,
|
|
115
|
+
packageName,
|
|
116
|
+
outDir,
|
|
117
|
+
coreHeadersXCFramework,
|
|
118
|
+
jsiHeadersPkgPath,
|
|
119
|
+
macroTool,
|
|
120
|
+
manifest,
|
|
121
|
+
}) {
|
|
122
|
+
if (jsiHeadersPkgPath == null) {
|
|
123
|
+
throw pluginError({
|
|
124
|
+
what: `${packageName} is built from its own Package.swift and needs the ExpoModulesJSI headers, but expo-modules-jsi is not autolinked.`,
|
|
125
|
+
why: 'The ExpoModulesCore headers it compiles against re-export ExpoModulesJSI.',
|
|
126
|
+
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()}`,
|
|
127
|
+
});
|
|
128
|
+
}
|
|
129
|
+
const directDir = path.join(outDir, 'direct');
|
|
130
|
+
fs.mkdirSync(directDir, { recursive: true });
|
|
131
|
+
emitCoreHeadersPackage(directDir, coreHeadersXCFramework, jsiHeadersPkgPath);
|
|
132
|
+
const macroLink = macroPluginLink();
|
|
133
|
+
if (macroLink) {
|
|
134
|
+
fs.mkdirSync(path.dirname(macroLink), { recursive: true });
|
|
135
|
+
relativeSymlink(macroTool, macroLink);
|
|
136
|
+
}
|
|
137
|
+
const link = path.join(directDir, packageName);
|
|
138
|
+
fs.mkdirSync(path.dirname(link), { recursive: true });
|
|
139
|
+
relativeSymlink(moduleRoot, link);
|
|
140
|
+
fs.rmSync(path.join(outDir, 'expo-source', manifest.name), { recursive: true, force: true });
|
|
141
|
+
|
|
142
|
+
return {
|
|
143
|
+
ok: {
|
|
144
|
+
packageDep: { name: manifest.name, path: link },
|
|
145
|
+
productDeps: manifest.products.map((p) => ({ name: p.name, package: manifest.name })),
|
|
146
|
+
spmProductNames: [],
|
|
147
|
+
partlyProvidedPackages: [],
|
|
148
|
+
},
|
|
149
|
+
};
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
/**
|
|
153
|
+
* `swift package dump-package` of the checked-in manifest at `moduleRoot`: the JSON the
|
|
154
|
+
* tool printed, and its parse.
|
|
155
|
+
*/
|
|
156
|
+
function dumpModuleManifest(moduleRoot, packageName) {
|
|
157
|
+
try {
|
|
158
|
+
const json = runDumpPackage(moduleRoot);
|
|
159
|
+
return { json, manifest: JSON.parse(json) };
|
|
160
|
+
} catch (error) {
|
|
161
|
+
throw pluginError(
|
|
162
|
+
{
|
|
163
|
+
what: `${packageName}'s Package.swift could not be evaluated: ${dumpFailureDetail(error)}.`,
|
|
164
|
+
why: `${packageName} is built from source, so the plugin reads its manifest with \`swift package dump-package\` to decide how to build it and to find the products it exports.`,
|
|
165
|
+
how: `Fix the Package.swift in ${moduleRoot}; run \`swift package dump-package\` in that folder to see the full error. If the swift command is missing, install Xcode and select its command line tools with \`sudo xcode-select --switch /Applications/Xcode.app\`. ${rerunSpmUpdate()}`,
|
|
166
|
+
},
|
|
167
|
+
{ cause: error }
|
|
168
|
+
);
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
function dumpFailureDetail(error) {
|
|
173
|
+
if (error.code === 'ENOENT') return 'the swift command was not found';
|
|
174
|
+
const output =
|
|
175
|
+
typeof error.stderr === 'string' && error.stderr.trim() ? error.stderr : error.message;
|
|
176
|
+
return output.trim().split('\n')[0];
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
function macroPluginLink() {
|
|
180
|
+
return process.env.BUILD_DIR ? path.join(process.env.BUILD_DIR, 'ExpoModulesMacros') : null;
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
// Far enough ahead that every later sync stamp is older.
|
|
184
|
+
const PENDING_MARKER_MTIME = new Date('2100-01-01T00:00:00Z');
|
|
185
|
+
|
|
186
|
+
/**
|
|
187
|
+
* Only a sync inside a build knows BUILD_DIR, so only it can create the macro plugin link.
|
|
188
|
+
* RN re-syncs in the build when a watched path has vanished or is newer than its stamp,
|
|
189
|
+
* and drops watched paths that do not exist.
|
|
190
|
+
* - In a build: watch the link, since Clean Build Folder deletes it but keeps the stamp.
|
|
191
|
+
* - Outside a build: the link cannot be made, yet the stamp is fresh. Watch a marker
|
|
192
|
+
* dated in the future, so the next build always re-syncs; that sync removes it.
|
|
193
|
+
*/
|
|
194
|
+
function prepareDirectWatchPaths(directPackages, outDir) {
|
|
195
|
+
const marker = path.join(outDir, 'direct', '.macro-plugin-link-pending');
|
|
196
|
+
const macroLink = macroPluginLink();
|
|
197
|
+
const hasDirect = directPackages.length > 0;
|
|
198
|
+
if (!hasDirect || macroLink) {
|
|
199
|
+
fs.rmSync(marker, { force: true });
|
|
200
|
+
return hasDirect ? [macroLink] : [];
|
|
201
|
+
}
|
|
202
|
+
if (fs.statSync(marker, { throwIfNoEntry: false })?.mtimeMs !== PENDING_MARKER_MTIME.getTime()) {
|
|
203
|
+
fs.mkdirSync(path.dirname(marker), { recursive: true });
|
|
204
|
+
fs.writeFileSync(marker, '');
|
|
205
|
+
fs.utimesSync(marker, PENDING_MARKER_MTIME, PENDING_MARKER_MTIME);
|
|
206
|
+
}
|
|
207
|
+
return [marker];
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
module.exports = {
|
|
211
|
+
dependsOnCoreHeaders,
|
|
212
|
+
dumpModuleManifest,
|
|
213
|
+
emitDirectPackage,
|
|
214
|
+
prepareDirectWatchPaths,
|
|
215
|
+
};
|