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

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 (164) 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 +217 -0
  14. package/src/lib/angular-build-context.js +374 -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 +164 -289
  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 +8 -5
  101. package/src/lib/live-reload-plugin.js +45 -10
  102. package/src/lib/live-reload-plugin.js.map +1 -1
  103. package/src/lib/models.d.ts +4 -1
  104. package/src/lib/ngp-compile-api.d.ts +55 -0
  105. package/src/lib/ngp-compile-api.js +11 -0
  106. package/src/lib/ngp-compile-api.js.map +1 -0
  107. package/src/lib/ngp-compile-plugin.d.ts +4 -0
  108. package/src/lib/ngp-compile-plugin.js +680 -0
  109. package/src/lib/ngp-compile-plugin.js.map +1 -0
  110. package/src/lib/ngtsc-compile-plugin.d.ts +23 -0
  111. package/src/lib/ngtsc-compile-plugin.js +780 -0
  112. package/src/lib/ngtsc-compile-plugin.js.map +1 -0
  113. package/src/lib/nx-folder-plugin.d.ts +6 -5
  114. package/src/lib/nx-folder-plugin.js +13 -9
  115. package/src/lib/nx-folder-plugin.js.map +1 -1
  116. package/src/lib/plugins/file-replacements.plugin.d.ts +6 -0
  117. package/src/lib/plugins/file-replacements.plugin.js +2 -2
  118. package/src/lib/plugins/file-replacements.plugin.js.map +1 -1
  119. package/src/lib/router-plugin.d.ts +5 -1
  120. package/src/lib/router-plugin.js +14 -6
  121. package/src/lib/router-plugin.js.map +1 -1
  122. package/src/lib/style-preprocessor.js +1 -2
  123. package/src/lib/stylesheet-registry.js +1 -2
  124. package/src/lib/stylesheet-registry.js.map +1 -1
  125. package/src/lib/tools/src/builders/vite/vite-build.impl.js +2 -3
  126. package/src/lib/tools/src/builders/vite/vite-build.impl.js.map +1 -1
  127. package/src/lib/tools/src/builders/vite-dev-server/dev-server.impl.js +1 -2
  128. package/src/lib/tools/src/builders/vite-dev-server/dev-server.impl.js.map +1 -1
  129. package/src/lib/utils/compilation-shared.d.ts +1 -4
  130. package/src/lib/utils/compilation-shared.js +9 -8
  131. package/src/lib/utils/compilation-shared.js.map +1 -1
  132. package/src/lib/utils/css-extension-resolver.js +1 -2
  133. package/src/lib/utils/css-preprocessor-workers.js +1 -2
  134. package/src/lib/utils/debug-harness.js +1 -2
  135. package/src/lib/utils/debug-log-file.js +1 -2
  136. package/src/lib/utils/debug.js +1 -2
  137. package/src/lib/utils/devkit.js +2 -3
  138. package/src/lib/utils/hmr-component-updates.d.ts +7 -0
  139. package/src/lib/utils/hmr-component-updates.js +86 -0
  140. package/src/lib/utils/hmr-component-updates.js.map +1 -0
  141. package/src/lib/utils/jit-inline-styles.js +1 -2
  142. package/src/lib/utils/lsp-type-checker.d.ts +75 -0
  143. package/src/lib/utils/lsp-type-checker.js +532 -0
  144. package/src/lib/utils/lsp-type-checker.js.map +1 -0
  145. package/src/lib/utils/ngp-host-fs.d.ts +43 -0
  146. package/src/lib/utils/ngp-host-fs.js +128 -0
  147. package/src/lib/utils/ngp-host-fs.js.map +1 -0
  148. package/src/lib/utils/plugin-config.d.ts +15 -8
  149. package/src/lib/utils/plugin-config.js +19 -7
  150. package/src/lib/utils/plugin-config.js.map +1 -1
  151. package/src/lib/utils/rolldown.js +1 -2
  152. package/src/lib/utils/safe-module-paths.js +1 -2
  153. package/src/lib/utils/stylesheet-warning.d.ts +2 -0
  154. package/src/lib/utils/stylesheet-warning.js +10 -0
  155. package/src/lib/utils/stylesheet-warning.js.map +1 -0
  156. package/src/lib/utils/transform-cache.js +1 -2
  157. package/src/lib/utils/transform-cache.js.map +1 -1
  158. package/src/lib/utils/tsconfig-resolver.js +2 -3
  159. package/src/lib/utils/virtual-ids.js +1 -2
  160. package/src/lib/utils/virtual-resources.js +1 -2
  161. package/src/lib/utils/virtual-resources.js.map +1 -1
  162. package/src/lib/virtual-modules-plugin.d.ts +11 -3
  163. package/src/lib/virtual-modules-plugin.js +70 -15
  164. package/src/lib/virtual-modules-plugin.js.map +1 -1
