@macroforge/mcp-server 0.1.40 → 0.1.49
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 +22 -0
- package/docs/BOOK.md +165 -0
- package/docs/api/api-overview.md +65 -46
- package/docs/api/expand-sync.md +88 -53
- package/docs/api/native-plugin.md +121 -71
- package/docs/api/position-mapper.md +114 -54
- package/docs/api/transform-sync.md +85 -59
- package/docs/builtin-macros/clone.md +0 -20
- package/docs/builtin-macros/debug.md +0 -23
- package/docs/builtin-macros/default.md +1 -40
- package/docs/builtin-macros/deserialize/example.md +8 -1416
- package/docs/builtin-macros/deserialize.md +8 -1416
- package/docs/builtin-macros/hash.md +0 -42
- package/docs/builtin-macros/macros-overview/detailed-documentation.md +13 -0
- package/docs/builtin-macros/macros-overview/enum-support.md +30 -0
- package/docs/builtin-macros/macros-overview/interface-support.md +28 -0
- package/docs/builtin-macros/macros-overview/overview.md +36 -0
- package/docs/builtin-macros/macros-overview/type-alias-support.md +62 -0
- package/docs/builtin-macros/macros-overview.md +171 -130
- package/docs/builtin-macros/ord.md +0 -25
- package/docs/builtin-macros/partial-eq.md +0 -84
- package/docs/builtin-macros/partial-ord.md +11 -43
- package/docs/builtin-macros/serialize.md +2 -62
- package/docs/concepts/architecture.md +125 -48
- package/docs/concepts/derive-system/built-in-vs-custom-macros.md +13 -0
- package/docs/concepts/derive-system/overview.md +200 -0
- package/docs/concepts/derive-system.md +171 -97
- package/docs/concepts/how-macros-work.md +89 -37
- package/docs/custom-macros/custom-overview.md +79 -57
- package/docs/custom-macros/rust-setup.md +138 -99
- package/docs/custom-macros/ts-macro-derive/accessing-field-data.md +40 -31
- package/docs/custom-macros/ts-macro-derive/adding-imports.md +14 -11
- package/docs/custom-macros/ts-macro-derive/attribute-options.md +20 -25
- package/docs/custom-macros/ts-macro-derive/complete-example.md +40 -38
- package/docs/custom-macros/ts-macro-derive/deriveinput-structure.md +49 -47
- package/docs/custom-macros/ts-macro-derive/function-signature.md +12 -0
- package/docs/custom-macros/ts-macro-derive/overview.md +9 -7
- package/docs/custom-macros/ts-macro-derive/parsing-input.md +20 -18
- package/docs/custom-macros/ts-macro-derive/returning-errors.md +15 -13
- package/docs/custom-macros/ts-macro-derive.md +322 -228
- package/docs/custom-macros/ts-quote/backtick-template-literals.md +19 -7
- package/docs/custom-macros/ts-quote/comments-and.md +56 -22
- package/docs/custom-macros/ts-quote/complete-example-json-derive-macro.md +89 -98
- package/docs/custom-macros/ts-quote/conditionals-ifif.md +35 -29
- package/docs/custom-macros/ts-quote/identifier-concatenation-content.md +30 -22
- package/docs/custom-macros/ts-quote/iteration-for.md +48 -40
- package/docs/custom-macros/ts-quote/local-constants-let.md +23 -21
- package/docs/custom-macros/ts-quote/match-expressions-match.md +46 -38
- package/docs/custom-macros/ts-quote/overview.md +5 -10
- package/docs/custom-macros/ts-quote/pattern-matching-iflet.md +39 -0
- package/docs/custom-macros/ts-quote/quick-reference.md +50 -129
- package/docs/custom-macros/ts-quote/side-effects-do.md +13 -78
- package/docs/custom-macros/ts-quote/string-interpolation-textexpr.md +36 -0
- package/docs/custom-macros/ts-quote/tsstream-injection-typescript.md +43 -35
- package/docs/custom-macros/ts-quote/while-loops-while.md +31 -23
- package/docs/custom-macros/ts-quote.md +799 -519
- package/docs/getting-started/first-macro.md +61 -32
- package/docs/getting-started/installation.md +109 -66
- package/docs/integration/cli.md +212 -103
- package/docs/integration/configuration.md +114 -71
- package/docs/integration/integration-overview.md +54 -17
- package/docs/integration/mcp-server.md +83 -42
- package/docs/integration/svelte-preprocessor.md +183 -126
- package/docs/integration/typescript-plugin.md +101 -54
- package/docs/integration/vite-plugin.md +116 -76
- package/docs/language-servers/ls-overview.md +37 -21
- package/docs/language-servers/svelte.md +69 -39
- package/docs/language-servers/zed.md +81 -45
- package/docs/roadmap/roadmap.md +75 -53
- package/docs/sections.json +333 -44
- package/package.json +27 -28
|
@@ -1,8 +1,13 @@
|
|
|
1
1
|
# Your First Macro
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
2
|
+
|
|
3
|
+
Let's create a class that uses Macroforge's derive macros to automatically generate useful methods.
|
|
4
|
+
|
|
5
|
+
## Creating a Class with Derive Macros
|
|
6
|
+
|
|
7
|
+
Start by creating a simple `User` class. We'll use the `@derive` decorator to automatically generate methods.
|
|
8
|
+
|
|
9
|
+
Before (Your Code)
|
|
10
|
+
|
|
6
11
|
```
|
|
7
12
|
/** @derive(Debug, Clone, PartialEq) */
|
|
8
13
|
export class User {
|
|
@@ -16,8 +21,10 @@ export class User {
|
|
|
16
21
|
this.email = email;
|
|
17
22
|
}
|
|
18
23
|
}
|
|
19
|
-
```
|
|
20
|
-
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
After (Generated)
|
|
27
|
+
|
|
21
28
|
```
|
|
22
29
|
export class User {
|
|
23
30
|
name: string;
|
|
@@ -63,26 +70,36 @@ export function userEquals(a: User, b: User): boolean {
|
|
|
63
70
|
if (a === b) return true;
|
|
64
71
|
return a.name === b.name && a.age === b.age && a.email === b.email;
|
|
65
72
|
}
|
|
66
|
-
```
|
|
67
|
-
|
|
68
|
-
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
## Using the Generated Methods
|
|
69
76
|
|
|
70
|
-
|
|
77
|
+
TypeScript
|
|
78
|
+
|
|
79
|
+
```
|
|
80
|
+
const user = new User("Alice", 30, "alice@example.com");
|
|
81
|
+
|
|
82
|
+
// Debug: toString()
|
|
71
83
|
console.log(user.toString());
|
|
72
|
-
//
|
|
84
|
+
// Output: User { name: Alice, age: 30, email: alice@example.com }
|
|
85
|
+
|
|
86
|
+
// Clone: clone()
|
|
87
|
+
const copy = user.clone();
|
|
88
|
+
console.log(copy.name); // "Alice"
|
|
89
|
+
|
|
90
|
+
// Eq: equals()
|
|
91
|
+
console.log(user.equals(copy)); // true
|
|
73
92
|
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
93
|
+
const different = new User("Bob", 25, "bob@example.com");
|
|
94
|
+
console.log(user.equals(different)); // false
|
|
95
|
+
```
|
|
96
|
+
|
|
97
|
+
## Customizing Behavior
|
|
77
98
|
|
|
78
|
-
|
|
79
|
-
|
|
99
|
+
You can customize how macros work using field-level decorators. For example, with the Debug macro:
|
|
100
|
+
|
|
101
|
+
Before (Your Code)
|
|
80
102
|
|
|
81
|
-
const different = new User("Bob", 25, "bob@example.com");
|
|
82
|
-
console.log(user.equals(different)); // false
|
|
83
|
-
``` ## Customizing Behavior
|
|
84
|
-
You can customize how macros work using field-level decorators. For example, with the Debug macro:
|
|
85
|
-
**Before:**
|
|
86
103
|
```
|
|
87
104
|
/** @derive(Debug) */
|
|
88
105
|
export class User {
|
|
@@ -100,8 +117,10 @@ export class User {
|
|
|
100
117
|
this.password = password;
|
|
101
118
|
}
|
|
102
119
|
}
|
|
103
|
-
```
|
|
104
|
-
|
|
120
|
+
```
|
|
121
|
+
|
|
122
|
+
After (Generated)
|
|
123
|
+
|
|
105
124
|
```
|
|
106
125
|
export class User {
|
|
107
126
|
id: number;
|
|
@@ -127,13 +146,23 @@ export function userToString(value: User): string {
|
|
|
127
146
|
parts.push('name: ' + value.name);
|
|
128
147
|
return 'User { ' + parts.join(', ') + ' }';
|
|
129
148
|
}
|
|
130
|
-
```
|
|
131
|
-
|
|
149
|
+
```
|
|
150
|
+
|
|
151
|
+
TypeScript
|
|
152
|
+
|
|
153
|
+
```
|
|
154
|
+
const user = new User(42, "Alice", "secret123");
|
|
132
155
|
console.log(user.toString());
|
|
133
|
-
//
|
|
134
|
-
//
|
|
135
|
-
```
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
156
|
+
// Output: User { userId: 42, name: Alice }
|
|
157
|
+
// Note: 'id' is renamed to 'userId', 'password' is skipped
|
|
158
|
+
```
|
|
159
|
+
|
|
160
|
+
Field-level decorators
|
|
161
|
+
|
|
162
|
+
Field-level decorators let you control exactly how each field is handled by the macro.
|
|
163
|
+
|
|
164
|
+
## Next Steps
|
|
165
|
+
|
|
166
|
+
* [Learn how macros work under the hood](../../docs/concepts)
|
|
167
|
+
* [Explore all Debug options](../../docs/builtin-macros/debug)
|
|
168
|
+
* [Create your own custom macros](../../docs/custom-macros)
|
|
@@ -1,67 +1,110 @@
|
|
|
1
1
|
# Installation
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
2
|
+
|
|
3
|
+
Get started with Macroforge in just a few minutes. Install the package and configure your project to start using TypeScript macros.
|
|
4
|
+
|
|
5
|
+
## Requirements
|
|
6
|
+
|
|
7
|
+
* Node.js 24.0 or later
|
|
8
|
+
* TypeScript 5.9 or later
|
|
9
|
+
|
|
10
|
+
## Install the Package
|
|
11
|
+
|
|
12
|
+
Install Macroforge using your preferred package manager:
|
|
13
|
+
|
|
14
|
+
npm
|
|
15
|
+
|
|
16
|
+
```
|
|
17
|
+
npm install macroforge
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
bun
|
|
21
|
+
|
|
22
|
+
```
|
|
23
|
+
bun add macroforge
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
pnpm
|
|
27
|
+
|
|
28
|
+
```
|
|
29
|
+
pnpm add macroforge
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
Info
|
|
33
|
+
|
|
34
|
+
Macroforge includes pre-built native binaries for macOS (x64, arm64), Linux (x64, arm64), and Windows (x64, arm64).
|
|
35
|
+
|
|
36
|
+
## Basic Usage
|
|
37
|
+
|
|
38
|
+
The simplest way to use Macroforge is with the built-in derive macros. Add a `@derive` comment decorator to your class:
|
|
39
|
+
|
|
40
|
+
user.ts
|
|
41
|
+
|
|
42
|
+
```
|
|
43
|
+
/** @derive(Debug, Clone, PartialEq) */
|
|
44
|
+
class User {
|
|
45
|
+
name: string;
|
|
46
|
+
age: number;
|
|
47
|
+
|
|
48
|
+
constructor(name: string, age: number) {
|
|
49
|
+
this.name = name;
|
|
50
|
+
this.age = age;
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
// After macro expansion, User has:
|
|
55
|
+
// - toString(): string (from Debug)
|
|
56
|
+
// - clone(): User (from Clone)
|
|
57
|
+
// - equals(other: unknown): boolean (from PartialEq)
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
## IDE Integration
|
|
61
|
+
|
|
62
|
+
For the best development experience, add the TypeScript plugin to your `tsconfig.json`:
|
|
63
|
+
|
|
64
|
+
tsconfig.json
|
|
65
|
+
|
|
66
|
+
```
|
|
67
|
+
{
|
|
68
|
+
"compilerOptions": {
|
|
69
|
+
"plugins": [
|
|
70
|
+
{
|
|
71
|
+
"name": "@macroforge/typescript-plugin"
|
|
72
|
+
}
|
|
73
|
+
]
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
This enables features like:
|
|
79
|
+
|
|
80
|
+
* Accurate error positions in your source code
|
|
81
|
+
* Autocompletion for generated methods
|
|
82
|
+
* Type checking for expanded code
|
|
83
|
+
|
|
84
|
+
## Build Integration (Vite)
|
|
85
|
+
|
|
86
|
+
If you're using Vite, add the plugin to your config for automatic macro expansion during build:
|
|
87
|
+
|
|
88
|
+
vite.config.ts
|
|
89
|
+
|
|
90
|
+
```
|
|
91
|
+
import macroforge from "@macroforge/vite-plugin";
|
|
92
|
+
import { defineConfig } from "vite";
|
|
93
|
+
|
|
94
|
+
export default defineConfig({
|
|
95
|
+
plugins: [
|
|
96
|
+
macroforge({
|
|
97
|
+
generateTypes: true,
|
|
98
|
+
typesOutputDir: ".macroforge/types"
|
|
99
|
+
})
|
|
100
|
+
]
|
|
101
|
+
});
|
|
102
|
+
```
|
|
103
|
+
|
|
104
|
+
## Next Steps
|
|
105
|
+
|
|
106
|
+
Now that you have Macroforge installed, learn how to use it:
|
|
107
|
+
|
|
108
|
+
* [Create your first macro](../docs/getting-started/first-macro)
|
|
109
|
+
* [Understand how macros work](../docs/concepts)
|
|
110
|
+
* [Explore built-in macros](../docs/builtin-macros)
|
package/docs/integration/cli.md
CHANGED
|
@@ -1,76 +1,156 @@
|
|
|
1
1
|
# Command Line Interface
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
2
|
+
|
|
3
|
+
macroforge v0.1.43
|
|
4
|
+
|
|
5
|
+
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.
|
|
6
|
+
|
|
7
|
+
## Installation
|
|
8
|
+
|
|
9
|
+
The CLI is a Rust binary. You can install it using Cargo:
|
|
10
|
+
|
|
11
|
+
Bash
|
|
12
|
+
|
|
13
|
+
```
|
|
14
|
+
cargo install macroforge_ts
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
Or build from source:
|
|
18
|
+
|
|
19
|
+
Bash
|
|
20
|
+
|
|
21
|
+
```
|
|
22
|
+
git clone https://github.com/rymskip/macroforge-ts.git
|
|
23
|
+
cd macroforge-ts/crates
|
|
24
|
+
cargo build --release --bin macroforge
|
|
25
|
+
|
|
26
|
+
# The binary is at target/release/macroforge
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
## Commands
|
|
30
|
+
|
|
31
|
+
### macroforge expand
|
|
32
|
+
|
|
33
|
+
Expands macros in a TypeScript file and outputs the transformed code.
|
|
34
|
+
|
|
35
|
+
Bash
|
|
36
|
+
|
|
37
|
+
```
|
|
38
|
+
macroforge expand <input> [options]
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
#### Arguments
|
|
42
|
+
|
|
43
|
+
| Argument | Description |
|
|
44
|
+
| --------- | -------------------------------------------- |
|
|
22
45
|
| `<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
|
-
```
|
|
33
|
-
macroforge expand src/user.ts
|
|
34
|
-
``` Expand and write to a file:
|
|
35
|
-
```
|
|
36
|
-
macroforge expand src/user.ts --out dist/user.js
|
|
37
|
-
``` Expand with both runtime output and type declarations:
|
|
38
|
-
```
|
|
39
|
-
macroforge expand src/user.ts --out dist/user.js --types-out dist/user.d.ts
|
|
40
|
-
``` Use fast built-in macros only (no external macro support):
|
|
41
|
-
```
|
|
42
|
-
macroforge expand src/user.ts --builtin-only
|
|
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
|
-
```
|
|
46
|
-
macroforge tsc [options]
|
|
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
|
-
```
|
|
54
|
-
macroforge tsc
|
|
55
|
-
``` Type check with a specific config:
|
|
56
|
-
```
|
|
57
|
-
macroforge tsc -p tsconfig.build.json
|
|
58
|
-
``` ## Output Format
|
|
59
|
-
### Expanded Code
|
|
60
|
-
When expanding a file like this:
|
|
61
|
-
```
|
|
62
|
-
/** @derive(Debug) */
|
|
63
|
-
class User {
|
|
64
|
-
name: string;
|
|
65
|
-
age: number;
|
|
66
46
|
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
47
|
+
#### Options
|
|
48
|
+
|
|
49
|
+
| Option | Description |
|
|
50
|
+
| -------------------- | --------------------------------------------------------------------- |
|
|
51
|
+
| `--out <path>` | Write the expanded JavaScript/TypeScript to a file |
|
|
52
|
+
| `--types-out <path>` | Write the generated `.d.ts` declarations to a file |
|
|
53
|
+
| `--print` | Print output to stdout even when `--out` is specified |
|
|
54
|
+
| `--builtin-only` | Use only built-in Rust macros (faster, but no external macro support) |
|
|
55
|
+
|
|
56
|
+
#### Examples
|
|
57
|
+
|
|
58
|
+
Expand a file and print to stdout:
|
|
59
|
+
|
|
60
|
+
Bash
|
|
61
|
+
|
|
62
|
+
```
|
|
63
|
+
macroforge expand src/user.ts
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
Expand and write to a file:
|
|
67
|
+
|
|
68
|
+
Bash
|
|
69
|
+
|
|
70
|
+
```
|
|
71
|
+
macroforge expand src/user.ts --out dist/user.js
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
Expand with both runtime output and type declarations:
|
|
75
|
+
|
|
76
|
+
Bash
|
|
77
|
+
|
|
78
|
+
```
|
|
79
|
+
macroforge expand src/user.ts --out dist/user.js --types-out dist/user.d.ts
|
|
80
|
+
```
|
|
81
|
+
|
|
82
|
+
Use fast built-in macros only (no external macro support):
|
|
83
|
+
|
|
84
|
+
Bash
|
|
85
|
+
|
|
86
|
+
```
|
|
87
|
+
macroforge expand src/user.ts --builtin-only
|
|
88
|
+
```
|
|
89
|
+
|
|
90
|
+
Note
|
|
91
|
+
|
|
92
|
+
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`.
|
|
93
|
+
|
|
94
|
+
### macroforge tsc
|
|
95
|
+
|
|
96
|
+
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.
|
|
97
|
+
|
|
98
|
+
Bash
|
|
99
|
+
|
|
100
|
+
```
|
|
101
|
+
macroforge tsc [options]
|
|
102
|
+
```
|
|
103
|
+
|
|
104
|
+
#### Options
|
|
105
|
+
|
|
106
|
+
| Option | Description |
|
|
107
|
+
| ---------------------- | -------------------------------------------------------------------------- |
|
|
108
|
+
| `-p, --project <path>` | Path to `tsconfig.json` (defaults to `tsconfig.json` in current directory) |
|
|
109
|
+
|
|
110
|
+
#### Examples
|
|
111
|
+
|
|
112
|
+
Type check with default tsconfig.json:
|
|
113
|
+
|
|
114
|
+
Bash
|
|
115
|
+
|
|
116
|
+
```
|
|
117
|
+
macroforge tsc
|
|
118
|
+
```
|
|
119
|
+
|
|
120
|
+
Type check with a specific config:
|
|
121
|
+
|
|
122
|
+
Bash
|
|
123
|
+
|
|
124
|
+
```
|
|
125
|
+
macroforge tsc -p tsconfig.build.json
|
|
126
|
+
```
|
|
127
|
+
|
|
128
|
+
## Output Format
|
|
129
|
+
|
|
130
|
+
### Expanded Code
|
|
131
|
+
|
|
132
|
+
When expanding a file like this:
|
|
133
|
+
|
|
134
|
+
TypeScript
|
|
135
|
+
|
|
136
|
+
```
|
|
137
|
+
/** @derive(Debug) */
|
|
138
|
+
class User {
|
|
139
|
+
name: string;
|
|
140
|
+
age: number;
|
|
141
|
+
|
|
142
|
+
constructor(name: string, age: number) {
|
|
143
|
+
this.name = name;
|
|
144
|
+
this.age = age;
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
```
|
|
148
|
+
|
|
149
|
+
The CLI outputs the expanded code with the generated methods:
|
|
150
|
+
|
|
151
|
+
TypeScript
|
|
152
|
+
|
|
153
|
+
```
|
|
74
154
|
class User {
|
|
75
155
|
name: string;
|
|
76
156
|
age: number;
|
|
@@ -84,38 +164,67 @@ class User {
|
|
|
84
164
|
return `User { name: ${this.name}, age: ${this.age} }`;
|
|
85
165
|
}
|
|
86
166
|
}
|
|
87
|
-
```
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
167
|
+
```
|
|
168
|
+
|
|
169
|
+
### Diagnostics
|
|
170
|
+
|
|
171
|
+
Errors and warnings are printed to stderr in a readable format:
|
|
172
|
+
|
|
173
|
+
Text
|
|
174
|
+
|
|
175
|
+
```
|
|
176
|
+
[macroforge] error at src/user.ts:5:1: Unknown derive macro: InvalidMacro
|
|
177
|
+
[macroforge] warning at src/user.ts:10:3: Field 'unused' is never used
|
|
178
|
+
```
|
|
179
|
+
|
|
180
|
+
## Use Cases
|
|
181
|
+
|
|
182
|
+
### CI/CD Type Checking
|
|
183
|
+
|
|
184
|
+
Use `macroforge tsc` in your CI pipeline to type-check with macro expansion:
|
|
185
|
+
|
|
186
|
+
JSON
|
|
187
|
+
|
|
188
|
+
```
|
|
189
|
+
# package.json
|
|
190
|
+
{
|
|
191
|
+
"scripts": {
|
|
192
|
+
"typecheck": "macroforge tsc"
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
```
|
|
196
|
+
|
|
197
|
+
### Debugging Macro Output
|
|
198
|
+
|
|
199
|
+
Use `macroforge expand` to inspect what code your macros generate:
|
|
200
|
+
|
|
201
|
+
Bash
|
|
202
|
+
|
|
203
|
+
```
|
|
204
|
+
macroforge expand src/models/user.ts | less
|
|
205
|
+
```
|
|
206
|
+
|
|
207
|
+
### Build Pipeline
|
|
208
|
+
|
|
209
|
+
Generate expanded files as part of a custom build:
|
|
210
|
+
|
|
211
|
+
Bash
|
|
212
|
+
|
|
213
|
+
```
|
|
109
214
|
#!/bin/bash
|
|
110
|
-
for
|
|
111
|
-
|
|
112
|
-
|
|
215
|
+
for file in src/**/*.ts; do
|
|
216
|
+
outfile="dist/$(basename "$file" .ts).js"
|
|
217
|
+
macroforge expand "$file" --out "$outfile"
|
|
113
218
|
done
|
|
114
|
-
```
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
|
121
|
-
|
|
|
219
|
+
```
|
|
220
|
+
|
|
221
|
+
## Built-in vs Full Mode
|
|
222
|
+
|
|
223
|
+
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:
|
|
224
|
+
|
|
225
|
+
| Feature | Default (Node.js) | `--builtin-only` (Rust) |
|
|
226
|
+
| --------------- | -------------------------------------- | ----------------------- |
|
|
227
|
+
| Built-in macros | Yes | Yes |
|
|
228
|
+
| External macros | Yes | No |
|
|
229
|
+
| Performance | Standard | Faster |
|
|
230
|
+
| Dependencies | Requires `macroforge` in node\_modules | None |
|