angular-rust-plugins 0.1.0
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 +118 -0
- package/binding/angular-binding.darwin-arm64.node +0 -0
- package/binding/index.d.ts +13 -0
- package/binding/index.js +316 -0
- package/binding/package.json +1 -0
- package/compiler/index.cjs +135 -0
- package/compiler/index.cjs.map +1 -0
- package/compiler/index.d.cts +12 -0
- package/compiler/index.d.ts +12 -0
- package/compiler/index.js +107 -0
- package/compiler/index.js.map +1 -0
- package/compiler/vite.cjs +135 -0
- package/compiler/vite.cjs.map +1 -0
- package/compiler/vite.d.cts +41 -0
- package/compiler/vite.d.ts +41 -0
- package/compiler/vite.js +109 -0
- package/compiler/vite.js.map +1 -0
- package/index.cjs +479 -0
- package/index.cjs.map +1 -0
- package/index.d.cts +8 -0
- package/index.d.ts +8 -0
- package/index.js +438 -0
- package/index.js.map +1 -0
- package/linker/esbuild.cjs +125 -0
- package/linker/esbuild.cjs.map +1 -0
- package/linker/esbuild.d.cts +39 -0
- package/linker/esbuild.d.ts +39 -0
- package/linker/esbuild.js +99 -0
- package/linker/esbuild.js.map +1 -0
- package/linker/index.cjs +372 -0
- package/linker/index.cjs.map +1 -0
- package/linker/index.d.cts +6 -0
- package/linker/index.d.ts +6 -0
- package/linker/index.js +333 -0
- package/linker/index.js.map +1 -0
- package/linker/rolldown.cjs +135 -0
- package/linker/rolldown.cjs.map +1 -0
- package/linker/rolldown.d.cts +36 -0
- package/linker/rolldown.d.ts +36 -0
- package/linker/rolldown.js +109 -0
- package/linker/rolldown.js.map +1 -0
- package/linker/vite.cjs +184 -0
- package/linker/vite.cjs.map +1 -0
- package/linker/vite.d.cts +58 -0
- package/linker/vite.d.ts +58 -0
- package/linker/vite.js +155 -0
- package/linker/vite.js.map +1 -0
- package/package.json +77 -0
- package/types-BTaYbdhr.d.cts +45 -0
- package/types-BTaYbdhr.d.ts +45 -0
package/linker/index.js
ADDED
|
@@ -0,0 +1,333 @@
|
|
|
1
|
+
// src/linker/esbuild.ts
|
|
2
|
+
import { promises as fs } from "fs";
|
|
3
|
+
import { createRequire } from "module";
|
|
4
|
+
import { dirname, join } from "path";
|
|
5
|
+
import { fileURLToPath } from "url";
|
|
6
|
+
|
|
7
|
+
// src/linker/types.ts
|
|
8
|
+
function needsLinking(code) {
|
|
9
|
+
return code.includes("\u0275\u0275ngDeclare");
|
|
10
|
+
}
|
|
11
|
+
function isAngularPackage(id) {
|
|
12
|
+
return id.includes("@angular") || id.includes("/@angular/");
|
|
13
|
+
}
|
|
14
|
+
function isJsFile(id) {
|
|
15
|
+
const cleanId = id.split("?")[0];
|
|
16
|
+
return cleanId.endsWith(".mjs") || cleanId.endsWith(".js");
|
|
17
|
+
}
|
|
18
|
+
function cleanModuleId(id) {
|
|
19
|
+
return id.split("?")[0];
|
|
20
|
+
}
|
|
21
|
+
var ANGULAR_PACKAGES = [
|
|
22
|
+
"@angular/core",
|
|
23
|
+
"@angular/common",
|
|
24
|
+
"@angular/platform-browser",
|
|
25
|
+
"@angular/platform-browser-dynamic",
|
|
26
|
+
"@angular/router",
|
|
27
|
+
"@angular/forms",
|
|
28
|
+
"@angular/animations",
|
|
29
|
+
"@angular/cdk",
|
|
30
|
+
"@angular/material"
|
|
31
|
+
];
|
|
32
|
+
var NON_ANGULAR_PACKAGES = ["zone.js", "rxjs", "rxjs/operators"];
|
|
33
|
+
|
|
34
|
+
// src/linker/esbuild.ts
|
|
35
|
+
var compilerInstance = null;
|
|
36
|
+
function getCompiler(options) {
|
|
37
|
+
if (compilerInstance) {
|
|
38
|
+
return compilerInstance;
|
|
39
|
+
}
|
|
40
|
+
try {
|
|
41
|
+
let binding;
|
|
42
|
+
if (options?.bindingPath) {
|
|
43
|
+
const require2 = createRequire(import.meta.url);
|
|
44
|
+
binding = require2(options.bindingPath);
|
|
45
|
+
} else {
|
|
46
|
+
const currentFileUrl = import.meta.url;
|
|
47
|
+
const currentFilePath = fileURLToPath(currentFileUrl);
|
|
48
|
+
const currentDir = dirname(currentFilePath);
|
|
49
|
+
const require2 = createRequire(currentFileUrl);
|
|
50
|
+
const possiblePaths = [
|
|
51
|
+
join(currentDir, "..", "binding"),
|
|
52
|
+
// dist/linker/../binding
|
|
53
|
+
join(currentDir, "binding"),
|
|
54
|
+
// same directory
|
|
55
|
+
join(currentDir, "..", "..", "binding")
|
|
56
|
+
// deeper nesting
|
|
57
|
+
];
|
|
58
|
+
let loadedBinding = null;
|
|
59
|
+
let lastError = null;
|
|
60
|
+
for (const bindingPath of possiblePaths) {
|
|
61
|
+
try {
|
|
62
|
+
loadedBinding = require2(bindingPath);
|
|
63
|
+
break;
|
|
64
|
+
} catch (e) {
|
|
65
|
+
lastError = e;
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
if (!loadedBinding) {
|
|
69
|
+
throw lastError || new Error("Could not find binding in any expected location");
|
|
70
|
+
}
|
|
71
|
+
binding = loadedBinding;
|
|
72
|
+
}
|
|
73
|
+
compilerInstance = new binding.Compiler();
|
|
74
|
+
return compilerInstance;
|
|
75
|
+
} catch (e) {
|
|
76
|
+
throw new Error(`Failed to load Angular Rust binding. Error: ${e}`);
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
function angularLinkerEsbuildPlugin(options) {
|
|
80
|
+
return {
|
|
81
|
+
name: "angular-linker-esbuild",
|
|
82
|
+
setup(build) {
|
|
83
|
+
const compiler = getCompiler(options);
|
|
84
|
+
const debug = options?.debug ?? false;
|
|
85
|
+
build.onLoad({ filter: /@angular\/.*\.(mjs|js)$/ }, async (args) => {
|
|
86
|
+
if (debug) {
|
|
87
|
+
console.log(`[Angular Linker] Processing: ${args.path}`);
|
|
88
|
+
}
|
|
89
|
+
const code = await fs.readFile(args.path, "utf8");
|
|
90
|
+
if (!needsLinking(code)) {
|
|
91
|
+
return { contents: code, loader: "js" };
|
|
92
|
+
}
|
|
93
|
+
try {
|
|
94
|
+
const result = compiler.linkFile(args.path, code);
|
|
95
|
+
if (result.startsWith("/* Linker Error")) {
|
|
96
|
+
if (debug) {
|
|
97
|
+
console.error(`[Angular Linker Error] ${args.path}:
|
|
98
|
+
${result}`);
|
|
99
|
+
}
|
|
100
|
+
return { contents: code, loader: "js" };
|
|
101
|
+
}
|
|
102
|
+
if (debug) {
|
|
103
|
+
console.log(`[Angular Linker] Successfully linked: ${args.path}`);
|
|
104
|
+
}
|
|
105
|
+
return { contents: result, loader: "js" };
|
|
106
|
+
} catch (e) {
|
|
107
|
+
if (debug) {
|
|
108
|
+
console.error(`[Angular Linker Failed] ${args.path}:`, e);
|
|
109
|
+
}
|
|
110
|
+
return { contents: code, loader: "js" };
|
|
111
|
+
}
|
|
112
|
+
});
|
|
113
|
+
}
|
|
114
|
+
};
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
// src/linker/rolldown.ts
|
|
118
|
+
import { createRequire as createRequire2 } from "module";
|
|
119
|
+
import { dirname as dirname2, join as join2 } from "path";
|
|
120
|
+
import { fileURLToPath as fileURLToPath2 } from "url";
|
|
121
|
+
var compilerInstance2 = null;
|
|
122
|
+
function getCompiler2(options) {
|
|
123
|
+
if (compilerInstance2) {
|
|
124
|
+
return compilerInstance2;
|
|
125
|
+
}
|
|
126
|
+
try {
|
|
127
|
+
let binding;
|
|
128
|
+
if (options?.bindingPath) {
|
|
129
|
+
const require2 = createRequire2(import.meta.url);
|
|
130
|
+
binding = require2(options.bindingPath);
|
|
131
|
+
} else {
|
|
132
|
+
const currentFileUrl = import.meta.url;
|
|
133
|
+
const currentFilePath = fileURLToPath2(currentFileUrl);
|
|
134
|
+
const currentDir = dirname2(currentFilePath);
|
|
135
|
+
const require2 = createRequire2(currentFileUrl);
|
|
136
|
+
const possiblePaths = [
|
|
137
|
+
join2(currentDir, "..", "binding"),
|
|
138
|
+
// dist/linker/../binding
|
|
139
|
+
join2(currentDir, "binding"),
|
|
140
|
+
// same directory
|
|
141
|
+
join2(currentDir, "..", "..", "binding")
|
|
142
|
+
// deeper nesting
|
|
143
|
+
];
|
|
144
|
+
let loadedBinding = null;
|
|
145
|
+
let lastError = null;
|
|
146
|
+
for (const bindingPath of possiblePaths) {
|
|
147
|
+
try {
|
|
148
|
+
loadedBinding = require2(bindingPath);
|
|
149
|
+
break;
|
|
150
|
+
} catch (e) {
|
|
151
|
+
lastError = e;
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
if (!loadedBinding) {
|
|
155
|
+
throw lastError || new Error("Could not find binding in any expected location");
|
|
156
|
+
}
|
|
157
|
+
binding = loadedBinding;
|
|
158
|
+
}
|
|
159
|
+
compilerInstance2 = new binding.Compiler();
|
|
160
|
+
return compilerInstance2;
|
|
161
|
+
} catch (e) {
|
|
162
|
+
throw new Error(`Failed to load Angular Rust binding. Error: ${e}`);
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
function angularLinkerRolldownPlugin(options) {
|
|
166
|
+
const debug = options?.debug ?? false;
|
|
167
|
+
let compiler;
|
|
168
|
+
return {
|
|
169
|
+
name: "angular-linker-rolldown",
|
|
170
|
+
async transform(code, id) {
|
|
171
|
+
if (!compiler) {
|
|
172
|
+
compiler = getCompiler2(options);
|
|
173
|
+
}
|
|
174
|
+
const isInNodeModules = id.includes("node_modules");
|
|
175
|
+
const cleanId = cleanModuleId(id);
|
|
176
|
+
if (!isAngularPackage(id) || !isInNodeModules || !isJsFile(id)) {
|
|
177
|
+
return null;
|
|
178
|
+
}
|
|
179
|
+
if (!needsLinking(code)) {
|
|
180
|
+
return null;
|
|
181
|
+
}
|
|
182
|
+
if (debug) {
|
|
183
|
+
console.log(`[Angular Linker] Linking: ${cleanId}`);
|
|
184
|
+
}
|
|
185
|
+
try {
|
|
186
|
+
const result = compiler.linkFile(cleanId, code);
|
|
187
|
+
if (result.startsWith("/* Linker Error")) {
|
|
188
|
+
console.error(`[Angular Linker Error] ${id}:
|
|
189
|
+
${result}`);
|
|
190
|
+
return null;
|
|
191
|
+
}
|
|
192
|
+
if (debug) {
|
|
193
|
+
console.log(`[Angular Linker] Successfully linked: ${cleanId}`);
|
|
194
|
+
}
|
|
195
|
+
return { code: result, map: null };
|
|
196
|
+
} catch (e) {
|
|
197
|
+
console.error(`[Angular Linker Failed] ${id}:`, e);
|
|
198
|
+
return null;
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
};
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
// src/linker/vite.ts
|
|
205
|
+
import { createRequire as createRequire3 } from "module";
|
|
206
|
+
import { dirname as dirname3, join as join3 } from "path";
|
|
207
|
+
import { fileURLToPath as fileURLToPath3 } from "url";
|
|
208
|
+
var compilerInstance3 = null;
|
|
209
|
+
function getCompiler3(options) {
|
|
210
|
+
if (compilerInstance3) {
|
|
211
|
+
return compilerInstance3;
|
|
212
|
+
}
|
|
213
|
+
try {
|
|
214
|
+
let binding;
|
|
215
|
+
if (options?.bindingPath) {
|
|
216
|
+
const require2 = createRequire3(import.meta.url);
|
|
217
|
+
binding = require2(options.bindingPath);
|
|
218
|
+
} else {
|
|
219
|
+
const currentFileUrl = import.meta.url;
|
|
220
|
+
const currentFilePath = fileURLToPath3(currentFileUrl);
|
|
221
|
+
const currentDir = dirname3(currentFilePath);
|
|
222
|
+
const require2 = createRequire3(currentFileUrl);
|
|
223
|
+
const possiblePaths = [
|
|
224
|
+
join3(currentDir, "..", "binding"),
|
|
225
|
+
// dist/linker/../binding
|
|
226
|
+
join3(currentDir, "binding"),
|
|
227
|
+
// same directory
|
|
228
|
+
join3(currentDir, "..", "..", "binding")
|
|
229
|
+
// deeper nesting
|
|
230
|
+
];
|
|
231
|
+
let loadedBinding = null;
|
|
232
|
+
let lastError = null;
|
|
233
|
+
for (const bindingPath of possiblePaths) {
|
|
234
|
+
try {
|
|
235
|
+
loadedBinding = require2(bindingPath);
|
|
236
|
+
break;
|
|
237
|
+
} catch (e) {
|
|
238
|
+
lastError = e;
|
|
239
|
+
}
|
|
240
|
+
}
|
|
241
|
+
if (!loadedBinding) {
|
|
242
|
+
throw lastError || new Error("Could not find binding in any expected location");
|
|
243
|
+
}
|
|
244
|
+
binding = loadedBinding;
|
|
245
|
+
}
|
|
246
|
+
compilerInstance3 = new binding.Compiler();
|
|
247
|
+
return compilerInstance3;
|
|
248
|
+
} catch (e) {
|
|
249
|
+
throw new Error(`Failed to load Angular Rust binding. Error: ${e}`);
|
|
250
|
+
}
|
|
251
|
+
}
|
|
252
|
+
function angularLinkerVitePlugin(options) {
|
|
253
|
+
const debug = options?.debug ?? false;
|
|
254
|
+
let compiler;
|
|
255
|
+
return {
|
|
256
|
+
name: "angular-linker-vite",
|
|
257
|
+
enforce: "pre",
|
|
258
|
+
config(config) {
|
|
259
|
+
const excludePackages = [
|
|
260
|
+
...ANGULAR_PACKAGES,
|
|
261
|
+
...options?.excludePackages ?? []
|
|
262
|
+
];
|
|
263
|
+
const includePackages = [
|
|
264
|
+
...NON_ANGULAR_PACKAGES,
|
|
265
|
+
...options?.includePackages ?? []
|
|
266
|
+
];
|
|
267
|
+
return {
|
|
268
|
+
optimizeDeps: {
|
|
269
|
+
exclude: excludePackages,
|
|
270
|
+
include: includePackages
|
|
271
|
+
}
|
|
272
|
+
};
|
|
273
|
+
},
|
|
274
|
+
transform(code, id) {
|
|
275
|
+
if (!compiler) {
|
|
276
|
+
compiler = getCompiler3(options);
|
|
277
|
+
}
|
|
278
|
+
if (!id.includes("node_modules")) {
|
|
279
|
+
return null;
|
|
280
|
+
}
|
|
281
|
+
if (!isAngularPackage(id)) {
|
|
282
|
+
return null;
|
|
283
|
+
}
|
|
284
|
+
if (!isJsFile(id)) {
|
|
285
|
+
return null;
|
|
286
|
+
}
|
|
287
|
+
if (!needsLinking(code)) {
|
|
288
|
+
return null;
|
|
289
|
+
}
|
|
290
|
+
const cleanId = cleanModuleId(id);
|
|
291
|
+
if (debug) {
|
|
292
|
+
console.log(`[Angular Linker] Linking: ${cleanId}`);
|
|
293
|
+
}
|
|
294
|
+
try {
|
|
295
|
+
const result = compiler.linkFile(cleanId, code);
|
|
296
|
+
if (result.startsWith("/* Linker Error")) {
|
|
297
|
+
console.error(`[Angular Linker Error] ${id}:
|
|
298
|
+
${result}`);
|
|
299
|
+
return null;
|
|
300
|
+
}
|
|
301
|
+
if (debug) {
|
|
302
|
+
console.log(`[Angular Linker] Successfully linked: ${cleanId}`);
|
|
303
|
+
}
|
|
304
|
+
return { code: result, map: null };
|
|
305
|
+
} catch (e) {
|
|
306
|
+
console.error(`[Angular Linker Failed] ${id}:`, e);
|
|
307
|
+
return null;
|
|
308
|
+
}
|
|
309
|
+
}
|
|
310
|
+
};
|
|
311
|
+
}
|
|
312
|
+
function getAngularViteConfig() {
|
|
313
|
+
return {
|
|
314
|
+
plugins: [angularLinkerVitePlugin()],
|
|
315
|
+
optimizeDeps: {
|
|
316
|
+
exclude: ANGULAR_PACKAGES,
|
|
317
|
+
include: NON_ANGULAR_PACKAGES
|
|
318
|
+
}
|
|
319
|
+
};
|
|
320
|
+
}
|
|
321
|
+
export {
|
|
322
|
+
ANGULAR_PACKAGES,
|
|
323
|
+
NON_ANGULAR_PACKAGES,
|
|
324
|
+
angularLinkerEsbuildPlugin,
|
|
325
|
+
angularLinkerRolldownPlugin,
|
|
326
|
+
angularLinkerVitePlugin,
|
|
327
|
+
cleanModuleId,
|
|
328
|
+
getAngularViteConfig,
|
|
329
|
+
isAngularPackage,
|
|
330
|
+
isJsFile,
|
|
331
|
+
needsLinking
|
|
332
|
+
};
|
|
333
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/linker/esbuild.ts","../../src/linker/types.ts","../../src/linker/rolldown.ts","../../src/linker/vite.ts"],"sourcesContent":["/**\n * Angular Linker Plugin for esbuild\n *\n * Use this plugin with Vite's optimizeDeps.esbuildOptions or standalone esbuild.\n *\n * @example\n * ```js\n * import { angularLinkerEsbuildPlugin } from 'vite-plugin-angular-rust/esbuild';\n *\n * // With esbuild\n * import esbuild from 'esbuild';\n *\n * esbuild.build({\n * plugins: [angularLinkerEsbuildPlugin()],\n * // ...\n * });\n *\n * // With Vite\n * import { defineConfig } from 'vite';\n *\n * export default defineConfig({\n * optimizeDeps: {\n * esbuildOptions: {\n * plugins: [angularLinkerEsbuildPlugin()],\n * },\n * },\n * });\n * ```\n */\n\nimport type { Plugin } from \"esbuild\";\nimport { promises as fs } from \"fs\";\nimport { createRequire } from \"module\";\nimport { dirname, join } from \"path\";\nimport { fileURLToPath } from \"url\";\nimport type { CompilerBinding, LinkerOptions } from \"./types\";\nimport { needsLinking } from \"./types\";\n\nlet compilerInstance: CompilerBinding | null = null;\n\nfunction getCompiler(options?: LinkerOptions): CompilerBinding {\n if (compilerInstance) {\n return compilerInstance;\n }\n\n try {\n let binding: { Compiler: new () => CompilerBinding };\n\n if (options?.bindingPath) {\n const require = createRequire(import.meta.url);\n binding = require(options.bindingPath);\n } else {\n // Load from bundled binding directory\n const currentFileUrl = import.meta.url;\n const currentFilePath = fileURLToPath(currentFileUrl);\n const currentDir = dirname(currentFilePath);\n const require = createRequire(currentFileUrl);\n\n // Try multiple possible binding locations\n const possiblePaths = [\n join(currentDir, \"..\", \"binding\"), // dist/linker/../binding\n join(currentDir, \"binding\"), // same directory\n join(currentDir, \"..\", \"..\", \"binding\"), // deeper nesting\n ];\n\n let loadedBinding: { Compiler: new () => CompilerBinding } | null = null;\n let lastError: unknown = null;\n\n for (const bindingPath of possiblePaths) {\n try {\n loadedBinding = require(bindingPath);\n break;\n } catch (e) {\n lastError = e;\n }\n }\n\n if (!loadedBinding) {\n throw (\n lastError ||\n new Error(\"Could not find binding in any expected location\")\n );\n }\n\n binding = loadedBinding;\n }\n\n compilerInstance = new binding.Compiler();\n return compilerInstance;\n } catch (e) {\n throw new Error(`Failed to load Angular Rust binding. Error: ${e}`);\n }\n}\n\n/**\n * Creates an esbuild plugin for Angular linker\n */\nexport function angularLinkerEsbuildPlugin(options?: LinkerOptions): Plugin {\n return {\n name: \"angular-linker-esbuild\",\n setup(build) {\n const compiler = getCompiler(options);\n const debug = options?.debug ?? false;\n\n // Handle all .mjs and .js files in @angular packages\n build.onLoad({ filter: /@angular\\/.*\\.(mjs|js)$/ }, async (args) => {\n if (debug) {\n console.log(`[Angular Linker] Processing: ${args.path}`);\n }\n\n const code = await fs.readFile(args.path, \"utf8\");\n\n // Check if file contains partial declarations\n if (!needsLinking(code)) {\n return { contents: code, loader: \"js\" };\n }\n\n try {\n const result = compiler.linkFile(args.path, code);\n\n if (result.startsWith(\"/* Linker Error\")) {\n if (debug) {\n console.error(`[Angular Linker Error] ${args.path}:\\n${result}`);\n }\n return { contents: code, loader: \"js\" };\n }\n\n if (debug) {\n console.log(`[Angular Linker] Successfully linked: ${args.path}`);\n }\n\n return { contents: result, loader: \"js\" };\n } catch (e) {\n if (debug) {\n console.error(`[Angular Linker Failed] ${args.path}:`, e);\n }\n return { contents: code, loader: \"js\" };\n }\n });\n },\n };\n}\n\nexport default angularLinkerEsbuildPlugin;\n","/**\n * Angular Linker Plugin Types\n */\n\nexport interface LinkerOptions {\n /**\n * Enable debug logging\n * @default false\n */\n debug?: boolean;\n\n /**\n * Custom path to the Angular Rust binding package\n * If not specified, will try to resolve @anthropic/angular-rust-binding\n */\n bindingPath?: string;\n}\n\nexport interface LinkerResult {\n code: string;\n map: null | undefined;\n}\n\nexport interface CompilerBinding {\n linkFile(filePath: string, code: string): string;\n compile?(filePath: string, code: string): string;\n}\n\n/**\n * Check if file contains Angular partial declarations that need linking\n */\nexport function needsLinking(code: string): boolean {\n return code.includes(\"ɵɵngDeclare\");\n}\n\n/**\n * Check if file is an Angular package file\n */\nexport function isAngularPackage(id: string): boolean {\n return id.includes(\"@angular\") || id.includes(\"/@angular/\");\n}\n\n/**\n * Check if file is a JavaScript/MJS file\n */\nexport function isJsFile(id: string): boolean {\n const cleanId = id.split(\"?\")[0];\n return cleanId.endsWith(\".mjs\") || cleanId.endsWith(\".js\");\n}\n\n/**\n * Clean module ID by removing query strings\n */\nexport function cleanModuleId(id: string): string {\n return id.split(\"?\")[0];\n}\n\n/**\n * Default Angular packages to exclude from pre-bundling\n */\nexport const ANGULAR_PACKAGES = [\n \"@angular/core\",\n \"@angular/common\",\n \"@angular/platform-browser\",\n \"@angular/platform-browser-dynamic\",\n \"@angular/router\",\n \"@angular/forms\",\n \"@angular/animations\",\n \"@angular/cdk\",\n \"@angular/material\",\n];\n\n/**\n * Packages that don't need linking and should be included in pre-bundling\n */\nexport const NON_ANGULAR_PACKAGES = [\"zone.js\", \"rxjs\", \"rxjs/operators\"];\n","/**\n * Angular Linker Plugin for Rolldown\n *\n * Use this plugin with rolldown-vite or standalone Rolldown.\n *\n * @example\n * ```js\n * import { angularLinkerRolldownPlugin } from 'vite-plugin-angular-rust/rolldown';\n * import { defineConfig } from 'vite';\n *\n * export default defineConfig({\n * plugins: [angularLinkerRolldownPlugin()],\n * optimizeDeps: {\n * exclude: [\n * '@angular/core',\n * '@angular/common',\n * '@angular/platform-browser',\n * '@angular/router',\n * ],\n * },\n * });\n * ```\n */\n\nimport { createRequire } from \"module\";\nimport { dirname, join } from \"path\";\nimport { fileURLToPath } from \"url\";\nimport type { CompilerBinding, LinkerOptions, LinkerResult } from \"./types\";\nimport {\n needsLinking,\n isAngularPackage,\n isJsFile,\n cleanModuleId,\n} from \"./types\";\n\nlet compilerInstance: CompilerBinding | null = null;\n\nfunction getCompiler(options?: LinkerOptions): CompilerBinding {\n if (compilerInstance) {\n return compilerInstance;\n }\n\n try {\n let binding: { Compiler: new () => CompilerBinding };\n\n if (options?.bindingPath) {\n const require = createRequire(import.meta.url);\n binding = require(options.bindingPath);\n } else {\n // Load from bundled binding directory\n const currentFileUrl = import.meta.url;\n const currentFilePath = fileURLToPath(currentFileUrl);\n const currentDir = dirname(currentFilePath);\n const require = createRequire(currentFileUrl);\n\n // Try multiple possible binding locations\n const possiblePaths = [\n join(currentDir, \"..\", \"binding\"), // dist/linker/../binding\n join(currentDir, \"binding\"), // same directory\n join(currentDir, \"..\", \"..\", \"binding\"), // deeper nesting\n ];\n\n let loadedBinding: { Compiler: new () => CompilerBinding } | null = null;\n let lastError: unknown = null;\n\n for (const bindingPath of possiblePaths) {\n try {\n loadedBinding = require(bindingPath);\n break;\n } catch (e) {\n lastError = e;\n }\n }\n\n if (!loadedBinding) {\n throw (\n lastError ||\n new Error(\"Could not find binding in any expected location\")\n );\n }\n\n binding = loadedBinding;\n }\n\n compilerInstance = new binding.Compiler();\n return compilerInstance;\n } catch (e) {\n throw new Error(`Failed to load Angular Rust binding. Error: ${e}`);\n }\n}\n\nexport interface RolldownPlugin {\n name: string;\n transform(\n code: string,\n id: string\n ): Promise<LinkerResult | null> | LinkerResult | null;\n}\n\n/**\n * Creates a Rolldown-compatible plugin for Angular linker\n */\nexport function angularLinkerRolldownPlugin(\n options?: LinkerOptions\n): RolldownPlugin {\n const debug = options?.debug ?? false;\n let compiler: CompilerBinding;\n\n return {\n name: \"angular-linker-rolldown\",\n async transform(code: string, id: string): Promise<LinkerResult | null> {\n // Lazy initialize compiler\n if (!compiler) {\n compiler = getCompiler(options);\n }\n\n // Only process @angular packages with .mjs or .js extensions\n const isInNodeModules = id.includes(\"node_modules\");\n const cleanId = cleanModuleId(id);\n\n if (!isAngularPackage(id) || !isInNodeModules || !isJsFile(id)) {\n return null;\n }\n\n // Check if file contains partial declarations\n if (!needsLinking(code)) {\n return null;\n }\n\n if (debug) {\n console.log(`[Angular Linker] Linking: ${cleanId}`);\n }\n\n try {\n const result = compiler.linkFile(cleanId, code);\n\n if (result.startsWith(\"/* Linker Error\")) {\n console.error(`[Angular Linker Error] ${id}:\\n${result}`);\n return null;\n }\n\n if (debug) {\n console.log(`[Angular Linker] Successfully linked: ${cleanId}`);\n }\n\n return { code: result, map: null };\n } catch (e) {\n console.error(`[Angular Linker Failed] ${id}:`, e);\n return null;\n }\n },\n };\n}\n\nexport default angularLinkerRolldownPlugin;\n","/**\n * Angular Linker Plugin for Vite\n *\n * This plugin handles Angular linking for both Vite's dev server (with rolldown/esbuild)\n * and production builds.\n *\n * @example\n * ```js\n * import { angularLinkerVitePlugin } from 'vite-plugin-angular-rust/vite';\n * import { defineConfig } from 'vite';\n *\n * export default defineConfig({\n * plugins: [angularLinkerVitePlugin()],\n * optimizeDeps: {\n * exclude: [\n * '@angular/core',\n * '@angular/common',\n * '@angular/platform-browser',\n * '@angular/router',\n * '@angular/forms',\n * ],\n * include: ['zone.js', 'rxjs', 'rxjs/operators'],\n * },\n * });\n * ```\n */\n\nimport type { Plugin } from \"vite\";\nimport { createRequire } from \"module\";\nimport { dirname, join } from \"path\";\nimport { fileURLToPath } from \"url\";\nimport type { CompilerBinding, LinkerOptions } from \"./types\";\nimport {\n needsLinking,\n isAngularPackage,\n isJsFile,\n cleanModuleId,\n ANGULAR_PACKAGES,\n NON_ANGULAR_PACKAGES,\n} from \"./types\";\n\nlet compilerInstance: CompilerBinding | null = null;\n\nfunction getCompiler(options?: LinkerOptions): CompilerBinding {\n if (compilerInstance) {\n return compilerInstance;\n }\n\n try {\n let binding: { Compiler: new () => CompilerBinding };\n\n if (options?.bindingPath) {\n const require = createRequire(import.meta.url);\n binding = require(options.bindingPath);\n } else {\n // Load from bundled binding directory\n const currentFileUrl = import.meta.url;\n const currentFilePath = fileURLToPath(currentFileUrl);\n const currentDir = dirname(currentFilePath);\n const require = createRequire(currentFileUrl);\n\n // Try multiple possible binding locations\n const possiblePaths = [\n join(currentDir, \"..\", \"binding\"), // dist/linker/../binding\n join(currentDir, \"binding\"), // same directory\n join(currentDir, \"..\", \"..\", \"binding\"), // deeper nesting\n ];\n\n let loadedBinding: { Compiler: new () => CompilerBinding } | null = null;\n let lastError: unknown = null;\n\n for (const bindingPath of possiblePaths) {\n try {\n loadedBinding = require(bindingPath);\n break;\n } catch (e) {\n lastError = e;\n }\n }\n\n if (!loadedBinding) {\n throw (\n lastError ||\n new Error(\"Could not find binding in any expected location\")\n );\n }\n\n binding = loadedBinding;\n }\n\n compilerInstance = new binding.Compiler();\n return compilerInstance;\n } catch (e) {\n throw new Error(`Failed to load Angular Rust binding. Error: ${e}`);\n }\n}\n\nexport interface ViteLinkerPluginOptions extends LinkerOptions {\n /**\n * Additional packages to exclude from pre-bundling\n */\n excludePackages?: string[];\n\n /**\n * Additional packages to include in pre-bundling (non-Angular packages)\n */\n includePackages?: string[];\n}\n\n/**\n * Creates a Vite plugin for Angular linker\n * Works with both rolldown-vite and standard Vite (esbuild)\n */\nexport function angularLinkerVitePlugin(\n options?: ViteLinkerPluginOptions\n): Plugin {\n const debug = options?.debug ?? false;\n let compiler: CompilerBinding;\n\n return {\n name: \"angular-linker-vite\",\n enforce: \"pre\",\n\n config(config) {\n // Merge optimizeDeps configuration\n const excludePackages = [\n ...ANGULAR_PACKAGES,\n ...(options?.excludePackages ?? []),\n ];\n const includePackages = [\n ...NON_ANGULAR_PACKAGES,\n ...(options?.includePackages ?? []),\n ];\n\n return {\n optimizeDeps: {\n exclude: excludePackages,\n include: includePackages,\n },\n };\n },\n\n transform(code: string, id: string) {\n // Lazy initialize compiler\n if (!compiler) {\n compiler = getCompiler(options);\n }\n\n // Only process node_modules\n if (!id.includes(\"node_modules\")) {\n return null;\n }\n\n // Only process Angular packages\n if (!isAngularPackage(id)) {\n return null;\n }\n\n // Only process JS files\n if (!isJsFile(id)) {\n return null;\n }\n\n // Check if file contains partial declarations\n if (!needsLinking(code)) {\n return null;\n }\n\n const cleanId = cleanModuleId(id);\n\n if (debug) {\n console.log(`[Angular Linker] Linking: ${cleanId}`);\n }\n\n try {\n const result = compiler.linkFile(cleanId, code);\n\n if (result.startsWith(\"/* Linker Error\")) {\n console.error(`[Angular Linker Error] ${id}:\\n${result}`);\n return null;\n }\n\n if (debug) {\n console.log(`[Angular Linker] Successfully linked: ${cleanId}`);\n }\n\n return { code: result, map: null };\n } catch (e) {\n console.error(`[Angular Linker Failed] ${id}:`, e);\n return null;\n }\n },\n };\n}\n\n/**\n * Get recommended Vite config for Angular with Rust linker\n */\nexport function getAngularViteConfig() {\n return {\n plugins: [angularLinkerVit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AY,OAAO;AAAA,MAChC;AAGA,UAAI,CAAC,GAAG,SAAS,cAAc,GAAG;AAChC,eAAO;AAAA,MACT;AAGA,UAAI,CAAC,iBAAiB,EAAE,GAAG;AACzB,eAAO;AAAA,MACT;AAGA,UAAI,CAAC,SAAS,EAAE,GAAG;AACjB,eAAO;AAAA,MACT;AAGA,UAAI,CAAC,aAAa,IAAI,GAAG;AACvB,eAAO;AAAA,MACT;AAEA,YAAM,UAAU,cAAc,EAAE;AAEhC,UAAI,OAAO;AACT,gBAAQ,IAAI,6BAA6B,OAAO,EAAE;AAAA,MACpD;AAEA,UAAI;AACF,cAAM,SAAS,SAAS,SAAS,SAAS,IAAI;AAE9C,YAAI,OAAO,WAAW,iBAAiB,GAAG;AACxC,kBAAQ,MAAM,0BAA0B,EAAE;AAAA,EAAM,MAAM,EAAE;AACxD,iBAAO;AAAA,QACT;AAEA,YAAI,OAAO;AACT,kBAAQ,IAAI,yCAAyC,OAAO,EAAE;AAAA,QAChE;AAEA,eAAO,EAAE,MAAM,QAAQ,KAAK,KAAK;AAAA,MACnC,SAAS,GAAG;AACV,gBAAQ,MAAM,2BAA2B,EAAE,KAAK,CAAC;AACjD,eAAO;AAAA,MACT;AAAA,IACF;AAAA,EACF;AACF;AAKO,SAAS,uBAAuB;AACrC,SAAO;AAAA,IACL,SAAS,CAAC,wBAAwB,CAAC;AAAA,IACnC,cAAc;AAAA,MACZ,SAAS;AAAA,MACT,SAAS;AAAA,IACX;AAAA,EACF;AACF;","names":["require","createRequire","dirname","join","fileURLToPath","compilerInstance","getCompiler","require","createRequire","fileURLToPath","dirname","join","createRequire","dirname","join","fileURLToPath","compilerInstance","getCompiler","require","createRequire","fileURLToPath","dirname","join"]}
|
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// src/linker/rolldown.ts
|
|
21
|
+
var rolldown_exports = {};
|
|
22
|
+
__export(rolldown_exports, {
|
|
23
|
+
angularLinkerRolldownPlugin: () => angularLinkerRolldownPlugin,
|
|
24
|
+
default: () => rolldown_default
|
|
25
|
+
});
|
|
26
|
+
module.exports = __toCommonJS(rolldown_exports);
|
|
27
|
+
var import_module = require("module");
|
|
28
|
+
var import_path = require("path");
|
|
29
|
+
var import_url = require("url");
|
|
30
|
+
|
|
31
|
+
// src/linker/types.ts
|
|
32
|
+
function needsLinking(code) {
|
|
33
|
+
return code.includes("\u0275\u0275ngDeclare");
|
|
34
|
+
}
|
|
35
|
+
function isAngularPackage(id) {
|
|
36
|
+
return id.includes("@angular") || id.includes("/@angular/");
|
|
37
|
+
}
|
|
38
|
+
function isJsFile(id) {
|
|
39
|
+
const cleanId = id.split("?")[0];
|
|
40
|
+
return cleanId.endsWith(".mjs") || cleanId.endsWith(".js");
|
|
41
|
+
}
|
|
42
|
+
function cleanModuleId(id) {
|
|
43
|
+
return id.split("?")[0];
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
// src/linker/rolldown.ts
|
|
47
|
+
var import_meta = {};
|
|
48
|
+
var compilerInstance = null;
|
|
49
|
+
function getCompiler(options) {
|
|
50
|
+
if (compilerInstance) {
|
|
51
|
+
return compilerInstance;
|
|
52
|
+
}
|
|
53
|
+
try {
|
|
54
|
+
let binding;
|
|
55
|
+
if (options?.bindingPath) {
|
|
56
|
+
const require2 = (0, import_module.createRequire)(import_meta.url);
|
|
57
|
+
binding = require2(options.bindingPath);
|
|
58
|
+
} else {
|
|
59
|
+
const currentFileUrl = import_meta.url;
|
|
60
|
+
const currentFilePath = (0, import_url.fileURLToPath)(currentFileUrl);
|
|
61
|
+
const currentDir = (0, import_path.dirname)(currentFilePath);
|
|
62
|
+
const require2 = (0, import_module.createRequire)(currentFileUrl);
|
|
63
|
+
const possiblePaths = [
|
|
64
|
+
(0, import_path.join)(currentDir, "..", "binding"),
|
|
65
|
+
// dist/linker/../binding
|
|
66
|
+
(0, import_path.join)(currentDir, "binding"),
|
|
67
|
+
// same directory
|
|
68
|
+
(0, import_path.join)(currentDir, "..", "..", "binding")
|
|
69
|
+
// deeper nesting
|
|
70
|
+
];
|
|
71
|
+
let loadedBinding = null;
|
|
72
|
+
let lastError = null;
|
|
73
|
+
for (const bindingPath of possiblePaths) {
|
|
74
|
+
try {
|
|
75
|
+
loadedBinding = require2(bindingPath);
|
|
76
|
+
break;
|
|
77
|
+
} catch (e) {
|
|
78
|
+
lastError = e;
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
if (!loadedBinding) {
|
|
82
|
+
throw lastError || new Error("Could not find binding in any expected location");
|
|
83
|
+
}
|
|
84
|
+
binding = loadedBinding;
|
|
85
|
+
}
|
|
86
|
+
compilerInstance = new binding.Compiler();
|
|
87
|
+
return compilerInstance;
|
|
88
|
+
} catch (e) {
|
|
89
|
+
throw new Error(`Failed to load Angular Rust binding. Error: ${e}`);
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
function angularLinkerRolldownPlugin(options) {
|
|
93
|
+
const debug = options?.debug ?? false;
|
|
94
|
+
let compiler;
|
|
95
|
+
return {
|
|
96
|
+
name: "angular-linker-rolldown",
|
|
97
|
+
async transform(code, id) {
|
|
98
|
+
if (!compiler) {
|
|
99
|
+
compiler = getCompiler(options);
|
|
100
|
+
}
|
|
101
|
+
const isInNodeModules = id.includes("node_modules");
|
|
102
|
+
const cleanId = cleanModuleId(id);
|
|
103
|
+
if (!isAngularPackage(id) || !isInNodeModules || !isJsFile(id)) {
|
|
104
|
+
return null;
|
|
105
|
+
}
|
|
106
|
+
if (!needsLinking(code)) {
|
|
107
|
+
return null;
|
|
108
|
+
}
|
|
109
|
+
if (debug) {
|
|
110
|
+
console.log(`[Angular Linker] Linking: ${cleanId}`);
|
|
111
|
+
}
|
|
112
|
+
try {
|
|
113
|
+
const result = compiler.linkFile(cleanId, code);
|
|
114
|
+
if (result.startsWith("/* Linker Error")) {
|
|
115
|
+
console.error(`[Angular Linker Error] ${id}:
|
|
116
|
+
${result}`);
|
|
117
|
+
return null;
|
|
118
|
+
}
|
|
119
|
+
if (debug) {
|
|
120
|
+
console.log(`[Angular Linker] Successfully linked: ${cleanId}`);
|
|
121
|
+
}
|
|
122
|
+
return { code: result, map: null };
|
|
123
|
+
} catch (e) {
|
|
124
|
+
console.error(`[Angular Linker Failed] ${id}:`, e);
|
|
125
|
+
return null;
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
};
|
|
129
|
+
}
|
|
130
|
+
var rolldown_default = angularLinkerRolldownPlugin;
|
|
131
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
132
|
+
0 && (module.exports = {
|
|
133
|
+
angularLinkerRolldownPlugin
|
|
134
|
+
});
|
|
135
|
+
//# sourceMappingURL=rolldown.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/linker/rolldown.ts","../../src/linker/types.ts"],"sourcesContent":["/**\n * Angular Linker Plugin for Rolldown\n *\n * Use this plugin with rolldown-vite or standalone Rolldown.\n *\n * @example\n * ```js\n * import { angularLinkerRolldownPlugin } from 'vite-plugin-angular-rust/rolldown';\n * import { defineConfig } from 'vite';\n *\n * export default defineConfig({\n * plugins: [angularLinkerRolldownPlugin()],\n * optimizeDeps: {\n * exclude: [\n * '@angular/core',\n * '@angular/common',\n * '@angular/platform-browser',\n * '@angular/router',\n * ],\n * },\n * });\n * ```\n */\n\nimport { createRequire } from \"module\";\nimport { dirname, join } from \"path\";\nimport { fileURLToPath } from \"url\";\nimport type { CompilerBinding, LinkerOptions, LinkerResult } from \"./types\";\nimport {\n needsLinking,\n isAngularPackage,\n isJsFile,\n cleanModuleId,\n} from \"./types\";\n\nlet compilerInstance: CompilerBinding | null = null;\n\nfunction getCompiler(options?: LinkerOptions): CompilerBinding {\n if (compilerInstance) {\n return compilerInstance;\n }\n\n try {\n let binding: { Compiler: new () => CompilerBinding };\n\n if (options?.bindingPath) {\n const require = createRequire(import.meta.url);\n binding = require(options.bindingPath);\n } else {\n // Load from bundled binding directory\n const currentFileUrl = import.meta.url;\n const currentFilePath = fileURLToPath(currentFileUrl);\n const currentDir = dirname(currentFilePath);\n const require = createRequire(currentFileUrl);\n\n // Try multiple possible binding locations\n const possiblePaths = [\n join(currentDir, \"..\", \"binding\"), // dist/linker/../binding\n join(currentDir, \"binding\"), // same directory\n join(currentDir, \"..\", \"..\", \"binding\"), // deeper nesting\n ];\n\n let loadedBinding: { Compiler: new () => CompilerBinding } | null = null;\n let lastError: unknown = null;\n\n for (const bindingPath of possiblePaths) {\n try {\n loadedBinding = require(bindingPath);\n break;\n } catch (e) {\n lastError = e;\n }\n }\n\n if (!loadedBinding) {\n throw (\n lastError ||\n new Error(\"Could not find binding in any expected location\")\n );\n }\n\n binding = loadedBinding;\n }\n\n compilerInstance = new binding.Compiler();\n return compilerInstance;\n } catch (e) {\n throw new Error(`Failed to load Angular Rust binding. Error: ${e}`);\n }\n}\n\nexport interface RolldownPlugin {\n name: string;\n transform(\n code: string,\n id: string\n ): Promise<LinkerResult | null> | LinkerResult | null;\n}\n\n/**\n * Creates a Rolldown-compatible plugin for Angular linker\n */\nexport function angularLinkerRolldownPlugin(\n options?: LinkerOptions\n): RolldownPlugin {\n const debug = options?.debug ?? false;\n let compiler: CompilerBinding;\n\n return {\n name: \"angular-linker-rolldown\",\n async transform(code: string, id: string): Promise<LinkerResult | null> {\n // Lazy initialize compiler\n if (!compiler) {\n compiler = getCompiler(options);\n }\n\n // Only process @angular packages with .mjs or .js extensions\n const isInNodeModules = id.includes(\"node_modules\");\n const cleanId = cleanModuleId(id);\n\n if (!isAngularPackage(id) || !isInNodeModules || !isJsFile(id)) {\n return null;\n }\n\n // Check if file contains partial declarations\n if (!needsLinking(code)) {\n return null;\n }\n\n if (debug) {\n console.log(`[Angular Linker] Linking: ${cleanId}`);\n }\n\n try {\n const result = compiler.linkFile(cleanId, code);\n\n if (result.startsWith(\"/* Linker Error\")) {\n console.error(`[Angular Linker Error] ${id}:\\n${result}`);\n return null;\n }\n\n if (debug) {\n console.log(`[Angular Linker] Successfully linked: ${cleanId}`);\n }\n\n return { code: result, map: null };\n } catch (e) {\n console.error(`[Angular Linker Failed] ${id}:`, e);\n return null;\n }\n },\n };\n}\n\nexport default angularLinkerRolldownPlugin;\n","/**\n * Angular Linker Plugin Types\n */\n\nexport interface LinkerOptions {\n /**\n * Enable debug logging\n * @default false\n */\n debug?: boolean;\n\n /**\n * Custom path to the Angular Rust binding package\n * If not specified, will try to resolve @anthropic/angular-rust-binding\n */\n bindingPath?: string;\n}\n\nexport interface LinkerResult {\n code: string;\n map: null | undefined;\n}\n\nexport interface CompilerBinding {\n linkFile(filePath: string, code: string): string;\n compile?(filePath: string, code: string): string;\n}\n\n/**\n * Check if file contains Angular partial declarations that need linking\n */\nexport function needsLinking(code: string): boolean {\n return code.includes(\"ɵɵngDeclare\");\n}\n\n/**\n * Check if file is an Angular package file\n */\nexport function isAngularPackage(id: string): boolean {\n return id.includes(\"@angular\") || id.includes(\"/@angular/\");\n}\n\n/**\n * Check if file is a JavaScript/MJS file\n */\nexport function isJsFile(id: string): boolean {\n const cleanId = id.split(\"?\")[0];\n return cleanId.endsWith(\".mjs\") || cleanId.endsWith(\".js\");\n}\n\n/**\n * Clean module ID by removing query strings\n */\nexport function cleanModuleId(id: string): string {\n return id.split(\"?\")[0];\n}\n\n/**\n * Default Angular packages to exclude from pre-bundling\n */\nexport const ANGULAR_PACKAGES = [\n \"@angular/core\",\n \"@angular/common\",\n \"@angular/platform-browser\",\n \"@angular/platform-browser-dynamic\",\n \"@angular/router\",\n \"@angular/forms\",\n \"@angular/animations\",\n \"@angular/cdk\",\n \"@angular/material\",\n];\n\n/**\n * Packages that don't need linking and should be included in pre-bundling\n */\nexport const NON_ANGULAR_PACKAGES = [\"zone.js\", \"rxjs\", \"rxjs/operators\"];\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAwBA,oBAA8B;AAC9B,kBAA8B;AAC9B,iBAA8B;;;ACKvB,SAAS,aAAa,MAAuB;AAClD,SAAO,KAAK,SAAS,uBAAa;AACpC;AAKO,SAAS,iBAAiB,IAAqB;AACpD,SAAO,GAAG,SAAS,UAAU,KAAK,GAAG,SAAS,YAAY;AAC5D;AAKO,SAAS,SAAS,IAAqB;AAC5C,QAAM,UAAU,GAAG,MAAM,GAAG,EAAE,CAAC;AAC/B,SAAO,QAAQ,SAAS,MAAM,KAAK,QAAQ,SAAS,KAAK;AAC3D;AAKO,SAAS,cAAc,IAAoB;AAChD,SAAO,GAAG,MAAM,GAAG,EAAE,CAAC;AACxB;;;ADvDA;AAmCA,IAAI,mBAA2C;AAE/C,SAAS,YAAY,SAA0C;AAC7D,MAAI,kBAAkB;AACpB,WAAO;AAAA,EACT;AAEA,MAAI;AACF,QAAI;AAEJ,QAAI,SAAS,aAAa;AACxB,YAAMA,eAAU,6BAAc,YAAY,GAAG;AAC7C,gBAAUA,SAAQ,QAAQ,WAAW;AAAA,IACvC,OAAO;AAEL,YAAM,iBAAiB,YAAY;AACnC,YAAM,s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AG;AACxC,kBAAQ,MAAM,0BAA0B,EAAE;AAAA,EAAM,MAAM,EAAE;AACxD,iBAAO;AAAA,QACT;AAEA,YAAI,OAAO;AACT,kBAAQ,IAAI,yCAAyC,OAAO,EAAE;AAAA,QAChE;AAEA,eAAO,EAAE,MAAM,QAAQ,KAAK,KAAK;AAAA,MACnC,SAAS,GAAG;AACV,gBAAQ,MAAM,2BAA2B,EAAE,KAAK,CAAC;AACjD,eAAO;AAAA,MACT;AAAA,IACF;AAAA,EACF;AACF;AAEA,IAAO,mBAAQ;","names":["require"]}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { L as LinkerOptions, b as LinkerResult } from '../types-BTaYbdhr.cjs';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Angular Linker Plugin for Rolldown
|
|
5
|
+
*
|
|
6
|
+
* Use this plugin with rolldown-vite or standalone Rolldown.
|
|
7
|
+
*
|
|
8
|
+
* @example
|
|
9
|
+
* ```js
|
|
10
|
+
* import { angularLinkerRolldownPlugin } from 'vite-plugin-angular-rust/rolldown';
|
|
11
|
+
* import { defineConfig } from 'vite';
|
|
12
|
+
*
|
|
13
|
+
* export default defineConfig({
|
|
14
|
+
* plugins: [angularLinkerRolldownPlugin()],
|
|
15
|
+
* optimizeDeps: {
|
|
16
|
+
* exclude: [
|
|
17
|
+
* '@angular/core',
|
|
18
|
+
* '@angular/common',
|
|
19
|
+
* '@angular/platform-browser',
|
|
20
|
+
* '@angular/router',
|
|
21
|
+
* ],
|
|
22
|
+
* },
|
|
23
|
+
* });
|
|
24
|
+
* ```
|
|
25
|
+
*/
|
|
26
|
+
|
|
27
|
+
interface RolldownPlugin {
|
|
28
|
+
name: string;
|
|
29
|
+
transform(code: string, id: string): Promise<LinkerResult | null> | LinkerResult | null;
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Creates a Rolldown-compatible plugin for Angular linker
|
|
33
|
+
*/
|
|
34
|
+
declare function angularLinkerRolldownPlugin(options?: LinkerOptions): RolldownPlugin;
|
|
35
|
+
|
|
36
|
+
export { type RolldownPlugin, angularLinkerRolldownPlugin, angularLinkerRolldownPlugin as default };
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { L as LinkerOptions, b as LinkerResult } from '../types-BTaYbdhr.js';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Angular Linker Plugin for Rolldown
|
|
5
|
+
*
|
|
6
|
+
* Use this plugin with rolldown-vite or standalone Rolldown.
|
|
7
|
+
*
|
|
8
|
+
* @example
|
|
9
|
+
* ```js
|
|
10
|
+
* import { angularLinkerRolldownPlugin } from 'vite-plugin-angular-rust/rolldown';
|
|
11
|
+
* import { defineConfig } from 'vite';
|
|
12
|
+
*
|
|
13
|
+
* export default defineConfig({
|
|
14
|
+
* plugins: [angularLinkerRolldownPlugin()],
|
|
15
|
+
* optimizeDeps: {
|
|
16
|
+
* exclude: [
|
|
17
|
+
* '@angular/core',
|
|
18
|
+
* '@angular/common',
|
|
19
|
+
* '@angular/platform-browser',
|
|
20
|
+
* '@angular/router',
|
|
21
|
+
* ],
|
|
22
|
+
* },
|
|
23
|
+
* });
|
|
24
|
+
* ```
|
|
25
|
+
*/
|
|
26
|
+
|
|
27
|
+
interface RolldownPlugin {
|
|
28
|
+
name: string;
|
|
29
|
+
transform(code: string, id: string): Promise<LinkerResult | null> | LinkerResult | null;
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Creates a Rolldown-compatible plugin for Angular linker
|
|
33
|
+
*/
|
|
34
|
+
declare function angularLinkerRolldownPlugin(options?: LinkerOptions): RolldownPlugin;
|
|
35
|
+
|
|
36
|
+
export { type RolldownPlugin, angularLinkerRolldownPlugin, angularLinkerRolldownPlugin as default };
|