@macroforge/mcp-server 0.1.39 → 0.1.42
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/docs/api/api-overview.md +32 -32
- package/docs/api/expand-sync.md +30 -30
- package/docs/api/native-plugin.md +38 -38
- package/docs/api/position-mapper.md +18 -18
- package/docs/api/transform-sync.md +31 -31
- package/docs/builtin-macros/default.md +6 -6
- package/docs/builtin-macros/macros-overview.md +84 -84
- package/docs/builtin-macros/partial-ord.md +18 -20
- package/docs/concepts/architecture.md +16 -16
- package/docs/concepts/derive-system.md +89 -68
- package/docs/concepts/how-macros-work.md +13 -12
- package/docs/custom-macros/custom-overview.md +36 -36
- package/docs/custom-macros/rust-setup.md +71 -71
- package/docs/custom-macros/ts-macro-derive.md +167 -167
- package/docs/custom-macros/ts-quote.md +347 -347
- package/docs/getting-started/first-macro.md +57 -55
- package/docs/getting-started/installation.md +34 -35
- package/docs/integration/cli.md +43 -43
- package/docs/integration/configuration.md +41 -41
- package/docs/integration/integration-overview.md +4 -4
- package/docs/integration/mcp-server.md +22 -22
- package/docs/integration/svelte-preprocessor.md +87 -87
- package/docs/integration/typescript-plugin.md +23 -24
- package/docs/integration/vite-plugin.md +40 -40
- package/docs/language-servers/svelte.md +15 -16
- package/docs/language-servers/zed.md +14 -15
- package/package.json +2 -2
|
@@ -1,137 +1,139 @@
|
|
|
1
1
|
# Your First Macro
|
|
2
2
|
*Let's create a class that uses Macroforge's derive macros to automatically generate useful methods.*
|
|
3
3
|
## Creating a Class with Derive Macros
|
|
4
|
-
Start by creating a simple
|
|
5
|
-
|
|
4
|
+
Start by creating a simple <code class="shiki-inline"><span class="line"><span style="--shiki-dark:#E1E4E8;--shiki-light:#24292E">User</code> class. We'll use the <code class="shiki-inline"><span class="line"><span style="--shiki-dark:#E1E4E8;--shiki-light:#24292E">@derive</code> decorator to automatically generate methods.
|
|
5
|
+
<div><div class="flex items-center justify-between gap-2 px-4 py-2 bg-muted rounded-t-lg border border-b-0 border-border">
|
|
6
|
+
**Before:**
|
|
6
7
|
```
|
|
7
8
|
/** @derive(Debug, Clone, PartialEq) */
|
|
8
|
-
export class User
|
|
9
|
+
export class User {
|
|
9
10
|
name: string;
|
|
10
11
|
age: number;
|
|
11
12
|
email: string;
|
|
12
13
|
|
|
13
|
-
constructor(name: string, age: number, email: string)
|
|
14
|
+
constructor(name: string, age: number, email: string) {
|
|
14
15
|
this.name = name;
|
|
15
16
|
this.age = age;
|
|
16
17
|
this.email = email;
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
```
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
``` <div class="flex items-center justify-between gap-2 px-4 py-2 bg-muted rounded-t-lg border border-b-0 border-border">
|
|
20
21
|
**After:**
|
|
21
22
|
```
|
|
22
|
-
export class User
|
|
23
|
+
export class User {
|
|
23
24
|
name: string;
|
|
24
25
|
age: number;
|
|
25
26
|
email: string;
|
|
26
27
|
|
|
27
|
-
constructor(name: string, age: number, email: string)
|
|
28
|
+
constructor(name: string, age: number, email: string) {
|
|
28
29
|
this.name = name;
|
|
29
30
|
this.age = age;
|
|
30
31
|
this.email = email;
|
|
31
|
-
|
|
32
|
+
}
|
|
32
33
|
|
|
33
|
-
static toString(value: User): string
|
|
34
|
+
static toString(value: User): string {
|
|
34
35
|
return userToString(value);
|
|
35
|
-
|
|
36
|
+
}
|
|
36
37
|
|
|
37
|
-
static clone(value: User): User
|
|
38
|
+
static clone(value: User): User {
|
|
38
39
|
return userClone(value);
|
|
39
|
-
|
|
40
|
+
}
|
|
40
41
|
|
|
41
|
-
static equals(a: User, b: User): boolean
|
|
42
|
+
static equals(a: User, b: User): boolean {
|
|
42
43
|
return userEquals(a, b);
|
|
43
|
-
|
|
44
|
-
|
|
44
|
+
}
|
|
45
|
+
}
|
|
45
46
|
|
|
46
|
-
export function userToString(value: User): string
|
|
47
|
+
export function userToString(value: User): string {
|
|
47
48
|
const parts: string[] = [];
|
|
48
49
|
parts.push('name: ' + value.name);
|
|
49
50
|
parts.push('age: ' + value.age);
|
|
50
51
|
parts.push('email: ' + value.email);
|
|
51
|
-
return 'User
|
|
52
|
-
|
|
52
|
+
return 'User { ' + parts.join(', ') + ' }';
|
|
53
|
+
}
|
|
53
54
|
|
|
54
|
-
export function userClone(value: User): User
|
|
55
|
+
export function userClone(value: User): User {
|
|
55
56
|
const cloned = Object.create(Object.getPrototypeOf(value));
|
|
56
57
|
cloned.name = value.name;
|
|
57
58
|
cloned.age = value.age;
|
|
58
59
|
cloned.email = value.email;
|
|
59
60
|
return cloned;
|
|
60
|
-
|
|
61
|
+
}
|
|
61
62
|
|
|
62
|
-
export function userEquals(a: User, b: User): boolean
|
|
63
|
+
export function userEquals(a: User, b: User): boolean {
|
|
63
64
|
if (a === b) return true;
|
|
64
|
-
return a.name === b.name
|
|
65
|
-
|
|
65
|
+
return a.name === b.name && a.age === b.age && a.email === b.email;
|
|
66
|
+
}
|
|
66
67
|
``` ## Using the Generated Methods
|
|
67
68
|
```
|
|
68
|
-
const
|
|
69
|
+
const user = new User("Alice", 30, "alice@example.com");
|
|
69
70
|
|
|
70
|
-
|
|
71
|
+
// Debug: toString()
|
|
71
72
|
console.log(user.toString());
|
|
72
|
-
|
|
73
|
+
// Output: User { name: Alice, age: 30, email: alice@example.com }
|
|
73
74
|
|
|
74
|
-
|
|
75
|
-
const
|
|
76
|
-
console.log(copy.name);
|
|
75
|
+
// Clone: clone()
|
|
76
|
+
const copy = user.clone();
|
|
77
|
+
console.log(copy.name); // "Alice"
|
|
77
78
|
|
|
78
|
-
|
|
79
|
-
console.log(user.equals(copy));
|
|
79
|
+
// Eq: equals()
|
|
80
|
+
console.log(user.equals(copy)); // true
|
|
80
81
|
|
|
81
|
-
const
|
|
82
|
-
console.log(user.equals(different));
|
|
82
|
+
const different = new User("Bob", 25, "bob@example.com");
|
|
83
|
+
console.log(user.equals(different)); // false
|
|
83
84
|
``` ## Customizing Behavior
|
|
84
85
|
You can customize how macros work using field-level decorators. For example, with the Debug macro:
|
|
85
|
-
|
|
86
|
+
<div><div class="flex items-center justify-between gap-2 px-4 py-2 bg-muted rounded-t-lg border border-b-0 border-border">
|
|
87
|
+
**Before:**
|
|
86
88
|
```
|
|
87
89
|
/** @derive(Debug) */
|
|
88
|
-
export class User
|
|
89
|
-
/** @debug(
|
|
90
|
+
export class User {
|
|
91
|
+
/** @debug({ rename: "userId" }) */
|
|
90
92
|
id: number;
|
|
91
93
|
|
|
92
94
|
name: string;
|
|
93
95
|
|
|
94
|
-
/** @debug(
|
|
96
|
+
/** @debug({ skip: true }) */
|
|
95
97
|
password: string;
|
|
96
98
|
|
|
97
|
-
constructor(id: number, name: string, password: string)
|
|
99
|
+
constructor(id: number, name: string, password: string) {
|
|
98
100
|
this.id = id;
|
|
99
101
|
this.name = name;
|
|
100
102
|
this.password = password;
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
```
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
``` <div class="flex items-center justify-between gap-2 px-4 py-2 bg-muted rounded-t-lg border border-b-0 border-border">
|
|
104
106
|
**After:**
|
|
105
107
|
```
|
|
106
|
-
export class User
|
|
108
|
+
export class User {
|
|
107
109
|
id: number;
|
|
108
110
|
|
|
109
111
|
name: string;
|
|
110
112
|
|
|
111
113
|
password: string;
|
|
112
114
|
|
|
113
|
-
constructor(id: number, name: string, password: string)
|
|
115
|
+
constructor(id: number, name: string, password: string) {
|
|
114
116
|
this.id = id;
|
|
115
117
|
this.name = name;
|
|
116
118
|
this.password = password;
|
|
117
|
-
|
|
119
|
+
}
|
|
118
120
|
|
|
119
|
-
static toString(value: User): string
|
|
121
|
+
static toString(value: User): string {
|
|
120
122
|
return userToString(value);
|
|
121
|
-
|
|
122
|
-
|
|
123
|
+
}
|
|
124
|
+
}
|
|
123
125
|
|
|
124
|
-
export function userToString(value: User): string
|
|
126
|
+
export function userToString(value: User): string {
|
|
125
127
|
const parts: string[] = [];
|
|
126
128
|
parts.push('userId: ' + value.id);
|
|
127
129
|
parts.push('name: ' + value.name);
|
|
128
|
-
return 'User
|
|
129
|
-
|
|
130
|
+
return 'User { ' + parts.join(', ') + ' }';
|
|
131
|
+
}
|
|
130
132
|
``` ```
|
|
131
|
-
const
|
|
133
|
+
const user = new User(42, "Alice", "secret123");
|
|
132
134
|
console.log(user.toString());
|
|
133
|
-
|
|
134
|
-
|
|
135
|
+
// Output: User { userId: 42, name: Alice }
|
|
136
|
+
// Note: 'id' is renamed to 'userId', 'password' is skipped
|
|
135
137
|
``` **Field-level decorators Field-level decorators let you control exactly how each field is handled by the macro. ## Next Steps
|
|
136
138
|
- [Learn how macros work under the hood](../../docs/concepts)
|
|
137
139
|
- [Explore all Debug options](../../docs/builtin-macros/debug)
|
|
@@ -6,40 +6,40 @@
|
|
|
6
6
|
## Install the Package
|
|
7
7
|
Install Macroforge using your preferred package manager:
|
|
8
8
|
```
|
|
9
|
-
npm
|
|
9
|
+
npm install macroforge
|
|
10
10
|
``` ```
|
|
11
|
-
bun
|
|
11
|
+
bun add macroforge
|
|
12
12
|
``` ```
|
|
13
|
-
pnpm
|
|
13
|
+
pnpm add macroforge
|
|
14
14
|
``` **Info Macroforge includes pre-built native binaries for macOS (x64, arm64), Linux (x64, arm64), and Windows (x64, arm64). ## Basic Usage
|
|
15
|
-
The simplest way to use Macroforge is with the built-in derive macros. Add a
|
|
15
|
+
The simplest way to use Macroforge is with the built-in derive macros. Add a **<code class="shiki-inline"><span class="line"><span style="--shiki-dark:#E1E4E8;--shiki-light:#24292E">@derive</code> comment decorator to your class:
|
|
16
16
|
```
|
|
17
|
-
|
|
18
|
-
class
|
|
19
|
-
|
|
20
|
-
|
|
17
|
+
/** @derive(Debug, Clone, PartialEq) */
|
|
18
|
+
class User {
|
|
19
|
+
name: string;
|
|
20
|
+
age: number;
|
|
21
21
|
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
22
|
+
constructor(name: string, age: number) {
|
|
23
|
+
this.name = name;
|
|
24
|
+
this.age = age;
|
|
25
|
+
}
|
|
26
26
|
}
|
|
27
27
|
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
28
|
+
// After macro expansion, User has:
|
|
29
|
+
// - toString(): string (from Debug)
|
|
30
|
+
// - clone(): User (from Clone)
|
|
31
|
+
// - equals(other: unknown): boolean (from PartialEq)
|
|
32
32
|
``` ## IDE Integration
|
|
33
|
-
For the best development experience, add the TypeScript plugin to your
|
|
33
|
+
For the best development experience, add the TypeScript plugin to your <code class="shiki-inline"><span class="line"><span style="--shiki-dark:#E1E4E8;--shiki-light:#24292E">tsconfig.json</code>:
|
|
34
34
|
```
|
|
35
35
|
{
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
36
|
+
"compilerOptions": {
|
|
37
|
+
"plugins": [
|
|
38
|
+
{
|
|
39
|
+
"name": "@macroforge/typescript-plugin"
|
|
40
|
+
}
|
|
41
|
+
]
|
|
42
|
+
}
|
|
43
43
|
}
|
|
44
44
|
``` This enables features like:
|
|
45
45
|
- Accurate error positions in your source code
|
|
@@ -48,20 +48,19 @@ class User {
|
|
|
48
48
|
## Build Integration (Vite)
|
|
49
49
|
If you're using Vite, add the plugin to your config for automatic macro expansion during build:
|
|
50
50
|
```
|
|
51
|
-
import
|
|
52
|
-
import
|
|
51
|
+
import macroforge from "@macroforge/vite-plugin";
|
|
52
|
+
import { defineConfig } from "vite";
|
|
53
53
|
|
|
54
|
-
export
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
54
|
+
export default defineConfig({
|
|
55
|
+
plugins: [
|
|
56
|
+
macroforge({
|
|
57
|
+
generateTypes: true,
|
|
58
|
+
typesOutputDir: ".macroforge/types"
|
|
59
|
+
})
|
|
60
|
+
]
|
|
61
61
|
});
|
|
62
62
|
``` ## Next Steps
|
|
63
63
|
Now that you have Macroforge installed, learn how to use it:
|
|
64
64
|
- [Create your first macro](../docs/getting-started/first-macro)
|
|
65
65
|
- [Understand how macros work](../docs/concepts)
|
|
66
|
-
- [Explore built-in macros](../docs/builtin-macros)
|
|
67
|
-
**
|
|
66
|
+
- [Explore built-in macros](../docs/builtin-macros)
|
package/docs/integration/cli.md
CHANGED
|
@@ -3,71 +3,71 @@
|
|
|
3
3
|
## Installation
|
|
4
4
|
The CLI is a Rust binary. You can install it using Cargo:
|
|
5
5
|
```
|
|
6
|
-
cargo
|
|
6
|
+
cargo install macroforge_ts
|
|
7
7
|
``` Or build from source:
|
|
8
8
|
```
|
|
9
|
-
git
|
|
10
|
-
cd
|
|
11
|
-
cargo
|
|
9
|
+
git clone https://github.com/rymskip/macroforge-ts.git
|
|
10
|
+
cd macroforge-ts/crates
|
|
11
|
+
cargo build --release --bin macroforge
|
|
12
12
|
|
|
13
|
-
|
|
13
|
+
# The binary is at target/release/macroforge
|
|
14
14
|
``` ## Commands
|
|
15
15
|
### macroforge expand
|
|
16
16
|
Expands macros in a TypeScript file and outputs the transformed code.
|
|
17
17
|
```
|
|
18
|
-
macroforge
|
|
18
|
+
macroforge expand <input> [options]
|
|
19
19
|
``` #### Arguments
|
|
20
20
|
| Argument | Description |
|
|
21
21
|
| --- | --- |
|
|
22
|
-
|
|
|
22
|
+
| <input> | Path to the TypeScript or TSX file to expand |
|
|
23
23
|
#### Options
|
|
24
24
|
| Option | Description |
|
|
25
25
|
| --- | --- |
|
|
26
|
-
|
|
|
27
|
-
|
|
|
28
|
-
|
|
|
29
|
-
|
|
|
26
|
+
| --out <path> | Write the expanded JavaScript/TypeScript to a file |
|
|
27
|
+
| --types-out <path> | Write the generated .d.ts declarations to a file |
|
|
28
|
+
| --print | Print output to stdout even when --out is specified |
|
|
29
|
+
| --builtin-only | Use only built-in Rust macros (faster, but no external macro support) |
|
|
30
30
|
#### Examples
|
|
31
31
|
Expand a file and print to stdout:
|
|
32
32
|
```
|
|
33
|
-
macroforge
|
|
33
|
+
macroforge expand src/user.ts
|
|
34
34
|
``` Expand and write to a file:
|
|
35
35
|
```
|
|
36
|
-
macroforge
|
|
36
|
+
macroforge expand src/user.ts --out dist/user.js
|
|
37
37
|
``` Expand with both runtime output and type declarations:
|
|
38
38
|
```
|
|
39
|
-
macroforge
|
|
39
|
+
macroforge expand src/user.ts --out dist/user.js --types-out dist/user.d.ts
|
|
40
40
|
``` Use fast built-in macros only (no external macro support):
|
|
41
41
|
```
|
|
42
|
-
macroforge
|
|
42
|
+
macroforge expand src/user.ts --builtin-only
|
|
43
43
|
``` > **Note:** By default, the CLI uses Node.js for full macro support (including external macros). It must be run from your project's root directory where macroforge and any external macro packages are installed in node_modules. ### macroforge tsc
|
|
44
|
-
Runs TypeScript type checking with macro expansion. This wraps
|
|
44
|
+
Runs TypeScript type checking with macro expansion. This wraps <code class="shiki-inline"><span class="line"><span style="--shiki-dark:#E1E4E8;--shiki-light:#24292E">tsc <span style="--shiki-dark:#F97583;--shiki-light:#D73A49">--<span style="--shiki-dark:#E1E4E8;--shiki-light:#24292E">noEmit</code> and expands macros before type checking, so your generated methods are properly type-checked.
|
|
45
45
|
```
|
|
46
|
-
macroforge
|
|
46
|
+
macroforge tsc [options]
|
|
47
47
|
``` #### Options
|
|
48
48
|
| Option | Description |
|
|
49
49
|
| --- | --- |
|
|
50
|
-
|
|
|
50
|
+
| -p, --project <path> | Path to tsconfig.json (defaults to tsconfig.json in current directory) |
|
|
51
51
|
#### Examples
|
|
52
52
|
Type check with default tsconfig.json:
|
|
53
53
|
```
|
|
54
|
-
macroforge
|
|
54
|
+
macroforge tsc
|
|
55
55
|
``` Type check with a specific config:
|
|
56
56
|
```
|
|
57
|
-
macroforge
|
|
57
|
+
macroforge tsc -p tsconfig.build.json
|
|
58
58
|
``` ## Output Format
|
|
59
59
|
### Expanded Code
|
|
60
60
|
When expanding a file like this:
|
|
61
61
|
```
|
|
62
|
-
|
|
63
|
-
class
|
|
64
|
-
|
|
65
|
-
|
|
62
|
+
/** @derive(Debug) */
|
|
63
|
+
class User {
|
|
64
|
+
name: string;
|
|
65
|
+
age: number;
|
|
66
66
|
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
67
|
+
constructor(name: string, age: number) {
|
|
68
|
+
this.name = name;
|
|
69
|
+
this.age = age;
|
|
70
|
+
}
|
|
71
71
|
}
|
|
72
72
|
``` The CLI outputs the expanded code with the generated methods:
|
|
73
73
|
```
|
|
@@ -87,35 +87,35 @@ class User {
|
|
|
87
87
|
``` ### Diagnostics
|
|
88
88
|
Errors and warnings are printed to stderr in a readable format:
|
|
89
89
|
```
|
|
90
|
-
[macroforge]
|
|
91
|
-
[macroforge]
|
|
90
|
+
[macroforge] error at src/user.ts:5:1: Unknown derive macro: InvalidMacro
|
|
91
|
+
[macroforge] warning at src/user.ts:10:3: Field 'unused' is never used
|
|
92
92
|
``` ## Use Cases
|
|
93
93
|
### CI/CD Type Checking
|
|
94
|
-
Use
|
|
94
|
+
Use <code class="shiki-inline"><span class="line"><span style="--shiki-dark:#B392F0;--shiki-light:#6F42C1">macroforge<span style="--shiki-dark:#9ECBFF;--shiki-light:#032F62"> tsc</code> in your CI pipeline to type-check with macro expansion:
|
|
95
95
|
```
|
|
96
|
-
|
|
96
|
+
# package.json
|
|
97
97
|
{
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
98
|
+
"scripts": {
|
|
99
|
+
"typecheck": "macroforge tsc"
|
|
100
|
+
}
|
|
101
101
|
}
|
|
102
102
|
``` ### Debugging Macro Output
|
|
103
|
-
Use
|
|
103
|
+
Use <code class="shiki-inline"><span class="line"><span style="--shiki-dark:#B392F0;--shiki-light:#6F42C1">macroforge<span style="--shiki-dark:#9ECBFF;--shiki-light:#032F62"> expand</code> to inspect what code your macros generate:
|
|
104
104
|
```
|
|
105
|
-
macroforge
|
|
105
|
+
macroforge expand src/models/user.ts | less
|
|
106
106
|
``` ### Build Pipeline
|
|
107
107
|
Generate expanded files as part of a custom build:
|
|
108
108
|
```
|
|
109
109
|
#!/bin/bash
|
|
110
|
-
for
|
|
111
|
-
|
|
112
|
-
|
|
110
|
+
for file in src/**/*.ts; do
|
|
111
|
+
outfile="dist/$(basename "$file" .ts).js"
|
|
112
|
+
macroforge expand "$file" --out "$outfile"
|
|
113
113
|
done
|
|
114
114
|
``` ## Built-in vs Full Mode
|
|
115
|
-
By default, the CLI uses Node.js for full macro support including external macros. Use
|
|
116
|
-
| Feature | Default (Node.js) |
|
|
115
|
+
By default, the CLI uses Node.js for full macro support including external macros. Use <code class="shiki-inline"><span class="line"><span style="--shiki-dark:#F97583;--shiki-light:#D73A49">--<span style="--shiki-dark:#E1E4E8;--shiki-light:#24292E">builtin<span style="--shiki-dark:#F97583;--shiki-light:#D73A49">-<span style="--shiki-dark:#E1E4E8;--shiki-light:#24292E">only</code> for faster expansion when you only need built-in macros:
|
|
116
|
+
| Feature | Default (Node.js) | --builtin-only (Rust) |
|
|
117
117
|
| --- | --- | --- |
|
|
118
118
|
| Built-in macros | Yes | Yes |
|
|
119
119
|
| External macros | Yes | No |
|
|
120
120
|
| Performance | Standard | Faster |
|
|
121
|
-
| Dependencies | Requires
|
|
121
|
+
| Dependencies | Requires macroforge in node_modules | None |
|
|
@@ -1,73 +1,73 @@
|
|
|
1
1
|
# Configuration
|
|
2
|
-
*Macroforge can be configured with a
|
|
2
|
+
*Macroforge can be configured with a <code class="shiki-inline"><span class="line"><span style="--shiki-dark:#E1E4E8;--shiki-light:#24292E">macroforge.json</code> file in your project root.*
|
|
3
3
|
## Configuration File
|
|
4
|
-
Create a
|
|
4
|
+
Create a <code class="shiki-inline"><span class="line"><span style="--shiki-dark:#E1E4E8;--shiki-light:#24292E">macroforge.json</code> file:
|
|
5
5
|
```
|
|
6
6
|
{
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
7
|
+
"allowNativeMacros": true,
|
|
8
|
+
"macroPackages": [],
|
|
9
|
+
"keepDecorators": false,
|
|
10
|
+
"limits": {
|
|
11
|
+
"maxExecutionTimeMs": 5000,
|
|
12
|
+
"maxMemoryBytes": 104857600,
|
|
13
|
+
"maxOutputSize": 10485760,
|
|
14
|
+
"maxDiagnostics": 100
|
|
15
|
+
}
|
|
16
16
|
}
|
|
17
17
|
``` ## Options Reference
|
|
18
18
|
### allowNativeMacros
|
|
19
|
-
| Type |
|
|
20
|
-
| Default |
|
|
21
|
-
Enable or disable native (Rust) macro packages. Set to
|
|
19
|
+
| Type | boolean |
|
|
20
|
+
| Default | true |
|
|
21
|
+
Enable or disable native (Rust) macro packages. Set to <code class="shiki-inline"><span class="line"><span style="--shiki-dark:#79B8FF;--shiki-light:#005CC5">false</code> to only allow built-in macros.
|
|
22
22
|
### macroPackages
|
|
23
|
-
| Type |
|
|
24
|
-
| Default |
|
|
23
|
+
| Type | string[] |
|
|
24
|
+
| Default | [] |
|
|
25
25
|
List of npm packages that provide macros. Macroforge will look for macros in these packages.
|
|
26
26
|
```
|
|
27
27
|
{
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
28
|
+
"macroPackages": [
|
|
29
|
+
"@my-org/custom-macros",
|
|
30
|
+
"community-macros"
|
|
31
|
+
]
|
|
32
32
|
}
|
|
33
33
|
``` ### keepDecorators
|
|
34
|
-
| Type |
|
|
35
|
-
| Default |
|
|
36
|
-
Keep
|
|
34
|
+
| Type | boolean |
|
|
35
|
+
| Default | false |
|
|
36
|
+
Keep <code class="shiki-inline"><span class="line"><span style="--shiki-dark:#E1E4E8;--shiki-light:#24292E">@derive</code> decorators in the output. Useful for debugging.
|
|
37
37
|
### limits
|
|
38
38
|
Configure resource limits for macro expansion:
|
|
39
39
|
```
|
|
40
40
|
{
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
41
|
+
"limits": {
|
|
42
|
+
// Maximum time for a single macro expansion (ms)
|
|
43
|
+
"maxExecutionTimeMs": 5000,
|
|
44
44
|
|
|
45
|
-
|
|
46
|
-
|
|
45
|
+
// Maximum memory usage (bytes)
|
|
46
|
+
"maxMemoryBytes": 104857600, // 100MB
|
|
47
47
|
|
|
48
|
-
|
|
49
|
-
|
|
48
|
+
// Maximum size of generated code (bytes)
|
|
49
|
+
"maxOutputSize": 10485760, // 10MB
|
|
50
50
|
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
51
|
+
// Maximum number of diagnostics per file
|
|
52
|
+
"maxDiagnostics": 100
|
|
53
|
+
}
|
|
54
54
|
}
|
|
55
55
|
``` ## Macro Runtime Overrides
|
|
56
56
|
Override settings for specific macros:
|
|
57
57
|
```
|
|
58
58
|
{
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
59
|
+
"macroRuntimeOverrides": {
|
|
60
|
+
"@my-org/macros": {
|
|
61
|
+
"maxExecutionTimeMs": 10000
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
64
|
}
|
|
65
65
|
``` **Warning Be careful when increasing limits, as this could allow malicious macros to consume excessive resources. ## Environment Variables
|
|
66
66
|
Some settings can be overridden with environment variables:
|
|
67
67
|
| Variable | Description |
|
|
68
68
|
| --- | --- |
|
|
69
|
-
|
|
|
70
|
-
|
|
|
69
|
+
| MACROFORGE_DEBUG | Enable debug logging |
|
|
70
|
+
| MACROFORGE_LOG_FILE | Write logs to a file |
|
|
71
71
|
```
|
|
72
|
-
MACROFORGE_DEBUG=1
|
|
72
|
+
MACROFORGE_DEBUG=1 npm run dev
|
|
73
73
|
```**
|
|
@@ -3,15 +3,15 @@
|
|
|
3
3
|
## Overview
|
|
4
4
|
| Integration | Purpose | Package |
|
|
5
5
|
| --- | --- | --- |
|
|
6
|
-
| TypeScript Plugin | IDE support (errors, completions) |
|
|
7
|
-
| Vite Plugin | Build-time macro expansion |
|
|
6
|
+
| TypeScript Plugin | IDE support (errors, completions) | @macroforge/typescript-plugin |
|
|
7
|
+
| Vite Plugin | Build-time macro expansion | @macroforge/vite-plugin |
|
|
8
8
|
## Recommended Setup
|
|
9
9
|
For the best development experience, use both integrations:
|
|
10
10
|
1. **TypeScript Plugin**: Provides real-time feedback in your IDE
|
|
11
11
|
2. **Vite Plugin**: Expands macros during development and production builds
|
|
12
12
|
```
|
|
13
|
-
|
|
14
|
-
npm
|
|
13
|
+
# Install both plugins
|
|
14
|
+
npm install -D @macroforge/typescript-plugin @macroforge/vite-plugin
|
|
15
15
|
``` ## How They Work Together
|
|
16
16
|
<div class="flex justify-center"><div class="border-2 border-primary bg-primary/10 rounded-lg px-6 py-3 text-center"><div class="font-semibold text-primary">Your Code TypeScript with @derive decorators <div class="absolute top-0 h-px bg-border" style="width: 50%; left: 25%;"> <div class="flex flex-col items-center"> <div class="border border-border bg-card rounded-lg px-4 py-3 text-center w-full mt-1"><div class="font-medium text-foreground">TypeScript Plugin Language service integration <div class="border border-success/30 bg-success/10 rounded-md px-3 py-2 text-center"><div class="text-sm font-medium text-success-foreground">IDE Feedback Errors & completions <div class="border border-border bg-card rounded-lg px-4 py-3 text-center w-full mt-1"><div class="font-medium text-foreground">Vite Plugin Build-time transformation <div class="border border-success/30 bg-success/10 rounded-md px-3 py-2 text-center"><div class="text-sm font-medium text-success-foreground">Dev Server Hot reload<div class="text-sm font-medium text-success-foreground">Production Build Optimized output ## Detailed Guides
|
|
17
17
|
- [TypeScript Plugin setup](../docs/integration/typescript-plugin)
|