@waynevanson/vite-plugin-cargo 2.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 +9 -6
- package/dist/index.d.ts +7 -4
- package/dist/index.js +212 -182
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
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.
|
|
@@ -38,7 +39,8 @@ import { cargo } from "vite-plugin-cargo";
|
|
|
38
39
|
export default defineConfig({
|
|
39
40
|
plugins: [
|
|
40
41
|
cargo({
|
|
41
|
-
|
|
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
|
|
92
|
-
|
|
|
93
|
-
| `includes`
|
|
94
|
-
| `browserOnly`
|
|
95
|
-
| `noTypescript`
|
|
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,5 +1,5 @@
|
|
|
1
|
-
import { default as default_2 } from 'picomatch';
|
|
2
1
|
import { Plugin as Plugin_2 } from 'vite';
|
|
2
|
+
import { StringFilter } from 'rollup';
|
|
3
3
|
import * as v from 'valibot';
|
|
4
4
|
|
|
5
5
|
export declare function buildWasmBindgen(options: VitePluginCargoOptionsInternal, context: PluginContext, library: LibraryContextRustBuild): void;
|
|
@@ -33,17 +33,20 @@ declare type VitePluginCargoOptions = v.InferInput<typeof VitePluginCargoOptions
|
|
|
33
33
|
declare type VitePluginCargoOptionsInternal = v.InferOutput<typeof VitePluginCargoOptionsSchema>;
|
|
34
34
|
|
|
35
35
|
declare const VitePluginCargoOptionsSchema: v.IntersectSchema<[v.SchemaWithPipe<readonly [v.ObjectSchema<{
|
|
36
|
-
readonly
|
|
36
|
+
readonly pattern: v.GenericSchema<StringFilter>;
|
|
37
37
|
readonly noTypescript: v.OptionalSchema<v.BooleanSchema<undefined>, false>;
|
|
38
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>;
|
|
39
40
|
}, undefined>, v.TransformAction<{
|
|
40
|
-
|
|
41
|
+
pattern: StringFilter;
|
|
41
42
|
noTypescript: boolean;
|
|
42
43
|
browserOnly: boolean;
|
|
44
|
+
cargoBuildOverrides?: ((args_0: string[]) => string[]) | undefined;
|
|
43
45
|
}, {
|
|
44
46
|
typescript: boolean;
|
|
45
47
|
browserless: boolean;
|
|
46
|
-
|
|
48
|
+
pattern: StringFilter;
|
|
49
|
+
cargoBuildOverrides: ((args_0: string[]) => string[]) | undefined;
|
|
47
50
|
}>]>, v.SchemaWithPipe<readonly [v.UnionSchema<[v.ObjectSchema<{
|
|
48
51
|
readonly allFeatures: v.LiteralSchema<true, undefined>;
|
|
49
52
|
}, undefined>, v.SchemaWithPipe<readonly [v.ObjectSchema<{
|
package/dist/index.js
CHANGED
|
@@ -1,259 +1,289 @@
|
|
|
1
1
|
import { execFileSync as f } from "node:child_process";
|
|
2
|
-
import * as
|
|
2
|
+
import * as x from "node:path";
|
|
3
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";
|
|
4
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";
|
|
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
6
|
import * as F from "node:crypto";
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
return typeof t == "string";
|
|
10
|
-
}
|
|
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;
|
|
20
|
-
}
|
|
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;
|
|
41
|
-
}
|
|
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(
|
|
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(
|
|
44
9
|
o,
|
|
45
10
|
"../deps",
|
|
46
|
-
`${
|
|
47
|
-
),
|
|
11
|
+
`${a}.d`
|
|
12
|
+
), s = await this.fs.readFile(i, {
|
|
48
13
|
encoding: "utf8"
|
|
49
|
-
}),
|
|
14
|
+
}), d = B(s), p = l.resolve(
|
|
50
15
|
o,
|
|
51
16
|
"../deps",
|
|
52
|
-
`${
|
|
53
|
-
),
|
|
54
|
-
return { wasmFilename: o, neighbours:
|
|
17
|
+
`${a}.wasm`
|
|
18
|
+
), m = $(p, d);
|
|
19
|
+
return { wasmFilename: o, neighbours: m };
|
|
55
20
|
}
|
|
56
|
-
function
|
|
21
|
+
function B(e) {
|
|
57
22
|
return new Map(
|
|
58
|
-
|
|
23
|
+
e.split(`
|
|
59
24
|
`).filter(Boolean).map((n) => {
|
|
60
|
-
const [r,
|
|
25
|
+
const [r, a] = n.split(": ");
|
|
61
26
|
return [
|
|
62
27
|
l.resolve(r),
|
|
63
|
-
new Set(
|
|
28
|
+
new Set(a?.split(" ").map((o) => l.resolve(o)) ?? [])
|
|
64
29
|
];
|
|
65
30
|
})
|
|
66
31
|
);
|
|
67
32
|
}
|
|
68
|
-
function $(
|
|
69
|
-
const r = /* @__PURE__ */ new Set(),
|
|
70
|
-
if (
|
|
33
|
+
function $(e, n) {
|
|
34
|
+
const r = /* @__PURE__ */ new Set(), a = n.get(e);
|
|
35
|
+
if (a === void 0)
|
|
71
36
|
throw new Error("Expect the start value to exist in the dependency graph");
|
|
72
|
-
const o = new Set(
|
|
37
|
+
const o = new Set(a);
|
|
73
38
|
for (; o.size > 0; )
|
|
74
|
-
for (const
|
|
75
|
-
r.add(
|
|
76
|
-
const
|
|
77
|
-
for (const
|
|
78
|
-
o.add(
|
|
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);
|
|
79
44
|
}
|
|
80
45
|
return r;
|
|
81
46
|
}
|
|
82
|
-
|
|
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
|
+
};
|
|
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) {
|
|
83
123
|
const n = ["metadata", "--no-deps", "--format-version=1"];
|
|
84
124
|
c("cargo %s", n.join(" "));
|
|
85
125
|
const r = f("cargo", n, {
|
|
86
|
-
cwd: l.dirname(
|
|
126
|
+
cwd: l.dirname(e.id),
|
|
87
127
|
encoding: "utf-8"
|
|
88
|
-
}).trim(),
|
|
89
|
-
return c("metadata %s", JSON.stringify(
|
|
128
|
+
}).trim(), a = JSON.parse(r);
|
|
129
|
+
return c("metadata %s", JSON.stringify(a, null, 2)), t.parse(C, a);
|
|
90
130
|
}
|
|
91
|
-
function
|
|
92
|
-
|
|
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;
|
|
93
151
|
}
|
|
94
|
-
const
|
|
95
|
-
|
|
96
|
-
|
|
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");
|
|
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");
|
|
137
155
|
}
|
|
138
|
-
function
|
|
139
|
-
if (
|
|
156
|
+
function A(e) {
|
|
157
|
+
if (e.length <= 2)
|
|
140
158
|
throw Error(
|
|
141
|
-
`Expected hash to be a string greater than two but received "${
|
|
159
|
+
`Expected hash to be a string greater than two but received "${e}"`
|
|
142
160
|
);
|
|
143
|
-
return
|
|
161
|
+
return x.resolve(M, e.slice(0, 2), e.slice(2));
|
|
144
162
|
}
|
|
145
|
-
const
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
features:
|
|
151
|
-
noDefaultFeatures:
|
|
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
|
|
152
170
|
}),
|
|
153
|
-
|
|
171
|
+
t.transform((e) => ({ possibleFeatures: e }))
|
|
154
172
|
)
|
|
155
173
|
]),
|
|
156
|
-
|
|
157
|
-
),
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
)
|
|
163
|
-
|
|
164
|
-
|
|
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
|
+
)
|
|
165
194
|
}),
|
|
166
|
-
|
|
167
|
-
typescript: !
|
|
168
|
-
browserless: !
|
|
169
|
-
|
|
195
|
+
t.transform((e) => ({
|
|
196
|
+
typescript: !e.noTypescript,
|
|
197
|
+
browserless: !e.browserOnly,
|
|
198
|
+
pattern: e.pattern,
|
|
199
|
+
cargoBuildOverrides: e.cargoBuildOverrides
|
|
170
200
|
}))
|
|
171
|
-
),
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
]),
|
|
175
|
-
function
|
|
176
|
-
const n =
|
|
201
|
+
), W = t.intersect([
|
|
202
|
+
H,
|
|
203
|
+
J
|
|
204
|
+
]), q = t.parser(W);
|
|
205
|
+
function X(e) {
|
|
206
|
+
const n = q(e), r = {
|
|
177
207
|
isServe: !1,
|
|
178
208
|
libraries: /* @__PURE__ */ new Map()
|
|
179
209
|
};
|
|
180
210
|
return {
|
|
181
211
|
name: "vite-plugin-cargo",
|
|
182
|
-
configResolved(
|
|
183
|
-
r.isServe =
|
|
212
|
+
configResolved(a) {
|
|
213
|
+
r.isServe = a.command === "serve";
|
|
184
214
|
},
|
|
185
|
-
async resolveId(
|
|
186
|
-
const
|
|
187
|
-
return
|
|
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);
|
|
188
218
|
},
|
|
189
219
|
transform: {
|
|
190
220
|
filter: {
|
|
191
|
-
id: n.
|
|
221
|
+
id: n.pattern
|
|
192
222
|
},
|
|
193
223
|
// todo: throw when importing a non-entry point.
|
|
194
224
|
// todo: consider: way in the future we could enable users to import any rust file
|
|
195
225
|
// and we'll add overrides instead of relying on Cargo.toml for `lib` information.
|
|
196
|
-
async handler(
|
|
197
|
-
const
|
|
198
|
-
c("library %s", { hash:
|
|
199
|
-
const
|
|
200
|
-
this,
|
|
201
|
-
g,
|
|
202
|
-
i
|
|
203
|
-
), v = await x.call(
|
|
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(
|
|
204
230
|
this,
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
),
|
|
231
|
+
m,
|
|
232
|
+
s
|
|
233
|
+
), O = await P(
|
|
234
|
+
s,
|
|
235
|
+
r.isServe,
|
|
236
|
+
n.cargoBuildOverrides
|
|
237
|
+
), h = await E.call(
|
|
208
238
|
this,
|
|
209
|
-
|
|
210
|
-
|
|
239
|
+
O,
|
|
240
|
+
s
|
|
211
241
|
);
|
|
212
|
-
c("watching-dependencies %s",
|
|
213
|
-
for (const
|
|
214
|
-
this.addWatchFile(
|
|
215
|
-
const
|
|
242
|
+
c("watching-dependencies %s", h.neighbours);
|
|
243
|
+
for (const _ of h.neighbours)
|
|
244
|
+
this.addWatchFile(_);
|
|
245
|
+
const w = {
|
|
216
246
|
id: o,
|
|
217
|
-
outDir:
|
|
218
|
-
project:
|
|
219
|
-
wasm:
|
|
247
|
+
outDir: p,
|
|
248
|
+
project: i,
|
|
249
|
+
wasm: h.wasmFilename
|
|
220
250
|
};
|
|
221
|
-
|
|
222
|
-
const
|
|
223
|
-
...
|
|
224
|
-
name:
|
|
251
|
+
z(n, r, w);
|
|
252
|
+
const v = {
|
|
253
|
+
...w,
|
|
254
|
+
name: u.libraryName
|
|
225
255
|
};
|
|
226
|
-
return n.typescript && await
|
|
256
|
+
return n.typescript && await V.call(this, v), { code: await I.call(
|
|
227
257
|
this,
|
|
228
|
-
|
|
258
|
+
v
|
|
229
259
|
) };
|
|
230
260
|
}
|
|
231
261
|
}
|
|
232
262
|
};
|
|
233
263
|
}
|
|
234
|
-
async function
|
|
235
|
-
const n = l.resolve(
|
|
264
|
+
async function I(e) {
|
|
265
|
+
const n = l.resolve(e.outDir, `${e.name}.js`);
|
|
236
266
|
return await this.fs.readFile(n, {
|
|
237
267
|
encoding: "utf8"
|
|
238
268
|
});
|
|
239
269
|
}
|
|
240
|
-
async function
|
|
241
|
-
const n = l.join(
|
|
270
|
+
async function V(e) {
|
|
271
|
+
const n = l.join(e.outDir, `${e.name}.d.ts`), r = `${e.id}.d.ts`;
|
|
242
272
|
await this.fs.copyFile(n, r);
|
|
243
273
|
}
|
|
244
|
-
function
|
|
245
|
-
const
|
|
274
|
+
function z(e, n, r) {
|
|
275
|
+
const a = [
|
|
246
276
|
"--target=bundler",
|
|
247
|
-
|
|
248
|
-
|
|
277
|
+
e.typescript || "--no-typescript",
|
|
278
|
+
e.browserless || "--browser",
|
|
249
279
|
n.isServe && "--debug",
|
|
250
280
|
`--out-dir=${r.outDir}`,
|
|
251
281
|
r.wasm
|
|
252
|
-
].filter(
|
|
253
|
-
c("wasm-bindgen %s",
|
|
282
|
+
].filter(S);
|
|
283
|
+
c("wasm-bindgen %s", a.join(" ")), f("wasm-bindgen", a);
|
|
254
284
|
}
|
|
255
285
|
export {
|
|
256
|
-
|
|
257
|
-
|
|
286
|
+
z as buildWasmBindgen,
|
|
287
|
+
X as cargo
|
|
258
288
|
};
|
|
259
289
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +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,EAAuBC,GAAY;AAClD,QAAMC,IAAO,CAAC,kBAAkB,wBAAwB;AAExD,EAAAN,EAAM,YAAYM,EAAK,KAAK,GAAG,CAAC;AAEhC,QAAMC,IAAUC,EAAa,SAASF,GAAM;AAAA,IAC3C,OAAO,CAAC,UAAU,QAAQ,QAAQ;AAAA,IAClC,UAAU;AAAA,IACV,KAAKG,EAAK,QAAQJ,CAAE;AAAA,EAAA,CACpB,EAAE,KAAA;AAEH,SAAAL,EAAM,cAAcO,CAAO,GAEpBA;AACR;AAEA,eAAsBG,EAErBC,GACAC,GACC;AAED,QAAMN,IAAO;AAAA,IACZ;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACAM,KAAW;AAAA,EAAA,EACV,OAAOV,CAAQ;AAEjB,EAAAF,EAAM,YAAYM,EAAK,KAAK,GAAG,CAAC;AAEhC,QAAMO,IAASL,EAAa,SAASF,GAAM;AAAA,IAC1C,KAAKG,EAAK,QAAQE,EAAQ,EAAE;AAAA,IAC5B,UAAU;AAAA,IACV,OAAO,CAAC,UAAU,QAAQ,QAAQ;AAAA,EAAA,CAClC;AAED,EAAAX,EAAM,uBAAuBa,CAAM;AAEnC,QAAMC,IAAOD,EACX,KAAA,EACA,MAAM;AAAA,CAAI,EACV,IAAI,CAACC,MAAS,KAAK,M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eAAeF,EAEd3B,GACC;AACD,QAAMpB,IAASrB,EAAK,KAAKyC,EAAQ,QAAQ,GAAGA,EAAQ,IAAI,OAAO,GACzDL,IAAS,GAAGK,EAAQ,EAAE;AAC5B,QAAM,KAAK,GAAG,SAASpB,GAAQe,CAAM;AACtC;AAMO,SAAS8B,EACfhE,GACAsD,GACAf,GACC;AACD,QAAM5C,IAAO;AAAA,IACZ;AAAA,IACAK,EAAQ,cAAc;AAAA,IACtBA,EAAQ,eAAe;AAAA,IACvBsD,EAAQ,WAAW;AAAA,IACnB,aAAaf,EAAQ,MAAM;AAAA,IAC3BA,EAAQ;AAAA,EAAA,EACP,OAAOhD,CAAQ;AAEjB,EAAAF,EAAM,mBAAmBM,EAAK,KAAK,GAAG,CAAC,GAEvCE,EAAa,gBAAgBF,CAAI;AAClC;"}
|
|
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;AAAA,EAAA;AAEJ;AAEA,SAASU,EAAmBK,GAAeT,GAAiC;AAC3E,QAAMU,wBAAiB,IAAA,GACjBC,IAAWX,EAAM,IAAIS,CAAK;AAEhC,MAAIE,MAAa;AAChB,UAAM,IAAI,M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