@analogjs/vite-plugin-angular 3.0.0-beta.9 → 3.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (161) hide show
  1. package/migrations/migrate-setup-vitest/migrate-setup-vitest.js +3 -3
  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 +5 -2
  9. package/src/index.d.ts +2 -0
  10. package/src/index.js +4 -3
  11. package/src/index.js.map +1 -1
  12. package/src/lib/analog-plugin-interop.js +2 -3
  13. package/src/lib/angular-build-context.d.ts +215 -0
  14. package/src/lib/angular-build-context.js +360 -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 +25 -11
  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 +16 -9
  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 +9 -1251
  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 +7 -5
  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 +37 -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 +156 -285
  33. package/src/lib/compilation-api/compilation-api-plugin.js.map +1 -1
  34. package/src/lib/compilation-api/index.js +1 -2
  35. package/src/lib/compiler/angular-version.js +0 -1
  36. package/src/lib/compiler/class-field-lowering.js +1 -2
  37. package/src/lib/compiler/compile.d.ts +1 -1
  38. package/src/lib/compiler/compile.js +224 -151
  39. package/src/lib/compiler/compile.js.map +1 -1
  40. package/src/lib/compiler/constants.js +1 -2
  41. package/src/lib/compiler/debug.js +1 -2
  42. package/src/lib/compiler/defer.d.ts +2 -3
  43. package/src/lib/compiler/defer.js +13 -16
  44. package/src/lib/compiler/defer.js.map +1 -1
  45. package/src/lib/compiler/dts-reader.d.ts +6 -1
  46. package/src/lib/compiler/dts-reader.js +20 -12
  47. package/src/lib/compiler/dts-reader.js.map +1 -1
  48. package/src/lib/compiler/hmr.d.ts +4 -0
  49. package/src/lib/compiler/hmr.js +8 -4
  50. package/src/lib/compiler/hmr.js.map +1 -1
  51. package/src/lib/compiler/index.d.ts +2 -2
  52. package/src/lib/compiler/index.js +6 -6
  53. package/src/lib/compiler/jit-metadata.js +1 -2
  54. package/src/lib/compiler/jit-transform.js +37 -15
  55. package/src/lib/compiler/jit-transform.js.map +1 -1
  56. package/src/lib/compiler/js-emitter.d.ts +0 -3
  57. package/src/lib/compiler/js-emitter.js +4 -23
  58. package/src/lib/compiler/js-emitter.js.map +1 -1
  59. package/src/lib/compiler/metadata.js +2 -3
  60. package/src/lib/compiler/registry.d.ts +9 -1
  61. package/src/lib/compiler/registry.js +36 -8
  62. package/src/lib/compiler/registry.js.map +1 -1
  63. package/src/lib/compiler/resource-inliner.d.ts +8 -9
  64. package/src/lib/compiler/resource-inliner.js +11 -20
  65. package/src/lib/compiler/resource-inliner.js.map +1 -1
  66. package/src/lib/compiler/style-ast.d.ts +22 -1
  67. package/src/lib/compiler/style-ast.js +37 -20
  68. package/src/lib/compiler/style-ast.js.map +1 -1
  69. package/src/lib/compiler/type-elision.d.ts +4 -3
  70. package/src/lib/compiler/type-elision.js +11 -13
  71. package/src/lib/compiler/type-elision.js.map +1 -1
  72. package/src/lib/compiler/utils.d.ts +9 -7
  73. package/src/lib/compiler/utils.js +50 -11
  74. package/src/lib/compiler/utils.js.map +1 -1
  75. package/src/lib/compiler-plugin.js +1 -2
  76. package/src/lib/component-resolvers.js +1 -2
  77. package/src/lib/component-scanner.d.ts +101 -0
  78. package/src/lib/component-scanner.js +331 -0
  79. package/src/lib/component-scanner.js.map +1 -0
  80. package/src/lib/component-styles-plugin.d.ts +52 -0
  81. package/src/lib/component-styles-plugin.js +352 -0
  82. package/src/lib/component-styles-plugin.js.map +1 -0
  83. package/src/lib/compose-angular-plugins.d.ts +12 -0
  84. package/src/lib/compose-angular-plugins.js +30 -0
  85. package/src/lib/compose-angular-plugins.js.map +1 -0
  86. package/src/lib/dev-server-mode-plugin.d.ts +7 -0
  87. package/src/lib/dev-server-mode-plugin.js +22 -0
  88. package/src/lib/dev-server-mode-plugin.js.map +1 -0
  89. package/src/lib/encapsulation-plugin.js +1 -2
  90. package/src/lib/fast-compile-api.d.ts +62 -0
  91. package/src/lib/fast-compile-api.js +11 -0
  92. package/src/lib/fast-compile-api.js.map +1 -0
  93. package/src/lib/fast-compile-plugin.d.ts +6 -1
  94. package/src/lib/fast-compile-plugin.js +222 -117
  95. package/src/lib/fast-compile-plugin.js.map +1 -1
  96. package/src/lib/host.d.ts +3 -0
  97. package/src/lib/host.js +5 -4
  98. package/src/lib/host.js.map +1 -1
  99. package/src/lib/hot-update-batch.js +1 -2
  100. package/src/lib/live-reload-plugin.d.ts +6 -3
  101. package/src/lib/live-reload-plugin.js +14 -8
  102. package/src/lib/live-reload-plugin.js.map +1 -1
  103. package/src/lib/ngp-compile-api.d.ts +55 -0
  104. package/src/lib/ngp-compile-api.js +11 -0
  105. package/src/lib/ngp-compile-api.js.map +1 -0
  106. package/src/lib/ngp-compile-plugin.d.ts +4 -0
  107. package/src/lib/ngp-compile-plugin.js +675 -0
  108. package/src/lib/ngp-compile-plugin.js.map +1 -0
  109. package/src/lib/ngtsc-compile-plugin.d.ts +23 -0
  110. package/src/lib/ngtsc-compile-plugin.js +776 -0
  111. package/src/lib/ngtsc-compile-plugin.js.map +1 -0
  112. package/src/lib/nx-folder-plugin.d.ts +6 -5
  113. package/src/lib/nx-folder-plugin.js +13 -9
  114. package/src/lib/nx-folder-plugin.js.map +1 -1
  115. package/src/lib/plugins/file-replacements.plugin.d.ts +6 -0
  116. package/src/lib/plugins/file-replacements.plugin.js +2 -2
  117. package/src/lib/plugins/file-replacements.plugin.js.map +1 -1
  118. package/src/lib/router-plugin.d.ts +5 -1
  119. package/src/lib/router-plugin.js +14 -6
  120. package/src/lib/router-plugin.js.map +1 -1
  121. package/src/lib/style-preprocessor.js +1 -2
  122. package/src/lib/stylesheet-registry.js +1 -2
  123. package/src/lib/stylesheet-registry.js.map +1 -1
  124. package/src/lib/tools/src/builders/vite/vite-build.impl.js +2 -3
  125. package/src/lib/tools/src/builders/vite/vite-build.impl.js.map +1 -1
  126. package/src/lib/tools/src/builders/vite-dev-server/dev-server.impl.js +1 -2
  127. package/src/lib/tools/src/builders/vite-dev-server/dev-server.impl.js.map +1 -1
  128. package/src/lib/utils/compilation-shared.js +3 -4
  129. package/src/lib/utils/css-extension-resolver.js +1 -2
  130. package/src/lib/utils/css-preprocessor-workers.js +1 -2
  131. package/src/lib/utils/debug-harness.js +1 -2
  132. package/src/lib/utils/debug-log-file.js +1 -2
  133. package/src/lib/utils/debug.js +1 -2
  134. package/src/lib/utils/devkit.js +2 -3
  135. package/src/lib/utils/hmr-component-updates.d.ts +7 -0
  136. package/src/lib/utils/hmr-component-updates.js +86 -0
  137. package/src/lib/utils/hmr-component-updates.js.map +1 -0
  138. package/src/lib/utils/jit-inline-styles.js +1 -2
  139. package/src/lib/utils/lsp-type-checker.d.ts +75 -0
  140. package/src/lib/utils/lsp-type-checker.js +532 -0
  141. package/src/lib/utils/lsp-type-checker.js.map +1 -0
  142. package/src/lib/utils/ngp-host-fs.d.ts +43 -0
  143. package/src/lib/utils/ngp-host-fs.js +128 -0
  144. package/src/lib/utils/ngp-host-fs.js.map +1 -0
  145. package/src/lib/utils/plugin-config.d.ts +15 -8
  146. package/src/lib/utils/plugin-config.js +19 -7
  147. package/src/lib/utils/plugin-config.js.map +1 -1
  148. package/src/lib/utils/rolldown.js +1 -2
  149. package/src/lib/utils/safe-module-paths.js +1 -2
  150. package/src/lib/utils/stylesheet-warning.d.ts +2 -0
  151. package/src/lib/utils/stylesheet-warning.js +10 -0
  152. package/src/lib/utils/stylesheet-warning.js.map +1 -0
  153. package/src/lib/utils/transform-cache.js +1 -2
  154. package/src/lib/utils/transform-cache.js.map +1 -1
  155. package/src/lib/utils/tsconfig-resolver.js +2 -3
  156. package/src/lib/utils/virtual-ids.js +1 -2
  157. package/src/lib/utils/virtual-resources.js +1 -2
  158. package/src/lib/utils/virtual-resources.js.map +1 -1
  159. package/src/lib/virtual-modules-plugin.d.ts +11 -3
  160. package/src/lib/virtual-modules-plugin.js +70 -15
  161. package/src/lib/virtual-modules-plugin.js.map +1 -1