@@ -0,0 +1,780 @@
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, className) => ({ hmrUpdateCode: fileEmitter(file)?.hmrUpdateCodes?.get(className) }));
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
+ hmrUpdateCodes: metadata.hmrUpdateCodes,
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
+ const fileClassNames = ctx.hmr.classNames.get(fileId);
463
+ debugHmr("TS file emitted", {
464
+ fileId,
465
+ hmrEligible: !!result?.hmrEligible,
466
+ hasClassName: !!fileClassNames?.size
467
+ });
468
+ debugHmrV("ts hmr evaluation", {
469
+ file: hmrCtx.file,
470
+ fileId,
471
+ hasResult: !!result,
472
+ hmrEligible: !!result?.hmrEligible,
473
+ hasClassName: !!fileClassNames?.size,
474
+ classNames: fileClassNames ? [...fileClassNames] : void 0,
475
+ updateCodes: result?.hmrUpdateCodes ? Object.fromEntries([...result.hmrUpdateCodes].map(([name, code]) => [name, describeStylesheetContent(code)])) : void 0,
476
+ errors: result?.errors?.length ?? 0,
477
+ warnings: result?.warnings?.length ?? 0,
478
+ 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."
479
+ });
480
+ }
481
+ const tsUpdateIds = ctx.shouldEnableLiveReload() && result?.hmrEligible ? ctx.hmr.toComponentUpdateIds(fileId) : [];
482
+ if (tsUpdateIds.length > 0) {
483
+ for (const relativeFileId of tsUpdateIds) {
484
+ debugHmr("sending component update", { relativeFileId });
485
+ debugHmrV("ts hmr component update payload", {
486
+ file: hmrCtx.file,
487
+ fileId,
488
+ relativeFileId
489
+ });
490
+ ctx.hmr.sendComponentUpdate(hmrCtx.server, relativeFileId);
491
+ }
492
+ return hmrCtx.modules.map((mod) => {
493
+ if (mod.id === hmrCtx.file) return markModuleSelfAccepting(mod);
494
+ return mod;
495
+ });
496
+ }
497
+ }
498
+ if (/\.(html|htm|css|less|sass|scss)$/.test(hmrCtx.file)) {
499
+ debugHmr("resource file changed", { file: hmrCtx.file });
500
+ fileTransformMap.delete(hmrCtx.file.split("?")[0]);
501
+ const stylesheetRegistry = ctx.styles.registry;
502
+ const fileModules = await getModulesForChangedFile(hmrCtx.server, hmrCtx.file, hmrCtx.modules, stylesheetRegistry);
503
+ /**
504
+ * Check to see if this was a direct request
505
+ * for an external resource (styles, html).
506
+ */
507
+ const isDirect = fileModules.find((mod) => !!mod.id && mod.id.includes("?direct") && isModuleForChangedResource(mod, hmrCtx.file, stylesheetRegistry));
508
+ const isInline = fileModules.find((mod) => !!mod.id && mod.id.includes("?inline") && isModuleForChangedResource(mod, hmrCtx.file, stylesheetRegistry));
509
+ debugHmrV("resource direct/inline detection", {
510
+ file: hmrCtx.file,
511
+ hasDirect: !!isDirect,
512
+ directId: isDirect?.id,
513
+ hasInline: !!isInline,
514
+ inlineId: isInline?.id
515
+ });
516
+ if (isDirect || isInline) {
517
+ if (ctx.shouldExternalizeStyles() && isDirect?.id && isDirect.file) {
518
+ const isComponentStyle = isDirect.type === "css" && isComponentStyleSheet(isDirect.id);
519
+ debugHmrV("resource direct branch", {
520
+ file: hmrCtx.file,
521
+ directId: isDirect.id,
522
+ directType: isDirect.type,
523
+ shouldExternalize: ctx.shouldExternalizeStyles(),
524
+ isComponentStyle
525
+ });
526
+ if (isComponentStyle) return handleDirectComponentStyleHmr({
527
+ server: hmrCtx.server,
528
+ file: hmrCtx.file,
529
+ directModule: isDirect,
530
+ fileModules,
531
+ stylesheetRegistry,
532
+ stylePreprocessor: ctx.stylePreprocessor
533
+ });
534
+ }
535
+ return fileModules;
536
+ }
537
+ if (ctx.shouldEnableLiveReload() && /\.(html|htm)$/.test(hmrCtx.file) && fileModules.length === 0) {
538
+ const ownerModules = findTemplateOwnerModules(hmrCtx.server, hmrCtx.file);
539
+ debugHmrV("template owner lookup", {
540
+ file: hmrCtx.file,
541
+ ownerCount: ownerModules.length,
542
+ ownerIds: ownerModules.map((mod) => mod.id),
543
+ 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."
544
+ });
545
+ if (ownerModules.length > 0) {
546
+ const ownerIds = ownerModules.map((mod) => mod.id).filter(Boolean);
547
+ ownerModules.forEach((mod) => hmrCtx.server.moduleGraph.invalidateModule(mod));
548
+ await hotUpdates.schedule(hmrCtx.file, ownerIds);
549
+ const updates = ownerIds.filter((id) => ctx.hmr.classNames.get(id)?.size);
550
+ debugHmrV("template owner recompilation result", {
551
+ file: hmrCtx.file,
552
+ ownerIds,
553
+ updates,
554
+ updateClassNames: updates.map((id) => ({
555
+ id,
556
+ classNames: [...ctx.hmr.classNames.get(id) ?? []]
557
+ })),
558
+ hint: updates.length > 0 ? "External template recompilation produced Angular component update targets." : "External template recompilation completed, but no Angular component update targets were surfaced."
559
+ });
560
+ if (updates.length > 0) {
561
+ debugHmr("template owner module invalidation", {
562
+ file: hmrCtx.file,
563
+ ownerIds,
564
+ updateCount: updates.length
565
+ });
566
+ updates.forEach((updateId) => {
567
+ for (const relativeFileId of ctx.hmr.toComponentUpdateIds(updateId)) ctx.hmr.sendComponentUpdate(hmrCtx.server, relativeFileId);
568
+ });
569
+ return ownerModules.map((mod) => markModuleSelfAccepting(mod));
570
+ }
571
+ }
572
+ }
573
+ const importers = fileModules.flatMap((mod) => [...mod.importers]);
574
+ if (importers.length === 0) return [];
575
+ importers.forEach((imp) => hmrCtx.server.moduleGraph.invalidateModule(imp));
576
+ await hotUpdates.schedule(hmrCtx.file, importers.map((imp) => imp.id));
577
+ const mods = [];
578
+ const updates = [];
579
+ importers.forEach((imp) => {
580
+ if (ctx.shouldExternalizeStyles() && imp.id && ctx.hmr.classNames.get(imp.id)?.size) updates.push(imp.id);
581
+ else mods.push(imp);
582
+ });
583
+ debugHmrV("resource importer analysis", {
584
+ file: hmrCtx.file,
585
+ fileModuleCount: fileModules.length,
586
+ importerCount: importers.length,
587
+ updates,
588
+ mods: mods.map((mod) => mod.id)
589
+ });
590
+ if (updates.length > 0) {
591
+ debugHmr("resource importer component updates", {
592
+ file: hmrCtx.file,
593
+ updateCount: updates.length
594
+ });
595
+ updates.forEach((updateId) => {
596
+ for (const relativeFileId of ctx.hmr.toComponentUpdateIds(updateId)) ctx.hmr.sendComponentUpdate(hmrCtx.server, relativeFileId);
597
+ });
598
+ return fileModules.map((mod) => {
599
+ if (mod.id === hmrCtx.file) return markModuleSelfAccepting(mod);
600
+ return mod;
601
+ });
602
+ }
603
+ return mods;
604
+ }
605
+ debugHmr("full reload — unrecognized file type", { file: hmrCtx.file });
606
+ ctx.hmr.clear();
607
+ return hmrCtx.modules;
608
+ },
609
+ resolveId(id, importer) {
610
+ const virtualId = resolveAngularVirtualId(id, importer, {
611
+ jit,
612
+ resolvedConfig: ctx.resolvedConfig
613
+ });
614
+ if (virtualId !== void 0) return virtualId;
615
+ return ctx.styles.resolveComponentStyleId(id);
616
+ },
617
+ async load(id) {
618
+ const virtualModule = await loadAngularVirtualModule(this, id, ctx.resolvedConfig);
619
+ if (virtualModule !== void 0) return virtualModule;
620
+ return ctx.styles.loadComponentStyle(id);
621
+ },
622
+ transform: {
623
+ filter: { id: {
624
+ include: [TS_EXT_REGEX],
625
+ exclude: [
626
+ /node_modules/,
627
+ "type=script",
628
+ "@ng/component"
629
+ ]
630
+ } },
631
+ async handler(code, id) {
632
+ if (ctx.transformFilter && !ctx.transformFilter(code, id)) return;
633
+ if (id.includes(".ts?")) id = id.replace(/\?(.*)/, "");
634
+ fileTransformMap.set(id, code);
635
+ /**
636
+ * Re-analyze on each transform
637
+ * for test(Vitest)
638
+ */
639
+ if (isTest) {
640
+ if (ctx.deferInitialCompilation && !initialCompilation) {
641
+ pendingCompilation = performCompilation(this.environment?.config ?? ctx.resolvedConfig);
642
+ initialCompilation = true;
643
+ }
644
+ const tsMod = viteServer?.moduleGraph.getModuleById(id);
645
+ if (tsMod) {
646
+ const invalidated = tsMod.lastInvalidationTimestamp;
647
+ if (ctx.testWatchMode && invalidated) pendingCompilation = performCompilation(this.environment?.config ?? ctx.resolvedConfig, [id]);
648
+ }
649
+ }
650
+ const hasComponent = code.includes("@Component");
651
+ debugCompilerV("transform", {
652
+ id,
653
+ codeLength: code.length,
654
+ hasComponent
655
+ });
656
+ const resolveResourceUrls = hasComponent && (ctx.watchMode || jit);
657
+ const templateUrls = resolveResourceUrls ? templateUrlsResolver.resolve(code, id) : [];
658
+ const styleUrls = resolveResourceUrls ? styleUrlsResolver.resolve(code, id) : [];
659
+ if (resolveResourceUrls && ctx.watchMode) for (const urlSet of [...templateUrls, ...styleUrls]) {
660
+ const [, absoluteFileUrl] = urlSet.split("|");
661
+ this.addWatchFile(absoluteFileUrl);
662
+ }
663
+ if (pendingCompilation) {
664
+ await pendingCompilation;
665
+ pendingCompilation = null;
666
+ }
667
+ await hotUpdates.wait();
668
+ const typescriptResult = fileEmitter(id);
669
+ if (!typescriptResult) {
670
+ debugCompilerV("transform skip (file not emitted by Angular)", { id });
671
+ const isAngular = !id.includes("@ng/component") && /(Component|Directive|Pipe|Injectable|NgModule)\(/.test(code);
672
+ debugEmit("transform emit miss", {
673
+ id,
674
+ normalizedId: normalizeEmitterLookupId(id),
675
+ knownOutputCount: outputFiles.size,
676
+ hasOutputFileHook: !!outputFile,
677
+ isAngular
678
+ });
679
+ 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.`);
680
+ return;
681
+ }
682
+ if (typescriptResult.warnings && typescriptResult.warnings.length > 0) this.warn(`${typescriptResult.warnings.join("\n")}`);
683
+ if (typescriptResult.errors && typescriptResult.errors.length > 0) this.error(`${typescriptResult.errors.join("\n")}`);
684
+ let data = typescriptResult.content ?? "";
685
+ debugEmitV("transform emit hit", {
686
+ id,
687
+ normalizedId: normalizeEmitterLookupId(id),
688
+ ...describeEmitMarkers(data),
689
+ errorCount: typescriptResult.errors?.length ?? 0,
690
+ warningCount: typescriptResult.warnings?.length ?? 0
691
+ });
692
+ if (jit && data.includes("angular:jit:")) {
693
+ data = data.replace(/angular:jit:style:inline;([A-Za-z0-9+/=]*)/g, (_match, encodedStyles) => toJitInlineStyleId(encodedStyles, isTest));
694
+ templateUrls.forEach((templateUrlSet) => {
695
+ const [templateFile, resolvedTemplateUrl] = templateUrlSet.split("|");
696
+ data = data.replace(`angular:jit:template:file;${templateFile}`, toVirtualRawId(resolvedTemplateUrl));
697
+ });
698
+ styleUrls.forEach((styleUrlSet) => {
699
+ const [styleFile, resolvedStyleUrl] = styleUrlSet.split("|");
700
+ markStylePathSafe(ctx.resolvedConfig, resolvedStyleUrl);
701
+ data = data.replace(`angular:jit:style:file;${styleFile}`, resolvedStyleUrl + "?inline");
702
+ });
703
+ }
704
+ if (data.includes("HmrLoad")) {
705
+ const hasMetaUrl = data.includes("getReplaceMetadataURL");
706
+ debugHmrV("vite-ignore injection", {
707
+ id,
708
+ dataLength: data.length,
709
+ hasMetaUrl
710
+ });
711
+ if (hasMetaUrl) {
712
+ const patched = injectViteIgnoreForHmrMetadata(data);
713
+ if (patched !== data && !patched.includes("@vite-ignore")) debugHmrV("vite-ignore regex fallback", { id });
714
+ data = patched;
715
+ }
716
+ }
717
+ if (typescriptResult.map) data = data.replace(/\s*\/\/# sourceMappingURL=[^\r\n]*\s*$/, "");
718
+ return {
719
+ code: data,
720
+ map: typescriptResult.map ? normalizeSourceMapSources(typescriptResult.map, id) : null
721
+ };
722
+ }
723
+ },
724
+ async closeBundle() {
725
+ closeRequested = true;
726
+ if (activeBuilds === 0) await closeCompilation();
727
+ }
728
+ };
729
+ }
730
+ /**
731
+ * @internal
732
+ */
733
+ function getFileMetadata(program, angularCompiler, hmrEnabled, disableTypeChecking, classNamesMap = /* @__PURE__ */ new Map()) {
734
+ const ts = require("typescript");
735
+ return (file) => {
736
+ const sourceFile = program.getSourceFile(file);
737
+ if (!sourceFile) return {};
738
+ const diagnostics = getDiagnosticsForSourceFile(sourceFile, !!disableTypeChecking, program, angularCompiler);
739
+ const errors = diagnostics.filter((d) => d.category === ts.DiagnosticCategory?.Error).map((d) => typeof d.messageText === "object" ? d.messageText.messageText : d.messageText);
740
+ const warnings = diagnostics.filter((d) => d.category === ts.DiagnosticCategory?.Warning).map((d) => d.messageText);
741
+ const hmrUpdateCodes = /* @__PURE__ */ new Map();
742
+ let hmrEligible = false;
743
+ if (hmrEnabled) {
744
+ for (const node of sourceFile.statements) if (ts.isClassDeclaration(node) && node.name != null) {
745
+ const updateCode = angularCompiler?.emitHmrUpdateModule(node);
746
+ if (updateCode) {
747
+ const className = node.name.getText();
748
+ hmrUpdateCodes.set(className, updateCode);
749
+ hmrEligible = true;
750
+ debugHmr("NgtscProgram emitHmrUpdateModule", {
751
+ file,
752
+ className
753
+ });
754
+ }
755
+ }
756
+ if (hmrUpdateCodes.size > 0) classNamesMap.set(file, new Set(hmrUpdateCodes.keys()));
757
+ else classNamesMap.delete(file);
758
+ }
759
+ return {
760
+ errors,
761
+ warnings,
762
+ hmrUpdateCodes: hmrUpdateCodes.size > 0 ? hmrUpdateCodes : void 0,
763
+ hmrEligible
764
+ };
765
+ };
766
+ }
767
+ function getDiagnosticsForSourceFile(sourceFile, disableTypeChecking, program, angularCompiler) {
768
+ const syntacticDiagnostics = program.getSyntacticDiagnostics(sourceFile);
769
+ if (disableTypeChecking) return syntacticDiagnostics;
770
+ const semanticDiagnostics = program.getSemanticDiagnostics(sourceFile);
771
+ const angularDiagnostics = angularCompiler ? angularCompiler.getDiagnosticsForFile(sourceFile, 1) : [];
772
+ return [
773
+ ...syntacticDiagnostics,
774
+ ...semanticDiagnostics,
775
+ ...angularDiagnostics
776
+ ];
777
+ }
778
+ export { createFsWatcherCacheInvalidator, evictDeletedFileMetadata, getFileMetadata, ngtscCompilePlugin };
779
+
780
+ //# sourceMappingURL=ngtsc-compile-plugin.js.map