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/README.md
ADDED
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
# angular-rust-plugins
|
|
2
|
+
|
|
3
|
+
High-performance Angular linker and compiler plugins powered by Rust. Supports **Vite**, **esbuild**, **Rolldown**, and more bundlers coming soon.
|
|
4
|
+
|
|
5
|
+
This package bundles the Angular Rust binding - no additional dependencies needed!
|
|
6
|
+
|
|
7
|
+
## 🚀 Installation
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
npm install angular-rust-plugins
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
## 📖 Usage
|
|
14
|
+
|
|
15
|
+
### Full Angular Setup with Vite
|
|
16
|
+
|
|
17
|
+
```js
|
|
18
|
+
// vite.config.js
|
|
19
|
+
import { defineConfig } from "vite";
|
|
20
|
+
import { angularLinkerVitePlugin } from "angular-rust-plugins/linker/vite";
|
|
21
|
+
import { angularCompilerVitePlugin } from "angular-rust-plugins/compiler/vite";
|
|
22
|
+
|
|
23
|
+
export default defineConfig({
|
|
24
|
+
plugins: [
|
|
25
|
+
angularLinkerVitePlugin(), // Links @angular/* packages
|
|
26
|
+
angularCompilerVitePlugin(), // Compiles your .ts files
|
|
27
|
+
],
|
|
28
|
+
});
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
### Linker Only (Vite)
|
|
32
|
+
|
|
33
|
+
```js
|
|
34
|
+
import { angularLinkerVitePlugin } from "angular-rust-plugins/linker/vite";
|
|
35
|
+
|
|
36
|
+
export default defineConfig({
|
|
37
|
+
plugins: [angularLinkerVitePlugin()],
|
|
38
|
+
});
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
### Linker with Rolldown
|
|
42
|
+
|
|
43
|
+
```js
|
|
44
|
+
import { angularLinkerRolldownPlugin } from "angular-rust-plugins/linker/rolldown";
|
|
45
|
+
|
|
46
|
+
export default defineConfig({
|
|
47
|
+
plugins: [angularLinkerRolldownPlugin()],
|
|
48
|
+
optimizeDeps: {
|
|
49
|
+
exclude: ["@angular/core", "@angular/common", "@angular/platform-browser"],
|
|
50
|
+
},
|
|
51
|
+
});
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
### Linker with esbuild
|
|
55
|
+
|
|
56
|
+
```js
|
|
57
|
+
import { angularLinkerEsbuildPlugin } from "angular-rust-plugins/linker/esbuild";
|
|
58
|
+
|
|
59
|
+
esbuild.build({
|
|
60
|
+
plugins: [angularLinkerEsbuildPlugin()],
|
|
61
|
+
});
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
## 📦 Package Exports
|
|
65
|
+
|
|
66
|
+
| Export Path | Description |
|
|
67
|
+
| -------------------------------------- | ---------------------- |
|
|
68
|
+
| `angular-rust-plugins` | All plugins |
|
|
69
|
+
| **Linker Plugins** | |
|
|
70
|
+
| `angular-rust-plugins/linker` | All linker plugins |
|
|
71
|
+
| `angular-rust-plugins/linker/vite` | Vite linker plugin |
|
|
72
|
+
| `angular-rust-plugins/linker/esbuild` | esbuild linker plugin |
|
|
73
|
+
| `angular-rust-plugins/linker/rolldown` | Rolldown linker plugin |
|
|
74
|
+
| **Compiler Plugins** | |
|
|
75
|
+
| `angular-rust-plugins/compiler` | All compiler plugins |
|
|
76
|
+
| `angular-rust-plugins/compiler/vite` | Vite compiler plugin |
|
|
77
|
+
|
|
78
|
+
## ⚙️ Options
|
|
79
|
+
|
|
80
|
+
### Linker Options
|
|
81
|
+
|
|
82
|
+
```ts
|
|
83
|
+
interface LinkerOptions {
|
|
84
|
+
debug?: boolean; // Enable debug logging
|
|
85
|
+
bindingPath?: string; // Custom path to binding
|
|
86
|
+
}
|
|
87
|
+
```
|
|
88
|
+
|
|
89
|
+
### Compiler Options
|
|
90
|
+
|
|
91
|
+
```ts
|
|
92
|
+
interface CompilerOptions {
|
|
93
|
+
debug?: boolean; // Enable debug logging
|
|
94
|
+
bindingPath?: string; // Custom path to binding
|
|
95
|
+
}
|
|
96
|
+
```
|
|
97
|
+
|
|
98
|
+
## 🔧 Development
|
|
99
|
+
|
|
100
|
+
```bash
|
|
101
|
+
# Build with current binding
|
|
102
|
+
npm run build
|
|
103
|
+
|
|
104
|
+
# Rebuild binding and plugin
|
|
105
|
+
npm run build:full
|
|
106
|
+
```
|
|
107
|
+
|
|
108
|
+
## ⚡ Performance
|
|
109
|
+
|
|
110
|
+
**2-5x faster** than TypeScript-based Angular compiler with lower memory usage.
|
|
111
|
+
|
|
112
|
+
## 📝 License
|
|
113
|
+
|
|
114
|
+
MIT
|
|
115
|
+
|
|
116
|
+
---
|
|
117
|
+
|
|
118
|
+
**Built with ❤️ using Rust**
|
|
Binary file
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/* tslint:disable */
|
|
2
|
+
/* eslint-disable */
|
|
3
|
+
|
|
4
|
+
/* auto-generated by NAPI-RS */
|
|
5
|
+
|
|
6
|
+
export declare function linkFile(sourceCode: string, filename: string): string
|
|
7
|
+
export declare class Compiler {
|
|
8
|
+
constructor()
|
|
9
|
+
compile(filename: string, content: string): string
|
|
10
|
+
constructor()
|
|
11
|
+
compile(filename: string, content: string): string
|
|
12
|
+
linkFile(filename: string, sourceCode: string): string
|
|
13
|
+
}
|
package/binding/index.js
ADDED
|
@@ -0,0 +1,316 @@
|
|
|
1
|
+
/* tslint:disable */
|
|
2
|
+
/* eslint-disable */
|
|
3
|
+
/* prettier-ignore */
|
|
4
|
+
|
|
5
|
+
/* auto-generated by NAPI-RS */
|
|
6
|
+
|
|
7
|
+
const { existsSync, readFileSync } = require('fs')
|
|
8
|
+
const { join } = require('path')
|
|
9
|
+
|
|
10
|
+
const { platform, arch } = process
|
|
11
|
+
|
|
12
|
+
let nativeBinding = null
|
|
13
|
+
let localFileExisted = false
|
|
14
|
+
let loadError = null
|
|
15
|
+
|
|
16
|
+
function isMusl() {
|
|
17
|
+
// For Node 10
|
|
18
|
+
if (!process.report || typeof process.report.getReport !== 'function') {
|
|
19
|
+
try {
|
|
20
|
+
const lddPath = require('child_process').execSync('which ldd').toString().trim()
|
|
21
|
+
return readFileSync(lddPath, 'utf8').includes('musl')
|
|
22
|
+
} catch (e) {
|
|
23
|
+
return true
|
|
24
|
+
}
|
|
25
|
+
} else {
|
|
26
|
+
const { glibcVersionRuntime } = process.report.getReport().header
|
|
27
|
+
return !glibcVersionRuntime
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
switch (platform) {
|
|
32
|
+
case 'android':
|
|
33
|
+
switch (arch) {
|
|
34
|
+
case 'arm64':
|
|
35
|
+
localFileExisted = existsSync(join(__dirname, 'angular-binding.android-arm64.node'))
|
|
36
|
+
try {
|
|
37
|
+
if (localFileExisted) {
|
|
38
|
+
nativeBinding = require('./angular-binding.android-arm64.node')
|
|
39
|
+
} else {
|
|
40
|
+
nativeBinding = require('@angular/rust-binding-android-arm64')
|
|
41
|
+
}
|
|
42
|
+
} catch (e) {
|
|
43
|
+
loadError = e
|
|
44
|
+
}
|
|
45
|
+
break
|
|
46
|
+
case 'arm':
|
|
47
|
+
localFileExisted = existsSync(join(__dirname, 'angular-binding.android-arm-eabi.node'))
|
|
48
|
+
try {
|
|
49
|
+
if (localFileExisted) {
|
|
50
|
+
nativeBinding = require('./angular-binding.android-arm-eabi.node')
|
|
51
|
+
} else {
|
|
52
|
+
nativeBinding = require('@angular/rust-binding-android-arm-eabi')
|
|
53
|
+
}
|
|
54
|
+
} catch (e) {
|
|
55
|
+
loadError = e
|
|
56
|
+
}
|
|
57
|
+
break
|
|
58
|
+
default:
|
|
59
|
+
throw new Error(`Unsupported architecture on Android ${arch}`)
|
|
60
|
+
}
|
|
61
|
+
break
|
|
62
|
+
case 'win32':
|
|
63
|
+
switch (arch) {
|
|
64
|
+
case 'x64':
|
|
65
|
+
localFileExisted = existsSync(
|
|
66
|
+
join(__dirname, 'angular-binding.win32-x64-msvc.node')
|
|
67
|
+
)
|
|
68
|
+
try {
|
|
69
|
+
if (localFileExisted) {
|
|
70
|
+
nativeBinding = require('./angular-binding.win32-x64-msvc.node')
|
|
71
|
+
} else {
|
|
72
|
+
nativeBinding = require('@angular/rust-binding-win32-x64-msvc')
|
|
73
|
+
}
|
|
74
|
+
} catch (e) {
|
|
75
|
+
loadError = e
|
|
76
|
+
}
|
|
77
|
+
break
|
|
78
|
+
case 'ia32':
|
|
79
|
+
localFileExisted = existsSync(
|
|
80
|
+
join(__dirname, 'angular-binding.win32-ia32-msvc.node')
|
|
81
|
+
)
|
|
82
|
+
try {
|
|
83
|
+
if (localFileExisted) {
|
|
84
|
+
nativeBinding = require('./angular-binding.win32-ia32-msvc.node')
|
|
85
|
+
} else {
|
|
86
|
+
nativeBinding = require('@angular/rust-binding-win32-ia32-msvc')
|
|
87
|
+
}
|
|
88
|
+
} catch (e) {
|
|
89
|
+
loadError = e
|
|
90
|
+
}
|
|
91
|
+
break
|
|
92
|
+
case 'arm64':
|
|
93
|
+
localFileExisted = existsSync(
|
|
94
|
+
join(__dirname, 'angular-binding.win32-arm64-msvc.node')
|
|
95
|
+
)
|
|
96
|
+
try {
|
|
97
|
+
if (localFileExisted) {
|
|
98
|
+
nativeBinding = require('./angular-binding.win32-arm64-msvc.node')
|
|
99
|
+
} else {
|
|
100
|
+
nativeBinding = require('@angular/rust-binding-win32-arm64-msvc')
|
|
101
|
+
}
|
|
102
|
+
} catch (e) {
|
|
103
|
+
loadError = e
|
|
104
|
+
}
|
|
105
|
+
break
|
|
106
|
+
default:
|
|
107
|
+
throw new Error(`Unsupported architecture on Windows: ${arch}`)
|
|
108
|
+
}
|
|
109
|
+
break
|
|
110
|
+
case 'darwin':
|
|
111
|
+
localFileExisted = existsSync(join(__dirname, 'angular-binding.darwin-universal.node'))
|
|
112
|
+
try {
|
|
113
|
+
if (localFileExisted) {
|
|
114
|
+
nativeBinding = require('./angular-binding.darwin-universal.node')
|
|
115
|
+
} else {
|
|
116
|
+
nativeBinding = require('@angular/rust-binding-darwin-universal')
|
|
117
|
+
}
|
|
118
|
+
break
|
|
119
|
+
} catch {}
|
|
120
|
+
switch (arch) {
|
|
121
|
+
case 'x64':
|
|
122
|
+
localFileExisted = existsSync(join(__dirname, 'angular-binding.darwin-x64.node'))
|
|
123
|
+
try {
|
|
124
|
+
if (localFileExisted) {
|
|
125
|
+
nativeBinding = require('./angular-binding.darwin-x64.node')
|
|
126
|
+
} else {
|
|
127
|
+
nativeBinding = require('@angular/rust-binding-darwin-x64')
|
|
128
|
+
}
|
|
129
|
+
} catch (e) {
|
|
130
|
+
loadError = e
|
|
131
|
+
}
|
|
132
|
+
break
|
|
133
|
+
case 'arm64':
|
|
134
|
+
localFileExisted = existsSync(
|
|
135
|
+
join(__dirname, 'angular-binding.darwin-arm64.node')
|
|
136
|
+
)
|
|
137
|
+
try {
|
|
138
|
+
if (localFileExisted) {
|
|
139
|
+
nativeBinding = require('./angular-binding.darwin-arm64.node')
|
|
140
|
+
} else {
|
|
141
|
+
nativeBinding = require('@angular/rust-binding-darwin-arm64')
|
|
142
|
+
}
|
|
143
|
+
} catch (e) {
|
|
144
|
+
loadError = e
|
|
145
|
+
}
|
|
146
|
+
break
|
|
147
|
+
default:
|
|
148
|
+
throw new Error(`Unsupported architecture on macOS: ${arch}`)
|
|
149
|
+
}
|
|
150
|
+
break
|
|
151
|
+
case 'freebsd':
|
|
152
|
+
if (arch !== 'x64') {
|
|
153
|
+
throw new Error(`Unsupported architecture on FreeBSD: ${arch}`)
|
|
154
|
+
}
|
|
155
|
+
localFileExisted = existsSync(join(__dirname, 'angular-binding.freebsd-x64.node'))
|
|
156
|
+
try {
|
|
157
|
+
if (localFileExisted) {
|
|
158
|
+
nativeBinding = require('./angular-binding.freebsd-x64.node')
|
|
159
|
+
} else {
|
|
160
|
+
nativeBinding = require('@angular/rust-binding-freebsd-x64')
|
|
161
|
+
}
|
|
162
|
+
} catch (e) {
|
|
163
|
+
loadError = e
|
|
164
|
+
}
|
|
165
|
+
break
|
|
166
|
+
case 'linux':
|
|
167
|
+
switch (arch) {
|
|
168
|
+
case 'x64':
|
|
169
|
+
if (isMusl()) {
|
|
170
|
+
localFileExisted = existsSync(
|
|
171
|
+
join(__dirname, 'angular-binding.linux-x64-musl.node')
|
|
172
|
+
)
|
|
173
|
+
try {
|
|
174
|
+
if (localFileExisted) {
|
|
175
|
+
nativeBinding = require('./angular-binding.linux-x64-musl.node')
|
|
176
|
+
} else {
|
|
177
|
+
nativeBinding = require('@angular/rust-binding-linux-x64-musl')
|
|
178
|
+
}
|
|
179
|
+
} catch (e) {
|
|
180
|
+
loadError = e
|
|
181
|
+
}
|
|
182
|
+
} else {
|
|
183
|
+
localFileExisted = existsSync(
|
|
184
|
+
join(__dirname, 'angular-binding.linux-x64-gnu.node')
|
|
185
|
+
)
|
|
186
|
+
try {
|
|
187
|
+
if (localFileExisted) {
|
|
188
|
+
nativeBinding = require('./angular-binding.linux-x64-gnu.node')
|
|
189
|
+
} else {
|
|
190
|
+
nativeBinding = require('@angular/rust-binding-linux-x64-gnu')
|
|
191
|
+
}
|
|
192
|
+
} catch (e) {
|
|
193
|
+
loadError = e
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
break
|
|
197
|
+
case 'arm64':
|
|
198
|
+
if (isMusl()) {
|
|
199
|
+
localFileExisted = existsSync(
|
|
200
|
+
join(__dirname, 'angular-binding.linux-arm64-musl.node')
|
|
201
|
+
)
|
|
202
|
+
try {
|
|
203
|
+
if (localFileExisted) {
|
|
204
|
+
nativeBinding = require('./angular-binding.linux-arm64-musl.node')
|
|
205
|
+
} else {
|
|
206
|
+
nativeBinding = require('@angular/rust-binding-linux-arm64-musl')
|
|
207
|
+
}
|
|
208
|
+
} catch (e) {
|
|
209
|
+
loadError = e
|
|
210
|
+
}
|
|
211
|
+
} else {
|
|
212
|
+
localFileExisted = existsSync(
|
|
213
|
+
join(__dirname, 'angular-binding.linux-arm64-gnu.node')
|
|
214
|
+
)
|
|
215
|
+
try {
|
|
216
|
+
if (localFileExisted) {
|
|
217
|
+
nativeBinding = require('./angular-binding.linux-arm64-gnu.node')
|
|
218
|
+
} else {
|
|
219
|
+
nativeBinding = require('@angular/rust-binding-linux-arm64-gnu')
|
|
220
|
+
}
|
|
221
|
+
} catch (e) {
|
|
222
|
+
loadError = e
|
|
223
|
+
}
|
|
224
|
+
}
|
|
225
|
+
break
|
|
226
|
+
case 'arm':
|
|
227
|
+
if (isMusl()) {
|
|
228
|
+
localFileExisted = existsSync(
|
|
229
|
+
join(__dirname, 'angular-binding.linux-arm-musleabihf.node')
|
|
230
|
+
)
|
|
231
|
+
try {
|
|
232
|
+
if (localFileExisted) {
|
|
233
|
+
nativeBinding = require('./angular-binding.linux-arm-musleabihf.node')
|
|
234
|
+
} else {
|
|
235
|
+
nativeBinding = require('@angular/rust-binding-linux-arm-musleabihf')
|
|
236
|
+
}
|
|
237
|
+
} catch (e) {
|
|
238
|
+
loadError = e
|
|
239
|
+
}
|
|
240
|
+
} else {
|
|
241
|
+
localFileExisted = existsSync(
|
|
242
|
+
join(__dirname, 'angular-binding.linux-arm-gnueabihf.node')
|
|
243
|
+
)
|
|
244
|
+
try {
|
|
245
|
+
if (localFileExisted) {
|
|
246
|
+
nativeBinding = require('./angular-binding.linux-arm-gnueabihf.node')
|
|
247
|
+
} else {
|
|
248
|
+
nativeBinding = require('@angular/rust-binding-linux-arm-gnueabihf')
|
|
249
|
+
}
|
|
250
|
+
} catch (e) {
|
|
251
|
+
loadError = e
|
|
252
|
+
}
|
|
253
|
+
}
|
|
254
|
+
break
|
|
255
|
+
case 'riscv64':
|
|
256
|
+
if (isMusl()) {
|
|
257
|
+
localFileExisted = existsSync(
|
|
258
|
+
join(__dirname, 'angular-binding.linux-riscv64-musl.node')
|
|
259
|
+
)
|
|
260
|
+
try {
|
|
261
|
+
if (localFileExisted) {
|
|
262
|
+
nativeBinding = require('./angular-binding.linux-riscv64-musl.node')
|
|
263
|
+
} else {
|
|
264
|
+
nativeBinding = require('@angular/rust-binding-linux-riscv64-musl')
|
|
265
|
+
}
|
|
266
|
+
} catch (e) {
|
|
267
|
+
loadError = e
|
|
268
|
+
}
|
|
269
|
+
} else {
|
|
270
|
+
localFileExisted = existsSync(
|
|
271
|
+
join(__dirname, 'angular-binding.linux-riscv64-gnu.node')
|
|
272
|
+
)
|
|
273
|
+
try {
|
|
274
|
+
if (localFileExisted) {
|
|
275
|
+
nativeBinding = require('./angular-binding.linux-riscv64-gnu.node')
|
|
276
|
+
} else {
|
|
277
|
+
nativeBinding = require('@angular/rust-binding-linux-riscv64-gnu')
|
|
278
|
+
}
|
|
279
|
+
} catch (e) {
|
|
280
|
+
loadError = e
|
|
281
|
+
}
|
|
282
|
+
}
|
|
283
|
+
break
|
|
284
|
+
case 's390x':
|
|
285
|
+
localFileExisted = existsSync(
|
|
286
|
+
join(__dirname, 'angular-binding.linux-s390x-gnu.node')
|
|
287
|
+
)
|
|
288
|
+
try {
|
|
289
|
+
if (localFileExisted) {
|
|
290
|
+
nativeBinding = require('./angular-binding.linux-s390x-gnu.node')
|
|
291
|
+
} else {
|
|
292
|
+
nativeBinding = require('@angular/rust-binding-linux-s390x-gnu')
|
|
293
|
+
}
|
|
294
|
+
} catch (e) {
|
|
295
|
+
loadError = e
|
|
296
|
+
}
|
|
297
|
+
break
|
|
298
|
+
default:
|
|
299
|
+
throw new Error(`Unsupported architecture on Linux: ${arch}`)
|
|
300
|
+
}
|
|
301
|
+
break
|
|
302
|
+
default:
|
|
303
|
+
throw new Error(`Unsupported OS: ${platform}, architecture: ${arch}`)
|
|
304
|
+
}
|
|
305
|
+
|
|
306
|
+
if (!nativeBinding) {
|
|
307
|
+
if (loadError) {
|
|
308
|
+
throw loadError
|
|
309
|
+
}
|
|
310
|
+
throw new Error(`Failed to load native binding`)
|
|
311
|
+
}
|
|
312
|
+
|
|
313
|
+
const { Compiler, linkFile } = nativeBinding
|
|
314
|
+
|
|
315
|
+
module.exports.Compiler = Compiler
|
|
316
|
+
module.exports.linkFile = linkFile
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"type":"commonjs"}
|
|
@@ -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/compiler/index.ts
|
|
21
|
+
var compiler_exports = {};
|
|
22
|
+
__export(compiler_exports, {
|
|
23
|
+
angularCompilerVitePlugin: () => angularCompilerVitePlugin
|
|
24
|
+
});
|
|
25
|
+
module.exports = __toCommonJS(compiler_exports);
|
|
26
|
+
|
|
27
|
+
// src/compiler/vite.ts
|
|
28
|
+
var import_module = require("module");
|
|
29
|
+
var import_path = require("path");
|
|
30
|
+
var import_url = require("url");
|
|
31
|
+
var import_meta = {};
|
|
32
|
+
var compilerInstance = null;
|
|
33
|
+
function getCompiler(options) {
|
|
34
|
+
if (compilerInstance) {
|
|
35
|
+
return compilerInstance;
|
|
36
|
+
}
|
|
37
|
+
try {
|
|
38
|
+
let binding;
|
|
39
|
+
if (options?.bindingPath) {
|
|
40
|
+
const require2 = (0, import_module.createRequire)(import_meta.url);
|
|
41
|
+
binding = require2(options.bindingPath);
|
|
42
|
+
} else {
|
|
43
|
+
const currentFileUrl = import_meta.url;
|
|
44
|
+
const currentFilePath = (0, import_url.fileURLToPath)(currentFileUrl);
|
|
45
|
+
const currentDir = (0, import_path.dirname)(currentFilePath);
|
|
46
|
+
const require2 = (0, import_module.createRequire)(currentFileUrl);
|
|
47
|
+
const possiblePaths = [
|
|
48
|
+
(0, import_path.join)(currentDir, "..", "binding"),
|
|
49
|
+
// dist/compiler/../binding
|
|
50
|
+
(0, import_path.join)(currentDir, "..", "..", "binding"),
|
|
51
|
+
// in case of deeper nesting
|
|
52
|
+
(0, import_path.join)(currentDir, "binding")
|
|
53
|
+
// same directory
|
|
54
|
+
];
|
|
55
|
+
let loadedBinding = null;
|
|
56
|
+
let lastError = null;
|
|
57
|
+
for (const bindingPath of possiblePaths) {
|
|
58
|
+
try {
|
|
59
|
+
loadedBinding = require2(bindingPath);
|
|
60
|
+
break;
|
|
61
|
+
} catch (e) {
|
|
62
|
+
lastError = e;
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
if (!loadedBinding) {
|
|
66
|
+
throw lastError || new Error("Could not find binding in any expected location");
|
|
67
|
+
}
|
|
68
|
+
binding = loadedBinding;
|
|
69
|
+
}
|
|
70
|
+
compilerInstance = new binding.Compiler();
|
|
71
|
+
return compilerInstance;
|
|
72
|
+
} catch (e) {
|
|
73
|
+
throw new Error(`Failed to load Angular Rust binding. Error: ${e}`);
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
function angularCompilerVitePlugin(options) {
|
|
77
|
+
const debug = options?.debug ?? false;
|
|
78
|
+
let compiler;
|
|
79
|
+
return {
|
|
80
|
+
name: "angular-rust-compiler",
|
|
81
|
+
enforce: "pre",
|
|
82
|
+
transform(code, id) {
|
|
83
|
+
if (!compiler) {
|
|
84
|
+
compiler = getCompiler(options);
|
|
85
|
+
}
|
|
86
|
+
if (id.includes("node_modules")) {
|
|
87
|
+
return null;
|
|
88
|
+
}
|
|
89
|
+
if (!id.endsWith(".ts") || id.endsWith(".d.ts")) {
|
|
90
|
+
return null;
|
|
91
|
+
}
|
|
92
|
+
if (debug) {
|
|
93
|
+
console.log(`[Angular Compiler] Compiling: ${id}`);
|
|
94
|
+
}
|
|
95
|
+
try {
|
|
96
|
+
const result = compiler.compile(id, code);
|
|
97
|
+
if (result.startsWith("/* Error")) {
|
|
98
|
+
console.error(`[Angular Compiler Error] ${id}:
|
|
99
|
+
${result}`);
|
|
100
|
+
throw new Error(`Rust Compilation Failed for ${id}`);
|
|
101
|
+
}
|
|
102
|
+
if (debug) {
|
|
103
|
+
console.log(`[Angular Compiler] Successfully compiled: ${id}`);
|
|
104
|
+
}
|
|
105
|
+
return { code: result, map: null };
|
|
106
|
+
} catch (e) {
|
|
107
|
+
console.error(`[Angular Compiler Failed] ${id}:`, e);
|
|
108
|
+
throw e;
|
|
109
|
+
}
|
|
110
|
+
},
|
|
111
|
+
handleHotUpdate({ file, server }) {
|
|
112
|
+
if (file.endsWith(".html")) {
|
|
113
|
+
const tsFile = file.replace(/\.html$/, ".ts");
|
|
114
|
+
if (debug) {
|
|
115
|
+
console.log(`[HMR] HTML changed: ${file}`);
|
|
116
|
+
console.log(`[HMR] Invalidating TS: ${tsFile}`);
|
|
117
|
+
}
|
|
118
|
+
const mod = server.moduleGraph.getModuleById(tsFile);
|
|
119
|
+
if (mod) {
|
|
120
|
+
server.moduleGraph.invalidateModule(mod);
|
|
121
|
+
server.ws.send({ type: "full-reload", path: "*" });
|
|
122
|
+
return [];
|
|
123
|
+
} else {
|
|
124
|
+
server.ws.send({ type: "full-reload", path: "*" });
|
|
125
|
+
return [];
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
};
|
|
130
|
+
}
|
|
131
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
132
|
+
0 && (module.exports = {
|
|
133
|
+
angularCompilerVitePlugin
|
|
134
|
+
});
|
|
135
|
+
//# sourceMappingURL=index.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/compiler/index.ts","../../src/compiler/vite.ts"],"sourcesContent":["/**\n * Angular Compiler Plugins - Index\n *\n * Re-exports all compiler plugins for different bundlers.\n */\n\nexport { angularCompilerVitePlugin } from \"./vite\";\nexport type { CompilerOptions } from \"./vite\";\nexport type { CompilerBinding } from \"./types\";\n","/**\n * Angular Compiler Plugin for Vite\n *\n * This plugin compiles Angular TypeScript files using the Rust-based Angular compiler.\n * Use with the linker plugin for a complete Angular build solution.\n *\n * @example\n * ```js\n * import { angularCompilerVitePlugin } from 'angular-rust-plugins/compiler/vite';\n * import { angularLinkerVitePlugin } from 'angular-rust-plugins/linker/vite';\n * import { defineConfig } from 'vite';\n *\n * export default defineConfig({\n * plugins: [\n * angularLinkerVitePlugin(),\n * angularCompilerVitePlugin(),\n * ],\n * });\n * ```\n */\n\nimport type { Plugin, HmrContext } from \"vite\";\nimport { createRequire } from \"module\";\nimport { dirname, join } from \"path\";\nimport { fileURLToPath } from \"url\";\nimport type { CompilerBinding } from \"./types\";\n\nlet compilerInstance: CompilerBinding | null = null;\n\nexport interface CompilerOptions {\n /**\n * Enable debug logging\n * @default false\n */\n debug?: boolean;\n\n /**\n * Custom path to the Angular Rust binding package\n */\n bindingPath?: string;\n}\n\nfunction getCompiler(options?: CompilerOptions): 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 // Use import.meta.url to get the actual location of this file\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/compiler/../binding\n join(currentDir, \"..\", \"..\", \"binding\"), // in case of deeper nesting\n join(currentDir, \"binding\"), // same directory\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 a Vite plugin for Angular Rust compiler\n * Compiles .ts files (except .d.ts) using the Rust compiler\n */\nexport function angularCompilerVitePlugin(options?: CompilerOptions): Plugin {\n const debug = options?.debug ?? false;\n let compiler: CompilerBinding;\n\n return {\n name: \"angular-rust-compiler\",\n enforce: \"pre\",\n\n transform(code: string, id: string) {\n // Lazy initialize compiler\n if (!compiler) {\n compiler = getCompiler(options);\n }\n\n // Skip node_modules - those are handled by linker, not compiler\n if (id.includes(\"node_modules\")) {\n return null;\n }\n\n // Only process TypeScript files, skip declaration files\n if (!id.endsWith(\".ts\") || id.endsWith(\".d.ts\")) {\n return null;\n }\n\n if (debug) {\n console.log(`[Angular Compiler] Compiling: ${id}`);\n }\n\n try {\n const result = compiler.compile(id, code);\n\n if (result.startsWith(\"/* Error\")) {\n console.error(`[Angular Compiler Error] ${id}:\\n${result}`);\n throw new Error(`Rust Compilation Failed for ${id}`);\n }\n\n if (debug) {\n console.log(`[Angular Compiler] Successfully compiled: ${id}`);\n }\n\n return { code: result, map: null };\n } catch (e) {\n console.error(`[Angular Compiler Failed] ${id}:`, e);\n throw e;\n }\n },\n\n handleHotUpdate({ file, server }: HmrContext) {\n // When HTML template changes, invalidate the corresponding TS file\n if (file.endsWith(\".html\")) {\n const tsFile = file.replace(/\\.html$/, \".ts\");\n\n if (debug) {\n console.log(`[HMR] HTML changed: ${file}`);\n console.log(`[HMR] Invalidating TS: ${tsFile}`);\n }\n\n const mod = server.moduleGraph.getModuleById(tsFile);\n if (mod) {\n server.moduleGraph.invalidateModule(mod);\n server.ws.send({ type: \"full-reload\", path: \"*\" });\n return [];\n } else {\n server.ws.send({ type: \"full-reload\", path: \"*\" });\n return [];\n }\n }\n },\n };\n}\n\nexport default angularCompilerVitePlugin;\n"],"mappings":"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","names":["require"]}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export { CompilerOptions, default as angularCompilerVitePlugin } from './vite.cjs';
|
|
2
|
+
import 'vite';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Compiler Types
|
|
6
|
+
*/
|
|
7
|
+
interface CompilerBinding {
|
|
8
|
+
compile(filePath: string, code: string): string;
|
|
9
|
+
linkFile(filePath: string, code: string): string;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export type { CompilerBinding };
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export { CompilerOptions, default as angularCompilerVitePlugin } from './vite.js';
|
|
2
|
+
import 'vite';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Compiler Types
|
|
6
|
+
*/
|
|
7
|
+
interface CompilerBinding {
|
|
8
|
+
compile(filePath: string, code: string): string;
|
|
9
|
+
linkFile(filePath: string, code: string): string;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export type { CompilerBinding };
|