@yodlpay/react-native 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +377 -0
- package/dist/index.cjs +174 -0
- package/dist/index.d.cts +128 -0
- package/dist/index.d.mts +128 -0
- package/dist/index.mjs +175 -0
- package/metro-config.cjs +96 -0
- package/package.json +76 -0
package/metro-config.cjs
ADDED
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Metro configuration helper for apps using @yodlpay/react-native via local `file:` linking.
|
|
3
|
+
*
|
|
4
|
+
* Usage in your app's metro.config.js:
|
|
5
|
+
*
|
|
6
|
+
* ```js
|
|
7
|
+
* const { getDefaultConfig } = require('expo/metro-config');
|
|
8
|
+
* const { withYodlReactNative } = require('@yodlpay/react-native/metro-config');
|
|
9
|
+
*
|
|
10
|
+
* const config = getDefaultConfig(__dirname);
|
|
11
|
+
* module.exports = withYodlReactNative(config, __dirname);
|
|
12
|
+
* ```
|
|
13
|
+
*
|
|
14
|
+
* If you have a custom resolveRequest, set it BEFORE calling withYodlReactNative:
|
|
15
|
+
*
|
|
16
|
+
* ```js
|
|
17
|
+
* config.resolver.resolveRequest = myCustomResolver;
|
|
18
|
+
* module.exports = withYodlReactNative(config, __dirname);
|
|
19
|
+
* ```
|
|
20
|
+
*/
|
|
21
|
+
const path = require('node:path');
|
|
22
|
+
const fs = require('node:fs');
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* Decide whether a bare module specifier should resolve from the consumer's
|
|
26
|
+
* project root instead of the linked workspace.
|
|
27
|
+
*
|
|
28
|
+
* When linked via `file:`, Metro bundles the SDK's compiled output straight
|
|
29
|
+
* out of the sibling workspace. The SDK keeps its peer deps external (`viem`,
|
|
30
|
+
* `react`, `react-native`, `react-native-webview`) — and their transitive deps
|
|
31
|
+
* like `ox` — so those would otherwise resolve into the workspace's pnpm store,
|
|
32
|
+
* a directory that lives *outside* the consumer's project root. Metro can't
|
|
33
|
+
* represent those sibling paths and emits broken specifiers such as
|
|
34
|
+
* `./yodl-sdk/node_modules/.pnpm/ox@.../index`.
|
|
35
|
+
*
|
|
36
|
+
* Deps the consumer installs itself (e.g. `viem`, `ox`, `react`) live under
|
|
37
|
+
* the project root, so resolving them from there avoids the broken sibling
|
|
38
|
+
* paths and guarantees a single instance. Anything else (the SDK's own bundled
|
|
39
|
+
* deps are already inlined, so this is mainly a defensive fallback) resolves
|
|
40
|
+
* from the workspace (see the `try/catch` in `resolveRequest`).
|
|
41
|
+
*/
|
|
42
|
+
function shouldResolveFromApp(moduleName) {
|
|
43
|
+
// Relative / absolute imports and node builtins resolve normally
|
|
44
|
+
if (moduleName.startsWith('.') || moduleName.startsWith('/') || moduleName.startsWith('node:')) {
|
|
45
|
+
return false;
|
|
46
|
+
}
|
|
47
|
+
// First-party workspace packages must resolve through the linked workspace
|
|
48
|
+
if (moduleName === '@yodlpay' || moduleName.startsWith('@yodlpay/')) {
|
|
49
|
+
return false;
|
|
50
|
+
}
|
|
51
|
+
return true;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
function withYodlReactNative(config, projectRoot) {
|
|
55
|
+
// Resolve the real path of the linked package (follows symlinks)
|
|
56
|
+
const yodlPkgDir = fs.realpathSync(
|
|
57
|
+
path.resolve(projectRoot, 'node_modules/@yodlpay/react-native'),
|
|
58
|
+
);
|
|
59
|
+
const workspaceRoot = path.resolve(yodlPkgDir, '../..');
|
|
60
|
+
|
|
61
|
+
// Watch the linked workspace for live reloading
|
|
62
|
+
config.watchFolders = [...(config.watchFolders || []), workspaceRoot];
|
|
63
|
+
|
|
64
|
+
// Capture any existing resolveRequest the user already set
|
|
65
|
+
config.resolver = config.resolver || {};
|
|
66
|
+
const userResolveRequest = config.resolver.resolveRequest || null;
|
|
67
|
+
|
|
68
|
+
const resolve = (ctx, name, plat) =>
|
|
69
|
+
userResolveRequest ? userResolveRequest(ctx, name, plat) : ctx.resolveRequest(ctx, name, plat);
|
|
70
|
+
|
|
71
|
+
config.resolver.resolveRequest = (context, moduleName, platform) => {
|
|
72
|
+
// When a third-party dep is imported from within the linked workspace,
|
|
73
|
+
// first try to resolve it from the consumer's project root. This keeps the
|
|
74
|
+
// app's own deps (react, react-native, viem, ox, ...) as single instances
|
|
75
|
+
// and sidesteps the broken sibling-path resolution.
|
|
76
|
+
if (context.originModulePath?.includes(workspaceRoot) && shouldResolveFromApp(moduleName)) {
|
|
77
|
+
const redirectedContext = {
|
|
78
|
+
...context,
|
|
79
|
+
originModulePath: path.resolve(projectRoot, '_virtual.js'),
|
|
80
|
+
};
|
|
81
|
+
try {
|
|
82
|
+
return resolve(redirectedContext, moduleName, platform);
|
|
83
|
+
} catch {
|
|
84
|
+
// Workspace-only dependency (e.g. permissionless, promptparse) that the
|
|
85
|
+
// consumer app doesn't install — fall back to workspace resolution.
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
// Otherwise delegate to the user's resolveRequest or Metro's default
|
|
90
|
+
return resolve(context, moduleName, platform);
|
|
91
|
+
};
|
|
92
|
+
|
|
93
|
+
return config;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
module.exports = { withYodlReactNative };
|
package/package.json
ADDED
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@yodlpay/react-native",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"type": "module",
|
|
5
|
+
"description": "Yodl React Native SDK — WebView wrapper with viem WalletClient integration",
|
|
6
|
+
"license": "MIT",
|
|
7
|
+
"engines": {
|
|
8
|
+
"node": ">=18"
|
|
9
|
+
},
|
|
10
|
+
"main": "./dist/index.cjs",
|
|
11
|
+
"module": "./dist/index.mjs",
|
|
12
|
+
"types": "./dist/index.d.mts",
|
|
13
|
+
"react-native": "./dist/index.cjs",
|
|
14
|
+
"exports": {
|
|
15
|
+
".": {
|
|
16
|
+
"react-native": "./dist/index.cjs",
|
|
17
|
+
"import": {
|
|
18
|
+
"types": "./dist/index.d.mts",
|
|
19
|
+
"default": "./dist/index.mjs"
|
|
20
|
+
},
|
|
21
|
+
"require": {
|
|
22
|
+
"types": "./dist/index.d.cts",
|
|
23
|
+
"default": "./dist/index.cjs"
|
|
24
|
+
}
|
|
25
|
+
},
|
|
26
|
+
"./metro-config": "./metro-config.cjs"
|
|
27
|
+
},
|
|
28
|
+
"repository": {
|
|
29
|
+
"type": "git",
|
|
30
|
+
"url": "git+https://github.com/yodlpay/yodl-sdk.git",
|
|
31
|
+
"directory": "packages/react-native"
|
|
32
|
+
},
|
|
33
|
+
"bugs": "https://github.com/yodlpay/yodl-sdk/issues",
|
|
34
|
+
"homepage": "https://github.com/yodlpay/yodl-sdk#readme",
|
|
35
|
+
"sideEffects": false,
|
|
36
|
+
"publishConfig": {
|
|
37
|
+
"access": "public"
|
|
38
|
+
},
|
|
39
|
+
"files": [
|
|
40
|
+
"dist/**/*.cjs",
|
|
41
|
+
"dist/**/*.mjs",
|
|
42
|
+
"dist/**/*.d.cts",
|
|
43
|
+
"dist/**/*.d.mts",
|
|
44
|
+
"metro-config.cjs",
|
|
45
|
+
"README.md"
|
|
46
|
+
],
|
|
47
|
+
"dependencies": {
|
|
48
|
+
"permissionless": "^0.3.6"
|
|
49
|
+
},
|
|
50
|
+
"peerDependencies": {
|
|
51
|
+
"react": ">=18.0.0",
|
|
52
|
+
"react-native": ">=0.72.0",
|
|
53
|
+
"react-native-webview": ">=13.0.0",
|
|
54
|
+
"viem": ">=2.0.0"
|
|
55
|
+
},
|
|
56
|
+
"devDependencies": {
|
|
57
|
+
"@arethetypeswrong/cli": "^0.18.2",
|
|
58
|
+
"@types/react": "^19.0.0",
|
|
59
|
+
"publint": "^0.3.21",
|
|
60
|
+
"react": "^19.0.0",
|
|
61
|
+
"react-native": "^0.79.0",
|
|
62
|
+
"react-native-webview": "^13.12.0",
|
|
63
|
+
"tsdown": "^0.22.0",
|
|
64
|
+
"typescript": "^5.7.2",
|
|
65
|
+
"viem": "^2.50.4",
|
|
66
|
+
"vitest": "^4.1.7",
|
|
67
|
+
"@yodlpay/sdk-core": "0.1.0"
|
|
68
|
+
},
|
|
69
|
+
"scripts": {
|
|
70
|
+
"build": "tsdown",
|
|
71
|
+
"typecheck": "tsc --noEmit",
|
|
72
|
+
"test": "vitest run",
|
|
73
|
+
"test:watch": "vitest",
|
|
74
|
+
"lint": "biome check ."
|
|
75
|
+
}
|
|
76
|
+
}
|