@miden-sdk/vite-plugin 0.13.3 → 0.14.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.
@@ -0,0 +1,19 @@
1
+ import { Plugin } from 'vite';
2
+
3
+ interface MidenVitePluginOptions {
4
+ /** Packages to deduplicate. Default: ["@miden-sdk/miden-sdk"] */
5
+ wasmPackages?: string[];
6
+ /**
7
+ * Enable COOP/COEP headers on dev server for SharedArrayBuffer support.
8
+ * Default: false — enabling this breaks OAuth popup flows (e.g. Para)
9
+ * because `same-origin` COOP nullifies `window.opener` in popups.
10
+ */
11
+ crossOriginIsolation?: boolean;
12
+ /** gRPC-web proxy target URL. Default: "https://rpc.testnet.miden.io". Set to false to disable. */
13
+ rpcProxyTarget?: string | false;
14
+ /** gRPC-web proxy path prefix. Default: "/rpc.Api" */
15
+ rpcProxyPath?: string;
16
+ }
17
+ declare function midenVitePlugin(options?: MidenVitePluginOptions): Plugin;
18
+
19
+ export { type MidenVitePluginOptions, midenVitePlugin as default, midenVitePlugin };
@@ -0,0 +1,19 @@
1
+ import { Plugin } from 'vite';
2
+
3
+ interface MidenVitePluginOptions {
4
+ /** Packages to deduplicate. Default: ["@miden-sdk/miden-sdk"] */
5
+ wasmPackages?: string[];
6
+ /**
7
+ * Enable COOP/COEP headers on dev server for SharedArrayBuffer support.
8
+ * Default: false — enabling this breaks OAuth popup flows (e.g. Para)
9
+ * because `same-origin` COOP nullifies `window.opener` in popups.
10
+ */
11
+ crossOriginIsolation?: boolean;
12
+ /** gRPC-web proxy target URL. Default: "https://rpc.testnet.miden.io". Set to false to disable. */
13
+ rpcProxyTarget?: string | false;
14
+ /** gRPC-web proxy path prefix. Default: "/rpc.Api" */
15
+ rpcProxyPath?: string;
16
+ }
17
+ declare function midenVitePlugin(options?: MidenVitePluginOptions): Plugin;
18
+
19
+ export { type MidenVitePluginOptions, midenVitePlugin as default, midenVitePlugin };
package/dist/index.js ADDED
@@ -0,0 +1,150 @@
1
+ "use strict";
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __export = (target, all) => {
9
+ for (var name in all)
10
+ __defProp(target, name, { get: all[name], enumerable: true });
11
+ };
12
+ var __copyProps = (to, from, except, desc) => {
13
+ if (from && typeof from === "object" || typeof from === "function") {
14
+ for (let key of __getOwnPropNames(from))
15
+ if (!__hasOwnProp.call(to, key) && key !== except)
16
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
+ }
18
+ return to;
19
+ };
20
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
+ // If the importer is in node compatibility mode or this is not an ESM
22
+ // file that has been converted to a CommonJS file using a Babel-
23
+ // compatible transform (i.e. "__esModule" has not been set), then set
24
+ // "default" to the CommonJS "module.exports" for node compatibility.
25
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
+ mod
27
+ ));
28
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
+
30
+ // src/index.ts
31
+ var index_exports = {};
32
+ __export(index_exports, {
33
+ default: () => index_default,
34
+ midenVitePlugin: () => midenVitePlugin
35
+ });
36
+ module.exports = __toCommonJS(index_exports);
37
+ var import_path = __toESM(require("path"));
38
+ var import_node_module = require("module");
39
+ var externalizeMidenReact = {
40
+ name: "externalize-miden-react",
41
+ setup(build) {
42
+ build.onResolve({ filter: /^@miden-sdk\/react$/ }, () => ({
43
+ path: "@miden-sdk/react",
44
+ external: true
45
+ }));
46
+ }
47
+ };
48
+ function midenVitePlugin(options) {
49
+ const {
50
+ wasmPackages = ["@miden-sdk/miden-sdk"],
51
+ crossOriginIsolation = false,
52
+ rpcProxyTarget = "https://rpc.testnet.miden.io",
53
+ rpcProxyPath = "/rpc.Api"
54
+ } = options ?? {};
55
+ const requiredDedupe = [
56
+ "react",
57
+ "react-dom",
58
+ "react/jsx-runtime",
59
+ "@miden-sdk/react"
60
+ ];
61
+ return {
62
+ name: "@miden-sdk/vite-plugin",
63
+ enforce: "pre",
64
+ config(userConfig, env) {
65
+ const root = userConfig.root ?? process.cwd();
66
+ const esmRequire = (0, import_node_module.createRequire)(`file://${root}/`);
67
+ const alias = wasmPackages.map((pkg) => {
68
+ let replacement;
69
+ try {
70
+ replacement = import_path.default.dirname(esmRequire.resolve(`${pkg}/package.json`));
71
+ } catch {
72
+ replacement = import_path.default.resolve(root, "node_modules", pkg);
73
+ }
74
+ return { find: pkg, replacement };
75
+ });
76
+ const serverConfig = {};
77
+ const previewConfig = {};
78
+ if (crossOriginIsolation) {
79
+ const coopCoepHeaders = {
80
+ "Cross-Origin-Opener-Policy": "same-origin",
81
+ "Cross-Origin-Embedder-Policy": "require-corp"
82
+ };
83
+ serverConfig.headers = coopCoepHeaders;
84
+ previewConfig.headers = coopCoepHeaders;
85
+ }
86
+ if (rpcProxyTarget !== false && env.command === "serve") {
87
+ serverConfig.proxy = {
88
+ [rpcProxyPath]: {
89
+ target: rpcProxyTarget,
90
+ changeOrigin: true
91
+ }
92
+ };
93
+ }
94
+ return {
95
+ resolve: {
96
+ alias,
97
+ dedupe: [...wasmPackages, ...requiredDedupe],
98
+ preserveSymlinks: true
99
+ },
100
+ optimizeDeps: {
101
+ exclude: [...wasmPackages]
102
+ },
103
+ build: {
104
+ target: "esnext"
105
+ },
106
+ worker: {
107
+ format: "es",
108
+ rollupOptions: { output: { format: "es" } }
109
+ },
110
+ server: serverConfig,
111
+ preview: previewConfig
112
+ };
113
+ },
114
+ // Use configResolved to inject the esbuild externalization plugin and
115
+ // dedupe entries into the final resolved config. This runs AFTER all
116
+ // plugins' config() hooks have been merged, so other plugins (e.g.
117
+ // vite-plugin-node-polyfills) can't overwrite these entries.
118
+ configResolved(config) {
119
+ if (!config.optimizeDeps.esbuildOptions) {
120
+ config.optimizeDeps.esbuildOptions = {};
121
+ }
122
+ const esbuildOpts = config.optimizeDeps.esbuildOptions;
123
+ if (!esbuildOpts.plugins) {
124
+ esbuildOpts.plugins = [];
125
+ }
126
+ const hasPlugin = esbuildOpts.plugins.some(
127
+ (p) => p.name === "externalize-miden-react"
128
+ );
129
+ if (!hasPlugin) {
130
+ esbuildOpts.plugins.push(externalizeMidenReact);
131
+ }
132
+ if (!esbuildOpts.target) {
133
+ esbuildOpts.target = "esnext";
134
+ }
135
+ if (!config.resolve.dedupe) {
136
+ config.resolve.dedupe = [];
137
+ }
138
+ for (const dep of requiredDedupe) {
139
+ if (!config.resolve.dedupe.includes(dep)) {
140
+ config.resolve.dedupe.push(dep);
141
+ }
142
+ }
143
+ }
144
+ };
145
+ }
146
+ var index_default = midenVitePlugin;
147
+ // Annotate the CommonJS export names for ESM import in node:
148
+ 0 && (module.exports = {
149
+ midenVitePlugin
150
+ });
package/dist/index.mjs ADDED
@@ -0,0 +1,115 @@
1
+ // src/index.ts
2
+ import path from "path";
3
+ import { createRequire } from "module";
4
+ var externalizeMidenReact = {
5
+ name: "externalize-miden-react",
6
+ setup(build) {
7
+ build.onResolve({ filter: /^@miden-sdk\/react$/ }, () => ({
8
+ path: "@miden-sdk/react",
9
+ external: true
10
+ }));
11
+ }
12
+ };
13
+ function midenVitePlugin(options) {
14
+ const {
15
+ wasmPackages = ["@miden-sdk/miden-sdk"],
16
+ crossOriginIsolation = false,
17
+ rpcProxyTarget = "https://rpc.testnet.miden.io",
18
+ rpcProxyPath = "/rpc.Api"
19
+ } = options ?? {};
20
+ const requiredDedupe = [
21
+ "react",
22
+ "react-dom",
23
+ "react/jsx-runtime",
24
+ "@miden-sdk/react"
25
+ ];
26
+ return {
27
+ name: "@miden-sdk/vite-plugin",
28
+ enforce: "pre",
29
+ config(userConfig, env) {
30
+ const root = userConfig.root ?? process.cwd();
31
+ const esmRequire = createRequire(`file://${root}/`);
32
+ const alias = wasmPackages.map((pkg) => {
33
+ let replacement;
34
+ try {
35
+ replacement = path.dirname(esmRequire.resolve(`${pkg}/package.json`));
36
+ } catch {
37
+ replacement = path.resolve(root, "node_modules", pkg);
38
+ }
39
+ return { find: pkg, replacement };
40
+ });
41
+ const serverConfig = {};
42
+ const previewConfig = {};
43
+ if (crossOriginIsolation) {
44
+ const coopCoepHeaders = {
45
+ "Cross-Origin-Opener-Policy": "same-origin",
46
+ "Cross-Origin-Embedder-Policy": "require-corp"
47
+ };
48
+ serverConfig.headers = coopCoepHeaders;
49
+ previewConfig.headers = coopCoepHeaders;
50
+ }
51
+ if (rpcProxyTarget !== false && env.command === "serve") {
52
+ serverConfig.proxy = {
53
+ [rpcProxyPath]: {
54
+ target: rpcProxyTarget,
55
+ changeOrigin: true
56
+ }
57
+ };
58
+ }
59
+ return {
60
+ resolve: {
61
+ alias,
62
+ dedupe: [...wasmPackages, ...requiredDedupe],
63
+ preserveSymlinks: true
64
+ },
65
+ optimizeDeps: {
66
+ exclude: [...wasmPackages]
67
+ },
68
+ build: {
69
+ target: "esnext"
70
+ },
71
+ worker: {
72
+ format: "es",
73
+ rollupOptions: { output: { format: "es" } }
74
+ },
75
+ server: serverConfig,
76
+ preview: previewConfig
77
+ };
78
+ },
79
+ // Use configResolved to inject the esbuild externalization plugin and
80
+ // dedupe entries into the final resolved config. This runs AFTER all
81
+ // plugins' config() hooks have been merged, so other plugins (e.g.
82
+ // vite-plugin-node-polyfills) can't overwrite these entries.
83
+ configResolved(config) {
84
+ if (!config.optimizeDeps.esbuildOptions) {
85
+ config.optimizeDeps.esbuildOptions = {};
86
+ }
87
+ const esbuildOpts = config.optimizeDeps.esbuildOptions;
88
+ if (!esbuildOpts.plugins) {
89
+ esbuildOpts.plugins = [];
90
+ }
91
+ const hasPlugin = esbuildOpts.plugins.some(
92
+ (p) => p.name === "externalize-miden-react"
93
+ );
94
+ if (!hasPlugin) {
95
+ esbuildOpts.plugins.push(externalizeMidenReact);
96
+ }
97
+ if (!esbuildOpts.target) {
98
+ esbuildOpts.target = "esnext";
99
+ }
100
+ if (!config.resolve.dedupe) {
101
+ config.resolve.dedupe = [];
102
+ }
103
+ for (const dep of requiredDedupe) {
104
+ if (!config.resolve.dedupe.includes(dep)) {
105
+ config.resolve.dedupe.push(dep);
106
+ }
107
+ }
108
+ }
109
+ };
110
+ }
111
+ var index_default = midenVitePlugin;
112
+ export {
113
+ index_default as default,
114
+ midenVitePlugin
115
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@miden-sdk/vite-plugin",
3
- "version": "0.13.3",
3
+ "version": "0.14.2",
4
4
  "description": "Vite plugin for Miden dApps — WASM dedup, COOP/COEP headers, and gRPC-web proxy",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.mjs",