@macroforge/vite-plugin 0.1.48 → 0.1.73
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/package.json +3 -3
- package/src/index.js +40 -7
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"dependencies": {
|
|
3
|
-
"@macroforge/shared": "^0.1.
|
|
4
|
-
"macroforge": "^0.1.
|
|
3
|
+
"@macroforge/shared": "^0.1.73",
|
|
4
|
+
"macroforge": "^0.1.73"
|
|
5
5
|
},
|
|
6
6
|
"devDependencies": {
|
|
7
7
|
"@types/node": "^22.0.0"
|
|
@@ -30,5 +30,5 @@
|
|
|
30
30
|
},
|
|
31
31
|
"type": "module",
|
|
32
32
|
"types": "src/index.d.ts",
|
|
33
|
-
"version": "0.1.
|
|
33
|
+
"version": "0.1.73"
|
|
34
34
|
}
|
package/src/index.js
CHANGED
|
@@ -46,17 +46,38 @@ import {
|
|
|
46
46
|
loadMacroConfig,
|
|
47
47
|
} from "@macroforge/shared";
|
|
48
48
|
|
|
49
|
-
const moduleRequire = createRequire(import.meta.url);
|
|
50
|
-
|
|
51
49
|
/** @type {typeof import('typescript') | undefined} */
|
|
52
50
|
let tsModule;
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
51
|
+
let tsModuleResolved = false;
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
* Lazily resolves TypeScript, trying the project root first (so the consuming
|
|
55
|
+
* project's copy is found) and falling back to the plugin's own location.
|
|
56
|
+
*/
|
|
57
|
+
function ensureTypeScript() {
|
|
58
|
+
if (tsModuleResolved) return tsModule;
|
|
59
|
+
tsModuleResolved = true;
|
|
60
|
+
|
|
61
|
+
// Try resolving from the project root (cwd) first, then from the plugin
|
|
62
|
+
const roots = [
|
|
63
|
+
process.cwd() + "/",
|
|
64
|
+
import.meta.url,
|
|
65
|
+
];
|
|
66
|
+
for (const root of roots) {
|
|
67
|
+
try {
|
|
68
|
+
const req = createRequire(root);
|
|
69
|
+
tsModule = req("typescript");
|
|
70
|
+
return tsModule;
|
|
71
|
+
} catch {
|
|
72
|
+
// continue to next root
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
|
|
56
76
|
tsModule = undefined;
|
|
57
77
|
console.warn(
|
|
58
78
|
"[@macroforge/vite-plugin] TypeScript not found. Generated .d.ts files will be skipped.",
|
|
59
79
|
);
|
|
80
|
+
return tsModule;
|
|
60
81
|
}
|
|
61
82
|
|
|
62
83
|
/** @type {Map<string, import('typescript').CompilerOptions>} */
|
|
@@ -79,7 +100,7 @@ async function ensureRequire() {
|
|
|
79
100
|
const { createRequire } = await import("node:module");
|
|
80
101
|
cachedRequire =
|
|
81
102
|
/** @type {NodeJS.Require} */ (createRequire(process.cwd() + "/"));
|
|
82
|
-
// @ts-ignore - Expose on globalThis so
|
|
103
|
+
// @ts-ignore - Expose on globalThis so Deno's CJS compat layer can use it
|
|
83
104
|
globalThis.require = cachedRequire;
|
|
84
105
|
}
|
|
85
106
|
|
|
@@ -93,6 +114,7 @@ async function ensureRequire() {
|
|
|
93
114
|
* @internal
|
|
94
115
|
*/
|
|
95
116
|
function getCompilerOptions(projectRoot) {
|
|
117
|
+
ensureTypeScript();
|
|
96
118
|
if (!tsModule) {
|
|
97
119
|
return undefined;
|
|
98
120
|
}
|
|
@@ -179,6 +201,7 @@ function getCompilerOptions(projectRoot) {
|
|
|
179
201
|
* @internal
|
|
180
202
|
*/
|
|
181
203
|
function emitDeclarationsFromCode(code, fileName, projectRoot) {
|
|
204
|
+
ensureTypeScript();
|
|
182
205
|
if (!tsModule) {
|
|
183
206
|
return undefined;
|
|
184
207
|
}
|
|
@@ -312,7 +335,8 @@ export async function macroforge() {
|
|
|
312
335
|
|
|
313
336
|
// Load the Rust binary first
|
|
314
337
|
try {
|
|
315
|
-
|
|
338
|
+
const projectRequire = createRequire(process.cwd() + "/");
|
|
339
|
+
rustTransformer = projectRequire("macroforge");
|
|
316
340
|
} catch (error) {
|
|
317
341
|
console.warn(
|
|
318
342
|
"[@macroforge/vite-plugin] Rust binary not found. Please run `npm run build:rust` first.",
|
|
@@ -545,6 +569,15 @@ export async function macroforge() {
|
|
|
545
569
|
"",
|
|
546
570
|
);
|
|
547
571
|
|
|
572
|
+
// For .svelte.ts modules, strip @derive JSDoc comments to prevent
|
|
573
|
+
// the Svelte preprocessor from re-expanding macros
|
|
574
|
+
if (id.endsWith(".svelte.ts") || id.endsWith(".svelte.js")) {
|
|
575
|
+
result.code = result.code.replace(
|
|
576
|
+
/\/\*\*\s*@derive\b[^*]*\*\//g,
|
|
577
|
+
"",
|
|
578
|
+
);
|
|
579
|
+
}
|
|
580
|
+
|
|
548
581
|
// Generate type definitions if enabled
|
|
549
582
|
if (generateTypes) {
|
|
550
583
|
const emitted = emitDeclarationsFromCode(
|