@macroforge/vite-plugin 0.1.40 → 0.1.43
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 +2 -2
- package/package.json +24 -18
- package/src/index.d.ts +21 -0
- package/src/index.js +558 -0
- package/dist/index.d.ts +0 -186
- package/dist/index.d.ts.map +0 -1
- package/dist/index.js +0 -692
package/dist/index.d.ts
DELETED
|
@@ -1,186 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @module @macroforge/vite-plugin
|
|
3
|
-
*
|
|
4
|
-
* Vite plugin for Macroforge compile-time TypeScript macro expansion.
|
|
5
|
-
*
|
|
6
|
-
* This plugin integrates Macroforge's Rust-based macro expander into the Vite build pipeline,
|
|
7
|
-
* enabling compile-time code generation through `@derive` decorators. It processes TypeScript
|
|
8
|
-
* files during the build, expands macros, generates type definitions, and emits metadata.
|
|
9
|
-
*
|
|
10
|
-
* @example
|
|
11
|
-
* ```typescript
|
|
12
|
-
* // vite.config.ts
|
|
13
|
-
* import { defineConfig } from 'vite';
|
|
14
|
-
* import macroforgePlugin from '@macroforge/vite-plugin';
|
|
15
|
-
*
|
|
16
|
-
* export default defineConfig({
|
|
17
|
-
* plugins: [
|
|
18
|
-
* macroforgePlugin({
|
|
19
|
-
* generateTypes: true,
|
|
20
|
-
* typesOutputDir: 'src/types/generated',
|
|
21
|
-
* emitMetadata: true,
|
|
22
|
-
* }),
|
|
23
|
-
* ],
|
|
24
|
-
* });
|
|
25
|
-
* ```
|
|
26
|
-
*
|
|
27
|
-
* @packageDocumentation
|
|
28
|
-
*/
|
|
29
|
-
import { Plugin } from "vite";
|
|
30
|
-
/**
|
|
31
|
-
* Configuration options for the Macroforge Vite plugin.
|
|
32
|
-
*
|
|
33
|
-
* @public
|
|
34
|
-
* @example
|
|
35
|
-
* ```typescript
|
|
36
|
-
* const options: NapiMacrosPluginOptions = {
|
|
37
|
-
* include: ['src/**\/*.ts'],
|
|
38
|
-
* exclude: ['**\/*.test.ts'],
|
|
39
|
-
* generateTypes: true,
|
|
40
|
-
* typesOutputDir: 'src/types/generated',
|
|
41
|
-
* emitMetadata: true,
|
|
42
|
-
* metadataOutputDir: 'src/macros/metadata',
|
|
43
|
-
* };
|
|
44
|
-
* ```
|
|
45
|
-
*/
|
|
46
|
-
export interface NapiMacrosPluginOptions {
|
|
47
|
-
/**
|
|
48
|
-
* Glob patterns, regular expressions, or arrays of either to specify which files
|
|
49
|
-
* should be processed by the macro expander.
|
|
50
|
-
*
|
|
51
|
-
* @remarks
|
|
52
|
-
* If not specified, all `.ts` and `.tsx` files (excluding `node_modules`) are processed.
|
|
53
|
-
*
|
|
54
|
-
* @example
|
|
55
|
-
* ```typescript
|
|
56
|
-
* include: ['src/**\/*.ts', /components\/.*\.tsx$/]
|
|
57
|
-
* ```
|
|
58
|
-
*/
|
|
59
|
-
include?: string | RegExp | (string | RegExp)[];
|
|
60
|
-
/**
|
|
61
|
-
* Glob patterns, regular expressions, or arrays of either to specify which files
|
|
62
|
-
* should be excluded from macro processing.
|
|
63
|
-
*
|
|
64
|
-
* @remarks
|
|
65
|
-
* Files in `node_modules` are always excluded by default.
|
|
66
|
-
*
|
|
67
|
-
* @example
|
|
68
|
-
* ```typescript
|
|
69
|
-
* exclude: ['**\/*.test.ts', '**\/*.spec.ts']
|
|
70
|
-
* ```
|
|
71
|
-
*/
|
|
72
|
-
exclude?: string | RegExp | (string | RegExp)[];
|
|
73
|
-
/**
|
|
74
|
-
* Whether to generate TypeScript declaration files (`.d.ts`) for transformed code.
|
|
75
|
-
*
|
|
76
|
-
* @remarks
|
|
77
|
-
* When enabled, the plugin uses the TypeScript compiler to emit declaration files
|
|
78
|
-
* based on the macro-expanded code. This ensures type definitions accurately reflect
|
|
79
|
-
* the generated code.
|
|
80
|
-
*
|
|
81
|
-
* @default true
|
|
82
|
-
*/
|
|
83
|
-
generateTypes?: boolean;
|
|
84
|
-
/**
|
|
85
|
-
* Output directory for generated TypeScript declaration files.
|
|
86
|
-
*
|
|
87
|
-
* @remarks
|
|
88
|
-
* Path is relative to the project root. The directory structure of the source files
|
|
89
|
-
* is preserved within this output directory.
|
|
90
|
-
*
|
|
91
|
-
* @default "src/macros/generated"
|
|
92
|
-
*
|
|
93
|
-
* @example
|
|
94
|
-
* ```typescript
|
|
95
|
-
* // Source: src/models/User.ts
|
|
96
|
-
* // Output: src/types/generated/models/User.d.ts
|
|
97
|
-
* typesOutputDir: 'src/types/generated'
|
|
98
|
-
* ```
|
|
99
|
-
*/
|
|
100
|
-
typesOutputDir?: string;
|
|
101
|
-
/**
|
|
102
|
-
* Whether to emit macro intermediate representation (IR) metadata as JSON files.
|
|
103
|
-
*
|
|
104
|
-
* @remarks
|
|
105
|
-
* The metadata contains information about which macros were applied, their configurations,
|
|
106
|
-
* and the transformation results. This can be useful for debugging, tooling integration,
|
|
107
|
-
* or build analysis.
|
|
108
|
-
*
|
|
109
|
-
* @default true
|
|
110
|
-
*/
|
|
111
|
-
emitMetadata?: boolean;
|
|
112
|
-
/**
|
|
113
|
-
* Output directory for macro IR metadata JSON files.
|
|
114
|
-
*
|
|
115
|
-
* @remarks
|
|
116
|
-
* Path is relative to the project root. If not specified, defaults to the same
|
|
117
|
-
* directory as `typesOutputDir`. Metadata files are named with a `.macro-ir.json` suffix.
|
|
118
|
-
*
|
|
119
|
-
* @default Same as `typesOutputDir`
|
|
120
|
-
*
|
|
121
|
-
* @example
|
|
122
|
-
* ```typescript
|
|
123
|
-
* // Source: src/models/User.ts
|
|
124
|
-
* // Output: src/macros/metadata/models/User.macro-ir.json
|
|
125
|
-
* metadataOutputDir: 'src/macros/metadata'
|
|
126
|
-
* ```
|
|
127
|
-
*/
|
|
128
|
-
metadataOutputDir?: string;
|
|
129
|
-
}
|
|
130
|
-
/**
|
|
131
|
-
* Creates a Vite plugin for Macroforge compile-time macro expansion.
|
|
132
|
-
*
|
|
133
|
-
* @remarks
|
|
134
|
-
* This is the main entry point for integrating Macroforge into a Vite build pipeline.
|
|
135
|
-
* The plugin:
|
|
136
|
-
*
|
|
137
|
-
* 1. **Runs early** (`enforce: "pre"`) to transform code before other plugins
|
|
138
|
-
* 2. **Processes TypeScript files** (`.ts` and `.tsx`) excluding `node_modules`
|
|
139
|
-
* 3. **Expands macros** using the Macroforge Rust binary via `expandSync()`
|
|
140
|
-
* 4. **Generates type definitions** for transformed code (optional, default: enabled)
|
|
141
|
-
* 5. **Emits metadata** about macro transformations (optional, default: enabled)
|
|
142
|
-
*
|
|
143
|
-
* **Plugin Lifecycle:**
|
|
144
|
-
* - `configResolved`: Initializes project root, loads config, and attempts to load Rust binary
|
|
145
|
-
* - `transform`: Processes each TypeScript file through the macro expander
|
|
146
|
-
*
|
|
147
|
-
* **Error Handling:**
|
|
148
|
-
* - If the Rust binary is not available, files pass through unchanged
|
|
149
|
-
* - Macro expansion errors are reported via Vite's `this.error()` mechanism
|
|
150
|
-
* - TypeScript emission errors are logged as warnings
|
|
151
|
-
*
|
|
152
|
-
* @param options - Plugin configuration options
|
|
153
|
-
*
|
|
154
|
-
* @returns A Vite plugin instance
|
|
155
|
-
*
|
|
156
|
-
* @public
|
|
157
|
-
*
|
|
158
|
-
* @example
|
|
159
|
-
* ```typescript
|
|
160
|
-
* // Basic usage
|
|
161
|
-
* import macroforgePlugin from '@macroforge/vite-plugin';
|
|
162
|
-
*
|
|
163
|
-
* export default defineConfig({
|
|
164
|
-
* plugins: [macroforgePlugin()],
|
|
165
|
-
* });
|
|
166
|
-
* ```
|
|
167
|
-
*
|
|
168
|
-
* @example
|
|
169
|
-
* ```typescript
|
|
170
|
-
* // With custom options
|
|
171
|
-
* import macroforgePlugin from '@macroforge/vite-plugin';
|
|
172
|
-
*
|
|
173
|
-
* export default defineConfig({
|
|
174
|
-
* plugins: [
|
|
175
|
-
* macroforgePlugin({
|
|
176
|
-
* generateTypes: true,
|
|
177
|
-
* typesOutputDir: 'src/types/generated',
|
|
178
|
-
* emitMetadata: false,
|
|
179
|
-
* }),
|
|
180
|
-
* ],
|
|
181
|
-
* });
|
|
182
|
-
* ```
|
|
183
|
-
*/
|
|
184
|
-
declare function napiMacrosPlugin(options?: NapiMacrosPluginOptions): Plugin;
|
|
185
|
-
export default napiMacrosPlugin;
|
|
186
|
-
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;AAEH,OAAO,EAAE,MAAM,EAAE,MAAM,MAAM,CAAC;AAqJ9B;;;;;;;;;;;;;;;GAeG;AACH,MAAM,WAAW,uBAAuB;IACtC;;;;;;;;;;;OAWG;IACH,OAAO,CAAC,EAAE,MAAM,GAAG,MAAM,GAAG,CAAC,MAAM,GAAG,MAAM,CAAC,EAAE,CAAC;IAEhD;;;;;;;;;;;OAWG;IACH,OAAO,CAAC,EAAE,MAAM,GAAG,MAAM,GAAG,CAAC,MAAM,GAAG,MAAM,CAAC,EAAE,CAAC;IAEhD;;;;;;;;;OASG;IACH,aAAa,CAAC,EAAE,OAAO,CAAC;IAExB;;;;;;;;;;;;;;;OAeG;IACH,cAAc,CAAC,EAAE,MAAM,CAAC;IAExB;;;;;;;;;OASG;IACH,YAAY,CAAC,EAAE,OAAO,CAAC;IAEvB;;;;;;;;;;;;;;;OAeG;IACH,iBAAiB,CAAC,EAAE,MAAM,CAAC;CAC5B;AA6TD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAqDG;AACH,iBAAS,gBAAgB,CAAC,OAAO,GAAE,uBAA4B,GAAG,MAAM,CAuTvE;AAED,eAAe,gBAAgB,CAAC"}
|