expo 58.0.16 → 58.0.17
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 +26 -26
- package/package.json +16 -15
- package/scripts/spm/README.md +23 -6
- package/scripts/spm/__tests__/app-target.test.js +3 -2
- package/scripts/spm/__tests__/commands.test.js +34 -0
- package/scripts/spm/__tests__/diagnostics.test.js +2 -0
- package/scripts/spm/__tests__/flavored-frameworks.test.js +185 -0
- package/scripts/spm/__tests__/manifests.test.js +104 -0
- package/scripts/spm/__tests__/plugin.test.js +206 -1
- package/scripts/spm/__tests__/script-phases.test.js +326 -0
- package/scripts/spm/app-target.js +4 -3
- package/scripts/spm/commands.js +32 -0
- package/scripts/spm/diagnostics.js +6 -4
- package/scripts/spm/flavored-frameworks.js +78 -3
- package/scripts/spm/manifests.js +60 -7
- package/scripts/spm/plugin.js +78 -7
- package/scripts/spm/script-phases.js +54 -0
- package/src/__tests__/tsconfig-base-export.test.node.ts +23 -0
- package/template.tgz +0 -0
|
@@ -27,6 +27,7 @@ jest.mock('../flavored-frameworks', () => ({
|
|
|
27
27
|
frameworkName === 'ExpoModulesCore' ? { id: 'ExpoModulesCore', name: 'ExpoModulesCore' } : null
|
|
28
28
|
),
|
|
29
29
|
resolveSpmDependencyFrameworks: jest.fn(() => []),
|
|
30
|
+
resolveHeadersXCFramework: jest.fn(() => null),
|
|
30
31
|
prepareCompileInterfaces: jest.fn(() => '/abs/interfaces'),
|
|
31
32
|
}));
|
|
32
33
|
// The module-root walk stays real; it is spied on so a test can assert that a
|
|
@@ -50,12 +51,14 @@ const {
|
|
|
50
51
|
} = require('../cli');
|
|
51
52
|
const { resolveAppTarget } = require('../app-target');
|
|
52
53
|
const { findModuleRoot } = require('../classify');
|
|
54
|
+
const { spmUpdateCommand } = require('../commands');
|
|
53
55
|
const { UnsupportedModulesError } = require('../diagnostics');
|
|
54
56
|
const { emitPureSwiftSourcePackage } = require('../manifests');
|
|
55
57
|
const {
|
|
56
58
|
artifactBaseDirs,
|
|
57
59
|
prepareCompileInterfaces,
|
|
58
60
|
resolveFlavoredFramework,
|
|
61
|
+
resolveHeadersXCFramework,
|
|
59
62
|
resolveSpmDependencyFrameworks,
|
|
60
63
|
} = require('../flavored-frameworks');
|
|
61
64
|
const {
|
|
@@ -132,6 +135,8 @@ function restoreModuleMocks() {
|
|
|
132
135
|
);
|
|
133
136
|
resolveSpmDependencyFrameworks.mockReset();
|
|
134
137
|
resolveSpmDependencyFrameworks.mockReturnValue([]);
|
|
138
|
+
resolveHeadersXCFramework.mockReset();
|
|
139
|
+
resolveHeadersXCFramework.mockReturnValue(null);
|
|
135
140
|
prepareCompileInterfaces.mockImplementation(() => '/abs/interfaces');
|
|
136
141
|
}
|
|
137
142
|
|
|
@@ -319,10 +324,27 @@ describe('the module registry', () => {
|
|
|
319
324
|
|
|
320
325
|
expect(run).toThrow(/ExpoModulesProvider\.swift/);
|
|
321
326
|
expect(run).toThrow(/expo-modules-autolinking exited with code 1/);
|
|
322
|
-
expect(run).toThrow(
|
|
327
|
+
expect(run).toThrow(spmUpdateCommand());
|
|
323
328
|
expect(printed(logs.warn)).not.toContain('ExpoModulesProvider');
|
|
324
329
|
});
|
|
325
330
|
|
|
331
|
+
// Workspaces hoist react-native above the app, where node_modules/react-native is missing.
|
|
332
|
+
it("names the update command through the app's react-native, relative to the app root", () => {
|
|
333
|
+
generateModulesProvider.mockImplementation(() => {
|
|
334
|
+
throw new Error('expo-modules-autolinking exited with code 1');
|
|
335
|
+
});
|
|
336
|
+
const hoistedApp = () =>
|
|
337
|
+
runPlugin(tmp, {
|
|
338
|
+
projectRoot: path.join(tmp, 'apps', 'mobile'),
|
|
339
|
+
appRoot: path.join(tmp, 'apps', 'mobile', 'ios'),
|
|
340
|
+
reactNativeRoot: path.join(tmp, 'node_modules', 'react-native'),
|
|
341
|
+
});
|
|
342
|
+
|
|
343
|
+
expect(hoistedApp).toThrow(
|
|
344
|
+
'`node ../../node_modules/react-native/scripts/setup-apple-spm.js update`'
|
|
345
|
+
);
|
|
346
|
+
});
|
|
347
|
+
|
|
326
348
|
it('fails the sync when generation writes no provider although modules resolved', () => {
|
|
327
349
|
generateModulesProvider.mockReturnValue(null);
|
|
328
350
|
|
|
@@ -3569,3 +3591,186 @@ describe('a gated pod linked where its autolinkWhen condition is not checked', (
|
|
|
3569
3591
|
expect(report).toContain('"ExpoScanner"');
|
|
3570
3592
|
});
|
|
3571
3593
|
});
|
|
3594
|
+
|
|
3595
|
+
// npm never ships the ExpoModulesJSI binary: it must be compiled against the app's
|
|
3596
|
+
// React Native. Source packages compile against its headers XCFramework, and an app
|
|
3597
|
+
// build phase builds, links and embeds the real framework.
|
|
3598
|
+
describe('ExpoModulesJSI', () => {
|
|
3599
|
+
captureConsole();
|
|
3600
|
+
|
|
3601
|
+
/**
|
|
3602
|
+
* Writes the expo-modules-jsi `versions`: `headers` into the headers' stamp, `autolinked`
|
|
3603
|
+
* into the autolinked package, and `built` into the copy the build phase's launcher reaches
|
|
3604
|
+
* through expo and expo-modules-core. Returns that copy's directory.
|
|
3605
|
+
*/
|
|
3606
|
+
function writeJsiVersions(tmp, headersXCFramework, { headers, autolinked, built }) {
|
|
3607
|
+
const writePackage = (dir, name, version) => {
|
|
3608
|
+
fs.mkdirSync(dir, { recursive: true });
|
|
3609
|
+
fs.writeFileSync(path.join(dir, 'package.json'), JSON.stringify({ name, version }));
|
|
3610
|
+
return dir;
|
|
3611
|
+
};
|
|
3612
|
+
fs.writeFileSync(
|
|
3613
|
+
path.join(headersXCFramework, 'expo-package.json'),
|
|
3614
|
+
JSON.stringify({ name: 'expo-modules-jsi', version: headers })
|
|
3615
|
+
);
|
|
3616
|
+
writePackage(path.join(tmp, 'expo-modules-jsi'), 'expo-modules-jsi', autolinked);
|
|
3617
|
+
const expo = writePackage(path.join(tmp, 'app', 'node_modules', 'expo'), 'expo', '1.0.0');
|
|
3618
|
+
const core = writePackage(
|
|
3619
|
+
path.join(expo, 'node_modules', 'expo-modules-core'),
|
|
3620
|
+
'expo-modules-core',
|
|
3621
|
+
'1.0.0'
|
|
3622
|
+
);
|
|
3623
|
+
return writePackage(
|
|
3624
|
+
path.join(core, 'node_modules', 'expo-modules-jsi'),
|
|
3625
|
+
'expo-modules-jsi',
|
|
3626
|
+
built
|
|
3627
|
+
);
|
|
3628
|
+
}
|
|
3629
|
+
|
|
3630
|
+
/**
|
|
3631
|
+
* Runs the plugin for core, expo-asset and, with `withJsi`, expo-modules-jsi. `versions`
|
|
3632
|
+
* stamps the headers and installs versions as `writeJsiVersions` describes.
|
|
3633
|
+
*/
|
|
3634
|
+
function syncApp({ withJsi = true, headers = 'resolved', versions } = {}) {
|
|
3635
|
+
const tmp = makeTempDir('expo-spm-jsi-');
|
|
3636
|
+
const outDir = path.join(tmp, 'out');
|
|
3637
|
+
const headersXCFramework = path.join(tmp, 'npm', 'ExpoModulesJSIHeaders.xcframework');
|
|
3638
|
+
fs.mkdirSync(headersXCFramework, { recursive: true });
|
|
3639
|
+
fs.writeFileSync(path.join(headersXCFramework, 'Info.plist'), '<plist/>');
|
|
3640
|
+
const core = pureSwiftModule(path.join(tmp, 'expo-modules-core'), 'ExpoModulesCore', spec());
|
|
3641
|
+
const jsi = pureSwiftModule(path.join(tmp, 'expo-modules-jsi'), 'ExpoModulesJSI', spec());
|
|
3642
|
+
const asset = pureSwiftModule(path.join(tmp, 'expo-asset'), 'ExpoAsset', spec());
|
|
3643
|
+
const builtJsiRoot =
|
|
3644
|
+
versions == null ? null : writeJsiVersions(tmp, headersXCFramework, versions);
|
|
3645
|
+
resolveExpoModules.mockReturnValue(
|
|
3646
|
+
modulesOf([
|
|
3647
|
+
coreAt(core),
|
|
3648
|
+
...(withJsi ? [['expo-modules-jsi', [['ExpoModulesJSI', jsi]]]] : []),
|
|
3649
|
+
['expo-asset', [['ExpoAsset', asset]]],
|
|
3650
|
+
])
|
|
3651
|
+
);
|
|
3652
|
+
// A Debug/Release JSI pair exists, as in a monorepo prebuild or an older package.
|
|
3653
|
+
resolveFlavoredFramework.mockImplementation(({ frameworkName }) =>
|
|
3654
|
+
['ExpoModulesCore', 'ExpoModulesJSI'].includes(frameworkName)
|
|
3655
|
+
? { id: frameworkName, frameworkName }
|
|
3656
|
+
: null
|
|
3657
|
+
);
|
|
3658
|
+
resolveHeadersXCFramework.mockReset();
|
|
3659
|
+
resolveHeadersXCFramework.mockReturnValue(headers === 'resolved' ? headersXCFramework : null);
|
|
3660
|
+
providerWrittenTo(outDir);
|
|
3661
|
+
let result = null;
|
|
3662
|
+
const thrown = thrownBy(() => {
|
|
3663
|
+
result = runPlugin(tmp);
|
|
3664
|
+
});
|
|
3665
|
+
const assetManifest = () =>
|
|
3666
|
+
fs.readFileSync(
|
|
3667
|
+
path.join(outDir, 'expo', 'expo-source', 'ExpoAsset', 'Package.swift'),
|
|
3668
|
+
'utf8'
|
|
3669
|
+
);
|
|
3670
|
+
return { tmp, outDir, headersXCFramework, builtJsiRoot, result, thrown, assetManifest };
|
|
3671
|
+
}
|
|
3672
|
+
|
|
3673
|
+
afterAll(restoreModuleMocks);
|
|
3674
|
+
|
|
3675
|
+
describe('when expo-modules-jsi is autolinked', () => {
|
|
3676
|
+
let app;
|
|
3677
|
+
|
|
3678
|
+
beforeAll(() => {
|
|
3679
|
+
app = syncApp();
|
|
3680
|
+
});
|
|
3681
|
+
|
|
3682
|
+
it('never links it as a precompiled framework, even when a Debug/Release pair exists', () => {
|
|
3683
|
+
expect(app.thrown).toBeNull();
|
|
3684
|
+
expect(app.result.flavoredFrameworks.map((f) => f.frameworkName)).toEqual([
|
|
3685
|
+
'ExpoModulesCore',
|
|
3686
|
+
]);
|
|
3687
|
+
expect(resolvedFor('expo-modules-jsi')).toBeUndefined();
|
|
3688
|
+
});
|
|
3689
|
+
|
|
3690
|
+
it("looks the headers up from the package's own lookup bases, into the plugin cache", () => {
|
|
3691
|
+
expect(resolveHeadersXCFramework).toHaveBeenCalledWith({
|
|
3692
|
+
packageName: 'expo-modules-jsi',
|
|
3693
|
+
moduleRoot: path.join(app.tmp, 'expo-modules-jsi'),
|
|
3694
|
+
productName: 'ExpoModulesJSI',
|
|
3695
|
+
cacheDir: path.join(app.tmp, 'app', 'ios', 'build', 'expo-xcframeworks'),
|
|
3696
|
+
});
|
|
3697
|
+
});
|
|
3698
|
+
|
|
3699
|
+
it('emits the headers package over the resolved XCFramework', () => {
|
|
3700
|
+
const pkgDir = path.join(app.outDir, 'expo', 'ExpoModulesJSIHeaders');
|
|
3701
|
+
expect(fs.readFileSync(path.join(pkgDir, 'Package.swift'), 'utf8')).toContain(
|
|
3702
|
+
'.linkedFramework("ExpoModulesJSI")'
|
|
3703
|
+
);
|
|
3704
|
+
expect(fs.readlinkSync(path.join(pkgDir, 'ExpoModulesJSIHeaders.xcframework'))).toBe(
|
|
3705
|
+
app.headersXCFramework
|
|
3706
|
+
);
|
|
3707
|
+
});
|
|
3708
|
+
|
|
3709
|
+
it('makes every emitted source package depend on the headers package', () => {
|
|
3710
|
+
const pkgDir = path.join(app.outDir, 'expo', 'ExpoModulesJSIHeaders');
|
|
3711
|
+
expect(app.assetManifest()).toContain(
|
|
3712
|
+
`.package(name: "ExpoModulesJSIHeaders", path: "${pkgDir}")`
|
|
3713
|
+
);
|
|
3714
|
+
expect(app.assetManifest()).toContain(
|
|
3715
|
+
'.product(name: "ExpoModulesJSIHeaders", package: "ExpoModulesJSIHeaders")'
|
|
3716
|
+
);
|
|
3717
|
+
});
|
|
3718
|
+
|
|
3719
|
+
it('adds the build phase', () => {
|
|
3720
|
+
expect(app.result.scriptPhases.map((p) => p.id)).toContain('expo-modules-jsi.build');
|
|
3721
|
+
});
|
|
3722
|
+
});
|
|
3723
|
+
|
|
3724
|
+
describe('when its headers are missing everywhere', () => {
|
|
3725
|
+
it('fails the sync, saying what is missing, why it is needed and how to get it', () => {
|
|
3726
|
+
const { thrown } = syncApp({ headers: 'missing' });
|
|
3727
|
+
expect(thrown).toBeInstanceOf(Error);
|
|
3728
|
+
expect(thrown.message).toContain('ExpoModulesJSIHeaders');
|
|
3729
|
+
expect(thrown.message).toMatch(/only the headers/);
|
|
3730
|
+
expect(thrown.message).toMatch(/reinstall/i);
|
|
3731
|
+
expect(thrown.message).toMatch(/et prebuild expo-modules-jsi/);
|
|
3732
|
+
});
|
|
3733
|
+
});
|
|
3734
|
+
|
|
3735
|
+
// The build phase compiles the framework from the installed sources, so headers of another
|
|
3736
|
+
// version leave a source package referencing a symbol the framework lacks.
|
|
3737
|
+
describe('when its headers are stamped with a version', () => {
|
|
3738
|
+
it('fails the sync when the autolinked expo-modules-jsi is another version', () => {
|
|
3739
|
+
const app = syncApp({ versions: { headers: '2.0.0', autolinked: '1.0.0', built: '2.0.0' } });
|
|
3740
|
+
expect(app.thrown).toBeInstanceOf(Error);
|
|
3741
|
+
for (const part of [app.headersXCFramework, '2.0.0', '1.0.0']) {
|
|
3742
|
+
expect(app.thrown.message).toContain(part);
|
|
3743
|
+
}
|
|
3744
|
+
expect(app.thrown.message).toContain(path.join(app.tmp, 'expo-modules-jsi'));
|
|
3745
|
+
expect(app.thrown.message).toMatch(/et prebuild expo-modules-jsi/);
|
|
3746
|
+
});
|
|
3747
|
+
|
|
3748
|
+
it('fails the sync when the copy the build phase builds is another version', () => {
|
|
3749
|
+
const app = syncApp({ versions: { headers: '1.0.0', autolinked: '1.0.0', built: '1.1.0' } });
|
|
3750
|
+
expect(app.thrown).toBeInstanceOf(Error);
|
|
3751
|
+
expect(app.thrown.message).toContain(app.builtJsiRoot);
|
|
3752
|
+
expect(app.thrown.message).toContain('1.1.0');
|
|
3753
|
+
});
|
|
3754
|
+
|
|
3755
|
+
it('syncs when every copy is that version', () => {
|
|
3756
|
+
const app = syncApp({ versions: { headers: '1.0.0', autolinked: '1.0.0', built: '1.0.0' } });
|
|
3757
|
+
expect(app.thrown).toBeNull();
|
|
3758
|
+
});
|
|
3759
|
+
});
|
|
3760
|
+
|
|
3761
|
+
describe('when expo-modules-jsi is not autolinked', () => {
|
|
3762
|
+
let app;
|
|
3763
|
+
|
|
3764
|
+
beforeAll(() => {
|
|
3765
|
+
app = syncApp({ withJsi: false });
|
|
3766
|
+
});
|
|
3767
|
+
|
|
3768
|
+
it('adds no headers package, no dependency on one and no build phase', () => {
|
|
3769
|
+
expect(app.thrown).toBeNull();
|
|
3770
|
+
expect(resolveHeadersXCFramework).not.toHaveBeenCalled();
|
|
3771
|
+
expect(fs.existsSync(path.join(app.outDir, 'expo', 'ExpoModulesJSIHeaders'))).toBe(false);
|
|
3772
|
+
expect(app.assetManifest()).not.toContain('ExpoModulesJSIHeaders');
|
|
3773
|
+
expect(app.result.scriptPhases.map((p) => p.id)).not.toContain('expo-modules-jsi.build');
|
|
3774
|
+
});
|
|
3775
|
+
});
|
|
3776
|
+
});
|
|
@@ -1,5 +1,10 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
+
const { execFileSync, spawnSync } = require('child_process');
|
|
4
|
+
const fs = require('fs');
|
|
5
|
+
const os = require('os');
|
|
6
|
+
const path = require('path');
|
|
7
|
+
|
|
3
8
|
const { scriptPhasesForModules } = require('../script-phases');
|
|
4
9
|
|
|
5
10
|
const APP_CONFIG_ID = 'expo-constants.app-config';
|
|
@@ -67,3 +72,324 @@ describe('scriptPhasesForModules', () => {
|
|
|
67
72
|
expect(twice).toEqual(once);
|
|
68
73
|
});
|
|
69
74
|
});
|
|
75
|
+
|
|
76
|
+
describe('the ExpoModulesJSI build phase', () => {
|
|
77
|
+
const JSI_BUILD_ID = 'expo-modules-jsi.build';
|
|
78
|
+
const PACKAGE_SCRIPT = 'apple/scripts/build-swiftpm-app-phase.sh';
|
|
79
|
+
const PACKAGE_SCRIPT_PATH = path.join(
|
|
80
|
+
__dirname,
|
|
81
|
+
'..',
|
|
82
|
+
'..',
|
|
83
|
+
'..',
|
|
84
|
+
'..',
|
|
85
|
+
'expo-modules-jsi',
|
|
86
|
+
PACKAGE_SCRIPT
|
|
87
|
+
);
|
|
88
|
+
const jsiPhase = (modules) => scriptPhasesForModules(modules).find((p) => p.id === JSI_BUILD_ID);
|
|
89
|
+
|
|
90
|
+
it('is emitted only when expo-modules-jsi is autolinked', () => {
|
|
91
|
+
expect(jsiPhase(['expo', 'expo-modules-core'])).toBeUndefined();
|
|
92
|
+
expect(jsiPhase(['expo', 'expo-modules-core', 'expo-modules-jsi'])).toBeDefined();
|
|
93
|
+
});
|
|
94
|
+
|
|
95
|
+
// Source packages compile against the headers XCFramework only; the app's own sources
|
|
96
|
+
// and its link step need the real framework, so the phase runs before they compile.
|
|
97
|
+
// It tracks its own inputs, so Xcode must run it on every build.
|
|
98
|
+
it('builds before the app target compiles, on every build', () => {
|
|
99
|
+
expect(jsiPhase(['expo-modules-jsi'])).toMatchObject({
|
|
100
|
+
name: 'Build ExpoModulesJSI',
|
|
101
|
+
position: 'beforeCompile',
|
|
102
|
+
alwaysOutOfDate: true,
|
|
103
|
+
});
|
|
104
|
+
});
|
|
105
|
+
|
|
106
|
+
describe('launcher', () => {
|
|
107
|
+
const { script } = jsiPhase(['expo-modules-jsi']) ?? { script: '' };
|
|
108
|
+
let tmp;
|
|
109
|
+
let srcRoot;
|
|
110
|
+
let rnDir;
|
|
111
|
+
let jsiDir;
|
|
112
|
+
|
|
113
|
+
// pnpm layout: expo-modules-jsi is reachable only from expo-modules-core's real
|
|
114
|
+
// location in the store, not from the app root.
|
|
115
|
+
beforeEach(() => {
|
|
116
|
+
tmp = fs.realpathSync(fs.mkdtempSync(path.join(os.tmpdir(), 'expo-jsi-launcher-')));
|
|
117
|
+
const app = path.join(tmp, 'app');
|
|
118
|
+
const store = path.join(app, 'node_modules', '.pnpm', 'expo-modules-core', 'node_modules');
|
|
119
|
+
const writePackage = (dir, name) => {
|
|
120
|
+
fs.mkdirSync(dir, { recursive: true });
|
|
121
|
+
fs.writeFileSync(path.join(dir, 'package.json'), JSON.stringify({ name }));
|
|
122
|
+
return dir;
|
|
123
|
+
};
|
|
124
|
+
srcRoot = path.join(app, 'ios');
|
|
125
|
+
fs.mkdirSync(srcRoot, { recursive: true });
|
|
126
|
+
rnDir = writePackage(path.join(app, 'node_modules', 'react-native'), 'react-native');
|
|
127
|
+
const expoDir = writePackage(path.join(app, 'node_modules', 'expo'), 'expo');
|
|
128
|
+
const coreDir = writePackage(path.join(store, 'expo-modules-core'), 'expo-modules-core');
|
|
129
|
+
fs.mkdirSync(path.join(expoDir, 'node_modules'));
|
|
130
|
+
fs.symlinkSync(coreDir, path.join(expoDir, 'node_modules', 'expo-modules-core'));
|
|
131
|
+
jsiDir = writePackage(path.join(store, 'expo-modules-jsi'), 'expo-modules-jsi');
|
|
132
|
+
const stub = path.join(jsiDir, PACKAGE_SCRIPT);
|
|
133
|
+
fs.mkdirSync(path.dirname(stub), { recursive: true });
|
|
134
|
+
// Not executable, as after a publish that drops the mode bit.
|
|
135
|
+
fs.writeFileSync(stub, 'echo "RN_DIR=$RN_DIR"\necho "SCRIPT=$0"\n', { mode: 0o644 });
|
|
136
|
+
});
|
|
137
|
+
|
|
138
|
+
afterEach(() => {
|
|
139
|
+
fs.rmSync(tmp, { recursive: true, force: true });
|
|
140
|
+
});
|
|
141
|
+
|
|
142
|
+
const runLauncher = (env) =>
|
|
143
|
+
spawnSync('bash', ['-c', script], {
|
|
144
|
+
// Xcode runs the phase from the project folder. Inside packages/expo, node would
|
|
145
|
+
// resolve `expo` to this package itself.
|
|
146
|
+
cwd: srcRoot,
|
|
147
|
+
encoding: 'utf8',
|
|
148
|
+
env: {
|
|
149
|
+
HOME: tmp,
|
|
150
|
+
PATH: process.env.PATH,
|
|
151
|
+
SRCROOT: srcRoot,
|
|
152
|
+
NODE_BINARY: process.execPath,
|
|
153
|
+
...env,
|
|
154
|
+
},
|
|
155
|
+
});
|
|
156
|
+
|
|
157
|
+
it('is valid bash with no host-specific path baked in', () => {
|
|
158
|
+
execFileSync('bash', ['-n'], { input: script });
|
|
159
|
+
expect(script).not.toMatch(/\/Users\//);
|
|
160
|
+
expect(script).not.toMatch(/node_modules/);
|
|
161
|
+
expect(script).not.toMatch(/SPIKE/i);
|
|
162
|
+
});
|
|
163
|
+
|
|
164
|
+
it('runs the package script with RN_DIR set, even without its executable bit', () => {
|
|
165
|
+
const result = runLauncher();
|
|
166
|
+
expect(result.stderr).toBe('');
|
|
167
|
+
expect(result.status).toBe(0);
|
|
168
|
+
expect(result.stdout).toContain(`RN_DIR=${fs.realpathSync(rnDir)}\n`);
|
|
169
|
+
expect(result.stdout).toContain(`SCRIPT=${path.join(jsiDir, PACKAGE_SCRIPT)}\n`);
|
|
170
|
+
});
|
|
171
|
+
|
|
172
|
+
it('fails with a clear error when expo-modules-jsi has no package script', () => {
|
|
173
|
+
fs.rmSync(path.join(jsiDir, PACKAGE_SCRIPT));
|
|
174
|
+
const result = runLauncher();
|
|
175
|
+
expect(result.status).not.toBe(0);
|
|
176
|
+
expect(result.stderr).toContain(`has no ${PACKAGE_SCRIPT}`);
|
|
177
|
+
});
|
|
178
|
+
|
|
179
|
+
it('fails with a clear error when expo-modules-jsi cannot be resolved', () => {
|
|
180
|
+
fs.rmSync(jsiDir, { recursive: true });
|
|
181
|
+
const result = runLauncher();
|
|
182
|
+
expect(result.status).not.toBe(0);
|
|
183
|
+
expect(result.stderr).toContain('could not be resolved');
|
|
184
|
+
});
|
|
185
|
+
|
|
186
|
+
const nodeOnSystemPath = ['/usr/bin/node', '/bin/node'].some((p) => fs.existsSync(p));
|
|
187
|
+
// Skipped where node is installed in /usr/bin or /bin: the case cannot be set up there.
|
|
188
|
+
(nodeOnSystemPath ? it.skip : it)('fails with a clear error when node is not found', () => {
|
|
189
|
+
const result = runLauncher({ PATH: '/usr/bin:/bin', NODE_BINARY: undefined });
|
|
190
|
+
expect(result.status).not.toBe(0);
|
|
191
|
+
expect(result.stderr).toContain('node was not found');
|
|
192
|
+
});
|
|
193
|
+
});
|
|
194
|
+
|
|
195
|
+
describe('package script', () => {
|
|
196
|
+
it('ships in expo-modules-jsi as an executable bash script', () => {
|
|
197
|
+
fs.accessSync(PACKAGE_SCRIPT_PATH, fs.constants.X_OK);
|
|
198
|
+
execFileSync('bash', ['-n', PACKAGE_SCRIPT_PATH]);
|
|
199
|
+
});
|
|
200
|
+
|
|
201
|
+
// pnpm publish drops the executable bit from every file not listed here.
|
|
202
|
+
it('keeps its executable bit when expo-modules-jsi is published', () => {
|
|
203
|
+
const packageJson = JSON.parse(
|
|
204
|
+
fs.readFileSync(path.join(PACKAGE_SCRIPT_PATH, '..', '..', '..', 'package.json'), 'utf8')
|
|
205
|
+
);
|
|
206
|
+
expect(packageJson.publishConfig.executableFiles).toContain(`./${PACKAGE_SCRIPT}`);
|
|
207
|
+
});
|
|
208
|
+
|
|
209
|
+
describe('when run', () => {
|
|
210
|
+
let tmp;
|
|
211
|
+
|
|
212
|
+
beforeEach(() => {
|
|
213
|
+
tmp = fs.mkdtempSync(path.join(os.tmpdir(), 'expo-jsi-phase-'));
|
|
214
|
+
});
|
|
215
|
+
|
|
216
|
+
afterEach(() => {
|
|
217
|
+
fs.rmSync(tmp, { recursive: true, force: true });
|
|
218
|
+
});
|
|
219
|
+
|
|
220
|
+
const runPackageScript = (env) =>
|
|
221
|
+
spawnSync('bash', [PACKAGE_SCRIPT_PATH], {
|
|
222
|
+
encoding: 'utf8',
|
|
223
|
+
env: { PATH: process.env.PATH, RN_DIR: tmp, ...env },
|
|
224
|
+
});
|
|
225
|
+
|
|
226
|
+
it('rejects a missing platform with a clear error', () => {
|
|
227
|
+
const result = runPackageScript();
|
|
228
|
+
expect(result.status).not.toBe(0);
|
|
229
|
+
expect(result.stderr).toContain('cannot be built for the platform');
|
|
230
|
+
expect(result.stderr).not.toContain('unbound variable');
|
|
231
|
+
});
|
|
232
|
+
|
|
233
|
+
it("reads React Native's headers from the slice being built", () => {
|
|
234
|
+
const reactHeaders = path.join(
|
|
235
|
+
tmp,
|
|
236
|
+
'build/xcframeworks/ReactNativeHeaders.xcframework/ios-arm64_x86_64-simulator/Headers'
|
|
237
|
+
);
|
|
238
|
+
fs.mkdirSync(path.join(reactHeaders, 'hermes'), { recursive: true });
|
|
239
|
+
fs.writeFileSync(path.join(reactHeaders, 'hermes', 'hermes.h'), '');
|
|
240
|
+
const result = runPackageScript({
|
|
241
|
+
PLATFORM_NAME: 'iphonesimulator',
|
|
242
|
+
SRCROOT: tmp,
|
|
243
|
+
OBJROOT: path.join(tmp, 'obj'),
|
|
244
|
+
});
|
|
245
|
+
expect(result.status).not.toBe(0);
|
|
246
|
+
expect(result.stderr).toContain(
|
|
247
|
+
'ReactNativeDependenciesHeaders.xcframework/ios-arm64_x86_64-simulator/Headers/folly is missing'
|
|
248
|
+
);
|
|
249
|
+
expect(result.stderr).toContain(`node ${tmp}/scripts/setup-apple-spm.js update`);
|
|
250
|
+
});
|
|
251
|
+
|
|
252
|
+
// plutil, which reads React Native's version, exists only on macOS.
|
|
253
|
+
(process.platform === 'darwin' ? describe : describe.skip)(
|
|
254
|
+
'with a stub build-xcframework.sh',
|
|
255
|
+
() => {
|
|
256
|
+
const SLICE = 'ios-arm64_x86_64-simulator';
|
|
257
|
+
let script;
|
|
258
|
+
let dsymFolder;
|
|
259
|
+
|
|
260
|
+
beforeEach(() => {
|
|
261
|
+
const scriptsDir = path.join(tmp, 'pkg', 'apple', 'scripts');
|
|
262
|
+
fs.mkdirSync(scriptsDir, { recursive: true });
|
|
263
|
+
script = path.join(scriptsDir, 'build-swiftpm-app-phase.sh');
|
|
264
|
+
fs.copyFileSync(PACKAGE_SCRIPT_PATH, script);
|
|
265
|
+
fs.writeFileSync(
|
|
266
|
+
path.join(scriptsDir, 'build-xcframework.sh'),
|
|
267
|
+
[
|
|
268
|
+
'#!/bin/bash',
|
|
269
|
+
'set -euo pipefail',
|
|
270
|
+
': "${PODS_ROOT:?}" "${EXPO_CUSTOM_BUILD_ROOT:?}"',
|
|
271
|
+
`SLICE_DIR="$EXPO_CUSTOM_BUILD_ROOT/Products/ExpoModulesJSI.xcframework/${SLICE}"`,
|
|
272
|
+
'mkdir -p "$SLICE_DIR/ExpoModulesJSI.framework"',
|
|
273
|
+
'touch "$SLICE_DIR/ExpoModulesJSI.framework/ExpoModulesJSI" "$SLICE_DIR/ExpoModulesJSI.framework/Info.plist"',
|
|
274
|
+
'if [ -n "${STUB_WITH_DSYM:-}" ]; then',
|
|
275
|
+
' mkdir -p "$SLICE_DIR/ExpoModulesJSI.framework.dSYM/Contents"',
|
|
276
|
+
' touch "$SLICE_DIR/ExpoModulesJSI.framework.dSYM/Contents/Info.plist"',
|
|
277
|
+
'fi',
|
|
278
|
+
'',
|
|
279
|
+
].join('\n'),
|
|
280
|
+
{ mode: 0o755 }
|
|
281
|
+
);
|
|
282
|
+
const xcframeworks = path.join(tmp, 'build', 'xcframeworks');
|
|
283
|
+
const reactHeaders = path.join(
|
|
284
|
+
xcframeworks,
|
|
285
|
+
'ReactNativeHeaders.xcframework',
|
|
286
|
+
SLICE,
|
|
287
|
+
'Headers'
|
|
288
|
+
);
|
|
289
|
+
fs.mkdirSync(path.join(reactHeaders, 'hermes'), { recursive: true });
|
|
290
|
+
fs.writeFileSync(path.join(reactHeaders, 'hermes', 'hermes.h'), '');
|
|
291
|
+
fs.mkdirSync(
|
|
292
|
+
path.join(
|
|
293
|
+
xcframeworks,
|
|
294
|
+
'ReactNativeDependenciesHeaders.xcframework',
|
|
295
|
+
SLICE,
|
|
296
|
+
'Headers',
|
|
297
|
+
'folly'
|
|
298
|
+
),
|
|
299
|
+
{ recursive: true }
|
|
300
|
+
);
|
|
301
|
+
fs.writeFileSync(
|
|
302
|
+
path.join(tmp, 'package.json'),
|
|
303
|
+
JSON.stringify({ name: 'react-native', version: '0.88.0' })
|
|
304
|
+
);
|
|
305
|
+
dsymFolder = path.join(tmp, 'dsyms');
|
|
306
|
+
});
|
|
307
|
+
|
|
308
|
+
const runStubbedScript = (env) =>
|
|
309
|
+
spawnSync('bash', [script], {
|
|
310
|
+
encoding: 'utf8',
|
|
311
|
+
env: {
|
|
312
|
+
PATH: process.env.PATH,
|
|
313
|
+
RN_DIR: tmp,
|
|
314
|
+
PLATFORM_NAME: 'iphonesimulator',
|
|
315
|
+
SRCROOT: tmp,
|
|
316
|
+
OBJROOT: path.join(tmp, 'obj'),
|
|
317
|
+
BUILT_PRODUCTS_DIR: path.join(tmp, 'products'),
|
|
318
|
+
TARGET_BUILD_DIR: path.join(tmp, 'target'),
|
|
319
|
+
FRAMEWORKS_FOLDER_PATH: 'Frameworks',
|
|
320
|
+
CODE_SIGNING_ALLOWED: 'NO',
|
|
321
|
+
DWARF_DSYM_FOLDER_PATH: dsymFolder,
|
|
322
|
+
...env,
|
|
323
|
+
},
|
|
324
|
+
});
|
|
325
|
+
|
|
326
|
+
const expectFrameworkCopied = () => {
|
|
327
|
+
for (const dir of [
|
|
328
|
+
path.join(tmp, 'products'),
|
|
329
|
+
path.join(tmp, 'target', 'Frameworks'),
|
|
330
|
+
]) {
|
|
331
|
+
expect(
|
|
332
|
+
fs.existsSync(path.join(dir, 'ExpoModulesJSI.framework', 'ExpoModulesJSI'))
|
|
333
|
+
).toBe(true);
|
|
334
|
+
}
|
|
335
|
+
};
|
|
336
|
+
|
|
337
|
+
it("copies the framework's dSYM into the app's dSYM folder", () => {
|
|
338
|
+
const result = runStubbedScript({ STUB_WITH_DSYM: '1' });
|
|
339
|
+
expect(result.stderr).toBe('');
|
|
340
|
+
expect(result.status).toBe(0);
|
|
341
|
+
expectFrameworkCopied();
|
|
342
|
+
expect(
|
|
343
|
+
fs.existsSync(
|
|
344
|
+
path.join(dsymFolder, 'ExpoModulesJSI.framework.dSYM', 'Contents', 'Info.plist')
|
|
345
|
+
)
|
|
346
|
+
).toBe(true);
|
|
347
|
+
});
|
|
348
|
+
|
|
349
|
+
it('copies no dSYM when the build produced none', () => {
|
|
350
|
+
const result = runStubbedScript();
|
|
351
|
+
expect(result.stderr).toBe('');
|
|
352
|
+
expect(result.status).toBe(0);
|
|
353
|
+
expectFrameworkCopied();
|
|
354
|
+
expect(fs.existsSync(path.join(dsymFolder, 'ExpoModulesJSI.framework.dSYM'))).toBe(
|
|
355
|
+
false
|
|
356
|
+
);
|
|
357
|
+
});
|
|
358
|
+
|
|
359
|
+
it('copies no dSYM when DWARF_DSYM_FOLDER_PATH is empty', () => {
|
|
360
|
+
const result = runStubbedScript({ STUB_WITH_DSYM: '1', DWARF_DSYM_FOLDER_PATH: '' });
|
|
361
|
+
expect(result.stderr).not.toContain('unbound variable');
|
|
362
|
+
expect(result.status).toBe(0);
|
|
363
|
+
expectFrameworkCopied();
|
|
364
|
+
expect(fs.existsSync(dsymFolder)).toBe(false);
|
|
365
|
+
});
|
|
366
|
+
}
|
|
367
|
+
);
|
|
368
|
+
});
|
|
369
|
+
|
|
370
|
+
it('builds, copies, embeds and signs the framework', () => {
|
|
371
|
+
const body = fs.readFileSync(PACKAGE_SCRIPT_PATH, 'utf8');
|
|
372
|
+
expect(body).toContain('"$JSI_DIR/apple/scripts/build-xcframework.sh"');
|
|
373
|
+
expect(body).toContain('$BUILT_PRODUCTS_DIR/ExpoModulesJSI.framework/');
|
|
374
|
+
expect(body).toContain(
|
|
375
|
+
'EMBEDDED="$TARGET_BUILD_DIR/$FRAMEWORKS_FOLDER_PATH/ExpoModulesJSI.framework"'
|
|
376
|
+
);
|
|
377
|
+
expect(body).toContain('/usr/bin/codesign');
|
|
378
|
+
expect(body).toContain('DWARF_DSYM_FOLDER_PATH');
|
|
379
|
+
});
|
|
380
|
+
|
|
381
|
+
// Inside node_modules the package directory may be read-only and is shared by every
|
|
382
|
+
// build folder, so all build state lives under the build folder's OBJROOT.
|
|
383
|
+
it('keeps the build of expo-modules-jsi under the build folder', () => {
|
|
384
|
+
const body = fs.readFileSync(PACKAGE_SCRIPT_PATH, 'utf8');
|
|
385
|
+
expect(body).toContain('JSI_ROOT="$OBJROOT/ExpoModulesJSI"');
|
|
386
|
+
expect(body).toContain('EXPO_CUSTOM_BUILD_ROOT="$JSI_ROOT/custom-build"');
|
|
387
|
+
});
|
|
388
|
+
|
|
389
|
+
it('does not resolve node or packages itself', () => {
|
|
390
|
+
const body = fs.readFileSync(PACKAGE_SCRIPT_PATH, 'utf8');
|
|
391
|
+
expect(body).not.toContain('NODE_BINARY');
|
|
392
|
+
expect(body).not.toContain('require.resolve');
|
|
393
|
+
});
|
|
394
|
+
});
|
|
395
|
+
});
|
|
@@ -18,6 +18,7 @@ const xcode = require(
|
|
|
18
18
|
require.resolve('xcode', { paths: [path.dirname(require.resolve('@expo/config-plugins'))] })
|
|
19
19
|
);
|
|
20
20
|
|
|
21
|
+
const { spmUpdateCommand } = require('./commands');
|
|
21
22
|
const { pluginError } = require('./diagnostics');
|
|
22
23
|
|
|
23
24
|
/** Written by RN's SwiftPM injector into the .xcodeproj it modified. */
|
|
@@ -116,7 +117,7 @@ function findTarget(appRoot, projectPath, targetName) {
|
|
|
116
117
|
? `${WARNING} the Xcode project under ${appRoot} has no target "${targetName}", which is the ` +
|
|
117
118
|
`target its SwiftPM injection marker names, so the Expo module registry will report no app ` +
|
|
118
119
|
`groups. The target was most likely renamed after the last sync — re-run ` +
|
|
119
|
-
|
|
120
|
+
`\`${spmUpdateCommand()}\` to re-inject it.`
|
|
120
121
|
: `${WARNING} the Xcode project under ${appRoot} has no application target, so the Expo module ` +
|
|
121
122
|
'registry will report no app groups. Regenerate the project with `npx expo prebuild`.'
|
|
122
123
|
);
|
|
@@ -178,7 +179,7 @@ function findEntitlementsFile(appRoot, projectPath, targetName) {
|
|
|
178
179
|
`${WARNING} target "${name}" declares an entitlements file that is not on disk ` +
|
|
179
180
|
`(${declared.join(', ')}), so the Expo module registry will report no app groups. Point ` +
|
|
180
181
|
'CODE_SIGN_ENTITLEMENTS at the file the target really uses, then re-run ' +
|
|
181
|
-
|
|
182
|
+
`\`${spmUpdateCommand()}\`.`
|
|
182
183
|
);
|
|
183
184
|
} else if (declared.length > 1) {
|
|
184
185
|
console.warn(
|
|
@@ -242,7 +243,7 @@ function unusablePropertiesError(propertiesPath, reason, options) {
|
|
|
242
243
|
{
|
|
243
244
|
what: `${propertiesPath} could not be read as Podfile properties (${reason}), so the plugin cannot tell which products this app links.`,
|
|
244
245
|
why: "Carrying on would read every property as unset and leave each gated product to its own default instead of the app's configuration, which only shows up at runtime, so the sync stops here.",
|
|
245
|
-
how:
|
|
246
|
+
how: `Restore the file to a JSON object of properties, then re-run \`${spmUpdateCommand()}\`.`,
|
|
246
247
|
},
|
|
247
248
|
options
|
|
248
249
|
);
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const path = require('path');
|
|
4
|
+
|
|
5
|
+
const DEFAULT_REACT_NATIVE_DIR = 'node_modules/react-native';
|
|
6
|
+
|
|
7
|
+
let reactNativeDir = DEFAULT_REACT_NATIVE_DIR;
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* The command that regenerates the app's SwiftPM setup, to run from the app root.
|
|
11
|
+
*
|
|
12
|
+
* It runs React Native's script directly, not `npx react-native spm update`: Expo apps do not use
|
|
13
|
+
* @react-native-community/cli, which is the wrapper that provides `react-native spm`.
|
|
14
|
+
* build-swiftpm-app-phase.sh (expo-modules-jsi) and README.md cannot import this and repeat the
|
|
15
|
+
* text by hand.
|
|
16
|
+
*/
|
|
17
|
+
function spmUpdateCommand() {
|
|
18
|
+
return `node ${reactNativeDir}/scripts/setup-apple-spm.js update`;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* Points `spmUpdateCommand` at the app's react-native, which a workspace may hoist above the
|
|
23
|
+
* app. With no argument, it returns to `node_modules/react-native`.
|
|
24
|
+
*/
|
|
25
|
+
function configureSpmUpdateCommand({ appRoot, reactNativeRoot } = {}) {
|
|
26
|
+
reactNativeDir =
|
|
27
|
+
appRoot == null || reactNativeRoot == null
|
|
28
|
+
? DEFAULT_REACT_NATIVE_DIR
|
|
29
|
+
: path.relative(appRoot, reactNativeRoot).split(path.sep).join('/');
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
module.exports = { configureSpmUpdateCommand, spmUpdateCommand };
|