Skip to content

Commit 0bf374c

Browse files
authored
feat: add expo plugin (#714)
1 parent c4f73ff commit 0bf374c

File tree

11 files changed

+1463
-62
lines changed

11 files changed

+1463
-62
lines changed

bun.lock

Lines changed: 1290 additions & 49 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,23 +15,25 @@
1515
"format": "bun --filter='*' format",
1616
"format:fix": "bun --filter='*' format:fix",
1717
"prepare": "bun --filter=\"react-native-quick-crypto\" prepare",
18-
"release": "./scripts/release.sh"
18+
"release": "./scripts/release.sh",
19+
"yalc": "cd packages/react-native-quick-crypto && bun yalc push --replace --sig"
1920
},
2021
"devDependencies": {
22+
"@eslint/compat": "1.2.8",
23+
"@eslint/js": "9.24.0",
2124
"@release-it/bumper": "7.0.2",
2225
"@release-it/conventional-changelog": "10.0.0",
23-
"release-it": "18.1.2",
24-
"eslint": "9.24.0",
25-
"@typescript-eslint/parser": "8.30.1",
2626
"@typescript-eslint/eslint-plugin": "8.30.1",
27+
"@typescript-eslint/parser": "8.30.1",
28+
"eslint": "9.24.0",
29+
"eslint-config-prettier": "10.1.2",
30+
"eslint-plugin-prettier": "5.2.6",
2731
"eslint-plugin-react-native": "5.0.0",
2832
"prettier": "3.5.3",
29-
"@eslint/js": "9.24.0",
30-
"@eslint/compat": "1.2.8",
33+
"release-it": "18.1.2",
3134
"typescript": "5.8.3",
3235
"typescript-eslint": "8.30.1",
33-
"eslint-plugin-prettier": "5.2.6",
34-
"eslint-config-prettier": "10.1.2"
36+
"yalc": "^1.0.0-pre.53"
3537
},
3638
"packageManager": "[email protected]",
3739
"release-it": {
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
const { createRNQCPlugin } = require('./lib/commonjs/expo-plugin/withRNQC');
2+
const pkg = require('./package.json');
3+
module.exports = createRNQCPlugin(pkg.name, pkg.version);

packages/react-native-quick-crypto/eslint.config.js renamed to packages/react-native-quick-crypto/eslint.config.mjs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,11 @@ export default [
5151
},
5252
// Ignore patterns
5353
{
54-
ignores: ['.prettierrc.js', '*.config.js', '**/lib/**', '**/test/**'],
54+
ignores: [
55+
'.prettierrc.js',
56+
'*.config.*js',
57+
'*.plugin.js',
58+
'**/lib/**',
59+
'**/test/**'],
5560
},
5661
];

