angular-rust-plugins 0.3.0 → 0.5.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.
Files changed (53) hide show
  1. package/README.md +22 -0
  2. package/binding/angular-binding.darwin-arm64.node +0 -0
  3. package/{dist/binding → binding}/index.d.ts +12 -1
  4. package/package.json +35 -44
  5. package/dist/README.md +0 -306
  6. package/dist/binding/angular-binding.darwin-arm64.node +0 -0
  7. package/dist/package.json +0 -77
  8. /package/{dist/binding → binding}/index.js +0 -0
  9. /package/{dist/binding → binding}/package.json +0 -0
  10. /package/{dist/compiler → compiler}/index.cjs +0 -0
  11. /package/{dist/compiler → compiler}/index.cjs.map +0 -0
  12. /package/{dist/compiler → compiler}/index.d.cts +0 -0
  13. /package/{dist/compiler → compiler}/index.d.ts +0 -0
  14. /package/{dist/compiler → compiler}/index.js +0 -0
  15. /package/{dist/compiler → compiler}/index.js.map +0 -0
  16. /package/{dist/compiler → compiler}/vite.cjs +0 -0
  17. /package/{dist/compiler → compiler}/vite.cjs.map +0 -0
  18. /package/{dist/compiler → compiler}/vite.d.cts +0 -0
  19. /package/{dist/compiler → compiler}/vite.d.ts +0 -0
  20. /package/{dist/compiler → compiler}/vite.js +0 -0
  21. /package/{dist/compiler → compiler}/vite.js.map +0 -0
  22. /package/{dist/index.cjs → index.cjs} +0 -0
  23. /package/{dist/index.cjs.map → index.cjs.map} +0 -0
  24. /package/{dist/index.d.cts → index.d.cts} +0 -0
  25. /package/{dist/index.d.ts → index.d.ts} +0 -0
  26. /package/{dist/index.js → index.js} +0 -0
  27. /package/{dist/index.js.map → index.js.map} +0 -0
  28. /package/{dist/linker → linker}/esbuild.cjs +0 -0
  29. /package/{dist/linker → linker}/esbuild.cjs.map +0 -0
  30. /package/{dist/linker → linker}/esbuild.d.cts +0 -0
  31. /package/{dist/linker → linker}/esbuild.d.ts +0 -0
  32. /package/{dist/linker → linker}/esbuild.js +0 -0
  33. /package/{dist/linker → linker}/esbuild.js.map +0 -0
  34. /package/{dist/linker → linker}/index.cjs +0 -0
  35. /package/{dist/linker → linker}/index.cjs.map +0 -0
  36. /package/{dist/linker → linker}/index.d.cts +0 -0
  37. /package/{dist/linker → linker}/index.d.ts +0 -0
  38. /package/{dist/linker → linker}/index.js +0 -0
  39. /package/{dist/linker → linker}/index.js.map +0 -0
  40. /package/{dist/linker → linker}/rolldown.cjs +0 -0
  41. /package/{dist/linker → linker}/rolldown.cjs.map +0 -0
  42. /package/{dist/linker → linker}/rolldown.d.cts +0 -0
  43. /package/{dist/linker → linker}/rolldown.d.ts +0 -0
  44. /package/{dist/linker → linker}/rolldown.js +0 -0
  45. /package/{dist/linker → linker}/rolldown.js.map +0 -0
  46. /package/{dist/linker → linker}/vite.cjs +0 -0
  47. /package/{dist/linker → linker}/vite.cjs.map +0 -0
  48. /package/{dist/linker → linker}/vite.d.cts +0 -0
  49. /package/{dist/linker → linker}/vite.d.ts +0 -0
  50. /package/{dist/linker → linker}/vite.js +0 -0
  51. /package/{dist/linker → linker}/vite.js.map +0 -0
  52. /package/{dist/types-BTaYbdhr.d.cts → types-BTaYbdhr.d.cts} +0 -0
  53. /package/{dist/types-BTaYbdhr.d.ts → types-BTaYbdhr.d.ts} +0 -0
