@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/LICENSE +201 -0
- package/README.md +83 -0
- package/dist/esbuild.d.ts +5 -0
- package/dist/esbuild.d.ts.map +1 -0
- package/dist/esbuild.js +5 -0
- package/dist/esbuild.js.map +1 -0
- package/dist/index.d.ts +153 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +289 -0
- package/dist/index.js.map +1 -0
- package/dist/rollup.d.ts +5 -0
- package/dist/rollup.d.ts.map +1 -0
- package/dist/rollup.js +5 -0
- package/dist/rollup.js.map +1 -0
- package/dist/rspack.d.ts +5 -0
- package/dist/rspack.d.ts.map +1 -0
- package/dist/rspack.js +5 -0
- package/dist/rspack.js.map +1 -0
- package/dist/vite.d.ts +18 -0
- package/dist/vite.d.ts.map +1 -0
- package/dist/vite.js +18 -0
- package/dist/vite.js.map +1 -0
- package/dist/webpack.d.ts +5 -0
- package/dist/webpack.d.ts.map +1 -0
- package/dist/webpack.js +5 -0
- package/dist/webpack.js.map +1 -0
- package/package.json +58 -0
- package/src/esbuild.ts +5 -0
- package/src/index.test.ts +347 -0
- package/src/index.ts +468 -0
- package/src/rollup.ts +5 -0
- package/src/rspack.ts +5 -0
- package/src/vite.ts +18 -0
- package/src/webpack.ts +5 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or
|
|
95
|
+
Derivative Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work,
|
|
103
|
+
excluding those notices that do not pertain to any part of
|
|
104
|
+
the Derivative Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
|
108
|
+
include a readable copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
|
111
|
+
of the following places: within a NOTICE text file distributed
|
|
112
|
+
as part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and
|
|
117
|
+
do not modify the License. You may add Your own attribution
|
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
+
that such additional attribution notices cannot be construed
|
|
121
|
+
as modifying the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions
|
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
+
the conditions stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
with Licensor regarding such Contributions.
|
|
137
|
+
|
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for describing the origin of the Work and
|
|
141
|
+
reproducing the content of the NOTICE file.
|
|
142
|
+
|
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
|
152
|
+
|
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
|
158
|
+
incidental, or consequential damages of any character arising as a
|
|
159
|
+
result of this License or out of the use or inability to use the
|
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
+
other commercial damages or losses), even if such Contributor
|
|
163
|
+
has been advised of the possibility of such damages.
|
|
164
|
+
|
|
165
|
+
9. Accepting Warranty or Support. While redistributing the Work or
|
|
166
|
+
Derivative Works thereof, You may choose to offer, and charge a
|
|
167
|
+
fee for, acceptance of support, warranty, indemnity, or other
|
|
168
|
+
liability obligations and/or rights consistent with this License.
|
|
169
|
+
However, in accepting such obligations, You may act only on Your
|
|
170
|
+
own behalf and on Your sole responsibility, not on behalf of any
|
|
171
|
+
other Contributor, and only if You agree to indemnify, defend,
|
|
172
|
+
and hold each Contributor harmless for any liability incurred by,
|
|
173
|
+
or claims asserted against, such Contributor by reason of your
|
|
174
|
+
accepting any such warranty or support.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
|
177
|
+
|
|
178
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
179
|
+
|
|
180
|
+
To apply the Apache License to your work, attach the following
|
|
181
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
182
|
+
replaced with your own identifying information. (Don't include
|
|
183
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
184
|
+
comment syntax for the file format. We also recommend that a
|
|
185
|
+
file or class name and description of purpose be included on the
|
|
186
|
+
same "printed page" as the copyright notice for easier
|
|
187
|
+
identification within third-party archives.
|
|
188
|
+
|
|
189
|
+
Copyright 2026 typescript-di contributors
|
|
190
|
+
|
|
191
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
192
|
+
you may not use this file except in compliance with the License.
|
|
193
|
+
You may obtain a copy of the License at
|
|
194
|
+
|
|
195
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
196
|
+
|
|
197
|
+
Unless required by applicable law or agreed to in writing, software
|
|
198
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
199
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
200
|
+
implied. See the License for the specific language governing
|
|
201
|
+
permissions and limitations under the License.
|
package/README.md
ADDED
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
# `@msulak/anvil-unplugin`
|
|
2
|
+
|
|
3
|
+
Run [`@msulak/anvil`](https://github.com/msulak13/tsdi) codegen as part of your bundler's normal pipeline. Built on [`unplugin`](https://github.com/unjs/unplugin) so a single adapter works across Vite, Rollup, Webpack, Rspack, and esbuild.
|
|
4
|
+
|
|
5
|
+
## Why
|
|
6
|
+
|
|
7
|
+
Today's flow without the plugin:
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
anvil build # regenerate every .anvil.ts
|
|
11
|
+
vite build # bundle
|
|
12
|
+
```
|
|
13
|
+
|
|
14
|
+
That gets stale fast in dev — every edit to a `@Module` requires re-running `anvil build` before `vite dev`'s HMR will see the change. With the plugin:
|
|
15
|
+
|
|
16
|
+
```ts
|
|
17
|
+
// vite.config.ts
|
|
18
|
+
import anvil from "@msulak/anvil-unplugin/vite";
|
|
19
|
+
|
|
20
|
+
export default defineConfig({
|
|
21
|
+
plugins: [anvil()],
|
|
22
|
+
});
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
Codegen runs on `buildStart` and on every relevant file change in dev (debounced). Validation errors flow through the bundler's normal error pipeline — Vite's overlay, Rollup's warning channel, Webpack's stats output.
|
|
26
|
+
|
|
27
|
+
## Per-bundler imports
|
|
28
|
+
|
|
29
|
+
```ts
|
|
30
|
+
import anvil from "@msulak/anvil-unplugin/vite"; // Vite plugin
|
|
31
|
+
import anvil from "@msulak/anvil-unplugin/rollup"; // Rollup plugin
|
|
32
|
+
import anvil from "@msulak/anvil-unplugin/webpack"; // Webpack plugin
|
|
33
|
+
import anvil from "@msulak/anvil-unplugin/rspack"; // Rspack plugin
|
|
34
|
+
import anvil from "@msulak/anvil-unplugin/esbuild"; // esbuild plugin
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
## Options
|
|
38
|
+
|
|
39
|
+
```ts
|
|
40
|
+
anvil({
|
|
41
|
+
// Component entry files. Defaults to whatever anvil.config.json
|
|
42
|
+
// declares, just like running `anvil build` with no args.
|
|
43
|
+
entries: ["src/**/*-component.ts"],
|
|
44
|
+
|
|
45
|
+
// Forwarded to `anvil build --tsconfig ...`. Lets the resolver honor
|
|
46
|
+
// tsconfig `paths` / `baseUrl` aliases.
|
|
47
|
+
tsconfig: "./tsconfig.json",
|
|
48
|
+
|
|
49
|
+
// Path to the `anvil` binary. Defaults to the native binary resolved
|
|
50
|
+
// via @msulak/anvil-cli's optionalDependencies.
|
|
51
|
+
cli: "/path/to/anvil",
|
|
52
|
+
|
|
53
|
+
// Debounce window for re-running codegen after a file edit (ms).
|
|
54
|
+
// Defaults to 100, matching `anvil watch`.
|
|
55
|
+
debounceMs: 100,
|
|
56
|
+
|
|
57
|
+
// Which codegen backend to use:
|
|
58
|
+
// - "native" (default): spawn the anvil Rust binary
|
|
59
|
+
// - "wasm": run in-process via @msulak/anvil-codegen-wasm (no spawn overhead)
|
|
60
|
+
mode: "native",
|
|
61
|
+
});
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
## How it works
|
|
65
|
+
|
|
66
|
+
The plugin invokes the `anvil` CLI as a child process (native mode) or runs the WASM pipeline in-process (wasm mode):
|
|
67
|
+
|
|
68
|
+
- **`buildStart`** — runs once at the beginning of every build, blocking the bundler until codegen finishes. If `anvil build` fails, the bundler's error handling surfaces the diagnostic.
|
|
69
|
+
- **`watchChange`** — fires on every source `.ts` / `.tsx` edit in dev. Schedules a debounced rebuild; concurrent edits collapse into a single re-run. `.anvil.ts` outputs are ignored to avoid self-trigger loops.
|
|
70
|
+
|
|
71
|
+
The bundler's normal TypeScript pipeline then picks up the freshly generated `*.anvil.ts` files. There's no special TS plugin; `.anvil.ts` is just `.ts`.
|
|
72
|
+
|
|
73
|
+
## How the binary gets there
|
|
74
|
+
|
|
75
|
+
`@msulak/anvil-unplugin` depends on [`@msulak/anvil-cli`](../anvil-cli/README.md), which is the npm launcher for anvil's native Rust binary. `@msulak/anvil-cli` declares one `optionalDependencies` entry per supported platform (`@msulak/anvil-cli-linux-x64`, `@msulak/anvil-cli-darwin-arm64`, etc.); npm installs **only** the matching one based on `os`/`cpu` filters. At runtime the unplugin calls `resolveBinaryPath()` from `@msulak/anvil-cli` to find the binary — no PATH manipulation or `cargo install` required.
|
|
76
|
+
|
|
77
|
+
The same `cli` option still works if you want to point at a custom build (a `cargo build --release`'d binary outside `node_modules`, for example).
|
|
78
|
+
|
|
79
|
+
## Limitations (v0.2)
|
|
80
|
+
|
|
81
|
+
- In native mode the plugin spawns one process per build. Hot reload is fast (~50–200ms for a typical project); use `mode: "wasm"` for in-process codegen without the spawn overhead.
|
|
82
|
+
- Diagnostics flow as raw `anvil` stderr through the bundler's error API. Future work: parse the structured output and emit per-file diagnostics with source maps.
|
|
83
|
+
- Watch granularity is "any `.ts` change re-runs codegen for all configured entries". The CLI's M5 watch mode does smarter per-entry source-closure tracking; future versions of this plugin should reuse that data instead of duplicating its own filter.
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { type AnvilPluginOptions } from "./index.js";
|
|
2
|
+
/** esbuild plugin form of `@anvil-di/anvil-unplugin`. See the package README. */
|
|
3
|
+
declare const esbuildPlugin: (options?: AnvilPluginOptions) => unknown;
|
|
4
|
+
export default esbuildPlugin;
|
|
5
|
+
//# sourceMappingURL=esbuild.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"esbuild.d.ts","sourceRoot":"","sources":["../src/esbuild.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"}
|
package/dist/esbuild.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"esbuild.js","sourceRoot":"","sources":["../src/esbuild.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/dist/index.d.ts
ADDED
|
@@ -0,0 +1,153 @@
|
|
|
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 { type UnpluginInstance } from "unplugin";
|
|
25
|
+
/**
|
|
26
|
+
* A hook that runs before `anvil build` in the plugin lifecycle.
|
|
27
|
+
*
|
|
28
|
+
* Implement this to perform custom codegen (e.g. `bellowsCodegen()`) before
|
|
29
|
+
* the main anvil compilation step. Returned by factory functions such as
|
|
30
|
+
* `bellowsCodegen` in `@anvil-di/bellows`.
|
|
31
|
+
*/
|
|
32
|
+
export interface PreBuildHook {
|
|
33
|
+
/** Stable identifier, shown in diagnostics. */
|
|
34
|
+
name: string;
|
|
35
|
+
/** Glob patterns whose changes should trigger a re-run in watch mode. */
|
|
36
|
+
watchPatterns: string[];
|
|
37
|
+
/** Return `true` if the hook should re-run given the set of changed files. */
|
|
38
|
+
shouldRerun(changedFiles: string[]): boolean;
|
|
39
|
+
/** Execute the hook; throw to signal failure. */
|
|
40
|
+
run(): Promise<void>;
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* A hook that runs after `anvil build` in the plugin lifecycle.
|
|
44
|
+
* Same shape as `PreBuildHook`; separated by name so callers can keep
|
|
45
|
+
* their intent explicit in the plugin options.
|
|
46
|
+
*/
|
|
47
|
+
export interface PostBuildHook {
|
|
48
|
+
/** Stable identifier, shown in diagnostics. */
|
|
49
|
+
name: string;
|
|
50
|
+
/** Glob patterns whose changes should trigger a re-run in watch mode. */
|
|
51
|
+
watchPatterns: string[];
|
|
52
|
+
/** Return `true` if the hook should re-run given the set of changed files. */
|
|
53
|
+
shouldRerun(changedFiles: string[]): boolean;
|
|
54
|
+
/** Execute the hook; throw to signal failure. */
|
|
55
|
+
run(): Promise<void>;
|
|
56
|
+
}
|
|
57
|
+
/** Plugin options. Every field is optional; sensible defaults match the CLI. */
|
|
58
|
+
export interface AnvilPluginOptions {
|
|
59
|
+
/**
|
|
60
|
+
* Component entry files to (re)generate. Each path is passed to
|
|
61
|
+
* `anvil build --entry <path>`. Defaults to whatever `anvil.config.json`
|
|
62
|
+
* (auto-discovered from the project root) declares — the same logic
|
|
63
|
+
* `anvil build` uses without arguments.
|
|
64
|
+
*/
|
|
65
|
+
entries?: string[];
|
|
66
|
+
/**
|
|
67
|
+
* Path to a `tsconfig.json`. Forwarded to the CLI as `--tsconfig`.
|
|
68
|
+
* Lets the resolver honor `paths` / `baseUrl` aliases.
|
|
69
|
+
*/
|
|
70
|
+
tsconfig?: string;
|
|
71
|
+
/**
|
|
72
|
+
* Path to the `anvil` binary. When unset, the plugin resolves the
|
|
73
|
+
* native binary via the `@anvil-di/anvil-cli` npm launcher — which in turn
|
|
74
|
+
* picks the right per-platform package (`@anvil-di/anvil-cli-linux-x64`,
|
|
75
|
+
* `@anvil-di/anvil-cli-darwin-arm64`, etc.) installed alongside it.
|
|
76
|
+
*
|
|
77
|
+
* Override only when you need to point at a custom build (e.g. a
|
|
78
|
+
* `cargo build`-produced binary outside `node_modules`).
|
|
79
|
+
*/
|
|
80
|
+
cli?: string;
|
|
81
|
+
/**
|
|
82
|
+
* Debounce window (ms) for re-running codegen after a file change in
|
|
83
|
+
* watch mode. Default: 100 — same value `anvil watch` uses for its
|
|
84
|
+
* own filesystem-event debouncing.
|
|
85
|
+
*/
|
|
86
|
+
debounceMs?: number;
|
|
87
|
+
/**
|
|
88
|
+
* Glob patterns the plugin will watch in dev mode. Editing any
|
|
89
|
+
* matching file triggers a debounced rebuild. Defaults to `**\/*.ts`
|
|
90
|
+
* — the codegen's M2 resolver is the layer that decides which files
|
|
91
|
+
* actually feed into a particular component, so over-watching is
|
|
92
|
+
* harmless (extra files just get filtered out by the resolver).
|
|
93
|
+
*/
|
|
94
|
+
include?: string[];
|
|
95
|
+
/**
|
|
96
|
+
* Which codegen backend to use (M13).
|
|
97
|
+
*
|
|
98
|
+
* - `"native"` (default): spawn the `anvil` Rust binary via
|
|
99
|
+
* `@anvil-di/anvil-cli`. Lower steady-state codegen latency, requires the
|
|
100
|
+
* per-platform binary to be installed.
|
|
101
|
+
* - `"wasm"`: run the entire pipeline in-process through
|
|
102
|
+
* `@anvil-di/anvil-codegen-wasm`. No `spawnSync` cost in the bundler hot
|
|
103
|
+
* path, works anywhere V8 runs (Bun, Cloudflare Workers,
|
|
104
|
+
* StackBlitz, etc.). The WASM compile + instantiate happens once
|
|
105
|
+
* on first build (~80-150ms); subsequent builds are direct
|
|
106
|
+
* function calls.
|
|
107
|
+
*
|
|
108
|
+
* The two paths produce byte-identical output for the same input
|
|
109
|
+
* — same parser, same graph builder, same emitter, just sourced
|
|
110
|
+
* from a process spawn vs an in-memory file map.
|
|
111
|
+
*/
|
|
112
|
+
mode?: "native" | "wasm";
|
|
113
|
+
/**
|
|
114
|
+
* For `mode: "wasm"`, the directory whose `.ts` / `.tsx` files
|
|
115
|
+
* should be loaded into the in-memory file map. Defaults to the
|
|
116
|
+
* directory containing the first `entries[0]`'s parent folder.
|
|
117
|
+
* The WASM resolver walks transitively from each entry — extra
|
|
118
|
+
* files in the map are harmless, missing files surface as a
|
|
119
|
+
* diagnostic. Set this when your sources live somewhere other
|
|
120
|
+
* than the entry's own subtree.
|
|
121
|
+
*/
|
|
122
|
+
rootDir?: string;
|
|
123
|
+
/**
|
|
124
|
+
* Hooks that run **before** `anvil build` on every `buildStart`.
|
|
125
|
+
*
|
|
126
|
+
* In watch mode a hook re-runs when `hook.shouldRerun(changedFiles)`
|
|
127
|
+
* returns `true`. If any pre-build hook re-runs, `anvil build` and
|
|
128
|
+
* all post-build hooks are also re-run.
|
|
129
|
+
*
|
|
130
|
+
* Hooks run in array order; the first failure aborts the build.
|
|
131
|
+
*/
|
|
132
|
+
preBuild?: PreBuildHook[];
|
|
133
|
+
/**
|
|
134
|
+
* Hooks that run **after** `anvil build` on every `buildStart`.
|
|
135
|
+
*
|
|
136
|
+
* In watch mode a post-build hook re-runs when any pre-build hook
|
|
137
|
+
* re-ran (because the build output may have changed), or when
|
|
138
|
+
* `hook.shouldRerun(changedFiles)` returns `true` and no pre-build
|
|
139
|
+
* hook ran.
|
|
140
|
+
*
|
|
141
|
+
* Hooks run in array order; the first failure aborts the post-build
|
|
142
|
+
* phase.
|
|
143
|
+
*/
|
|
144
|
+
postBuild?: PostBuildHook[];
|
|
145
|
+
}
|
|
146
|
+
/**
|
|
147
|
+
* The unplugin factory. Each per-bundler entry point (`/vite`,
|
|
148
|
+
* `/rollup`, etc.) just calls `anvilUnplugin.<name>(options)` to get a
|
|
149
|
+
* bundler-specific plugin object.
|
|
150
|
+
*/
|
|
151
|
+
export declare const anvilUnplugin: UnpluginInstance<AnvilPluginOptions | undefined, false>;
|
|
152
|
+
export default anvilUnplugin;
|
|
153
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;GAsBG;AAaH,OAAO,EAAkB,KAAK,gBAAgB,EAAE,MAAM,UAAU,CAAC;AAMjE;;;;;;GAMG;AACH,MAAM,WAAW,YAAY;IAC3B,+CAA+C;IAC/C,IAAI,EAAE,MAAM,CAAC;IACb,yEAAyE;IACzE,aAAa,EAAE,MAAM,EAAE,CAAC;IACxB,8EAA8E;IAC9E,WAAW,CAAC,YAAY,EAAE,MAAM,EAAE,GAAG,OAAO,CAAC;IAC7C,iDAAiD;IACjD,GAAG,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;CACtB;AAED;;;;GAIG;AACH,MAAM,WAAW,aAAa;IAC5B,+CAA+C;IAC/C,IAAI,EAAE,MAAM,CAAC;IACb,yEAAyE;IACzE,aAAa,EAAE,MAAM,EAAE,CAAC;IACxB,8EAA8E;IAC9E,WAAW,CAAC,YAAY,EAAE,MAAM,EAAE,GAAG,OAAO,CAAC;IAC7C,iDAAiD;IACjD,GAAG,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;CACtB;AAED,gFAAgF;AAChF,MAAM,WAAW,kBAAkB;IACjC;;;;;OAKG;IACH,OAAO,CAAC,EAAE,MAAM,EAAE,CAAC;IACnB;;;OAGG;IACH,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB;;;;;;;;OAQG;IACH,GAAG,CAAC,EAAE,MAAM,CAAC;IACb;;;;OAIG;IACH,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB;;;;;;OAMG;IACH,OAAO,CAAC,EAAE,MAAM,EAAE,CAAC;IACnB;;;;;;;;;;;;;;;;OAgBG;IACH,IAAI,CAAC,EAAE,QAAQ,GAAG,MAAM,CAAC;IACzB;;;;;;;;OAQG;IACH,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB;;;;;;;;OAQG;IACH,QAAQ,CAAC,EAAE,YAAY,EAAE,CAAC;IAC1B;;;;;;;;;;OAUG;IACH,SAAS,CAAC,EAAE,aAAa,EAAE,CAAC;CAC7B;AAED;;;;GAIG;AACH,eAAO,MAAM,aAAa,EAAE,gBAAgB,CAAC,kBAAkB,GAAG,SAAS,EAAE,KAAK,CA0H9E,CAAC;AA+KL,eAAe,aAAa,CAAC"}
|