@analogjs/vite-plugin-angular 3.0.0-alpha.5 → 3.0.0-alpha.51
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 +30 -0
- package/migrations/migrate-setup-vitest/migrate-setup-vitest.d.ts +2 -0
- package/migrations/migrate-setup-vitest/migrate-setup-vitest.js +49 -0
- package/migrations/migrate-setup-vitest/migrate-setup-vitest.js.map +1 -0
- package/migrations/migration.json +7 -1
- package/migrations/migrations.json +9 -0
- package/migrations/update-3-0-0/migrate-setup-vitest.d.ts +2 -0
- package/migrations/update-3-0-0/migrate-setup-vitest.js +36 -0
- package/migrations/update-3-0-0/migrate-setup-vitest.js.map +1 -0
- package/package.json +41 -12
- package/src/index.d.ts +3 -2
- package/src/index.js +6 -2
- package/src/index.js.map +1 -1
- package/src/lib/angular-build-optimizer-plugin.d.ts +4 -4
- package/src/lib/angular-build-optimizer-plugin.js +48 -62
- package/src/lib/angular-build-optimizer-plugin.js.map +1 -1
- package/src/lib/angular-jit-plugin.d.ts +3 -3
- package/src/lib/angular-jit-plugin.js +39 -37
- package/src/lib/angular-jit-plugin.js.map +1 -1
- package/src/lib/angular-pending-tasks.plugin.d.ts +7 -7
- package/src/lib/angular-pending-tasks.plugin.js +17 -18
- package/src/lib/angular-pending-tasks.plugin.js.map +1 -1
- package/src/lib/angular-vite-plugin.d.ts +180 -44
- package/src/lib/angular-vite-plugin.js +1233 -969
- package/src/lib/angular-vite-plugin.js.map +1 -1
- package/src/lib/angular-vitest-plugin.d.ts +19 -15
- package/src/lib/angular-vitest-plugin.js +99 -114
- package/src/lib/angular-vitest-plugin.js.map +1 -1
- package/src/lib/compilation-api/compilation-api-plugin.d.ts +29 -0
- package/src/lib/compilation-api/compilation-api-plugin.js +480 -0
- package/src/lib/compilation-api/compilation-api-plugin.js.map +1 -0
- package/src/lib/compilation-api/index.d.ts +1 -0
- package/src/lib/compilation-api/index.js +1 -0
- package/src/lib/compiler/angular-version.d.ts +19 -0
- package/src/lib/compiler/angular-version.js +16 -0
- package/src/lib/compiler/angular-version.js.map +1 -0
- package/src/lib/compiler/class-field-lowering.d.ts +23 -0
- package/src/lib/compiler/class-field-lowering.js +131 -0
- package/src/lib/compiler/class-field-lowering.js.map +1 -0
- package/src/lib/compiler/compile.d.ts +44 -0
- package/src/lib/compiler/compile.js +731 -0
- package/src/lib/compiler/compile.js.map +1 -0
- package/src/lib/compiler/constants.d.ts +18 -0
- package/src/lib/compiler/constants.js +52 -0
- package/src/lib/compiler/constants.js.map +1 -0
- package/src/lib/compiler/debug.d.ts +22 -0
- package/src/lib/compiler/debug.js +20 -0
- package/src/lib/compiler/debug.js.map +1 -0
- package/src/lib/compiler/defer.d.ts +57 -0
- package/src/lib/compiler/defer.js +154 -0
- package/src/lib/compiler/defer.js.map +1 -0
- package/src/lib/compiler/dts-reader.d.ts +35 -0
- package/src/lib/compiler/dts-reader.js +365 -0
- package/src/lib/compiler/dts-reader.js.map +1 -0
- package/src/lib/compiler/hmr.d.ts +16 -0
- package/src/lib/compiler/hmr.js +69 -0
- package/src/lib/compiler/hmr.js.map +1 -0
- package/src/lib/compiler/index.d.ts +7 -0
- package/src/lib/compiler/index.js +7 -0
- package/src/lib/compiler/jit-metadata.d.ts +14 -0
- package/src/lib/compiler/jit-metadata.js +146 -0
- package/src/lib/compiler/jit-metadata.js.map +1 -0
- package/src/lib/compiler/jit-transform.d.ts +24 -0
- package/src/lib/compiler/jit-transform.js +200 -0
- package/src/lib/compiler/jit-transform.js.map +1 -0
- package/src/lib/compiler/js-emitter.d.ts +10 -0
- package/src/lib/compiler/js-emitter.js +445 -0
- package/src/lib/compiler/js-emitter.js.map +1 -0
- package/src/lib/compiler/metadata.d.ts +45 -0
- package/src/lib/compiler/metadata.js +633 -0
- package/src/lib/compiler/metadata.js.map +1 -0
- package/src/lib/compiler/registry.d.ts +49 -0
- package/src/lib/compiler/registry.js +164 -0
- package/src/lib/compiler/registry.js.map +1 -0
- package/src/lib/compiler/resource-inliner.d.ts +21 -0
- package/src/lib/compiler/resource-inliner.js +152 -0
- package/src/lib/compiler/resource-inliner.js.map +1 -0
- package/src/lib/compiler/style-ast.d.ts +8 -0
- package/src/lib/compiler/style-ast.js +54 -0
- package/src/lib/compiler/style-ast.js.map +1 -0
- package/src/lib/compiler/styles.d.ts +13 -0
- package/src/lib/compiler/test-helpers.d.ts +7 -0
- package/src/lib/compiler/type-elision.d.ts +26 -0
- package/src/lib/compiler/type-elision.js +211 -0
- package/src/lib/compiler/type-elision.js.map +1 -0
- package/src/lib/compiler/utils.d.ts +10 -0
- package/src/lib/compiler/utils.js +35 -0
- package/src/lib/compiler/utils.js.map +1 -0
- package/src/lib/compiler-plugin.d.ts +11 -11
- package/src/lib/compiler-plugin.js +43 -44
- package/src/lib/compiler-plugin.js.map +1 -1
- package/src/lib/component-resolvers.d.ts +23 -5
- package/src/lib/component-resolvers.js +153 -63
- package/src/lib/component-resolvers.js.map +1 -1
- package/src/lib/encapsulation-plugin.d.ts +13 -0
- package/src/lib/encapsulation-plugin.js +48 -0
- package/src/lib/encapsulation-plugin.js.map +1 -0
- package/src/lib/fast-compile-plugin.d.ts +28 -0
- package/src/lib/fast-compile-plugin.js +289 -0
- package/src/lib/fast-compile-plugin.js.map +1 -0
- package/src/lib/host.d.ts +10 -8
- package/src/lib/host.js +113 -101
- package/src/lib/host.js.map +1 -1
- package/src/lib/live-reload-plugin.d.ts +5 -5
- package/src/lib/live-reload-plugin.js +61 -62
- package/src/lib/live-reload-plugin.js.map +1 -1
- package/src/lib/models.d.ts +9 -9
- package/src/lib/nx-folder-plugin.d.ts +5 -5
- package/src/lib/nx-folder-plugin.js +18 -16
- package/src/lib/nx-folder-plugin.js.map +1 -1
- package/src/lib/plugins/file-replacements.plugin.d.ts +4 -4
- package/src/lib/plugins/file-replacements.plugin.js +40 -62
- package/src/lib/plugins/file-replacements.plugin.js.map +1 -1
- package/src/lib/router-plugin.d.ts +1 -1
- package/src/lib/router-plugin.js +23 -23
- package/src/lib/router-plugin.js.map +1 -1
- package/src/lib/style-pipeline.d.ts +15 -0
- package/src/lib/style-pipeline.js +31 -0
- package/src/lib/style-pipeline.js.map +1 -0
- package/src/lib/style-preprocessor.d.ts +35 -0
- package/src/lib/style-preprocessor.js +35 -0
- package/src/lib/style-preprocessor.js.map +1 -0
- package/src/lib/stylesheet-registry.d.ts +73 -0
- package/src/lib/stylesheet-registry.js +168 -0
- package/src/lib/stylesheet-registry.js.map +1 -0
- package/src/lib/tailwind-plugin.d.ts +34 -0
- package/src/lib/tailwind-plugin.js +116 -0
- package/src/lib/tailwind-plugin.js.map +1 -0
- package/src/lib/template-class-binding-guard-plugin.d.ts +30 -0
- package/src/lib/template-class-binding-guard-plugin.js +237 -0
- package/src/lib/template-class-binding-guard-plugin.js.map +1 -0
- package/src/lib/tools/package.json +2 -7
- package/src/lib/tools/src/builders/vite/vite-build.impl.js +31 -38
- package/src/lib/tools/src/builders/vite/vite-build.impl.js.map +1 -1
- package/src/lib/tools/src/builders/vite-dev-server/dev-server.impl.js +51 -62
- package/src/lib/tools/src/builders/vite-dev-server/dev-server.impl.js.map +1 -1
- package/src/lib/tools/src/index.js +0 -2
- package/src/lib/utils/compilation-shared.d.ts +58 -0
- package/src/lib/utils/compilation-shared.js +133 -0
- package/src/lib/utils/compilation-shared.js.map +1 -0
- package/src/lib/utils/compiler-plugin-options.d.ts +11 -11
- package/src/lib/utils/debug-harness.d.ts +23 -0
- package/src/lib/utils/debug-harness.js +88 -0
- package/src/lib/utils/debug-harness.js.map +1 -0
- package/src/lib/utils/debug-log-file.d.ts +5 -0
- package/src/lib/utils/debug-log-file.js +56 -0
- package/src/lib/utils/debug-log-file.js.map +1 -0
- package/src/lib/utils/debug.d.ts +28 -0
- package/src/lib/utils/debug.js +39 -0
- package/src/lib/utils/debug.js.map +1 -0
- package/src/lib/utils/devkit.d.ts +6 -6
- package/src/lib/utils/devkit.js +34 -38
- package/src/lib/utils/devkit.js.map +1 -1
- package/src/lib/utils/hmr-candidates.d.ts +28 -28
- package/src/lib/utils/plugin-config.d.ts +37 -0
- package/src/lib/utils/plugin-config.js +71 -0
- package/src/lib/utils/plugin-config.js.map +1 -0
- package/src/lib/utils/rolldown.d.ts +2 -0
- package/src/lib/utils/rolldown.js +12 -0
- package/src/lib/utils/rolldown.js.map +1 -0
- package/src/lib/utils/safe-module-paths.d.ts +16 -0
- package/src/lib/utils/safe-module-paths.js +29 -0
- package/src/lib/utils/safe-module-paths.js.map +1 -0
- package/src/lib/utils/source-file-cache.d.ts +8 -15
- package/src/lib/utils/source-file-cache.js +35 -37
- package/src/lib/utils/source-file-cache.js.map +1 -1
- package/src/lib/utils/tailwind-reference.d.ts +12 -0
- package/src/lib/utils/tailwind-reference.js +99 -0
- package/src/lib/utils/tailwind-reference.js.map +1 -0
- package/src/lib/utils/tsconfig-resolver.d.ts +28 -0
- package/src/lib/utils/tsconfig-resolver.js +191 -0
- package/src/lib/utils/tsconfig-resolver.js.map +1 -0
- package/src/lib/utils/virtual-ids.d.ts +4 -0
- package/src/lib/utils/virtual-ids.js +23 -0
- package/src/lib/utils/virtual-ids.js.map +1 -0
- package/src/lib/utils/virtual-resources.d.ts +19 -0
- package/src/lib/utils/virtual-resources.js +38 -0
- package/src/lib/utils/virtual-resources.js.map +1 -0
- package/src/lib/virtual-modules-plugin.d.ts +5 -0
- package/src/lib/virtual-modules-plugin.js +23 -0
- package/src/lib/virtual-modules-plugin.js.map +1 -0
- package/src/test-setup.d.ts +2 -0
- package/setup-vitest.d.ts +0 -4
- package/setup-vitest.js +0 -215
- package/setup-vitest.js.map +0 -1
- package/src/lib/models.js +0 -1
- package/src/lib/models.js.map +0 -1
- package/src/lib/tools/README.md +0 -3
- package/src/lib/tools/src/index.d.ts +0 -0
- package/src/lib/tools/src/index.js.map +0 -1
- package/src/lib/utils/compiler-plugin-options.js +0 -1
- package/src/lib/utils/compiler-plugin-options.js.map +0 -1
- package/src/lib/utils/hmr-candidates.js +0 -272
- package/src/lib/utils/hmr-candidates.js.map +0 -1
|
@@ -1,982 +1,1246 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import
|
|
4
|
-
import
|
|
5
|
-
import {
|
|
6
|
-
import
|
|
7
|
-
import {
|
|
8
|
-
import {
|
|
9
|
-
import {
|
|
10
|
-
import {
|
|
11
|
-
import {
|
|
12
|
-
import {
|
|
13
|
-
import {
|
|
14
|
-
import {
|
|
15
|
-
import {
|
|
16
|
-
|
|
17
|
-
import
|
|
18
|
-
import {
|
|
19
|
-
import {
|
|
20
|
-
import {
|
|
21
|
-
import {
|
|
22
|
-
import {
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
*
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
|
|
726
|
-
|
|
727
|
-
|
|
728
|
-
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
|
|
738
|
-
|
|
739
|
-
|
|
740
|
-
|
|
741
|
-
|
|
742
|
-
|
|
743
|
-
|
|
744
|
-
|
|
745
|
-
|
|
746
|
-
|
|
747
|
-
|
|
748
|
-
|
|
749
|
-
|
|
750
|
-
|
|
751
|
-
|
|
752
|
-
|
|
753
|
-
|
|
754
|
-
|
|
755
|
-
|
|
756
|
-
|
|
757
|
-
|
|
758
|
-
|
|
759
|
-
|
|
760
|
-
|
|
761
|
-
|
|
762
|
-
|
|
763
|
-
|
|
764
|
-
|
|
765
|
-
|
|
766
|
-
|
|
767
|
-
|
|
768
|
-
|
|
769
|
-
|
|
770
|
-
|
|
771
|
-
|
|
772
|
-
|
|
773
|
-
|
|
774
|
-
|
|
775
|
-
|
|
776
|
-
|
|
777
|
-
|
|
778
|
-
|
|
779
|
-
|
|
780
|
-
|
|
781
|
-
|
|
782
|
-
|
|
783
|
-
|
|
784
|
-
|
|
785
|
-
|
|
786
|
-
|
|
787
|
-
|
|
788
|
-
|
|
789
|
-
|
|
790
|
-
|
|
791
|
-
|
|
792
|
-
|
|
793
|
-
|
|
794
|
-
|
|
795
|
-
|
|
796
|
-
|
|
797
|
-
|
|
798
|
-
|
|
799
|
-
|
|
800
|
-
|
|
801
|
-
|
|
802
|
-
|
|
803
|
-
|
|
804
|
-
|
|
805
|
-
|
|
806
|
-
|
|
807
|
-
|
|
808
|
-
|
|
809
|
-
|
|
810
|
-
|
|
811
|
-
|
|
812
|
-
|
|
813
|
-
|
|
814
|
-
|
|
815
|
-
|
|
816
|
-
|
|
817
|
-
|
|
818
|
-
|
|
819
|
-
|
|
820
|
-
|
|
821
|
-
|
|
822
|
-
|
|
823
|
-
|
|
824
|
-
|
|
825
|
-
|
|
826
|
-
|
|
827
|
-
|
|
828
|
-
|
|
829
|
-
|
|
830
|
-
|
|
831
|
-
|
|
832
|
-
|
|
833
|
-
|
|
834
|
-
|
|
835
|
-
|
|
836
|
-
|
|
837
|
-
|
|
838
|
-
|
|
839
|
-
|
|
840
|
-
|
|
841
|
-
|
|
842
|
-
|
|
843
|
-
|
|
844
|
-
|
|
845
|
-
|
|
846
|
-
|
|
847
|
-
|
|
848
|
-
|
|
849
|
-
|
|
850
|
-
|
|
851
|
-
|
|
852
|
-
|
|
853
|
-
|
|
854
|
-
|
|
855
|
-
|
|
856
|
-
|
|
857
|
-
|
|
858
|
-
|
|
859
|
-
|
|
860
|
-
|
|
861
|
-
|
|
862
|
-
|
|
863
|
-
|
|
1
|
+
import { angularFullVersion, cjt, sourceFileCache } from "./utils/devkit.js";
|
|
2
|
+
import { getJsTransformConfigKey, isRolldown } from "./utils/rolldown.js";
|
|
3
|
+
import { buildOptimizerPlugin } from "./angular-build-optimizer-plugin.js";
|
|
4
|
+
import { activateDeferredDebug, applyDebugOption, debugCompiler, debugCompilerV, debugEmit, debugEmitV, debugHmr, debugHmrV, debugStyles, debugStylesV } from "./utils/debug.js";
|
|
5
|
+
import { jitPlugin } from "./angular-jit-plugin.js";
|
|
6
|
+
import { createCompilerPlugin, createRolldownCompilerPlugin } from "./compiler-plugin.js";
|
|
7
|
+
import { StyleUrlsResolver, TemplateUrlsResolver, getAngularComponentMetadata } from "./component-resolvers.js";
|
|
8
|
+
import { AnalogStylesheetRegistry, preprocessStylesheet, rewriteRelativeCssImports } from "./stylesheet-registry.js";
|
|
9
|
+
import { augmentHostWithCaching, augmentHostWithResources, augmentProgramWithVersioning, mergeTransformers } from "./host.js";
|
|
10
|
+
import { TS_EXT_REGEX, createTsConfigGetter, getTsConfigPath } from "./utils/plugin-config.js";
|
|
11
|
+
import { TsconfigResolver } from "./utils/tsconfig-resolver.js";
|
|
12
|
+
import { configureStylePipelineRegistry } from "./style-pipeline.js";
|
|
13
|
+
import { describeStylesheetContent, injectViteIgnoreForHmrMetadata, isIgnoredHmrFile, isTestWatchMode } from "./utils/compilation-shared.js";
|
|
14
|
+
import { toVirtualRawId } from "./utils/virtual-ids.js";
|
|
15
|
+
import { loadVirtualRawModule, rewriteHtmlRawImport } from "./utils/virtual-resources.js";
|
|
16
|
+
import { compilationAPIPlugin } from "./compilation-api/compilation-api-plugin.js";
|
|
17
|
+
import "./compilation-api/index.js";
|
|
18
|
+
import { markStylePathSafe } from "./utils/safe-module-paths.js";
|
|
19
|
+
import { fastCompilePlugin } from "./fast-compile-plugin.js";
|
|
20
|
+
import { removeActiveGraphMetadata, removeStyleOwnerMetadata, templateClassBindingGuardPlugin } from "./template-class-binding-guard-plugin.js";
|
|
21
|
+
import { buildStylePreprocessor, tailwindReferencePlugin, validateTailwindConfig } from "./tailwind-plugin.js";
|
|
22
|
+
import { encapsulationPlugin, getComponentStyleSheetMeta, isComponentStyleSheet } from "./encapsulation-plugin.js";
|
|
23
|
+
import { virtualModulesPlugin } from "./virtual-modules-plugin.js";
|
|
24
|
+
import { angularVitestPlugins } from "./angular-vitest-plugin.js";
|
|
25
|
+
import { pendingTasksPlugin } from "./angular-pending-tasks.plugin.js";
|
|
26
|
+
import { liveReloadPlugin } from "./live-reload-plugin.js";
|
|
27
|
+
import { nxFolderPlugin } from "./nx-folder-plugin.js";
|
|
28
|
+
import { replaceFiles } from "./plugins/file-replacements.plugin.js";
|
|
29
|
+
import { routerPlugin } from "./router-plugin.js";
|
|
30
|
+
import { union } from "es-toolkit";
|
|
31
|
+
import { existsSync, mkdirSync, readFileSync, writeFileSync } from "node:fs";
|
|
32
|
+
import { basename, dirname, isAbsolute, join, relative, resolve } from "node:path";
|
|
33
|
+
import * as compilerCli from "@angular/compiler-cli";
|
|
34
|
+
import { createRequire } from "node:module";
|
|
35
|
+
import { defaultClientConditions, normalizePath, preprocessCSS } from "vite";
|
|
36
|
+
//#region packages/vite-plugin-angular/src/lib/angular-vite-plugin.ts
|
|
37
|
+
var require = createRequire(import.meta.url);
|
|
38
|
+
var classNames = /* @__PURE__ */ new Map();
|
|
39
|
+
function evictDeletedFileMetadata(file, { removeActiveGraphMetadata, removeStyleOwnerMetadata, classNamesMap, fileTransformMap }) {
|
|
40
|
+
const normalizedFile = normalizePath(file.split("?")[0]);
|
|
41
|
+
removeActiveGraphMetadata(normalizedFile);
|
|
42
|
+
removeStyleOwnerMetadata(normalizedFile);
|
|
43
|
+
classNamesMap.delete(normalizedFile);
|
|
44
|
+
fileTransformMap.delete(normalizedFile);
|
|
45
|
+
}
|
|
46
|
+
function angular(options) {
|
|
47
|
+
applyDebugOption(options?.debug, options?.workspaceRoot);
|
|
48
|
+
const liveReload = options?.liveReload ?? true;
|
|
49
|
+
/**
|
|
50
|
+
* Normalize plugin options so defaults
|
|
51
|
+
* are used for values not provided.
|
|
52
|
+
*/
|
|
53
|
+
const pluginOptions = {
|
|
54
|
+
tsconfigGetter: createTsConfigGetter(options?.tsconfig),
|
|
55
|
+
workspaceRoot: options?.workspaceRoot ?? process.cwd(),
|
|
56
|
+
inlineStylesExtension: options?.inlineStylesExtension ?? "css",
|
|
57
|
+
advanced: { tsTransformers: {
|
|
58
|
+
before: options?.advanced?.tsTransformers?.before ?? [],
|
|
59
|
+
after: options?.advanced?.tsTransformers?.after ?? [],
|
|
60
|
+
afterDeclarations: options?.advanced?.tsTransformers?.afterDeclarations ?? []
|
|
61
|
+
} },
|
|
62
|
+
supportedBrowsers: options?.supportedBrowsers ?? ["safari 15"],
|
|
63
|
+
jit: options?.jit,
|
|
64
|
+
include: options?.include ?? [],
|
|
65
|
+
additionalContentDirs: options?.additionalContentDirs ?? [],
|
|
66
|
+
liveReload,
|
|
67
|
+
disableTypeChecking: options?.disableTypeChecking ?? true,
|
|
68
|
+
fileReplacements: options?.fileReplacements ?? [],
|
|
69
|
+
useAngularCompilationAPI: options?.experimental?.useAngularCompilationAPI ?? false,
|
|
70
|
+
fastCompile: options?.fastCompile ?? false,
|
|
71
|
+
fastCompileMode: options?.fastCompileMode ?? "full",
|
|
72
|
+
hasTailwindCss: !!options?.tailwindCss,
|
|
73
|
+
tailwindCss: options?.tailwindCss,
|
|
74
|
+
stylePreprocessor: buildStylePreprocessor(options)
|
|
75
|
+
};
|
|
76
|
+
let resolvedConfig;
|
|
77
|
+
let tsConfigResolutionContext = null;
|
|
78
|
+
const ts = require("typescript");
|
|
79
|
+
let builder;
|
|
80
|
+
let nextProgram;
|
|
81
|
+
let cachedHost;
|
|
82
|
+
let cachedHostKey;
|
|
83
|
+
const isTest = process.env.NODE_ENV === "test" || !!process.env["VITEST"];
|
|
84
|
+
const tsconfigResolver = new TsconfigResolver({
|
|
85
|
+
workspaceRoot: pluginOptions.workspaceRoot,
|
|
86
|
+
include: pluginOptions.include,
|
|
87
|
+
liveReload: pluginOptions.liveReload,
|
|
88
|
+
hasTailwindCss: pluginOptions.hasTailwindCss,
|
|
89
|
+
isTest
|
|
90
|
+
});
|
|
91
|
+
function invalidateFsCaches() {
|
|
92
|
+
tsconfigResolver.invalidateIncludeCache();
|
|
93
|
+
}
|
|
94
|
+
function invalidateTsconfigCaches() {
|
|
95
|
+
tsconfigResolver.invalidateTsconfigCaches();
|
|
96
|
+
cachedHost = void 0;
|
|
97
|
+
cachedHostKey = void 0;
|
|
98
|
+
}
|
|
99
|
+
let watchMode = false;
|
|
100
|
+
let testWatchMode = isTestWatchMode();
|
|
101
|
+
const activeGraphComponentMetadata = /* @__PURE__ */ new Map();
|
|
102
|
+
const selectorOwners = /* @__PURE__ */ new Map();
|
|
103
|
+
const classNameOwners = /* @__PURE__ */ new Map();
|
|
104
|
+
const transformedStyleOwnerMetadata = /* @__PURE__ */ new Map();
|
|
105
|
+
const styleSourceOwners = /* @__PURE__ */ new Map();
|
|
106
|
+
function hasViteHmrTransport() {
|
|
107
|
+
return resolvedConfig ? resolvedConfig.server.hmr !== false : true;
|
|
108
|
+
}
|
|
109
|
+
function shouldEnableLiveReload() {
|
|
110
|
+
return !!((isTest ? testWatchMode : watchMode) && pluginOptions.liveReload && hasViteHmrTransport());
|
|
111
|
+
}
|
|
112
|
+
/**
|
|
113
|
+
* Determines whether Angular should externalize component styles.
|
|
114
|
+
*
|
|
115
|
+
* When true, Angular emits style references (hash-based IDs) instead of
|
|
116
|
+
* inlining CSS strings. Vite's resolveId → load → transform pipeline
|
|
117
|
+
* then serves these virtual modules, allowing @tailwindcss/vite to
|
|
118
|
+
* process @reference directives.
|
|
119
|
+
*
|
|
120
|
+
* Required for TWO independent use-cases:
|
|
121
|
+
* 1. HMR — Vite needs external modules for hot replacement
|
|
122
|
+
* 2. Tailwind CSS (hasTailwindCss) — styles must pass through Vite's
|
|
123
|
+
* CSS pipeline so @tailwindcss/vite can resolve @apply directives
|
|
124
|
+
*
|
|
125
|
+
* In production builds (!watchMode), styles are NOT externalized — they
|
|
126
|
+
* are inlined after preprocessCSS runs eagerly in transformStylesheet.
|
|
127
|
+
*/
|
|
128
|
+
function shouldExternalizeStyles() {
|
|
129
|
+
if (!(isTest ? testWatchMode : watchMode)) return false;
|
|
130
|
+
return !!(shouldEnableLiveReload() || pluginOptions.hasTailwindCss);
|
|
131
|
+
}
|
|
132
|
+
function validateNoDuplicateAnalogPlugins(config) {
|
|
133
|
+
const analogInstances = (config.plugins ?? []).filter((p) => p.name === "@analogjs/vite-plugin-angular");
|
|
134
|
+
if (analogInstances.length > 1 && !config.build?.ssr) throw new Error(`[@analogjs/vite-plugin-angular] analog() is registered ${analogInstances.length} times. Each instance creates separate style maps, causing component styles to be lost. Remove duplicate registrations.`);
|
|
135
|
+
}
|
|
136
|
+
let stylesheetRegistry;
|
|
137
|
+
const sourceFileCache$1 = new sourceFileCache();
|
|
138
|
+
const isVitestVscode = !!process.env["VITEST_VSCODE"];
|
|
139
|
+
const isStackBlitz = !!process.versions["webcontainer"];
|
|
140
|
+
const isAstroIntegration = process.env["ANALOG_ASTRO"] === "true";
|
|
141
|
+
const jit = typeof pluginOptions?.jit !== "undefined" ? pluginOptions.jit : isTest;
|
|
142
|
+
let viteServer;
|
|
143
|
+
const styleUrlsResolver = new StyleUrlsResolver();
|
|
144
|
+
const guardContext = {
|
|
145
|
+
styleUrlsResolver,
|
|
146
|
+
activeGraphComponentMetadata,
|
|
147
|
+
selectorOwners,
|
|
148
|
+
classNameOwners,
|
|
149
|
+
transformedStyleOwnerMetadata,
|
|
150
|
+
styleSourceOwners
|
|
151
|
+
};
|
|
152
|
+
const templateUrlsResolver = new TemplateUrlsResolver();
|
|
153
|
+
let outputFile;
|
|
154
|
+
const outputFiles = /* @__PURE__ */ new Map();
|
|
155
|
+
const normalizeEmitterLookupId = (file) => {
|
|
156
|
+
const normalizedFile = normalizePath(file);
|
|
157
|
+
if (!normalizedFile.startsWith("/@fs/")) return normalizedFile;
|
|
158
|
+
return normalizePath(normalizedFile.slice(4).replace(/^\/([A-Za-z]:\/)/, "$1"));
|
|
159
|
+
};
|
|
160
|
+
const describeEmitMarkers = (content) => ({
|
|
161
|
+
contentLength: content.length,
|
|
162
|
+
hasCmp: content.includes("ɵcmp"),
|
|
163
|
+
hasFac: content.includes("ɵfac"),
|
|
164
|
+
hasProv: content.includes("ɵprov"),
|
|
165
|
+
hasDecorate: content.includes("__decorate"),
|
|
166
|
+
hasMetadata: content.includes("__metadata")
|
|
167
|
+
});
|
|
168
|
+
const fileEmitter = (file) => {
|
|
169
|
+
const normalizedFile = normalizeEmitterLookupId(file);
|
|
170
|
+
const hadCachedEmit = outputFiles.has(normalizedFile);
|
|
171
|
+
outputFile?.(normalizedFile);
|
|
172
|
+
const emittedResult = outputFiles.get(normalizedFile);
|
|
173
|
+
debugEmitV("fileEmitter lookup", {
|
|
174
|
+
requestFile: file,
|
|
175
|
+
normalizedFile,
|
|
176
|
+
hadCachedEmit,
|
|
177
|
+
hasOutputFileHook: !!outputFile,
|
|
178
|
+
emitted: !!emittedResult,
|
|
179
|
+
knownOutputCount: outputFiles.size,
|
|
180
|
+
contentLength: emittedResult?.content?.length ?? 0,
|
|
181
|
+
errorCount: emittedResult?.errors?.length ?? 0,
|
|
182
|
+
warningCount: emittedResult?.warnings?.length ?? 0
|
|
183
|
+
});
|
|
184
|
+
return emittedResult;
|
|
185
|
+
};
|
|
186
|
+
let initialCompilation = false;
|
|
187
|
+
const declarationFiles = [];
|
|
188
|
+
const fileTransformMap = /* @__PURE__ */ new Map();
|
|
189
|
+
let styleTransform;
|
|
190
|
+
let pendingCompilation;
|
|
191
|
+
let compilationLock = Promise.resolve();
|
|
192
|
+
function angularPlugin() {
|
|
193
|
+
let isProd = false;
|
|
194
|
+
if (angularFullVersion < 19e4 && pluginOptions.liveReload) {
|
|
195
|
+
debugHmr("hmr disabled: Angular version does not support HMR APIs", {
|
|
196
|
+
angularVersion: angularFullVersion,
|
|
197
|
+
isTest
|
|
198
|
+
});
|
|
199
|
+
console.warn("[@analogjs/vite-plugin-angular]: HMR was disabled because Angular v19+ is required for externalRuntimeStyles/_enableHmr support. Detected Angular version: %s.", angularFullVersion);
|
|
200
|
+
pluginOptions.liveReload = false;
|
|
201
|
+
}
|
|
202
|
+
if (isTest) {
|
|
203
|
+
pluginOptions.liveReload = false;
|
|
204
|
+
debugHmr("hmr disabled", {
|
|
205
|
+
angularVersion: angularFullVersion,
|
|
206
|
+
isTest
|
|
207
|
+
});
|
|
208
|
+
}
|
|
209
|
+
return {
|
|
210
|
+
name: "@analogjs/vite-plugin-angular",
|
|
211
|
+
async config(config, { command }) {
|
|
212
|
+
activateDeferredDebug(command);
|
|
213
|
+
watchMode = command === "serve";
|
|
214
|
+
isProd = config.mode === "production" || process.env.NODE_ENV === "production";
|
|
215
|
+
tsConfigResolutionContext = {
|
|
216
|
+
root: config.root || ".",
|
|
217
|
+
isProd,
|
|
218
|
+
isLib: !!config?.build?.lib
|
|
219
|
+
};
|
|
220
|
+
const preliminaryTsConfigPath = resolveTsConfigPath();
|
|
221
|
+
const esbuild = config.esbuild ?? false;
|
|
222
|
+
const oxc = config.oxc ?? false;
|
|
223
|
+
const defineOptions = {
|
|
224
|
+
ngJitMode: "false",
|
|
225
|
+
ngI18nClosureMode: "false",
|
|
226
|
+
...watchMode ? {} : { ngDevMode: "false" }
|
|
227
|
+
};
|
|
228
|
+
const useRolldown = isRolldown();
|
|
229
|
+
const jsTransformConfigKey = getJsTransformConfigKey();
|
|
230
|
+
const jsTransformConfigValue = jsTransformConfigKey === "oxc" ? oxc : esbuild;
|
|
231
|
+
const rolldownOptions = { plugins: [createRolldownCompilerPlugin({
|
|
232
|
+
tsconfig: preliminaryTsConfigPath,
|
|
233
|
+
sourcemap: !isProd,
|
|
234
|
+
advancedOptimizations: isProd,
|
|
235
|
+
jit,
|
|
236
|
+
incremental: watchMode
|
|
237
|
+
}, !isAstroIntegration)] };
|
|
238
|
+
const esbuildOptions = {
|
|
239
|
+
plugins: [createCompilerPlugin({
|
|
240
|
+
tsconfig: preliminaryTsConfigPath,
|
|
241
|
+
sourcemap: !isProd,
|
|
242
|
+
advancedOptimizations: isProd,
|
|
243
|
+
jit,
|
|
244
|
+
incremental: watchMode
|
|
245
|
+
}, isTest, !isAstroIntegration)],
|
|
246
|
+
define: defineOptions
|
|
247
|
+
};
|
|
248
|
+
return {
|
|
249
|
+
[jsTransformConfigKey]: jsTransformConfigValue,
|
|
250
|
+
optimizeDeps: {
|
|
251
|
+
include: [
|
|
252
|
+
"rxjs/operators",
|
|
253
|
+
"rxjs",
|
|
254
|
+
"tslib"
|
|
255
|
+
],
|
|
256
|
+
exclude: ["@angular/platform-server"],
|
|
257
|
+
...useRolldown ? { rolldownOptions } : { esbuildOptions }
|
|
258
|
+
},
|
|
259
|
+
resolve: { conditions: ["style", ...config.resolve?.conditions || defaultClientConditions] }
|
|
260
|
+
};
|
|
261
|
+
},
|
|
262
|
+
configResolved(config) {
|
|
263
|
+
resolvedConfig = config;
|
|
264
|
+
if (config.logger?.warnOnce) {
|
|
265
|
+
const originalWarnOnce = config.logger.warnOnce;
|
|
266
|
+
config.logger.warnOnce = (msg, options) => {
|
|
267
|
+
if (typeof msg === "string" && msg.includes("Sourcemap") && msg.includes("node_modules")) return;
|
|
268
|
+
originalWarnOnce(msg, options);
|
|
269
|
+
};
|
|
270
|
+
}
|
|
271
|
+
if (pluginOptions.hasTailwindCss) {
|
|
272
|
+
validateTailwindConfig(pluginOptions.tailwindCss, config, watchMode);
|
|
273
|
+
validateNoDuplicateAnalogPlugins(config);
|
|
274
|
+
}
|
|
275
|
+
if (!jit) styleTransform = (code, filename) => preprocessCSS(code, filename, config);
|
|
276
|
+
if (isTest) testWatchMode = !(config.server.watch === null) || config.test?.watch === true || testWatchMode;
|
|
277
|
+
},
|
|
278
|
+
configureServer(server) {
|
|
279
|
+
viteServer = server;
|
|
280
|
+
const invalidateCompilationOnFsChange = createFsWatcherCacheInvalidator(invalidateFsCaches, invalidateTsconfigCaches, () => performCompilation(resolvedConfig));
|
|
281
|
+
server.watcher.on("add", invalidateCompilationOnFsChange);
|
|
282
|
+
server.watcher.on("unlink", (file) => {
|
|
283
|
+
evictDeletedFileMetadata(file, {
|
|
284
|
+
removeActiveGraphMetadata: (f) => removeActiveGraphMetadata(guardContext, f),
|
|
285
|
+
removeStyleOwnerMetadata: (f) => removeStyleOwnerMetadata(guardContext, f),
|
|
286
|
+
classNamesMap: classNames,
|
|
287
|
+
fileTransformMap
|
|
288
|
+
});
|
|
289
|
+
return invalidateCompilationOnFsChange();
|
|
290
|
+
});
|
|
291
|
+
server.watcher.on("change", (file) => {
|
|
292
|
+
if (file.includes("tsconfig")) invalidateTsconfigCaches();
|
|
293
|
+
});
|
|
294
|
+
},
|
|
295
|
+
async buildStart() {
|
|
296
|
+
if (!isVitestVscode) {
|
|
297
|
+
await performCompilation(resolvedConfig);
|
|
298
|
+
pendingCompilation = null;
|
|
299
|
+
initialCompilation = true;
|
|
300
|
+
}
|
|
301
|
+
},
|
|
302
|
+
async handleHotUpdate(ctx) {
|
|
303
|
+
if (isIgnoredHmrFile(ctx.file)) {
|
|
304
|
+
debugHmr("ignored file change", { file: ctx.file });
|
|
305
|
+
return [];
|
|
306
|
+
}
|
|
307
|
+
if (TS_EXT_REGEX.test(ctx.file)) {
|
|
308
|
+
const [fileId] = ctx.file.split("?");
|
|
309
|
+
debugHmr("TS file changed", {
|
|
310
|
+
file: ctx.file,
|
|
311
|
+
fileId
|
|
312
|
+
});
|
|
313
|
+
pendingCompilation = performCompilation(resolvedConfig, [fileId]);
|
|
314
|
+
let result;
|
|
315
|
+
if (shouldEnableLiveReload()) {
|
|
316
|
+
await pendingCompilation;
|
|
317
|
+
pendingCompilation = null;
|
|
318
|
+
result = fileEmitter(fileId);
|
|
319
|
+
debugHmr("TS file emitted", {
|
|
320
|
+
fileId,
|
|
321
|
+
hmrEligible: !!result?.hmrEligible,
|
|
322
|
+
hasClassName: !!classNames.get(fileId)
|
|
323
|
+
});
|
|
324
|
+
debugHmrV("ts hmr evaluation", {
|
|
325
|
+
file: ctx.file,
|
|
326
|
+
fileId,
|
|
327
|
+
hasResult: !!result,
|
|
328
|
+
hmrEligible: !!result?.hmrEligible,
|
|
329
|
+
hasClassName: !!classNames.get(fileId),
|
|
330
|
+
className: classNames.get(fileId),
|
|
331
|
+
updateCode: result?.hmrUpdateCode ? describeStylesheetContent(result.hmrUpdateCode) : void 0,
|
|
332
|
+
errors: result?.errors?.length ?? 0,
|
|
333
|
+
warnings: result?.warnings?.length ?? 0,
|
|
334
|
+
hint: result?.hmrEligible ? "A TS-side component change, including inline template edits, produced an Angular HMR payload." : "No Angular HMR payload was emitted for this TS change; the change may not affect component template state."
|
|
335
|
+
});
|
|
336
|
+
}
|
|
337
|
+
if (shouldEnableLiveReload() && result?.hmrEligible && classNames.get(fileId)) {
|
|
338
|
+
const relativeFileId = `${normalizePath(relative(process.cwd(), fileId))}@${classNames.get(fileId)}`;
|
|
339
|
+
debugHmr("sending component update", { relativeFileId });
|
|
340
|
+
debugHmrV("ts hmr component update payload", {
|
|
341
|
+
file: ctx.file,
|
|
342
|
+
fileId,
|
|
343
|
+
relativeFileId,
|
|
344
|
+
className: classNames.get(fileId)
|
|
345
|
+
});
|
|
346
|
+
sendHMRComponentUpdate(ctx.server, relativeFileId);
|
|
347
|
+
return ctx.modules.map((mod) => {
|
|
348
|
+
if (mod.id === ctx.file) return markModuleSelfAccepting(mod);
|
|
349
|
+
return mod;
|
|
350
|
+
});
|
|
351
|
+
}
|
|
352
|
+
}
|
|
353
|
+
if (/\.(html|htm|css|less|sass|scss)$/.test(ctx.file)) {
|
|
354
|
+
debugHmr("resource file changed", { file: ctx.file });
|
|
355
|
+
fileTransformMap.delete(ctx.file.split("?")[0]);
|
|
356
|
+
/**
|
|
357
|
+
* Check to see if this was a direct request
|
|
358
|
+
* for an external resource (styles, html).
|
|
359
|
+
*/
|
|
360
|
+
const isDirect = fileModules.find((mod) => !!mod.id && mod.id.includes("?direct") && isModuleForChangedResource(mod, ctx.file, stylesheetRegistry));
|
|
361
|
+
const isInline = fileModules.find((mod) => !!mod.id && mod.id.includes("?inline") && isModuleForChangedResource(mod, ctx.file, stylesheetRegistry));
|
|
362
|
+
debugHmrV("resource direct/inline detection", {
|
|
363
|
+
file: ctx.file,
|
|
364
|
+
hasDirect: !!isDirect,
|
|
365
|
+
directId: isDirect?.id,
|
|
366
|
+
hasInline: !!isInline,
|
|
367
|
+
inlineId: isInline?.id
|
|
368
|
+
});
|
|
369
|
+
if (isDirect || isInline) {
|
|
370
|
+
if (shouldExternalizeStyles() && isDirect?.id && isDirect.file) {
|
|
371
|
+
const isComponentStyle = isDirect.type === "css" && isComponentStyleSheet(isDirect.id);
|
|
372
|
+
debugHmrV("resource direct branch", {
|
|
373
|
+
file: ctx.file,
|
|
374
|
+
directId: isDirect.id,
|
|
375
|
+
directType: isDirect.type,
|
|
376
|
+
shouldExternalize: shouldExternalizeStyles(),
|
|
377
|
+
isComponentStyle
|
|
378
|
+
});
|
|
379
|
+
if (isComponentStyle) {
|
|
380
|
+
const { encapsulation } = getComponentStyleSheetMeta(isDirect.id);
|
|
381
|
+
const wrapperModules = await findComponentStylesheetWrapperModules(ctx.server, ctx.file, isDirect, fileModules, stylesheetRegistry);
|
|
382
|
+
const stylesheetDiagnosis = diagnoseComponentStylesheetPipeline(ctx.file, isDirect, stylesheetRegistry, wrapperModules, pluginOptions.stylePreprocessor);
|
|
383
|
+
debugStylesV("HMR: component stylesheet changed", {
|
|
384
|
+
file: isDirect.file,
|
|
385
|
+
encapsulation
|
|
386
|
+
});
|
|
387
|
+
debugHmrV("component stylesheet wrapper modules", {
|
|
388
|
+
file: ctx.file,
|
|
389
|
+
wrapperCount: wrapperModules.length,
|
|
390
|
+
wrapperIds: wrapperModules.map((mod) => mod.id),
|
|
391
|
+
availableModuleIds: fileModules.map((mod) => mod.id)
|
|
392
|
+
});
|
|
393
|
+
debugHmrV("component stylesheet pipeline diagnosis", stylesheetDiagnosis);
|
|
394
|
+
ctx.server.moduleGraph.invalidateModule(isDirect);
|
|
395
|
+
debugHmrV("component stylesheet direct module invalidated", {
|
|
396
|
+
file: ctx.file,
|
|
397
|
+
directModuleId: isDirect.id,
|
|
398
|
+
directModuleUrl: isDirect.url,
|
|
399
|
+
reason: "Ensure Vite drops stale direct CSS transform results before wrapper or fallback handling continues."
|
|
400
|
+
});
|
|
401
|
+
const trackedWrapperRequestIds = stylesheetDiagnosis.trackedRequestIds.filter((id) => id.includes("?ngcomp="));
|
|
402
|
+
if (encapsulation !== "shadow" && (wrapperModules.length > 0 || trackedWrapperRequestIds.length > 0)) {
|
|
403
|
+
wrapperModules.forEach((mod) => ctx.server.moduleGraph.invalidateModule(mod));
|
|
404
|
+
debugHmrV("sending css-update for component stylesheet", {
|
|
405
|
+
file: ctx.file,
|
|
406
|
+
path: isDirect.url,
|
|
407
|
+
acceptedPath: isDirect.file,
|
|
408
|
+
wrapperCount: wrapperModules.length,
|
|
409
|
+
trackedWrapperRequestIds,
|
|
410
|
+
hint: wrapperModules.length > 0 ? "Live wrapper modules were found and invalidated before sending the CSS update." : "No live wrapper ModuleNode was available, but the wrapper request id is already tracked, so Analog is trusting the browser-visible wrapper identity and patching the direct stylesheet instead of forcing a reload."
|
|
411
|
+
});
|
|
412
|
+
sendCssUpdate(ctx.server, {
|
|
413
|
+
path: isDirect.url,
|
|
414
|
+
acceptedPath: isDirect.file
|
|
415
|
+
});
|
|
416
|
+
logComponentStylesheetHmrOutcome({
|
|
417
|
+
file: ctx.file,
|
|
418
|
+
encapsulation,
|
|
419
|
+
diagnosis: stylesheetDiagnosis,
|
|
420
|
+
outcome: "css-update",
|
|
421
|
+
directModuleId: isDirect.id,
|
|
422
|
+
wrapperIds: wrapperModules.map((mod) => mod.id)
|
|
423
|
+
});
|
|
424
|
+
return union(fileModules.filter((mod) => {
|
|
425
|
+
return mod.file !== ctx.file || mod.id !== isDirect.id;
|
|
426
|
+
}).map((mod) => {
|
|
427
|
+
if (mod.file === ctx.file) return markModuleSelfAccepting(mod);
|
|
428
|
+
return mod;
|
|
429
|
+
}), wrapperModules.map((mod) => markModuleSelfAccepting(mod)));
|
|
430
|
+
}
|
|
431
|
+
debugHmrV("component stylesheet hmr fallback: full reload", {
|
|
432
|
+
file: ctx.file,
|
|
433
|
+
encapsulation,
|
|
434
|
+
reason: trackedWrapperRequestIds.length === 0 ? "missing-wrapper-module" : encapsulation === "shadow" ? "shadow-encapsulation" : "tracked-wrapper-still-not-patchable",
|
|
435
|
+
directId: isDirect.id,
|
|
436
|
+
trackedRequestIds: stylesheetRegistry?.getRequestIdsForSource(ctx.file) ?? []
|
|
437
|
+
});
|
|
438
|
+
const ownerModules = findStyleOwnerModules(ctx.server, ctx.file, styleSourceOwners);
|
|
439
|
+
debugHmrV("component stylesheet owner fallback lookup", {
|
|
440
|
+
file: ctx.file,
|
|
441
|
+
ownerCount: ownerModules.length,
|
|
442
|
+
ownerIds: ownerModules.map((mod) => mod.id),
|
|
443
|
+
ownerFiles: [...styleSourceOwners.get(normalizePath(ctx.file)) ?? []]
|
|
444
|
+
});
|
|
445
|
+
if (ownerModules.length > 0) {
|
|
446
|
+
pendingCompilation = performCompilation(resolvedConfig, [...ownerModules.map((mod) => mod.id).filter(Boolean)]);
|
|
447
|
+
await pendingCompilation;
|
|
448
|
+
pendingCompilation = null;
|
|
449
|
+
const updates = ownerModules.map((mod) => mod.id).filter((id) => !!id && !!classNames.get(id));
|
|
450
|
+
const derivedUpdates = ownerModules.map((mod) => mod.id).filter((id) => !!id).flatMap((ownerId) => resolveComponentClassNamesForStyleOwner(ownerId, ctx.file).map((className) => ({
|
|
451
|
+
ownerId,
|
|
452
|
+
className,
|
|
453
|
+
via: "raw-component-metadata"
|
|
454
|
+
})));
|
|
455
|
+
debugHmrV("component stylesheet owner fallback compilation", {
|
|
456
|
+
file: ctx.file,
|
|
457
|
+
ownerIds: ownerModules.map((mod) => mod.id),
|
|
458
|
+
updateIds: updates,
|
|
459
|
+
classNames: updates.map((id) => ({
|
|
460
|
+
id,
|
|
461
|
+
className: classNames.get(id)
|
|
462
|
+
})),
|
|
463
|
+
derivedUpdates
|
|
464
|
+
});
|
|
465
|
+
if (derivedUpdates.length > 0) debugHmrV("component stylesheet owner fallback derived updates", {
|
|
466
|
+
file: ctx.file,
|
|
467
|
+
updates: derivedUpdates,
|
|
468
|
+
hint: "Angular did not repopulate classNames during CSS-only owner recompilation, so Analog derived component identities from raw component metadata."
|
|
469
|
+
});
|
|
470
|
+
}
|
|
471
|
+
logComponentStylesheetHmrOutcome({
|
|
472
|
+
file: ctx.file,
|
|
473
|
+
encapsulation,
|
|
474
|
+
diagnosis: stylesheetDiagnosis,
|
|
475
|
+
outcome: "full-reload",
|
|
476
|
+
directModuleId: isDirect.id,
|
|
477
|
+
wrapperIds: wrapperModules.map((mod) => mod.id),
|
|
478
|
+
ownerIds: ownerModules.map((mod) => mod.id)
|
|
479
|
+
});
|
|
480
|
+
sendFullReload(ctx.server, {
|
|
481
|
+
file: ctx.file,
|
|
482
|
+
encapsulation,
|
|
483
|
+
reason: wrapperModules.length === 0 ? "missing-wrapper-module-and-no-owner-updates" : "shadow-encapsulation",
|
|
484
|
+
directId: isDirect.id,
|
|
485
|
+
trackedRequestIds: stylesheetRegistry?.getRequestIdsForSource(ctx.file) ?? []
|
|
486
|
+
});
|
|
487
|
+
return [];
|
|
488
|
+
}
|
|
489
|
+
}
|
|
490
|
+
return fileModules;
|
|
491
|
+
}
|
|
492
|
+
if (shouldEnableLiveReload() && /\.(html|htm)$/.test(ctx.file) && fileModules.length === 0) {
|
|
493
|
+
const ownerModules = findTemplateOwnerModules(ctx.server, ctx.file);
|
|
494
|
+
debugHmrV("template owner lookup", {
|
|
495
|
+
file: ctx.file,
|
|
496
|
+
ownerCount: ownerModules.length,
|
|
497
|
+
ownerIds: ownerModules.map((mod) => mod.id),
|
|
498
|
+
hint: ownerModules.length > 0 ? "The external template has candidate TS owner modules that can be recompiled for HMR." : "No TS owner modules were visible for this external template change; HMR will fall through to the generic importer path."
|
|
499
|
+
});
|
|
500
|
+
if (ownerModules.length > 0) {
|
|
501
|
+
const ownerIds = ownerModules.map((mod) => mod.id).filter(Boolean);
|
|
502
|
+
ownerModules.forEach((mod) => ctx.server.moduleGraph.invalidateModule(mod));
|
|
503
|
+
pendingCompilation = performCompilation(resolvedConfig, ownerIds);
|
|
504
|
+
await pendingCompilation;
|
|
505
|
+
pendingCompilation = null;
|
|
506
|
+
const updates = ownerIds.filter((id) => classNames.get(id));
|
|
507
|
+
debugHmrV("template owner recompilation result", {
|
|
508
|
+
file: ctx.file,
|
|
509
|
+
ownerIds,
|
|
510
|
+
updates,
|
|
511
|
+
updateClassNames: updates.map((id) => ({
|
|
512
|
+
id,
|
|
513
|
+
className: classNames.get(id)
|
|
514
|
+
})),
|
|
515
|
+
hint: updates.length > 0 ? "External template recompilation produced Angular component update targets." : "External template recompilation completed, but no Angular component update targets were surfaced."
|
|
516
|
+
});
|
|
517
|
+
if (updates.length > 0) {
|
|
518
|
+
debugHmr("template owner module invalidation", {
|
|
519
|
+
file: ctx.file,
|
|
520
|
+
ownerIds,
|
|
521
|
+
updateCount: updates.length
|
|
522
|
+
});
|
|
523
|
+
updates.forEach((updateId) => {
|
|
524
|
+
const relativeFileId = `${normalizePath(relative(process.cwd(), updateId))}@${classNames.get(updateId)}`;
|
|
525
|
+
sendHMRComponentUpdate(ctx.server, relativeFileId);
|
|
526
|
+
});
|
|
527
|
+
return ownerModules.map((mod) => markModuleSelfAccepting(mod));
|
|
528
|
+
}
|
|
529
|
+
}
|
|
530
|
+
}
|
|
531
|
+
const mods = [];
|
|
532
|
+
const updates = [];
|
|
533
|
+
fileModules.forEach((mod) => {
|
|
534
|
+
mod.importers.forEach((imp) => {
|
|
535
|
+
ctx.server.moduleGraph.invalidateModule(imp);
|
|
536
|
+
if (shouldExternalizeStyles() && classNames.get(imp.id)) updates.push(imp.id);
|
|
537
|
+
else mods.push(imp);
|
|
538
|
+
});
|
|
539
|
+
});
|
|
540
|
+
debugHmrV("resource importer analysis", {
|
|
541
|
+
file: ctx.file,
|
|
542
|
+
fileModuleCount: fileModules.length,
|
|
543
|
+
importerCount: fileModules.reduce((count, mod) => count + mod.importers.size, 0),
|
|
544
|
+
updates,
|
|
545
|
+
mods: mods.map((mod) => mod.id)
|
|
546
|
+
});
|
|
547
|
+
pendingCompilation = performCompilation(resolvedConfig, [...mods.map((mod) => mod.id).filter(Boolean), ...updates]);
|
|
548
|
+
if (updates.length > 0) {
|
|
549
|
+
await pendingCompilation;
|
|
550
|
+
pendingCompilation = null;
|
|
551
|
+
debugHmr("resource importer component updates", {
|
|
552
|
+
file: ctx.file,
|
|
553
|
+
updateCount: updates.length
|
|
554
|
+
});
|
|
555
|
+
updates.forEach((updateId) => {
|
|
556
|
+
const impRelativeFileId = `${normalizePath(relative(process.cwd(), updateId))}@${classNames.get(updateId)}`;
|
|
557
|
+
sendHMRComponentUpdate(ctx.server, impRelativeFileId);
|
|
558
|
+
});
|
|
559
|
+
return fileModules.map((mod) => {
|
|
560
|
+
if (mod.id === ctx.file) return markModuleSelfAccepting(mod);
|
|
561
|
+
return mod;
|
|
562
|
+
});
|
|
563
|
+
}
|
|
564
|
+
return mods;
|
|
565
|
+
}
|
|
566
|
+
debugHmr("full reload — unrecognized file type", { file: ctx.file });
|
|
567
|
+
classNames.clear();
|
|
568
|
+
return ctx.modules;
|
|
569
|
+
},
|
|
570
|
+
resolveId(id, importer) {
|
|
571
|
+
if (id.startsWith("virtual:@analogjs/vite-plugin-angular:raw:")) return `\0${id}`;
|
|
572
|
+
if (jit && id.startsWith("angular:jit:")) {
|
|
573
|
+
const filePath = normalizePath(resolve(dirname(importer), id.split(";")[1]));
|
|
574
|
+
if (id.includes(":style")) {
|
|
575
|
+
markStylePathSafe(resolvedConfig, filePath);
|
|
576
|
+
return filePath + "?inline";
|
|
577
|
+
}
|
|
578
|
+
return toVirtualRawId(filePath);
|
|
579
|
+
}
|
|
580
|
+
const rawRewrite = rewriteHtmlRawImport(id, importer);
|
|
581
|
+
if (rawRewrite) return rawRewrite;
|
|
582
|
+
if (/\.(css|scss|sass|less)\?inline$/.test(id) && importer) {
|
|
583
|
+
const filePath = id.split("?")[0];
|
|
584
|
+
const resolved = isAbsolute(filePath) ? normalizePath(filePath) : normalizePath(resolve(dirname(importer), filePath));
|
|
585
|
+
markStylePathSafe(resolvedConfig, resolved);
|
|
586
|
+
return resolved + "?inline";
|
|
587
|
+
}
|
|
588
|
+
if (isComponentStyleSheet(id)) {
|
|
589
|
+
const filename = getFilenameFromPath(id);
|
|
590
|
+
if (stylesheetRegistry?.hasServed(filename)) {
|
|
591
|
+
debugStylesV("resolveId: kept preprocessed ID", { filename });
|
|
592
|
+
return id;
|
|
593
|
+
}
|
|
594
|
+
const componentStyles = stylesheetRegistry?.resolveExternalSource(filename);
|
|
595
|
+
if (componentStyles) {
|
|
596
|
+
debugStylesV("resolveId: mapped external stylesheet", {
|
|
597
|
+
filename,
|
|
598
|
+
resolvedPath: componentStyles
|
|
599
|
+
});
|
|
600
|
+
return componentStyles + new URL(id, "http://localhost").search;
|
|
601
|
+
}
|
|
602
|
+
debugStyles("resolveId: component stylesheet NOT FOUND in either map", {
|
|
603
|
+
filename,
|
|
604
|
+
inlineMapSize: stylesheetRegistry?.servedCount ?? 0,
|
|
605
|
+
externalMapSize: stylesheetRegistry?.externalCount ?? 0
|
|
606
|
+
});
|
|
607
|
+
}
|
|
608
|
+
},
|
|
609
|
+
async load(id) {
|
|
610
|
+
const rawModule = await loadVirtualRawModule(this, id);
|
|
611
|
+
if (rawModule !== void 0) return rawModule;
|
|
612
|
+
if (/\.(css|scss|sass|less)\?inline$/.test(id)) markStylePathSafe(resolvedConfig, id.split("?")[0]);
|
|
613
|
+
if (isComponentStyleSheet(id)) {
|
|
614
|
+
const filename = getFilenameFromPath(id);
|
|
615
|
+
const componentStyles = stylesheetRegistry?.getServedContent(filename);
|
|
616
|
+
if (componentStyles) {
|
|
617
|
+
stylesheetRegistry?.registerActiveRequest(id);
|
|
618
|
+
debugHmrV("stylesheet active request registered", {
|
|
619
|
+
requestId: id,
|
|
620
|
+
filename,
|
|
621
|
+
sourcePath: stylesheetRegistry?.resolveExternalSource(filename) ?? stylesheetRegistry?.resolveExternalSource(filename.replace(/^\//, "")),
|
|
622
|
+
trackedRequestIds: stylesheetRegistry?.getRequestIdsForSource(stylesheetRegistry?.resolveExternalSource(filename) ?? stylesheetRegistry?.resolveExternalSource(filename.replace(/^\//, "")) ?? "") ?? []
|
|
623
|
+
});
|
|
624
|
+
debugStylesV("load: served inline component stylesheet", {
|
|
625
|
+
filename,
|
|
626
|
+
length: componentStyles.length,
|
|
627
|
+
requestId: id,
|
|
628
|
+
...describeStylesheetContent(componentStyles)
|
|
629
|
+
});
|
|
630
|
+
return componentStyles;
|
|
631
|
+
}
|
|
632
|
+
}
|
|
633
|
+
},
|
|
634
|
+
transform: {
|
|
635
|
+
filter: { id: {
|
|
636
|
+
include: [TS_EXT_REGEX],
|
|
637
|
+
exclude: [
|
|
638
|
+
/node_modules/,
|
|
639
|
+
"type=script",
|
|
640
|
+
"@ng/component"
|
|
641
|
+
]
|
|
642
|
+
} },
|
|
643
|
+
async handler(code, id) {
|
|
644
|
+
/**
|
|
645
|
+
* Check for options.transformFilter
|
|
646
|
+
*/
|
|
647
|
+
if (options?.transformFilter && !(options?.transformFilter(code, id) ?? true)) return;
|
|
648
|
+
/**
|
|
649
|
+
* Skip transforming content files
|
|
650
|
+
*/
|
|
651
|
+
if (id.includes("?") && id.includes("analog-content-")) return;
|
|
652
|
+
if (id.includes(".ts?")) id = id.replace(/\?(.*)/, "");
|
|
653
|
+
fileTransformMap.set(id, code);
|
|
654
|
+
/**
|
|
655
|
+
* Re-analyze on each transform
|
|
656
|
+
* for test(Vitest)
|
|
657
|
+
*/
|
|
658
|
+
if (isTest) {
|
|
659
|
+
if (isVitestVscode && !initialCompilation) {
|
|
660
|
+
pendingCompilation = performCompilation(resolvedConfig);
|
|
661
|
+
initialCompilation = true;
|
|
662
|
+
}
|
|
663
|
+
const tsMod = viteServer?.moduleGraph.getModuleById(id);
|
|
664
|
+
if (tsMod) {
|
|
665
|
+
const invalidated = tsMod.lastInvalidationTimestamp;
|
|
666
|
+
if (testWatchMode && invalidated) pendingCompilation = performCompilation(resolvedConfig, [id]);
|
|
667
|
+
}
|
|
668
|
+
}
|
|
669
|
+
const hasComponent = code.includes("@Component");
|
|
670
|
+
debugCompilerV("transform", {
|
|
671
|
+
id,
|
|
672
|
+
codeLength: code.length,
|
|
673
|
+
hasComponent
|
|
674
|
+
});
|
|
675
|
+
const templateUrls = hasComponent ? templateUrlsResolver.resolve(code, id) : [];
|
|
676
|
+
const styleUrls = hasComponent ? styleUrlsResolver.resolve(code, id) : [];
|
|
677
|
+
if (hasComponent && watchMode) for (const urlSet of [...templateUrls, ...styleUrls]) {
|
|
678
|
+
const [, absoluteFileUrl] = urlSet.split("|");
|
|
679
|
+
this.addWatchFile(absoluteFileUrl);
|
|
680
|
+
}
|
|
681
|
+
if (pendingCompilation) {
|
|
682
|
+
await pendingCompilation;
|
|
683
|
+
pendingCompilation = null;
|
|
684
|
+
}
|
|
685
|
+
const typescriptResult = fileEmitter(id);
|
|
686
|
+
if (!typescriptResult) {
|
|
687
|
+
debugCompilerV("transform skip (file not emitted by Angular)", { id });
|
|
688
|
+
const isAngular = !id.includes("@ng/component") && /(Component|Directive|Pipe|Injectable|NgModule)\(/.test(code);
|
|
689
|
+
debugEmit("transform emit miss", {
|
|
690
|
+
id,
|
|
691
|
+
normalizedId: normalizeEmitterLookupId(id),
|
|
692
|
+
knownOutputCount: outputFiles.size,
|
|
693
|
+
hasOutputFileHook: !!outputFile,
|
|
694
|
+
isAngular
|
|
695
|
+
});
|
|
696
|
+
if (isAngular) this.warn(`[@analogjs/vite-plugin-angular]: "${id}" contains Angular decorators but is not in the TypeScript program. Ensure it is included in your tsconfig.`);
|
|
697
|
+
return;
|
|
698
|
+
}
|
|
699
|
+
if (typescriptResult.warnings && typescriptResult.warnings.length > 0) this.warn(`${typescriptResult.warnings.join("\n")}`);
|
|
700
|
+
if (typescriptResult.errors && typescriptResult.errors.length > 0) this.error(`${typescriptResult.errors.join("\n")}`);
|
|
701
|
+
let data = typescriptResult.content ?? "";
|
|
702
|
+
debugEmitV("transform emit hit", {
|
|
703
|
+
id,
|
|
704
|
+
normalizedId: normalizeEmitterLookupId(id),
|
|
705
|
+
...describeEmitMarkers(data),
|
|
706
|
+
errorCount: typescriptResult.errors?.length ?? 0,
|
|
707
|
+
warningCount: typescriptResult.warnings?.length ?? 0
|
|
708
|
+
});
|
|
709
|
+
if (jit && data.includes("angular:jit:")) {
|
|
710
|
+
data = data.replace(/angular:jit:style:inline;/g, "virtual:angular:jit:style:inline;");
|
|
711
|
+
templateUrls.forEach((templateUrlSet) => {
|
|
712
|
+
const [templateFile, resolvedTemplateUrl] = templateUrlSet.split("|");
|
|
713
|
+
data = data.replace(`angular:jit:template:file;${templateFile}`, toVirtualRawId(resolvedTemplateUrl));
|
|
714
|
+
});
|
|
715
|
+
styleUrls.forEach((styleUrlSet) => {
|
|
716
|
+
const [styleFile, resolvedStyleUrl] = styleUrlSet.split("|");
|
|
717
|
+
markStylePathSafe(resolvedConfig, resolvedStyleUrl);
|
|
718
|
+
data = data.replace(`angular:jit:style:file;${styleFile}`, resolvedStyleUrl + "?inline");
|
|
719
|
+
});
|
|
720
|
+
}
|
|
721
|
+
if (data.includes("HmrLoad")) {
|
|
722
|
+
const hasMetaUrl = data.includes("getReplaceMetadataURL");
|
|
723
|
+
debugHmrV("vite-ignore injection", {
|
|
724
|
+
id,
|
|
725
|
+
dataLength: data.length,
|
|
726
|
+
hasMetaUrl
|
|
727
|
+
});
|
|
728
|
+
if (hasMetaUrl) {
|
|
729
|
+
const patched = injectViteIgnoreForHmrMetadata(data);
|
|
730
|
+
if (patched !== data && !patched.includes("@vite-ignore")) debugHmrV("vite-ignore regex fallback", { id });
|
|
731
|
+
data = patched;
|
|
732
|
+
}
|
|
733
|
+
}
|
|
734
|
+
return {
|
|
735
|
+
code: data,
|
|
736
|
+
map: null
|
|
737
|
+
};
|
|
738
|
+
}
|
|
739
|
+
},
|
|
740
|
+
closeBundle() {
|
|
741
|
+
declarationFiles.forEach(({ declarationFileDir, declarationPath, data }) => {
|
|
742
|
+
mkdirSync(declarationFileDir, { recursive: true });
|
|
743
|
+
writeFileSync(declarationPath, data, "utf-8");
|
|
744
|
+
});
|
|
745
|
+
}
|
|
746
|
+
};
|
|
747
|
+
}
|
|
748
|
+
const compilationPlugin = pluginOptions.useAngularCompilationAPI ? compilationAPIPlugin({
|
|
749
|
+
tsconfigGetter: pluginOptions.tsconfigGetter,
|
|
750
|
+
workspaceRoot: pluginOptions.workspaceRoot,
|
|
751
|
+
inlineStylesExtension: pluginOptions.inlineStylesExtension,
|
|
752
|
+
jit,
|
|
753
|
+
liveReload: pluginOptions.liveReload,
|
|
754
|
+
disableTypeChecking: pluginOptions.disableTypeChecking,
|
|
755
|
+
supportedBrowsers: pluginOptions.supportedBrowsers,
|
|
756
|
+
transformFilter: options?.transformFilter,
|
|
757
|
+
fileReplacements: pluginOptions.fileReplacements,
|
|
758
|
+
stylePreprocessor: pluginOptions.stylePreprocessor,
|
|
759
|
+
stylePipeline: options?.stylePipeline,
|
|
760
|
+
hasTailwindCss: pluginOptions.hasTailwindCss,
|
|
761
|
+
tailwindCss: pluginOptions.tailwindCss,
|
|
762
|
+
isTest,
|
|
763
|
+
isAstroIntegration,
|
|
764
|
+
include: pluginOptions.include,
|
|
765
|
+
additionalContentDirs: pluginOptions.additionalContentDirs,
|
|
766
|
+
debug: options?.debug
|
|
767
|
+
}) : pluginOptions.fastCompile ? fastCompilePlugin({
|
|
768
|
+
tsconfigGetter: pluginOptions.tsconfigGetter,
|
|
769
|
+
workspaceRoot: pluginOptions.workspaceRoot,
|
|
770
|
+
inlineStylesExtension: pluginOptions.inlineStylesExtension,
|
|
771
|
+
jit,
|
|
772
|
+
liveReload: pluginOptions.liveReload,
|
|
773
|
+
supportedBrowsers: pluginOptions.supportedBrowsers,
|
|
774
|
+
transformFilter: options?.transformFilter,
|
|
775
|
+
isTest,
|
|
776
|
+
isAstroIntegration,
|
|
777
|
+
fastCompileMode: pluginOptions.fastCompileMode
|
|
778
|
+
}) : angularPlugin();
|
|
779
|
+
return [
|
|
780
|
+
replaceFiles(pluginOptions.fileReplacements, pluginOptions.workspaceRoot),
|
|
781
|
+
virtualModulesPlugin({ jit }),
|
|
782
|
+
templateClassBindingGuardPlugin(guardContext),
|
|
783
|
+
pluginOptions.hasTailwindCss && tailwindReferencePlugin({ tailwindCss: pluginOptions.tailwindCss }),
|
|
784
|
+
pluginOptions.liveReload && liveReloadPlugin({
|
|
785
|
+
classNames,
|
|
786
|
+
fileEmitter
|
|
787
|
+
}),
|
|
788
|
+
compilationPlugin,
|
|
789
|
+
!pluginOptions.fastCompile && pluginOptions.liveReload && liveReloadPlugin({
|
|
790
|
+
classNames,
|
|
791
|
+
fileEmitter
|
|
792
|
+
}),
|
|
793
|
+
...isTest && !isStackBlitz ? angularVitestPlugins() : [],
|
|
794
|
+
jit && jitPlugin({ inlineStylesExtension: pluginOptions.inlineStylesExtension }),
|
|
795
|
+
buildOptimizerPlugin({
|
|
796
|
+
supportedBrowsers: pluginOptions.supportedBrowsers,
|
|
797
|
+
jit
|
|
798
|
+
}),
|
|
799
|
+
routerPlugin(),
|
|
800
|
+
angularFullVersion < 190004 && pendingTasksPlugin(),
|
|
801
|
+
nxFolderPlugin(),
|
|
802
|
+
encapsulationPlugin(shouldExternalizeStyles)
|
|
803
|
+
].filter(Boolean);
|
|
804
|
+
function resolveTsConfigPath() {
|
|
805
|
+
const tsconfigValue = pluginOptions.tsconfigGetter();
|
|
806
|
+
return getTsConfigPath(tsConfigResolutionContext.root, tsconfigValue, tsConfigResolutionContext.isProd, isTest, tsConfigResolutionContext.isLib);
|
|
807
|
+
}
|
|
808
|
+
async function performCompilation(config, ids) {
|
|
809
|
+
let resolve;
|
|
810
|
+
const previousLock = compilationLock;
|
|
811
|
+
compilationLock = new Promise((r) => {
|
|
812
|
+
resolve = r;
|
|
813
|
+
});
|
|
814
|
+
try {
|
|
815
|
+
await previousLock;
|
|
816
|
+
await _doPerformCompilation(config, ids);
|
|
817
|
+
} finally {
|
|
818
|
+
resolve();
|
|
819
|
+
}
|
|
820
|
+
}
|
|
821
|
+
/**
|
|
822
|
+
* This method share mutable state and performs the actual compilation work.
|
|
823
|
+
* It should not be called concurrently. Use `performCompilation` which wraps this method in a lock to ensure only one compilation runs at a time.
|
|
824
|
+
*/
|
|
825
|
+
async function _doPerformCompilation(config, ids) {
|
|
826
|
+
const isProd = config.mode === "production";
|
|
827
|
+
const modifiedFiles = new Set(ids ?? []);
|
|
828
|
+
sourceFileCache$1.invalidate(modifiedFiles);
|
|
829
|
+
if (ids?.length) for (const id of ids || []) fileTransformMap.delete(id);
|
|
830
|
+
const resolvedTsConfigPath = resolveTsConfigPath();
|
|
831
|
+
const cached = tsconfigResolver.getCachedTsconfigOptions(resolvedTsConfigPath, config);
|
|
832
|
+
const tsCompilerOptions = { ...cached.options };
|
|
833
|
+
let rootNames = [...cached.rootNames];
|
|
834
|
+
if (shouldExternalizeStyles()) tsCompilerOptions["externalRuntimeStyles"] = true;
|
|
835
|
+
if (shouldEnableLiveReload()) {
|
|
836
|
+
tsCompilerOptions["_enableHmr"] = true;
|
|
837
|
+
tsCompilerOptions["supportTestBed"] = true;
|
|
838
|
+
}
|
|
839
|
+
debugCompiler("tsCompilerOptions (NgtscProgram path)", {
|
|
840
|
+
liveReload: pluginOptions.liveReload,
|
|
841
|
+
viteHmr: hasViteHmrTransport(),
|
|
842
|
+
shouldExternalize: shouldExternalizeStyles(),
|
|
843
|
+
externalRuntimeStyles: !!tsCompilerOptions["externalRuntimeStyles"],
|
|
844
|
+
hmrEnabled: !!tsCompilerOptions["_enableHmr"]
|
|
845
|
+
});
|
|
846
|
+
if (tsCompilerOptions["compilationMode"] === "partial") {
|
|
847
|
+
tsCompilerOptions["supportTestBed"] = true;
|
|
848
|
+
tsCompilerOptions["supportJitMode"] = true;
|
|
849
|
+
}
|
|
850
|
+
if (!isTest && config.build?.lib) {
|
|
851
|
+
tsCompilerOptions["declaration"] = true;
|
|
852
|
+
tsCompilerOptions["declarationMap"] = watchMode;
|
|
853
|
+
tsCompilerOptions["inlineSources"] = true;
|
|
854
|
+
}
|
|
855
|
+
if (isTest) tsCompilerOptions["supportTestBed"] = true;
|
|
856
|
+
const replacements = pluginOptions.fileReplacements.map((rp) => join(pluginOptions.workspaceRoot, rp.ssr || rp.with));
|
|
857
|
+
rootNames = union(rootNames, tsconfigResolver.ensureIncludeCache(), replacements);
|
|
858
|
+
const hostKey = JSON.stringify(tsCompilerOptions);
|
|
859
|
+
let host;
|
|
860
|
+
if (cachedHost && cachedHostKey === hostKey) host = cachedHost;
|
|
861
|
+
else {
|
|
862
|
+
host = ts.createIncrementalCompilerHost(tsCompilerOptions, {
|
|
863
|
+
...ts.sys,
|
|
864
|
+
readFile(path, encoding) {
|
|
865
|
+
if (fileTransformMap.has(path)) return fileTransformMap.get(path);
|
|
866
|
+
const file = ts.sys.readFile.call(null, path, encoding);
|
|
867
|
+
if (file) fileTransformMap.set(path, file);
|
|
868
|
+
return file;
|
|
869
|
+
}
|
|
870
|
+
});
|
|
871
|
+
cachedHost = host;
|
|
872
|
+
cachedHostKey = hostKey;
|
|
873
|
+
if (watchMode) augmentHostWithCaching(host, sourceFileCache$1);
|
|
874
|
+
}
|
|
875
|
+
if (!jit) {
|
|
876
|
+
const externalizeStyles = !!tsCompilerOptions["externalRuntimeStyles"];
|
|
877
|
+
stylesheetRegistry = externalizeStyles ? new AnalogStylesheetRegistry() : void 0;
|
|
878
|
+
if (stylesheetRegistry) configureStylePipelineRegistry(pluginOptions.stylePipeline, stylesheetRegistry, { workspaceRoot: pluginOptions.workspaceRoot });
|
|
879
|
+
debugStyles("stylesheet registry initialized (NgtscProgram path)", { externalizeStyles });
|
|
880
|
+
augmentHostWithResources(host, styleTransform, {
|
|
881
|
+
inlineStylesExtension: pluginOptions.inlineStylesExtension,
|
|
882
|
+
isProd,
|
|
883
|
+
stylesheetRegistry,
|
|
884
|
+
sourceFileCache: sourceFileCache$1,
|
|
885
|
+
stylePreprocessor: pluginOptions.stylePreprocessor
|
|
886
|
+
});
|
|
887
|
+
}
|
|
888
|
+
/**
|
|
889
|
+
* Creates a new NgtscProgram to analyze/re-analyze
|
|
890
|
+
* the source files and create a file emitter.
|
|
891
|
+
* This is shared between an initial build and a hot update.
|
|
892
|
+
*/
|
|
893
|
+
let typeScriptProgram;
|
|
894
|
+
let angularCompiler;
|
|
895
|
+
const oldBuilder = builder ?? ts.readBuilderProgram(tsCompilerOptions, host);
|
|
896
|
+
if (!jit) {
|
|
897
|
+
const angularProgram = new compilerCli.NgtscProgram(rootNames, tsCompilerOptions, host, nextProgram);
|
|
898
|
+
angularCompiler = angularProgram.compiler;
|
|
899
|
+
typeScriptProgram = angularProgram.compiler.getCurrentProgram();
|
|
900
|
+
augmentProgramWithVersioning(typeScriptProgram);
|
|
901
|
+
builder = ts.createEmitAndSemanticDiagnosticsBuilderProgram(typeScriptProgram, host, oldBuilder);
|
|
902
|
+
nextProgram = angularProgram;
|
|
903
|
+
} else {
|
|
904
|
+
builder = ts.createEmitAndSemanticDiagnosticsBuilderProgram(rootNames, tsCompilerOptions, host, oldBuilder);
|
|
905
|
+
typeScriptProgram = builder.getProgram();
|
|
906
|
+
}
|
|
907
|
+
if (!watchMode) builder = ts.createAbstractBuilder(typeScriptProgram, host, oldBuilder);
|
|
908
|
+
if (angularCompiler) await angularCompiler.analyzeAsync();
|
|
909
|
+
const transformers = mergeTransformers({ before: jit ? [compilerCli.constructorParametersDownlevelTransform(builder.getProgram()), cjt(() => builder.getProgram().getTypeChecker())] : [] }, jit ? {} : angularCompiler.prepareEmit().transformers);
|
|
910
|
+
const fileMetadata = getFileMetadata(builder, angularCompiler, pluginOptions.liveReload, pluginOptions.disableTypeChecking);
|
|
911
|
+
const writeFileCallback = (_filename, content, _a, _b, sourceFiles) => {
|
|
912
|
+
if (!sourceFiles?.length) return;
|
|
913
|
+
const filename = normalizePath(sourceFiles[0].fileName);
|
|
914
|
+
if (filename.includes("ngtypecheck.ts") || filename.includes(".d.")) return;
|
|
915
|
+
const metadata = watchMode ? fileMetadata(filename) : {};
|
|
916
|
+
outputFiles.set(filename, {
|
|
917
|
+
content,
|
|
918
|
+
dependencies: [],
|
|
919
|
+
errors: metadata.errors,
|
|
920
|
+
warnings: metadata.warnings,
|
|
921
|
+
hmrUpdateCode: metadata.hmrUpdateCode,
|
|
922
|
+
hmrEligible: metadata.hmrEligible
|
|
923
|
+
});
|
|
924
|
+
debugEmitV("registered ngtsc output", {
|
|
925
|
+
filename,
|
|
926
|
+
...describeEmitMarkers(content),
|
|
927
|
+
errorCount: metadata.errors?.length ?? 0,
|
|
928
|
+
warningCount: metadata.warnings?.length ?? 0,
|
|
929
|
+
hmrEligible: !!metadata.hmrEligible,
|
|
930
|
+
knownOutputCount: outputFiles.size
|
|
931
|
+
});
|
|
932
|
+
};
|
|
933
|
+
const writeOutputFile = (id) => {
|
|
934
|
+
const sourceFile = builder.getSourceFile(id);
|
|
935
|
+
if (!sourceFile) return;
|
|
936
|
+
let content = "";
|
|
937
|
+
builder.emit(sourceFile, (filename, data) => {
|
|
938
|
+
if (/\.[cm]?js$/.test(filename)) content = data;
|
|
939
|
+
if (!watchMode && !isTest && /\.d\.ts/.test(filename) && !filename.includes(".ngtypecheck.")) {
|
|
940
|
+
const declarationPath = resolve(config.root, config.build.outDir, relative(config.root, filename)).replace("/src/", "/");
|
|
941
|
+
const declarationFileDir = declarationPath.replace(basename(filename), "").replace("/src/", "/");
|
|
942
|
+
declarationFiles.push({
|
|
943
|
+
declarationFileDir,
|
|
944
|
+
declarationPath,
|
|
945
|
+
data
|
|
946
|
+
});
|
|
947
|
+
}
|
|
948
|
+
}, void 0, void 0, transformers);
|
|
949
|
+
writeFileCallback(id, content, false, void 0, [sourceFile]);
|
|
950
|
+
if (angularCompiler) angularCompiler.incrementalCompilation.recordSuccessfulEmit(sourceFile);
|
|
951
|
+
};
|
|
952
|
+
if (watchMode) {
|
|
953
|
+
if (ids && ids.length > 0) ids.forEach((id) => writeOutputFile(id));
|
|
954
|
+
else if (isTest) while (builder.emitNextAffectedFile(writeFileCallback, void 0, void 0, transformers));
|
|
955
|
+
}
|
|
956
|
+
if (!isTest)
|
|
957
|
+
/**
|
|
958
|
+
* Perf: Output files on demand so the dev server
|
|
959
|
+
* isn't blocked when emitting files.
|
|
960
|
+
*/
|
|
961
|
+
outputFile = writeOutputFile;
|
|
962
|
+
}
|
|
963
|
+
}
|
|
964
|
+
function createFsWatcherCacheInvalidator(invalidateFsCaches, invalidateTsconfigCaches, performCompilation) {
|
|
965
|
+
return async () => {
|
|
966
|
+
invalidateFsCaches();
|
|
967
|
+
invalidateTsconfigCaches();
|
|
968
|
+
await performCompilation();
|
|
969
|
+
};
|
|
970
|
+
}
|
|
971
|
+
function isModuleForChangedResource(mod, changedFile, stylesheetRegistry) {
|
|
972
|
+
const normalizedChangedFile = normalizePath(changedFile.split("?")[0]);
|
|
973
|
+
if (normalizePath((mod.file ?? "").split("?")[0]) === normalizedChangedFile) return true;
|
|
974
|
+
if (!mod.id) return false;
|
|
975
|
+
const requestPath = getFilenameFromPath(mod.id);
|
|
976
|
+
return normalizePath((stylesheetRegistry?.resolveExternalSource(requestPath) ?? stylesheetRegistry?.resolveExternalSource(requestPath.replace(/^\//, "")) ?? "").split("?")[0]) === normalizedChangedFile;
|
|
977
|
+
}
|
|
978
|
+
function diagnoseComponentStylesheetPipeline(changedFile, directModule, stylesheetRegistry, wrapperModules, stylePreprocessor) {
|
|
979
|
+
const normalizedFile = normalizePath(changedFile.split("?")[0]);
|
|
980
|
+
const sourceExists = existsSync(normalizedFile);
|
|
981
|
+
const sourceCode = sourceExists ? readFileSync(normalizedFile, "utf-8") : void 0;
|
|
982
|
+
const directRequestPath = directModule.id ? getFilenameFromPath(directModule.id) : void 0;
|
|
983
|
+
const sourcePath = directRequestPath ? stylesheetRegistry?.resolveExternalSource(directRequestPath) ?? stylesheetRegistry?.resolveExternalSource(directRequestPath.replace(/^\//, "")) : normalizedFile;
|
|
984
|
+
const registryCode = directRequestPath ? stylesheetRegistry?.getServedContent(directRequestPath) : void 0;
|
|
985
|
+
const trackedRequestIds = stylesheetRegistry?.getRequestIdsForSource(sourcePath ?? "") ?? [];
|
|
986
|
+
const dependencies = stylesheetRegistry?.getDependenciesForSource(sourcePath ?? "") ?? [];
|
|
987
|
+
const diagnostics = stylesheetRegistry?.getDiagnosticsForSource(sourcePath ?? "") ?? [];
|
|
988
|
+
const tags = stylesheetRegistry?.getTagsForSource(sourcePath ?? "") ?? [];
|
|
989
|
+
const anomalies = [];
|
|
990
|
+
const hints = [];
|
|
991
|
+
if (!sourceExists) {
|
|
992
|
+
anomalies.push("source_file_missing");
|
|
993
|
+
hints.push("The stylesheet watcher fired for a file that no longer exists on disk.");
|
|
994
|
+
}
|
|
995
|
+
if (!registryCode) {
|
|
996
|
+
anomalies.push("registry_content_missing");
|
|
997
|
+
hints.push("The stylesheet registry has no served content for the direct module request path.");
|
|
998
|
+
}
|
|
999
|
+
if (sourceCode && registryCode) {
|
|
1000
|
+
let expectedRegistryCode = preprocessStylesheet(sourceCode, normalizedFile, stylePreprocessor);
|
|
1001
|
+
expectedRegistryCode = rewriteRelativeCssImports(expectedRegistryCode, normalizedFile);
|
|
1002
|
+
if (describeStylesheetContent(expectedRegistryCode).digest !== describeStylesheetContent(registryCode).digest) {
|
|
1003
|
+
anomalies.push("source_registry_mismatch");
|
|
1004
|
+
hints.push("The source file changed, but the served stylesheet content in the registry is still stale.");
|
|
1005
|
+
}
|
|
1006
|
+
}
|
|
1007
|
+
if (trackedRequestIds.length === 0) {
|
|
1008
|
+
anomalies.push("no_tracked_requests");
|
|
1009
|
+
hints.push("No live stylesheet requests are tracked for this source file, so HMR has no browser-facing target.");
|
|
1010
|
+
}
|
|
1011
|
+
if (trackedRequestIds.some((id) => id.includes("?ngcomp=")) && wrapperModules.length === 0) {
|
|
1012
|
+
anomalies.push("tracked_wrapper_missing_from_module_graph");
|
|
1013
|
+
hints.push("A wrapper request id is known, but Vite did not expose a live wrapper module during this HMR pass.");
|
|
1014
|
+
}
|
|
1015
|
+
if (trackedRequestIds.every((id) => !id.includes("?ngcomp=")) && wrapperModules.length === 0) {
|
|
1016
|
+
anomalies.push("wrapper_not_yet_tracked");
|
|
1017
|
+
hints.push("Only direct stylesheet requests were tracked during this HMR pass; the wrapper request may be appearing too late.");
|
|
1018
|
+
}
|
|
1019
|
+
return {
|
|
1020
|
+
file: changedFile,
|
|
1021
|
+
sourcePath,
|
|
1022
|
+
source: sourceCode ? describeStylesheetContent(rewriteRelativeCssImports(preprocessStylesheet(sourceCode, normalizedFile, stylePreprocessor), normalizedFile)) : void 0,
|
|
1023
|
+
registry: registryCode ? describeStylesheetContent(registryCode) : void 0,
|
|
1024
|
+
dependencies,
|
|
1025
|
+
diagnostics,
|
|
1026
|
+
tags,
|
|
1027
|
+
directModuleId: directModule.id,
|
|
1028
|
+
directModuleUrl: directModule.url,
|
|
1029
|
+
trackedRequestIds,
|
|
1030
|
+
wrapperCount: wrapperModules.length,
|
|
1031
|
+
anomalies,
|
|
1032
|
+
hints
|
|
1033
|
+
};
|
|
1034
|
+
}
|
|
1035
|
+
async function findComponentStylesheetWrapperModules(server, changedFile, directModule, fileModules, stylesheetRegistry) {
|
|
1036
|
+
const wrapperModules = /* @__PURE__ */ new Map();
|
|
1037
|
+
for (const mod of fileModules) if (mod.id && mod.type === "js" && isComponentStyleSheet(mod.id) && isModuleForChangedResource(mod, changedFile, stylesheetRegistry)) wrapperModules.set(mod.id, mod);
|
|
1038
|
+
const directRequestIds = /* @__PURE__ */ new Set();
|
|
1039
|
+
if (directModule.id) directRequestIds.add(directModule.id);
|
|
1040
|
+
if (directModule.url) directRequestIds.add(directModule.url);
|
|
1041
|
+
const requestPath = directModule.id ? getFilenameFromPath(directModule.id) : void 0;
|
|
1042
|
+
const sourcePath = requestPath ? stylesheetRegistry?.resolveExternalSource(requestPath) ?? stylesheetRegistry?.resolveExternalSource(requestPath.replace(/^\//, "")) : void 0;
|
|
1043
|
+
for (const requestId of stylesheetRegistry?.getRequestIdsForSource(sourcePath ?? "") ?? []) if (requestId.includes("?ngcomp=")) directRequestIds.add(requestId);
|
|
1044
|
+
const candidateWrapperIds = [...directRequestIds].filter((id) => id.includes("?direct&ngcomp=")).map((id) => id.replace("?direct&ngcomp=", "?ngcomp="));
|
|
1045
|
+
const lookupHits = [];
|
|
1046
|
+
for (const candidate of candidateWrapperIds) {
|
|
1047
|
+
const mod = await server.moduleGraph.getModuleByUrl(candidate) ?? server.moduleGraph.getModuleById(candidate);
|
|
1048
|
+
lookupHits.push({
|
|
1049
|
+
candidate,
|
|
1050
|
+
via: mod?.url === candidate ? "url" : mod ? "id" : void 0,
|
|
1051
|
+
moduleId: mod?.id,
|
|
1052
|
+
moduleType: mod?.type
|
|
1053
|
+
});
|
|
1054
|
+
if (mod?.id && mod.type === "js" && isComponentStyleSheet(mod.id) && isModuleForChangedResource(mod, changedFile, stylesheetRegistry)) wrapperModules.set(mod.id, mod);
|
|
1055
|
+
}
|
|
1056
|
+
debugHmrV("component stylesheet wrapper lookup", {
|
|
1057
|
+
file: changedFile,
|
|
1058
|
+
sourcePath,
|
|
1059
|
+
directModuleId: directModule.id,
|
|
1060
|
+
directModuleUrl: directModule.url,
|
|
1061
|
+
candidateWrapperIds,
|
|
1062
|
+
lookupHits
|
|
1063
|
+
});
|
|
1064
|
+
if (wrapperModules.size === 0) debugHmrV("component stylesheet wrapper lookup empty", {
|
|
1065
|
+
file: changedFile,
|
|
1066
|
+
sourcePath,
|
|
1067
|
+
directModuleId: directModule.id,
|
|
1068
|
+
directModuleUrl: directModule.url,
|
|
1069
|
+
candidateWrapperIds
|
|
1070
|
+
});
|
|
1071
|
+
return [...wrapperModules.values()];
|
|
864
1072
|
}
|
|
865
1073
|
function sendHMRComponentUpdate(server, id) {
|
|
866
|
-
|
|
867
|
-
|
|
868
|
-
|
|
869
|
-
|
|
870
|
-
|
|
1074
|
+
debugHmrV("ws send: angular component update", {
|
|
1075
|
+
id,
|
|
1076
|
+
timestamp: Date.now()
|
|
1077
|
+
});
|
|
1078
|
+
server.ws.send("angular:component-update", {
|
|
1079
|
+
id: encodeURIComponent(id),
|
|
1080
|
+
timestamp: Date.now()
|
|
1081
|
+
});
|
|
1082
|
+
classNames.delete(id);
|
|
871
1083
|
}
|
|
872
|
-
|
|
873
|
-
|
|
874
|
-
|
|
875
|
-
|
|
876
|
-
|
|
877
|
-
|
|
878
|
-
|
|
879
|
-
|
|
880
|
-
|
|
881
|
-
|
|
882
|
-
|
|
883
|
-
|
|
884
|
-
|
|
885
|
-
|
|
886
|
-
|
|
887
|
-
.map((d) => d.messageText);
|
|
888
|
-
let hmrUpdateCode = undefined;
|
|
889
|
-
let hmrEligible = false;
|
|
890
|
-
if (liveReload) {
|
|
891
|
-
for (const node of sourceFile.statements) {
|
|
892
|
-
if (ts.isClassDeclaration(node) && node.name != null) {
|
|
893
|
-
hmrUpdateCode = angularCompiler?.emitHmrUpdateModule(node);
|
|
894
|
-
if (hmrUpdateCode) {
|
|
895
|
-
classNames.set(file, node.name.getText());
|
|
896
|
-
hmrEligible = true;
|
|
897
|
-
}
|
|
898
|
-
}
|
|
899
|
-
}
|
|
900
|
-
}
|
|
901
|
-
return { errors, warnings, hmrUpdateCode, hmrEligible };
|
|
902
|
-
};
|
|
1084
|
+
function sendCssUpdate(server, update) {
|
|
1085
|
+
const timestamp = Date.now();
|
|
1086
|
+
debugHmrV("ws send: css-update", {
|
|
1087
|
+
...update,
|
|
1088
|
+
timestamp
|
|
1089
|
+
});
|
|
1090
|
+
server.ws.send({
|
|
1091
|
+
type: "update",
|
|
1092
|
+
updates: [{
|
|
1093
|
+
type: "css-update",
|
|
1094
|
+
timestamp,
|
|
1095
|
+
path: update.path,
|
|
1096
|
+
acceptedPath: update.acceptedPath
|
|
1097
|
+
}]
|
|
1098
|
+
});
|
|
903
1099
|
}
|
|
904
|
-
function
|
|
905
|
-
|
|
906
|
-
|
|
907
|
-
|
|
908
|
-
// So always show these types of errors regardless if type checking is disabled
|
|
909
|
-
return syntacticDiagnostics;
|
|
910
|
-
}
|
|
911
|
-
const semanticDiagnostics = program.getSemanticDiagnostics(sourceFile);
|
|
912
|
-
const angularDiagnostics = angularCompiler
|
|
913
|
-
? angularCompiler.getDiagnosticsForFile(sourceFile, 1)
|
|
914
|
-
: [];
|
|
915
|
-
return [
|
|
916
|
-
...syntacticDiagnostics,
|
|
917
|
-
...semanticDiagnostics,
|
|
918
|
-
...angularDiagnostics,
|
|
919
|
-
];
|
|
1100
|
+
function sendFullReload(server, details) {
|
|
1101
|
+
debugHmrV("ws send: full-reload", details);
|
|
1102
|
+
server.ws.send("analog:debug-full-reload", details);
|
|
1103
|
+
server.ws.send({ type: "full-reload" });
|
|
920
1104
|
}
|
|
921
|
-
function
|
|
922
|
-
|
|
923
|
-
|
|
924
|
-
|
|
925
|
-
|
|
926
|
-
return {
|
|
927
|
-
...mod,
|
|
928
|
-
isSelfAccepting: true,
|
|
929
|
-
};
|
|
1105
|
+
function resolveComponentClassNamesForStyleOwner(ownerFile, sourcePath) {
|
|
1106
|
+
if (!existsSync(ownerFile)) return [];
|
|
1107
|
+
const components = getAngularComponentMetadata(readFileSync(ownerFile, "utf-8"));
|
|
1108
|
+
const normalizedSourcePath = normalizePath(sourcePath);
|
|
1109
|
+
return components.filter((component) => component.styleUrls.some((styleUrl) => normalizePath(resolve(dirname(ownerFile), styleUrl)) === normalizedSourcePath)).map((component) => component.className);
|
|
930
1110
|
}
|
|
931
|
-
function
|
|
932
|
-
|
|
1111
|
+
function logComponentStylesheetHmrOutcome(details) {
|
|
1112
|
+
const pitfalls = [];
|
|
1113
|
+
const rejectedPreferredPaths = [];
|
|
1114
|
+
const hints = [];
|
|
1115
|
+
if (details.encapsulation === "shadow") {
|
|
1116
|
+
pitfalls.push("shadow-encapsulation");
|
|
1117
|
+
rejectedPreferredPaths.push("css-update");
|
|
1118
|
+
rejectedPreferredPaths.push("owner-component-update");
|
|
1119
|
+
hints.push("Shadow DOM styles cannot rely on Vite CSS patching because Angular applies them inside a shadow root.");
|
|
1120
|
+
}
|
|
1121
|
+
if (details.diagnosis.anomalies.includes("wrapper_not_yet_tracked")) {
|
|
1122
|
+
pitfalls.push("wrapper-not-yet-tracked");
|
|
1123
|
+
rejectedPreferredPaths.push("css-update");
|
|
1124
|
+
hints.push("The direct stylesheet module exists, but the browser-visible Angular wrapper module was not available in the live graph during this HMR pass.");
|
|
1125
|
+
}
|
|
1126
|
+
if (details.diagnosis.anomalies.includes("tracked_wrapper_missing_from_module_graph")) {
|
|
1127
|
+
pitfalls.push("tracked-wrapper-missing-from-module-graph");
|
|
1128
|
+
rejectedPreferredPaths.push("css-update");
|
|
1129
|
+
hints.push("A wrapper request id is known, but Vite could not resolve a live wrapper module for targeted CSS HMR.");
|
|
1130
|
+
}
|
|
1131
|
+
if ((details.ownerIds?.filter(Boolean).length ?? 0) === 0) {
|
|
1132
|
+
pitfalls.push("no-owner-modules");
|
|
1133
|
+
if (details.outcome === "full-reload") {
|
|
1134
|
+
rejectedPreferredPaths.push("owner-component-update");
|
|
1135
|
+
hints.push("No owning TS component modules were available in the module graph for owner-based fallback.");
|
|
1136
|
+
}
|
|
1137
|
+
} else if ((details.updateIds?.length ?? 0) === 0) {
|
|
1138
|
+
pitfalls.push("owner-modules-without-class-identities");
|
|
1139
|
+
if (details.outcome === "full-reload") {
|
|
1140
|
+
rejectedPreferredPaths.push("owner-component-update");
|
|
1141
|
+
hints.push("Owner modules were found, but Angular did not expose component class identities after recompilation, so no targeted component update could be sent.");
|
|
1142
|
+
}
|
|
1143
|
+
}
|
|
1144
|
+
debugHmrV("component stylesheet hmr outcome", {
|
|
1145
|
+
file: details.file,
|
|
1146
|
+
outcome: details.outcome,
|
|
1147
|
+
encapsulation: details.encapsulation,
|
|
1148
|
+
directModuleId: details.directModuleId,
|
|
1149
|
+
wrapperIds: details.wrapperIds ?? [],
|
|
1150
|
+
ownerIds: details.ownerIds ?? [],
|
|
1151
|
+
updateIds: details.updateIds ?? [],
|
|
1152
|
+
preferredPath: details.encapsulation === "shadow" ? "full-reload" : "css-update",
|
|
1153
|
+
rejectedPreferredPaths: [...new Set(rejectedPreferredPaths)],
|
|
1154
|
+
pitfalls: [...new Set(pitfalls)],
|
|
1155
|
+
anomalies: details.diagnosis.anomalies,
|
|
1156
|
+
hints: [...new Set([...details.diagnosis.hints, ...hints])]
|
|
1157
|
+
});
|
|
933
1158
|
}
|
|
934
|
-
function
|
|
935
|
-
|
|
936
|
-
|
|
937
|
-
|
|
938
|
-
|
|
939
|
-
|
|
940
|
-
|
|
941
|
-
|
|
942
|
-
|
|
943
|
-
|
|
944
|
-
|
|
1159
|
+
function findTemplateOwnerModules(server, resourceFile) {
|
|
1160
|
+
const candidateTsFiles = [normalizePath(resourceFile.split("?")[0]).replace(/\.(html|htm)$/i, ".ts")];
|
|
1161
|
+
const modules = /* @__PURE__ */ new Map();
|
|
1162
|
+
for (const candidate of candidateTsFiles) server.moduleGraph.getModulesByFile(candidate)?.forEach((mod) => {
|
|
1163
|
+
if (mod.id) modules.set(mod.id, mod);
|
|
1164
|
+
});
|
|
1165
|
+
return [...modules.values()];
|
|
1166
|
+
}
|
|
1167
|
+
function findStyleOwnerModules(server, resourceFile, styleSourceOwners) {
|
|
1168
|
+
const normalizedResourceFile = normalizePath(resourceFile.split("?")[0]);
|
|
1169
|
+
const candidateOwnerFiles = [...styleSourceOwners.get(normalizedResourceFile) ?? []];
|
|
1170
|
+
const modules = /* @__PURE__ */ new Map();
|
|
1171
|
+
for (const ownerFile of candidateOwnerFiles) server.moduleGraph.getModulesByFile(ownerFile)?.forEach((mod) => {
|
|
1172
|
+
if (mod.id) modules.set(mod.id, mod);
|
|
1173
|
+
});
|
|
1174
|
+
return [...modules.values()];
|
|
1175
|
+
}
|
|
1176
|
+
function getFileMetadata(program, angularCompiler, hmrEnabled, disableTypeChecking) {
|
|
1177
|
+
const ts = require("typescript");
|
|
1178
|
+
return (file) => {
|
|
1179
|
+
const sourceFile = program.getSourceFile(file);
|
|
1180
|
+
if (!sourceFile) return {};
|
|
1181
|
+
const diagnostics = getDiagnosticsForSourceFile(sourceFile, !!disableTypeChecking, program, angularCompiler);
|
|
1182
|
+
const errors = diagnostics.filter((d) => d.category === ts.DiagnosticCategory?.Error).map((d) => typeof d.messageText === "object" ? d.messageText.messageText : d.messageText);
|
|
1183
|
+
const warnings = diagnostics.filter((d) => d.category === ts.DiagnosticCategory?.Warning).map((d) => d.messageText);
|
|
1184
|
+
let hmrUpdateCode = void 0;
|
|
1185
|
+
let hmrEligible = false;
|
|
1186
|
+
if (hmrEnabled) {
|
|
1187
|
+
for (const node of sourceFile.statements) if (ts.isClassDeclaration(node) && node.name != null) {
|
|
1188
|
+
hmrUpdateCode = angularCompiler?.emitHmrUpdateModule(node);
|
|
1189
|
+
if (hmrUpdateCode) {
|
|
1190
|
+
const className = node.name.getText();
|
|
1191
|
+
classNames.set(file, className);
|
|
1192
|
+
hmrEligible = true;
|
|
1193
|
+
debugHmr("NgtscProgram emitHmrUpdateModule", {
|
|
1194
|
+
file,
|
|
1195
|
+
className
|
|
1196
|
+
});
|
|
1197
|
+
}
|
|
1198
|
+
}
|
|
1199
|
+
}
|
|
1200
|
+
return {
|
|
1201
|
+
errors,
|
|
1202
|
+
warnings,
|
|
1203
|
+
hmrUpdateCode,
|
|
1204
|
+
hmrEligible
|
|
1205
|
+
};
|
|
1206
|
+
};
|
|
1207
|
+
}
|
|
1208
|
+
function getDiagnosticsForSourceFile(sourceFile, disableTypeChecking, program, angularCompiler) {
|
|
1209
|
+
const syntacticDiagnostics = program.getSyntacticDiagnostics(sourceFile);
|
|
1210
|
+
if (disableTypeChecking) return syntacticDiagnostics;
|
|
1211
|
+
const semanticDiagnostics = program.getSemanticDiagnostics(sourceFile);
|
|
1212
|
+
const angularDiagnostics = angularCompiler ? angularCompiler.getDiagnosticsForFile(sourceFile, 1) : [];
|
|
1213
|
+
return [
|
|
1214
|
+
...syntacticDiagnostics,
|
|
1215
|
+
...semanticDiagnostics,
|
|
1216
|
+
...angularDiagnostics
|
|
1217
|
+
];
|
|
1218
|
+
}
|
|
1219
|
+
function markModuleSelfAccepting(mod) {
|
|
1220
|
+
if ("_clientModule" in mod) mod["_clientModule"].isSelfAccepting = true;
|
|
1221
|
+
return {
|
|
1222
|
+
...mod,
|
|
1223
|
+
isSelfAccepting: true
|
|
1224
|
+
};
|
|
945
1225
|
}
|
|
946
1226
|
/**
|
|
947
|
-
|
|
948
|
-
|
|
949
|
-
|
|
950
|
-
|
|
1227
|
+
* Removes leading / and query string from a url path
|
|
1228
|
+
* e.g. /foo.scss?direct&ngcomp=ng-c3153525609&e=0 returns foo.scss
|
|
1229
|
+
* @param id
|
|
1230
|
+
*/
|
|
951
1231
|
function getFilenameFromPath(id) {
|
|
952
|
-
|
|
1232
|
+
try {
|
|
1233
|
+
return new URL(id, "http://localhost").pathname.replace(/^\//, "");
|
|
1234
|
+
} catch {
|
|
1235
|
+
const queryIndex = id.indexOf("?");
|
|
1236
|
+
return (queryIndex >= 0 ? id.slice(0, queryIndex) : id).replace(/^\//, "");
|
|
1237
|
+
}
|
|
953
1238
|
}
|
|
954
1239
|
/**
|
|
955
|
-
|
|
956
|
-
|
|
957
|
-
|
|
958
|
-
|
|
959
|
-
|
|
960
|
-
|
|
961
|
-
if (hasRun) {
|
|
962
|
-
return false;
|
|
963
|
-
}
|
|
964
|
-
// vitest --no-run
|
|
965
|
-
const hasNoRun = args.find((arg) => arg.includes('--no-run'));
|
|
966
|
-
if (hasNoRun) {
|
|
967
|
-
return true;
|
|
968
|
-
}
|
|
969
|
-
// check for --watch=false or --no-watch
|
|
970
|
-
const hasWatch = args.find((arg) => arg.includes('watch'));
|
|
971
|
-
if (hasWatch && ['false', 'no'].some((neg) => hasWatch.includes(neg))) {
|
|
972
|
-
return false;
|
|
973
|
-
}
|
|
974
|
-
// check for --watch false
|
|
975
|
-
const watchIndex = args.findIndex((arg) => arg.includes('watch'));
|
|
976
|
-
const watchArg = args[watchIndex + 1];
|
|
977
|
-
if (watchArg && watchArg === 'false') {
|
|
978
|
-
return false;
|
|
979
|
-
}
|
|
980
|
-
return true;
|
|
981
|
-
}
|
|
1240
|
+
* Checks for vitest run from the command line
|
|
1241
|
+
* @returns boolean
|
|
1242
|
+
*/
|
|
1243
|
+
//#endregion
|
|
1244
|
+
export { angular };
|
|
1245
|
+
|
|
982
1246
|
//# sourceMappingURL=angular-vite-plugin.js.map
|