packages/react-native-quick-crypto/package.json

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
"name": "react-native-quick-crypto",
33
"version": "1.0.0-beta.17",
44
"description": "A fast implementation of Node's `crypto` module written in C/C++ JSI",
5-
"type": "module",
65
"main": "lib/commonjs/index",
76
"module": "lib/module/index",
87
"types": "lib/typescript/index.d.ts",
@@ -33,9 +32,9 @@
3332
"deps",
3433
"nitrogen",
3534
"react-native.config.js",
36-
"app.plugin.js",
3735
"*.podspec",
3836
"README.md",
37+
"app.plugin.js",
3938
"!**/__tests__",
4039
"!**/__fixtures__",
4140
"!**/__mocks__"
@@ -45,9 +44,13 @@
4544
"ios",
4645
"android",
4746
"jsi",
47+
"nitro",
4848
"crypto",
49+
"cryptography",
50+
"cryptocurrency",
4951
"c++",
5052
"fast",
53+
"quick",
5154
"web3"
5255
],
5356
"repository": {
@@ -76,10 +79,12 @@
7679
},
7780
"devDependencies": {
7881
"@types/jest": "29.5.11",
79-
"@types/node": "^22.0.0",
82+
"@types/node": "22.0.0",
8083
"@types/react": "18.3.3",
8184
"@types/readable-stream": "4.0.18",
8285
"del-cli": "6.0.0",
86+
"expo": "^47.0.0",
87+
"expo-build-properties": "0.14.6",
8388
"jest": "29.7.0",
8489
"nitro-codegen": "0.25.2",
8590
"react-native-builder-bob": "0.39.1",
@@ -88,7 +93,13 @@
8893
"peerDependencies": {
8994
"react": "*",
9095
"react-native": "*",
91-
"react-native-nitro-modules": "*"
96+
"react-native-nitro-modules": "*",
97+
"expo": ">=47.0.0"
98+
},
99+
"peerDependenciesMeta": {
100+
"expo": {
101+
"optional": true
102+
}
92103
},
93104
"release-it": {
94105
"npm": {

packages/react-native-quick-crypto/prettier.config.js renamed to packages/react-native-quick-crypto/prettier.config.mjs

File renamed without changes.
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
export type ConfigProps = {
2+
/**
3+
* Enable libsodium support
4+
* @default false
5+
*/
6+
sodiumEnabled?: boolean;
7+
};
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import { createRunOncePlugin } from 'expo/config-plugins';
2+
import type { ConfigPlugin } from 'expo/config-plugins';
3+
import type { ConfigProps } from './@types';
4+
import { withSodiumIos } from './withSodiumIos';
5+
import { withSodiumAndroid } from './withSodiumAndroid';
6+
import { withXCode } from './withXCode';
7+
8+
const withRNQCInternal: ConfigPlugin<ConfigProps> = (config, props = {}) => {
9+
// add XCode workarounds for some 16.x releases that are not RN-friendly
10+
config = withXCode(config, props);
11+
12+
// enable libsodium algorithms
13+
if (props.sodiumEnabled) {
14+
config = withSodiumIos(config, props);
15+
config = withSodiumAndroid(config, props);
16+
}
17+
18+
return config;
19+
};
20+
21+
export function createRNQCPlugin(name: string, version: string) {
22+
return createRunOncePlugin(withRNQCInternal, name, version);
23+
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import type { ConfigPlugin } from 'expo/config-plugins';
2+
import { withGradleProperties } from 'expo/config-plugins';
3+
import type { ConfigProps } from './@types';
4+
5+
export const withSodiumAndroid: ConfigPlugin<ConfigProps> = config => {
6+
return withGradleProperties(config, config => {
7+
config.modResults = config.modResults || [];
8+
9+
// Check if the property already exists
10+
const existingProperty = config.modResults.find(
11+
item => item.type === 'property' && item.key === 'sodiumEnabled',
12+
);
13+
14+
if (!existingProperty) {
15+
config.modResults.push({
16+
type: 'property',
17+
key: 'sodiumEnabled',
18+
value: 'true',
19+
});
20+
}
21+
22+
return config;
23+
});
24+
};
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
import type { ConfigPlugin } from 'expo/config-plugins';
2+
import { withDangerousMod } from 'expo/config-plugins';
3+
import fs from 'fs';
4+
import path from 'path';
5+
import type { ConfigProps } from './@types';
6+
7+
export const withSodiumIos: ConfigPlugin<ConfigProps> = config => {
8+
return withDangerousMod(config, [
9+
'ios',
10+
config => {
11+
const podfilePath = path.join(
12+
config.modRequest.platformProjectRoot,
13+
'Podfile',
14+
);
15+
let contents = fs.readFileSync(podfilePath, 'utf-8');
16+
17+
// Check if SODIUM_ENABLED is already set
18+
if (!contents.includes("ENV['SODIUM_ENABLED']")) {
19+
// Add it right after the RCT_NEW_ARCH_ENABLED ENV variable
20+
contents = contents.replace(
21+
/^(ENV\['RCT_NEW_ARCH_ENABLED'\].*$)/m,
22+
`$1\nENV['SODIUM_ENABLED'] = '1'`,
23+
);
24+
fs.writeFileSync(podfilePath, contents);
25+
}
26+
27+
return config;
28+
},
29+
]);
30+
};

0 commit comments

Comments
 (0)