@macroforge/mcp-server 0.1.33 → 0.1.35
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 +68 -0
- package/dist/index.d.ts +32 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +46 -1
- package/dist/index.js.map +1 -1
- package/dist/tools/docs-loader.d.ts +133 -5
- package/dist/tools/docs-loader.d.ts.map +1 -1
- package/dist/tools/docs-loader.js +131 -15
- package/dist/tools/docs-loader.js.map +1 -1
- package/dist/tools/index.d.ts +48 -1
- package/dist/tools/index.d.ts.map +1 -1
- package/dist/tools/index.js +163 -14
- package/dist/tools/index.js.map +1 -1
- package/docs/api/api-overview.md +24 -46
- package/docs/api/expand-sync.md +24 -51
- package/docs/api/native-plugin.md +24 -56
- package/docs/api/position-mapper.md +34 -76
- package/docs/api/transform-sync.md +27 -59
- package/docs/builtin-macros/clone.md +45 -104
- package/docs/builtin-macros/debug.md +33 -104
- package/docs/builtin-macros/default.md +78 -114
- package/docs/builtin-macros/deserialize.md +93 -273
- package/docs/builtin-macros/hash.md +58 -100
- package/docs/builtin-macros/macros-overview.md +42 -103
- package/docs/builtin-macros/ord.md +65 -133
- package/docs/builtin-macros/partial-eq.md +53 -179
- package/docs/builtin-macros/partial-ord.md +67 -159
- package/docs/builtin-macros/serialize.md +64 -194
- package/docs/concepts/architecture.md +40 -99
- package/docs/concepts/derive-system.md +129 -125
- package/docs/concepts/how-macros-work.md +52 -84
- package/docs/custom-macros/custom-overview.md +17 -39
- package/docs/custom-macros/rust-setup.md +22 -55
- package/docs/custom-macros/ts-macro-derive.md +43 -107
- package/docs/custom-macros/ts-quote.md +177 -507
- package/docs/getting-started/first-macro.md +108 -33
- package/docs/getting-started/installation.md +32 -73
- package/docs/integration/cli.md +70 -156
- package/docs/integration/configuration.md +32 -75
- package/docs/integration/integration-overview.md +16 -55
- package/docs/integration/mcp-server.md +30 -69
- package/docs/integration/svelte-preprocessor.md +60 -83
- package/docs/integration/typescript-plugin.md +32 -74
- package/docs/integration/vite-plugin.md +30 -79
- package/docs/language-servers/ls-overview.md +22 -46
- package/docs/language-servers/svelte.md +30 -69
- package/docs/language-servers/zed.md +34 -72
- package/docs/roadmap/roadmap.md +54 -130
- package/docs/sections.json +3 -262
- package/package.json +2 -2
|
@@ -1,16 +1,64 @@
|
|
|
1
1
|
# Your First Macro
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
2
|
+
*Let's create a class that uses Macroforge's derive macros to automatically generate useful methods.*
|
|
3
|
+
## Creating a Class with Derive Macros
|
|
4
|
+
Start by creating a simple `User` class. We'll use the `@derive` decorator to automatically generate methods.
|
|
5
|
+
**Before:**
|
|
6
|
+
```
|
|
7
|
+
/** @derive(Debug, Clone, PartialEq) */
|
|
8
|
+
export class User {
|
|
9
|
+
name: string;
|
|
10
|
+
age: number;
|
|
11
|
+
email: string;
|
|
12
|
+
|
|
13
|
+
constructor(name: string, age: number, email: string) {
|
|
14
|
+
this.name = name;
|
|
15
|
+
this.age = age;
|
|
16
|
+
this.email = email;
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
```
|
|
20
|
+
**After:**
|
|
21
|
+
```
|
|
22
|
+
export class User {
|
|
23
|
+
name: string;
|
|
24
|
+
age: number;
|
|
25
|
+
email: string;
|
|
26
|
+
|
|
27
|
+
constructor(name: string, age: number, email: string) {
|
|
28
|
+
this.name = name;
|
|
29
|
+
this.age = age;
|
|
30
|
+
this.email = email;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
toString(): string {
|
|
34
|
+
const parts: string[] = [];
|
|
35
|
+
parts.push('name: ' + this.name);
|
|
36
|
+
parts.push('age: ' + this.age);
|
|
37
|
+
parts.push('email: ' + this.email);
|
|
38
|
+
return 'User { ' + parts.join(', ') + ' }';
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
clone(): User {
|
|
42
|
+
const cloned = Object.create(Object.getPrototypeOf(this));
|
|
43
|
+
cloned.name = this.name;
|
|
44
|
+
cloned.age = this.age;
|
|
45
|
+
cloned.email = this.email;
|
|
46
|
+
return cloned;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
equals(other: unknown): boolean {
|
|
50
|
+
if (this === other) return true;
|
|
51
|
+
if (!(other instanceof User)) return false;
|
|
52
|
+
const typedOther = other as User;
|
|
53
|
+
return (
|
|
54
|
+
this.name === typedOther.name &&
|
|
55
|
+
this.age === typedOther.age &&
|
|
56
|
+
this.email === typedOther.email
|
|
57
|
+
);
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
``` ## Using the Generated Methods
|
|
61
|
+
```
|
|
14
62
|
const user = new User("Alice", 30, "alice@example.com");
|
|
15
63
|
|
|
16
64
|
// Debug: toString()
|
|
@@ -26,29 +74,56 @@ console.log(user.equals(copy)); // true
|
|
|
26
74
|
|
|
27
75
|
const different = new User("Bob", 25, "bob@example.com");
|
|
28
76
|
console.log(user.equals(different)); // false
|
|
77
|
+
``` ## Customizing Behavior
|
|
78
|
+
You can customize how macros work using field-level decorators. For example, with the Debug macro:
|
|
79
|
+
**Before:**
|
|
29
80
|
```
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
81
|
+
/** @derive(Debug) */
|
|
82
|
+
export class User {
|
|
83
|
+
/** @debug({ rename: "userId" }) */
|
|
84
|
+
id: number;
|
|
85
|
+
|
|
86
|
+
name: string;
|
|
87
|
+
|
|
88
|
+
/** @debug({ skip: true }) */
|
|
89
|
+
password: string;
|
|
90
|
+
|
|
91
|
+
constructor(id: number, name: string, password: string) {
|
|
92
|
+
this.id = id;
|
|
93
|
+
this.name = name;
|
|
94
|
+
this.password = password;
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
```
|
|
98
|
+
**After:**
|
|
99
|
+
```
|
|
100
|
+
export class User {
|
|
101
|
+
id: number;
|
|
102
|
+
|
|
103
|
+
name: string;
|
|
104
|
+
|
|
105
|
+
password: string;
|
|
106
|
+
|
|
107
|
+
constructor(id: number, name: string, password: string) {
|
|
108
|
+
this.id = id;
|
|
109
|
+
this.name = name;
|
|
110
|
+
this.password = password;
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
toString(): string {
|
|
114
|
+
const parts: string[] = [];
|
|
115
|
+
parts.push('userId: ' + this.id);
|
|
116
|
+
parts.push('name: ' + this.name);
|
|
117
|
+
return 'User { ' + parts.join(', ') + ' }';
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
``` ```
|
|
38
121
|
const user = new User(42, "Alice", "secret123");
|
|
39
122
|
console.log(user.toString());
|
|
40
123
|
// Output: User { userId: 42, name: Alice }
|
|
41
124
|
// Note: 'id' is renamed to 'userId', 'password' is skipped
|
|
42
|
-
```
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
## Next Steps
|
|
49
|
-
|
|
50
|
-
- [Learn how macros work under the hood]({base}/docs/concepts)
|
|
51
|
-
|
|
52
|
-
- [Explore all Debug options]({base}/docs/builtin-macros/debug)
|
|
53
|
-
|
|
54
|
-
- [Create your own custom macros]({base}/docs/custom-macros)
|
|
125
|
+
``` **Field-level decorators Field-level decorators let you control exactly how each field is handled by the macro. ## Next Steps
|
|
126
|
+
- [Learn how macros work under the hood](../../docs/concepts)
|
|
127
|
+
- [Explore all Debug options](../../docs/builtin-macros/debug)
|
|
128
|
+
- [Create your own custom macros](../../docs/custom-macros)
|
|
129
|
+
**
|
|
@@ -1,42 +1,20 @@
|
|
|
1
1
|
# Installation
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
- TypeScript 5.9 or later
|
|
10
|
-
|
|
11
|
-
## Install the Package
|
|
12
|
-
|
|
13
|
-
Install Macroforge using your preferred package manager:
|
|
14
|
-
|
|
15
|
-
`npm`
|
|
16
|
-
```bash
|
|
2
|
+
*Get started with Macroforge in just a few minutes. Install the package and configure your project to start using TypeScript macros.*
|
|
3
|
+
## Requirements
|
|
4
|
+
- Node.js 24.0 or later
|
|
5
|
+
- TypeScript 5.9 or later
|
|
6
|
+
## Install the Package
|
|
7
|
+
Install Macroforge using your preferred package manager:
|
|
8
|
+
```
|
|
17
9
|
npm install macroforge
|
|
18
|
-
```
|
|
19
|
-
|
|
20
|
-
`bun`
|
|
21
|
-
```bash
|
|
10
|
+
``` ```
|
|
22
11
|
bun add macroforge
|
|
23
|
-
```
|
|
24
|
-
|
|
25
|
-
`pnpm`
|
|
26
|
-
```bash
|
|
12
|
+
``` ```
|
|
27
13
|
pnpm add macroforge
|
|
28
|
-
```
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
## Basic Usage
|
|
34
|
-
|
|
35
|
-
The simplest way to use Macroforge is with the built-in derive macros. Add a `@derive` comment decorator to your class:
|
|
36
|
-
|
|
37
|
-
`user.ts`
|
|
38
|
-
```typescript
|
|
39
|
-
/** @derive(Debug, Clone, Eq) */
|
|
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 `@derive` comment decorator to your class:
|
|
16
|
+
```
|
|
17
|
+
/** @derive(Debug, Clone, PartialEq) */
|
|
40
18
|
class User {
|
|
41
19
|
name: string;
|
|
42
20
|
age: number;
|
|
@@ -48,17 +26,12 @@ class User {
|
|
|
48
26
|
}
|
|
49
27
|
|
|
50
28
|
// After macro expansion, User has:
|
|
51
|
-
// - toString(): string
|
|
52
|
-
// - clone(): User
|
|
53
|
-
// - equals(other:
|
|
54
|
-
```
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
For the best development experience, add the TypeScript plugin to your `tsconfig.json`:
|
|
59
|
-
|
|
60
|
-
`tsconfig.json`
|
|
61
|
-
```json
|
|
29
|
+
// - toString(): string (from Debug)
|
|
30
|
+
// - clone(): User (from Clone)
|
|
31
|
+
// - equals(other: unknown): boolean (from PartialEq)
|
|
32
|
+
``` ## IDE Integration
|
|
33
|
+
For the best development experience, add the TypeScript plugin to your `tsconfig.json`:
|
|
34
|
+
```
|
|
62
35
|
{
|
|
63
36
|
"compilerOptions": {
|
|
64
37
|
"plugins": [
|
|
@@ -68,22 +41,13 @@ For the best development experience, add the TypeScript plugin to your `tsconfig
|
|
|
68
41
|
]
|
|
69
42
|
}
|
|
70
43
|
}
|
|
71
|
-
```
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
- Type checking for expanded code
|
|
80
|
-
|
|
81
|
-
## Build Integration (Vite)
|
|
82
|
-
|
|
83
|
-
If you're using Vite, add the plugin to your config for automatic macro expansion during build:
|
|
84
|
-
|
|
85
|
-
`vite.config.ts`
|
|
86
|
-
```typescript
|
|
44
|
+
``` This enables features like:
|
|
45
|
+
- Accurate error positions in your source code
|
|
46
|
+
- Autocompletion for generated methods
|
|
47
|
+
- Type checking for expanded code
|
|
48
|
+
## Build Integration (Vite)
|
|
49
|
+
If you're using Vite, add the plugin to your config for automatic macro expansion during build:
|
|
50
|
+
```
|
|
87
51
|
import macroforge from "@macroforge/vite-plugin";
|
|
88
52
|
import { defineConfig } from "vite";
|
|
89
53
|
|
|
@@ -95,14 +59,9 @@ export default defineConfig({
|
|
|
95
59
|
})
|
|
96
60
|
]
|
|
97
61
|
});
|
|
98
|
-
```
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
- [Create your first macro]({base}/docs/getting-started/first-macro)
|
|
105
|
-
|
|
106
|
-
- [Understand how macros work]({base}/docs/concepts)
|
|
107
|
-
|
|
108
|
-
- [Explore built-in macros]({base}/docs/builtin-macros)
|
|
62
|
+
``` ## Next Steps
|
|
63
|
+
Now that you have Macroforge installed, learn how to use it:
|
|
64
|
+
- [Create your first macro](../docs/getting-started/first-macro)
|
|
65
|
+
- [Understand how macros work](../docs/concepts)
|
|
66
|
+
- [Explore built-in macros](../docs/builtin-macros)
|
|
67
|
+
**
|
package/docs/integration/cli.md
CHANGED
|
@@ -1,117 +1,64 @@
|
|
|
1
1
|
# Command Line Interface
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
The CLI is a Rust binary. You can install it using Cargo:
|
|
8
|
-
|
|
9
|
-
```bash
|
|
2
|
+
*This binary provides command-line utilities for working with Macroforge TypeScript macros. It is designed for development workflows, enabling macro expansion and type checking without requiring Node.js integration.*
|
|
3
|
+
## Installation
|
|
4
|
+
The CLI is a Rust binary. You can install it using Cargo:
|
|
5
|
+
```
|
|
10
6
|
cargo install macroforge_ts
|
|
11
|
-
```
|
|
12
|
-
|
|
13
|
-
Or build from source:
|
|
14
|
-
|
|
15
|
-
```bash
|
|
7
|
+
``` Or build from source:
|
|
8
|
+
```
|
|
16
9
|
git clone https://github.com/rymskip/macroforge-ts.git
|
|
17
10
|
cd macroforge-ts/crates
|
|
18
11
|
cargo build --release --bin macroforge
|
|
19
12
|
|
|
20
13
|
# The binary is at target/release/macroforge
|
|
21
|
-
```
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
### macroforge expand
|
|
26
|
-
|
|
27
|
-
Expands macros in a TypeScript file and outputs the transformed code.
|
|
28
|
-
|
|
29
|
-
```bash
|
|
14
|
+
``` ## Commands
|
|
15
|
+
### macroforge expand
|
|
16
|
+
Expands macros in a TypeScript file and outputs the transformed code.
|
|
17
|
+
```
|
|
30
18
|
macroforge expand <input> [options]
|
|
31
|
-
```
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
| `--out
|
|
41
|
-
|
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
| `--print`
|
|
47
|
-
| Print output to stdout even when `--out` is specified
|
|
48
|
-
|
|
49
|
-
| `--builtin-only`
|
|
50
|
-
| Use only built-in Rust macros (faster, but no external macro support)
|
|
51
|
-
|
|
52
|
-
#### Examples
|
|
53
|
-
|
|
54
|
-
Expand a file and print to stdout:
|
|
55
|
-
|
|
56
|
-
```bash
|
|
19
|
+
``` #### Arguments
|
|
20
|
+
| Argument | Description |
|
|
21
|
+
| --- | --- |
|
|
22
|
+
| `<input>` | Path to the TypeScript or TSX file to expand |
|
|
23
|
+
#### Options
|
|
24
|
+
| Option | Description |
|
|
25
|
+
| --- | --- |
|
|
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
|
+
#### Examples
|
|
31
|
+
Expand a file and print to stdout:
|
|
32
|
+
```
|
|
57
33
|
macroforge expand src/user.ts
|
|
58
|
-
```
|
|
59
|
-
|
|
60
|
-
Expand and write to a file:
|
|
61
|
-
|
|
62
|
-
```bash
|
|
34
|
+
``` Expand and write to a file:
|
|
35
|
+
```
|
|
63
36
|
macroforge expand src/user.ts --out dist/user.js
|
|
64
|
-
```
|
|
65
|
-
|
|
66
|
-
Expand with both runtime output and type declarations:
|
|
67
|
-
|
|
68
|
-
```bash
|
|
37
|
+
``` Expand with both runtime output and type declarations:
|
|
38
|
+
```
|
|
69
39
|
macroforge expand src/user.ts --out dist/user.js --types-out dist/user.d.ts
|
|
70
|
-
```
|
|
71
|
-
|
|
72
|
-
Use fast built-in macros only (no external macro support):
|
|
73
|
-
|
|
74
|
-
```bash
|
|
40
|
+
``` Use fast built-in macros only (no external macro support):
|
|
41
|
+
```
|
|
75
42
|
macroforge expand src/user.ts --builtin-only
|
|
76
|
-
```
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
> 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`.
|
|
80
|
-
|
|
81
|
-
### macroforge tsc
|
|
82
|
-
|
|
83
|
-
Runs TypeScript type checking with macro expansion. This wraps `tsc --noEmit` and expands macros before type checking, so your generated methods are properly type-checked.
|
|
84
|
-
|
|
85
|
-
```bash
|
|
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 `tsc --noEmit` and expands macros before type checking, so your generated methods are properly type-checked.
|
|
45
|
+
```
|
|
86
46
|
macroforge tsc [options]
|
|
87
|
-
```
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
#### Examples
|
|
95
|
-
|
|
96
|
-
Type check with default tsconfig.json:
|
|
97
|
-
|
|
98
|
-
```bash
|
|
47
|
+
``` #### Options
|
|
48
|
+
| Option | Description |
|
|
49
|
+
| --- | --- |
|
|
50
|
+
| `-p, --project <path>` | Path to `tsconfig.json` (defaults to `tsconfig.json` in current directory) |
|
|
51
|
+
#### Examples
|
|
52
|
+
Type check with default tsconfig.json:
|
|
53
|
+
```
|
|
99
54
|
macroforge tsc
|
|
100
|
-
```
|
|
101
|
-
|
|
102
|
-
Type check with a specific config:
|
|
103
|
-
|
|
104
|
-
```bash
|
|
55
|
+
``` Type check with a specific config:
|
|
56
|
+
```
|
|
105
57
|
macroforge tsc -p tsconfig.build.json
|
|
106
|
-
```
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
### Expanded Code
|
|
111
|
-
|
|
112
|
-
When expanding a file like this:
|
|
113
|
-
|
|
114
|
-
```typescript
|
|
58
|
+
``` ## Output Format
|
|
59
|
+
### Expanded Code
|
|
60
|
+
When expanding a file like this:
|
|
61
|
+
```
|
|
115
62
|
/** @derive(Debug) */
|
|
116
63
|
class User {
|
|
117
64
|
name: string;
|
|
@@ -122,11 +69,8 @@ class User {
|
|
|
122
69
|
this.age = age;
|
|
123
70
|
}
|
|
124
71
|
}
|
|
125
|
-
```
|
|
126
|
-
|
|
127
|
-
The CLI outputs the expanded code with the generated methods:
|
|
128
|
-
|
|
129
|
-
```typescript
|
|
72
|
+
``` The CLI outputs the expanded code with the generated methods:
|
|
73
|
+
```
|
|
130
74
|
class User {
|
|
131
75
|
name: string;
|
|
132
76
|
age: number;
|
|
@@ -137,71 +81,41 @@ class User {
|
|
|
137
81
|
}
|
|
138
82
|
|
|
139
83
|
[Symbol.for("nodejs.util.inspect.custom")](): string {
|
|
140
|
-
return
|
|
84
|
+
return `User { name: ${this.name}, age: ${this.age} }`;
|
|
141
85
|
}
|
|
142
86
|
}
|
|
143
|
-
```
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
Errors and warnings are printed to stderr in a readable format:
|
|
148
|
-
|
|
149
|
-
```text
|
|
87
|
+
``` ### Diagnostics
|
|
88
|
+
Errors and warnings are printed to stderr in a readable format:
|
|
89
|
+
```
|
|
150
90
|
[macroforge] error at src/user.ts:5:1: Unknown derive macro: InvalidMacro
|
|
151
91
|
[macroforge] warning at src/user.ts:10:3: Field 'unused' is never used
|
|
152
|
-
```
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
### CI/CD Type Checking
|
|
157
|
-
|
|
158
|
-
Use `macroforge tsc` in your CI pipeline to type-check with macro expansion:
|
|
159
|
-
|
|
160
|
-
```json
|
|
92
|
+
``` ## Use Cases
|
|
93
|
+
### CI/CD Type Checking
|
|
94
|
+
Use `macroforge tsc` in your CI pipeline to type-check with macro expansion:
|
|
95
|
+
```
|
|
161
96
|
# package.json
|
|
162
97
|
{
|
|
163
98
|
"scripts": {
|
|
164
99
|
"typecheck": "macroforge tsc"
|
|
165
100
|
}
|
|
166
101
|
}
|
|
167
|
-
```
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
Use `macroforge expand` to inspect what code your macros generate:
|
|
172
|
-
|
|
173
|
-
```bash
|
|
102
|
+
``` ### Debugging Macro Output
|
|
103
|
+
Use `macroforge expand` to inspect what code your macros generate:
|
|
104
|
+
```
|
|
174
105
|
macroforge expand src/models/user.ts | less
|
|
175
|
-
```
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
Generate expanded files as part of a custom build:
|
|
180
|
-
|
|
181
|
-
```bash
|
|
106
|
+
``` ### Build Pipeline
|
|
107
|
+
Generate expanded files as part of a custom build:
|
|
108
|
+
```
|
|
182
109
|
#!/bin/bash
|
|
183
110
|
for file in src/**/*.ts; do
|
|
184
111
|
outfile="dist/$(basename "$file" .ts).js"
|
|
185
112
|
macroforge expand "$file" --out "$outfile"
|
|
186
113
|
done
|
|
187
|
-
```
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
|
194
|
-
|
|
|
195
|
-
| Yes
|
|
196
|
-
|
|
197
|
-
| External macros
|
|
198
|
-
| Yes
|
|
199
|
-
| No
|
|
200
|
-
|
|
201
|
-
| Performance
|
|
202
|
-
| Standard
|
|
203
|
-
| Faster
|
|
204
|
-
|
|
205
|
-
| Dependencies
|
|
206
|
-
| Requires `macroforge` in node_modules
|
|
207
|
-
| None
|
|
114
|
+
``` ## Built-in vs Full Mode
|
|
115
|
+
By default, the CLI uses Node.js for full macro support including external macros. Use `--builtin-only` for faster expansion when you only need built-in macros:
|
|
116
|
+
| Feature | Default (Node.js) | `--builtin-only` (Rust) |
|
|
117
|
+
| --- | --- | --- |
|
|
118
|
+
| Built-in macros | Yes | Yes |
|
|
119
|
+
| External macros | Yes | No |
|
|
120
|
+
| Performance | Standard | Faster |
|
|
121
|
+
| Dependencies | Requires `macroforge` in node_modules | None |
|
|
@@ -1,13 +1,8 @@
|
|
|
1
1
|
# Configuration
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
Create a `macroforge.json` file:
|
|
8
|
-
|
|
9
|
-
`macroforge.json`
|
|
10
|
-
```json
|
|
2
|
+
*Macroforge can be configured with a `macroforge.json` file in your project root.*
|
|
3
|
+
## Configuration File
|
|
4
|
+
Create a `macroforge.json` file:
|
|
5
|
+
```
|
|
11
6
|
{
|
|
12
7
|
"allowNativeMacros": true,
|
|
13
8
|
"macroPackages": [],
|
|
@@ -19,54 +14,29 @@ Create a `macroforge.json` file:
|
|
|
19
14
|
"maxDiagnostics": 100
|
|
20
15
|
}
|
|
21
16
|
}
|
|
22
|
-
```
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
| Type
|
|
29
|
-
| `
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
| `true`
|
|
33
|
-
|
|
34
|
-
Enable or disable native (Rust) macro packages. Set to `false` to only allow built-in macros.
|
|
35
|
-
|
|
36
|
-
### macroPackages
|
|
37
|
-
|
|
38
|
-
| Type
|
|
39
|
-
| `string[]`
|
|
40
|
-
|
|
41
|
-
| Default
|
|
42
|
-
| `[]`
|
|
43
|
-
|
|
44
|
-
List of npm packages that provide macros. Macroforge will look for macros in these packages.
|
|
45
|
-
|
|
46
|
-
```json
|
|
17
|
+
``` ## Options Reference
|
|
18
|
+
### allowNativeMacros
|
|
19
|
+
| Type | `boolean` |
|
|
20
|
+
| Default | `true` |
|
|
21
|
+
Enable or disable native (Rust) macro packages. Set to `false` to only allow built-in macros.
|
|
22
|
+
### macroPackages
|
|
23
|
+
| Type | `string[]` |
|
|
24
|
+
| Default | `[]` |
|
|
25
|
+
List of npm packages that provide macros. Macroforge will look for macros in these packages.
|
|
26
|
+
```
|
|
47
27
|
{
|
|
48
28
|
"macroPackages": [
|
|
49
29
|
"@my-org/custom-macros",
|
|
50
30
|
"community-macros"
|
|
51
31
|
]
|
|
52
32
|
}
|
|
53
|
-
```
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
| Default
|
|
61
|
-
| `false`
|
|
62
|
-
|
|
63
|
-
Keep `@derive` decorators in the output. Useful for debugging.
|
|
64
|
-
|
|
65
|
-
### limits
|
|
66
|
-
|
|
67
|
-
Configure resource limits for macro expansion:
|
|
68
|
-
|
|
69
|
-
```json
|
|
33
|
+
``` ### keepDecorators
|
|
34
|
+
| Type | `boolean` |
|
|
35
|
+
| Default | `false` |
|
|
36
|
+
Keep `@derive` decorators in the output. Useful for debugging.
|
|
37
|
+
### limits
|
|
38
|
+
Configure resource limits for macro expansion:
|
|
39
|
+
```
|
|
70
40
|
{
|
|
71
41
|
"limits": {
|
|
72
42
|
// Maximum time for a single macro expansion (ms)
|
|
@@ -82,13 +52,9 @@ Configure resource limits for macro expansion:
|
|
|
82
52
|
"maxDiagnostics": 100
|
|
83
53
|
}
|
|
84
54
|
}
|
|
85
|
-
```
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
Override settings for specific macros:
|
|
90
|
-
|
|
91
|
-
```json
|
|
55
|
+
``` ## Macro Runtime Overrides
|
|
56
|
+
Override settings for specific macros:
|
|
57
|
+
```
|
|
92
58
|
{
|
|
93
59
|
"macroRuntimeOverrides": {
|
|
94
60
|
"@my-org/macros": {
|
|
@@ -96,21 +62,12 @@ Override settings for specific macros:
|
|
|
96
62
|
}
|
|
97
63
|
}
|
|
98
64
|
}
|
|
99
|
-
```
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
Some settings can be overridden with environment variables:
|
|
107
|
-
|
|
108
|
-
| `MACROFORGE_DEBUG`
|
|
109
|
-
| Enable debug logging
|
|
110
|
-
|
|
111
|
-
| `MACROFORGE_LOG_FILE`
|
|
112
|
-
| Write logs to a file
|
|
113
|
-
|
|
114
|
-
```bash
|
|
65
|
+
``` **Warning Be careful when increasing limits, as this could allow malicious macros to consume excessive resources. ## Environment Variables
|
|
66
|
+
Some settings can be overridden with environment variables:
|
|
67
|
+
| Variable | Description |
|
|
68
|
+
| --- | --- |
|
|
69
|
+
| `MACROFORGE_DEBUG` | Enable debug logging |
|
|
70
|
+
| `MACROFORGE_LOG_FILE` | Write logs to a file |
|
|
71
|
+
```
|
|
115
72
|
MACROFORGE_DEBUG=1 npm run dev
|
|
116
|
-
|
|
73
|
+
```**
|