@waynevanson/vite-plugin-cargo 1.0.0 → 2.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
@@ -21,7 +21,7 @@ You must have the following installed on your system:
21
21
  ## Installation
22
22
 
23
23
  ```bash
24
- npm install vite-plugin-cargo --save-dev
24
+ npm install @waynevanson/vite-plugin-cargo --save-dev
25
25
 
26
26
  ```
27
27
 
package/dist/index.d.ts CHANGED
@@ -1,13 +1,78 @@
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 { default as default_2 } from 'picomatch';
2
+ import { Plugin as Plugin_2 } from 'vite';
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 includes: v.GenericSchema<default_2.Glob>;
37
+ readonly noTypescript: v.OptionalSchema<v.BooleanSchema<undefined>, false>;
38
+ readonly browserOnly: v.OptionalSchema<v.BooleanSchema<undefined>, false>;
39
+ }, undefined>, v.TransformAction<{
40
+ includes: default_2.Glob;
41
+ noTypescript: boolean;
42
+ browserOnly: boolean;
43
+ }, {
44
+ typescript: boolean;
45
+ browserless: boolean;
46
+ includes: default_2.Glob;
47
+ }>]>, v.SchemaWithPipe<readonly [v.UnionSchema<[v.ObjectSchema<{
48
+ readonly allFeatures: v.LiteralSchema<true, undefined>;
49
+ }, undefined>, v.SchemaWithPipe<readonly [v.ObjectSchema<{
50
+ readonly features: v.OptionalSchema<v.ArraySchema<v.StringSchema<undefined>, undefined>, undefined>;
51
+ readonly noDefaultFeatures: v.OptionalSchema<v.BooleanSchema<undefined>, false>;
52
+ }, undefined>, v.TransformAction<{
53
+ features?: string[] | undefined;
54
+ noDefaultFeatures: boolean;
55
+ }, {
56
+ possibleFeatures: {
57
+ features?: string[] | undefined;
58
+ noDefaultFeatures: boolean;
59
+ };
60
+ }>]>], undefined>, v.TransformAction<{
61
+ allFeatures: true;
62
+ } | {
63
+ possibleFeatures: {
64
+ features?: string[] | undefined;
65
+ noDefaultFeatures: boolean;
66
+ };
67
+ }, {
68
+ features: {
69
+ allFeatures: true;
70
+ } | {
71
+ possibleFeatures: {
72
+ features?: string[] | undefined;
73
+ noDefaultFeatures: boolean;
74
+ };
75
+ };
76
+ }>]>], undefined>;
77
+
78
+ export { }
package/dist/index.js CHANGED
@@ -1,140 +1,259 @@
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 S from "node:path";
3
+ import l from "node:path";
4
+ 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";
5
+ import * as e 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";
6
+ import * as F from "node:crypto";
7
+ const c = D("vite-plugin-cargo");
8
+ function w(t) {
9
+ return typeof t == "string";
32
10
  }
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;
11
+ function _(t) {
12
+ const n = ["locate-project", "--message-format=plain"];
13
+ c("cargo %s", n.join(" "));
14
+ const r = f("cargo", n, {
15
+ stdio: ["ignore", "pipe", "ignore"],
16
+ encoding: "utf-8",
17
+ cwd: l.dirname(t)
18
+ }).trim();
19
+ return c("project %o", r), r;
44
20
  }
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;
21
+ async function x(t, n) {
22
+ const r = [
23
+ "build",
24
+ "--lib",
25
+ "--target=wasm32-unknown-unknown",
26
+ "--message-format=json",
27
+ "--color=never",
28
+ "--quiet",
29
+ n || "--release"
30
+ ].filter(w);
31
+ c("cargo %s", r.join(" "));
32
+ const s = f("cargo", r, {
33
+ cwd: l.dirname(t.id),
34
+ encoding: "utf-8",
35
+ stdio: ["ignore", "pipe", "ignore"]
36
+ });
37
+ c("artifacts-ndjson %s", s);
38
+ const o = s.trim().split(`
39
+ `).map((a) => JSON.parse(a));
40
+ return c("artifacts %o", o), o;
69
41
  }
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
- };
42
+ async function C(t, n) {
43
+ const r = t.filter((d) => d?.reason === "compiler-artifact").filter((d) => d?.manifest_path === n.project)?.[0], s = r.target.name, o = r?.filenames?.[0], a = l.resolve(
44
+ o,
45
+ "../deps",
46
+ `${s}.d`
47
+ ), i = await this.fs.readFile(a, {
48
+ encoding: "utf8"
49
+ }), p = O(i), u = l.resolve(
50
+ o,
51
+ "../deps",
52
+ `${s}.wasm`
53
+ ), g = $(u, p);
54
+ return { wasmFilename: o, neighbours: g };
140
55
  }
