Skip to content

Commit 2fd1357

Browse files
Raiden-16F7Raiden-16F7Chriztiaan
authored
Expo Config Plugin (#79)
* Expo Config Plugin Created * Only add pre_install entry when staticLibrary option is specified for plugin. --------- Co-authored-by: Raiden-16F7 <[email protected]> Co-authored-by: Christiaan Landman <[email protected]> Co-authored-by: Christiaan Landman <[email protected]>
1 parent 0d40b3a commit 2fd1357

File tree

6 files changed

+387
-13
lines changed

6 files changed

+387
-13
lines changed

.changeset/funny-crabs-smoke.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@journeyapps/react-native-quick-sqlite": patch
3+
---
4+
5+
Added expo config plugin, that automatically applies podfile changes needed for use_frameworks when `staticLibrary` option is specified for the plugin.

README.md

+23
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,26 @@
55
This repository is a fork of [react-native-quick-sqlite](https://github.com/ospfranco/react-native-quick-sqlite?tab=readme-ov-file) that includes custom SQLite extensions built specifically for **PowerSync**. It has been modified to meet the needs of **PowerSync**, adding features or behaviors that are different from the original repository.
66

77
It is **not** intended to be used independently, use [PowerSync React Native SDK](https://github.com/powersync-ja/powersync-js/tree/main/packages/react-native) and install this alongside it as a peer dependency.
8+
9+
### For Expo
10+
11+
#### iOS with `use_frameworks!`
12+
13+
If your iOS project uses `use_frameworks!`, add the `react-native-quick-sqlite` plugin to your **app.json** or **app.config.js** and configure the `staticLibrary` option:
14+
15+
```json
16+
{
17+
"expo": {
18+
"plugins": [
19+
[
20+
"@journeyapps/react-native-quick-sqlite",
21+
{
22+
"staticLibrary": true
23+
}
24+
]
25+
]
26+
}
27+
}
28+
```
29+
30+
This plugin automatically configures the necessary build settings for `react-native-quick-sqlite` to work with `use_frameworks!`.

app.plugin.js

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
module.exports = require('./lib/commonjs/withUseFrameworks');

package.json

+2
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
"ios",
1919
"cpp",
2020
"meta.json",
21+
"app.plugin.js",
2122
"react-native-quick-sqlite.podspec",
2223
"!android/build",
2324
"!android/.cxx",
@@ -49,6 +50,7 @@
4950
"homepage": "https://github.com/powersync-ja/react-native-quick-sqlite#readme",
5051
"devDependencies": {
5152
"@changesets/cli": "^2.26.2",
53+
"@expo/config-plugins": "^9.0.17",
5254
"prettier": "^3.3.3",
5355
"react": "18.3.1",
5456
"react-native": "0.76.2",

src/withUseFrameworks.ts

+57
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
const { ConfigPlugin, withDangerousMod, createRunOncePlugin } = require('@expo/config-plugins');
2+
const fs = require('fs');
3+
const path = require('path');
4+
5+
// Define package metadata
6+
const pkg = { name: '@journeyapps/react-native-quick-sqlite', version: 'UNVERSIONED' };
7+
8+
// Function to modify the Podfile
9+
function modifyPodfile(podfilePath: string) {
10+
let podfile = fs.readFileSync(podfilePath, 'utf8');
11+
const preinstallScript = `
12+
pre_install do |installer|
13+
installer.pod_targets.each do |pod|
14+
if pod.name.eql?('react-native-quick-sqlite')
15+
def pod.build_type
16+
Pod::BuildType.static_library
17+
end
18+
end
19+
end
20+
end
21+
`;
22+
// Ensure script is added only once
23+
if (!podfile.includes('react-native-quick-sqlite')) {
24+
podfile = podfile.replace(/target\s+'[^']+'\s+do/, `$&\n${preinstallScript}`);
25+
fs.writeFileSync(podfilePath, podfile, 'utf8');
26+
console.log(`Added pre_install script for react-native-quick-sqlite to Podfile`);
27+
}
28+
}
29+
30+
// Config Plugin
31+
const withUseFrameworks = (config, options = { staticLibrary: false }) => {
32+
const { staticLibrary } = options;
33+
34+
return withDangerousMod(config, [
35+
'ios',
36+
(config) => {
37+
if (!staticLibrary) {
38+
return config;
39+
}
40+
41+
const podfilePath = path.join(config.modRequest.platformProjectRoot, 'Podfile');
42+
if (fs.existsSync(podfilePath)) {
43+
modifyPodfile(podfilePath);
44+
} else {
45+
console.warn(`Podfile not found at ${podfilePath}`);
46+
}
47+
return config;
48+
}
49+
]);
50+
};
51+
52+
const pluginWithOptions = (config, options) => {
53+
return withUseFrameworks(config, options);
54+
};
55+
56+
// Export the plugin with Expo's createRunOncePlugin
57+
module.exports = createRunOncePlugin(pluginWithOptions, pkg.name, pkg.version);

0 commit comments

Comments
 (0)