@waynevanson/vite-plugin-cargo 1.0.0 → 3.0.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 CHANGED
@@ -5,6 +5,7 @@ A Vite plugin that seamlessly integrates Rust crates into your frontend project
5
5
  ## Features
6
6
 
7
7
  - **Zero-Config Compiling**: Automatically detects the closest `Cargo.toml`.
8
+ - **Watch mode**: Watches dependencies related to the entrypoint.
8
9
  - **WASM-Bindgen Integration**: Generates the necessary JS glue code automatically.
9
10
  - **TypeScript Support**: Automatically generates and syncs `.d.ts` files for your Rust exports.
10
11
  - **HMR Support**: Works with Vite's dev server.
@@ -21,7 +22,7 @@ You must have the following installed on your system:
21
22
  ## Installation
22
23
 
23
24
  ```bash
24
- npm install vite-plugin-cargo --save-dev
25
+ npm install @waynevanson/vite-plugin-cargo --save-dev
25
26
 
26
27
  ```
27
28
 
@@ -38,7 +39,8 @@ import { cargo } from "vite-plugin-cargo";
38
39
  export default defineConfig({
39
40
  plugins: [
40
41
  cargo({
41
- includes: ["src/lib.rs"], // Files to treat as Cargo entrypoints
42
+ // Files to treat as Cargo entrypoints
43
+ includes: ["**/src/lib.rs"],
42
44
  }),
43
45
  ],
44
46
  });
@@ -88,11 +90,12 @@ console.log(greet("Vite"));
88
90
 
89
91
  ### Base Configuration
90
92
 
91
- | Option | Type | Description |
92
- | :------------- | :-------- | :----------------------------------------------- |
93
- | `includes` | `string | string[]` Glob pattern of Rust files to process. |
94
- | `browserOnly` | `boolean` | (Optional) Passes `--browser` to `wasm-bindgen`. |
95
- | `noTypescript` | `boolean` | (Optional) Disables `.d.ts` generation. |
93
+ | Option | Type | Description |
94
+ | :-------------------- | :--------------------------------------- | :----------------------------------------------- |
95
+ | `includes` | `string \| string[]` | Glob patterns of possible entry points. |
96
+ | `browserOnly` | `boolean` | (Optional) Passes `--browser` to `wasm-bindgen`. |
97
+ | `noTypescript` | `boolean` | (Optional) Disables `.d.ts` generation. |
98
+ | `cargoBuildOverrides` | `(args: Array<string>) => Array<string>` | (Optional) Override args to `cargo build`. |
96
99
 
97
100
  ### Rust Features
98
101
 
