@macroforge/vite-plugin 0.1.37 → 0.1.39
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/dist/index.d.ts.map +1 -1
- package/dist/index.js +89 -0
- package/package.json +2 -2
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;AAEH,OAAO,EAAE,MAAM,EAAE,MAAM,MAAM,CAAC;
|
|
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"}
|
package/dist/index.js
CHANGED
|
@@ -40,6 +40,92 @@ catch (error) {
|
|
|
40
40
|
}
|
|
41
41
|
const compilerOptionsCache = new Map();
|
|
42
42
|
let cachedRequire;
|
|
43
|
+
/**
|
|
44
|
+
* Cache for external macro package manifests.
|
|
45
|
+
* Maps package path to its manifest (or null if failed to load).
|
|
46
|
+
*/
|
|
47
|
+
const externalManifestCache = new Map();
|
|
48
|
+
/**
|
|
49
|
+
* Parses macro import comments from TypeScript code.
|
|
50
|
+
*
|
|
51
|
+
* @remarks
|
|
52
|
+
* Extracts macro names mapped to their source module paths from
|
|
53
|
+
* `/** import macro { ... } from "package" * /` comments.
|
|
54
|
+
*
|
|
55
|
+
* @param text - The TypeScript source code to parse
|
|
56
|
+
* @returns Map of macro names to their module paths
|
|
57
|
+
*
|
|
58
|
+
* @example
|
|
59
|
+
* ```typescript
|
|
60
|
+
* const text = `/** import macro {JSON, FieldController} from "@playground/macro"; * /`;
|
|
61
|
+
* parseMacroImportComments(text);
|
|
62
|
+
* // => Map { "JSON" => "@playground/macro", "FieldController" => "@playground/macro" }
|
|
63
|
+
* ```
|
|
64
|
+
*
|
|
65
|
+
* @internal
|
|
66
|
+
*/
|
|
67
|
+
function parseMacroImportComments(text) {
|
|
68
|
+
const imports = new Map();
|
|
69
|
+
const pattern = /\/\*\*\s*import\s+macro\s*\{([^}]+)\}\s*from\s*["']([^"']+)["']/gi;
|
|
70
|
+
let match;
|
|
71
|
+
while ((match = pattern.exec(text)) !== null) {
|
|
72
|
+
const names = match[1]
|
|
73
|
+
.split(",")
|
|
74
|
+
.map((n) => n.trim())
|
|
75
|
+
.filter(Boolean);
|
|
76
|
+
const modulePath = match[2];
|
|
77
|
+
for (const name of names) {
|
|
78
|
+
imports.set(name, modulePath);
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
return imports;
|
|
82
|
+
}
|
|
83
|
+
/**
|
|
84
|
+
* Attempts to load the manifest from an external macro package.
|
|
85
|
+
*
|
|
86
|
+
* External macro packages (like `@playground/macro`) export their own
|
|
87
|
+
* `__macroforgeGetManifest()` function that provides macro metadata
|
|
88
|
+
* including descriptions.
|
|
89
|
+
*
|
|
90
|
+
* @param modulePath - The package path (e.g., "@playground/macro")
|
|
91
|
+
* @returns The macro manifest, or null if loading failed
|
|
92
|
+
*
|
|
93
|
+
* @internal
|
|
94
|
+
*/
|
|
95
|
+
function getExternalManifest(modulePath) {
|
|
96
|
+
if (externalManifestCache.has(modulePath)) {
|
|
97
|
+
return externalManifestCache.get(modulePath) ?? null;
|
|
98
|
+
}
|
|
99
|
+
try {
|
|
100
|
+
const pkg = moduleRequire(modulePath);
|
|
101
|
+
if (typeof pkg.__macroforgeGetManifest === "function") {
|
|
102
|
+
const manifest = pkg.__macroforgeGetManifest();
|
|
103
|
+
externalManifestCache.set(modulePath, manifest);
|
|
104
|
+
return manifest;
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
catch {
|
|
108
|
+
// Package not found or doesn't export manifest
|
|
109
|
+
}
|
|
110
|
+
externalManifestCache.set(modulePath, null);
|
|
111
|
+
return null;
|
|
112
|
+
}
|
|
113
|
+
/**
|
|
114
|
+
* Collects decorator modules from external macro packages referenced in the code.
|
|
115
|
+
*
|
|
116
|
+
* @param code - The TypeScript source code to scan
|
|
117
|
+
* @returns Array of decorator module names from external packages
|
|
118
|
+
*
|
|
119
|
+
* @internal
|
|
120
|
+
*/
|
|
121
|
+
function collectExternalDecoratorModules(code) {
|
|
122
|
+
const imports = parseMacroImportComments(code);
|
|
123
|
+
const modulePaths = [...new Set(imports.values())];
|
|
124
|
+
return modulePaths.flatMap((modulePath) => {
|
|
125
|
+
const manifest = getExternalManifest(modulePath);
|
|
126
|
+
return manifest?.decorators.map((d) => d.module) ?? [];
|
|
127
|
+
});
|
|
128
|
+
}
|
|
43
129
|
/**
|
|
44
130
|
* Ensures that `require()` is available in the current execution context.
|
|
45
131
|
*
|
|
@@ -544,9 +630,12 @@ function napiMacrosPlugin(options = {}) {
|
|
|
544
630
|
return null;
|
|
545
631
|
}
|
|
546
632
|
try {
|
|
633
|
+
// Collect external decorator modules from macro imports
|
|
634
|
+
const externalDecoratorModules = collectExternalDecoratorModules(code);
|
|
547
635
|
// Perform macro expansion via the Rust binary
|
|
548
636
|
const result = rustTransformer.expandSync(code, id, {
|
|
549
637
|
keepDecorators: macroConfig.keepDecorators,
|
|
638
|
+
externalDecoratorModules,
|
|
550
639
|
});
|
|
551
640
|
// Report diagnostics from macro expansion
|
|
552
641
|
for (const diag of result.diagnostics) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@macroforge/vite-plugin",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.39",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -18,7 +18,7 @@
|
|
|
18
18
|
"test": "npm run build && node --test tests/**/*.test.js"
|
|
19
19
|
},
|
|
20
20
|
"dependencies": {
|
|
21
|
-
"macroforge": "^0.1.
|
|
21
|
+
"macroforge": "^0.1.39"
|
|
22
22
|
},
|
|
23
23
|
"devDependencies": {
|
|
24
24
|
"typescript": "^5.9.3",
|