@analogjs/vite-plugin-angular 3.0.0-beta.5 → 3.0.0-beta.50

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 (133) hide show
  1. package/migrations/migrate-setup-vitest/migrate-setup-vitest.js +2 -1
  2. package/migrations/migrate-setup-vitest/migrate-setup-vitest.js.map +1 -1
  3. package/ngp/LICENSE +21 -0
  4. package/ngp/api.mjs +46806 -0
  5. package/ngp/build.json +4 -0
  6. package/ngp/ng_analyze.cjs +601 -0
  7. package/ngp/ng_analyze_bg.wasm +0 -0
  8. package/package.json +4 -1
  9. package/src/index.d.ts +2 -0
  10. package/src/index.js +3 -1
  11. package/src/index.js.map +1 -1
  12. package/src/lib/analog-plugin-interop.js +1 -1
  13. package/src/lib/angular-build-context.d.ts +215 -0
  14. package/src/lib/angular-build-context.js +361 -0
  15. package/src/lib/angular-build-context.js.map +1 -0
  16. package/src/lib/angular-build-optimizer-plugin.d.ts +6 -4
  17. package/src/lib/angular-build-optimizer-plugin.js +24 -9
  18. package/src/lib/angular-build-optimizer-plugin.js.map +1 -1
  19. package/src/lib/angular-jit-plugin.d.ts +5 -3
  20. package/src/lib/angular-jit-plugin.js +14 -6
  21. package/src/lib/angular-jit-plugin.js.map +1 -1
  22. package/src/lib/angular-vite-plugin.d.ts +6 -109
  23. package/src/lib/angular-vite-plugin.js +8 -1249
  24. package/src/lib/angular-vite-plugin.js.map +1 -1
  25. package/src/lib/angular-vitest-plugin.d.ts +3 -2
  26. package/src/lib/angular-vitest-plugin.js +6 -3
  27. package/src/lib/angular-vitest-plugin.js.map +1 -1
  28. package/src/lib/companion-plugins.d.ts +7 -0
  29. package/src/lib/companion-plugins.js +38 -0
  30. package/src/lib/companion-plugins.js.map +1 -0
  31. package/src/lib/compilation-api/compilation-api-plugin.d.ts +11 -2
  32. package/src/lib/compilation-api/compilation-api-plugin.js +154 -282
  33. package/src/lib/compilation-api/compilation-api-plugin.js.map +1 -1
  34. package/src/lib/compiler/compile.d.ts +1 -1
  35. package/src/lib/compiler/compile.js +190 -145
  36. package/src/lib/compiler/compile.js.map +1 -1
  37. package/src/lib/compiler/defer.d.ts +2 -3
  38. package/src/lib/compiler/defer.js +12 -14
  39. package/src/lib/compiler/defer.js.map +1 -1
  40. package/src/lib/compiler/dts-reader.d.ts +6 -1
  41. package/src/lib/compiler/dts-reader.js +19 -10
  42. package/src/lib/compiler/dts-reader.js.map +1 -1
  43. package/src/lib/compiler/hmr.d.ts +4 -0
  44. package/src/lib/compiler/hmr.js +7 -2
  45. package/src/lib/compiler/hmr.js.map +1 -1
  46. package/src/lib/compiler/index.d.ts +2 -2
  47. package/src/lib/compiler/index.js +4 -4
  48. package/src/lib/compiler/jit-metadata.d.ts +3 -1
  49. package/src/lib/compiler/jit-metadata.js +10 -8
  50. package/src/lib/compiler/jit-metadata.js.map +1 -1
  51. package/src/lib/compiler/jit-transform.js +2 -2
  52. package/src/lib/compiler/jit-transform.js.map +1 -1
  53. package/src/lib/compiler/js-emitter.d.ts +0 -3
  54. package/src/lib/compiler/js-emitter.js +3 -21
  55. package/src/lib/compiler/js-emitter.js.map +1 -1
  56. package/src/lib/compiler/registry.d.ts +7 -1
  57. package/src/lib/compiler/registry.js +23 -3
  58. package/src/lib/compiler/registry.js.map +1 -1
  59. package/src/lib/compiler/resource-inliner.d.ts +8 -9
  60. package/src/lib/compiler/resource-inliner.js +10 -18
  61. package/src/lib/compiler/resource-inliner.js.map +1 -1
  62. package/src/lib/compiler/style-ast.d.ts +9 -1
  63. package/src/lib/compiler/style-ast.js +26 -5
  64. package/src/lib/compiler/style-ast.js.map +1 -1
  65. package/src/lib/compiler/type-elision.d.ts +4 -3
  66. package/src/lib/compiler/type-elision.js +10 -11
  67. package/src/lib/compiler/type-elision.js.map +1 -1
  68. package/src/lib/compiler/utils.d.ts +9 -7
  69. package/src/lib/compiler/utils.js +49 -9
  70. package/src/lib/compiler/utils.js.map +1 -1
  71. package/src/lib/component-scanner.d.ts +74 -0
  72. package/src/lib/component-scanner.js +178 -0
  73. package/src/lib/component-scanner.js.map +1 -0
  74. package/src/lib/component-styles-plugin.d.ts +52 -0
  75. package/src/lib/component-styles-plugin.js +353 -0
  76. package/src/lib/component-styles-plugin.js.map +1 -0
  77. package/src/lib/compose-angular-plugins.d.ts +12 -0
  78. package/src/lib/compose-angular-plugins.js +31 -0
  79. package/src/lib/compose-angular-plugins.js.map +1 -0
  80. package/src/lib/dev-server-mode-plugin.d.ts +7 -0
  81. package/src/lib/dev-server-mode-plugin.js +23 -0
  82. package/src/lib/dev-server-mode-plugin.js.map +1 -0
  83. package/src/lib/fast-compile-api.d.ts +62 -0
  84. package/src/lib/fast-compile-api.js +12 -0
  85. package/src/lib/fast-compile-api.js.map +1 -0
  86. package/src/lib/fast-compile-plugin.d.ts +6 -1
  87. package/src/lib/fast-compile-plugin.js +167 -107
  88. package/src/lib/fast-compile-plugin.js.map +1 -1
  89. package/src/lib/host.d.ts +3 -0
  90. package/src/lib/host.js +4 -2
  91. package/src/lib/host.js.map +1 -1
  92. package/src/lib/live-reload-plugin.d.ts +6 -3
  93. package/src/lib/live-reload-plugin.js +13 -6
  94. package/src/lib/live-reload-plugin.js.map +1 -1
  95. package/src/lib/ngp-compile-api.d.ts +55 -0
  96. package/src/lib/ngp-compile-api.js +12 -0
  97. package/src/lib/ngp-compile-api.js.map +1 -0
  98. package/src/lib/ngp-compile-plugin.d.ts +4 -0
  99. package/src/lib/ngp-compile-plugin.js +662 -0
  100. package/src/lib/ngp-compile-plugin.js.map +1 -0
  101. package/src/lib/ngtsc-compile-plugin.d.ts +23 -0
  102. package/src/lib/ngtsc-compile-plugin.js +778 -0
  103. package/src/lib/ngtsc-compile-plugin.js.map +1 -0
  104. package/src/lib/nx-folder-plugin.d.ts +6 -5
  105. package/src/lib/nx-folder-plugin.js +12 -7
  106. package/src/lib/nx-folder-plugin.js.map +1 -1
  107. package/src/lib/plugins/file-replacements.plugin.d.ts +6 -0
  108. package/src/lib/plugins/file-replacements.plugin.js +1 -0
  109. package/src/lib/plugins/file-replacements.plugin.js.map +1 -1
  110. package/src/lib/router-plugin.d.ts +5 -1
  111. package/src/lib/router-plugin.js +13 -4
  112. package/src/lib/router-plugin.js.map +1 -1
  113. package/src/lib/utils/compilation-shared.js +1 -1
  114. package/src/lib/utils/devkit.js +1 -1
  115. package/src/lib/utils/hmr-component-updates.d.ts +7 -0
  116. package/src/lib/utils/hmr-component-updates.js +87 -0
  117. package/src/lib/utils/hmr-component-updates.js.map +1 -0
  118. package/src/lib/utils/lsp-type-checker.d.ts +75 -0
  119. package/src/lib/utils/lsp-type-checker.js +531 -0
  120. package/src/lib/utils/lsp-type-checker.js.map +1 -0
  121. package/src/lib/utils/ngp-host-fs.d.ts +32 -0
  122. package/src/lib/utils/ngp-host-fs.js +104 -0
  123. package/src/lib/utils/ngp-host-fs.js.map +1 -0
  124. package/src/lib/utils/plugin-config.d.ts +15 -8
  125. package/src/lib/utils/plugin-config.js +18 -5
  126. package/src/lib/utils/plugin-config.js.map +1 -1
  127. package/src/lib/utils/stylesheet-warning.d.ts +2 -0
  128. package/src/lib/utils/stylesheet-warning.js +11 -0
  129. package/src/lib/utils/stylesheet-warning.js.map +1 -0
  130. package/src/lib/utils/tsconfig-resolver.js +1 -1
  131. package/src/lib/virtual-modules-plugin.d.ts +11 -3
  132. package/src/lib/virtual-modules-plugin.js +43 -12
  133. package/src/lib/virtual-modules-plugin.js.map +1 -1