@@ -0,0 +1,776 @@
1
+ import { createAngularBuildContext, isAngularBuildContext } from "./angular-build-context.js";
2
+ import { StyleUrlsResolver, TemplateUrlsResolver } from "./component-resolvers.js";
3
+ import { findTemplateOwnerModules, getModulesForChangedFile, handleDirectComponentStyleHmr, isModuleForChangedResource, markModuleSelfAccepting } from "./component-styles-plugin.js";
4
+ import { isComponentStyleSheet } from "./encapsulation-plugin.js";
5
+ import { augmentHostWithCaching, augmentHostWithModuleResolution, augmentHostWithResources, augmentProgramWithVersioning, mergeTransformers } from "./host.js";
6
+ import { createHotUpdateBatcher } from "./hot-update-batch.js";
7
+ import { describeStylesheetContent, injectViteIgnoreForHmrMetadata } from "./utils/compilation-shared.js";
8
+ import { releaseCssPreprocessorWorkers } from "./utils/css-preprocessor-workers.js";
9
+ import { activateDeferredDebug, debugCompiler, debugCompilerV, debugEmit, debugEmitV, debugHmr, debugHmrV, debugStyles } from "./utils/debug.js";
10
+ import { SourceFileCache, createJitResourceTransformer } from "./utils/devkit.js";
11
+ import { toJitInlineStyleId } from "./utils/jit-inline-styles.js";
12
+ import { EXCLUDED_TS_EXT_REGEX, TS_EXT_REGEX, createDepOptimizerConfig } from "./utils/plugin-config.js";
13
+ import { getJsTransformConfigKey } from "./utils/rolldown.js";
14
+ import { markStylePathSafe } from "./utils/safe-module-paths.js";
15
+ import { toVirtualRawId } from "./utils/virtual-ids.js";
16
+ import { loadAngularVirtualModule, resolveAngularVirtualId } from "./virtual-modules-plugin.js";
17
+ import { union } from "es-toolkit";
18
+ import { mkdirSync, realpathSync, writeFileSync } from "node:fs";
19
+ import { createRequire } from "node:module";
20
+ import { basename, dirname, isAbsolute, join, relative, resolve } from "node:path";
21
+ import { normalizePath, preprocessCSS } from "vite";
22
+ import * as compilerCli from "@angular/compiler-cli";
23
+ // packages/vite-plugin-angular/src/lib/ngtsc-compile-plugin.ts
24
+ var require = createRequire(import.meta.url);
25
+ function evictDeletedFileMetadata(file, { classNamesMap, fileTransformMap }) {
26
+ const normalizedFile = normalizePath(file.split("?")[0]);
27
+ classNamesMap.delete(normalizedFile);
28
+ fileTransformMap.delete(normalizedFile);
29
+ }
30
+ function createFsWatcherCacheInvalidator(invalidateFsCaches, invalidateTsconfigCaches, performCompilation) {
31
+ return async () => {
32
+ invalidateFsCaches();
33
+ invalidateTsconfigCaches();
34
+ await performCompilation();
35
+ };
36
+ }
37
+ /**
38
+ * Compiles Angular TypeScript sources using `@angular/compiler-cli` (`NgtscProgram`).
39
+ */
40
+ function ngtscCompilePlugin(ctxOrOptions) {
41
+ const ctx = isAngularBuildContext(ctxOrOptions) ? ctxOrOptions : createAngularBuildContext({
42
+ ...ctxOrOptions,
43
+ compilationBackend: "ngtsc"
44
+ });
45
+ const ts = require("typescript");
46
+ let cachedBuilder;
47
+ let nextProgram;
48
+ let cachedHost;
49
+ let cachedHostKey;
50
+ function invalidateFsCaches() {
51
+ ctx.tsconfigResolver.invalidateIncludeCache();
52
+ }
53
+ function invalidateTsconfigCaches() {
54
+ ctx.tsconfigResolver.invalidateTsconfigCaches();
55
+ cachedHost = void 0;
56
+ cachedHostKey = void 0;
57
+ }
58
+ const sourceFileCache = new SourceFileCache();
59
+ const tsSourceFileCache = /* @__PURE__ */ new Map();
60
+ function invalidateSourceFiles(files) {
61
+ for (const file of files) tsSourceFileCache.delete(normalizePath(file));
62
+ sourceFileCache.invalidate(files);
63
+ }
64
+ const { jit, isTest } = ctx.options;
65
+ let viteServer;
66
+ const styleUrlsResolver = new StyleUrlsResolver();
67
+ const templateUrlsResolver = new TemplateUrlsResolver();
68
+ let outputFile;
69
+ const outputFiles = /* @__PURE__ */ new Map();
70
+ const realPaths = /* @__PURE__ */ new Map();
71
+ const toRealPath = (file) => {
72
+ const normalizedFile = normalizePath(file);
73
+ const cachedPath = realPaths.get(normalizedFile);
74
+ if (cachedPath !== void 0) return cachedPath;
75
+ let realPath;
76
+ try {
77
+ realPath = normalizePath(realpathSync(normalizedFile));
78
+ } catch {
79
+ return normalizedFile;
80
+ }
81
+ realPaths.set(normalizedFile, realPath);
82
+ return realPath;
83
+ };
84
+ const normalizeEmitterLookupId = (file) => {
85
+ const normalizedFile = normalizePath(file);
86
+ if (!normalizedFile.startsWith("/@fs/")) return toRealPath(normalizedFile);
87
+ const fsPath = normalizedFile.slice(4).replace(/^\/([A-Za-z]:\/)/, "$1");
88
+ return toRealPath(fsPath);
89
+ };
90
+ const describeEmitMarkers = (content) => ({
91
+ contentLength: content.length,
92
+ hasCmp: content.includes("ɵcmp"),
93
+ hasFac: content.includes("ɵfac"),
94
+ hasProv: content.includes("ɵprov"),
95
+ hasDecorate: content.includes("__decorate"),
96
+ hasMetadata: content.includes("__metadata")
97
+ });
98
+ const fileEmitter = (file) => {
99
+ const normalizedFile = normalizeEmitterLookupId(file);
100
+ const hadCachedEmit = outputFiles.has(normalizedFile);
101
+ outputFile?.(normalizedFile);
102
+ const emittedResult = outputFiles.get(normalizedFile);
103
+ debugEmitV("fileEmitter lookup", {
104
+ requestFile: file,
105
+ normalizedFile,
106
+ hadCachedEmit,
107
+ hasOutputFileHook: !!outputFile,
108
+ emitted: !!emittedResult,
109
+ knownOutputCount: outputFiles.size,
110
+ contentLength: emittedResult?.content?.length ?? 0,
111
+ errorCount: emittedResult?.errors?.length ?? 0,
112
+ warningCount: emittedResult?.warnings?.length ?? 0
113
+ });
114
+ return emittedResult;
115
+ };
116
+ ctx.hmr.setFileEmitter((file) => fileEmitter(file));
117
+ const compilerApi = {
118
+ angularCompiler: true,
119
+ getTsConfigPath: () => ctx.resolveTsConfigPath(),
120
+ getSourceMap: (id) => outputFiles.get(normalizeEmitterLookupId(id))?.map,
121
+ hasEmitted: (id) => outputFiles.has(normalizeEmitterLookupId(id))
122
+ };
123
+ ctx.registerCompiler({
124
+ name: "@analogjs/vite-plugin-angular",
125
+ getTsConfigPath: compilerApi.getTsConfigPath,
126
+ getSourceMap: compilerApi.getSourceMap,
127
+ hasEmitted: compilerApi.hasEmitted
128
+ });
129
+ let initialCompilation = false;
130
+ let activeBuilds = 0;
131
+ let closeRequested = false;
132
+ const declarationFiles = [];
133
+ const fileTransformMap = /* @__PURE__ */ new Map();
134
+ let styleTransform;
135
+ let pendingCompilation = null;
136
+ let compilationLock = Promise.resolve();
137
+ const hotUpdates = createHotUpdateBatcher((ids) => performCompilation(ctx.resolvedConfig, ids));
138
+ function releaseCompilation() {
139
+ cachedBuilder = void 0;
140
+ nextProgram = void 0;
141
+ cachedHost = void 0;
142
+ cachedHostKey = void 0;
143
+ outputFile = void 0;
144
+ outputFiles.clear();
145
+ fileTransformMap.clear();
146
+ tsSourceFileCache.clear();
147
+ sourceFileCache.clear();
148
+ sourceFileCache.modifiedFiles.clear();
149
+ sourceFileCache.babelFileCache?.clear();
150
+ sourceFileCache.typeScriptFileCache?.clear();
151
+ sourceFileCache.referencedFiles = void 0;
152
+ ctx.tsconfigResolver.invalidateAll();
153
+ releaseCssPreprocessorWorkers();
154
+ ctx.styles.clear();
155
+ }
156
+ async function closeCompilation() {
157
+ closeRequested = false;
158
+ hotUpdates.close();
159
+ await compilationLock;
160
+ declarationFiles.forEach(({ declarationFileDir, declarationPath, data }) => {
161
+ mkdirSync(declarationFileDir, { recursive: true });
162
+ writeFileSync(declarationPath, data, "utf-8");
163
+ });
164
+ declarationFiles.length = 0;
165
+ releaseCompilation();
166
+ }
167
+ function normalizeSourceMapSources(map, id) {
168
+ const sourceMap = JSON.parse(map);
169
+ const sourceDirectory = dirname(id);
170
+ const sourceRoot = sourceMap.sourceRoot ?? "";
171
+ sourceMap.sources = sourceMap.sources?.map((source) => {
172
+ if (isAbsolute(source) || /^[a-z][a-z\d+.-]*:/i.test(source)) return normalizePath(source);
173
+ return normalizePath(resolve(sourceDirectory, sourceRoot, source));
174
+ });
175
+ delete sourceMap.sourceRoot;
176
+ return JSON.stringify(sourceMap);
177
+ }
178
+ async function performCompilation(config, ids) {
179
+ let releaseLock;
180
+ const previousLock = compilationLock;
181
+ compilationLock = new Promise((r) => {
182
+ releaseLock = r;
183
+ });
184
+ try {
185
+ await previousLock;
186
+ await ctx.refreshIntegrations(config);
187
+ await _doPerformCompilation(config, ids);
188
+ } finally {
189
+ releaseLock();
190
+ }
191
+ }
192
+ /**
193
+ * This method shares mutable state and performs the actual compilation work.
194
+ * It should not be called concurrently. Use `performCompilation` which wraps
195
+ * this method in a lock to ensure only one compilation runs at a time.
196
+ */
197
+ async function _doPerformCompilation(config, ids) {
198
+ const isProd = config.mode === "production";
199
+ invalidateSourceFiles(new Set(ids ?? []));
200
+ if (ids?.length) for (const id of ids) fileTransformMap.delete(id);
201
+ const resolvedTsConfigPath = ctx.resolveTsConfigPath();
202
+ const cached = ctx.tsconfigResolver.getCachedTsconfigOptions(resolvedTsConfigPath, config);
203
+ const tsCompilerOptions = { ...cached.options };
204
+ let rootNames = [...cached.rootNames];
205
+ if (ctx.shouldExternalizeStyles()) tsCompilerOptions["externalRuntimeStyles"] = true;
206
+ if (ctx.shouldEnableLiveReload()) {
207
+ tsCompilerOptions["_enableHmr"] = true;
208
+ tsCompilerOptions["supportTestBed"] = true;
209
+ }
210
+ debugCompiler("tsCompilerOptions (NgtscProgram path)", {
211
+ liveReload: ctx.options.liveReload,
212
+ viteHmr: ctx.hasViteHmrTransport(),
213
+ externalizeStylesRequested: ctx.externalizeStylesRequested,
214
+ shouldExternalize: ctx.shouldExternalizeStyles(),
215
+ externalRuntimeStyles: !!tsCompilerOptions["externalRuntimeStyles"],
216
+ hmrEnabled: !!tsCompilerOptions["_enableHmr"]
217
+ });
218
+ if (tsCompilerOptions["compilationMode"] === "partial") {
219
+ tsCompilerOptions["supportTestBed"] = true;
220
+ tsCompilerOptions["supportJitMode"] = true;
221
+ }
222
+ if (!isTest && config.build?.lib) {
223
+ tsCompilerOptions["declaration"] = true;
224
+ tsCompilerOptions["declarationMap"] = ctx.watchMode;
225
+ tsCompilerOptions["inlineSources"] = true;
226
+ }
227
+ if (isTest) tsCompilerOptions["supportTestBed"] = true;
228
+ const replacements = ctx.options.fileReplacements.map((rp) => join(ctx.options.workspaceRoot, rp.ssr || rp.with));
229
+ rootNames = [...new Set(union(union(rootNames, ctx.tsconfigResolver.ensureIncludeCache()), replacements).map(toRealPath))];
230
+ const hostKey = JSON.stringify(tsCompilerOptions);
231
+ let host;
232
+ if (cachedHost && cachedHostKey === hostKey) host = cachedHost;
233
+ else {
234
+ host = ts.createIncrementalCompilerHost(tsCompilerOptions, {
235
+ ...ts.sys,
236
+ readFile(path, encoding) {
237
+ if (fileTransformMap.has(path)) return fileTransformMap.get(path);
238
+ const file = ts.sys.readFile.call(null, path, encoding);
239
+ if (file) fileTransformMap.set(path, file);
240
+ return file;
241
+ }
242
+ });
243
+ augmentHostWithModuleResolution(host, tsCompilerOptions);
244
+ cachedHost = host;
245
+ cachedHostKey = hostKey;
246
+ if (ctx.watchMode) augmentHostWithCaching(host, tsSourceFileCache);
247
+ }
248
+ if (!jit) {
249
+ const externalizeStyles = !!tsCompilerOptions["externalRuntimeStyles"];
250
+ const stylesheetRegistry = ctx.styles.resetRegistry(externalizeStyles);
251
+ debugStyles("stylesheet registry initialized (NgtscProgram path)", { externalizeStyles });
252
+ augmentHostWithResources(host, styleTransform, {
253
+ inlineStylesExtension: ctx.options.inlineStylesExtension,
254
+ isProd,
255
+ stylesheetRegistry,
256
+ sourceFileCache,
257
+ stylePreprocessor: ctx.stylePreprocessor,
258
+ logger: ctx.resolvedConfig?.logger,
259
+ isBuild: ctx.resolvedConfig?.command === "build"
260
+ });
261
+ }
262
+ /**
263
+ * Creates a new NgtscProgram to analyze/re-analyze
264
+ * the source files and create a file emitter.
265
+ * This is shared between an initial build and a hot update.
266
+ */
267
+ let typeScriptProgram;
268
+ let angularCompiler;
269
+ let builder;
270
+ const oldBuilder = ids?.some((id) => EXCLUDED_TS_EXT_REGEX.test(id)) ? void 0 : cachedBuilder ?? ts.readBuilderProgram(tsCompilerOptions, host);
271
+ if (!jit) {
272
+ const angularProgram = new compilerCli.NgtscProgram(rootNames, tsCompilerOptions, host, nextProgram);
273
+ angularCompiler = angularProgram.compiler;
274
+ typeScriptProgram = angularProgram.compiler.getCurrentProgram();
275
+ augmentProgramWithVersioning(typeScriptProgram);
276
+ builder = ts.createEmitAndSemanticDiagnosticsBuilderProgram(typeScriptProgram, host, oldBuilder);
277
+ nextProgram = angularProgram;
278
+ } else {
279
+ builder = ts.createEmitAndSemanticDiagnosticsBuilderProgram(rootNames, tsCompilerOptions, host, oldBuilder);
280
+ typeScriptProgram = builder.getProgram();
281
+ }
282
+ if (!ctx.watchMode) builder = ts.createAbstractBuilder(typeScriptProgram, host, oldBuilder);
283
+ cachedBuilder = builder;
284
+ if (angularCompiler) {
285
+ await angularCompiler.analyzeAsync();
286
+ if (!ctx.options.disableTypeChecking) typeScriptProgram.getOptionsDiagnostics();
287
+ }
288
+ const beforeTransformers = jit ? [compilerCli.constructorParametersDownlevelTransform(builder.getProgram()), createJitResourceTransformer(() => builder.getProgram().getTypeChecker())] : [];
289
+ const transformers = mergeTransformers({ before: beforeTransformers }, jit ? {} : angularCompiler.prepareEmit().transformers);
290
+ const fileMetadata = getFileMetadata(builder, angularCompiler, ctx.options.liveReload, ctx.options.disableTypeChecking, ctx.hmr.classNames);
291
+ const writeFileCallback = (_filename, content, _a, _b, sourceFiles) => {
292
+ if (!sourceFiles?.length) return;
293
+ const filename = normalizePath(sourceFiles[0].fileName);
294
+ if (filename.includes("ngtypecheck.ts") || filename.includes(".d.") || _filename.endsWith(".d.ts") || _filename.endsWith(".d.mts") || _filename.endsWith(".d.cts")) return;
295
+ if (/\.[cm]?js\.map$/.test(_filename)) {
296
+ const existing = outputFiles.get(filename);
297
+ outputFiles.set(filename, {
298
+ ...existing ?? { dependencies: [] },
299
+ map: content
300
+ });
301
+ return;
302
+ }
303
+ const metadata = ctx.watchMode ? fileMetadata(filename) : {};
304
+ const existing = outputFiles.get(filename);
305
+ outputFiles.set(filename, {
306
+ ...existing ?? {},
307
+ content,
308
+ dependencies: [],
309
+ errors: metadata.errors,
310
+ warnings: metadata.warnings,
311
+ hmrUpdateCode: metadata.hmrUpdateCode,
312
+ hmrEligible: metadata.hmrEligible
313
+ });
314
+ debugEmitV("registered ngtsc output", {
315
+ filename,
316
+ ...describeEmitMarkers(content),
317
+ errorCount: metadata.errors?.length ?? 0,
318
+ warningCount: metadata.warnings?.length ?? 0,
319
+ hmrEligible: !!metadata.hmrEligible,
320
+ knownOutputCount: outputFiles.size
321
+ });
322
+ };
323
+ const writeOutputFile = (id) => {
324
+ const sourceFile = builder.getSourceFile(toRealPath(id));
325
+ if (!sourceFile) return;
326
+ let content = "";
327
+ let map;
328
+ let mapFilename;
329
+ builder.emit(sourceFile, (filename, data) => {
330
+ if (/\.[cm]?js$/.test(filename)) content = data;
331
+ if (/\.[cm]?js\.map$/.test(filename)) {
332
+ map = data;
333
+ mapFilename = filename;
334
+ }
335
+ if (!ctx.watchMode && !isTest && /\.d\.ts/.test(filename) && !filename.includes(".ngtypecheck.")) {
336
+ const root = toRealPath(config.root);
337
+ const declarationPath = resolve(root, config.build.outDir, relative(root, filename)).replace("/src/", "/");
338
+ const declarationFileDir = declarationPath.replace(basename(filename), "").replace("/src/", "/");
339
+ declarationFiles.push({
340
+ declarationFileDir,
341
+ declarationPath,
342
+ data
343
+ });
344
+ }
345
+ }, void 0, void 0, transformers);
346
+ writeFileCallback(id, content, false, void 0, [sourceFile]);
347
+ if (map !== void 0 && mapFilename !== void 0) writeFileCallback(mapFilename, map, false, void 0, [sourceFile]);
348
+ if (angularCompiler) angularCompiler.incrementalCompilation.recordSuccessfulEmit(sourceFile);
349
+ };
350
+ if (ctx.watchMode) {
351
+ if (ids && ids.length > 0) ids.forEach((id) => writeOutputFile(id));
352
+ else if (isTest)
353
+ /**
354
+ * Only block the server from starting up
355
+ * during testing.
356
+ */
357
+ while (builder.emitNextAffectedFile(writeFileCallback, void 0, void 0, transformers));
358
+ }
359
+ if (!isTest)
360
+ /**
361
+ * Perf: Output files on demand so the dev server
362
+ * isn't blocked when emitting files.
363
+ */
364
+ outputFile = writeOutputFile;
365
+ }
366
+ return {
367
+ name: "@analogjs/vite-plugin-angular",
368
+ api: compilerApi,
369
+ async config(config, { command, mode }) {
370
+ activateDeferredDebug(command);
371
+ const resolution = ctx.initConfig(config, {
372
+ command,
373
+ mode
374
+ });
375
+ const preliminaryTsConfigPath = ctx.resolveTsConfigPath();
376
+ const esbuild = config.esbuild ?? false;
377
+ const oxc = config.oxc ?? false;
378
+ const jsTransformConfigKey = getJsTransformConfigKey();
379
+ const jsTransformConfigValue = jsTransformConfigKey === "oxc" ? oxc : esbuild;
380
+ const depOptimizer = createDepOptimizerConfig({
381
+ tsconfig: preliminaryTsConfigPath,
382
+ isProd: resolution.isProd,
383
+ jit: ctx.options.jit,
384
+ watchMode: ctx.watchMode,
385
+ isTest: ctx.options.isTest,
386
+ isAstroIntegration: ctx.options.isAstroIntegration
387
+ });
388
+ return {
389
+ [jsTransformConfigKey]: jsTransformConfigValue,
390
+ ...depOptimizer
391
+ };
392
+ },
393
+ configResolved(config) {
394
+ ctx.setResolvedConfig(config);
395
+ if (!jit) styleTransform = (code, filename) => preprocessCSS(code, filename, config);
396
+ },
397
+ configureServer(server) {
398
+ viteServer = server;
399
+ hotUpdates.configureServer(server);
400
+ const invalidateCompilationOnFsChange = createFsWatcherCacheInvalidator(invalidateFsCaches, invalidateTsconfigCaches, () => performCompilation(ctx.resolvedConfig));
401
+ server.watcher.on("add", (file) => {
402
+ if (EXCLUDED_TS_EXT_REGEX.test(file)) invalidateSourceFiles(/* @__PURE__ */ new Set([normalizePath(file)]));
403
+ return invalidateCompilationOnFsChange();
404
+ });
405
+ server.watcher.on("unlink", (file) => {
406
+ const id = normalizePath(file);
407
+ outputFiles.delete(id);
408
+ tsSourceFileCache.delete(id);
409
+ sourceFileCache.invalidate(/* @__PURE__ */ new Set([id]));
410
+ evictDeletedFileMetadata(file, {
411
+ classNamesMap: ctx.hmr.classNames,
412
+ fileTransformMap
413
+ });
414
+ return invalidateCompilationOnFsChange();
415
+ });
416
+ server.watcher.on("change", (file) => {
417
+ if (file.includes("tsconfig")) invalidateTsconfigCaches();
418
+ });
419
+ },
420
+ async buildStart() {
421
+ activeBuilds++;
422
+ if (!jit) styleTransform = (code, filename) => preprocessCSS(code, filename, ctx.resolvedConfig);
423
+ if (!ctx.deferInitialCompilation) {
424
+ pendingCompilation = performCompilation(this.environment?.config ?? ctx.resolvedConfig);
425
+ await pendingCompilation;
426
+ pendingCompilation = null;
427
+ initialCompilation = true;
428
+ }
429
+ },
430
+ async buildEnd() {
431
+ activeBuilds = Math.max(0, activeBuilds - 1);
432
+ if (activeBuilds > 0) return;
433
+ if (closeRequested) {
434
+ await closeCompilation();
435
+ return;
436
+ }
437
+ if (!ctx.watchMode) releaseCompilation();
438
+ },
439
+ async handleHotUpdate(hmrCtx) {
440
+ if (ctx.hmr.isIgnoredFile(hmrCtx.file)) {
441
+ debugHmr("ignored file change", { file: hmrCtx.file });
442
+ return [];
443
+ }
444
+ if (TS_EXT_REGEX.test(hmrCtx.file)) {
445
+ const [fileId] = hmrCtx.file.split("?");
446
+ debugHmr("TS file changed", {
447
+ file: hmrCtx.file,
448
+ fileId
449
+ });
450
+ await hotUpdates.schedule(hmrCtx.file, [fileId]);
451
+ if (EXCLUDED_TS_EXT_REGEX.test(fileId)) {
452
+ hmrCtx.server.moduleGraph.invalidateAll();
453
+ hmrCtx.server.ws.send({
454
+ type: "full-reload",
455
+ triggeredBy: fileId
456
+ });
457
+ return [];
458
+ }
459
+ let result;
460
+ if (ctx.shouldEnableLiveReload()) {
461
+ result = fileEmitter(fileId);
462
+ debugHmr("TS file emitted", {
463
+ fileId,
464
+ hmrEligible: !!result?.hmrEligible,
465
+ hasClassName: !!ctx.hmr.classNames.get(fileId)
466
+ });
467
+ debugHmrV("ts hmr evaluation", {
468
+ file: hmrCtx.file,
469
+ fileId,
470
+ hasResult: !!result,
471
+ hmrEligible: !!result?.hmrEligible,
472
+ hasClassName: !!ctx.hmr.classNames.get(fileId),
473
+ className: ctx.hmr.classNames.get(fileId),
474
+ updateCode: result?.hmrUpdateCode ? describeStylesheetContent(result.hmrUpdateCode) : void 0,
475
+ errors: result?.errors?.length ?? 0,
476
+ warnings: result?.warnings?.length ?? 0,
477
+ 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."
478
+ });
479
+ }
480
+ if (ctx.shouldEnableLiveReload() && result?.hmrEligible && ctx.hmr.classNames.get(fileId)) {
481
+ const relativeFileId = ctx.hmr.toComponentUpdateId(fileId);
482
+ debugHmr("sending component update", { relativeFileId });
483
+ debugHmrV("ts hmr component update payload", {
484
+ file: hmrCtx.file,
485
+ fileId,
486
+ relativeFileId,
487
+ className: ctx.hmr.classNames.get(fileId)
488
+ });
489
+ ctx.hmr.sendComponentUpdate(hmrCtx.server, relativeFileId);
490
+ return hmrCtx.modules.map((mod) => {
491
+ if (mod.id === hmrCtx.file) return markModuleSelfAccepting(mod);
492
+ return mod;
493
+ });
494
+ }
495
+ }
496
+ if (/\.(html|htm|css|less|sass|scss)$/.test(hmrCtx.file)) {
497
+ debugHmr("resource file changed", { file: hmrCtx.file });
498
+ fileTransformMap.delete(hmrCtx.file.split("?")[0]);
499
+ const stylesheetRegistry = ctx.styles.registry;
500
+ const fileModules = await getModulesForChangedFile(hmrCtx.server, hmrCtx.file, hmrCtx.modules, stylesheetRegistry);
501
+ /**
502
+ * Check to see if this was a direct request
503
+ * for an external resource (styles, html).
504
+ */
505
+ const isDirect = fileModules.find((mod) => !!mod.id && mod.id.includes("?direct") && isModuleForChangedResource(mod, hmrCtx.file, stylesheetRegistry));
506
+ const isInline = fileModules.find((mod) => !!mod.id && mod.id.includes("?inline") && isModuleForChangedResource(mod, hmrCtx.file, stylesheetRegistry));
507
+ debugHmrV("resource direct/inline detection", {
508
+ file: hmrCtx.file,
509
+ hasDirect: !!isDirect,
510
+ directId: isDirect?.id,
511
+ hasInline: !!isInline,
512
+ inlineId: isInline?.id
513
+ });
514
+ if (isDirect || isInline) {
515
+ if (ctx.shouldExternalizeStyles() && isDirect?.id && isDirect.file) {
516
+ const isComponentStyle = isDirect.type === "css" && isComponentStyleSheet(isDirect.id);
517
+ debugHmrV("resource direct branch", {
518
+ file: hmrCtx.file,
519
+ directId: isDirect.id,
520
+ directType: isDirect.type,
521
+ shouldExternalize: ctx.shouldExternalizeStyles(),
522
+ isComponentStyle
523
+ });
524
+ if (isComponentStyle) return handleDirectComponentStyleHmr({
525
+ server: hmrCtx.server,
526
+ file: hmrCtx.file,
527
+ directModule: isDirect,
528
+ fileModules,
529
+ stylesheetRegistry,
530
+ stylePreprocessor: ctx.stylePreprocessor
531
+ });
532
+ }
533
+ return fileModules;
534
+ }
535
+ if (ctx.shouldEnableLiveReload() && /\.(html|htm)$/.test(hmrCtx.file) && fileModules.length === 0) {
536
+ const ownerModules = findTemplateOwnerModules(hmrCtx.server, hmrCtx.file);
537
+ debugHmrV("template owner lookup", {
538
+ file: hmrCtx.file,
539
+ ownerCount: ownerModules.length,
540
+ ownerIds: ownerModules.map((mod) => mod.id),
541
+ 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."
542
+ });
543
+ if (ownerModules.length > 0) {
544
+ const ownerIds = ownerModules.map((mod) => mod.id).filter(Boolean);
545
+ ownerModules.forEach((mod) => hmrCtx.server.moduleGraph.invalidateModule(mod));
546
+ await hotUpdates.schedule(hmrCtx.file, ownerIds);
547
+ const updates = ownerIds.filter((id) => ctx.hmr.classNames.get(id));
548
+ debugHmrV("template owner recompilation result", {
549
+ file: hmrCtx.file,
550
+ ownerIds,
551
+ updates,
552
+ updateClassNames: updates.map((id) => ({
553
+ id,
554
+ className: ctx.hmr.classNames.get(id)
555
+ })),
556
+ hint: updates.length > 0 ? "External template recompilation produced Angular component update targets." : "External template recompilation completed, but no Angular component update targets were surfaced."
557
+ });
558
+ if (updates.length > 0) {
559
+ debugHmr("template owner module invalidation", {
560
+ file: hmrCtx.file,
561
+ ownerIds,
562
+ updateCount: updates.length
563
+ });
564
+ updates.forEach((updateId) => {
565
+ ctx.hmr.sendComponentUpdate(hmrCtx.server, ctx.hmr.toComponentUpdateId(updateId));
566
+ });
567
+ return ownerModules.map((mod) => markModuleSelfAccepting(mod));
568
+ }
569
+ }
570
+ }
571
+ const importers = fileModules.flatMap((mod) => [...mod.importers]);
572
+ if (importers.length === 0) return [];
573
+ importers.forEach((imp) => hmrCtx.server.moduleGraph.invalidateModule(imp));
574
+ await hotUpdates.schedule(hmrCtx.file, importers.map((imp) => imp.id));
575
+ const mods = [];
576
+ const updates = [];
577
+ importers.forEach((imp) => {
578
+ if (ctx.shouldExternalizeStyles() && imp.id && ctx.hmr.classNames.get(imp.id)) updates.push(imp.id);
579
+ else mods.push(imp);
580
+ });
581
+ debugHmrV("resource importer analysis", {
582
+ file: hmrCtx.file,
583
+ fileModuleCount: fileModules.length,
584
+ importerCount: importers.length,
585
+ updates,
586
+ mods: mods.map((mod) => mod.id)
587
+ });
588
+ if (updates.length > 0) {
589
+ debugHmr("resource importer component updates", {
590
+ file: hmrCtx.file,
591
+ updateCount: updates.length
592
+ });
593
+ updates.forEach((updateId) => {
594
+ ctx.hmr.sendComponentUpdate(hmrCtx.server, ctx.hmr.toComponentUpdateId(updateId));
595
+ });
596
+ return fileModules.map((mod) => {
597
+ if (mod.id === hmrCtx.file) return markModuleSelfAccepting(mod);
598
+ return mod;
599
+ });
600
+ }
601
+ return mods;
602
+ }
603
+ debugHmr("full reload — unrecognized file type", { file: hmrCtx.file });
604
+ ctx.hmr.clear();
605
+ return hmrCtx.modules;
606
+ },
607
+ resolveId(id, importer) {
608
+ const virtualId = resolveAngularVirtualId(id, importer, {
609
+ jit,
610
+ resolvedConfig: ctx.resolvedConfig
611
+ });
612
+ if (virtualId !== void 0) return virtualId;
613
+ return ctx.styles.resolveComponentStyleId(id);
614
+ },
615
+ async load(id) {
616
+ const virtualModule = await loadAngularVirtualModule(this, id, ctx.resolvedConfig);
617
+ if (virtualModule !== void 0) return virtualModule;
618
+ return ctx.styles.loadComponentStyle(id);
619
+ },
620
+ transform: {
621
+ filter: { id: {
622
+ include: [TS_EXT_REGEX],
623
+ exclude: [
624
+ /node_modules/,
625
+ "type=script",
626
+ "@ng/component"
627
+ ]
628
+ } },
629
+ async handler(code, id) {
630
+ if (ctx.transformFilter && !ctx.transformFilter(code, id)) return;
631
+ if (id.includes(".ts?")) id = id.replace(/\?(.*)/, "");
632
+ fileTransformMap.set(id, code);
633
+ /**
634
+ * Re-analyze on each transform
635
+ * for test(Vitest)
636
+ */
637
+ if (isTest) {
638
+ if (ctx.deferInitialCompilation && !initialCompilation) {
639
+ pendingCompilation = performCompilation(this.environment?.config ?? ctx.resolvedConfig);
640
+ initialCompilation = true;
641
+ }
642
+ const tsMod = viteServer?.moduleGraph.getModuleById(id);
643
+ if (tsMod) {
644
+ const invalidated = tsMod.lastInvalidationTimestamp;
645
+ if (ctx.testWatchMode && invalidated) pendingCompilation = performCompilation(this.environment?.config ?? ctx.resolvedConfig, [id]);
646
+ }
647
+ }
648
+ const hasComponent = code.includes("@Component");
649
+ debugCompilerV("transform", {
650
+ id,
651
+ codeLength: code.length,
652
+ hasComponent
653
+ });
654
+ const resolveResourceUrls = hasComponent && (ctx.watchMode || jit);
655
+ const templateUrls = resolveResourceUrls ? templateUrlsResolver.resolve(code, id) : [];
656
+ const styleUrls = resolveResourceUrls ? styleUrlsResolver.resolve(code, id) : [];
657
+ if (resolveResourceUrls && ctx.watchMode) for (const urlSet of [...templateUrls, ...styleUrls]) {
658
+ const [, absoluteFileUrl] = urlSet.split("|");
659
+ this.addWatchFile(absoluteFileUrl);
660
+ }
661
+ if (pendingCompilation) {
662
+ await pendingCompilation;
663
+ pendingCompilation = null;
664
+ }
665
+ await hotUpdates.wait();
666
+ const typescriptResult = fileEmitter(id);
667
+ if (!typescriptResult) {
668
+ debugCompilerV("transform skip (file not emitted by Angular)", { id });
669
+ const isAngular = !id.includes("@ng/component") && /(Component|Directive|Pipe|Injectable|NgModule)\(/.test(code);
670
+ debugEmit("transform emit miss", {
671
+ id,
672
+ normalizedId: normalizeEmitterLookupId(id),
673
+ knownOutputCount: outputFiles.size,
674
+ hasOutputFileHook: !!outputFile,
675
+ isAngular
676
+ });
677
+ 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.`);
678
+ return;
679
+ }
680
+ if (typescriptResult.warnings && typescriptResult.warnings.length > 0) this.warn(`${typescriptResult.warnings.join("\n")}`);
681
+ if (typescriptResult.errors && typescriptResult.errors.length > 0) this.error(`${typescriptResult.errors.join("\n")}`);
682
+ let data = typescriptResult.content ?? "";
683
+ debugEmitV("transform emit hit", {
684
+ id,
685
+ normalizedId: normalizeEmitterLookupId(id),
686
+ ...describeEmitMarkers(data),
687
+ errorCount: typescriptResult.errors?.length ?? 0,
688
+ warningCount: typescriptResult.warnings?.length ?? 0
689
+ });
690
+ if (jit && data.includes("angular:jit:")) {
691
+ data = data.replace(/angular:jit:style:inline;([A-Za-z0-9+/=]*)/g, (_match, encodedStyles) => toJitInlineStyleId(encodedStyles, isTest));
692
+ templateUrls.forEach((templateUrlSet) => {
693
+ const [templateFile, resolvedTemplateUrl] = templateUrlSet.split("|");
694
+ data = data.replace(`angular:jit:template:file;${templateFile}`, toVirtualRawId(resolvedTemplateUrl));
695
+ });
696
+ styleUrls.forEach((styleUrlSet) => {
697
+ const [styleFile, resolvedStyleUrl] = styleUrlSet.split("|");
698
+ markStylePathSafe(ctx.resolvedConfig, resolvedStyleUrl);
699
+ data = data.replace(`angular:jit:style:file;${styleFile}`, resolvedStyleUrl + "?inline");
700
+ });
701
+ }
702
+ if (data.includes("HmrLoad")) {
703
+ const hasMetaUrl = data.includes("getReplaceMetadataURL");
704
+ debugHmrV("vite-ignore injection", {
705
+ id,
706
+ dataLength: data.length,
707
+ hasMetaUrl
708
+ });
709
+ if (hasMetaUrl) {
710
+ const patched = injectViteIgnoreForHmrMetadata(data);
711
+ if (patched !== data && !patched.includes("@vite-ignore")) debugHmrV("vite-ignore regex fallback", { id });
712
+ data = patched;
713
+ }
714
+ }
715
+ if (typescriptResult.map) data = data.replace(/\s*\/\/# sourceMappingURL=[^\r\n]*\s*$/, "");
716
+ return {
717
+ code: data,
718
+ map: typescriptResult.map ? normalizeSourceMapSources(typescriptResult.map, id) : null
719
+ };
720
+ }
721
+ },
722
+ async closeBundle() {
723
+ closeRequested = true;
724
+ if (activeBuilds === 0) await closeCompilation();
725
+ }
726
+ };
727
+ }
728
+ /**
729
+ * @internal
730
+ */
731
+ function getFileMetadata(program, angularCompiler, hmrEnabled, disableTypeChecking, classNamesMap = /* @__PURE__ */ new Map()) {
732
+ const ts = require("typescript");
733
+ return (file) => {
734
+ const sourceFile = program.getSourceFile(file);
735
+ if (!sourceFile) return {};
736
+ const diagnostics = getDiagnosticsForSourceFile(sourceFile, !!disableTypeChecking, program, angularCompiler);
737
+ const errors = diagnostics.filter((d) => d.category === ts.DiagnosticCategory?.Error).map((d) => typeof d.messageText === "object" ? d.messageText.messageText : d.messageText);
738
+ const warnings = diagnostics.filter((d) => d.category === ts.DiagnosticCategory?.Warning).map((d) => d.messageText);
739
+ let hmrUpdateCode = void 0;
740
+ let hmrEligible = false;
741
+ if (hmrEnabled) {
742
+ for (const node of sourceFile.statements) if (ts.isClassDeclaration(node) && node.name != null) {
743
+ hmrUpdateCode = angularCompiler?.emitHmrUpdateModule(node);
744
+ if (hmrUpdateCode) {
745
+ const className = node.name.getText();
746
+ classNamesMap.set(file, className);
747
+ hmrEligible = true;
748
+ debugHmr("NgtscProgram emitHmrUpdateModule", {
749
+ file,
750
+ className
751
+ });
752
+ }
753
+ }
754
+ }
755
+ return {
756
+ errors,
757
+ warnings,
758
+ hmrUpdateCode,
759
+ hmrEligible
760
+ };
761
+ };
762
+ }
763
+ function getDiagnosticsForSourceFile(sourceFile, disableTypeChecking, program, angularCompiler) {
764
+ const syntacticDiagnostics = program.getSyntacticDiagnostics(sourceFile);
765
+ if (disableTypeChecking) return syntacticDiagnostics;
766
+ const semanticDiagnostics = program.getSemanticDiagnostics(sourceFile);
767
+ const angularDiagnostics = angularCompiler ? angularCompiler.getDiagnosticsForFile(sourceFile, 1) : [];
768
+ return [
769
+ ...syntacticDiagnostics,
770
+ ...semanticDiagnostics,
771
+ ...angularDiagnostics
772
+ ];
773
+ }
774
+ export { createFsWatcherCacheInvalidator, evictDeletedFileMetadata, getFileMetadata, ngtscCompilePlugin };
775
+
776
+ //# sourceMappingURL=ngtsc-compile-plugin.js.map