@miden-sdk/create-miden-para-react 0.13.0 → 0.13.2
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 +5 -5
- package/bin/create-miden-para-react.mjs +8 -10
- package/package.json +1 -1
- package/template/src/App.tsx +27 -24
- package/template/vite.config.ts +28 -21
package/README.md
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
# @miden-sdk/create-miden-para-react
|
|
2
2
|
|
|
3
|
-
`npm create @miden-sdk/miden-para-react@latest my-app` scaffolds the latest Vite `react-ts` starter, overwrites it with this repo's `vite.config.ts`, swaps in a Para + Miden-ready `App.tsx`, and adds the deps needed to run it out of the box. The scaffold always runs `create-vite` with `--yes --no-install` and pipes
|
|
3
|
+
`npm create @miden-sdk/miden-para-react@latest my-app` scaffolds the latest Vite `react-ts` starter, overwrites it with this repo's `vite.config.ts`, swaps in a Para + Miden-ready `App.tsx`, and adds the deps needed to run it out of the box. The scaffold always runs `create-vite` with `--yes --no-install` and pipes "no" to the install prompt to prevent upstream installs from overwriting the template before we patch it.
|
|
4
4
|
|
|
5
5
|
## What it does
|
|
6
6
|
- Runs `npm create vite@latest <target> -- --template react-ts` so you always start from the upstream default.
|
|
7
7
|
- Replaces `vite.config.ts` with the Para + Miden-friendly config (dedupe/exclude and WASM asset handling).
|
|
8
|
-
- Replaces `src/App.tsx` with a
|
|
9
|
-
- Adds Para/Miden
|
|
10
|
-
- Installs dependencies using your detected package manager (`pnpm`, `yarn`, `bun`, or falls back to `npm`); `create-vite` is invoked with `--yes --no-install` and auto-answers
|
|
11
|
-
- Writes `.npmrc` with `legacy-peer-deps=true`
|
|
8
|
+
- Replaces `src/App.tsx` with a `ParaSignerProvider` + `MidenProvider` starter that reports wallet, account ID, and client readiness.
|
|
9
|
+
- Adds Para/Miden deps: `@miden-sdk/miden-para`, `@miden-sdk/react`, `@getpara/react-sdk-lite`, `@getpara/evm-wallet-connectors`, `@miden-sdk/miden-sdk`, plus dev plugins `vite-plugin-node-polyfills`, `vite-plugin-wasm`, and `vite-plugin-top-level-await`.
|
|
10
|
+
- Installs dependencies using your detected package manager (`pnpm`, `yarn`, `bun`, or falls back to `npm`); `create-vite` is invoked with `--yes --no-install` and auto-answers "no" to install prompts to avoid reverting the patched files.
|
|
11
|
+
- Writes `.npmrc` with `legacy-peer-deps=true` for peer dependency resolution.
|
|
12
12
|
- Adds `src/polyfills.ts` and injects it into `src/main.tsx` to provide `Buffer`/`process` in the browser.
|
|
13
13
|
|
|
14
14
|
## Usage
|
|
@@ -27,8 +27,8 @@ const repoRoot = resolve(__dirname, "..", "..", "..");
|
|
|
27
27
|
const localMidenParaPath =
|
|
28
28
|
process.env.MIDEN_PARA_LOCAL_MIDEN_PARA_PATH ?? repoRoot;
|
|
29
29
|
const localUseMidenParaReactPath =
|
|
30
|
-
process.env.
|
|
31
|
-
|
|
30
|
+
process.env.MIDEN_PARA_LOCAL_USE_MIDEN_PARA_REACT_PATH ??
|
|
31
|
+
join(repoRoot, "packages", "use-miden-para-react");
|
|
32
32
|
const useLocalDeps = process.env.MIDEN_PARA_LOCAL_DEPS === "1";
|
|
33
33
|
|
|
34
34
|
const args = process.argv.slice(2);
|
|
@@ -211,22 +211,20 @@ function ensureMidenParaDependencies(targetRoot) {
|
|
|
211
211
|
pkg.scripts = pkg.scripts ?? {};
|
|
212
212
|
const midenParaVersion = useLocalDeps
|
|
213
213
|
? `file:${localMidenParaPath}`
|
|
214
|
-
: "0.13.
|
|
214
|
+
: "0.13.1";
|
|
215
215
|
const useMidenParaReactVersion = useLocalDeps
|
|
216
216
|
? `file:${localUseMidenParaReactPath}`
|
|
217
217
|
: "^0.13.0";
|
|
218
|
-
// Align with examples/react so Para SDK connector peers are satisfied
|
|
218
|
+
// Align with examples/react-signer so Para SDK connector peers are satisfied
|
|
219
219
|
Object.assign(pkg.dependencies, {
|
|
220
220
|
...pkg.dependencies,
|
|
221
|
-
"@getpara/react-sdk-lite": "2.
|
|
222
|
-
"@getpara/evm-wallet-connectors": "^2.
|
|
223
|
-
"@tanstack/react-query": "^5.90.12",
|
|
224
|
-
"@wagmi/core": "^3.0.0",
|
|
221
|
+
"@getpara/react-sdk-lite": "^2.2.0",
|
|
222
|
+
"@getpara/evm-wallet-connectors": "^2.2.0",
|
|
225
223
|
"@miden-sdk/miden-sdk": "^0.13.0",
|
|
226
224
|
"@miden-sdk/miden-para": midenParaVersion,
|
|
227
225
|
"@miden-sdk/use-miden-para-react": useMidenParaReactVersion,
|
|
228
|
-
|
|
229
|
-
|
|
226
|
+
"@miden-sdk/react": "^0.13.1",
|
|
227
|
+
"@tanstack/react-query": "^5.0.0",
|
|
230
228
|
});
|
|
231
229
|
|
|
232
230
|
Object.assign(pkg.devDependencies, {
|
package/package.json
CHANGED
package/template/src/App.tsx
CHANGED
|
@@ -1,42 +1,45 @@
|
|
|
1
1
|
import './App.css';
|
|
2
2
|
import '@getpara/react-sdk-lite/styles.css';
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import { QueryClient, QueryClientProvider } from '@tanstack/react-query';
|
|
6
|
-
|
|
7
|
-
const queryClient = new QueryClient();
|
|
3
|
+
import { ParaSignerProvider, useParaSigner } from '@miden-sdk/use-miden-para-react';
|
|
4
|
+
import { MidenProvider, useSigner, useMiden } from '@miden-sdk/react';
|
|
8
5
|
|
|
9
6
|
function App() {
|
|
10
7
|
return (
|
|
11
|
-
<
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
>
|
|
8
|
+
<ParaSignerProvider
|
|
9
|
+
apiKey={import.meta.env.VITE_PARA_API_KEY}
|
|
10
|
+
environment="BETA"
|
|
11
|
+
appName="Starter for MidenxPara"
|
|
12
|
+
>
|
|
13
|
+
<MidenProvider config={{ rpcUrl: 'testnet' }}>
|
|
18
14
|
<Content />
|
|
19
|
-
</
|
|
20
|
-
</
|
|
15
|
+
</MidenProvider>
|
|
16
|
+
</ParaSignerProvider>
|
|
21
17
|
);
|
|
22
18
|
}
|
|
23
19
|
|
|
24
20
|
function Content() {
|
|
25
|
-
const
|
|
26
|
-
|
|
27
|
-
);
|
|
28
|
-
|
|
29
|
-
const
|
|
21
|
+
const signer = useSigner();
|
|
22
|
+
const { wallet } = useParaSigner();
|
|
23
|
+
const { isReady, signerAccountId } = useMiden();
|
|
24
|
+
|
|
25
|
+
const handleConnect = async () => {
|
|
26
|
+
if (signer?.isConnected) {
|
|
27
|
+
await signer.disconnect();
|
|
28
|
+
} else {
|
|
29
|
+
await signer?.connect();
|
|
30
|
+
}
|
|
31
|
+
};
|
|
30
32
|
|
|
31
33
|
return (
|
|
32
34
|
<div>
|
|
33
|
-
<button onClick={
|
|
34
|
-
{isConnected ? 'Disconnect Para' : 'Connect with Para'}
|
|
35
|
+
<button onClick={handleConnect}>
|
|
36
|
+
{signer?.isConnected ? 'Disconnect Para' : 'Connect with Para'}
|
|
35
37
|
</button>
|
|
36
|
-
{isConnected && (
|
|
38
|
+
{signer?.isConnected && (
|
|
37
39
|
<>
|
|
38
|
-
<p>
|
|
39
|
-
<p>
|
|
40
|
+
<p>Wallet: {wallet?.address ?? '—'}</p>
|
|
41
|
+
<p>Account: {signerAccountId ?? '—'}</p>
|
|
42
|
+
<p>Client ready: {isReady ? 'yes' : 'no'}</p>
|
|
40
43
|
</>
|
|
41
44
|
)}
|
|
42
45
|
</div>
|
package/template/vite.config.ts
CHANGED
|
@@ -3,19 +3,37 @@ import react from '@vitejs/plugin-react';
|
|
|
3
3
|
import { nodePolyfills } from 'vite-plugin-node-polyfills';
|
|
4
4
|
import wasm from 'vite-plugin-wasm';
|
|
5
5
|
import topLevelAwait from 'vite-plugin-top-level-await';
|
|
6
|
-
import path from 'path';
|
|
7
|
-
import { fileURLToPath } from 'url';
|
|
8
6
|
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
'
|
|
13
|
-
'
|
|
14
|
-
|
|
7
|
+
// Optional connector families that are never imported by the starter template.
|
|
8
|
+
// Alias them to an empty module so Vite doesn't try to resolve their deps.
|
|
9
|
+
const optionalPackages = [
|
|
10
|
+
'@getpara/solana-wallet-connectors',
|
|
11
|
+
'@getpara/cosmos-wallet-connectors',
|
|
12
|
+
'@getpara/wagmi-v2-connector',
|
|
13
|
+
'wagmi',
|
|
14
|
+
'@wagmi/core',
|
|
15
|
+
'@wagmi/connectors',
|
|
16
|
+
];
|
|
17
|
+
|
|
18
|
+
// Mark any import whose bare specifier starts with an optional package
|
|
19
|
+
// (including subpath imports like "wagmi/connectors") as external so
|
|
20
|
+
// Rollup skips them entirely. These code paths are never reached at runtime.
|
|
21
|
+
function externalizeOptionalPackages() {
|
|
22
|
+
return {
|
|
23
|
+
name: 'externalize-optional-packages',
|
|
24
|
+
enforce: 'pre' as const,
|
|
25
|
+
resolveId(id: string) {
|
|
26
|
+
if (optionalPackages.some((pkg) => id === pkg || id.startsWith(pkg + '/'))) {
|
|
27
|
+
return { id, external: true };
|
|
28
|
+
}
|
|
29
|
+
},
|
|
30
|
+
};
|
|
31
|
+
}
|
|
15
32
|
|
|
16
33
|
// Keep the miden SDK unbundled so its WASM asset path stays valid in dev.
|
|
17
34
|
export default defineConfig({
|
|
18
35
|
plugins: [
|
|
36
|
+
externalizeOptionalPackages(),
|
|
19
37
|
wasm(),
|
|
20
38
|
topLevelAwait(),
|
|
21
39
|
react(),
|
|
@@ -28,8 +46,7 @@ export default defineConfig({
|
|
|
28
46
|
// to prevent multiple runtimes in dev.
|
|
29
47
|
exclude: [
|
|
30
48
|
'@miden-sdk/miden-sdk',
|
|
31
|
-
|
|
32
|
-
'@getpara/cosmos-wallet-connectors',
|
|
49
|
+
...optionalPackages,
|
|
33
50
|
],
|
|
34
51
|
esbuildOptions: {
|
|
35
52
|
target: 'esnext',
|
|
@@ -37,22 +54,12 @@ export default defineConfig({
|
|
|
37
54
|
},
|
|
38
55
|
build: {
|
|
39
56
|
target: 'esnext',
|
|
40
|
-
rollupOptions: {
|
|
41
|
-
external: [
|
|
42
|
-
'@getpara/solana-wallet-connectors',
|
|
43
|
-
'@getpara/cosmos-wallet-connectors',
|
|
44
|
-
],
|
|
45
|
-
},
|
|
46
57
|
},
|
|
47
58
|
worker: {
|
|
48
59
|
format: 'es',
|
|
49
60
|
},
|
|
50
61
|
resolve: {
|
|
51
|
-
dedupe: ['@getpara/web-sdk', '@getpara/react-sdk-lite'],
|
|
52
|
-
alias: {
|
|
53
|
-
'@getpara/solana-wallet-connectors': optionalConnectorsPath,
|
|
54
|
-
'@getpara/cosmos-wallet-connectors': optionalConnectorsPath,
|
|
55
|
-
},
|
|
62
|
+
dedupe: ['@getpara/web-sdk', '@getpara/react-sdk-lite', 'react', 'react-dom'],
|
|
56
63
|
},
|
|
57
64
|
// Ensure Vite treats wasm as a static asset with the correct MIME type.
|
|
58
65
|
assetsInclude: ['**/*.wasm'],
|