@@ -0,0 +1,353 @@
1
+ import { debugHmr, debugHmrV, debugStylesV } from "./utils/debug.js";
2
+ import { getComponentStyleSheetMeta, isComponentStyleSheet } from "./encapsulation-plugin.js";
3
+ import { preprocessStylesheet, rewriteRelativeCssImports } from "./stylesheet-registry.js";
4
+ import { describeStylesheetContent } from "./utils/compilation-shared.js";
5
+ import { ensureAngularBuildContext, getFilenameFromPath } from "./angular-build-context.js";
6
+ import { union } from "es-toolkit";
7
+ import { existsSync, readFileSync } from "node:fs";
8
+ import { normalizePath } from "vite";
9
+ //#region packages/vite-plugin-angular/src/lib/component-styles-plugin.ts
10
+ /**
11
+ * Self-contained Vite plugin that resolves and serves externalized Angular
12
+ * component stylesheets (`?ngcomp=...`) from the shared `AngularBuildContext`
13
+ * stylesheet registry and refreshes served records on source CSS edits.
14
+ */
15
+ function componentStylesPlugin(ctxOrOptions) {
16
+ const ctx = ensureAngularBuildContext(ctxOrOptions);
17
+ return {
18
+ name: "@analogjs/vite-plugin-angular:component-styles",
19
+ enforce: "pre",
20
+ async configResolved(config) {
21
+ await ctx.resolveConfig(config);
22
+ },
23
+ resolveId(id) {
24
+ return ctx.styles.resolveComponentStyleId(id);
25
+ },
26
+ load(id) {
27
+ return ctx.styles.loadComponentStyle(id);
28
+ },
29
+ handleHotUpdate(hmrCtx) {
30
+ if (/\.(css|less|sass|scss)$/.test(hmrCtx.file)) {
31
+ debugHmr("stylesheet file changed", { file: hmrCtx.file });
32
+ ctx.styles.refreshForFile(hmrCtx.file);
33
+ }
34
+ }
35
+ };
36
+ }
37
+ function markModuleSelfAccepting(mod) {
38
+ if ("_clientModule" in mod) mod["_clientModule"].isSelfAccepting = true;
39
+ return {
40
+ ...mod,
41
+ isSelfAccepting: true
42
+ };
43
+ }
44
+ /**
45
+ * Returns every live Vite module that can legitimately represent a changed
46
+ * Angular resource file.
47
+ *
48
+ * For normal files, `getModulesByFile()` is enough. For Angular component
49
+ * stylesheets, it is not: the browser often holds virtual hashed requests
50
+ * (`/abc123.css?direct&ngcomp=...` and `/abc123.css?ngcomp=...`) that are no
51
+ * longer discoverable from the original source path alone. We therefore merge:
52
+ * - watcher event modules
53
+ * - module-graph modules by source file
54
+ * - registry-tracked live request ids resolved back through the module graph
55
+ */
56
+ async function getModulesForChangedFile(server, file, eventModules = [], stylesheetRegistry) {
57
+ const normalizedFile = normalizePath(file.split("?")[0]);
58
+ const modules = /* @__PURE__ */ new Map();
59
+ for (const mod of eventModules) if (mod.id) modules.set(mod.id, mod);
60
+ server.moduleGraph.getModulesByFile(normalizedFile)?.forEach((mod) => {
61
+ if (mod.id) modules.set(mod.id, mod);
62
+ });
63
+ const stylesheetRequestIds = stylesheetRegistry?.getRequestIdsForSource(normalizedFile) ?? [];
64
+ const requestIdHits = [];
65
+ for (const requestId of stylesheetRequestIds) {
66
+ const candidates = [requestId, requestId.startsWith("/") ? requestId : `/${requestId}`];
67
+ for (const candidate of candidates) {
68
+ const mod = await server.moduleGraph.getModuleByUrl(candidate) ?? server.moduleGraph.getModuleById(candidate);
69
+ requestIdHits.push({
70
+ requestId,
71
+ candidate,
72
+ via: mod?.url === candidate ? "url" : "id",
73
+ moduleId: mod?.id ?? void 0
74
+ });
75
+ if (mod?.id) modules.set(mod.id, mod);
76
+ }
77
+ }
78
+ debugHmrV("getModulesForChangedFile registry lookup", {
79
+ file: normalizedFile,
80
+ stylesheetRequestIds,
81
+ requestIdHits,
82
+ resolvedModuleIds: [...modules.keys()]
83
+ });
84
+ return [...modules.values()];
85
+ }
86
+ function isModuleForChangedResource(mod, changedFile, stylesheetRegistry) {
87
+ const normalizedChangedFile = normalizePath(changedFile.split("?")[0]);
88
+ if (normalizePath((mod.file ?? "").split("?")[0]) === normalizedChangedFile) return true;
89
+ if (!mod.id) return false;
90
+ const requestPath = getFilenameFromPath(mod.id);
91
+ const sourcePath = stylesheetRegistry?.resolveExternalSource(requestPath) ?? stylesheetRegistry?.resolveExternalSource(requestPath.replace(/^\//, "")) ?? stylesheetRegistry?.getServedSourcePath(requestPath) ?? stylesheetRegistry?.getServedSourcePath(requestPath.replace(/^\//, ""));
92
+ return normalizePath((sourcePath ?? "").split("?")[0]) === normalizedChangedFile;
93
+ }
94
+ function resolveDirectStylesheetSourcePath(normalizedFile, directModule, stylesheetRegistry) {
95
+ const directRequestPath = directModule.id ? getFilenameFromPath(directModule.id) : void 0;
96
+ return {
97
+ directRequestPath,
98
+ sourcePath: directRequestPath ? stylesheetRegistry?.resolveExternalSource(directRequestPath) ?? stylesheetRegistry?.resolveExternalSource(directRequestPath.replace(/^\//, "")) ?? stylesheetRegistry?.getServedSourcePath(directRequestPath) ?? stylesheetRegistry?.getServedSourcePath(directRequestPath.replace(/^\//, "")) : normalizedFile
99
+ };
100
+ }
101
+ function diagnoseComponentStylesheetPipeline(changedFile, directModule, stylesheetRegistry, wrapperModules, stylePreprocessor) {
102
+ const normalizedFile = normalizePath(changedFile.split("?")[0]);
103
+ const sourceExists = existsSync(normalizedFile);
104
+ const sourceCode = sourceExists ? readFileSync(normalizedFile, "utf-8") : void 0;
105
+ const { directRequestPath, sourcePath } = resolveDirectStylesheetSourcePath(normalizedFile, directModule, stylesheetRegistry);
106
+ const registryCode = directRequestPath ? stylesheetRegistry?.getServedContent(directRequestPath) : void 0;
107
+ const trackedRequestIds = stylesheetRegistry?.getRequestIdsForSource(sourcePath ?? "") ?? [];
108
+ const dependencies = stylesheetRegistry?.getDependenciesForSource(sourcePath ?? "") ?? [];
109
+ const diagnostics = stylesheetRegistry?.getDiagnosticsForSource(sourcePath ?? "") ?? [];
110
+ const tags = stylesheetRegistry?.getTagsForSource(sourcePath ?? "") ?? [];
111
+ const anomalies = [];
112
+ const hints = [];
113
+ if (!sourceExists) {
114
+ anomalies.push("source_file_missing");
115
+ hints.push("The stylesheet watcher fired for a file that no longer exists on disk.");
116
+ }
117
+ if (!registryCode) {
118
+ anomalies.push("registry_content_missing");
119
+ hints.push("The stylesheet registry has no served content for the direct module request path.");
120
+ }
121
+ const registryDescription = registryCode ? describeStylesheetContent(registryCode) : void 0;
122
+ let sourceDescription;
123
+ if (sourceCode !== void 0) try {
124
+ let expectedRegistryCode = preprocessStylesheet(sourceCode, normalizedFile, stylePreprocessor);
125
+ expectedRegistryCode = rewriteRelativeCssImports(expectedRegistryCode, normalizedFile);
126
+ sourceDescription = describeStylesheetContent(expectedRegistryCode);
127
+ } catch {
128
+ anomalies.push("source_preprocess_failed");
129
+ hints.push("Diagnostic preprocessing of the source stylesheet failed; falling back to raw source summary.");
130
+ sourceDescription = describeStylesheetContent(sourceCode);
131
+ }
132
+ if (sourceDescription && registryDescription && !anomalies.includes("source_preprocess_failed") && sourceDescription.digest !== registryDescription.digest) {
133
+ anomalies.push("source_registry_mismatch");
134
+ hints.push("The source file changed, but the served stylesheet content in the registry is still stale.");
135
+ }
136
+ if (trackedRequestIds.length === 0) {
137
+ anomalies.push("no_tracked_requests");
138
+ hints.push("No live stylesheet requests are tracked for this source file, so HMR has no browser-facing target.");
139
+ }
140
+ if (trackedRequestIds.some((id) => id.includes("?ngcomp=")) && wrapperModules.length === 0) {
141
+ anomalies.push("tracked_wrapper_missing_from_module_graph");
142
+ hints.push("A wrapper request id is known, but Vite did not expose a live wrapper module during this HMR pass.");
143
+ }
144
+ if (trackedRequestIds.every((id) => !id.includes("?ngcomp=")) && wrapperModules.length === 0) {
145
+ anomalies.push("wrapper_not_yet_tracked");
146
+ hints.push("Only direct stylesheet requests were tracked during this HMR pass; the wrapper request may be appearing too late.");
147
+ }
148
+ return {
149
+ file: changedFile,
150
+ sourcePath,
151
+ source: sourceDescription,
152
+ registry: registryDescription,
153
+ dependencies,
154
+ diagnostics,
155
+ tags,
156
+ directModuleId: directModule.id ?? void 0,
157
+ directModuleUrl: directModule.url,
158
+ trackedRequestIds,
159
+ wrapperCount: wrapperModules.length,
160
+ anomalies,
161
+ hints
162
+ };
163
+ }
164
+ async function findComponentStylesheetWrapperModules(server, changedFile, directModule, fileModules, stylesheetRegistry) {
165
+ const wrapperModules = /* @__PURE__ */ new Map();
166
+ for (const mod of fileModules) if (mod.id && mod.type === "js" && isComponentStyleSheet(mod.id) && isModuleForChangedResource(mod, changedFile, stylesheetRegistry)) wrapperModules.set(mod.id, mod);
167
+ const directRequestIds = /* @__PURE__ */ new Set();
168
+ if (directModule.id) directRequestIds.add(directModule.id);
169
+ if (directModule.url) directRequestIds.add(directModule.url);
170
+ const requestPath = directModule.id ? getFilenameFromPath(directModule.id) : void 0;
171
+ const sourcePath = requestPath ? stylesheetRegistry?.resolveExternalSource(requestPath) ?? stylesheetRegistry?.resolveExternalSource(requestPath.replace(/^\//, "")) ?? stylesheetRegistry?.getServedSourcePath(requestPath) ?? stylesheetRegistry?.getServedSourcePath(requestPath.replace(/^\//, "")) : void 0;
172
+ for (const requestId of stylesheetRegistry?.getRequestIdsForSource(sourcePath ?? "") ?? []) if (requestId.includes("?ngcomp=")) directRequestIds.add(requestId);
173
+ const candidateWrapperIds = [...directRequestIds].filter((id) => id.includes("?direct&ngcomp=")).map((id) => id.replace("?direct&ngcomp=", "?ngcomp="));
174
+ const lookupHits = [];
175
+ for (const candidate of candidateWrapperIds) {
176
+ const mod = await server.moduleGraph.getModuleByUrl(candidate) ?? server.moduleGraph.getModuleById(candidate);
177
+ lookupHits.push({
178
+ candidate,
179
+ via: mod?.url === candidate ? "url" : mod ? "id" : void 0,
180
+ moduleId: mod?.id ?? void 0,
181
+ moduleType: mod?.type
182
+ });
183
+ if (mod?.id && mod.type === "js" && isComponentStyleSheet(mod.id) && isModuleForChangedResource(mod, changedFile, stylesheetRegistry)) wrapperModules.set(mod.id, mod);
184
+ }
185
+ debugHmrV("component stylesheet wrapper lookup", {
186
+ file: changedFile,
187
+ sourcePath,
188
+ directModuleId: directModule.id,
189
+ directModuleUrl: directModule.url,
190
+ candidateWrapperIds,
191
+ lookupHits
192
+ });
193
+ if (wrapperModules.size === 0) debugHmrV("component stylesheet wrapper lookup empty", {
194
+ file: changedFile,
195
+ sourcePath,
196
+ directModuleId: directModule.id,
197
+ directModuleUrl: directModule.url,
198
+ candidateWrapperIds
199
+ });
200
+ return [...wrapperModules.values()];
201
+ }
202
+ function findTemplateOwnerModules(server, resourceFile) {
203
+ const candidateTsFiles = [normalizePath(resourceFile.split("?")[0]).replace(/\.(html|htm)$/i, ".ts")];
204
+ const modules = /* @__PURE__ */ new Map();
205
+ for (const candidate of candidateTsFiles) server.moduleGraph.getModulesByFile(candidate)?.forEach((mod) => {
206
+ if (mod.id) modules.set(mod.id, mod);
207
+ });
208
+ return [...modules.values()];
209
+ }
210
+ function sendCssUpdate(server, update) {
211
+ const timestamp = Date.now();
212
+ debugHmrV("ws send: css-update", {
213
+ ...update,
214
+ timestamp
215
+ });
216
+ server.ws.send({
217
+ type: "update",
218
+ updates: [{
219
+ type: "css-update",
220
+ timestamp,
221
+ path: update.path,
222
+ acceptedPath: update.acceptedPath
223
+ }]
224
+ });
225
+ }
226
+ function sendFullReload(server, details) {
227
+ debugHmrV("ws send: full-reload", details);
228
+ server.ws.send("analog:debug-full-reload", details);
229
+ server.ws.send({ type: "full-reload" });
230
+ }
231
+ function logComponentStylesheetHmrOutcome(details) {
232
+ const pitfalls = [];
233
+ const rejectedPreferredPaths = [];
234
+ const hints = [];
235
+ if (details.encapsulation === "shadow") {
236
+ pitfalls.push("shadow-encapsulation");
237
+ rejectedPreferredPaths.push("css-update");
238
+ hints.push("Shadow DOM styles cannot rely on Vite CSS patching because Angular applies them inside a shadow root.");
239
+ }
240
+ if (details.diagnosis.anomalies.includes("wrapper_not_yet_tracked")) {
241
+ pitfalls.push("wrapper-not-yet-tracked");
242
+ rejectedPreferredPaths.push("css-update");
243
+ 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.");
244
+ }
245
+ if (details.diagnosis.anomalies.includes("tracked_wrapper_missing_from_module_graph")) {
246
+ pitfalls.push("tracked-wrapper-missing-from-module-graph");
247
+ rejectedPreferredPaths.push("css-update");
248
+ hints.push("A wrapper request id is known, but Vite could not resolve a live wrapper module for targeted CSS HMR.");
249
+ }
250
+ debugHmrV("component stylesheet hmr outcome", {
251
+ file: details.file,
252
+ outcome: details.outcome,
253
+ encapsulation: details.encapsulation,
254
+ directModuleId: details.directModuleId,
255
+ wrapperIds: details.wrapperIds ?? [],
256
+ preferredPath: details.encapsulation === "shadow" ? "full-reload" : "css-update",
257
+ rejectedPreferredPaths: [...new Set(rejectedPreferredPaths)],
258
+ pitfalls: [...new Set(pitfalls)],
259
+ anomalies: details.diagnosis.anomalies,
260
+ hints: [.../* @__PURE__ */ new Set([...details.diagnosis.hints, ...hints])]
261
+ });
262
+ }
263
+ async function handleDirectComponentStyleHmr(options) {
264
+ const { server, file, directModule, fileModules, stylesheetRegistry, stylePreprocessor } = options;
265
+ const { encapsulation } = getComponentStyleSheetMeta(directModule.id);
266
+ const wrapperModules = await findComponentStylesheetWrapperModules(server, file, directModule, fileModules, stylesheetRegistry);
267
+ const { sourcePath } = resolveDirectStylesheetSourcePath(normalizePath(file.split("?")[0]), directModule, stylesheetRegistry);
268
+ const trackedRequestIds = stylesheetRegistry?.getRequestIdsForSource(sourcePath ?? "") ?? [];
269
+ let stylesheetDiagnosis;
270
+ if (debugHmrV.enabled) try {
271
+ stylesheetDiagnosis = diagnoseComponentStylesheetPipeline(file, directModule, stylesheetRegistry, wrapperModules, stylePreprocessor);
272
+ } catch (error) {
273
+ debugHmrV("component stylesheet pipeline diagnosis failed", {
274
+ file,
275
+ error: error instanceof Error ? error.message : String(error)
276
+ });
277
+ }
278
+ debugStylesV("HMR: component stylesheet changed", {
279
+ file: directModule.file,
280
+ encapsulation
281
+ });
282
+ debugHmrV("component stylesheet wrapper modules", {
283
+ file,
284
+ wrapperCount: wrapperModules.length,
285
+ wrapperIds: wrapperModules.map((mod) => mod.id),
286
+ availableModuleIds: fileModules.map((mod) => mod.id)
287
+ });
288
+ if (stylesheetDiagnosis) debugHmrV("component stylesheet pipeline diagnosis", stylesheetDiagnosis);
289
+ server.moduleGraph.invalidateModule(directModule);
290
+ debugHmrV("component stylesheet direct module invalidated", {
291
+ file,
292
+ directModuleId: directModule.id,
293
+ directModuleUrl: directModule.url,
294
+ reason: "Ensure Vite drops stale direct CSS transform results before wrapper or fallback handling continues."
295
+ });
296
+ const trackedWrapperRequestIds = trackedRequestIds.filter((id) => id.includes("?ngcomp="));
297
+ if (encapsulation !== "shadow" && (wrapperModules.length > 0 || trackedWrapperRequestIds.length > 0)) {
298
+ wrapperModules.forEach((mod) => server.moduleGraph.invalidateModule(mod));
299
+ debugHmrV("sending css-update for component stylesheet", {
300
+ file,
301
+ path: directModule.url,
302
+ acceptedPath: directModule.file,
303
+ wrapperCount: wrapperModules.length,
304
+ trackedWrapperRequestIds,
305
+ 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."
306
+ });
307
+ sendCssUpdate(server, {
308
+ path: directModule.url,
309
+ acceptedPath: directModule.file
310
+ });
311
+ if (stylesheetDiagnosis) logComponentStylesheetHmrOutcome({
312
+ file,
313
+ encapsulation,
314
+ diagnosis: stylesheetDiagnosis,
315
+ outcome: "css-update",
316
+ directModuleId: directModule.id ?? void 0,
317
+ wrapperIds: wrapperModules.map((mod) => mod.id).filter((id) => id !== null)
318
+ });
319
+ return union(fileModules.filter((mod) => {
320
+ return mod.file !== file || mod.id !== directModule.id;
321
+ }).map((mod) => {
322
+ if (mod.file === file) return markModuleSelfAccepting(mod);
323
+ return mod;
324
+ }), wrapperModules.map((mod) => markModuleSelfAccepting(mod)));
325
+ }
326
+ debugHmrV("component stylesheet hmr fallback: full reload", {
327
+ file,
328
+ encapsulation,
329
+ reason: trackedWrapperRequestIds.length === 0 ? "missing-wrapper-module" : encapsulation === "shadow" ? "shadow-encapsulation" : "tracked-wrapper-still-not-patchable",
330
+ directId: directModule.id,
331
+ trackedRequestIds: stylesheetRegistry?.getRequestIdsForSource(file) ?? []
332
+ });
333
+ if (stylesheetDiagnosis) logComponentStylesheetHmrOutcome({
334
+ file,
335
+ encapsulation,
336
+ diagnosis: stylesheetDiagnosis,
337
+ outcome: "full-reload",
338
+ directModuleId: directModule.id ?? void 0,
339
+ wrapperIds: wrapperModules.map((mod) => mod.id).filter((id) => id !== null)
340
+ });
341
+ sendFullReload(server, {
342
+ file,
343
+ encapsulation,
344
+ reason: wrapperModules.length === 0 ? "missing-wrapper-module" : "shadow-encapsulation",
345
+ directId: directModule.id,
346
+ trackedRequestIds: stylesheetRegistry?.getRequestIdsForSource(file) ?? []
347
+ });
348
+ return [];
349
+ }
350
+ //#endregion
351
+ export { componentStylesPlugin, diagnoseComponentStylesheetPipeline, findComponentStylesheetWrapperModules, findTemplateOwnerModules, getModulesForChangedFile, handleDirectComponentStyleHmr, isModuleForChangedResource, markModuleSelfAccepting };
352
+
353
+ //# sourceMappingURL=component-styles-plugin.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"component-styles-plugin.js","names":[],"sources":["../../../src/lib/component-styles-plugin.ts"],"sourcesContent":["import { existsSync, readFileSync } from 'node:fs';\nimport { union } from 'es-toolkit';\nimport {\n normalizePath,\n type ModuleNode,\n type Plugin,\n type ViteDevServer,\n} from 'vite';\n\nimport {\n ensureAngularBuildContext,\n getFilenameFromPath,\n type AngularBuildContext,\n type AngularBuildContextOptions,\n} from './angular-build-context.js';\nimport {\n getComponentStyleSheetMeta,\n isComponentStyleSheet,\n} from './encapsulation-plugin.js';\nimport type {\n StylePreprocessor,\n StylesheetDependency,\n} from './style-preprocessor.js';\nimport {\n AnalogStylesheetRegistry,\n preprocessStylesheet,\n rewriteRelativeCssImports,\n} from './stylesheet-registry.js';\nimport { describeStylesheetContent } from './utils/compilation-shared.js';\nimport { debugHmr, debugHmrV, debugStylesV } from './utils/debug.js';\n\nexport interface ComponentStylesheetPipelineDiagnosis {\n file: string;\n sourcePath?: string;\n source?: ReturnType<typeof describeStylesheetContent>;\n registry?: ReturnType<typeof describeStylesheetContent>;\n dependencies: StylesheetDependency[];\n diagnostics: ReturnType<AnalogStylesheetRegistry['getDiagnosticsForSource']>;\n tags: string[];\n directModuleId?: string;\n directModuleUrl?: string;\n trackedRequestIds: string[];\n wrapperCount: number;\n anomalies: string[];\n hints: string[];\n}\n\n/**\n * Self-contained Vite plugin that resolves and serves externalized Angular\n * component stylesheets (`?ngcomp=...`) from the shared `AngularBuildContext`\n * stylesheet registry and refreshes served records on source CSS edits.\n */\nexport function componentStylesPlugin(\n ctxOrOptions?: AngularBuildContext | AngularBuildContextOptions,\n): Plugin {\n const ctx = ensureAngularBuildContext(ctxOrOptions);\n\n return {\n name: '@analogjs/vite-plugin-angular:component-styles',\n enforce: 'pre',\n async configResolved(config) {\n await ctx.resolveConfig(config);\n },\n resolveId(id) {\n return ctx.styles.resolveComponentStyleId(id);\n },\n load(id) {\n return ctx.styles.loadComponentStyle(id);\n },\n handleHotUpdate(hmrCtx) {\n if (/\\.(css|less|sass|scss)$/.test(hmrCtx.file)) {\n debugHmr('stylesheet file changed', { file: hmrCtx.file });\n ctx.styles.refreshForFile(hmrCtx.file);\n }\n return undefined;\n },\n };\n}\n\nexport function markModuleSelfAccepting(mod: ModuleNode): ModuleNode {\n // support Vite 6\n if ('_clientModule' in mod) {\n (mod as unknown as { _clientModule: { isSelfAccepting: boolean } })[\n '_clientModule'\n ].isSelfAccepting = true;\n }\n\n return {\n ...mod,\n isSelfAccepting: true,\n } as ModuleNode;\n}\n\n/**\n * Returns every live Vite module that can legitimately represent a changed\n * Angular resource file.\n *\n * For normal files, `getModulesByFile()` is enough. For Angular component\n * stylesheets, it is not: the browser often holds virtual hashed requests\n * (`/abc123.css?direct&ngcomp=...` and `/abc123.css?ngcomp=...`) that are no\n * longer discoverable from the original source path alone. We therefore merge:\n * - watcher event modules\n * - module-graph modules by source file\n * - registry-tracked live request ids resolved back through the module graph\n */\nexport async function getModulesForChangedFile(\n server: ViteDevServer,\n file: string,\n eventModules: readonly ModuleNode[] = [],\n stylesheetRegistry?: AnalogStylesheetRegistry,\n): Promise<ModuleNode[]> {\n const normalizedFile = normalizePath(file.split('?')[0]);\n const modules = new Map<string, ModuleNode>();\n\n for (const mod of eventModules) {\n if (mod.id) {\n modules.set(mod.id, mod);\n }\n }\n\n server.moduleGraph.getModulesByFile(normalizedFile)?.forEach((mod) => {\n if (mod.id) {\n modules.set(mod.id, mod);\n }\n });\n\n const stylesheetRequestIds =\n stylesheetRegistry?.getRequestIdsForSource(normalizedFile) ?? [];\n const requestIdHits: Array<{\n requestId: string;\n candidate: string;\n via: 'url' | 'id';\n moduleId?: string;\n }> = [];\n for (const requestId of stylesheetRequestIds) {\n const candidates = [\n requestId,\n requestId.startsWith('/') ? requestId : `/${requestId}`,\n ];\n\n for (const candidate of candidates) {\n // `getModuleByUrl()` is the important lookup here. Angular's wrapper\n // module is served by URL and can be absent from a straight `getModuleById`\n // lookup during CSS HMR, even though it is the browser-visible module\n // that must be refreshed. We keep `getModuleById()` as a compatibility\n // fallback for the simpler direct CSS case.\n const mod =\n (await server.moduleGraph.getModuleByUrl(candidate)) ??\n server.moduleGraph.getModuleById(candidate);\n requestIdHits.push({\n requestId,\n candidate,\n via: mod?.url === candidate ? 'url' : 'id',\n moduleId: mod?.id ?? undefined,\n });\n if (mod?.id) {\n modules.set(mod.id, mod);\n }\n }\n }\n\n debugHmrV('getModulesForChangedFile registry lookup', {\n file: normalizedFile,\n stylesheetRequestIds,\n requestIdHits,\n resolvedModuleIds: [...modules.keys()],\n });\n\n return [...modules.values()];\n}\n\nexport function isModuleForChangedResource(\n mod: ModuleNode,\n changedFile: string,\n stylesheetRegistry?: AnalogStylesheetRegistry,\n): boolean {\n const normalizedChangedFile = normalizePath(changedFile.split('?')[0]);\n\n if (normalizePath((mod.file ?? '').split('?')[0]) === normalizedChangedFile) {\n return true;\n }\n\n if (!mod.id) {\n return false;\n }\n\n // Virtual Angular stylesheet modules do not report the original source file\n // as `mod.file`; they point at the served hashed stylesheet asset instead.\n // Recover the source file through the stylesheet registry so HMR can still\n // answer \"does this live module belong to the resource that just changed?\"\n const requestPath = getFilenameFromPath(mod.id);\n const sourcePath =\n stylesheetRegistry?.resolveExternalSource(requestPath) ??\n stylesheetRegistry?.resolveExternalSource(requestPath.replace(/^\\//, '')) ??\n stylesheetRegistry?.getServedSourcePath(requestPath) ??\n stylesheetRegistry?.getServedSourcePath(requestPath.replace(/^\\//, ''));\n\n return (\n normalizePath((sourcePath ?? '').split('?')[0]) === normalizedChangedFile\n );\n}\n\nfunction resolveDirectStylesheetSourcePath(\n normalizedFile: string,\n directModule: ModuleNode,\n stylesheetRegistry?: AnalogStylesheetRegistry,\n): { directRequestPath?: string; sourcePath: string | undefined } {\n const directRequestPath = directModule.id\n ? getFilenameFromPath(directModule.id)\n : undefined;\n const sourcePath = directRequestPath\n ? (stylesheetRegistry?.resolveExternalSource(directRequestPath) ??\n stylesheetRegistry?.resolveExternalSource(\n directRequestPath.replace(/^\\//, ''),\n ) ??\n stylesheetRegistry?.getServedSourcePath(directRequestPath) ??\n stylesheetRegistry?.getServedSourcePath(\n directRequestPath.replace(/^\\//, ''),\n ))\n : normalizedFile;\n\n return { directRequestPath, sourcePath };\n}\n\nexport function diagnoseComponentStylesheetPipeline(\n changedFile: string,\n directModule: ModuleNode,\n stylesheetRegistry: AnalogStylesheetRegistry | undefined,\n wrapperModules: ModuleNode[],\n stylePreprocessor?: StylePreprocessor,\n): ComponentStylesheetPipelineDiagnosis {\n const normalizedFile = normalizePath(changedFile.split('?')[0]);\n const sourceExists = existsSync(normalizedFile);\n const sourceCode = sourceExists\n ? readFileSync(normalizedFile, 'utf-8')\n : undefined;\n\n const { directRequestPath, sourcePath } = resolveDirectStylesheetSourcePath(\n normalizedFile,\n directModule,\n stylesheetRegistry,\n );\n const registryCode = directRequestPath\n ? stylesheetRegistry?.getServedContent(directRequestPath)\n : undefined;\n const trackedRequestIds =\n stylesheetRegistry?.getRequestIdsForSource(sourcePath ?? '') ?? [];\n const dependencies =\n stylesheetRegistry?.getDependenciesForSource(sourcePath ?? '') ?? [];\n const diagnostics =\n stylesheetRegistry?.getDiagnosticsForSource(sourcePath ?? '') ?? [];\n const tags = stylesheetRegistry?.getTagsForSource(sourcePath ?? '') ?? [];\n\n const anomalies: string[] = [];\n const hints: string[] = [];\n\n if (!sourceExists) {\n anomalies.push('source_file_missing');\n hints.push(\n 'The stylesheet watcher fired for a file that no longer exists on disk.',\n );\n }\n\n if (!registryCode) {\n anomalies.push('registry_content_missing');\n hints.push(\n 'The stylesheet registry has no served content for the direct module request path.',\n );\n }\n\n const registryDescription = registryCode\n ? describeStylesheetContent(registryCode)\n : undefined;\n let sourceDescription:\n | ReturnType<typeof describeStylesheetContent>\n | undefined;\n\n if (sourceCode !== undefined) {\n try {\n // Compare against the same served representation that the registry stores,\n // not the raw file on disk. Analog intentionally prepends `@reference`\n // and rewrites relative imports before the stylesheet reaches Vite, so a\n // raw-source hash comparison would flag a false positive on every healthy\n // update.\n let expectedRegistryCode = preprocessStylesheet(\n sourceCode,\n normalizedFile,\n stylePreprocessor,\n );\n expectedRegistryCode = rewriteRelativeCssImports(\n expectedRegistryCode,\n normalizedFile,\n );\n sourceDescription = describeStylesheetContent(expectedRegistryCode);\n } catch {\n anomalies.push('source_preprocess_failed');\n hints.push(\n 'Diagnostic preprocessing of the source stylesheet failed; falling back to raw source summary.',\n );\n sourceDescription = describeStylesheetContent(sourceCode);\n }\n }\n\n if (\n sourceDescription &&\n registryDescription &&\n !anomalies.includes('source_preprocess_failed') &&\n sourceDescription.digest !== registryDescription.digest\n ) {\n anomalies.push('source_registry_mismatch');\n hints.push(\n 'The source file changed, but the served stylesheet content in the registry is still stale.',\n );\n }\n\n if (trackedRequestIds.length === 0) {\n anomalies.push('no_tracked_requests');\n hints.push(\n 'No live stylesheet requests are tracked for this source file, so HMR has no browser-facing target.',\n );\n }\n\n if (\n trackedRequestIds.some((id) => id.includes('?ngcomp=')) &&\n wrapperModules.length === 0\n ) {\n anomalies.push('tracked_wrapper_missing_from_module_graph');\n hints.push(\n 'A wrapper request id is known, but Vite did not expose a live wrapper module during this HMR pass.',\n );\n }\n\n if (\n trackedRequestIds.every((id) => !id.includes('?ngcomp=')) &&\n wrapperModules.length === 0\n ) {\n anomalies.push('wrapper_not_yet_tracked');\n hints.push(\n 'Only direct stylesheet requests were tracked during this HMR pass; the wrapper request may be appearing too late.',\n );\n }\n\n return {\n file: changedFile,\n sourcePath,\n source: sourceDescription,\n registry: registryDescription,\n dependencies,\n diagnostics,\n tags,\n directModuleId: directModule.id ?? undefined,\n directModuleUrl: directModule.url,\n trackedRequestIds,\n wrapperCount: wrapperModules.length,\n anomalies,\n hints,\n };\n}\n\nexport async function findComponentStylesheetWrapperModules(\n server: ViteDevServer,\n changedFile: string,\n directModule: ModuleNode,\n fileModules: ModuleNode[],\n stylesheetRegistry?: AnalogStylesheetRegistry,\n): Promise<ModuleNode[]> {\n const wrapperModules = new Map<string, ModuleNode>();\n\n // Fast path: if the wrapper JS module is already present in the resolved\n // fileModules set for this HMR cycle, use it directly.\n for (const mod of fileModules) {\n if (\n mod.id &&\n mod.type === 'js' &&\n isComponentStyleSheet(mod.id) &&\n isModuleForChangedResource(mod, changedFile, stylesheetRegistry)\n ) {\n wrapperModules.set(mod.id, mod);\n }\n }\n\n const directRequestIds = new Set<string>();\n if (directModule.id) {\n directRequestIds.add(directModule.id);\n }\n if (directModule.url) {\n directRequestIds.add(directModule.url);\n }\n\n const requestPath = directModule.id\n ? getFilenameFromPath(directModule.id)\n : undefined;\n const sourcePath = requestPath\n ? (stylesheetRegistry?.resolveExternalSource(requestPath) ??\n stylesheetRegistry?.resolveExternalSource(\n requestPath.replace(/^\\//, ''),\n ) ??\n stylesheetRegistry?.getServedSourcePath(requestPath) ??\n stylesheetRegistry?.getServedSourcePath(requestPath.replace(/^\\//, '')))\n : undefined;\n\n // HMR timing matters here. On a pure CSS edit, the browser often already has\n // the `?ngcomp=...` wrapper module loaded, but the registry may only know\n // about the `?direct&ngcomp=...` request at the moment the file watcher\n // fires. Pull in any already-tracked wrapper ids for the same source file,\n // then derive wrapper candidates from the known direct request ids.\n for (const requestId of stylesheetRegistry?.getRequestIdsForSource(\n sourcePath ?? '',\n ) ?? []) {\n if (requestId.includes('?ngcomp=')) {\n directRequestIds.add(requestId);\n }\n }\n\n const candidateWrapperIds = [...directRequestIds]\n .filter((id) => id.includes('?direct&ngcomp='))\n .map((id) => id.replace('?direct&ngcomp=', '?ngcomp='));\n\n const lookupHits: Array<{\n candidate: string;\n via?: 'url' | 'id';\n moduleId?: string;\n moduleType?: string;\n }> = [];\n\n for (const candidate of candidateWrapperIds) {\n // Wrapper modules are served by URL and can be absent from a straight\n // module-id lookup during HMR. Prefer URL resolution first, then fall back\n // to id lookup for compatibility with simpler module graph states.\n const mod =\n (await server.moduleGraph.getModuleByUrl(candidate)) ??\n server.moduleGraph.getModuleById(candidate);\n lookupHits.push({\n candidate,\n via: mod?.url === candidate ? 'url' : mod ? 'id' : undefined,\n moduleId: mod?.id ?? undefined,\n moduleType: mod?.type,\n });\n if (\n mod?.id &&\n mod.type === 'js' &&\n isComponentStyleSheet(mod.id) &&\n isModuleForChangedResource(mod, changedFile, stylesheetRegistry)\n ) {\n wrapperModules.set(mod.id, mod);\n }\n }\n\n debugHmrV('component stylesheet wrapper lookup', {\n file: changedFile,\n sourcePath,\n directModuleId: directModule.id,\n directModuleUrl: directModule.url,\n candidateWrapperIds,\n lookupHits,\n });\n\n if (wrapperModules.size === 0) {\n debugHmrV('component stylesheet wrapper lookup empty', {\n file: changedFile,\n sourcePath,\n directModuleId: directModule.id,\n directModuleUrl: directModule.url,\n candidateWrapperIds,\n });\n }\n\n return [...wrapperModules.values()];\n}\n\nexport function findTemplateOwnerModules(\n server: ViteDevServer,\n resourceFile: string,\n): ModuleNode[] {\n const normalizedResourceFile = normalizePath(resourceFile.split('?')[0]);\n const candidateTsFiles = [\n normalizedResourceFile.replace(/\\.(html|htm)$/i, '.ts'),\n ];\n\n const modules = new Map<string, ModuleNode>();\n for (const candidate of candidateTsFiles) {\n const owners = server.moduleGraph.getModulesByFile(candidate);\n owners?.forEach((mod) => {\n if (mod.id) {\n modules.set(mod.id, mod);\n }\n });\n }\n\n return [...modules.values()];\n}\n\nfunction sendCssUpdate(\n server: ViteDevServer,\n update: {\n path: string;\n acceptedPath: string;\n },\n): void {\n const timestamp = Date.now();\n debugHmrV('ws send: css-update', {\n ...update,\n timestamp,\n });\n server.ws.send({\n type: 'update',\n updates: [\n {\n type: 'css-update',\n timestamp,\n path: update.path,\n acceptedPath: update.acceptedPath,\n },\n ],\n });\n}\n\nfunction sendFullReload(\n server: ViteDevServer,\n details: Record<string, unknown>,\n): void {\n debugHmrV('ws send: full-reload', details);\n server.ws.send('analog:debug-full-reload', details);\n server.ws.send({ type: 'full-reload' });\n}\n\ntype ComponentStylesheetHmrOutcome = 'css-update' | 'full-reload';\n\nfunction logComponentStylesheetHmrOutcome(details: {\n file: string;\n encapsulation: string | undefined;\n diagnosis: ComponentStylesheetPipelineDiagnosis;\n outcome: ComponentStylesheetHmrOutcome;\n directModuleId?: string;\n wrapperIds?: string[];\n}): void {\n const pitfalls: string[] = [];\n const rejectedPreferredPaths: string[] = [];\n const hints: string[] = [];\n\n if (details.encapsulation === 'shadow') {\n pitfalls.push('shadow-encapsulation');\n rejectedPreferredPaths.push('css-update');\n hints.push(\n 'Shadow DOM styles cannot rely on Vite CSS patching because Angular applies them inside a shadow root.',\n );\n }\n\n if (details.diagnosis.anomalies.includes('wrapper_not_yet_tracked')) {\n pitfalls.push('wrapper-not-yet-tracked');\n rejectedPreferredPaths.push('css-update');\n hints.push(\n 'The direct stylesheet module exists, but the browser-visible Angular wrapper module was not available in the live graph during this HMR pass.',\n );\n }\n\n if (\n details.diagnosis.anomalies.includes(\n 'tracked_wrapper_missing_from_module_graph',\n )\n ) {\n pitfalls.push('tracked-wrapper-missing-from-module-graph');\n rejectedPreferredPaths.push('css-update');\n hints.push(\n 'A wrapper request id is known, but Vite could not resolve a live wrapper module for targeted CSS HMR.',\n );\n }\n\n debugHmrV('component stylesheet hmr outcome', {\n file: details.file,\n outcome: details.outcome,\n encapsulation: details.encapsulation,\n directModuleId: details.directModuleId,\n wrapperIds: details.wrapperIds ?? [],\n preferredPath:\n details.encapsulation === 'shadow' ? 'full-reload' : 'css-update',\n rejectedPreferredPaths: [...new Set(rejectedPreferredPaths)],\n pitfalls: [...new Set(pitfalls)],\n anomalies: details.diagnosis.anomalies,\n hints: [...new Set([...details.diagnosis.hints, ...hints])],\n });\n}\n\nexport async function handleDirectComponentStyleHmr(options: {\n server: ViteDevServer;\n file: string;\n directModule: ModuleNode;\n fileModules: ModuleNode[];\n stylesheetRegistry?: AnalogStylesheetRegistry;\n stylePreprocessor?: StylePreprocessor;\n}): Promise<ModuleNode[]> {\n const {\n server,\n file,\n directModule,\n fileModules,\n stylesheetRegistry,\n stylePreprocessor,\n } = options;\n const { encapsulation } = getComponentStyleSheetMeta(directModule.id!);\n\n // Angular exposes one component stylesheet through two module shapes:\n // 1. a `?direct&ngcomp=...` CSS module that Vite can patch with a normal `css-update`\n // 2. a `?ngcomp=...` JS wrapper module that embeds `__vite__css` for Angular's runtime\n //\n // Value: invalidate the browser-visible wrapper before patching the direct CSS\n // module so Angular re-evaluates the same live wrapper it is actually using.\n const wrapperModules = await findComponentStylesheetWrapperModules(\n server,\n file,\n directModule,\n fileModules,\n stylesheetRegistry,\n );\n const normalizedFile = normalizePath(file.split('?')[0]);\n const { sourcePath } = resolveDirectStylesheetSourcePath(\n normalizedFile,\n directModule,\n stylesheetRegistry,\n );\n const trackedRequestIds =\n stylesheetRegistry?.getRequestIdsForSource(sourcePath ?? '') ?? [];\n\n let stylesheetDiagnosis: ComponentStylesheetPipelineDiagnosis | undefined;\n if (debugHmrV.enabled) {\n try {\n stylesheetDiagnosis = diagnoseComponentStylesheetPipeline(\n file,\n directModule,\n stylesheetRegistry,\n wrapperModules,\n stylePreprocessor,\n );\n } catch (error) {\n debugHmrV('component stylesheet pipeline diagnosis failed', {\n file,\n error: error instanceof Error ? error.message : String(error),\n });\n }\n }\n debugStylesV('HMR: component stylesheet changed', {\n file: directModule.file,\n encapsulation,\n });\n debugHmrV('component stylesheet wrapper modules', {\n file,\n wrapperCount: wrapperModules.length,\n wrapperIds: wrapperModules.map((mod) => mod.id),\n availableModuleIds: fileModules.map((mod) => mod.id),\n });\n if (stylesheetDiagnosis) {\n debugHmrV('component stylesheet pipeline diagnosis', stylesheetDiagnosis);\n }\n\n // Drop Vite's cached direct-module transform before wrapper lookup and patching continue.\n server.moduleGraph.invalidateModule(directModule);\n debugHmrV('component stylesheet direct module invalidated', {\n file,\n directModuleId: directModule.id,\n directModuleUrl: directModule.url,\n reason:\n 'Ensure Vite drops stale direct CSS transform results before wrapper or fallback handling continues.',\n });\n\n // CSS-only HMR is safe only when the browser-visible wrapper is known and the\n // component is not using Shadow DOM.\n const trackedWrapperRequestIds = trackedRequestIds.filter((id) =>\n id.includes('?ngcomp='),\n );\n const canUseCssUpdate =\n encapsulation !== 'shadow' &&\n (wrapperModules.length > 0 || trackedWrapperRequestIds.length > 0);\n\n if (canUseCssUpdate) {\n wrapperModules.forEach((mod) => server.moduleGraph.invalidateModule(mod));\n debugHmrV('sending css-update for component stylesheet', {\n file,\n path: directModule.url,\n acceptedPath: directModule.file,\n wrapperCount: wrapperModules.length,\n trackedWrapperRequestIds,\n hint:\n wrapperModules.length > 0\n ? 'Live wrapper modules were found and invalidated before sending the CSS update.'\n : '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.',\n });\n sendCssUpdate(server, {\n path: directModule.url,\n acceptedPath: directModule.file!,\n });\n if (stylesheetDiagnosis) {\n logComponentStylesheetHmrOutcome({\n file,\n encapsulation,\n diagnosis: stylesheetDiagnosis,\n outcome: 'css-update',\n directModuleId: directModule.id ?? undefined,\n wrapperIds: wrapperModules\n .map((mod) => mod.id)\n .filter((id): id is string => id !== null),\n });\n }\n\n return union(\n fileModules\n .filter((mod) => {\n // Component stylesheets will have 2 modules (*.component.scss and *.component.scss?direct&ngcomp=xyz&e=x)\n // We remove the module with the query params to prevent vite double logging the stylesheet name\n return mod.file !== file || mod.id !== directModule.id;\n })\n .map((mod) => {\n if (mod.file === file) {\n return markModuleSelfAccepting(mod);\n }\n return mod;\n }) as ModuleNode[],\n wrapperModules.map((mod) => markModuleSelfAccepting(mod)),\n );\n }\n\n // If the browser-visible `?ngcomp=...` wrapper cannot be trusted, prefer\n // correctness over a partial patch and reload.\n debugHmrV('component stylesheet hmr fallback: full reload', {\n file,\n encapsulation,\n reason:\n trackedWrapperRequestIds.length === 0\n ? 'missing-wrapper-module'\n : encapsulation === 'shadow'\n ? 'shadow-encapsulation'\n : 'tracked-wrapper-still-not-patchable',\n directId: directModule.id,\n trackedRequestIds: stylesheetRegistry?.getRequestIdsForSource(file) ?? [],\n });\n if (stylesheetDiagnosis) {\n logComponentStylesheetHmrOutcome({\n file,\n encapsulation,\n diagnosis: stylesheetDiagnosis,\n outcome: 'full-reload',\n directModuleId: directModule.id ?? undefined,\n wrapperIds: wrapperModules\n .map((mod) => mod.id)\n .filter((id): id is string => id !== null),\n });\n }\n sendFullReload(server, {\n file,\n encapsulation,\n reason:\n wrapperModules.length === 0\n ? 'missing-wrapper-module'\n : 'shadow-encapsulation',\n directId: directModule.id,\n trackedRequestIds: stylesheetRegistry?.getRequestIdsForSource(file) ?? [],\n });\n return [];\n}\n"],"mappings":";;;;;;;;;;;;;;AAoDA,SAAgB,sBACd,cACQ;CACR,MAAM,MAAM,0BAA0B,YAAY;CAElD,OAAO;EACL,MAAM;EACN,SAAS;EACT,MAAM,eAAe,QAAQ;GAC3B,MAAM,IAAI,cAAc,MAAM;EAChC;EACA,UAAU,IAAI;GACZ,OAAO,IAAI,OAAO,wBAAwB,EAAE;EAC9C;EACA,KAAK,IAAI;GACP,OAAO,IAAI,OAAO,mBAAmB,EAAE;EACzC;EACA,gBAAgB,QAAQ;GACtB,IAAI,0BAA0B,KAAK,OAAO,IAAI,GAAG;IAC/C,SAAS,2BAA2B,EAAE,MAAM,OAAO,KAAK,CAAC;IACzD,IAAI,OAAO,eAAe,OAAO,IAAI;GACvC;EAEF;CACF;AACF;AAEA,SAAgB,wBAAwB,KAA6B;CAEnE,IAAI,mBAAmB,KACrB,IACE,gBACD,CAAC,kBAAkB;CAGtB,OAAO;EACL,GAAG;EACH,iBAAiB;CACnB;AACF;;;;;;;;;;;;;AAcA,eAAsB,yBAC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B,oBAAoB,uBAAuB,IAAI,KAAK,CAAC;CAC1E,CAAC;CACD,IAAI,qBACF,iCAAiC;EAC/B;EACA;EACA,WAAW;EACX,SAAS;EACT,gBAAgB,aAAa,MAAM,KAAA;EACnC,YAAY,eACT,KAAK,QAAQ,IAAI,EAAE,CAAC,CACpB,QAAQ,OAAqB,OAAO,IAAI;CAC7C,CAAC;CAEH,eAAe,QAAQ;EACrB;EACA;EACA,QACE,eAAe,WAAW,IACtB,2BACA;EACN,UAAU,aAAa;EACvB,mBAAmB,oBAAoB,uBAAuB,IAAI,KAAK,CAAC;CAC1E,CAAC;CACD,OAAO,CAAC;AACV"}
@@ -0,0 +1,12 @@
1
+ import type { Plugin } from "vite";
2
+ import { type AngularBuildContext, type AngularBuildContextOptions } from "./angular-build-context.js";
3
+ /**
4
+ * Instantiates the compiler plugin matching `ctx.options.compilation` and
5
+ * registers its `AngularCompilerCapabilities` onto `ctx`.
6
+ */
7
+ export declare function selectAngularCompilerPlugin(ctx: AngularBuildContext): Plugin;
8
+ /**
9
+ * Composes the selected Angular compiler plugin and Analog's companion plugins
10
+ * around an `AngularBuildContext` (or options object).
11
+ */
12
+ export declare function composeAngularPlugins(ctxOrOptions?: AngularBuildContext | AngularBuildContextOptions): Plugin[];
@@ -0,0 +1,31 @@
1
+ import { ensureAngularBuildContext } from "./angular-build-context.js";
2
+ import { composeWithCompanions } from "./companion-plugins.js";
3
+ import { compilationApiPlugin } from "./compilation-api/compilation-api-plugin.js";
4
+ import { fastCompilePlugin } from "./fast-compile-plugin.js";
5
+ import { ngpCompilePlugin } from "./ngp-compile-plugin.js";
6
+ import { ngtscCompilePlugin } from "./ngtsc-compile-plugin.js";
7
+ //#region packages/vite-plugin-angular/src/lib/compose-angular-plugins.ts
8
+ /**
9
+ * Instantiates the compiler plugin matching `ctx.options.compilation` and
10
+ * registers its `AngularCompilerCapabilities` onto `ctx`.
11
+ */
12
+ function selectAngularCompilerPlugin(ctx) {
13
+ switch (ctx.options.compilation) {
14
+ case "fast": return fastCompilePlugin(ctx);
15
+ case "ngp": return ngpCompilePlugin(ctx);
16
+ case "compilation-api": return compilationApiPlugin(ctx);
17
+ default: return ngtscCompilePlugin(ctx);
18
+ }
19
+ }
20
+ /**
21
+ * Composes the selected Angular compiler plugin and Analog's companion plugins
22
+ * around an `AngularBuildContext` (or options object).
23
+ */
24
+ function composeAngularPlugins(ctxOrOptions) {
25
+ const ctx = ensureAngularBuildContext(ctxOrOptions);
26
+ return composeWithCompanions(ctx, selectAngularCompilerPlugin(ctx));
27
+ }
28
+ //#endregion
29
+ export { composeAngularPlugins, selectAngularCompilerPlugin };
30
+
31
+ //# sourceMappingURL=compose-angular-plugins.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"compose-angular-plugins.js","names":[],"sources":["../../../src/lib/compose-angular-plugins.ts"],"sourcesContent":["import type { Plugin } from 'vite';\n\nimport {\n ensureAngularBuildContext,\n type AngularBuildContext,\n type AngularBuildContextOptions,\n} from './angular-build-context.js';\nimport { compilationApiPlugin } from './compilation-api/compilation-api-plugin.js';\nimport { composeWithCompanions } from './companion-plugins.js';\nimport { fastCompilePlugin } from './fast-compile-plugin.js';\nimport { ngpCompilePlugin } from './ngp-compile-plugin.js';\nimport { ngtscCompilePlugin } from './ngtsc-compile-plugin.js';\n\n/**\n * Instantiates the compiler plugin matching `ctx.options.compilation` and\n * registers its `AngularCompilerCapabilities` onto `ctx`.\n */\nexport function selectAngularCompilerPlugin(ctx: AngularBuildContext): Plugin {\n switch (ctx.options.compilation) {\n case 'fast':\n return fastCompilePlugin(ctx);\n case 'ngp':\n return ngpCompilePlugin(ctx);\n case 'compilation-api':\n return compilationApiPlugin(ctx);\n case 'ngtsc':\n default:\n return ngtscCompilePlugin(ctx);\n }\n}\n\n/**\n * Composes the selected Angular compiler plugin and Analog's companion plugins\n * around an `AngularBuildContext` (or options object).\n */\nexport function composeAngularPlugins(\n ctxOrOptions?: AngularBuildContext | AngularBuildContextOptions,\n): Plugin[] {\n const ctx = ensureAngularBuildContext(ctxOrOptions);\n return composeWithCompanions(ctx, selectAngularCompilerPlugin(ctx));\n}\n"],"mappings":";;;;;;;;;;;AAiBA,SAAgB,4BAA4B,KAAkC;CAC5E,QAAQ,IAAI,QAAQ,aAApB;EACE,KAAK,QACH,OAAO,kBAAkB,GAAG;EAC9B,KAAK,OACH,OAAO,iBAAiB,GAAG;EAC7B,KAAK,mBACH,OAAO,qBAAqB,GAAG;EAEjC,SACE,OAAO,mBAAmB,GAAG;CACjC;AACF;;;;;AAMA,SAAgB,sBACd,cACU;CACV,MAAM,MAAM,0BAA0B,YAAY;CAClD,OAAO,sBAAsB,KAAK,4BAA4B,GAAG,CAAC;AACpE"}
@@ -0,0 +1,7 @@
1
+ import type { Plugin } from "vite";
2
+ /**
3
+ * Defines `ngServerMode: 'true'` for server environments during `vite serve`.
4
+ * Runs after other plugins' `configEnvironment` hooks so an explicit
5
+ * `consumer` configured by a downstream plugin is respected.
6
+ */
7
+ export declare function devServerModePlugin(): Plugin;
@@ -0,0 +1,23 @@
1
+ import { isServerEnvironment } from "./utils/plugin-config.js";
2
+ //#region packages/vite-plugin-angular/src/lib/dev-server-mode-plugin.ts
3
+ /**
4
+ * Defines `ngServerMode: 'true'` for server environments during `vite serve`.
5
+ * Runs after other plugins' `configEnvironment` hooks so an explicit
6
+ * `consumer` configured by a downstream plugin is respected.
7
+ */
8
+ function devServerModePlugin() {
9
+ return {
10
+ name: "@analogjs/vite-plugin-angular-dev-server-mode",
11
+ apply: "serve",
12
+ configEnvironment: {
13
+ order: "post",
14
+ handler(name, config) {
15
+ if (isServerEnvironment(name, config)) return { define: { ngServerMode: "true" } };
16
+ }
17
+ }
18
+ };
19
+ }
20
+ //#endregion
21
+ export { devServerModePlugin };
22
+
23
+ //# sourceMappingURL=dev-server-mode-plugin.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"dev-server-mode-plugin.js","names":[],"sources":["../../../src/lib/dev-server-mode-plugin.ts"],"sourcesContent":["import type { Plugin } from 'vite';\nimport { isServerEnvironment } from './utils/plugin-config.js';\n\n/**\n * Defines `ngServerMode: 'true'` for server environments during `vite serve`.\n * Runs after other plugins' `configEnvironment` hooks so an explicit\n * `consumer` configured by a downstream plugin is respected.\n */\nexport function devServerModePlugin(): Plugin {\n return {\n name: '@analogjs/vite-plugin-angular-dev-server-mode',\n apply: 'serve',\n configEnvironment: {\n order: 'post',\n handler(name, config) {\n if (isServerEnvironment(name, config)) {\n return { define: { ngServerMode: 'true' } };\n }\n return undefined;\n },\n },\n };\n}\n"],"mappings":";;;;;;;AAQA,SAAgB,sBAA8B;CAC5C,OAAO;EACL,MAAM;EACN,OAAO;EACP,mBAAmB;GACjB,OAAO;GACP,QAAQ,MAAM,QAAQ;IACpB,IAAI,oBAAoB,MAAM,MAAM,GAClC,OAAO,EAAE,QAAQ,EAAE,cAAc,OAAO,EAAE;GAG9C;EACF;CACF;AACF"}
@@ -0,0 +1,62 @@
1
+ /**
2
+ * The fast compile path's plugin API, for Vite plugins that compile other
3
+ * source formats into Angular components (for example `.tsrx` modules).
4
+ *
5
+ * Such a plugin finds the fast compile plugin by its `api.fastCompile`
6
+ * property, lowers its modules to TypeScript, and hands the result to
7
+ * `compile()`.
8
+ */
9
+ /** Resolves an import the way Vite's `this.resolve` does. */
10
+ export type FastCompileResolve = (specifier: string, importer: string) => Promise<{
11
+ id: string;
12
+ external?: boolean | "absolute" | "relative";
13
+ } | null>;
14
+ /** A source format whose modules compile to Angular components. */
15
+ export interface FastCompileSourceFormat {
16
+ /** Short name used in diagnostics, for example `'tsrx'`. */
17
+ name: string;
18
+ /** Whether a module path (without query) belongs to this format. */
19
+ test(path: string): boolean;
20
+ /**
21
+ * TypeScript for registry scanning. It must declare the same Angular
22
+ * classes, selectors, inputs and outputs as the compiled module; template
23
+ * details may be placeholders.
24
+ */
25
+ toScanSource(code: string, path: string): Promise<string> | string;
26
+ }
27
+ /** A source map, as a JSON string or an object. */
28
+ export type SourceMapInput = string | {
29
+ [key: string]: unknown;
30
+ };
31
+ export interface FastCompileOptions {
32
+ /** Resolves the module's imports, usually the calling plugin's `this.resolve`. */
33
+ resolve: FastCompileResolve;
34
+ /**
35
+ * Maps the compiled output's source map (which points at `code`) back to
36
+ * the module's original source.
37
+ */
38
+ mapToSource?(map: SourceMapInput): {
39
+ [key: string]: unknown;
40
+ };
41
+ }
42
+ export interface FastCompileApi {
43
+ /** Registers a source format so registry scans and HMR understand its modules. */
44
+ registerSourceFormat(format: FastCompileSourceFormat): void;
45
+ /**
46
+ * Scans the modules behind `specifiers`, imported by `importer`, into the
47
+ * component registry so `resolveSelector` knows their selectors. Relative
48
+ * imports are scanned from source; packages from their `.d.ts` declarations.
49
+ */
50
+ scanImports(specifiers: string[], importer: string, resolve: FastCompileResolve): Promise<void>;
51
+ /** The element selector of a component or directive class, if known. */
52
+ resolveSelector(className: string): string | null;
53
+ /** Compiles TypeScript produced for module `id`. */
54
+ compile(code: string, id: string, options: FastCompileOptions): Promise<{
55
+ code: string;
56
+ map: SourceMapInput | null;
57
+ } | undefined>;
58
+ }
59
+ /** Finds the fast compile plugin's API among resolved Vite plugins. */
60
+ export declare function findFastCompileApi(plugins: readonly {
61
+ api?: unknown;
62
+ }[]): FastCompileApi | undefined;
@@ -0,0 +1,12 @@
1
+ //#region packages/vite-plugin-angular/src/lib/fast-compile-api.ts
2
+ /** Finds the fast compile plugin's API among resolved Vite plugins. */
3
+ function findFastCompileApi(plugins) {
4
+ for (const plugin of plugins) {
5
+ const api = plugin.api;
6
+ if (api?.fastCompile) return api.fastCompile;
7
+ }
8
+ }
9
+ //#endregion
10
+ export { findFastCompileApi };
11
+
12
+ //# sourceMappingURL=fast-compile-api.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"fast-compile-api.js","names":[],"sources":["../../../src/lib/fast-compile-api.ts"],"sourcesContent":["/**\n * The fast compile path's plugin API, for Vite plugins that compile other\n * source formats into Angular components (for example `.tsrx` modules).\n *\n * Such a plugin finds the fast compile plugin by its `api.fastCompile`\n * property, lowers its modules to TypeScript, and hands the result to\n * `compile()`.\n */\n\n/** Resolves an import the way Vite's `this.resolve` does. */\nexport type FastCompileResolve = (\n specifier: string,\n importer: string,\n) => Promise<{\n id: string;\n external?: boolean | 'absolute' | 'relative';\n} | null>;\n\n/** A source format whose modules compile to Angular components. */\nexport interface FastCompileSourceFormat {\n /** Short name used in diagnostics, for example `'tsrx'`. */\n name: string;\n /** Whether a module path (without query) belongs to this format. */\n test(path: string): boolean;\n /**\n * TypeScript for registry scanning. It must declare the same Angular\n * classes, selectors, inputs and outputs as the compiled module; template\n * details may be placeholders.\n */\n toScanSource(code: string, path: string): Promise<string> | string;\n}\n\n/** A source map, as a JSON string or an object. */\nexport type SourceMapInput = string | { [key: string]: unknown };\n\nexport interface FastCompileOptions {\n /** Resolves the module's imports, usually the calling plugin's `this.resolve`. */\n resolve: FastCompileResolve;\n /**\n * Maps the compiled output's source map (which points at `code`) back to\n * the module's original source.\n */\n mapToSource?(map: SourceMapInput): { [key: string]: unknown };\n}\n\nexport interface FastCompileApi {\n /** Registers a source format so registry scans and HMR understand its modules. */\n registerSourceFormat(format: FastCompileSourceFormat): void;\n /**\n * Scans the modules behind `specifiers`, imported by `importer`, into the\n * component registry so `resolveSelector` knows their selectors. Relative\n * imports are scanned from source; packages from their `.d.ts` declarations.\n */\n scanImports(\n specifiers: string[],\n importer: string,\n resolve: FastCompileResolve,\n ): Promise<void>;\n /** The element selector of a component or directive class, if known. */\n resolveSelector(className: string): string | null;\n /** Compiles TypeScript produced for module `id`. */\n compile(\n code: string,\n id: string,\n options: FastCompileOptions,\n ): Promise<{ code: string; map: SourceMapInput | null } | undefined>;\n}\n\n/** Finds the fast compile plugin's API among resolved Vite plugins. */\nexport function findFastCompileApi(\n plugins: readonly { api?: unknown }[],\n): FastCompileApi | undefined {\n for (const plugin of plugins) {\n const api = plugin.api as { fastCompile?: FastCompileApi } | undefined;\n if (api?.fastCompile) {\n return api.fastCompile;\n }\n }\n return undefined;\n}\n"],"mappings":";;AAqEA,SAAgB,mBACd,SAC4B;CAC5B,KAAK,MAAM,UAAU,SAAS;EAC5B,MAAM,MAAM,OAAO;EACnB,IAAI,KAAK,aACP,OAAO,IAAI;CAEf;AAEF"}
@@ -1,4 +1,6 @@
1
1
  import { Plugin } from "vite";
2
+ import { type AngularBuildContext, type AngularBuildContextOptions } from "./angular-build-context.js";
3
+ import type { TypeCheckerOption } from "./utils/lsp-type-checker.js";
2
4
  export interface FastCompilePluginOptions {
3
5
  tsconfigGetter: () => string;
4
6
  workspaceRoot: string;
@@ -8,6 +10,9 @@ export interface FastCompilePluginOptions {
8
10
  isTest: boolean;
9
11
  isAstroIntegration: boolean;
10
12
  fastCompileMode?: "full" | "partial";
13
+ disableTypeChecking?: boolean;
14
+ typeChecker?: TypeCheckerOption;
15
+ include?: string[];
11
16
  }
12
17
  /**
13
18
  * Directory that `compilerOptions.paths` targets resolve against. Mirrors
@@ -19,4 +24,4 @@ export declare function getPathsBasePath(options: {
19
24
  baseUrl?: string;
20
25
  pathsBasePath?: string;
21
26
  } | undefined, fallback: string): string;
22
- export declare function fastCompilePlugin(pluginOptions: FastCompilePluginOptions): Plugin;
27
+ export declare function fastCompilePlugin(optionsOrCtx?: AngularBuildContext | FastCompilePluginOptions | AngularBuildContextOptions): Plugin;