Skip to content

Instantly share code, notes, and snippets.

@sgup
Last active February 4, 2025 17:08
Show Gist options
  • Save sgup/c12ea5bfaf9a3ae83dff9012741c2b77 to your computer and use it in GitHub Desktop.
Save sgup/c12ea5bfaf9a3ae83dff9012741c2b77 to your computer and use it in GitHub Desktop.
Expo plugin for OP-SQLite
const {
withPodfileProperties,
withDangerousMod,
} = require("@expo/config-plugins");
const fs = require("fs");
const path = require("path");
async function readFileAsync(path) {
return fs.promises.readFile(path, "utf8");
}
async function saveFileAsync(path, content) {
return fs.promises.writeFile(path, content, "utf8");
}
const withOpSqliteMods = (c) => {
c = withStaticPreinstall(c);
c = withUseThirdPartySQLitePod(c);
return c;
};
const withUseThirdPartySQLitePod = (expoConfig) => {
return withPodfileProperties(expoConfig, (config) => {
config.modResults = {
...config.modResults,
"expo.updates.useThirdPartySQLitePod": "true",
};
return config;
});
};
const withStaticPreinstall = (c) => {
return withDangerousMod(c, [
"ios",
async (config) => {
const podfilePath = path.join(
config.modRequest.platformProjectRoot,
"Podfile",
);
const podfileContent = await readFileAsync(podfilePath);
// Add pre_install hook:
const preInstallHook = `
pre_install do |installer|
installer.pod_targets.each do |pod|
if pod.name.eql?('op-sqlite')
def pod.build_type
Pod::BuildType.static_library
end
end
end
end`;
if (!podfileContent.includes("pre_install")) {
const updatedContent = podfileContent.replace(
/(\n\s*end\s*)$/,
`${preInstallHook}\n$1`,
);
await saveFileAsync(podfilePath, updatedContent);
}
return config;
},
]);
};
module.exports = (config) => withOpSqliteMods(config);
@sgup
Copy link
Author

sgup commented Feb 4, 2025

Usage in app.config.ts:

import withOpSqlPlugin from "./plugins/expo-op-sqlite.plugin";
...
export default withOpSqlPlugin(config);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment