@anvil-di/anvil-unplugin 0.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js ADDED
@@ -0,0 +1,289 @@
1
+ /**
2
+ * `@anvil-di/anvil-unplugin` — runs anvil's Rust codegen as part of any bundler's
3
+ * pipeline. One adapter; every bundler (Vite, Rollup, Webpack, Rspack,
4
+ * esbuild) via [unplugin](https://github.com/unjs/unplugin).
5
+ *
6
+ * The plugin invokes the `anvil` CLI binary on:
7
+ * - `buildStart` (once at the beginning of every build)
8
+ * - `watchChange` (debounced, when any source `.ts` is edited in dev)
9
+ *
10
+ * It emits the generated `*.anvil.ts` files alongside their source
11
+ * components — same shape as running `anvil build` manually. The
12
+ * bundler's normal TS pipeline picks them up.
13
+ *
14
+ * @example
15
+ * ```ts
16
+ * // vite.config.ts
17
+ * import anvil from "@anvil-di/anvil-unplugin/vite";
18
+ *
19
+ * export default defineConfig({
20
+ * plugins: [anvil()],
21
+ * });
22
+ * ```
23
+ */
24
+ import { execFile } from "node:child_process";
25
+ import { promisify } from "node:util";
26
+ import path from "node:path";
27
+ import { readdirSync, readFileSync, statSync, writeFileSync, existsSync, mkdirSync, } from "node:fs";
28
+ import { createUnplugin } from "unplugin";
29
+ import { resolveBinaryPath, unresolvableBinaryError } from "@anvil-di/anvil-cli";
30
+ import { compile as wasmCompile } from "@anvil-di/anvil-codegen-wasm";
31
+ const execFileAsync = promisify(execFile);
32
+ /**
33
+ * The unplugin factory. Each per-bundler entry point (`/vite`,
34
+ * `/rollup`, etc.) just calls `anvilUnplugin.<name>(options)` to get a
35
+ * bundler-specific plugin object.
36
+ */
37
+ export const anvilUnplugin = createUnplugin((rawOptions) => {
38
+ // Default `cli` to whatever `@anvil-di/anvil-cli` resolves at runtime (the
39
+ // matching `@anvil-di/anvil-cli-<platform>-<arch>` package, or the
40
+ // `ANVIL_CLI_BIN` env override). This is the recommended path for
41
+ // npm-distributed users; explicit `cli:` overrides take priority
42
+ // for monorepo dev where the binary lives in `target/release`.
43
+ const resolvedCli = rawOptions?.cli ?? resolveBinaryPath();
44
+ const mode = rawOptions?.mode ?? "native";
45
+ const options = {
46
+ cli: resolvedCli,
47
+ debounceMs: rawOptions?.debounceMs ?? 100,
48
+ include: rawOptions?.include ?? ["**/*.ts"],
49
+ mode,
50
+ entries: rawOptions?.entries,
51
+ tsconfig: rawOptions?.tsconfig,
52
+ rootDir: rawOptions?.rootDir,
53
+ preBuild: rawOptions?.preBuild,
54
+ postBuild: rawOptions?.postBuild,
55
+ };
56
+ let pending;
57
+ let inFlight;
58
+ // Files that changed during the current debounce window.
59
+ let pendingChanges = new Set();
60
+ async function runCodegenOnce() {
61
+ // Coalesce concurrent invocations: the second caller awaits the
62
+ // first's in-flight Promise rather than spawning a duplicate
63
+ // `anvil build`.
64
+ if (inFlight !== undefined) {
65
+ return inFlight;
66
+ }
67
+ inFlight = (async () => {
68
+ try {
69
+ if (options.mode === "wasm") {
70
+ await runWasmBuild(options);
71
+ }
72
+ else {
73
+ await invokeBuild(options);
74
+ }
75
+ }
76
+ finally {
77
+ inFlight = undefined;
78
+ }
79
+ })();
80
+ return inFlight;
81
+ }
82
+ // Run hooks triggered by a set of changed files.
83
+ // Pre-build hooks run first; if any ran, anvil build + all post-build
84
+ // hooks follow. If none ran, only the post-build hooks that opt-in run.
85
+ async function runHooksForChanges(changedFiles) {
86
+ const preBuildHooks = options.preBuild ?? [];
87
+ const postBuildHooks = options.postBuild ?? [];
88
+ const preBuildToRun = preBuildHooks.filter((h) => h.shouldRerun(changedFiles));
89
+ for (const hook of preBuildToRun) {
90
+ await hook.run();
91
+ }
92
+ if (preBuildToRun.length > 0) {
93
+ await runCodegenOnce();
94
+ for (const hook of postBuildHooks) {
95
+ await hook.run();
96
+ }
97
+ }
98
+ else {
99
+ for (const hook of postBuildHooks.filter((h) => h.shouldRerun(changedFiles))) {
100
+ await hook.run();
101
+ }
102
+ }
103
+ }
104
+ function scheduleRebuild(changedFile) {
105
+ pendingChanges.add(changedFile);
106
+ if (pending !== undefined) {
107
+ clearTimeout(pending);
108
+ }
109
+ pending = setTimeout(() => {
110
+ pending = undefined;
111
+ const files = [...pendingChanges];
112
+ pendingChanges = new Set();
113
+ // Errors in watch mode are reported to stderr; we don't crash
114
+ // the dev server.
115
+ void runHooksForChanges(files).catch(() => { });
116
+ }, options.debounceMs);
117
+ }
118
+ return {
119
+ name: "anvil-unplugin",
120
+ // unplugin's universal hooks. Each bundler maps these onto its
121
+ // own lifecycle (Vite's `buildStart`, Webpack's tap, etc.).
122
+ async buildStart() {
123
+ // Execution order: preBuild hooks → anvil build → postBuild hooks.
124
+ // Fail fast on the first error so the bundler surfaces the diagnostic.
125
+ for (const hook of options.preBuild ?? []) {
126
+ await hook.run();
127
+ }
128
+ await runCodegenOnce();
129
+ for (const hook of options.postBuild ?? []) {
130
+ await hook.run();
131
+ }
132
+ },
133
+ watchChange(id) {
134
+ // Skip our own output so we don't infinite-loop.
135
+ if (id.endsWith(".anvil.ts")) {
136
+ return;
137
+ }
138
+ if (!id.endsWith(".ts") && !id.endsWith(".tsx")) {
139
+ return;
140
+ }
141
+ scheduleRebuild(id);
142
+ },
143
+ };
144
+ });
145
+ async function invokeBuild(options) {
146
+ if (options.cli === null) {
147
+ throw new Error(unresolvableBinaryError());
148
+ }
149
+ const cli = options.cli;
150
+ // The CLI accepts a single --entry per invocation. When the user
151
+ // supplies multiple, we spawn once per entry — concurrency is fine
152
+ // because each entry's output file is co-located with that entry,
153
+ // so writes don't race.
154
+ const tsconfigArgs = options.tsconfig === undefined ? [] : ["--tsconfig", options.tsconfig];
155
+ if (options.entries === undefined || options.entries.length === 0) {
156
+ // Let the CLI auto-discover from `anvil.config.json` /
157
+ // `package.json#anvil`.
158
+ await execFileAsync(cli, ["build", ...tsconfigArgs]);
159
+ return;
160
+ }
161
+ await Promise.all(options.entries.map((entry) => execFileAsync(cli, [
162
+ "build",
163
+ "--entry",
164
+ path.resolve(entry),
165
+ ...tsconfigArgs,
166
+ ])));
167
+ }
168
+ /**
169
+ * M13: in-process codegen via `@anvil-di/anvil-codegen-wasm`.
170
+ *
171
+ * Reads every `.ts` / `.tsx` file under `rootDir` (defaulting to the
172
+ * first entry's parent dir) into an in-memory file map, hands it to
173
+ * the WASM compile function, and writes the emitted dagger files
174
+ * back to disk co-located with their components — same layout the
175
+ * native CLI produces, just without the `spawnSync` round-trip.
176
+ *
177
+ * Diagnostics are written to stderr in the same format as `anvil
178
+ * check`. Future revisions of this hook will route them through the
179
+ * unplugin context's `this.error` / `this.warn` for inline overlay
180
+ * support, but those APIs differ across bundlers and stderr is the
181
+ * lowest-common-denominator surface that works everywhere today.
182
+ */
183
+ async function runWasmBuild(options) {
184
+ if (options.entries === undefined || options.entries.length === 0) {
185
+ throw new Error("@anvil-di/anvil-unplugin: `mode: \"wasm\"` requires explicit `entries:` paths " +
186
+ "(auto-discovery from anvil.config.json isn't wired through the WASM " +
187
+ "build yet). Specify `entries: ['src/**/*-component.ts']` or similar.");
188
+ }
189
+ const root = options.rootDir ?? path.dirname(path.resolve(options.entries[0]));
190
+ const files = collectSourceFiles(root);
191
+ // Also pull in the `@anvil-di/anvil` runtime so bare-specifier imports
192
+ // resolve. Locate via require.resolve so we don't hardcode the path.
193
+ try {
194
+ const anvilPkg = require.resolve("@anvil-di/anvil/package.json");
195
+ const anvilDir = path.dirname(anvilPkg);
196
+ addRecursive(anvilDir, files);
197
+ }
198
+ catch {
199
+ // The `@anvil-di/anvil` runtime isn't installed — caller probably stubbed it
200
+ // themselves under a different name; the WASM resolver will
201
+ // surface a `BareNotFound` if anything's actually missing.
202
+ }
203
+ const aliases = options.tsconfig === undefined ? [] : tsconfigPathsFrom(options.tsconfig);
204
+ for (const entry of options.entries) {
205
+ const entryAbs = path.resolve(entry);
206
+ const result = wasmCompile({
207
+ entryPath: entryAbs,
208
+ files,
209
+ aliases,
210
+ version: "0.0.1-wasm",
211
+ });
212
+ for (const diag of result.diagnostics) {
213
+ process.stderr.write(`anvil: ${diag.code}: ${diag.summary}\n`);
214
+ process.stderr.write(` at ${diag.primary.path}:${diag.primary.start}\n`);
215
+ }
216
+ for (const emitted of result.emittedFiles) {
217
+ const dir = path.dirname(emitted.path);
218
+ if (!existsSync(dir))
219
+ mkdirSync(dir, { recursive: true });
220
+ writeFileSync(emitted.path, emitted.contents, "utf8");
221
+ }
222
+ }
223
+ }
224
+ /**
225
+ * Read every `.ts` / `.tsx` file under `root` into a map keyed by
226
+ * absolute path. Skips `node_modules` (those entries are added
227
+ * separately when the host's `@anvil-di/anvil` runtime is located).
228
+ */
229
+ function collectSourceFiles(root) {
230
+ const out = {};
231
+ addRecursive(root, out);
232
+ return out;
233
+ }
234
+ function addRecursive(dir, out) {
235
+ let entries;
236
+ try {
237
+ entries = readdirSync(dir, { withFileTypes: true });
238
+ }
239
+ catch {
240
+ return;
241
+ }
242
+ for (const entry of entries) {
243
+ if (entry.name === "node_modules" || entry.name.startsWith("."))
244
+ continue;
245
+ const abs = path.join(dir, entry.name);
246
+ if (entry.isDirectory()) {
247
+ addRecursive(abs, out);
248
+ continue;
249
+ }
250
+ if (entry.isFile() &&
251
+ (abs.endsWith(".ts") || abs.endsWith(".tsx") || abs.endsWith(".d.ts"))) {
252
+ try {
253
+ out[abs] = readFileSync(abs, "utf8");
254
+ }
255
+ catch {
256
+ // Skip unreadable files; the resolver will surface them if they
257
+ // were actually needed.
258
+ }
259
+ }
260
+ }
261
+ // Avoid lint-warn for unused statSync; the import is documented as
262
+ // available for future host-specific filesystem probes.
263
+ void statSync;
264
+ }
265
+ /**
266
+ * Pull `compilerOptions.paths` aliases out of a tsconfig.json on
267
+ * disk. Best-effort — bad JSON or missing paths field returns an
268
+ * empty list rather than throwing.
269
+ */
270
+ function tsconfigPathsFrom(tsconfigPath) {
271
+ try {
272
+ const raw = readFileSync(tsconfigPath, "utf8");
273
+ // Strip simple block comments — tsconfig.json technically
274
+ // permits them. Not a full JSONC parser; covers the 99% case.
275
+ const cleaned = raw.replace(/\/\*[\s\S]*?\*\//g, "");
276
+ const cfg = JSON.parse(cleaned);
277
+ const baseUrl = cfg.compilerOptions?.baseUrl ?? ".";
278
+ const baseDir = path.resolve(path.dirname(tsconfigPath), baseUrl);
279
+ const paths = cfg.compilerOptions?.paths ?? {};
280
+ return Object.entries(paths).flatMap(([pattern, targets]) => targets.length === 0
281
+ ? []
282
+ : [{ pattern, target: targets[0], baseDir }]);
283
+ }
284
+ catch {
285
+ return [];
286
+ }
287
+ }
288
+ export default anvilUnplugin;
289
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;GAsBG;AAEH,OAAO,EAAE,QAAQ,EAAE,MAAM,oBAAoB,CAAC;AAC9C,OAAO,EAAE,SAAS,EAAE,MAAM,WAAW,CAAC;AACtC,OAAO,IAAI,MAAM,WAAW,CAAC;AAC7B,OAAO,EACL,WAAW,EACX,YAAY,EACZ,QAAQ,EACR,aAAa,EACb,UAAU,EACV,SAAS,GACV,MAAM,SAAS,CAAC;AACjB,OAAO,EAAE,cAAc,EAAyB,MAAM,UAAU,CAAC;AACjE,OAAO,EAAE,iBAAiB,EAAE,uBAAuB,EAAE,MAAM,qBAAqB,CAAC;AACjF,OAAO,EAAE,OAAO,IAAI,WAAW,EAAE,MAAM,8BAA8B,CAAC;AAEtE,MAAM,aAAa,GAAG,SAAS,CAAC,QAAQ,CAAC,CAAC;AA8H1C;;;;GAIG;AACH,MAAM,CAAC,MAAM,aAAa,GACxB,cAAc,CAAiC,CAAC,UAAU,EAAE,EAAE;IAC5D,2EAA2E;IAC3E,mEAAmE;IACnE,kEAAkE;IAClE,iEAAiE;IACjE,+DAA+D;IAC/D,MAAM,WAAW,GAAG,UAAU,EAAE,GAAG,IAAI,iBAAiB,EAAE,CAAC;IAC3D,MAAM,IAAI,GAAsB,UAAU,EAAE,IAAI,IAA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M,GAAG,GAAG,IAAI,CAAC,KAAK,CAAC,OAAO,CAK7B,CAAC;QACF,MAAM,OAAO,GAAG,GAAG,CAAC,eAAe,EAAE,OAAO,IAAI,GAAG,CAAC;QACpD,MAAM,OAAO,GAAG,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,OAAO,CAAC,YAAY,CAAC,EAAE,OAAO,CAAC,CAAC;QAClE,MAAM,KAAK,GAAG,GAAG,CAAC,eAAe,EAAE,KAAK,IAAI,EAAE,CAAC;QAC/C,OAAO,MAAM,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,OAAO,EAAE,OAAO,CAAC,EAAE,EAAE,CAC1D,OAAO,CAAC,MAAM,KAAK,CAAC;YAClB,CAAC,CAAC,EAAE;YACJ,CAAC,CAAC,CAAC,EAAE,OAAO,EAAE,MAAM,EAAE,OAAO,CAAC,CAAC,CAAE,EAAE,OAAO,EAAE,CAAC,CAChD,CAAC;IACJ,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,EAAE,CAAC;IACZ,CAAC;AACH,CAAC;AAED,eAAe,aAAa,CAAC"}
@@ -0,0 +1,5 @@
1
+ import { type AnvilPluginOptions } from "./index.js";
2
+ /** Rollup plugin form of `@anvil-di/anvil-unplugin`. See the package README. */
3
+ declare const rollupPlugin: (options?: AnvilPluginOptions) => unknown;
4
+ export default rollupPlugin;
5
+ //# sourceMappingURL=rollup.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"rollup.d.ts","sourceRoot":"","sources":["../src/rollup.ts"],"names":[],"mappings":"AAAA,OAAO,EAAiB,KAAK,kBAAkB,EAAE,MAAM,YAAY,CAAC;AAEpE,gFAAgF;AAChF,QAAA,MAAM,YAAY,EAA2B,CAAC,OAAO,CAAC,EAAE,kBAAkB,KAAK,OAAO,CAAC;AACvF,eAAe,YAAY,CAAC"}
package/dist/rollup.js ADDED
@@ -0,0 +1,5 @@
1
+ import { anvilUnplugin } from "./index.js";
2
+ /** Rollup plugin form of `@anvil-di/anvil-unplugin`. See the package README. */
3
+ const rollupPlugin = anvilUnplugin.rollup;
4
+ export default rollupPlugin;
5
+ //# sourceMappingURL=rollup.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"rollup.js","sourceRoot":"","sources":["../src/rollup.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAA2B,MAAM,YAAY,CAAC;AAEpE,gFAAgF;AAChF,MAAM,YAAY,GAAG,aAAa,CAAC,MAAmD,CAAC;AACvF,eAAe,YAAY,CAAC"}
@@ -0,0 +1,5 @@
1
+ import { type AnvilPluginOptions } from "./index.js";
2
+ /** Rspack plugin form of `@anvil-di/anvil-unplugin`. See the package README. */
3
+ declare const rspackPlugin: (options?: AnvilPluginOptions) => unknown;
4
+ export default rspackPlugin;
5
+ //# sourceMappingURL=rspack.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"rspack.d.ts","sourceRoot":"","sources":["../src/rspack.ts"],"names":[],"mappings":"AAAA,OAAO,EAAiB,KAAK,kBAAkB,EAAE,MAAM,YAAY,CAAC;AAEpE,gFAAgF;AAChF,QAAA,MAAM,YAAY,EAA2B,CAAC,OAAO,CAAC,EAAE,kBAAkB,KAAK,OAAO,CAAC;AACvF,eAAe,YAAY,CAAC"}
package/dist/rspack.js ADDED
@@ -0,0 +1,5 @@
1
+ import { anvilUnplugin } from "./index.js";
2
+ /** Rspack plugin form of `@anvil-di/anvil-unplugin`. See the package README. */
3
+ const rspackPlugin = anvilUnplugin.rspack;
4
+ export default rspackPlugin;
5
+ //# sourceMappingURL=rspack.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"rspack.js","sourceRoot":"","sources":["../src/rspack.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAA2B,MAAM,YAAY,CAAC;AAEpE,gFAAgF;AAChF,MAAM,YAAY,GAAG,aAAa,CAAC,MAAmD,CAAC;AACvF,eAAe,YAAY,CAAC"}
package/dist/vite.d.ts ADDED
@@ -0,0 +1,18 @@
1
+ import { type AnvilPluginOptions } from "./index.js";
2
+ /**
3
+ * Vite plugin that runs anvil codegen at build start and on file
4
+ * changes in dev. Equivalent to `anvil build` integrated into the
5
+ * normal Vite pipeline.
6
+ *
7
+ * @example
8
+ * ```ts
9
+ * import anvil from "@anvil-di/anvil-unplugin/vite";
10
+ *
11
+ * export default defineConfig({
12
+ * plugins: [anvil({ tsconfig: "./tsconfig.json" })],
13
+ * });
14
+ * ```
15
+ */
16
+ declare const vitePlugin: (options?: AnvilPluginOptions) => unknown;
17
+ export default vitePlugin;
18
+ //# sourceMappingURL=vite.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"vite.d.ts","sourceRoot":"","sources":["../src/vite.ts"],"names":[],"mappings":"AAAA,OAAO,EAAiB,KAAK,kBAAkB,EAAE,MAAM,YAAY,CAAC;AAEpE;;;;;;;;;;;;;GAaG;AACH,QAAA,MAAM,UAAU,EAAyB,CAAC,OAAO,CAAC,EAAE,kBAAkB,KAAK,OAAO,CAAC;AACnF,eAAe,UAAU,CAAC"}
package/dist/vite.js ADDED
@@ -0,0 +1,18 @@
1
+ import { anvilUnplugin } from "./index.js";
2
+ /**
3
+ * Vite plugin that runs anvil codegen at build start and on file
4
+ * changes in dev. Equivalent to `anvil build` integrated into the
5
+ * normal Vite pipeline.
6
+ *
7
+ * @example
8
+ * ```ts
9
+ * import anvil from "@anvil-di/anvil-unplugin/vite";
10
+ *
11
+ * export default defineConfig({
12
+ * plugins: [anvil({ tsconfig: "./tsconfig.json" })],
13
+ * });
14
+ * ```
15
+ */
16
+ const vitePlugin = anvilUnplugin.vite;
17
+ export default vitePlugin;
18
+ //# sourceMappingURL=vite.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"vite.js","sourceRoot":"","sources":["../src/vite.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAA2B,MAAM,YAAY,CAAC;AAEpE;;;;;;;;;;;;;GAaG;AACH,MAAM,UAAU,GAAG,aAAa,CAAC,IAAiD,CAAC;AACnF,eAAe,UAAU,CAAC"}
@@ -0,0 +1,5 @@
1
+ import { type AnvilPluginOptions } from "./index.js";
2
+ /** Webpack plugin form of `@anvil-di/anvil-unplugin`. See the package README. */
3
+ declare const webpackPlugin: (options?: AnvilPluginOptions) => unknown;
4
+ export default webpackPlugin;
5
+ //# sourceMappingURL=webpack.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"webpack.d.ts","sourceRoot":"","sources":["../src/webpack.ts"],"names":[],"mappings":"AAAA,OAAO,EAAiB,KAAK,kBAAkB,EAAE,MAAM,YAAY,CAAC;AAEpE,iFAAiF;AACjF,QAAA,MAAM,aAAa,EAA4B,CAAC,OAAO,CAAC,EAAE,kBAAkB,KAAK,OAAO,CAAC;AACzF,eAAe,aAAa,CAAC"}
@@ -0,0 +1,5 @@
1
+ import { anvilUnplugin } from "./index.js";
2
+ /** Webpack plugin form of `@anvil-di/anvil-unplugin`. See the package README. */
3
+ const webpackPlugin = anvilUnplugin.webpack;
4
+ export default webpackPlugin;
5
+ //# sourceMappingURL=webpack.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"webpack.js","sourceRoot":"","sources":["../src/webpack.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAA2B,MAAM,YAAY,CAAC;AAEpE,iFAAiF;AACjF,MAAM,aAAa,GAAG,aAAa,CAAC,OAAoD,CAAC;AACzF,eAAe,aAAa,CAAC"}
package/package.json ADDED
@@ -0,0 +1,58 @@
1
+ {
2
+ "name": "@anvil-di/anvil-unplugin",
3
+ "version": "0.0.2",
4
+ "description": "Run anvil codegen as part of your bundler's normal pipeline. One plugin, every bundler (Vite, Rollup, Webpack, Rspack, esbuild) via unplugin.",
5
+ "license": "Apache-2.0",
6
+ "type": "module",
7
+ "main": "./dist/index.js",
8
+ "module": "./dist/index.js",
9
+ "types": "./dist/index.d.ts",
10
+ "exports": {
11
+ ".": {
12
+ "types": "./dist/index.d.ts",
13
+ "import": "./dist/index.js"
14
+ },
15
+ "./vite": {
16
+ "types": "./dist/vite.d.ts",
17
+ "import": "./dist/vite.js"
18
+ },
19
+ "./rollup": {
20
+ "types": "./dist/rollup.d.ts",
21
+ "import": "./dist/rollup.js"
22
+ },
23
+ "./webpack": {
24
+ "types": "./dist/webpack.d.ts",
25
+ "import": "./dist/webpack.js"
26
+ },
27
+ "./rspack": {
28
+ "types": "./dist/rspack.d.ts",
29
+ "import": "./dist/rspack.js"
30
+ },
31
+ "./esbuild": {
32
+ "types": "./dist/esbuild.d.ts",
33
+ "import": "./dist/esbuild.js"
34
+ }
35
+ },
36
+ "files": [
37
+ "dist",
38
+ "src"
39
+ ],
40
+ "dependencies": {
41
+ "unplugin": "^1.16.0",
42
+ "@anvil-di/anvil-codegen-wasm": "0.0.2",
43
+ "@anvil-di/anvil-cli": "0.0.2"
44
+ },
45
+ "devDependencies": {
46
+ "@types/node": "^22.10.0",
47
+ "typescript": "^5.7.2",
48
+ "vitest": "^2.1.8"
49
+ },
50
+ "publishConfig": {
51
+ "access": "public"
52
+ },
53
+ "scripts": {
54
+ "build": "tsc -p tsconfig.json",
55
+ "typecheck": "tsc -p tsconfig.json --noEmit",
56
+ "test": "vitest run"
57
+ }
58
+ }
package/src/esbuild.ts ADDED
@@ -0,0 +1,5 @@
1
+ import { anvilUnplugin, type AnvilPluginOptions } from "./index.js";
2
+
3
+ /** esbuild plugin form of `@anvil-di/anvil-unplugin`. See the package README. */
4
+ const esbuildPlugin = anvilUnplugin.esbuild as (options?: AnvilPluginOptions) => unknown;
5
+ export default esbuildPlugin;