Skip to content

Expo Config Plugin #79

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 11 commits into from
May 13, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/funny-crabs-smoke.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@journeyapps/react-native-quick-sqlite": patch
---

Added expo config plugin, that automatically applies podfile changes needed for use_frameworks when `staticLibrary` option is specified for the plugin.
23 changes: 23 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,26 @@
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.

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.

### For Expo

#### iOS with `use_frameworks!`

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:

```json
{
"expo": {
"plugins": [
[
"@journeyapps/react-native-quick-sqlite",
{
"staticLibrary": true
}
]
]
}
}
```

This plugin automatically configures the necessary build settings for `react-native-quick-sqlite` to work with `use_frameworks!`.
1 change: 1 addition & 0 deletions app.plugin.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
module.exports = require('./lib/commonjs/withUseFrameworks');
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
"ios",
"cpp",
"meta.json",
"app.plugin.js",
"react-native-quick-sqlite.podspec",
"!android/build",
"!android/.cxx",
Expand Down Expand Up @@ -49,6 +50,7 @@
"homepage": "https://github.com/powersync-ja/react-native-quick-sqlite#readme",
"devDependencies": {
"@changesets/cli": "^2.26.2",
"@expo/config-plugins": "^9.0.17",
"prettier": "^3.3.3",
"react": "18.3.1",
"react-native": "0.76.2",
Expand Down
57 changes: 57 additions & 0 deletions src/withUseFrameworks.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
const { ConfigPlugin, withDangerousMod, createRunOncePlugin } = require('@expo/config-plugins');
const fs = require('fs');
const path = require('path');

// Define package metadata
const pkg = { name: '@journeyapps/react-native-quick-sqlite', version: 'UNVERSIONED' };

// Function to modify the Podfile
function modifyPodfile(podfilePath: string) {
let podfile = fs.readFileSync(podfilePath, 'utf8');
const preinstallScript = `
pre_install do |installer|
installer.pod_targets.each do |pod|
if pod.name.eql?('react-native-quick-sqlite')
def pod.build_type
Pod::BuildType.static_library
end
end
end
end
`;
// Ensure script is added only once
if (!podfile.includes('react-native-quick-sqlite')) {
podfile = podfile.replace(/target\s+'[^']+'\s+do/, `$&\n${preinstallScript}`);
fs.writeFileSync(podfilePath, podfile, 'utf8');
console.log(`Added pre_install script for react-native-quick-sqlite to Podfile`);
}
}

// Config Plugin
const withUseFrameworks = (config, options = { staticLibrary: false }) => {
const { staticLibrary } = options;

return withDangerousMod(config, [
'ios',
(config) => {
if (!staticLibrary) {
return config;
}

const podfilePath = path.join(config.modRequest.platformProjectRoot, 'Podfile');
if (fs.existsSync(podfilePath)) {
modifyPodfile(podfilePath);
} else {
console.warn(`Podfile not found at ${podfilePath}`);
}
return config;
}
]);
};

const pluginWithOptions = (config, options) => {
return withUseFrameworks(config, options);
};

// Export the plugin with Expo's createRunOncePlugin
module.exports = createRunOncePlugin(pluginWithOptions, pkg.name, pkg.version);
Loading