Skip to content

Commit e43564e

Browse files
committed
Only add pre_install entry when staticLibrary option is specified for plugin.
1 parent f7099d8 commit e43564e

File tree

2 files changed

+20
-7
lines changed

2 files changed

+20
-7
lines changed

README.md

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,19 @@ It is **not** intended to be used independently, use [PowerSync React Native SDK
1010

1111
#### iOS with `use_frameworks!`
1212

13-
If your iOS project uses `use_frameworks!`, add the config plugin to your **app.json** or **app.config.js**:
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:
1414

1515
```json
1616
{
1717
"expo": {
18-
"plugins": [["@journeyapps/react-native-quick-sqlite"]]
18+
"plugins": [
19+
[
20+
"@journeyapps/react-native-quick-sqlite",
21+
{
22+
"staticLibrary": true
23+
}
24+
]
25+
]
1926
}
2027
}
2128
```

src/withUseFrameworks.ts

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ const path = require('path');
66
const pkg = { name: '@journeyapps/react-native-quick-sqlite', version: 'UNVERSIONED' };
77

88
// Function to modify the Podfile
9-
function modifyPodfile(podfilePath) {
9+
function modifyPodfile(podfilePath: string, staticLibrary: boolean) {
1010
let podfile = fs.readFileSync(podfilePath, 'utf8');
1111
const preinstallScript = `
1212
pre_install do |installer|
@@ -20,21 +20,23 @@ pre_install do |installer|
2020
end
2121
`;
2222
// Ensure script is added only once
23-
if (!podfile.includes('react-native-quick-sqlite')) {
23+
if (staticLibrary && !podfile.includes('react-native-quick-sqlite')) {
2424
podfile = podfile.replace(/target\s+'[^']+'\s+do/, `$&\n${preinstallScript}`);
2525
fs.writeFileSync(podfilePath, podfile, 'utf8');
2626
console.log(`Added pre_install script for react-native-quick-sqlite to Podfile`);
2727
}
2828
}
2929

3030
// Config Plugin
31-
const withUseFrameworks = (config) => {
31+
const withUseFrameworks = (config, options = { staticLibrary: false }) => {
32+
const { staticLibrary } = options;
33+
3234
return withDangerousMod(config, [
3335
'ios',
3436
(config) => {
3537
const podfilePath = path.join(config.modRequest.platformProjectRoot, 'Podfile');
3638
if (fs.existsSync(podfilePath)) {
37-
modifyPodfile(podfilePath);
39+
modifyPodfile(podfilePath, staticLibrary);
3840
} else {
3941
console.warn(`Podfile not found at ${podfilePath}`);
4042
}
@@ -43,5 +45,9 @@ const withUseFrameworks = (config) => {
4345
]);
4446
};
4547

48+
const pluginWithOptions = (config, options) => {
49+
return withUseFrameworks(config, options);
50+
};
51+
4652
// Export the plugin with Expo's createRunOncePlugin
47-
module.exports = createRunOncePlugin(withUseFrameworks, pkg.name, pkg.version);
53+
module.exports = createRunOncePlugin(pluginWithOptions, pkg.name, pkg.version);

0 commit comments

Comments
 (0)