package/dist/index.d.ts CHANGED
@@ -1,13 +1,81 @@
1
- import picomatch from "picomatch";
2
- import type { Plugin } from "vite";
3
- export type VitePluginCargoOptions = {
4
- includes: picomatch.Glob;
5
- browserOnly?: boolean;
6
- noTypescript?: boolean;
7
- } & ({
8
- noDefaultFeatures?: boolean;
9
- features?: Array<string>;
10
- } | {
11
- allFeatures: true;
12
- });
13
- export declare function cargo(pluginOptions: VitePluginCargoOptions): Plugin<never>;
1
+ import { Plugin as Plugin_2 } from 'vite';
2
+ import { StringFilter } from 'rollup';
3
+ import * as v from 'valibot';
4
+
5
+ export declare function buildWasmBindgen(options: VitePluginCargoOptionsInternal, context: PluginContext, library: LibraryContextRustBuild): void;
6
+
7
+ export declare function cargo(pluginOptions_: VitePluginCargoOptions): Plugin_2<never>;
8
+
9
+ export declare interface Library {
10
+ id: string;
11
+ outDir: LibraryDir;
12
+ }
13
+
14
+ declare type LibraryContextBase = {
15
+ id: string;
16
+ project: string;
17
+ };
18
+
19
+ declare type LibraryContextRustBuild = LibraryContextBase & {
20
+ outDir: string;
21
+ wasm: string;
22
+ };
23
+
24
+ declare type LibraryDir = string;
25
+
26
+ export declare interface PluginContext {
27
+ isServe: boolean;
28
+ libraries: Map<string, Library>;
29
+ }
30
+
31
+ declare type VitePluginCargoOptions = v.InferInput<typeof VitePluginCargoOptionsSchema>;
32
+
33
+ declare type VitePluginCargoOptionsInternal = v.InferOutput<typeof VitePluginCargoOptionsSchema>;
34
+
35
+ declare const VitePluginCargoOptionsSchema: v.IntersectSchema<[v.SchemaWithPipe<readonly [v.ObjectSchema<{
36
+ readonly pattern: v.GenericSchema<StringFilter>;
37
+ readonly noTypescript: v.OptionalSchema<v.BooleanSchema<undefined>, false>;
38
+ readonly browserOnly: v.OptionalSchema<v.BooleanSchema<undefined>, false>;
39
+ readonly cargoBuildOverrides: v.OptionalSchema<v.SchemaWithPipe<readonly [v.FunctionSchema<undefined>, v.ArgsAction<(...args: unknown[]) => unknown, v.StrictTupleSchema<[v.ArraySchema<v.StringSchema<undefined>, undefined>], undefined>>, v.ReturnsAction<(args_0: string[]) => unknown, v.ArraySchema<v.StringSchema<undefined>, undefined>>]>, undefined>;
40
+ }, undefined>, v.TransformAction<{
41
+ pattern: StringFilter;
42
+ noTypescript: boolean;
43
+ browserOnly: boolean;
44
+ cargoBuildOverrides?: ((args_0: string[]) => string[]) | undefined;
45
+ }, {
46
+ typescript: boolean;
47
+ browserless: boolean;
48
+ pattern: StringFilter;
49
+ cargoBuildOverrides: ((args_0: string[]) => string[]) | undefined;
50
+ }>]>, v.SchemaWithPipe<readonly [v.UnionSchema<[v.ObjectSchema<{
51
+ readonly allFeatures: v.LiteralSchema<true, undefined>;
52
+ }, undefined>, v.SchemaWithPipe<readonly [v.ObjectSchema<{
53
+ readonly features: v.OptionalSchema<v.ArraySchema<v.StringSchema<undefined>, undefined>, undefined>;
54
+ readonly noDefaultFeatures: v.OptionalSchema<v.BooleanSchema<undefined>, false>;
55
+ }, undefined>, v.TransformAction<{
56
+ features?: string[] | undefined;
57
+ noDefaultFeatures: boolean;
58
+ }, {
59
+ possibleFeatures: {
60
+ features?: string[] | undefined;
61
+ noDefaultFeatures: boolean;
62
+ };
63
+ }>]>], undefined>, v.TransformAction<{
64
+ allFeatures: true;
65
+ } | {
66
+ possibleFeatures: {
67
+ features?: string[] | undefined;
68
+ noDefaultFeatures: boolean;
69
+ };
70
+ }, {
71
+ features: {
72
+ allFeatures: true;
73
+ } | {
74
+ possibleFeatures: {
75
+ features?: string[] | undefined;
76
+ noDefaultFeatures: boolean;
77
+ };
78
+ };
79
+ }>]>], undefined>;
80
+
81
+ export { }
package/dist/index.js CHANGED
@@ -1,140 +1,289 @@
1
- import { execFileSync } from "node:child_process";
2
- import { createHash } from "node:crypto";
3
- import path from "node:path";
4
- import picomatch from "picomatch";
5
- import * as v from "valibot";
6
- // todo: Replace all schema with only parsing what we need to searching.
7
- const MetadataSchema = (options) => v.nonNullish(v.pipe(v.object({
8
- packages: v.array(v.pipe(v.object({
9
- manifest_path: v.string(),
10
- targets: v.array(v.object({
11
- kind: v.array(v.string()),
12
- name: v.string(),
13
- src_path: v.string(),
14
- })),
15
- }), v.transform((package_) => package_.targets.flatMap((target) => target.kind.flatMap((kind) => ({
16
- manifest_path: package_.manifest_path,
17
- ...target,
18
- kind,
19
- })))))),
20
- }), v.transform((packages) => packages.packages.flat()), v.findItem((metadata) => v.is(v.object({
21
- manifest_path: v.literal(options.project),
22
- name: v.string(),
23
- src_path: v.literal(options.id),
24
- kind: v.literal("cdylib"),
25
- }), metadata))));
26
- function getClosestCargoProject(id) {
27
- return execFileSync("cargo", ["locate-project", "--message-format=plain"], {
28
- stdio: ["ignore", "pipe", "ignore"],
29
- encoding: "utf-8",
30
- cwd: path.dirname(id),
31
- }).trim();
1
+ import { execFileSync as f } from "node:child_process";
2
+ import * as x from "node:path";
3
+ import l from "node:path";
4
+ import * as t from "/home/waynevanson/code/waynevanson/vite-plugin-cargo/node_modules/.pnpm/valibot@1.2.0_typescript@5.9.3/node_modules/valibot/dist/index.mjs";
5
+ import { createDebug as D } from "/home/waynevanson/code/waynevanson/vite-plugin-cargo/node_modules/.pnpm/obug@2.1.1/node_modules/obug/dist/browser.js";
6
+ import * as F from "node:crypto";
7
+ async function E(e, n) {
8
+ const r = e.filter((u) => u?.reason === "compiler-artifact").filter((u) => u?.manifest_path === n.project)?.[0], a = r.target.name, o = r?.filenames?.[0], i = l.resolve(
9
+ o,
10
+ "../deps",
11
+ `${a}.d`
12
+ ), s = await this.fs.readFile(i, {
13
+ encoding: "utf8"
14
+ }), d = B(s), p = l.resolve(
15
+ o,
16
+ "../deps",
17
+ `${a}.wasm`
18
+ ), m = $(p, d);
19
+ return { wasmFilename: o, neighbours: m };
32
20
  }
33
- // todo: what to do there's multiple libraries for the same file?
34
- // Maybe add config force user to resolve this.
35
- function ensureRustLibraryMetadata(options) {
36
- // validate if the file is the entrypoint to a cdylib target as rust lib
37
- const metacontent = execFileSync("cargo", ["metadata", "--no-deps", "--format-version=1"], {
38
- cwd: path.dirname(options.id),
39
- encoding: "utf-8",
40
- }).trim();
41
- // find the right library from our file
42
- const metadata = v.parse(MetadataSchema(options), JSON.parse(metacontent));
43
- return metadata;
21
+ function B(e) {
22
+ return new Map(
23
+ e.split(`
24
+ `).filter(Boolean).map((n) => {
25
+ const [r, a] = n.split(": ");
26
+ return [
27
+ l.resolve(r),
28
+ new Set(a?.split(" ").map((o) => l.resolve(o)) ?? [])
29
+ ];
30
+ })
31
+ );
44
32
  }
45
- function compileLibrary(options, isServe) {
46
- // create `.wasm` from `.rs`
47
- const ndjson = execFileSync("cargo", [
48
- "build",
49
- "--lib",
50
- "--target=wasm32-unknown-unknown",
51
- "--message-format=json",
52
- "--color=never",
53
- "--quiet",
54
- isServe || "--release",
55
- ].filter((a) => typeof a === "string"), {
56
- cwd: path.dirname(options.id),
57
- encoding: "utf-8",
58
- stdio: ["ignore", "pipe", "ignore"],
59
- });
60
- const json = ndjson
61
- .trim()
62
- .split("\n")
63
- .map((json) => JSON.parse(json));
64
- // find the `.wasm` file
65
- const filename = json
66
- .filter((a) => a?.reason === "compiler-artifact")
67
- .filter((a) => a?.manifest_path === options.project)[0]?.filenames?.[0];
68
- return filename;
33
+ function $(e, n) {
34
+ const r = /* @__PURE__ */ new Set(), a = n.get(e);
35
+ if (a === void 0)
36
+ throw new Error("Expect the start value to exist in the dependency graph");
37
+ const o = new Set(a);
38
+ for (; o.size > 0; )
39
+ for (const i of o) {
40
+ r.add(i), o.delete(i);
41
+ const d = (n.get(i) ?? /* @__PURE__ */ new Set()).difference(r);
42
+ for (const p of d)
43
+ o.add(p);
44
+ }
45
+ return r;
69
46
  }
70
- // 1. Plugin for Rust -> WASM -> WASM + ESM
71
- // Dependencies:
72
- // 1. `cargo`
73
- // 2. `wasm_bindgen`
74
- export function cargo(pluginOptions) {
75
- const matches = picomatch(pluginOptions.includes, { contains: true });
76
- const typescript = !(pluginOptions?.noTypescript ?? false);
77
- let isServe = false;
78
- const libraries = new Map();
79
- return {
80
- name: "vite-plugin-cargo",
81
- configResolved(config) {
82
- isServe = config.command === "serve";
83
- },
84
- async resolveId(source, importer) {
85
- // check if this import came from one of our entrypoints
86
- const entry = libraries
87
- .values()
88
- .find((library) => library.id === importer);
89
- if (entry === undefined) {
90
- return null;
91
- }
92
- // ensure source is relative to wasm_bindgen output dir
93
- return path.resolve(entry.outDir, source);
94
- },
95
- async transform(_code, id) {
96
- if (!matches(id)) {
97
- return null;
98
- }
99
- const project = getClosestCargoProject(id);
100
- const options = { id, project };
101
- const metadata = ensureRustLibraryMetadata(options);
102
- const hash = createHash("sha256")
103
- .update(`${project}:${id}`)
104
- .digest("hex");
105
- const outDir = path.resolve(`node_modules/.cache/vite-plugin-cargo/${hash}`);
106
- libraries.set(hash, { id, outDir, project });
107
- const wasm = compileLibrary(options, isServe);
108
- // create `.js` from `.wasm`
109
- //
110
- // `.js` and `.wasm` files are created in outDir,
111
- // and added to dependency graph from imports in the `.js` entrypoint.
112
- execFileSync("wasm-bindgen", [
113
- "--target=bundler",
114
- `--out-dir=${outDir}`,
115
- isServe && `--debug`,
116
- typescript || `--no-typescript`,
117
- pluginOptions.browserOnly && `--browser`,
118
- wasm,
119
- ].filter((a) => typeof a === "string"));
120
- const entrypoint = path.resolve(outDir, `${metadata.name}.js`);
121
- const content = await this.fs.readFile(entrypoint, { encoding: "utf8" });
122
- // `.d.ts` from `wasm_bindgen` aren't read I believe, so we emit them ourselves.
123
- // todo: only emit the files we load. Currently we assume they're all loaded.
124
- if (typescript) {
125
- // add `.d.ts` to files
126
- const filenames = await this.fs.readdir(outDir);
127
- await Promise.all(filenames
128
- .filter((filename) => filename.endsWith(".d.ts"))
129
- .map(async (filename) => await this.load({ id: path.resolve(outDir, filename) })));
130
- // copy <name>.d.ts to the <id>.d.ts so user gets type definitions
131
- const source = path.join(outDir, `${metadata.name}.d.ts`);
132
- const target = `${id}.d.ts`;
133
- await this.fs.copyFile(source, target);
134
- }
135
- return {
136
- code: content,
137
- };
138
- },
139
- };
47
+ const c = D("vite-plugin-cargo");
48
+ function k(e, n) {
49
+ const r = j(
50
+ e.packages,
51
+ (i) => i.manifest_path === n.project
52
+ );
53
+ if (r === void 0)
54
+ throw new Error(
55
+ `Expected at least 1 package to have the manifest_path of ${n.project}`
56
+ );
57
+ const a = t.object({
58
+ name: t.string(),
59
+ src_path: t.literal(n.id),
60
+ kind: t.tuple([t.literal("cdylib")]),
61
+ crate_types: t.tuple([t.literal("cdylib")])
62
+ }), o = j(
63
+ r?.targets ?? [],
64
+ (i) => t.is(a, i)
65
+ );
66
+ if (o === void 0)
67
+ throw new Error(
68
+ `Expected at least 1 target to match the src_path of ${n.id} and be a cdylib target`
69
+ );
70
+ return {
71
+ libraryName: o.name
72
+ };
140
73
  }
74
+ function j(e, n) {
75
+ let r;
76
+ for (const a of e)
77
+ if (n(a)) {
78
+ if (r !== void 0)
79
+ throw new Error("Found multiple of the same item");
80
+ r = a;
81
+ }
82
+ return r;
83
+ }
84
+ const C = t.object({
85
+ packages: t.array(
86
+ t.object({
87
+ name: t.string(),
88
+ id: t.string(),
89
+ manifest_path: t.string(),
90
+ dependencies: t.array(
91
+ t.object({
92
+ name: t.string(),
93
+ source: t.string(),
94
+ req: t.string(),
95
+ kind: t.nullable(t.string())
96
+ })
97
+ ),
98
+ targets: t.array(
99
+ t.object({
100
+ kind: t.array(t.string()),
101
+ crate_types: t.array(t.string()),
102
+ name: t.string(),
103
+ src_path: t.string()
104
+ })
105
+ )
106
+ })
107
+ )
108
+ });
109
+ function S(e) {
110
+ return typeof e == "string";
111
+ }
112
+ function L(e) {
113
+ const n = ["locate-project", "--message-format=plain"];
114
+ c("cargo %s", n.join(" "));
115
+ const r = f("cargo", n, {
116
+ stdio: ["ignore", "pipe", "ignore"],
117
+ encoding: "utf-8",
118
+ cwd: l.dirname(e)
119
+ }).trim();
120
+ return c("project %o", r), r;
121
+ }
122
+ function N(e) {
123
+ const n = ["metadata", "--no-deps", "--format-version=1"];
124
+ c("cargo %s", n.join(" "));
125
+ const r = f("cargo", n, {
126
+ cwd: l.dirname(e.id),
127
+ encoding: "utf-8"
128
+ }).trim(), a = JSON.parse(r);
129
+ return c("metadata %s", JSON.stringify(a, null, 2)), t.parse(C, a);
130
+ }
131
+ async function P(e, n, r) {
132
+ let a = [
133
+ "build",
134
+ "--lib",
135
+ "--target=wasm32-unknown-unknown",
136
+ "--message-format=json",
137
+ "--color=never",
138
+ "--quiet",
139
+ n || "--release"
140
+ ].filter(S);
141
+ c("cargo-raw-args %s", a.join(" ")), r && (a = r(a), c("cargo-override-args %s", a.join(" ")));
142
+ const o = f("cargo", a, {
143
+ cwd: l.dirname(e.id),
144
+ encoding: "utf-8",
145
+ stdio: ["ignore", "pipe", "ignore"]
146
+ });
147
+ c("artifacts-ndjson %s", o);
148
+ const i = o.trim().split(`
149
+ `).map((s) => JSON.parse(s));
150
+ return c("artifacts %o", i), i;
151
+ }
152
+ const M = "node_modules/.cache/vitest-plugin-cargo";
153
+ function T(e) {
154
+ return F.createHash("sha256").update(`${e.project}:${e.id}`).digest("hex");
155
+ }
156
+ function A(e) {
157
+ if (e.length <= 2)
158
+ throw Error(
159
+ `Expected hash to be a string greater than two but received "${e}"`
160
+ );
161
+ return x.resolve(M, e.slice(0, 2), e.slice(2));
162
+ }
163
+ const b = t.optional(t.boolean(), !1), J = t.pipe(
164
+ t.union([
165
+ t.object({ allFeatures: t.literal(!0) }),
166
+ t.pipe(
167
+ t.object({
168
+ features: t.optional(t.array(t.string())),
169
+ noDefaultFeatures: b
170
+ }),
171
+ t.transform((e) => ({ possibleFeatures: e }))
172
+ )
173
+ ]),
174
+ t.transform((e) => ({ features: e }))
175
+ ), g = t.union([t.string(), t.instance(RegExp)]), y = (e) => t.union([e, t.array(e)]), R = t.union([
176
+ g,
177
+ y(g),
178
+ t.object({
179
+ include: t.optional(t.union([y(g)])),
180
+ exclude: t.optional(t.union([y(g)]))
181
+ })
182
+ ]), H = t.pipe(
183
+ t.object({
184
+ pattern: R,
185
+ noTypescript: b,
186
+ browserOnly: b,
187
+ cargoBuildOverrides: t.optional(
188
+ t.pipe(
189
+ t.function(),
190
+ t.args(t.strictTuple([t.array(t.string())])),
191
+ t.returns(t.array(t.string()))
192
+ )
193
+ )
194
+ }),
195
+ t.transform((e) => ({
196
+ typescript: !e.noTypescript,
197
+ browserless: !e.browserOnly,
198
+ pattern: e.pattern,
199
+ cargoBuildOverrides: e.cargoBuildOverrides
200
+ }))
201
+ ), W = t.intersect([
202
+ H,
203
+ J
204
+ ]), q = t.parser(W);
205
+ function X(e) {
206
+ const n = q(e), r = {
207
+ isServe: !1,
208
+ libraries: /* @__PURE__ */ new Map()
209
+ };
210
+ return {
211
+ name: "vite-plugin-cargo",
212
+ configResolved(a) {
213
+ r.isServe = a.command === "serve";
214
+ },
215
+ async resolveId(a, o) {
216
+ const i = r.libraries.values().find((s) => s.id === o)?.outDir;
217
+ return i === void 0 ? null : l.resolve(i, a);
218
+ },
219
+ transform: {
220
+ filter: {
221
+ id: n.pattern
222
+ },
223
+ // todo: throw when importing a non-entry point.
224
+ // todo: consider: way in the future we could enable users to import any rust file
225
+ // and we'll add overrides instead of relying on Cargo.toml for `lib` information.
226
+ async handler(a, o) {
227
+ const i = L(o), s = { id: o, project: i }, d = T(s), p = A(d);
228
+ c("library %s", { hash: d, id: o, outDir: p }), r.libraries.set(d, { id: o, outDir: p });
229
+ const m = N(s), u = k.call(
230
+ this,
231
+ m,
232
+ s
233
+ ), O = await P(
234
+ s,
235
+ r.isServe,
236
+ n.cargoBuildOverrides
237
+ ), h = await E.call(
238
+ this,
239
+ O,
240
+ s
241
+ );
242
+ c("watching-dependencies %s", h.neighbours);
243
+ for (const _ of h.neighbours)
244
+ this.addWatchFile(_);
245
+ const w = {
246
+ id: o,
247
+ outDir: p,
248
+ project: i,
249
+ wasm: h.wasmFilename
250
+ };
251
+ z(n, r, w);
252
+ const v = {
253
+ ...w,
254
+ name: u.libraryName
255
+ };
256
+ return n.typescript && await V.call(this, v), { code: await I.call(
257
+ this,
258
+ v
259
+ ) };
260
+ }
261
+ }
262
+ };
263
+ }
264
+ async function I(e) {
265
+ const n = l.resolve(e.outDir, `${e.name}.js`);
266
+ return await this.fs.readFile(n, {
267
+ encoding: "utf8"
268
+ });
269
+ }
270
+ async function V(e) {
271
+ const n = l.join(e.outDir, `${e.name}.d.ts`), r = `${e.id}.d.ts`;
272
+ await this.fs.copyFile(n, r);
273
+ }
274
+ function z(e, n, r) {
275
+ const a = [
276
+ "--target=bundler",
277
+ e.typescript || "--no-typescript",
278
+ e.browserless || "--browser",
279
+ n.isServe && "--debug",
280
+ `--out-dir=${r.outDir}`,
281
+ r.wasm
282
+ ].filter(S);
283
+ c("wasm-bindgen %s", a.join(" ")), f("wasm-bindgen", a);
284
+ }
285
+ export {
286
+ z as buildWasmBindgen,
287
+ X as cargo
288
+ };
289
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sources":["../src/artifacts.ts","../src/debug.ts","../src/metadata.ts","../src/utils.ts","../src/cargo.ts","../src/constants.ts","../src/library.ts","../src/plugin-options.ts","../src/index.ts"],"sourcesContent":["import path from \"node:path\";\nimport type { TransformPluginContext } from \"rollup\";\nimport type { LibraryContextBase } from \"./library\";\n\nexport async function deriveLibraryArtifact(\n\tthis: TransformPluginContext,\n\tartifacts: Array<any>,\n\toptions: LibraryContextBase,\n) {\n\t// todo: validation and error messages\n\tconst artifact = artifacts\n\t\t.filter((a) => a?.reason === \"compiler-artifact\")\n\t\t.filter((a) => a?.manifest_path === options.project)?.[0];\n\n\t// todo: hold paths here\n\tconst libraryName = artifact.target.name;\n\tconst wasmFilename: string = artifact?.filenames?.[0];\n\n\tconst dependencyFilepath = path.resolve(\n\t\twasmFilename,\n\t\t\"../deps\",\n\t\t`${libraryName}.d`,\n\t);\n\n\tconst dependencies = await this.fs.readFile(dependencyFilepath, {\n\t\tencoding: \"utf8\",\n\t});\n\n\tconst graph = createGraphFromDependencies(dependencies);\n\n\tconst neighboursEntry = path.resolve(\n\t\twasmFilename,\n\t\t\"../deps\",\n\t\t`${libraryName}.wasm`,\n\t);\n\n\tconst neighbours = findAllDescendants(neighboursEntry, graph);\n\n\treturn { wasmFilename, neighbours };\n}\n\nexport function createGraphFromDependencies(contents: string) {\n\treturn new Map(\n\t\tcontents\n\t\t\t.split(\"\\n\")\n\t\t\t.filter(Boolean)\n\t\t\t.map((line) => {\n\t\t\t\tconst [source, targets] = line.split(\": \");\n\t\t\t\treturn [\n\t\t\t\t\tpath.resolve(source),\n\t\t\t\t\tnew Set(targets?.split(\" \").map((a) => path.resolve(a)) ?? []),\n\t\t\t\t] as const;\n\t\t\t}),\n\t);\n}\n\nfunction findAllDescendants(start: string, graph: Map<string, Set<string>>) {\n\tconst collecteds = new Set<string>();\n\tconst initials = graph.get(start);\n\n\tif (initials === undefined) {\n\t\tthrow new Error(`Expect the start value to exist in the dependency graph`);\n\t}\n\n\tconst sources = new Set<string>(initials);\n\n\twhile (sources.size > 0) {\n\t\tfor (const source of sources) {\n\t\t\t// move from sources into collected\n\t\t\tcollecteds.add(source);\n\t\t\tsources.delete(source);\n\n\t\t\tconst targets = graph.get(source) ?? new Set();\n\n\t\t\t// filter out targets that may have been traversed\n\t\t\tconst uncollecteds = targets.difference(collecteds);\n\n\t\t\t// queue files to be collected\n\t\t\tfor (const uncollected of uncollecteds) {\n\t\t\t\tsources.add(uncollected);\n\t\t\t}\n\t\t}\n\t}\n\n\treturn collecteds;\n}\n","import { createDebug } from \"obug\";\n\n// I hate this. Maybe use pino? It's for me and not anyone else\nexport const debug = createDebug(\"vite-plugin-cargo\");\n","import type { TransformPluginContext } from \"rollup\";\nimport * as v from \"valibot\";\nimport type { MetadaSchemaOptions } from \"./types\";\n\n// this seems like a lot of work just to get the library name out of the metadata..\n// I think it's more validation\n// We have access to name later when we cargo build.\nexport function getLibraryData(\n\tthis: TransformPluginContext,\n\tmetadata: v.InferOutput<typeof MetadataSchema>,\n\toptions: MetadaSchemaOptions,\n) {\n\tconst package_ = findOnlyOne(\n\t\tmetadata.packages,\n\t\t(a) => a.manifest_path === options.project,\n\t);\n\n\tif (package_ === undefined) {\n\t\tthrow new Error(\n\t\t\t`Expected at least 1 package to have the manifest_path of ${options.project}`,\n\t\t);\n\t}\n\n\tconst TargetSchema = v.object({\n\t\tname: v.string(),\n\t\tsrc_path: v.literal(options.id),\n\t\tkind: v.tuple([v.literal(\"cdylib\")]),\n\t\tcrate_types: v.tuple([v.literal(\"cdylib\")]),\n\t});\n\n\tconst target = findOnlyOne(package_?.targets ?? [], (target) =>\n\t\tv.is(TargetSchema, target),\n\t);\n\n\tif (target === undefined) {\n\t\tthrow new Error(\n\t\t\t`Expected at least 1 target to match the src_path of ${options.id} and be a cdylib target`,\n\t\t);\n\t}\n\n\treturn {\n\t\tlibraryName: target.name,\n\t};\n}\n\nexport function findOnlyOne<T, U extends T>(\n\tarray: Array<T>,\n\tpredicate: ((item: T) => item is U) | ((value: T) => boolean),\n): U | undefined {\n\tlet found: U | undefined;\n\n\tfor (const item of array) {\n\t\tif (!predicate(item)) {\n\t\t\tcontinue;\n\t\t}\n\n\t\tif (found !== undefined) {\n\t\t\tthrow new Error(`Found multiple of the same item`);\n\t\t}\n\n\t\tfound = item as U;\n\t}\n\n\treturn found;\n}\n\n// There's more data but we're only going to validate what we need\nexport const MetadataSchema = v.object({\n\tpackages: v.array(\n\t\tv.object({\n\t\t\tname: v.string(),\n\t\t\tid: v.string(),\n\t\t\tmanifest_path: v.string(),\n\t\t\tdependencies: v.array(\n\t\t\t\tv.object({\n\t\t\t\t\tname: v.string(),\n\t\t\t\t\tsource: v.string(),\n\t\t\t\t\treq: v.string(),\n\t\t\t\t\tkind: v.nullable(v.string()),\n\t\t\t\t}),\n\t\t\t),\n\t\t\ttargets: v.array(\n\t\t\t\tv.object({\n\t\t\t\t\tkind: v.array(v.string()),\n\t\t\t\t\tcrate_types: v.array(v.string()),\n\t\t\t\t\tname: v.string(),\n\t\t\t\t\tsrc_path: v.string(),\n\t\t\t\t}),\n\t\t\t),\n\t\t}),\n\t),\n});\n","export function isString(value: unknown): value is string {\n\treturn typeof value === \"string\";\n}\n","import { execFileSync } from \"node:child_process\";\nimport path from \"node:path\";\nimport * as v from \"valibot\";\nimport { debug } from \"./debug\";\nimport { MetadataSchema } from \"./metadata\";\nimport type { MetadaSchemaOptions } from \"./types\";\nimport { isString } from \"./utils\";\n\nexport function cargoLocateProject(id: string) {\n\tconst args = [\"locate-project\", \"--message-format=plain\"];\n\n\tdebug(\"cargo %s\", args.join(\" \"));\n\n\tconst project = execFileSync(\"cargo\", args, {\n\t\tstdio: [\"ignore\", \"pipe\", \"ignore\"],\n\t\tencoding: \"utf-8\",\n\t\tcwd: path.dirname(id),\n\t}).trim();\n\n\tdebug(\"project %o\", project);\n\n\treturn project;\n}\n\nexport function cargoMetadata(options: MetadaSchemaOptions) {\n\tconst args = [\"metadata\", \"--no-deps\", \"--format-version=1\"];\n\tdebug(\"cargo %s\", args.join(\" \"));\n\tconst metacontent = execFileSync(\"cargo\", args, {\n\t\tcwd: path.dirname(options.id),\n\t\tencoding: \"utf-8\",\n\t}).trim();\n\n\tconst json = JSON.parse(metacontent);\n\n\tdebug(\"metadata %s\", JSON.stringify(json, null, 2));\n\n\treturn v.parse(MetadataSchema, json);\n}\n\nexport async function cargoBuild(\n\toptions: MetadaSchemaOptions,\n\tisServe: boolean,\n\toverrides: undefined | ((args: Array<string>) => Array<string>),\n) {\n\t// create `.wasm` from `.rs`\n\tlet args = [\n\t\t\"build\",\n\t\t\"--lib\",\n\t\t\"--target=wasm32-unknown-unknown\",\n\t\t\"--message-format=json\",\n\t\t\"--color=never\",\n\t\t\"--quiet\",\n\t\tisServe || \"--release\",\n\t].filter(isString);\n\n\tdebug(\"cargo-raw-args %s\", args.join(\" \"));\n\n\tif (overrides) {\n\t\targs = overrides(args);\n\t\tdebug(\"cargo-override-args %s\", args.join(\" \"));\n\t}\n\n\tconst ndjson = execFileSync(\"cargo\", args, {\n\t\tcwd: path.dirname(options.id),\n\t\tencoding: \"utf-8\",\n\t\tstdio: [\"ignore\", \"pipe\", \"ignore\"],\n\t});\n\n\tdebug(\"artifacts-ndjson %s\", ndjson);\n\n\tconst json = ndjson\n\t\t.trim()\n\t\t.split(\"\\n\")\n\t\t.map((json) => JSON.parse(json));\n\n\tdebug(\"artifacts %o\", json);\n\n\t// todo: validate json data\n\treturn json;\n}\n","export const CACHE_DIR = \"node_modules/.cache/vitest-plugin-cargo\";\n","import * as crypto from \"node:crypto\";\nimport * as path from \"node:path\";\nimport { CACHE_DIR } from \"./constants\";\n\nexport type LibraryContextBase = {\n\tid: string;\n\tproject: string;\n};\n\nexport type LibraryContextRustBuild = LibraryContextBase & {\n\toutDir: string;\n\twasm: string;\n};\n\nexport type LibraryContextWasmBuild = LibraryContextRustBuild & {\n\tname: string;\n};\n\nexport type Hash = string;\n\nexport function createLibraryHash(library: LibraryContextBase): Hash {\n\treturn crypto\n\t\t.createHash(\"sha256\")\n\t\t.update(`${library.project}:${library.id}`)\n\t\t.digest(\"hex\") as Hash;\n}\n\nexport type LibraryDir = string;\n\nexport function createLibraryDir(hash: Hash): LibraryDir {\n\tif (hash.length <= 2) {\n\t\tthrow Error(\n\t\t\t`Expected hash to be a string greater than two but received \"${hash}\"`,\n\t\t);\n\t}\n\n\treturn path.resolve(CACHE_DIR, hash.slice(0, 2), hash.slice(2));\n}\n","import type picomatch from \"picomatch\";\nimport type { StringFilter } from \"rollup\";\nimport * as v from \"valibot\";\n\nconst enable = v.optional(v.boolean(), false);\n\nconst FeaturesSchema = v.pipe(\n\tv.union([\n\t\tv.object({ allFeatures: v.literal(true) }),\n\t\tv.pipe(\n\t\t\tv.object({\n\t\t\t\tfeatures: v.optional(v.array(v.string())),\n\t\t\t\tnoDefaultFeatures: enable,\n\t\t\t}),\n\t\t\tv.transform((possibleFeatures) => ({ possibleFeatures })),\n\t\t),\n\t]),\n\tv.transform((features) => ({ features })),\n);\n\nconst PatternSchema = v.union([v.string(), v.instance(RegExp)]);\nconst MaybeArraySchema = <TSchema extends v.GenericSchema>(schema: TSchema) =>\n\tv.union([schema, v.array(schema)]);\n\nconst StringFilterSchema: v.GenericSchema<StringFilter> = v.union([\n\tPatternSchema,\n\tMaybeArraySchema(PatternSchema),\n\tv.object({\n\t\tinclude: v.optional(v.union([MaybeArraySchema(PatternSchema)])),\n\t\texclude: v.optional(v.union([MaybeArraySchema(PatternSchema)])),\n\t}),\n]);\n\nconst VitePluginCargoOptionsBaseSchema = v.pipe(\n\tv.object({\n\t\tpattern: StringFilterSchema,\n\t\tnoTypescript: enable,\n\t\tbrowserOnly: enable,\n\t\tcargoBuildOverrides: v.optional(\n\t\t\tv.pipe(\n\t\t\t\tv.function(),\n\t\t\t\tv.args(v.strictTuple([v.array(v.string())])),\n\t\t\t\tv.returns(v.array(v.string())),\n\t\t\t),\n\t\t),\n\t}),\n\tv.transform((base) => ({\n\t\ttypescript: !base.noTypescript,\n\t\tbrowserless: !base.browserOnly,\n\t\tpattern: base.pattern,\n\t\tcargoBuildOverrides: base.cargoBuildOverrides,\n\t})),\n);\n\nconst VitePluginCargoOptionsSchema = v.intersect([\n\tVitePluginCargoOptionsBaseSchema,\n\tFeaturesSchema,\n]);\n\nexport const parsePluginOptions = v.parser(VitePluginCargoOptionsSchema);\n\nexport type VitePluginCargoOptions = v.InferInput<\n\ttypeof VitePluginCargoOptionsSchema\n>;\n\nexport type VitePluginCargoOptionsInternal = v.InferOutput<\n\ttypeof VitePluginCargoOptionsSchema\n>;\n","import { execFileSync } from \"node:child_process\";\nimport path from \"node:path\";\nimport type { TransformPluginContext } from \"rollup\";\nimport type { Plugin } from \"vite\";\nimport { deriveLibraryArtifact } from \"./artifacts\";\nimport { cargoBuild, cargoLocateProject, cargoMetadata } from \"./cargo\";\nimport { debug } from \"./debug\";\nimport {\n\tcreateLibraryDir,\n\tcreateLibraryHash,\n\ttype LibraryContextBase,\n\ttype LibraryContextRustBuild,\n\ttype LibraryContextWasmBuild,\n\ttype LibraryDir,\n} from \"./library\";\nimport { getLibraryData } from \"./metadata\";\nimport {\n\ttype VitePluginCargoOptionsInternal as PluginOptions,\n\tparsePluginOptions,\n\ttype VitePluginCargoOptions,\n} from \"./plugin-options\";\nimport { isString } from \"./utils\";\n\nexport interface Library {\n\tid: string;\n\toutDir: LibraryDir;\n}\n\nexport interface PluginContext {\n\tisServe: boolean;\n\tlibraries: Map<string, Library>;\n}\n\n// use our own debugger for debugging.\nexport function cargo(pluginOptions_: VitePluginCargoOptions): Plugin<never> {\n\tconst pluginOptions = parsePluginOptions(pluginOptions_);\n\n\tconst context = {\n\t\tisServe: false,\n\t\tlibraries: new Map<string, Library>(),\n\t};\n\n\treturn {\n\t\tname: \"vite-plugin-cargo\",\n\t\tconfigResolved(config) {\n\t\t\tcontext.isServe = config.command === \"serve\";\n\t\t},\n\t\tasync resolveId(source, importer) {\n\t\t\t// check if this import came from one of our entrypoints\n\t\t\tconst outDir = context.libraries\n\t\t\t\t.values()\n\t\t\t\t.find((library) => library.id === importer)?.outDir;\n\n\t\t\tif (outDir === undefined) {\n\t\t\t\treturn null;\n\t\t\t}\n\n\t\t\t// ensure source is relative to wasm_bindgen output dir\n\t\t\treturn path.resolve(outDir, source);\n\t\t},\n\t\ttransform: {\n\t\t\tfilter: {\n\t\t\t\tid: pluginOptions.pattern,\n\t\t\t},\n\t\t\t// todo: throw when importing a non-entry point.\n\t\t\t// todo: consider: way in the future we could enable users to import any rust file\n\t\t\t// and we'll add overrides instead of relying on Cargo.toml for `lib` information.\n\t\t\tasync handler(_code, id) {\n\t\t\t\tconst project = cargoLocateProject(id);\n\t\t\t\tconst libraryContextBase: LibraryContextBase = { id, project };\n\n\t\t\t\tconst hash = createLibraryHash(libraryContextBase);\n\t\t\t\tconst outDir = createLibraryDir(hash);\n\n\t\t\t\tdebug(\"library %s\", { hash, id, outDir });\n\n\t\t\t\t// keep track of libraries compiled\n\t\t\t\t// for resolving `wasm-bingen` files to `outDir`.\n\t\t\t\tcontext.libraries.set(hash, { id, outDir });\n\n\t\t\t\tconst metadatas = cargoMetadata(libraryContextBase);\n\n\t\t\t\t// find the right library from our file\n\t\t\t\tconst metadata = getLibraryData.call(\n\t\t\t\t\tthis,\n\t\t\t\t\tmetadatas,\n\t\t\t\t\tlibraryContextBase,\n\t\t\t\t);\n\n\t\t\t\tconst artifacts = await cargoBuild(\n\t\t\t\t\tlibraryContextBase,\n\t\t\t\t\tcontext.isServe,\n\t\t\t\t\tpluginOptions.cargoBuildOverrides,\n\t\t\t\t);\n\n\t\t\t\tconst rustLibrary = await deriveLibraryArtifact.call(\n\t\t\t\t\tthis,\n\t\t\t\t\tartifacts,\n\t\t\t\t\tlibraryContextBase,\n\t\t\t\t);\n\n\t\t\t\tdebug(\"watching-dependencies %s\", rustLibrary.neighbours);\n\n\t\t\t\t// Watch for files only\n\t\t\t\tfor (const neighbour of rustLibrary.neighbours) {\n\t\t\t\t\tthis.addWatchFile(neighbour);\n\t\t\t\t}\n\n\t\t\t\tconst libraryContextRustBuild: LibraryContextRustBuild = {\n\t\t\t\t\tid,\n\t\t\t\t\toutDir,\n\t\t\t\t\tproject,\n\t\t\t\t\twasm: rustLibrary.wasmFilename,\n\t\t\t\t};\n\n\t\t\t\tbuildWasmBindgen(pluginOptions, context, libraryContextRustBuild);\n\n\t\t\t\tconst libraryContextWasmBuild: LibraryContextWasmBuild = {\n\t\t\t\t\t...libraryContextRustBuild,\n\t\t\t\t\tname: metadata.libraryName,\n\t\t\t\t};\n\n\t\t\t\t// copy <name>.d.ts to the <id>.d.ts so user gets type definitions for their rust file.\n\t\t\t\tif (pluginOptions.typescript) {\n\t\t\t\t\tawait copyTypescriptDeclaration.call(this, libraryContextWasmBuild);\n\t\t\t\t}\n\n\t\t\t\t// read `.js` entry point for code resolution\n\t\t\t\tconst code = await readJavascriptEntryPoint.call(\n\t\t\t\t\tthis,\n\t\t\t\t\tlibraryContextWasmBuild,\n\t\t\t\t);\n\n\t\t\t\treturn { code };\n\t\t\t},\n\t\t},\n\t};\n}\n\nasync function readJavascriptEntryPoint(\n\tthis: TransformPluginContext,\n\tlibrary: LibraryContextWasmBuild,\n) {\n\tconst entrypoint = path.resolve(library.outDir, `${library.name}.js`);\n\tconst content = await this.fs.readFile(entrypoint, {\n\t\tencoding: \"utf8\",\n\t});\n\n\treturn content;\n}\n\nasync function copyTypescriptDeclaration(\n\tthis: TransformPluginContext,\n\tlibrary: LibraryContextWasmBuild,\n) {\n\tconst source = path.join(library.outDir, `${library.name}.d.ts`);\n\tconst target = `${library.id}.d.ts`;\n\tawait this.fs.copyFile(source, target);\n}\n\n// create `.js` from `.wasm`\n//\n// `.js` and `.wasm` files are created in outDir,\n// and added to dependency graph from imports in the `.js` entrypoint.\nexport function buildWasmBindgen(\n\toptions: PluginOptions,\n\tcontext: PluginContext,\n\tlibrary: LibraryContextRustBuild,\n) {\n\tconst args = [\n\t\t\"--target=bundler\",\n\t\toptions.typescript || `--no-typescript`,\n\t\toptions.browserless || `--browser`,\n\t\tcontext.isServe && `--debug`,\n\t\t`--out-dir=${library.outDir}`,\n\t\tlibrary.wasm,\n\t].filter(isString);\n\n\tdebug(\"wasm-bindgen %s\", args.join(\" \"));\n\n\texecFileSync(\"wasm-bindgen\", args);\n}\n"],"names":["deriveLibraryArtifact","artifacts","options","artifact","a","libraryName","wasmFilename","dependencyFilepath","path","dependencies","graph","createGraphFromDependencies","neighboursEntry","neighbours","findAllDescendants","contents","line","source","targets","start","collecteds","initials","sources","uncollecteds","uncollected","debug","createDebug","getLibraryData","metadata","package_","findOnlyOne","TargetSchema","v","target","array","predicate","found","item","MetadataSchema","isString","value","cargoLocateProject","id","args","project","execFileSync","cargoMetadata","metacontent","json","cargoBuild","isServe","overrides","ndjson","CACHE_DIR","createLibraryHash","library","crypto","createLibraryDir","hash","enable","FeaturesSchema","possibleFeatures","features","PatternSchema","MaybeArraySchema","schema","StringFilterSchema","VitePluginCargoOptionsBaseSchema","base","VitePluginCargoOptionsSchema","parsePluginOptions","cargo","pluginOptions_","pluginOptions","context","config","importer","outDir","_code","libraryContextBase","metadatas","rustLibrary","neighbour","libraryContextRustBuild","buildWasmBindgen","libraryContextWasmBuild","copyTypescriptDeclaration","readJavascriptEntryPoint","entrypoint"],"mappings":";;;;;;AAIA,eAAsBA,EAErBC,GACAC,GACC;AAED,QAAMC,IAAWF,EACf,OAAO,CAACG,MAAMA,GAAG,WAAW,mBAAmB,EAC/C,OAAO,CAACA,MAAMA,GAAG,kBAAkBF,EAAQ,OAAO,IAAI,CAAC,GAGnDG,IAAcF,EAAS,OAAO,MAC9BG,IAAuBH,GAAU,YAAY,CAAC,GAE9CI,IAAqBC,EAAK;AAAA,IAC/BF;AAAA,IACA;AAAA,IACA,GAAGD,CAAW;AAAA,EAAA,GAGTI,IAAe,MAAM,KAAK,GAAG,SAASF,GAAoB;AAAA,IAC/D,UAAU;AAAA,EAAA,CACV,GAEKG,IAAQC,EAA4BF,CAAY,GAEhDG,IAAkBJ,EAAK;AAAA,IAC5BF;AAAA,IACA;AAAA,IACA,GAAGD,CAAW;AAAA,EAAA,GAGTQ,IAAaC,EAAmBF,GAAiBF,CAAK;AAE5D,SAAO,EAAE,cAAAJ,GAAc,YAAAO,EAAA;AACxB;AAEO,SAASF,EAA4BI,GAAkB;AAC7D,SAAO,IAAI;AAAA,IACVA,EACE,MAAM;AAAA,CAAI,EACV,OAAO,OAAO,EACd,IAAI,CAACC,MAAS;AACd,YAAM,CAACC,GAAQC,CAAO,IAAIF,EAAK,MAAM,IAAI;AACzC,aAAO;AAAA,QACNR,EAAK,QAAQS,CAAM;AAAA,QACnB,IAAI,IAAIC,GAAS,MAAM,GAAG,EAAE,IAAI,CAACd,MAAMI,EAAK,QAAQJ,CAAC,CAAC,KAAK,CAAA,CAAE;AAAA,MAAA;AAAA,IAE/D,CAAC;AA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,IAClD,UAAU;AAAA,EAAA,CACV;AAGF;AAEA,eAAeF,EAEd/B,GACC;AACD,QAAMtC,IAAST,EAAK,KAAK+C,EAAQ,QAAQ,GAAGA,EAAQ,IAAI,OAAO,GACzDtB,IAAS,GAAGsB,EAAQ,EAAE;AAC5B,QAAM,KAAK,GAAG,SAAStC,GAAQgB,CAAM;AACtC;AAMO,SAASmD,EACflF,GACAwE,GACAnB,GACC;AACD,QAAMZ,IAAO;AAAA,IACZ;AAAA,IACAzC,EAAQ,cAAc;AAAA,IACtBA,EAAQ,eAAe;AAAA,IACvBwE,EAAQ,WAAW;AAAA,IACnB,aAAanB,EAAQ,MAAM;AAAA,IAC3BA,EAAQ;AAAA,EAAA,EACP,OAAOhB,CAAQ;AAEjB,EAAAd,EAAM,mBAAmBkB,EAAK,KAAK,GAAG,CAAC,GAEvCE,EAAa,gBAAgBF,CAAI;AAClC;"}
package/package.json CHANGED
@@ -1,48 +1,61 @@
1
1
  {
2
- "name": "@waynevanson/vite-plugin-cargo",
3
- "version": "1.0.0",
4
- "description": "Import wasm_bingen compatible Rust to JavaScript via Vite",
5
- "main": "dist/index.js",
6
- "types": "dist/index.d.ts",
7
- "type": "module",
8
- "repository": {
9
- "url": "https://github.com/waynevanson/vite-plugin-cargo"
10
- },
11
- "publishConfig": {
12
- "access": "public",
13
- "registry": "https://registry.npmjs.org/"
14
- },
15
- "files": [
16
- "dist"
17
- ],
18
- "keywords": [
19
- "vite-plugin"
20
- ],
21
- "scripts": {
22
- "build": "tsc",
23
- "prepublishOnly": "tsc"
24
- },
25
- "author": "Wayne Van Son",
26
- "license": "MIT",
27
- "packageManager": "pnpm@10.27.0",
28
- "devDependencies": {
29
- "@biomejs/biome": "^2.3.13",
30
- "@types/node": "^24.10.9",
31
- "@types/picomatch": "^4.0.2",
32
- "typescript": "^5.9.3",
33
- "vite": "^7.3.1",
34
- "vitest": "^4.0.18"
35
- },
36
- "dependencies": {
37
- "picomatch": "^4.0.3",
38
- "valibot": "^1.2.0"
39
- },
40
- "peerDependencies": {
41
- "vite": "^7.3.1"
42
- },
43
- "peerDependenciesMeta": {
44
- "vite": {
45
- "optional": false
46
- }
47
- }
48
- }
2
+ "name": "@waynevanson/vite-plugin-cargo",
3
+ "version": "3.0.0",
4
+ "description": "Import wasm_bingen compatible Rust to JavaScript via Vite",
5
+ "main": "dist/index.js",
6
+ "types": "dist/index.d.ts",
7
+ "exports": {
8
+ "types": "./dist/index.d.ts",
9
+ "default": "./dist/index.js"
10
+ },
11
+ "type": "module",
12
+ "repository": {
13
+ "url": "https://github.com/waynevanson/vite-plugin-cargo"
14
+ },
15
+ "publishConfig": {
16
+ "access": "public",
17
+ "registry": "https://registry.npmjs.org/"
18
+ },
19
+ "files": [
20
+ "dist"
21
+ ],
22
+ "keywords": [
23
+ "vite-plugin"
24
+ ],
25
+ "author": "Wayne Van Son",
26
+ "license": "MIT",
27
+ "devDependencies": {
28
+ "@biomejs/biome": "^2.3.13",
29
+ "@microsoft/api-extractor": "^7.56.0",
30
+ "@types/node": "^24.10.9",
31
+ "@types/picomatch": "^4.0.2",
32
+ "rollup": "^4.57.1",
33
+ "typescript": "^5.9.3",
34
+ "unplugin-dts": "1.0.0-beta.6",
35
+ "vite": "^7.3.1",
36
+ "vite-plugin-dts": "^4.5.4",
37
+ "vite-plugin-inspect": "^11.3.3",
38
+ "vite-plugin-wasm": "^3.5.0",
39
+ "vitest": "^4.0.18"
40
+ },
41
+ "dependencies": {
42
+ "@types/debug": "^4.1.12",
43
+ "debug": "^4.4.3",
44
+ "glob": "^13.0.0",
45
+ "obug": "^2.1.1",
46
+ "picomatch": "^4.0.3",
47
+ "pino": "^10.3.0",
48
+ "valibot": "^1.2.0"
49
+ },
50
+ "peerDependencies": {
51
+ "vite": "^7.3.1"
52
+ },
53
+ "peerDependenciesMeta": {
54
+ "vite": {
55
+ "optional": false
56
+ }
57
+ },
58
+ "scripts": {
59
+ "build": "vite build"
60
+ }
61
+ }