56
+ function O(t) {
57
+ return new Map(
58
+ t.split(`
59
+ `).filter(Boolean).map((n) => {
60
+ const [r, s] = n.split(": ");
61
+ return [
62
+ l.resolve(r),
63
+ new Set(s?.split(" ").map((o) => l.resolve(o)) ?? [])
64
+ ];
65
+ })
66
+ );
67
+ }
68
+ function $(t, n) {
69
+ const r = /* @__PURE__ */ new Set(), s = n.get(t);
70
+ if (s === void 0)
71
+ throw new Error("Expect the start value to exist in the dependency graph");
72
+ const o = new Set(s);
73
+ for (; o.size > 0; )
74
+ for (const a of o) {
75
+ r.add(a), o.delete(a);
76
+ const p = (n.get(a) ?? /* @__PURE__ */ new Set()).difference(r);
77
+ for (const u of p)
78
+ o.add(u);
79
+ }
80
+ return r;
81
+ }
82
+ function E(t) {
83
+ const n = ["metadata", "--no-deps", "--format-version=1"];
84
+ c("cargo %s", n.join(" "));
85
+ const r = f("cargo", n, {
86
+ cwd: l.dirname(t.id),
87
+ encoding: "utf-8"
88
+ }).trim(), s = JSON.parse(r);
89
+ return c("metadata %s", JSON.stringify(s, null, 2)), s;
90
+ }
91
+ function k(t, n) {
92
+ return e.parse(B(n), t);
93
+ }
94
+ const B = (t) => e.nonNullish(
95
+ e.pipe(
96
+ e.object({
97
+ packages: e.array(
98
+ e.pipe(
99
+ e.object({
100
+ manifest_path: e.string(),
101
+ targets: e.array(
102
+ e.object({
103
+ kind: e.array(e.string()),
104
+ name: e.string(),
105
+ src_path: e.string()
106
+ })
107
+ )
108
+ }),
109
+ e.transform(
110
+ (n) => n.targets.flatMap(
111
+ (r) => r.kind.flatMap((s) => ({
112
+ manifest_path: n.manifest_path,
113
+ ...r,
114
+ kind: s
115
+ }))
116
+ )
117
+ )
118
+ )
119
+ )
120
+ }),
121
+ e.transform((n) => n.packages.flat()),
122
+ e.findItem(
123
+ (n) => e.is(
124
+ e.object({
125
+ manifest_path: e.literal(t.project),
126
+ name: e.string(),
127
+ src_path: e.literal(t.id),
128
+ kind: e.literal("cdylib")
129
+ }),
130
+ n
131
+ )
132
+ )
133
+ )
134
+ ), L = "node_modules/.cache/vitest-plugin-cargo";
135
+ function M(t) {
136
+ return F.createHash("sha256").update(`${t.project}:${t.id}`).digest("hex");
137
+ }
138
+ function N(t) {
139
+ if (t.length <= 2)
140
+ throw Error(
141
+ `Expected hash to be a string greater than two but received "${t}"`
142
+ );
143
+ return S.resolve(L, t.slice(0, 2), t.slice(2));
144
+ }
145
+ const h = e.optional(e.boolean(), !1), P = e.pipe(
146
+ e.union([
147
+ e.object({ allFeatures: e.literal(!0) }),
148
+ e.pipe(
149
+ e.object({
150
+ features: e.optional(e.array(e.string())),
151
+ noDefaultFeatures: h
152
+ }),
153
+ e.transform((t) => ({ possibleFeatures: t }))
154
+ )
155
+ ]),
156
+ e.transform((t) => ({ features: t }))
157
+ ), R = e.pipe(
158
+ e.object({
159
+ includes: e.union(
160
+ [e.string(), e.array(e.string())],
161
+ "Glob"
162
+ ),
163
+ noTypescript: h,
164
+ browserOnly: h
165
+ }),
166
+ e.transform((t) => ({
167
+ typescript: !t.noTypescript,
168
+ browserless: !t.browserOnly,
169
+ includes: t.includes
170
+ }))
171
+ ), J = e.intersect([
172
+ R,
173
+ P
174
+ ]), A = e.parser(J);
175
+ function z(t) {
176
+ const n = A(t), r = {
177
+ isServe: !1,
178
+ libraries: /* @__PURE__ */ new Map()
179
+ };
180
+ return {
181
+ name: "vite-plugin-cargo",
182
+ configResolved(s) {
183
+ r.isServe = s.command === "serve";
184
+ },
185
+ async resolveId(s, o) {
186
+ const a = r.libraries.values().find((i) => i.id === o)?.outDir;
187
+ return a === void 0 ? null : l.resolve(a, s);
188
+ },
189
+ transform: {
190
+ filter: {
191
+ id: n.includes
192
+ },
193
+ // todo: throw when importing a non-entry point.
194
+ // todo: consider: way in the future we could enable users to import any rust file
195
+ // and we'll add overrides instead of relying on Cargo.toml for `lib` information.
196
+ async handler(s, o) {
197
+ const a = _(o), i = { id: o, project: a }, p = M(i), u = N(p);
198
+ c("library %s", { hash: p, id: o, outDir: u }), r.libraries.set(p, { id: o, outDir: u });
199
+ const g = E(i), d = k.call(
200
+ this,
201
+ g,
202
+ i
203
+ ), v = await x.call(
204
+ this,
205
+ i,
206
+ r.isServe
207
+ ), m = await C.call(
208
+ this,
209
+ v,
210
+ i
211
+ );
212
+ c("watching-dependencies %s", m.neighbours);
213
+ for (const j of m.neighbours)
214
+ this.addWatchFile(j);
215
+ const b = {
216
+ id: o,
217
+ outDir: u,
218
+ project: a,
219
+ wasm: m.wasmFilename
220
+ };
221
+ T(n, r, b);
222
+ const y = {
223
+ ...b,
224
+ name: d.name
225
+ };
226
+ return n.typescript && await I.call(this, y), { code: await H.call(
227
+ this,
228
+ y
229
+ ) };
230
+ }
231
+ }
232
+ };
233
+ }
234
+ async function H(t) {
235
+ const n = l.resolve(t.outDir, `${t.name}.js`);
236
+ return await this.fs.readFile(n, {
237
+ encoding: "utf8"
238
+ });
239
+ }
240
+ async function I(t) {
241
+ const n = l.join(t.outDir, `${t.name}.d.ts`), r = `${t.id}.d.ts`;
242
+ await this.fs.copyFile(n, r);
243
+ }
244
+ function T(t, n, r) {
245
+ const s = [
246
+ "--target=bundler",
247
+ t.typescript || "--no-typescript",
248
+ t.browserless || "--browser",
249
+ n.isServe && "--debug",
250
+ `--out-dir=${r.outDir}`,
251
+ r.wasm
252
+ ].filter(w);
253
+ c("wasm-bindgen %s", s.join(" ")), f("wasm-bindgen", s);
254
+ }
255
+ export {
256
+ T as buildWasmBindgen,
257
+ z as cargo
258
+ };
259
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sources":["../src/debug.ts","../src/utils.ts","../src/cargo.ts","../src/compile-rust-library.ts","../src/find-wasm-name.ts","../src/constants.ts","../src/library.ts","../src/plugin-options.ts","../src/index.ts"],"sourcesContent":["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","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 type { TransformPluginContext } from \"rollup\";\nimport { debug } from \"./debug\";\nimport type { MetadaSchemaOptions } from \"./types\";\nimport { isString } from \"./utils\";\n\nexport function getClosestCargoProject(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 async function compileRustLibrary(\n\tthis: TransformPluginContext,\n\toptions: MetadaSchemaOptions,\n\tisServe: boolean,\n) {\n\t// create `.wasm` from `.rs`\n\tconst 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 %s\", args.join(\" \"));\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","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 { execFileSync } from \"node:child_process\";\nimport path from \"node:path\";\nimport type { TransformPluginContext } from \"rollup\";\nimport * as v from \"valibot\";\nimport { debug } from \"./debug\";\nimport type { MetadaSchemaOptions } from \"./types\";\n\nexport function getRustMetadata(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 json;\n}\n\nexport function getLibraryData(\n\tthis: TransformPluginContext,\n\tmetadata: unknown,\n\toptions: MetadaSchemaOptions,\n) {\n\treturn v.parse(MetadataSchema(options), metadata);\n}\n\n// todo: Replace all schema with only parsing what we need to searching.\nconst MetadataSchema = (options: MetadaSchemaOptions) =>\n\tv.nonNullish(\n\t\tv.pipe(\n\t\t\tv.object({\n\t\t\t\tpackages: v.array(\n\t\t\t\t\tv.pipe(\n\t\t\t\t\t\tv.object({\n\t\t\t\t\t\t\tmanifest_path: v.string(),\n\t\t\t\t\t\t\ttargets: v.array(\n\t\t\t\t\t\t\t\tv.object({\n\t\t\t\t\t\t\t\t\tkind: v.array(v.string()),\n\t\t\t\t\t\t\t\t\tname: v.string(),\n\t\t\t\t\t\t\t\t\tsrc_path: v.string(),\n\t\t\t\t\t\t\t\t}),\n\t\t\t\t\t\t\t),\n\t\t\t\t\t\t}),\n\t\t\t\t\t\tv.transform((package_) =>\n\t\t\t\t\t\t\tpackage_.targets.flatMap((target) =>\n\t\t\t\t\t\t\t\ttarget.kind.flatMap((kind) => ({\n\t\t\t\t\t\t\t\t\tmanifest_path: package_.manifest_path,\n\t\t\t\t\t\t\t\t\t...target,\n\t\t\t\t\t\t\t\t\tkind,\n\t\t\t\t\t\t\t\t})),\n\t\t\t\t\t\t\t),\n\t\t\t\t\t\t),\n\t\t\t\t\t),\n\t\t\t\t),\n\t\t\t}),\n\t\t\tv.transform((packages) => packages.packages.flat()),\n\t\t\tv.findItem((metadata) =>\n\t\t\t\tv.is(\n\t\t\t\t\tv.object({\n\t\t\t\t\t\tmanifest_path: v.literal(options.project),\n\t\t\t\t\t\tname: v.string(),\n\t\t\t\t\t\tsrc_path: v.literal(options.id),\n\t\t\t\t\t\tkind: v.literal(\"cdylib\"),\n\t\t\t\t\t}),\n\t\t\t\t\tmetadata,\n\t\t\t\t),\n\t\t\t),\n\t\t),\n\t);\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 * 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 VitePluginCargoOptionsBaseSchema = v.pipe(\n\tv.object({\n\t\tincludes: v.union(\n\t\t\t[v.string(), v.array(v.string())],\n\t\t\t\"Glob\",\n\t\t) as v.GenericSchema<picomatch.Glob>,\n\t\tnoTypescript: enable,\n\t\tbrowserOnly: enable,\n\t}),\n\tv.transform((base) => ({\n\t\ttypescript: !base.noTypescript,\n\t\tbrowserless: !base.browserOnly,\n\t\tincludes: base.includes,\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 { compileRustLibrary, getClosestCargoProject } from \"./cargo\";\nimport { deriveLibraryArtifact } from \"./compile-rust-library\";\nimport { debug } from \"./debug\";\nimport { getLibraryData, getRustMetadata } from \"./find-wasm-name\";\nimport {\n\tcreateLibraryDir,\n\tcreateLibraryHash,\n\ttype LibraryContextBase,\n\ttype LibraryContextRustBuild,\n\ttype LibraryContextWasmBuild,\n\ttype LibraryDir,\n} from \"./library\";\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.includes,\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 = getClosestCargoProject(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 = getRustMetadata(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 compileRustLibrary.call(\n\t\t\t\t\tthis,\n\t\t\t\t\tlibraryContextBase,\n\t\t\t\t\tcontext.isServe,\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.name,\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":["debug","createDebug","isString","value","getClosestCargoProject","id","args","project","execFileSync","path","compileRustLibrary","options","isServe","ndjson","json","deriveLibraryArtifact","artifacts","artifact","a","libraryName","wasmFilename","dependencyFilepath","dependencies","graph","createGraphFromDependencies","neighboursEntry","neighbours","findAllDescendants","contents","line","source","targets","start","collecteds","initials","sources","uncollecteds","uncollected","getRustMetadata","metacontent","getLibraryData","metadata","v","MetadataSchema","package_","target","kind","packages","CACHE_DIR","createLibraryHash","library","crypto","createLibraryDir","hash","enable","FeaturesSchema","possibleFeatures","features","VitePluginCargoOptionsBaseSchema","base","VitePluginCargoOptionsSchema","parsePluginOptions","cargo","pluginOptions_","pluginOptions","context","config","importer","outDir","_code","libraryContextBase","metadatas","rustLibrary","neighbour","libraryContextRustBuild","buildWasmBindgen","libraryContextWasmBuild","copyTypescriptDeclaration","readJavascriptEntryPoint","entrypoint"],"mappings":";;;;;;AAGO,MAAMA,IAAQC,EAAY,mBAAmB;ACH7C,SAASC,EAASC,GAAiC;AACzD,SAAO,OAAOA,KAAU;AACzB;ACKO,SAASC,EAAuB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,CAAQ;AAEjB,EAAAF,EAAM,mBAAmBM,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": "2.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
+ }