package/README.md CHANGED
@@ -4,6 +4,14 @@ High-performance Angular linker and compiler plugins powered by Rust. Supports *
4
4
 
5
5
  This package bundles the Angular Rust binding - no additional dependencies needed!
6
6
 
7
+ ## ✨ Features
8
+
9
+ - ✅ **Standard Directives**: Full support for `*ngIf` (with `else`, `then`, `as`) and `*ngFor` (with all context variables).
10
+ - ✅ **Template Parity**: 100% output parity with NGTSC for template instructions and `consts` array sorting.
11
+ - ✅ **Change Detection**: Optimized listener emission for `OnPush` components.
12
+ - ✅ **Signal Support**: Full support for modern Angular signals (`input()`, `output()`, `computed()`, etc.).
13
+ - ✅ **Blazing Fast**: Uses the Rust-based compiler for ~3-5x faster compilation compared to standard TypeScript-based compilation.
14
+
7
15
  ## 🚀 Installation
8
16
 
9
17
  ```bash
@@ -277,6 +285,20 @@ Ensure your `tsconfig.json` includes:
277
285
 
278
286
  The compiler plugin includes HMR support for `.html` template files. When you modify a template, the corresponding component will be recompiled automatically.
279
287
 
288
+ ## 💡 Advanced Directive Support
289
+
290
+ The compiler now achieves full feature parity with the standard Angular compiler for core structural directives:
291
+
292
+ ### `*ngFor` Support
293
+ - **Full Context Access**: Support for `index`, `count`, `first`, `last`, `even`, `odd`.
294
+ - **Performance**: Automatic optimization of context access in event listeners.
295
+ - **Parity**: Identical `consts` array ordering through source-span sorting.
296
+
297
+ ### `*ngIf` Support
298
+ - **Complex Templates**: Support for `else` and `then` templates with `TemplateRef` extraction.
299
+ - **As Syntax**: Support for the `as` local variable binding (e.g., `*ngIf="obs$ | async as val"`).
300
+ - **Context Isolation**: Correct variable scoping and restoration for nested conditionals.
301
+
280
302
  ## ⚡ Performance
281
303
 
282
304
  **2-5x faster** than TypeScript-based Angular compiler with lower memory usage.
@@ -4,10 +4,21 @@
4
4
  /* auto-generated by NAPI-RS */
5
5
 
6
6
  export declare function linkFile(sourceCode: string, filename: string): string
7
+ export interface Diagnostic {
8
+ file?: string
9
+ message: string
10
+ code: number
11
+ start?: number
12
+ length?: number
13
+ }
14
+ export interface CompileResult {
15
+ code: string
16
+ diagnostics: Array<Diagnostic>
17
+ }
7
18
  export declare class Compiler {
8
19
  constructor()
9
20
  compile(filename: string, content: string): string
10
21
  constructor()
11
- compile(filename: string, content: string): string
22
+ compile(filename: string, content: string): CompileResult
12
23
  linkFile(filename: string, sourceCode: string): string
13
24
  }
package/package.json CHANGED
@@ -1,66 +1,62 @@
1
1
  {
2
2
  "name": "angular-rust-plugins",
3
- "version": "0.3.0",
3
+ "version": "0.5.0",
4
4
  "description": "Angular plugins for bundlers (Vite, esbuild, Rolldown, Webpack, Rspack) - powered by Rust compiler",
5
5
  "author": "Truonglv4",
6
6
  "license": "MIT",
7
7
  "type": "module",
8
- "main": "./dist/index.cjs",
9
- "module": "./dist/index.js",
10
- "types": "./dist/index.d.ts",
8
+ "main": "./index.cjs",
9
+ "module": "./index.js",
10
+ "types": "./index.d.ts",
11
11
  "exports": {
12
12
  ".": {
13
- "types": "./dist/index.d.ts",
14
- "import": "./dist/index.js",
15
- "require": "./dist/index.cjs"
13
+ "types": "./index.d.ts",
14
+ "import": "./index.js",
15
+ "require": "./index.cjs"
16
16
  },
17
17
  "./linker": {
18
- "types": "./dist/linker/index.d.ts",
19
- "import": "./dist/linker/index.js",
20
- "require": "./dist/linker/index.cjs"
18
+ "types": "./linker/index.d.ts",
19
+ "import": "./linker/index.js",
20
+ "require": "./linker/index.cjs"
21
21
  },
22
22
  "./linker/vite": {
23
- "types": "./dist/linker/vite.d.ts",
24
- "import": "./dist/linker/vite.js",
25
- "require": "./dist/linker/vite.cjs"
23
+ "types": "./linker/vite.d.ts",
24
+ "import": "./linker/vite.js",
25
+ "require": "./linker/vite.cjs"
26
26
  },
27
27
  "./linker/esbuild": {
28
- "types": "./dist/linker/esbuild.d.ts",
29
- "import": "./dist/linker/esbuild.js",
30
- "require": "./dist/linker/esbuild.cjs"
28
+ "types": "./linker/esbuild.d.ts",
29
+ "import": "./linker/esbuild.js",
30
+ "require": "./linker/esbuild.cjs"
31
31
  },
32
32
  "./linker/rolldown": {
33
- "types": "./dist/linker/rolldown.d.ts",
34
- "import": "./dist/linker/rolldown.js",
35
- "require": "./dist/linker/rolldown.cjs"
33
+ "types": "./linker/rolldown.d.ts",
34
+ "import": "./linker/rolldown.js",
35
+ "require": "./linker/rolldown.cjs"
36
36
  },
37
37
  "./compiler": {
38
- "types": "./dist/compiler/index.d.ts",
39
- "import": "./dist/compiler/index.js",
40
- "require": "./dist/compiler/index.cjs"
38
+ "types": "./compiler/index.d.ts",
39
+ "import": "./compiler/index.js",
40
+ "require": "./compiler/index.cjs"
41
41
  },
42
42
  "./compiler/vite": {
43
- "types": "./dist/compiler/vite.d.ts",
44
- "import": "./dist/compiler/vite.js",
45
- "require": "./dist/compiler/vite.cjs"
43
+ "types": "./compiler/vite.d.ts",
44
+ "import": "./compiler/vite.js",
45
+ "require": "./compiler/vite.cjs"
46
46
  }
47
47
  },
48
48
  "files": [
49
- "dist",
50
- "README.md"
49
+ "binding",
50
+ "linker",
51
+ "compiler",
52
+ "index.js",
53
+ "index.cjs",
54
+ "index.d.ts",
55
+ "index.d.cts",
56
+ "*.map",
57
+ "types-*.d.ts",
58
+ "types-*.d.cts"
51
59
  ],
52
- "scripts": {
53
- "copy-binding": "rm -rf src/binding && mkdir -p src/binding && cp ../binding/index.js ../binding/index.d.ts ../binding/*.node src/binding/ 2>/dev/null || true && echo '{\"type\":\"commonjs\"}' > src/binding/package.json",
54
- "copy-binding-to-dist": "mkdir -p dist/binding && cp src/binding/* dist/binding/",
55
- "copy-package": "cp package.dist.json dist/package.json",
56
- "copy-docs": "cp README.md dist/",
57
- "build": "npm run copy-binding && tsup && npm run copy-binding-to-dist && npm run copy-package && npm run copy-docs",
58
- "build:full": "cd ../binding && npm run build && cd ../linker-plugins && npm run build",
59
- "dev": "tsup --watch",
60
- "prepublishOnly": "npm run build",
61
- "pack:dist": "cd dist && npm pack",
62
- "publish": "cd dist && npm publish"
63
- },
64
60
  "keywords": [
65
61
  "angular",
66
62
  "linker",
@@ -77,10 +73,5 @@
77
73
  "repository": {
78
74
  "type": "git",
79
75
  "url": "https://github.com/truonglvos/angular-rust-compiler/tree/main/packages/linker-plugins"
80
- },
81
- "devDependencies": {
82
- "tsup": "^8.3.5",
83
- "typescript": "^5.7.2",
84
- "vite": "^6.0.0"
85
76
  }
86
77
  }
package/dist/README.md DELETED
@@ -1,306 +0,0 @@
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
- ## 📋 Quick Start
14
-
15
- ### 1. Create `index.html`
16
-
17
- Create an `index.html` file at the root of your project:
18
-
19
- ```html
20
- <!doctype html>
21
- <html lang="en">
22
- <head>
23
- <meta charset="utf-8">
24
- <title>My Angular App</title>
25
- <base href="/">
26
- <meta name="viewport" content="width=device-width, initial-scale=1">
27
- <link rel="icon" type="image/x-icon" href="favicon.ico">
28
- </head>
29
- <body>
30
- <app-root></app-root>
31
- <script type="module" src="/src/main.ts"></script>
32
- </body>
33
- </html>
34
- ```
35
-
36
- ### 2. Create `vite.config.mjs`
37
-
38
- ```js
39
- import { defineConfig } from "vite";
40
- import { angularLinkerRolldownPlugin } from "angular-rust-plugins/linker/rolldown";
41
- import { angularCompilerVitePlugin } from "angular-rust-plugins/compiler/vite";
42
-
43
- export default defineConfig({
44
- plugins: [
45
- // Linker plugin - processes @angular/* packages in node_modules
46
- angularLinkerRolldownPlugin(),
47
- // Compiler plugin - compiles your .ts files with Angular decorators
48
- angularCompilerVitePlugin(),
49
- ],
50
- resolve: {
51
- extensions: [".ts", ".js", ".json"],
52
- },
53
- server: {
54
- port: 4200,
55
- },
56
- optimizeDeps: {
57
- // Exclude Angular packages from pre-bundling so linker plugin can process them
58
- exclude: [
59
- "@angular/core",
60
- "@angular/common",
61
- "@angular/platform-browser",
62
- "@angular/router",
63
- "@angular/forms",
64
- ],
65
- // Still include zone.js and rxjs which don't need linking
66
- include: ["zone.js", "rxjs", "rxjs/operators"],
67
- },
68
- });
69
- ```
70
-
71
- ### 3. Run dev server
72
-
73
- ```bash
74
- npx vite
75
- ```
76
-
77
- ## 📖 Complete Configuration Examples
78
-
79
- ### Full Angular Setup with Vite (Recommended)
80
-
81
- ```js
82
- // vite.config.mjs
83
- import { defineConfig } from "vite";
84
- import { angularLinkerRolldownPlugin } from "angular-rust-plugins/linker/rolldown";
85
- import { angularCompilerVitePlugin } from "angular-rust-plugins/compiler/vite";
86
-
87
- export default defineConfig({
88
- plugins: [
89
- angularLinkerRolldownPlugin({ debug: false }),
90
- angularCompilerVitePlugin({ debug: false }),
91
- ],
92
- resolve: {
93
- extensions: [".ts", ".js", ".json"],
94
- },
95
- server: {
96
- port: 4200,
97
- open: true, // Open browser automatically
98
- },
99
- build: {
100
- target: "esnext",
101
- sourcemap: true,
102
- },
103
- optimizeDeps: {
104
- exclude: [
105
- "@angular/core",
106
- "@angular/common",
107
- "@angular/platform-browser",
108
- "@angular/router",
109
- "@angular/forms",
110
- "@angular/animations",
111
- "@angular/platform-browser-dynamic",
112
- ],
113
- include: ["zone.js", "rxjs", "rxjs/operators"],
114
- },
115
- });
116
- ```
117
-
118
- ### Linker Only (Vite) - For existing Angular projects
119
-
120
- If you only need the linker (for pre-AOT compiled Angular libraries):
121
-
122
- ```js
123
- import { defineConfig } from "vite";
124
- import { angularLinkerVitePlugin } from "angular-rust-plugins/linker/vite";
125
-
126
- export default defineConfig({
127
- plugins: [angularLinkerVitePlugin()],
128
- optimizeDeps: {
129
- exclude: ["@angular/core", "@angular/common", "@angular/platform-browser"],
130
- },
131
- });
132
- ```
133
-
134
- ### Linker with Rolldown (for Vite 6+)
135
-
136
- ```js
137
- import { defineConfig } from "vite";
138
- import { angularLinkerRolldownPlugin } from "angular-rust-plugins/linker/rolldown";
139
-
140
- export default defineConfig({
141
- plugins: [angularLinkerRolldownPlugin()],
142
- optimizeDeps: {
143
- exclude: ["@angular/core", "@angular/common", "@angular/platform-browser"],
144
- },
145
- });
146
- ```
147
-
148
- ### Linker with esbuild
149
-
150
- ```js
151
- import esbuild from "esbuild";
152
- import { angularLinkerEsbuildPlugin } from "angular-rust-plugins/linker/esbuild";
153
-
154
- esbuild.build({
155
- entryPoints: ["src/main.ts"],
156
- bundle: true,
157
- outfile: "dist/bundle.js",
158
- plugins: [angularLinkerEsbuildPlugin()],
159
- });
160
- ```
161
-
162
- ## 📦 Package Exports
163
-
164
- | Export Path | Description |
165
- | -------------------------------------- | ---------------------------------- |
166
- | `angular-rust-plugins` | All plugins |
167
- | **Linker Plugins** | |
168
- | `angular-rust-plugins/linker` | All linker plugins |
169
- | `angular-rust-plugins/linker/vite` | Vite linker plugin (esbuild-based) |
170
- | `angular-rust-plugins/linker/esbuild` | esbuild linker plugin |
171
- | `angular-rust-plugins/linker/rolldown` | Rolldown linker plugin |
172
- | **Compiler Plugins** | |
173
- | `angular-rust-plugins/compiler` | All compiler plugins |
174
- | `angular-rust-plugins/compiler/vite` | Vite compiler plugin |
175
-
176
- ## ⚙️ Options
177
-
178
- ### Linker Options
179
-
180
- ```ts
181
- interface LinkerOptions {
182
- debug?: boolean; // Enable debug logging (default: false)
183
- bindingPath?: string; // Custom path to binding (optional)
184
- }
185
- ```
186
-
187
- ### Compiler Options
188
-
189
- ```ts
190
- interface CompilerOptions {
191
- debug?: boolean; // Enable debug logging (default: false)
192
- bindingPath?: string; // Custom path to binding (optional)
193
- }
194
- ```
195
-
196
- ## 📁 Project Structure
197
-
198
- Your Angular project should have this structure:
199
-
200
- ```
201
- my-angular-app/
202
- ├── index.html # Entry HTML file
203
- ├── vite.config.mjs # Vite configuration
204
- ├── package.json
205
- ├── tsconfig.json
206
- ├── src/
207
- │ ├── main.ts # Bootstrap entry
208
- │ ├── styles.css # Global styles
209
- │ └── app/
210
- │ ├── app.ts # Root component
211
- │ ├── app.html # Root template
212
- │ └── app.config.ts # App configuration
213
- └── public/
214
- └── favicon.ico
215
- ```
216
-
217
- ### Example `src/main.ts`
218
-
219
- ```ts
220
- import { bootstrapApplication } from "@angular/platform-browser";
221
- import { appConfig } from "./app/app.config";
222
- import { App } from "./app/app";
223
-
224
- bootstrapApplication(App, appConfig).catch((err) => console.error(err));
225
- ```
226
-
227
- ### Example `src/app/app.ts`
228
-
229
- ```ts
230
- import { Component } from "@angular/core";
231
-
232
- @Component({
233
- selector: "app-root",
234
- standalone: true,
235
- templateUrl: "./app.html",
236
- styleUrl: "./app.css",
237
- })
238
- export class App {
239
- title = "My Angular App";
240
- }
241
- ```
242
-
243
- ## 🔧 Troubleshooting
244
-
245
- ### Angular packages not being linked
246
-
247
- Make sure Angular packages are excluded from `optimizeDeps`:
248
-
249
- ```js
250
- optimizeDeps: {
251
- exclude: [
252
- "@angular/core",
253
- "@angular/common",
254
- "@angular/platform-browser",
255
- // Add other @angular/* packages you use
256
- ],
257
- }
258
- ```
259
-
260
- ### TypeScript compilation errors
261
-
262
- Ensure your `tsconfig.json` includes:
263
-
264
- ```json
265
- {
266
- "compilerOptions": {
267
- "target": "ES2022",
268
- "module": "ES2022",
269
- "moduleResolution": "bundler",
270
- "experimentalDecorators": true,
271
- "emitDecoratorMetadata": true
272
- }
273
- }
274
- ```
275
-
276
- ### HMR (Hot Module Replacement)
277
-
278
- The compiler plugin includes HMR support for `.html` template files. When you modify a template, the corresponding component will be recompiled automatically.
279
-
280
- ## ⚡ Performance
281
-
282
- **2-5x faster** than TypeScript-based Angular compiler with lower memory usage.
283
-
284
- | Metric | angular-rust-plugins | Angular CLI |
285
- | --------------- | -------------------- | ----------- |
286
- | Initial compile | ~500ms | ~2000ms |
287
- | HMR update | ~50ms | ~200ms |
288
- | Memory usage | ~100MB | ~500MB |
289
-
290
- ## 🔧 Development
291
-
292
- ```bash
293
- # Build with current binding
294
- npm run build
295
-
296
- # Rebuild binding and plugin
297
- npm run build:full
298
- ```
299
-
300
- ## 📝 License
301
-
302
- MIT
303
-
304
- ---
305
-
306
- **Built with ❤️ using Rust**
package/dist/package.json DELETED
@@ -1,77 +0,0 @@
1
- {
2
- "name": "angular-rust-plugins",
3
- "version": "0.2.0",
4
- "description": "Angular plugins for bundlers (Vite, esbuild, Rolldown, Webpack, Rspack) - powered by Rust compiler",
5
- "author": "Truonglv4",
6
- "license": "MIT",
7
- "type": "module",
8
- "main": "./index.cjs",
9
- "module": "./index.js",
10
- "types": "./index.d.ts",
11
- "exports": {
12
- ".": {
13
- "types": "./index.d.ts",
14
- "import": "./index.js",
15
- "require": "./index.cjs"
16
- },
17
- "./linker": {
18
- "types": "./linker/index.d.ts",
19
- "import": "./linker/index.js",
20
- "require": "./linker/index.cjs"
21
- },
22
- "./linker/vite": {
23
- "types": "./linker/vite.d.ts",
24
- "import": "./linker/vite.js",
25
- "require": "./linker/vite.cjs"
26
- },
27
- "./linker/esbuild": {
28
- "types": "./linker/esbuild.d.ts",
29
- "import": "./linker/esbuild.js",
30
- "require": "./linker/esbuild.cjs"
31
- },
32
- "./linker/rolldown": {
33
- "types": "./linker/rolldown.d.ts",
34
- "import": "./linker/rolldown.js",
35
- "require": "./linker/rolldown.cjs"
36
- },
37
- "./compiler": {
38
- "types": "./compiler/index.d.ts",
39
- "import": "./compiler/index.js",
40
- "require": "./compiler/index.cjs"
41
- },
42
- "./compiler/vite": {
43
- "types": "./compiler/vite.d.ts",
44
- "import": "./compiler/vite.js",
45
- "require": "./compiler/vite.cjs"
46
- }
47
- },
48
- "files": [
49
- "binding",
50
- "linker",
51
- "compiler",
52
- "index.js",
53
- "index.cjs",
54
- "index.d.ts",
55
- "index.d.cts",
56
- "*.map",
57
- "types-*.d.ts",
58
- "types-*.d.cts"
59
- ],
60
- "keywords": [
61
- "angular",
62
- "linker",
63
- "compiler",
64
- "vite",
65
- "esbuild",
66
- "rolldown",
67
- "webpack",
68
- "rspack",
69
- "rust",
70
- "aot",
71
- "bundler"
72
- ],
73
- "repository": {
74
- "type": "git",
75
- "url": "https://github.com/truonglvos/angular-rust-compiler/tree/main/packages/linker-plugins"
76
- }
77
- }
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes