@analogjs/vite-plugin-angular 3.0.0-alpha.22 → 3.0.0-alpha.23

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@analogjs/vite-plugin-angular",
3
- "version": "3.0.0-alpha.22",
3
+ "version": "3.0.0-alpha.23",
4
4
  "description": "Vite Plugin for Angular",
5
5
  "type": "module",
6
6
  "keywords": [
@@ -36,6 +36,7 @@
36
36
  }
37
37
  },
38
38
  "dependencies": {
39
+ "obug": "^2.1.1",
39
40
  "oxc-parser": "^0.121.0",
40
41
  "oxc-resolver": "^11.19.1",
41
42
  "rolldown": "^1.0.0-rc.12",
@@ -2,6 +2,7 @@ import { NgtscProgram } from "@angular/compiler-cli";
2
2
  import * as ts from "typescript";
3
3
  import { Plugin } from "vite";
4
4
  import type { StylePreprocessor } from "./style-preprocessor.js";
5
+ import { type DebugOption } from "./utils/debug.js";
5
6
  import { FileReplacement } from "./plugins/file-replacements.plugin.js";
6
7
  export declare enum DiagnosticModes {
7
8
  None = 0,
@@ -35,6 +36,18 @@ export interface PluginOptions {
35
36
  useAngularCompilationAPI?: boolean;
36
37
  };
37
38
  /**
39
+ * Enable debug logging for specific scopes.
40
+ *
41
+ * - `true` → enables all `analog:angular:*` scopes
42
+ * - `string[]` → enables listed namespaces (e.g. `['analog:angular:compiler']`)
43
+ * - `{ scopes?, mode? }` → object form with optional `mode: 'build' | 'dev'`
44
+ * to restrict output to a specific Vite command (omit for both)
45
+ *
46
+ * Also responds to the `DEBUG` env var (Node.js) or `localStorage.debug`
47
+ * (browser), using the `obug` convention.
48
+ */
49
+ debug?: DebugOption;
50
+ /**
38
51
  * Optional preprocessor that transforms component CSS before it enters Vite's
39
52
  * preprocessCSS pipeline. Runs on every component stylesheet (both external
40
53
  * `.component.css` files and inline `styles: [...]` blocks).
@@ -4,6 +4,7 @@ import { buildOptimizerPlugin } from "./angular-build-optimizer-plugin.js";
4
4
  import { jitPlugin } from "./angular-jit-plugin.js";
5
5
  import { createCompilerPlugin, createRolldownCompilerPlugin } from "./compiler-plugin.js";
6
6
  import { StyleUrlsResolver, TemplateUrlsResolver } from "./component-resolvers.js";
7
+ import { activateDeferredDebug, applyDebugOption, debugCompilationApi, debugCompiler, debugHmr, debugStyles, debugTailwind } from "./utils/debug.js";
7
8
  import { augmentHostWithCaching, augmentHostWithResources, augmentProgramWithVersioning, mergeTransformers } from "./host.js";
8
9
  import { angularVitestPlugins } from "./angular-vitest-plugin.js";
9
10
  import { pendingTasksPlugin } from "./angular-pending-tasks.plugin.js";
@@ -49,18 +50,33 @@ function buildStylePreprocessor(options) {
49
50
  if (tw) {
50
51
  const rootStylesheet = tw.rootStylesheet;
51
52
  const prefixes = tw.prefixes;
53
+ debugTailwind("configured", {
54
+ rootStylesheet,
55
+ prefixes
56
+ });
52
57
  tailwindPreprocessor = (code, filename) => {
53
- if (code.includes("@reference") || code.includes("@import \"tailwindcss\"") || code.includes("@import 'tailwindcss'")) return code;
54
- if (!(prefixes ? prefixes.some((prefix) => code.includes(prefix)) : code.includes("@apply"))) return code;
58
+ if (code.includes("@reference") || code.includes("@import \"tailwindcss\"") || code.includes("@import 'tailwindcss'")) {
59
+ debugTailwind("skip (already has @reference or is root)", { filename });
60
+ return code;
61
+ }
62
+ if (!(prefixes ? prefixes.some((prefix) => code.includes(prefix)) : code.includes("@apply"))) {
63
+ debugTailwind("skip (no Tailwind usage detected)", { filename });
64
+ return code;
65
+ }
66
+ debugTailwind("injected @reference", { filename });
55
67
  return `@reference "${relative(dirname(filename), rootStylesheet)}";\n${code}`;
56
68
  };
57
69
  }
58
- if (tailwindPreprocessor && userPreprocessor) return (code, filename) => {
59
- return userPreprocessor(tailwindPreprocessor(code, filename), filename);
60
- };
70
+ if (tailwindPreprocessor && userPreprocessor) {
71
+ debugTailwind("chained with user stylePreprocessor");
72
+ return (code, filename) => {
73
+ return userPreprocessor(tailwindPreprocessor(code, filename), filename);
74
+ };
75
+ }
61
76
  return tailwindPreprocessor ?? userPreprocessor;
62
77
  }
63
78
  function angular(options) {
79
+ applyDebugOption(options?.debug);
64
80
  /**
65
81
  * Normalize plugin options so defaults
66
82
  * are used for values not provided.
@@ -129,16 +145,22 @@ function angular(options) {
129
145
  let angularCompilation;
130
146
  function angularPlugin() {
131
147
  let isProd = false;
132
- if (angularFullVersion < 19e4 || isTest) pluginOptions.liveReload = false;
133
- if (pluginOptions.useAngularCompilationAPI) {
134
- if (angularFullVersion < 200100) {
135
- pluginOptions.useAngularCompilationAPI = false;
136
- console.warn("[@analogjs/vite-plugin-angular]: The Angular Compilation API is only available with Angular v20.1 and later");
137
- }
148
+ if (angularFullVersion < 19e4 || isTest) {
149
+ pluginOptions.liveReload = false;
150
+ debugHmr("liveReload disabled", {
151
+ angularVersion: angularFullVersion,
152
+ isTest
153
+ });
138
154
  }
155
+ if (pluginOptions.useAngularCompilationAPI) if (angularFullVersion < 200100) {
156
+ pluginOptions.useAngularCompilationAPI = false;
157
+ debugCompilationApi("disabled: Angular version %s < 20.1", angularFullVersion);
158
+ console.warn("[@analogjs/vite-plugin-angular]: The Angular Compilation API is only available with Angular v20.1 and later");
159
+ } else debugCompilationApi("enabled (Angular %s)", angularFullVersion);
139
160
  return {
140
161
  name: "@analogjs/vite-plugin-angular",
141
162
  async config(config, { command }) {
163
+ activateDeferredDebug(command);
142
164
  watchMode = command === "serve";
143
165
  isProd = config.mode === "production" || process.env.NODE_ENV === "production";
144
166
  tsConfigResolutionContext = {
@@ -149,6 +171,7 @@ function angular(options) {
149
171
  const preliminaryTsConfigPath = resolveTsConfigPath();
150
172
  const esbuild = pluginOptions.useAngularCompilationAPI ? void 0 : config.esbuild ?? false;
151
173
  const oxc = pluginOptions.useAngularCompilationAPI ? void 0 : config.oxc ?? false;
174
+ if (pluginOptions.useAngularCompilationAPI) debugCompilationApi("esbuild/oxc disabled, Angular handles transforms");
152
175
  const defineOptions = {
153
176
  ngJitMode: "false",
154
177
  ngI18nClosureMode: "false",
@@ -189,6 +212,7 @@ function angular(options) {
189
212
  if (pluginOptions.useAngularCompilationAPI) {
190
213
  externalComponentStyles = /* @__PURE__ */ new Map();
191
214
  inlineComponentStyles = /* @__PURE__ */ new Map();
215
+ debugStyles("style maps initialized (Angular Compilation API)");
192
216
  }
193
217
  if (!jit) styleTransform = (code, filename) => preprocessCSS(code, filename, config);
194
218
  if (isTest) testWatchMode = !(config.server.watch === null) || config.test?.watch === true || testWatchMode;
@@ -212,15 +236,25 @@ function angular(options) {
212
236
  async handleHotUpdate(ctx) {
213
237
  if (TS_EXT_REGEX.test(ctx.file)) {
214
238
  const [fileId] = ctx.file.split("?");
239
+ debugHmr("TS file changed", {
240
+ file: ctx.file,
241
+ fileId
242
+ });
215
243
  pendingCompilation = performCompilation(resolvedConfig, [fileId]);
216
244
  let result;
217
245
  if (pluginOptions.liveReload) {
218
246
  await pendingCompilation;
219
247
  pendingCompilation = null;
220
248
  result = fileEmitter(fileId);
249
+ debugHmr("TS file emitted", {
250
+ fileId,
251
+ hmrEligible: !!result?.hmrEligible,
252
+ hasClassName: !!classNames.get(fileId)
253
+ });
221
254
  }
222
255
  if (pluginOptions.liveReload && result?.hmrEligible && classNames.get(fileId)) {
223
256
  const relativeFileId = `${normalizePath(relative(process.cwd(), fileId))}@${classNames.get(fileId)}`;
257
+ debugHmr("sending component update", { relativeFileId });
224
258
  sendHMRComponentUpdate(ctx.server, relativeFileId);
225
259
  return ctx.modules.map((mod) => {
226
260
  if (mod.id === ctx.file) return markModuleSelfAccepting(mod);
@@ -229,6 +263,7 @@ function angular(options) {
229
263
  }
230
264
  }
231
265
  if (/\.(html|htm|css|less|sass|scss)$/.test(ctx.file)) {
266
+ debugHmr("resource file changed", { file: ctx.file });
232
267
  fileTransformMap.delete(ctx.file.split("?")[0]);
233
268
  /**
234
269
  * Check to see if this was a direct request
@@ -240,6 +275,10 @@ function angular(options) {
240
275
  if (pluginOptions.liveReload && isDirect?.id && isDirect.file) {
241
276
  if (isDirect.type === "css" && isComponentStyleSheet(isDirect.id)) {
242
277
  const { encapsulation } = getComponentStyleSheetMeta(isDirect.id);
278
+ debugStyles("HMR: component stylesheet changed", {
279
+ file: isDirect.file,
280
+ encapsulation
281
+ });
243
282
  if (encapsulation !== "shadow") {
244
283
  ctx.server.ws.send({
245
284
  type: "update",
@@ -274,6 +313,10 @@ function angular(options) {
274
313
  if (updates.length > 0) {
275
314
  await pendingCompilation;
276
315
  pendingCompilation = null;
316
+ debugHmr("resource importer component updates", {
317
+ file: ctx.file,
318
+ updateCount: updates.length
319
+ });
277
320
  updates.forEach((updateId) => {
278
321
  const impRelativeFileId = `${normalizePath(relative(process.cwd(), updateId))}@${classNames.get(updateId)}`;
279
322
  sendHMRComponentUpdate(ctx.server, impRelativeFileId);
@@ -285,6 +328,7 @@ function angular(options) {
285
328
  }
286
329
  return mods;
287
330
  }
331
+ debugHmr("full reload — unrecognized file type", { file: ctx.file });
288
332
  classNames.clear();
289
333
  return ctx.modules;
290
334
  },
@@ -294,14 +338,28 @@ function angular(options) {
294
338
  return `${normalizePath(resolve(dirname(importer), path))}?${id.includes(":style") ? "inline" : "raw"}`;
295
339
  }
296
340
  if (isComponentStyleSheet(id)) {
297
- const componentStyles = externalComponentStyles?.get(getFilenameFromPath(id));
298
- if (componentStyles) return componentStyles + new URL(id, "http://localhost").search;
341
+ const filename = getFilenameFromPath(id);
342
+ const componentStyles = externalComponentStyles?.get(filename);
343
+ if (componentStyles) {
344
+ debugStyles("resolveId: mapped external stylesheet", {
345
+ filename,
346
+ resolvedPath: componentStyles
347
+ });
348
+ return componentStyles + new URL(id, "http://localhost").search;
349
+ }
299
350
  }
300
351
  },
301
352
  async load(id) {
302
353
  if (isComponentStyleSheet(id)) {
303
- const componentStyles = inlineComponentStyles?.get(getFilenameFromPath(id));
304
- if (componentStyles) return componentStyles;
354
+ const filename = getFilenameFromPath(id);
355
+ const componentStyles = inlineComponentStyles?.get(filename);
356
+ if (componentStyles) {
357
+ debugStyles("load: served inline component stylesheet", {
358
+ filename,
359
+ length: componentStyles.length
360
+ });
361
+ return componentStyles;
362
+ }
305
363
  }
306
364
  },
307
365
  transform: {
@@ -319,7 +377,10 @@ function angular(options) {
319
377
  */
320
378
  if (options?.transformFilter && !(options?.transformFilter(code, id) ?? true)) return;
321
379
  if (pluginOptions.useAngularCompilationAPI) {
322
- if (!/(Component|Directive|Pipe|Injectable|NgModule)\(/.test(code)) return;
380
+ if (!/(Component|Directive|Pipe|Injectable|NgModule)\(/.test(code)) {
381
+ debugCompilationApi("transform skip (non-Angular file)", { id });
382
+ return;
383
+ }
323
384
  }
324
385
  /**
325
386
  * Skip transforming content files
@@ -330,10 +391,16 @@ function angular(options) {
330
391
  */
331
392
  if (pluginOptions.liveReload && isComponentStyleSheet(id)) {
332
393
  const { encapsulation, componentId } = getComponentStyleSheetMeta(id);
333
- if (encapsulation === "emulated" && componentId) return {
334
- code: ngCompiler.encapsulateStyle(code, componentId),
335
- map: null
336
- };
394
+ if (encapsulation === "emulated" && componentId) {
395
+ debugStyles("applying emulated view encapsulation", {
396
+ stylesheet: id.split("?")[0],
397
+ componentId
398
+ });
399
+ return {
400
+ code: ngCompiler.encapsulateStyle(code, componentId),
401
+ map: null
402
+ };
403
+ }
337
404
  }
338
405
  if (id.includes(".ts?")) id = id.replace(/\?(.*)/, "");
339
406
  fileTransformMap.set(id, code);
@@ -353,6 +420,11 @@ function angular(options) {
353
420
  }
354
421
  }
355
422
  const hasComponent = code.includes("@Component");
423
+ debugCompiler("transform", {
424
+ id,
425
+ codeLength: code.length,
426
+ hasComponent
427
+ });
356
428
  const templateUrls = hasComponent ? templateUrlsResolver.resolve(code, id) : [];
357
429
  const styleUrls = hasComponent ? styleUrlsResolver.resolve(code, id) : [];
358
430
  if (hasComponent && watchMode) for (const urlSet of [...templateUrls, ...styleUrls]) {
@@ -458,7 +530,10 @@ function angular(options) {
458
530
  angularCompilation ??= await createAngularCompilation(!!pluginOptions.jit, false);
459
531
  const modifiedFiles = ids?.length ? new Set(ids.map((file) => normalizePath(file))) : void 0;
460
532
  if (modifiedFiles?.size) sourceFileCache$1.invalidate(modifiedFiles);
461
- if (modifiedFiles?.size && angularCompilation.update) await angularCompilation.update(modifiedFiles);
533
+ if (modifiedFiles?.size && angularCompilation.update) {
534
+ debugCompilationApi("incremental update", { files: [...modifiedFiles] });
535
+ await angularCompilation.update(modifiedFiles);
536
+ }
462
537
  const resolvedTsConfigPath = resolveTsConfigPath();
463
538
  const compilationResult = await angularCompilation.initialize(resolvedTsConfigPath, {
464
539
  fileReplacements: toAngularCompilationFileReplacements(pluginOptions.fileReplacements, pluginOptions.workspaceRoot),
@@ -469,8 +544,17 @@ function angular(options) {
469
544
  if (pluginOptions.liveReload && watchMode) {
470
545
  const stylesheetId = createHash("sha256").update(containingFile).update(className).update(String(order)).update(preprocessedData).digest("hex") + "." + pluginOptions.inlineStylesExtension;
471
546
  inlineComponentStyles.set(stylesheetId, preprocessedData);
547
+ debugStyles("stylesheet deferred to Vite pipeline (liveReload)", {
548
+ stylesheetId,
549
+ resourceFile: resourceFile ?? "(inline)"
550
+ });
472
551
  return stylesheetId;
473
552
  }
553
+ debugStyles("stylesheet processed inline via preprocessCSS (no liveReload)", {
554
+ filename,
555
+ resourceFile: resourceFile ?? "(inline)",
556
+ dataLength: preprocessedData.length
557
+ });
474
558
  let stylesheetResult;
475
559
  try {
476
560
  stylesheetResult = await preprocessCSS(preprocessedData, `${filename}?direct`, resolvedConfig);
@@ -488,6 +572,12 @@ function angular(options) {
488
572
  tsCompilerOptions["externalRuntimeStyles"] = true;
489
573
  tsCompilerOptions["supportTestBed"] = true;
490
574
  }
575
+ debugCompiler("tsCompilerOptions (compilation API)", {
576
+ liveReload: pluginOptions.liveReload,
577
+ watchMode,
578
+ externalRuntimeStyles: !!tsCompilerOptions["externalRuntimeStyles"],
579
+ hmr: !!tsCompilerOptions["_enableHmr"]
580
+ });
491
581
  if (tsCompilerOptions.compilationMode === "partial") {
492
582
  tsCompilerOptions["supportTestBed"] = true;
493
583
  tsCompilerOptions["supportJitMode"] = true;
@@ -502,11 +592,19 @@ function angular(options) {
502
592
  });
503
593
  compilationResult.externalStylesheets?.forEach((value, key) => {
504
594
  externalComponentStyles?.set(`${value}.css`, key);
595
+ debugStyles("external stylesheet registered for resolveId mapping", {
596
+ filename: `${value}.css`,
597
+ resolvedPath: key
598
+ });
505
599
  });
506
600
  const diagnostics = await angularCompilation.diagnoseFiles(pluginOptions.disableTypeChecking ? DiagnosticModes.All & ~DiagnosticModes.Semantic : DiagnosticModes.All);
507
601
  const errors = diagnostics.errors?.length ? diagnostics.errors : [];
508
602
  const warnings = diagnostics.warnings?.length ? diagnostics.warnings : [];
509
603
  const templateUpdates = mapTemplateUpdatesToFiles(compilationResult.templateUpdates);
604
+ if (templateUpdates.size > 0) debugHmr("compilation API template updates", {
605
+ count: templateUpdates.size,
606
+ files: [...templateUpdates.keys()]
607
+ });
510
608
  for (const file of await angularCompilation.emitAffectedFiles()) {
511
609
  const normalizedFilename = normalizePath(file.filename);
512
610
  const templateUpdate = templateUpdates.get(normalizedFilename);
@@ -540,6 +638,7 @@ function angular(options) {
540
638
  */
541
639
  async function _doPerformCompilation(config, ids) {
542
640
  if (pluginOptions.useAngularCompilationAPI) {
641
+ debugCompilationApi("using compilation API path", { modifiedFiles: ids?.length ?? 0 });
543
642
  await performAngularCompilation(config, ids);
544
643
  return;
545
644
  }
@@ -587,6 +686,10 @@ function angular(options) {
587
686
  tsCompilerOptions["externalRuntimeStyles"] = true;
588
687
  tsCompilerOptions["supportTestBed"] = true;
589
688
  }
689
+ debugCompiler("tsCompilerOptions (NgtscProgram path)", {
690
+ externalRuntimeStyles: !!tsCompilerOptions["externalRuntimeStyles"],
691
+ hmr: !!tsCompilerOptions["_enableHmr"]
692
+ });
590
693
  if (tsCompilerOptions["compilationMode"] === "partial") {
591
694
  tsCompilerOptions["supportTestBed"] = true;
592
695
  tsCompilerOptions["supportJitMode"] = true;
@@ -621,8 +724,10 @@ function angular(options) {
621
724
  if (watchMode) augmentHostWithCaching(host, sourceFileCache$1);
622
725
  }
623
726
  if (!jit) {
624
- inlineComponentStyles = tsCompilerOptions["externalRuntimeStyles"] ? /* @__PURE__ */ new Map() : void 0;
625
- externalComponentStyles = tsCompilerOptions["externalRuntimeStyles"] ? /* @__PURE__ */ new Map() : void 0;
727
+ const externalizeStyles = !!tsCompilerOptions["externalRuntimeStyles"];
728
+ inlineComponentStyles = externalizeStyles ? /* @__PURE__ */ new Map() : void 0;
729
+ externalComponentStyles = externalizeStyles ? /* @__PURE__ */ new Map() : void 0;
730
+ debugStyles("style maps initialized (NgtscProgram path)", { externalizeStyles });
626
731
  augmentHostWithResources(host, styleTransform, {
627
732
  inlineStylesExtension: pluginOptions.inlineStylesExtension,
628
733
  isProd,
@@ -769,8 +874,13 @@ function getFileMetadata(program, angularCompiler, liveReload, disableTypeChecki
769
874
  for (const node of sourceFile.statements) if (ts.isClassDeclaration(node) && node.name != null) {
770
875
  hmrUpdateCode = angularCompiler?.emitHmrUpdateModule(node);
771
876
  if (hmrUpdateCode) {
772
- classNames.set(file, node.name.getText());
877
+ const className = node.name.getText();
878
+ classNames.set(file, className);
773
879
  hmrEligible = true;
880
+ debugHmr("NgtscProgram emitHmrUpdateModule", {
881
+ file,
882
+ className
883
+ });
774
884
  }
775
885
  }
776
886
  }
@@ -1 +1 @@
1
- {"version":3,"file":"angular-vite-plugin.js","names":[],"sources":["../../../src/lib/angular-vite-plugin.ts"],"sourcesContent":["import { NgtscProgram } from '@angular/compiler-cli';\nimport { existsSync, mkdirSync, writeFileSync } from 'node:fs';\nimport {\n basename,\n dirname,\n isAbsolute,\n join,\n relative,\n resolve,\n} from 'node:path';\nimport * as vite from 'vite';\n\nimport * as compilerCli from '@angular/compiler-cli';\nimport { createRequire } from 'node:module';\nimport * as ts from 'typescript';\nimport { type createAngularCompilation as createAngularCompilationType } from '@angular/build/private';\n\nimport * as ngCompiler from '@angular/compiler';\nimport { globSync } from 'tinyglobby';\nimport {\n defaultClientConditions,\n ModuleNode,\n normalizePath,\n Plugin,\n preprocessCSS,\n ResolvedConfig,\n ViteDevServer,\n} from 'vite';\nimport { buildOptimizerPlugin } from './angular-build-optimizer-plugin.js';\nimport { jitPlugin } from './angular-jit-plugin.js';\nimport {\n createCompilerPlugin,\n createRolldownCompilerPlugin,\n} from './compiler-plugin.js';\nimport {\n StyleUrlsResolver,\n TemplateUrlsResolver,\n} from './component-resolvers.js';\nimport {\n augmentHostWithCaching,\n augmentHostWithResources,\n augmentProgramWithVersioning,\n mergeTransformers,\n} from './host.js';\nimport type { StylePreprocessor } from './style-preprocessor.js';\n\nimport { angularVitestPlugins } from './angular-vitest-plugin.js';\nimport {\n createAngularCompilation,\n createJitResourceTransformer,\n SourceFileCache,\n angularFullVersion,\n} from './utils/devkit.js';\nimport { getJsTransformConfigKey, isRolldown } from './utils/rolldown.js';\nimport { type SourceFileCache as SourceFileCacheType } from './utils/source-file-cache.js';\n\nconst require = createRequire(import.meta.url);\n\nimport { pendingTasksPlugin } from './angular-pending-tasks.plugin.js';\nimport { liveReloadPlugin } from './live-reload-plugin.js';\nimport { EmitFileResult } from './models.js';\nimport { nxFolderPlugin } from './nx-folder-plugin.js';\nimport {\n FileReplacement,\n FileReplacementSSR,\n FileReplacementWith,\n replaceFiles,\n} from './plugins/file-replacements.plugin.js';\nimport { routerPlugin } from './router-plugin.js';\nimport { createHash } from 'node:crypto';\n\nexport enum DiagnosticModes {\n None = 0,\n Option = 1 << 0,\n Syntactic = 1 << 1,\n Semantic = 1 << 2,\n All = Option | Syntactic | Semantic,\n}\n\nexport interface PluginOptions {\n tsconfig?: string | (() => string);\n workspaceRoot?: string;\n inlineStylesExtension?: string;\n jit?: boolean;\n advanced?: {\n /**\n * Custom TypeScript transformers that are run before Angular compilation\n */\n tsTransformers?: ts.CustomTransformers;\n };\n supportedBrowsers?: string[];\n transformFilter?: (code: string, id: string) => boolean;\n /**\n * Additional files to include in compilation\n */\n include?: string[];\n additionalContentDirs?: string[];\n liveReload?: boolean;\n disableTypeChecking?: boolean;\n fileReplacements?: FileReplacement[];\n experimental?: {\n useAngularCompilationAPI?: boolean;\n };\n /**\n * Optional preprocessor that transforms component CSS before it enters Vite's\n * preprocessCSS pipeline. Runs on every component stylesheet (both external\n * `.component.css` files and inline `styles: [...]` blocks).\n *\n * @param code - Raw CSS content of the component stylesheet\n * @param filename - Resolved file path of the stylesheet (or containing .ts file for inline styles)\n * @returns Transformed CSS string, or the original code if no transformation is needed\n */\n stylePreprocessor?: StylePreprocessor;\n /**\n * First-class Tailwind CSS v4 integration for Angular component styles.\n *\n * Angular's compiler processes component CSS through Vite's `preprocessCSS()`,\n * which runs `@tailwindcss/vite` — but each component stylesheet is processed\n * in isolation without access to the root Tailwind configuration (prefix, @theme,\n * @custom-variant, @plugin definitions). This causes errors like:\n *\n * \"Cannot apply utility class `sa:grid` because the `sa` variant does not exist\"\n *\n * The `tailwindCss` option solves this by auto-injecting a `@reference` directive\n * into every component CSS file that uses Tailwind utilities, pointing it to the\n * root Tailwind stylesheet so `@tailwindcss/vite` can resolve the full configuration.\n *\n * @example Basic usage — reference a root Tailwind CSS file:\n * ```ts\n * import { resolve } from 'node:path';\n *\n * angular({\n * tailwindCss: {\n * rootStylesheet: resolve(__dirname, 'src/styles/tailwind.css'),\n * },\n * })\n * ```\n *\n * @example With prefix detection — only inject for files using specific prefixes:\n * ```ts\n * angular({\n * tailwindCss: {\n * rootStylesheet: resolve(__dirname, 'src/styles/tailwind.css'),\n * // Only inject @reference into files that use these prefixed classes\n * prefixes: ['sa:', 'tw:'],\n * },\n * })\n * ```\n *\n * @example AnalogJS platform — passed through the `vite` option:\n * ```ts\n * analog({\n * vite: {\n * tailwindCss: {\n * rootStylesheet: resolve(__dirname, '../../../libs/meritos/tailwind.config.css'),\n * },\n * },\n * })\n * ```\n */\n tailwindCss?: {\n /**\n * Absolute path to the root Tailwind CSS file that contains `@import \"tailwindcss\"`,\n * `@theme`, `@custom-variant`, and `@plugin` definitions.\n *\n * A `@reference` directive pointing to this file will be auto-injected into\n * component CSS files that use Tailwind utilities.\n */\n rootStylesheet: string;\n /**\n * Optional list of class prefixes to detect (e.g. `['sa:', 'tw:']`).\n * When provided, `@reference` is only injected into component CSS files that\n * contain at least one of these prefixes. When omitted, `@reference` is injected\n * into all component CSS files that contain `@apply` or `@` directives.\n *\n * @default undefined — inject into all component CSS files with `@apply`\n */\n prefixes?: string[];\n };\n}\n\n/**\n * TypeScript file extension regex\n * Match .(c or m)ts, .ts extensions with an optional ? for query params\n * Ignore .tsx extensions\n */\nconst TS_EXT_REGEX = /\\.[cm]?(ts)[^x]?\\??/;\nconst classNames = new Map();\n\ninterface DeclarationFile {\n declarationFileDir: string;\n declarationPath: string;\n data: string;\n}\n\n/**\n * Builds a resolved stylePreprocessor function from plugin options.\n * If `tailwindCss` is provided, creates an auto-reference injector.\n * If `stylePreprocessor` is also provided, chains them (tailwind first, then user).\n */\nfunction buildStylePreprocessor(\n options?: PluginOptions,\n): ((code: string, filename: string) => string) | undefined {\n const userPreprocessor = options?.stylePreprocessor;\n const tw = options?.tailwindCss;\n\n if (!tw && !userPreprocessor) {\n return undefined;\n }\n\n // Build the Tailwind @reference injector\n let tailwindPreprocessor:\n | ((code: string, filename: string) => string)\n | undefined;\n\n if (tw) {\n const rootStylesheet = tw.rootStylesheet;\n const prefixes = tw.prefixes;\n\n tailwindPreprocessor = (code: string, filename: string): string => {\n // Skip if already has @reference or is a root Tailwind file\n if (\n code.includes('@reference') ||\n code.includes('@import \"tailwindcss\"') ||\n code.includes(\"@import 'tailwindcss'\")\n ) {\n return code;\n }\n\n // Check if the file uses Tailwind utilities\n const needsReference = prefixes\n ? prefixes.some((prefix) => code.includes(prefix))\n : code.includes('@apply');\n\n if (!needsReference) {\n return code;\n }\n\n const refPath = relative(dirname(filename), rootStylesheet);\n return `@reference \"${refPath}\";\\n${code}`;\n };\n }\n\n // Chain: tailwind preprocessor first, then user preprocessor\n if (tailwindPreprocessor && userPreprocessor) {\n return (code: string, filename: string) => {\n const intermediate = tailwindPreprocessor!(code, filename);\n return userPreprocessor(intermediate, filename);\n };\n }\n\n return tailwindPreprocessor ?? userPreprocessor;\n}\n\nexport function angular(options?: PluginOptions): Plugin[] {\n /**\n * Normalize plugin options so defaults\n * are used for values not provided.\n */\n const pluginOptions = {\n tsconfigGetter: createTsConfigGetter(options?.tsconfig),\n workspaceRoot: options?.workspaceRoot ?? process.cwd(),\n inlineStylesExtension: options?.inlineStylesExtension ?? 'css',\n advanced: {\n tsTransformers: {\n before: options?.advanced?.tsTransformers?.before ?? [],\n after: options?.advanced?.tsTransformers?.after ?? [],\n afterDeclarations:\n options?.advanced?.tsTransformers?.afterDeclarations ?? [],\n },\n },\n supportedBrowsers: options?.supportedBrowsers ?? ['safari 15'],\n jit: options?.jit,\n include: options?.include ?? [],\n additionalContentDirs: options?.additionalContentDirs ?? [],\n liveReload: options?.liveReload ?? false,\n disableTypeChecking: options?.disableTypeChecking ?? true,\n fileReplacements: options?.fileReplacements ?? [],\n useAngularCompilationAPI:\n options?.experimental?.useAngularCompilationAPI ?? false,\n stylePreprocessor: buildStylePreprocessor(options),\n };\n\n let resolvedConfig: ResolvedConfig;\n // Store config context needed for getTsConfigPath resolution\n let tsConfigResolutionContext: {\n root: string;\n isProd: boolean;\n isLib: boolean;\n } | null = null;\n\n const ts = require('typescript');\n let builder: ts.BuilderProgram | ts.EmitAndSemanticDiagnosticsBuilderProgram;\n let nextProgram: NgtscProgram | undefined;\n // Caches (always rebuild Angular program per user request)\n const tsconfigOptionsCache = new Map<\n string,\n { options: ts.CompilerOptions; rootNames: string[] }\n >();\n let cachedHost: ts.CompilerHost | undefined;\n let cachedHostKey: string | undefined;\n let includeCache: string[] = [];\n function invalidateFsCaches() {\n includeCache = [];\n }\n function invalidateTsconfigCaches() {\n // `readConfiguration` caches the root file list, so hot-added pages can be\n // missing from Angular's compilation program until we clear this state.\n tsconfigOptionsCache.clear();\n cachedHost = undefined;\n cachedHostKey = undefined;\n }\n let watchMode = false;\n let testWatchMode = isTestWatchMode();\n let inlineComponentStyles: Map<string, string> | undefined;\n let externalComponentStyles: Map<string, string> | undefined;\n const sourceFileCache: SourceFileCacheType = new SourceFileCache();\n const isTest = process.env['NODE_ENV'] === 'test' || !!process.env['VITEST'];\n const isVitestVscode = !!process.env['VITEST_VSCODE'];\n const isStackBlitz = !!process.versions['webcontainer'];\n const isAstroIntegration = process.env['ANALOG_ASTRO'] === 'true';\n\n const jit =\n typeof pluginOptions?.jit !== 'undefined' ? pluginOptions.jit : isTest;\n let viteServer: ViteDevServer | undefined;\n\n const styleUrlsResolver = new StyleUrlsResolver();\n const templateUrlsResolver = new TemplateUrlsResolver();\n let outputFile: ((file: string) => void) | undefined;\n const outputFiles = new Map<string, EmitFileResult>();\n const fileEmitter = (file: string) => {\n outputFile?.(file);\n return outputFiles.get(normalizePath(file));\n };\n let initialCompilation = false;\n const declarationFiles: DeclarationFile[] = [];\n const fileTransformMap = new Map<string, string>();\n let styleTransform: (\n code: string,\n filename: string,\n ) => Promise<vite.PreprocessCSSResult>;\n let pendingCompilation: Promise<void> | null;\n let compilationLock = Promise.resolve();\n // Persistent Angular Compilation API instance. Kept alive across rebuilds so\n // Angular can diff previous state and emit `templateUpdates` for HMR.\n // Previously the compilation was recreated on every pass, which meant Angular\n // never had prior state and could never produce HMR payloads.\n let angularCompilation:\n | Awaited<ReturnType<typeof createAngularCompilationType>>\n | undefined;\n\n function angularPlugin(): Plugin {\n let isProd = false;\n\n if (angularFullVersion < 190000 || isTest) {\n pluginOptions.liveReload = false;\n }\n\n // liveReload and fileReplacements guards were previously here and forced\n // both options off when useAngularCompilationAPI was enabled. Those guards\n // have been removed because:\n // - liveReload: the persistent compilation instance (above) now gives\n // Angular the prior state it needs to emit `templateUpdates` for HMR\n // - fileReplacements: Angular's AngularHostOptions already accepts a\n // `fileReplacements` record — we now convert and pass it through in\n // `performAngularCompilation` via `toAngularCompilationFileReplacements`\n if (pluginOptions.useAngularCompilationAPI) {\n if (angularFullVersion < 200100) {\n pluginOptions.useAngularCompilationAPI = false;\n console.warn(\n '[@analogjs/vite-plugin-angular]: The Angular Compilation API is only available with Angular v20.1 and later',\n );\n }\n }\n\n return {\n name: '@analogjs/vite-plugin-angular',\n async config(config, { command }) {\n watchMode = command === 'serve';\n isProd =\n config.mode === 'production' ||\n process.env['NODE_ENV'] === 'production';\n\n // Store the config context for later resolution in configResolved\n tsConfigResolutionContext = {\n root: config.root || '.',\n isProd,\n isLib: !!config?.build?.lib,\n };\n\n // Do a preliminary resolution for esbuild plugin (before configResolved)\n const preliminaryTsConfigPath = resolveTsConfigPath();\n\n const esbuild = pluginOptions.useAngularCompilationAPI\n ? undefined\n : (config.esbuild ?? false);\n const oxc = pluginOptions.useAngularCompilationAPI\n ? undefined\n : (config.oxc ?? false);\n\n const defineOptions = {\n ngJitMode: 'false',\n ngI18nClosureMode: 'false',\n ...(watchMode ? {} : { ngDevMode: 'false' }),\n };\n const useRolldown = isRolldown();\n const jsTransformConfigKey = getJsTransformConfigKey();\n const jsTransformConfigValue =\n jsTransformConfigKey === 'oxc' ? oxc : esbuild;\n\n const rolldownOptions: vite.DepOptimizationOptions['rolldownOptions'] =\n {\n plugins: [\n createRolldownCompilerPlugin(\n {\n tsconfig: preliminaryTsConfigPath,\n sourcemap: !isProd,\n advancedOptimizations: isProd,\n jit,\n incremental: watchMode,\n },\n // Astro manages the transformer lifecycle externally.\n !isAstroIntegration,\n ),\n ],\n };\n\n const esbuildOptions: vite.DepOptimizationOptions['esbuildOptions'] = {\n plugins: [\n createCompilerPlugin(\n {\n tsconfig: preliminaryTsConfigPath,\n sourcemap: !isProd,\n advancedOptimizations: isProd,\n jit,\n incremental: watchMode,\n },\n isTest,\n !isAstroIntegration,\n ),\n ],\n define: defineOptions,\n };\n\n return {\n [jsTransformConfigKey]: jsTransformConfigValue,\n optimizeDeps: {\n include: ['rxjs/operators', 'rxjs'],\n exclude: ['@angular/platform-server'],\n ...(useRolldown ? { rolldownOptions } : { esbuildOptions }),\n },\n resolve: {\n conditions: [\n 'style',\n ...(config.resolve?.conditions || defaultClientConditions),\n ],\n },\n };\n },\n configResolved(config) {\n resolvedConfig = config;\n\n if (pluginOptions.useAngularCompilationAPI) {\n externalComponentStyles = new Map();\n inlineComponentStyles = new Map();\n }\n\n if (!jit) {\n styleTransform = (code: string, filename: string) =>\n preprocessCSS(code, filename, config);\n }\n\n if (isTest) {\n // set test watch mode\n // - vite override from vitest-angular\n // - @nx/vite executor set server.watch explicitly to undefined (watch)/null (watch=false)\n // - vite config for test.watch variable\n // - vitest watch mode detected from the command line\n testWatchMode =\n !(config.server.watch === null) ||\n (config as any).test?.watch === true ||\n testWatchMode;\n }\n },\n configureServer(server) {\n viteServer = server;\n // Add/unlink changes the TypeScript program shape, not just file\n // contents, so we need to invalidate both include discovery and the\n // cached tsconfig root names before recompiling.\n const invalidateCompilationOnFsChange = createFsWatcherCacheInvalidator(\n invalidateFsCaches,\n invalidateTsconfigCaches,\n () => performCompilation(resolvedConfig),\n );\n server.watcher.on('add', invalidateCompilationOnFsChange);\n server.watcher.on('unlink', invalidateCompilationOnFsChange);\n server.watcher.on('change', (file) => {\n if (file.includes('tsconfig')) {\n invalidateTsconfigCaches();\n }\n });\n },\n async buildStart() {\n // Defer the first compilation in test mode\n if (!isVitestVscode) {\n await performCompilation(resolvedConfig);\n pendingCompilation = null;\n\n initialCompilation = true;\n }\n },\n async handleHotUpdate(ctx) {\n if (TS_EXT_REGEX.test(ctx.file)) {\n const [fileId] = ctx.file.split('?');\n\n pendingCompilation = performCompilation(resolvedConfig, [fileId]);\n\n let result;\n\n if (pluginOptions.liveReload) {\n await pendingCompilation;\n pendingCompilation = null;\n result = fileEmitter(fileId);\n }\n\n if (\n pluginOptions.liveReload &&\n result?.hmrEligible &&\n classNames.get(fileId)\n ) {\n const relativeFileId = `${normalizePath(\n relative(process.cwd(), fileId),\n )}@${classNames.get(fileId)}`;\n\n sendHMRComponentUpdate(ctx.server, relativeFileId);\n\n return ctx.modules.map((mod) => {\n if (mod.id === ctx.file) {\n return markModuleSelfAccepting(mod);\n }\n\n return mod;\n });\n }\n }\n\n if (/\\.(html|htm|css|less|sass|scss)$/.test(ctx.file)) {\n fileTransformMap.delete(ctx.file.split('?')[0]);\n /**\n * Check to see if this was a direct request\n * for an external resource (styles, html).\n */\n const isDirect = ctx.modules.find(\n (mod) => ctx.file === mod.file && mod.id?.includes('?direct'),\n );\n const isInline = ctx.modules.find(\n (mod) => ctx.file === mod.file && mod.id?.includes('?inline'),\n );\n\n if (isDirect || isInline) {\n if (pluginOptions.liveReload && isDirect?.id && isDirect.file) {\n const isComponentStyle =\n isDirect.type === 'css' && isComponentStyleSheet(isDirect.id);\n if (isComponentStyle) {\n const { encapsulation } = getComponentStyleSheetMeta(\n isDirect.id,\n );\n\n // Track if the component uses ShadowDOM encapsulation\n // Shadow DOM components currently require a full reload.\n // Vite's CSS hot replacement does not support shadow root searching.\n if (encapsulation !== 'shadow') {\n ctx.server.ws.send({\n type: 'update',\n updates: [\n {\n type: 'css-update',\n timestamp: Date.now(),\n path: isDirect.url,\n acceptedPath: isDirect.file,\n },\n ],\n });\n\n return ctx.modules\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 \"hmr update *.component.scss, *.component.scss?direct&ngcomp=xyz&e=x\"\n return mod.file !== ctx.file || mod.id !== isDirect.id;\n })\n .map((mod) => {\n if (mod.file === ctx.file) {\n return markModuleSelfAccepting(mod);\n }\n return mod;\n }) as ModuleNode[];\n }\n }\n }\n return ctx.modules;\n }\n\n const mods: ModuleNode[] = [];\n const updates: string[] = [];\n ctx.modules.forEach((mod) => {\n mod.importers.forEach((imp) => {\n ctx.server.moduleGraph.invalidateModule(imp);\n\n if (pluginOptions.liveReload && classNames.get(imp.id)) {\n updates.push(imp.id as string);\n } else {\n mods.push(imp);\n }\n });\n });\n\n pendingCompilation = performCompilation(resolvedConfig, [\n ...mods.map((mod) => mod.id as string),\n ...updates,\n ]);\n\n if (updates.length > 0) {\n await pendingCompilation;\n pendingCompilation = null;\n\n updates.forEach((updateId) => {\n const impRelativeFileId = `${normalizePath(\n relative(process.cwd(), updateId),\n )}@${classNames.get(updateId)}`;\n\n sendHMRComponentUpdate(ctx.server, impRelativeFileId);\n });\n\n return ctx.modules.map((mod) => {\n if (mod.id === ctx.file) {\n return markModuleSelfAccepting(mod);\n }\n\n return mod;\n });\n }\n\n return mods;\n }\n\n // clear HMR updates with a full reload\n classNames.clear();\n return ctx.modules;\n },\n resolveId(id, importer) {\n if (jit && id.startsWith('angular:jit:')) {\n const path = id.split(';')[1];\n return `${normalizePath(\n resolve(dirname(importer as string), path),\n )}?${id.includes(':style') ? 'inline' : 'raw'}`;\n }\n\n // Map angular external styleUrls to the source file\n if (isComponentStyleSheet(id)) {\n const componentStyles = externalComponentStyles?.get(\n getFilenameFromPath(id),\n );\n if (componentStyles) {\n return componentStyles + new URL(id, 'http://localhost').search;\n }\n }\n\n return undefined;\n },\n async load(id) {\n // Map angular inline styles to the source text\n if (isComponentStyleSheet(id)) {\n const componentStyles = inlineComponentStyles?.get(\n getFilenameFromPath(id),\n );\n if (componentStyles) {\n return componentStyles;\n }\n }\n\n return;\n },\n transform: {\n filter: {\n id: {\n include: [TS_EXT_REGEX],\n exclude: [/node_modules/, 'type=script', '@ng/component'],\n },\n },\n async handler(code, id) {\n /**\n * Check for options.transformFilter\n */\n if (\n options?.transformFilter &&\n !(options?.transformFilter(code, id) ?? true)\n ) {\n return;\n }\n\n if (pluginOptions.useAngularCompilationAPI) {\n const isAngular =\n /(Component|Directive|Pipe|Injectable|NgModule)\\(/.test(code);\n\n if (!isAngular) {\n return;\n }\n }\n\n /**\n * Skip transforming content files\n */\n if (id.includes('?') && id.includes('analog-content-')) {\n return;\n }\n\n /**\n * Encapsulate component stylesheets that use emulated encapsulation\n */\n if (pluginOptions.liveReload && isComponentStyleSheet(id)) {\n const { encapsulation, componentId } =\n getComponentStyleSheetMeta(id);\n if (encapsulation === 'emulated' && componentId) {\n const encapsulated = ngCompiler.encapsulateStyle(\n code,\n componentId,\n );\n return {\n code: encapsulated,\n map: null,\n };\n }\n }\n\n if (id.includes('.ts?')) {\n // Strip the query string off the ID\n // in case of a dynamically loaded file\n id = id.replace(/\\?(.*)/, '');\n }\n\n fileTransformMap.set(id, code);\n\n /**\n * Re-analyze on each transform\n * for test(Vitest)\n */\n if (isTest) {\n if (isVitestVscode && !initialCompilation) {\n // Do full initial compilation\n pendingCompilation = performCompilation(resolvedConfig);\n initialCompilation = true;\n }\n\n const tsMod = viteServer?.moduleGraph.getModuleById(id);\n if (tsMod) {\n const invalidated = tsMod.lastInvalidationTimestamp;\n\n if (testWatchMode && invalidated) {\n pendingCompilation = performCompilation(resolvedConfig, [id]);\n }\n }\n }\n\n const hasComponent = code.includes('@Component');\n const templateUrls = hasComponent\n ? templateUrlsResolver.resolve(code, id)\n : [];\n const styleUrls = hasComponent\n ? styleUrlsResolver.resolve(code, id)\n : [];\n\n if (hasComponent && watchMode) {\n for (const urlSet of [...templateUrls, ...styleUrls]) {\n // `urlSet` is a string where a relative path is joined with an\n // absolute path using the `|` symbol.\n // For example: `./app.component.html|/home/projects/analog/src/app/app.component.html`.\n const [, absoluteFileUrl] = urlSet.split('|');\n this.addWatchFile(absoluteFileUrl);\n }\n }\n\n if (pendingCompilation) {\n await pendingCompilation;\n pendingCompilation = null;\n }\n\n const typescriptResult = fileEmitter(id);\n\n if (\n typescriptResult?.warnings &&\n typescriptResult?.warnings.length > 0\n ) {\n this.warn(`${typescriptResult.warnings.join('\\n')}`);\n }\n\n if (typescriptResult?.errors && typescriptResult?.errors.length > 0) {\n this.error(`${typescriptResult.errors.join('\\n')}`);\n }\n\n // return fileEmitter\n let data = typescriptResult?.content ?? '';\n\n if (jit && data.includes('angular:jit:')) {\n data = data.replace(\n /angular:jit:style:inline;/g,\n 'virtual:angular:jit:style:inline;',\n );\n\n templateUrls.forEach((templateUrlSet) => {\n const [templateFile, resolvedTemplateUrl] =\n templateUrlSet.split('|');\n data = data.replace(\n `angular:jit:template:file;${templateFile}`,\n `${resolvedTemplateUrl}?raw`,\n );\n });\n\n styleUrls.forEach((styleUrlSet) => {\n const [styleFile, resolvedStyleUrl] = styleUrlSet.split('|');\n data = data.replace(\n `angular:jit:style:file;${styleFile}`,\n `${resolvedStyleUrl}?inline`,\n );\n });\n }\n\n return {\n code: data,\n map: null,\n };\n },\n },\n closeBundle() {\n declarationFiles.forEach(\n ({ declarationFileDir, declarationPath, data }) => {\n mkdirSync(declarationFileDir, { recursive: true });\n writeFileSync(declarationPath, data, 'utf-8');\n },\n );\n // Tear down the persistent compilation instance at end of build so it\n // does not leak memory across unrelated Vite invocations.\n angularCompilation?.close?.();\n angularCompilation = undefined;\n },\n };\n }\n\n return [\n replaceFiles(pluginOptions.fileReplacements, pluginOptions.workspaceRoot),\n angularPlugin(),\n pluginOptions.liveReload && liveReloadPlugin({ classNames, fileEmitter }),\n ...(isTest && !isStackBlitz ? angularVitestPlugins() : []),\n (jit &&\n jitPlugin({\n inlineStylesExtension: pluginOptions.inlineStylesExtension,\n })) as Plugin,\n buildOptimizerPlugin({\n supportedBrowsers: pluginOptions.supportedBrowsers,\n jit,\n }),\n routerPlugin(),\n angularFullVersion < 190004 && pendingTasksPlugin(),\n nxFolderPlugin(),\n ].filter(Boolean) as Plugin[];\n\n function findIncludes() {\n const workspaceRoot = normalizePath(resolve(pluginOptions.workspaceRoot));\n\n // Map include patterns to absolute workspace paths\n const globs = [\n ...pluginOptions.include.map((glob) => `${workspaceRoot}${glob}`),\n ];\n\n // Discover TypeScript files using tinyglobby\n return globSync(globs, {\n dot: true,\n absolute: true,\n });\n }\n\n function createTsConfigGetter(tsconfigOrGetter?: string | (() => string)) {\n if (typeof tsconfigOrGetter === 'function') {\n return tsconfigOrGetter;\n }\n\n return () => tsconfigOrGetter || '';\n }\n\n function getTsConfigPath(\n root: string,\n tsconfig: string,\n isProd: boolean,\n isTest: boolean,\n isLib: boolean,\n ) {\n if (tsconfig && isAbsolute(tsconfig)) {\n if (!existsSync(tsconfig)) {\n console.error(\n `[@analogjs/vite-plugin-angular]: Unable to resolve tsconfig at ${tsconfig}. This causes compilation issues. Check the path or set the \"tsconfig\" property with an absolute path.`,\n );\n }\n\n return tsconfig;\n }\n\n let tsconfigFilePath = './tsconfig.app.json';\n\n if (isLib) {\n tsconfigFilePath = isProd\n ? './tsconfig.lib.prod.json'\n : './tsconfig.lib.json';\n }\n\n if (isTest) {\n tsconfigFilePath = './tsconfig.spec.json';\n }\n\n if (tsconfig) {\n tsconfigFilePath = tsconfig;\n }\n\n const resolvedPath = resolve(root, tsconfigFilePath);\n\n if (!existsSync(resolvedPath)) {\n console.error(\n `[@analogjs/vite-plugin-angular]: Unable to resolve tsconfig at ${resolvedPath}. This causes compilation issues. Check the path or set the \"tsconfig\" property with an absolute path.`,\n );\n }\n\n return resolvedPath;\n }\n\n function resolveTsConfigPath() {\n const tsconfigValue = pluginOptions.tsconfigGetter();\n\n return getTsConfigPath(\n tsConfigResolutionContext!.root,\n tsconfigValue,\n tsConfigResolutionContext!.isProd,\n isTest,\n tsConfigResolutionContext!.isLib,\n );\n }\n\n /**\n * Perform compilation using Angular's private Compilation API.\n *\n * Key differences from the standard `performCompilation` path:\n * 1. The compilation instance is reused across rebuilds (nullish-coalescing\n * assignment below) so Angular retains prior state and can diff it to\n * produce `templateUpdates` for HMR.\n * 2. `ids` (modified files) are forwarded to both the source-file cache and\n * `angularCompilation.update()` so that incremental re-analysis is\n * scoped to what actually changed.\n * 3. `fileReplacements` are converted and passed into Angular's host via\n * `toAngularCompilationFileReplacements`.\n * 4. `templateUpdates` from the compilation result are mapped back to\n * file-level HMR metadata (`hmrUpdateCode`, `hmrEligible`, `classNames`).\n */\n async function performAngularCompilation(\n config: ResolvedConfig,\n ids?: string[],\n ) {\n // Reuse the existing instance so Angular can diff against prior state.\n angularCompilation ??= await (\n createAngularCompilation as typeof createAngularCompilationType\n )(!!pluginOptions.jit, false);\n const modifiedFiles = ids?.length\n ? new Set(ids.map((file) => normalizePath(file)))\n : undefined;\n if (modifiedFiles?.size) {\n sourceFileCache.invalidate(modifiedFiles);\n }\n // Notify Angular of modified files before re-initialization so it can\n // scope its incremental analysis.\n if (modifiedFiles?.size && angularCompilation.update) {\n await angularCompilation.update(modifiedFiles);\n }\n\n const resolvedTsConfigPath = resolveTsConfigPath();\n const compilationResult = await angularCompilation.initialize(\n resolvedTsConfigPath,\n {\n // Convert Analog's browser-style `{ replace, with }` entries into the\n // `Record<string, string>` shape that Angular's AngularHostOptions\n // expects. SSR-only replacements (`{ replace, ssr }`) are intentionally\n // excluded — they stay on the Vite runtime side.\n fileReplacements: toAngularCompilationFileReplacements(\n pluginOptions.fileReplacements,\n pluginOptions.workspaceRoot,\n ),\n modifiedFiles,\n async transformStylesheet(\n data,\n containingFile,\n resourceFile,\n order,\n className,\n ) {\n const filename =\n resourceFile ??\n containingFile.replace(\n '.ts',\n `.${pluginOptions.inlineStylesExtension}`,\n );\n\n // Apply any user-defined stylesheet preprocessing before Vite transforms it.\n const preprocessedData = pluginOptions.stylePreprocessor\n ? (pluginOptions.stylePreprocessor(data, filename) ?? data)\n : data;\n\n if (pluginOptions.liveReload && watchMode) {\n // Store the preprocessed (but not yet CSS-transformed) data so that\n // Vite's serve-time pipeline handles PostCSS / Tailwind processing\n // exactly once when the load hook returns this CSS. Running\n // preprocessCSS() here would strip directives like @reference before\n // the CSS re-enters the transform pipeline, causing plugins such as\n // @tailwindcss/vite to fail on the second pass.\n // Guard must match the externalRuntimeStyles condition (line ~927)\n // because the Angular compiler only emits external style references\n // when externalRuntimeStyles is enabled.\n const id = createHash('sha256')\n .update(containingFile)\n .update(className as string)\n .update(String(order))\n .update(preprocessedData)\n .digest('hex');\n const stylesheetId = id + '.' + pluginOptions.inlineStylesExtension;\n inlineComponentStyles!.set(stylesheetId, preprocessedData);\n return stylesheetId;\n }\n\n // Non-liveReload: the CSS is returned directly to the Angular\n // compiler and never re-enters Vite's pipeline, so we must run\n // preprocessCSS() eagerly here.\n let stylesheetResult;\n\n try {\n stylesheetResult = await preprocessCSS(\n preprocessedData,\n `${filename}?direct`,\n resolvedConfig,\n );\n } catch (e) {\n console.error(`${e}`);\n }\n\n return stylesheetResult?.code || '';\n },\n processWebWorker(workerFile, containingFile) {\n return '';\n },\n },\n (tsCompilerOptions) => {\n if (pluginOptions.liveReload && watchMode) {\n tsCompilerOptions['_enableHmr'] = true;\n tsCompilerOptions['externalRuntimeStyles'] = true;\n // Workaround for https://github.com/angular/angular/issues/59310\n // Force extra instructions to be generated for HMR w/defer\n tsCompilerOptions['supportTestBed'] = true;\n }\n\n if (tsCompilerOptions.compilationMode === 'partial') {\n // These options can't be false in partial mode\n tsCompilerOptions['supportTestBed'] = true;\n tsCompilerOptions['supportJitMode'] = true;\n }\n\n if (!isTest && config.build?.lib) {\n tsCompilerOptions['declaration'] = true;\n tsCompilerOptions['declarationMap'] = watchMode;\n tsCompilerOptions['inlineSources'] = true;\n }\n\n if (isTest) {\n // Allow `TestBed.overrideXXX()` APIs.\n tsCompilerOptions['supportTestBed'] = true;\n }\n\n return tsCompilerOptions;\n },\n );\n\n compilationResult.externalStylesheets?.forEach((value, key) => {\n externalComponentStyles?.set(`${value}.css`, key);\n });\n\n const diagnostics = await angularCompilation.diagnoseFiles(\n pluginOptions.disableTypeChecking\n ? DiagnosticModes.All & ~DiagnosticModes.Semantic\n : DiagnosticModes.All,\n );\n\n const errors = diagnostics.errors?.length ? diagnostics.errors : [];\n const warnings = diagnostics.warnings?.length ? diagnostics.warnings : [];\n // Angular encodes template updates as `encodedFilePath@ClassName` keys.\n // `mapTemplateUpdatesToFiles` decodes them back to absolute file paths so\n // we can attach HMR metadata to the correct `EmitFileResult` below.\n const templateUpdates = mapTemplateUpdatesToFiles(\n compilationResult.templateUpdates,\n );\n\n for (const file of await angularCompilation.emitAffectedFiles()) {\n const normalizedFilename = normalizePath(file.filename);\n const templateUpdate = templateUpdates.get(normalizedFilename);\n\n if (templateUpdate) {\n classNames.set(normalizedFilename, templateUpdate.className);\n }\n\n // Surface Angular's HMR payloads into Analog's existing live-reload\n // flow via the `hmrUpdateCode` / `hmrEligible` fields.\n outputFiles.set(normalizedFilename, {\n content: file.contents,\n dependencies: [],\n errors: errors.map((error: { text?: string }) => error.text || ''),\n warnings: warnings.map(\n (warning: { text?: string }) => warning.text || '',\n ),\n hmrUpdateCode: templateUpdate?.code,\n hmrEligible: !!templateUpdate?.code,\n });\n }\n }\n\n async function performCompilation(config: ResolvedConfig, ids?: string[]) {\n let resolve: (() => unknown) | undefined;\n const previousLock = compilationLock;\n compilationLock = new Promise<void>((r) => {\n resolve = r;\n });\n try {\n await previousLock;\n await _doPerformCompilation(config, ids);\n } finally {\n resolve!();\n }\n }\n\n /**\n * This method share mutable state and performs the actual compilation work.\n * It should not be called concurrently. Use `performCompilation` which wraps this method in a lock to ensure only one compilation runs at a time.\n */\n async function _doPerformCompilation(config: ResolvedConfig, ids?: string[]) {\n // Forward `ids` (modified files) so the Compilation API path can do\n // incremental re-analysis instead of a full recompile on every change.\n if (pluginOptions.useAngularCompilationAPI) {\n await performAngularCompilation(config, ids);\n return;\n }\n\n const isProd = config.mode === 'production';\n const modifiedFiles = new Set<string>(ids ?? []);\n sourceFileCache.invalidate(modifiedFiles);\n\n if (ids?.length) {\n for (const id of ids || []) {\n fileTransformMap.delete(id);\n }\n }\n\n // Cached include discovery (invalidated only on FS events)\n if (pluginOptions.include.length > 0 && includeCache.length === 0) {\n includeCache = findIncludes();\n }\n\n const resolvedTsConfigPath = resolveTsConfigPath();\n const tsconfigKey = [\n resolvedTsConfigPath,\n isProd ? 'prod' : 'dev',\n isTest ? 'test' : 'app',\n config.build?.lib ? 'lib' : 'nolib',\n ].join('|');\n let cached = tsconfigOptionsCache.get(tsconfigKey);\n\n if (!cached) {\n const read = compilerCli.readConfiguration(resolvedTsConfigPath, {\n suppressOutputPathCheck: true,\n outDir: undefined,\n sourceMap: false,\n inlineSourceMap: !isProd,\n inlineSources: !isProd,\n declaration: false,\n declarationMap: false,\n allowEmptyCodegenFiles: false,\n annotationsAs: 'decorators',\n enableResourceInlining: false,\n noEmitOnError: false,\n mapRoot: undefined,\n sourceRoot: undefined,\n supportTestBed: false,\n supportJitMode: false,\n });\n cached = { options: read.options, rootNames: read.rootNames };\n tsconfigOptionsCache.set(tsconfigKey, cached);\n }\n\n // Clone options before mutation (preserve cache purity)\n const tsCompilerOptions = { ...cached.options };\n let rootNames = [...cached.rootNames];\n\n if (pluginOptions.liveReload && watchMode) {\n tsCompilerOptions['_enableHmr'] = true;\n tsCompilerOptions['externalRuntimeStyles'] = true;\n // Workaround for https://github.com/angular/angular/issues/59310\n // Force extra instructions to be generated for HMR w/defer\n tsCompilerOptions['supportTestBed'] = true;\n }\n\n if (tsCompilerOptions['compilationMode'] === 'partial') {\n // These options can't be false in partial mode\n tsCompilerOptions['supportTestBed'] = true;\n tsCompilerOptions['supportJitMode'] = true;\n }\n\n if (!isTest && config.build?.lib) {\n tsCompilerOptions['declaration'] = true;\n tsCompilerOptions['declarationMap'] = watchMode;\n tsCompilerOptions['inlineSources'] = true;\n }\n\n if (isTest) {\n // Allow `TestBed.overrideXXX()` APIs.\n tsCompilerOptions['supportTestBed'] = true;\n }\n\n const replacements = pluginOptions.fileReplacements.map((rp) =>\n join(\n pluginOptions.workspaceRoot,\n (rp as FileReplacementSSR).ssr || (rp as FileReplacementWith).with,\n ),\n );\n // Merge + dedupe root names\n rootNames = [...new Set([...rootNames, ...includeCache, ...replacements])];\n const hostKey = JSON.stringify(tsCompilerOptions);\n let host: ts.CompilerHost;\n\n if (cachedHost && cachedHostKey === hostKey) {\n host = cachedHost;\n } else {\n host = ts.createIncrementalCompilerHost(tsCompilerOptions, {\n ...ts.sys,\n readFile(path: string, encoding: string) {\n if (fileTransformMap.has(path)) {\n return fileTransformMap.get(path);\n }\n\n const file = ts.sys.readFile.call(null, path, encoding);\n\n if (file) {\n fileTransformMap.set(path, file);\n }\n\n return file;\n },\n });\n cachedHost = host;\n cachedHostKey = hostKey;\n\n // Only store cache if in watch mode\n if (watchMode) {\n augmentHostWithCaching(host, sourceFileCache);\n }\n }\n\n if (!jit) {\n inlineComponentStyles = tsCompilerOptions['externalRuntimeStyles']\n ? new Map()\n : undefined;\n externalComponentStyles = tsCompilerOptions['externalRuntimeStyles']\n ? new Map()\n : undefined;\n augmentHostWithResources(host, styleTransform, {\n inlineStylesExtension: pluginOptions.inlineStylesExtension,\n isProd,\n inlineComponentStyles,\n externalComponentStyles,\n sourceFileCache,\n stylePreprocessor: pluginOptions.stylePreprocessor,\n });\n }\n\n /**\n * Creates a new NgtscProgram to analyze/re-analyze\n * the source files and create a file emitter.\n * This is shared between an initial build and a hot update.\n */\n let typeScriptProgram: ts.Program;\n let angularCompiler: NgtscProgram['compiler'];\n const oldBuilder =\n builder ?? ts.readBuilderProgram(tsCompilerOptions, host);\n\n if (!jit) {\n // Create the Angular specific program that contains the Angular compiler\n const angularProgram: NgtscProgram = new compilerCli.NgtscProgram(\n rootNames,\n tsCompilerOptions,\n host,\n nextProgram,\n );\n angularCompiler = angularProgram.compiler;\n typeScriptProgram = angularProgram.compiler.getCurrentProgram();\n augmentProgramWithVersioning(typeScriptProgram);\n\n builder = ts.createEmitAndSemanticDiagnosticsBuilderProgram(\n typeScriptProgram,\n host,\n oldBuilder as ts.EmitAndSemanticDiagnosticsBuilderProgram,\n );\n\n nextProgram = angularProgram;\n } else {\n builder = ts.createEmitAndSemanticDiagnosticsBuilderProgram(\n rootNames,\n tsCompilerOptions,\n host,\n oldBuilder as ts.EmitAndSemanticDiagnosticsBuilderProgram,\n );\n\n typeScriptProgram = builder.getProgram();\n }\n\n if (!watchMode) {\n // When not in watch mode, the startup cost of the incremental analysis can be avoided by\n // using an abstract builder that only wraps a TypeScript program.\n builder = ts.createAbstractBuilder(typeScriptProgram, host, oldBuilder);\n }\n\n if (angularCompiler!) {\n await angularCompiler.analyzeAsync();\n }\n\n const beforeTransformers = jit\n ? [\n compilerCli.constructorParametersDownlevelTransform(\n builder.getProgram(),\n ),\n createJitResourceTransformer(() =>\n builder.getProgram().getTypeChecker(),\n ),\n ]\n : [];\n\n const transformers = mergeTransformers(\n { before: beforeTransformers },\n jit ? {} : angularCompiler!.prepareEmit().transformers,\n );\n\n const fileMetadata = getFileMetadata(\n builder,\n angularCompiler!,\n pluginOptions.liveReload,\n pluginOptions.disableTypeChecking,\n );\n\n const writeFileCallback: ts.WriteFileCallback = (\n _filename,\n content,\n _a,\n _b,\n sourceFiles,\n ) => {\n if (!sourceFiles?.length) {\n return;\n }\n\n const filename = normalizePath(sourceFiles[0].fileName);\n\n if (filename.includes('ngtypecheck.ts') || filename.includes('.d.')) {\n return;\n }\n\n const metadata = watchMode ? fileMetadata(filename) : {};\n\n outputFiles.set(filename, {\n content,\n dependencies: [],\n errors: metadata.errors,\n warnings: metadata.warnings,\n hmrUpdateCode: metadata.hmrUpdateCode,\n hmrEligible: metadata.hmrEligible,\n });\n };\n\n const writeOutputFile = (id: string) => {\n const sourceFile = builder.getSourceFile(id);\n if (!sourceFile) {\n return;\n }\n\n let content = '';\n builder.emit(\n sourceFile,\n (filename, data) => {\n if (/\\.[cm]?js$/.test(filename)) {\n content = data;\n }\n\n if (\n !watchMode &&\n !isTest &&\n /\\.d\\.ts/.test(filename) &&\n !filename.includes('.ngtypecheck.')\n ) {\n // output to library root instead /src\n const declarationPath = resolve(\n config.root,\n config.build.outDir,\n relative(config.root, filename),\n ).replace('/src/', '/');\n\n const declarationFileDir = declarationPath\n .replace(basename(filename), '')\n .replace('/src/', '/');\n\n declarationFiles.push({\n declarationFileDir,\n declarationPath,\n data,\n });\n }\n },\n undefined /* cancellationToken */,\n undefined /* emitOnlyDtsFiles */,\n transformers,\n );\n\n writeFileCallback(id, content, false, undefined, [sourceFile]);\n\n if (angularCompiler) {\n angularCompiler.incrementalCompilation.recordSuccessfulEmit(sourceFile);\n }\n };\n\n if (watchMode) {\n if (ids && ids.length > 0) {\n ids.forEach((id) => writeOutputFile(id));\n } else {\n /**\n * Only block the server from starting up\n * during testing.\n */\n if (isTest) {\n // TypeScript will loop until there are no more affected files in the program\n while (\n (\n builder as ts.EmitAndSemanticDiagnosticsBuilderProgram\n ).emitNextAffectedFile(\n writeFileCallback,\n undefined,\n undefined,\n transformers,\n )\n ) {\n /* empty */\n }\n }\n }\n }\n\n if (!isTest) {\n /**\n * Perf: Output files on demand so the dev server\n * isn't blocked when emitting files.\n */\n outputFile = writeOutputFile;\n }\n }\n}\n\nexport function createFsWatcherCacheInvalidator(\n invalidateFsCaches: () => void,\n invalidateTsconfigCaches: () => void,\n performCompilation: () => Promise<void>,\n): () => Promise<void> {\n return async (): Promise<void> => {\n invalidateFsCaches();\n invalidateTsconfigCaches();\n await performCompilation();\n };\n}\n\n/**\n * Convert Analog/Angular CLI-style file replacements into the flat record\n * expected by `AngularHostOptions.fileReplacements`.\n *\n * Only browser replacements (`{ replace, with }`) are converted. SSR-only\n * replacements (`{ replace, ssr }`) are left for the Vite runtime plugin to\n * handle — they should not be baked into the Angular compilation host because\n * that would apply them to both browser and server builds.\n *\n * Relative paths are resolved against `workspaceRoot` so that the host\n * receives the same absolute paths it would get from the Angular CLI.\n */\nexport function toAngularCompilationFileReplacements(\n replacements: FileReplacement[],\n workspaceRoot: string,\n): Record<string, string> | undefined {\n const mappedReplacements = replacements.flatMap((replacement) => {\n // Skip SSR-only entries — they use `ssr` instead of `with`.\n if (!('with' in replacement)) {\n return [];\n }\n\n return [\n [\n isAbsolute(replacement.replace)\n ? replacement.replace\n : resolve(workspaceRoot, replacement.replace),\n isAbsolute(replacement.with)\n ? replacement.with\n : resolve(workspaceRoot, replacement.with),\n ] as const,\n ];\n });\n\n return mappedReplacements.length\n ? Object.fromEntries(mappedReplacements)\n : undefined;\n}\n\n/**\n * Map Angular's `templateUpdates` (keyed by `encodedFilePath@ClassName`)\n * back to absolute file paths with their associated HMR code and component\n * class name.\n *\n * Angular's private Compilation API emits template update keys in the form\n * `encodeURIComponent(relativePath + '@' + className)`. We decode and resolve\n * them so the caller can look up updates by the same normalized absolute path\n * used elsewhere in the plugin (`outputFiles`, `classNames`, etc.).\n */\nexport function mapTemplateUpdatesToFiles(\n templateUpdates: ReadonlyMap<string, string> | undefined,\n): Map<\n string,\n {\n className: string;\n code: string;\n }\n> {\n const updatesByFile = new Map<string, { className: string; code: string }>();\n\n templateUpdates?.forEach((code, encodedUpdateId) => {\n const [file, className = ''] =\n decodeURIComponent(encodedUpdateId).split('@');\n const resolvedFile = normalizePath(resolve(process.cwd(), file));\n\n updatesByFile.set(resolvedFile, {\n className,\n code,\n });\n });\n\n return updatesByFile;\n}\n\nfunction sendHMRComponentUpdate(server: ViteDevServer, id: string) {\n server.ws.send('angular:component-update', {\n id: encodeURIComponent(id),\n timestamp: Date.now(),\n });\n\n classNames.delete(id);\n}\n\nexport function getFileMetadata(\n program: ts.BuilderProgram,\n angularCompiler?: NgtscProgram['compiler'],\n liveReload?: boolean,\n disableTypeChecking?: boolean,\n) {\n const ts = require('typescript');\n return (\n file: string,\n ): {\n errors?: string[];\n warnings?: (string | ts.DiagnosticMessageChain)[];\n hmrUpdateCode?: string | null;\n hmrEligible?: boolean;\n } => {\n const sourceFile = program.getSourceFile(file);\n if (!sourceFile) {\n return {};\n }\n\n const diagnostics = getDiagnosticsForSourceFile(\n sourceFile,\n !!disableTypeChecking,\n program,\n angularCompiler,\n );\n\n const errors = diagnostics\n .filter((d) => d.category === ts.DiagnosticCategory?.Error)\n .map((d) =>\n typeof d.messageText === 'object'\n ? d.messageText.messageText\n : d.messageText,\n );\n\n const warnings = diagnostics\n .filter((d) => d.category === ts.DiagnosticCategory?.Warning)\n .map((d) => d.messageText);\n\n let hmrUpdateCode: string | null | undefined = undefined;\n\n let hmrEligible = false;\n if (liveReload) {\n for (const node of sourceFile.statements) {\n if (ts.isClassDeclaration(node) && (node as any).name != null) {\n hmrUpdateCode = angularCompiler?.emitHmrUpdateModule(node as any);\n if (hmrUpdateCode) {\n classNames.set(file, (node as any).name.getText());\n hmrEligible = true;\n }\n }\n }\n }\n\n return { errors, warnings, hmrUpdateCode, hmrEligible };\n };\n}\n\nfunction getDiagnosticsForSourceFile(\n sourceFile: ts.SourceFile,\n disableTypeChecking: boolean,\n program: ts.BuilderProgram,\n angularCompiler?: NgtscProgram['compiler'],\n) {\n const syntacticDiagnostics = program.getSyntacticDiagnostics(sourceFile);\n\n if (disableTypeChecking) {\n // Syntax errors are cheap to compute and the app will not run if there are any\n // So always show these types of errors regardless if type checking is disabled\n return syntacticDiagnostics;\n }\n\n const semanticDiagnostics = program.getSemanticDiagnostics(sourceFile);\n const angularDiagnostics = angularCompiler\n ? angularCompiler.getDiagnosticsForFile(sourceFile, 1)\n : [];\n return [\n ...syntacticDiagnostics,\n ...semanticDiagnostics,\n ...angularDiagnostics,\n ];\n}\n\nfunction markModuleSelfAccepting(mod: ModuleNode): ModuleNode {\n // support Vite 6\n if ('_clientModule' in mod) {\n (mod as any)['_clientModule'].isSelfAccepting = true;\n }\n\n return {\n ...mod,\n isSelfAccepting: true,\n } as ModuleNode;\n}\n\nfunction isComponentStyleSheet(id: string): boolean {\n return id.includes('ngcomp=');\n}\n\nfunction getComponentStyleSheetMeta(id: string): {\n componentId: string;\n encapsulation: 'emulated' | 'shadow' | 'none';\n} {\n const params = new URL(id, 'http://localhost').searchParams;\n const encapsulationMapping = {\n '0': 'emulated',\n '2': 'none',\n '3': 'shadow',\n };\n return {\n componentId: params.get('ngcomp')!,\n encapsulation: encapsulationMapping[\n params.get('e') as keyof typeof encapsulationMapping\n ] as 'emulated' | 'shadow' | 'none',\n };\n}\n\n/**\n * Removes leading / and query string from a url path\n * e.g. /foo.scss?direct&ngcomp=ng-c3153525609&e=0 returns foo.scss\n * @param id\n */\nfunction getFilenameFromPath(id: string): string {\n return new URL(id, 'http://localhost').pathname.replace(/^\\//, '');\n}\n\n/**\n * Checks for vitest run from the command line\n * @returns boolean\n */\nexport function isTestWatchMode(args: string[] = process.argv): boolean {\n // vitest --run\n const hasRun = args.find((arg) => arg.includes('--run'));\n if (hasRun) {\n return false;\n }\n\n // vitest --no-run\n const hasNoRun = args.find((arg) => arg.includes('--no-run'));\n if (hasNoRun) {\n return true;\n }\n\n // check for --watch=false or --no-watch\n const hasWatch = args.find((arg) => arg.includes('watch'));\n if (hasWatch && ['false', 'no'].some((neg) => hasWatch.includes(neg))) {\n return false;\n }\n\n // check for --watch false\n const watchIndex = args.findIndex((arg) => arg.includes('watch'));\n const watchArg = args[watchIndex + 1];\n if (watchArg && watchArg === 'false') {\n return false;\n }\n\n return true;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;AAwDA,IAAM,UAAU,cAAc,OAAO,KAAK,IAAI;AAe9C,IAAY,kBAAL,yBAAA,iBAAA;AACL,iBAAA,gBAAA,UAAA,KAAA;AACA,iBAAA,gBAAA,YAAA,KAAA;AACA,iBAAA,gBAAA,eAAA,KAAA;AACA,iBAAA,gBAAA,cAAA,KAAA;AACA,iBAAA,gBAAA,SAAA,KAAA;;KACD;;;;;;AA6GD,IAAM,eAAe;AACrB,IAAM,6BAAa,IAAI,KAAK;;;;;;AAa5B,SAAS,uBACP,SAC0D;CAC1D,MAAM,mBAAmB,SAAS;CAClC,MAAM,KAAK,SAAS;AAEpB,KAAI,CAAC,MAAM,CAAC,iBACV;CAIF,IAAI;AAIJ,KAAI,IAAI;EACN,MAAM,iBAAiB,GAAG;EAC1B,MAAM,WAAW,GAAG;AAEpB,0BAAwB,MAAc,aAA6B;AAEjE,OACE,KAAK,SAAS,aAAa,IAC3B,KAAK,SAAS,0BAAwB,IACtC,KAAK,SAAS,wBAAwB,CAEtC,QAAO;AAQT,OAAI,EAJmB,WACnB,SAAS,MAAM,WAAW,KAAK,SAAS,OAAO,CAAC,GAChD,KAAK,SAAS,SAAS,EAGzB,QAAO;AAIT,UAAO,eADS,SAA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C;AAM/C,QAAO;EACL,aAAa,OAAO,IAAI,SAAS;EACjC,eAP2B;GAC3B,KAAK;GACL,KAAK;GACL,KAAK;GACN,CAIG,OAAO,IAAI,IAAI;EAElB;;;;;;;AAQH,SAAS,oBAAoB,IAAoB;AAC/C,QAAO,IAAI,IAAI,IAAI,mBAAmB,CAAC,SAAS,QAAQ,OAAO,GAAG;;;;;;AAOpE,SAAgB,gBAAgB,OAAiB,QAAQ,MAAe;AAGtE,KADe,KAAK,MAAM,QAAQ,IAAI,SAAS,QAAQ,CAAC,CAEtD,QAAO;AAKT,KADiB,KAAK,MAAM,QAAQ,IAAI,SAAS,WAAW,CAAC,CAE3D,QAAO;CAIT,MAAM,WAAW,KAAK,MAAM,QAAQ,IAAI,SAAS,QAAQ,CAAC;AAC1D,KAAI,YAAY,CAAC,SAAS,KAAK,CAAC,MAAM,QAAQ,SAAS,SAAS,IAAI,CAAC,CACnE,QAAO;CAKT,MAAM,WAAW,KADE,KAAK,WAAW,QAAQ,IAAI,SAAS,QAAQ,CAAC,GAC9B;AACnC,KAAI,YAAY,aAAa,QAC3B,QAAO;AAGT,QAAO"}
1
+ {"version":3,"file":"angular-vite-plugin.js","names":[],"sources":["../../../src/lib/angular-vite-plugin.ts"],"sourcesContent":["import { NgtscProgram } from '@angular/compiler-cli';\nimport { existsSync, mkdirSync, writeFileSync } from 'node:fs';\nimport {\n basename,\n dirname,\n isAbsolute,\n join,\n relative,\n resolve,\n} from 'node:path';\nimport * as vite from 'vite';\n\nimport * as compilerCli from '@angular/compiler-cli';\nimport { createRequire } from 'node:module';\nimport * as ts from 'typescript';\nimport { type createAngularCompilation as createAngularCompilationType } from '@angular/build/private';\n\nimport * as ngCompiler from '@angular/compiler';\nimport { globSync } from 'tinyglobby';\nimport {\n defaultClientConditions,\n ModuleNode,\n normalizePath,\n Plugin,\n preprocessCSS,\n ResolvedConfig,\n ViteDevServer,\n} from 'vite';\nimport { buildOptimizerPlugin } from './angular-build-optimizer-plugin.js';\nimport { jitPlugin } from './angular-jit-plugin.js';\nimport {\n createCompilerPlugin,\n createRolldownCompilerPlugin,\n} from './compiler-plugin.js';\nimport {\n StyleUrlsResolver,\n TemplateUrlsResolver,\n} from './component-resolvers.js';\nimport {\n augmentHostWithCaching,\n augmentHostWithResources,\n augmentProgramWithVersioning,\n mergeTransformers,\n} from './host.js';\nimport type { StylePreprocessor } from './style-preprocessor.js';\n\nimport { angularVitestPlugins } from './angular-vitest-plugin.js';\nimport {\n createAngularCompilation,\n createJitResourceTransformer,\n SourceFileCache,\n angularFullVersion,\n} from './utils/devkit.js';\nimport {\n activateDeferredDebug,\n applyDebugOption,\n debugCompilationApi,\n debugCompiler,\n debugHmr,\n debugStyles,\n debugTailwind,\n type DebugOption,\n} from './utils/debug.js';\nimport { getJsTransformConfigKey, isRolldown } from './utils/rolldown.js';\nimport { type SourceFileCache as SourceFileCacheType } from './utils/source-file-cache.js';\n\nconst require = createRequire(import.meta.url);\n\nimport { pendingTasksPlugin } from './angular-pending-tasks.plugin.js';\nimport { liveReloadPlugin } from './live-reload-plugin.js';\nimport { EmitFileResult } from './models.js';\nimport { nxFolderPlugin } from './nx-folder-plugin.js';\nimport {\n FileReplacement,\n FileReplacementSSR,\n FileReplacementWith,\n replaceFiles,\n} from './plugins/file-replacements.plugin.js';\nimport { routerPlugin } from './router-plugin.js';\nimport { createHash } from 'node:crypto';\n\nexport enum DiagnosticModes {\n None = 0,\n Option = 1 << 0,\n Syntactic = 1 << 1,\n Semantic = 1 << 2,\n All = Option | Syntactic | Semantic,\n}\n\nexport interface PluginOptions {\n tsconfig?: string | (() => string);\n workspaceRoot?: string;\n inlineStylesExtension?: string;\n jit?: boolean;\n advanced?: {\n /**\n * Custom TypeScript transformers that are run before Angular compilation\n */\n tsTransformers?: ts.CustomTransformers;\n };\n supportedBrowsers?: string[];\n transformFilter?: (code: string, id: string) => boolean;\n /**\n * Additional files to include in compilation\n */\n include?: string[];\n additionalContentDirs?: string[];\n liveReload?: boolean;\n disableTypeChecking?: boolean;\n fileReplacements?: FileReplacement[];\n experimental?: {\n useAngularCompilationAPI?: boolean;\n };\n /**\n * Enable debug logging for specific scopes.\n *\n * - `true` → enables all `analog:angular:*` scopes\n * - `string[]` → enables listed namespaces (e.g. `['analog:angular:compiler']`)\n * - `{ scopes?, mode? }` → object form with optional `mode: 'build' | 'dev'`\n * to restrict output to a specific Vite command (omit for both)\n *\n * Also responds to the `DEBUG` env var (Node.js) or `localStorage.debug`\n * (browser), using the `obug` convention.\n */\n debug?: DebugOption;\n /**\n * Optional preprocessor that transforms component CSS before it enters Vite's\n * preprocessCSS pipeline. Runs on every component stylesheet (both external\n * `.component.css` files and inline `styles: [...]` blocks).\n *\n * @param code - Raw CSS content of the component stylesheet\n * @param filename - Resolved file path of the stylesheet (or containing .ts file for inline styles)\n * @returns Transformed CSS string, or the original code if no transformation is needed\n */\n stylePreprocessor?: StylePreprocessor;\n /**\n * First-class Tailwind CSS v4 integration for Angular component styles.\n *\n * Angular's compiler processes component CSS through Vite's `preprocessCSS()`,\n * which runs `@tailwindcss/vite` — but each component stylesheet is processed\n * in isolation without access to the root Tailwind configuration (prefix, @theme,\n * @custom-variant, @plugin definitions). This causes errors like:\n *\n * \"Cannot apply utility class `sa:grid` because the `sa` variant does not exist\"\n *\n * The `tailwindCss` option solves this by auto-injecting a `@reference` directive\n * into every component CSS file that uses Tailwind utilities, pointing it to the\n * root Tailwind stylesheet so `@tailwindcss/vite` can resolve the full configuration.\n *\n * @example Basic usage — reference a root Tailwind CSS file:\n * ```ts\n * import { resolve } from 'node:path';\n *\n * angular({\n * tailwindCss: {\n * rootStylesheet: resolve(__dirname, 'src/styles/tailwind.css'),\n * },\n * })\n * ```\n *\n * @example With prefix detection — only inject for files using specific prefixes:\n * ```ts\n * angular({\n * tailwindCss: {\n * rootStylesheet: resolve(__dirname, 'src/styles/tailwind.css'),\n * // Only inject @reference into files that use these prefixed classes\n * prefixes: ['sa:', 'tw:'],\n * },\n * })\n * ```\n *\n * @example AnalogJS platform — passed through the `vite` option:\n * ```ts\n * analog({\n * vite: {\n * tailwindCss: {\n * rootStylesheet: resolve(__dirname, '../../../libs/meritos/tailwind.config.css'),\n * },\n * },\n * })\n * ```\n */\n tailwindCss?: {\n /**\n * Absolute path to the root Tailwind CSS file that contains `@import \"tailwindcss\"`,\n * `@theme`, `@custom-variant`, and `@plugin` definitions.\n *\n * A `@reference` directive pointing to this file will be auto-injected into\n * component CSS files that use Tailwind utilities.\n */\n rootStylesheet: string;\n /**\n * Optional list of class prefixes to detect (e.g. `['sa:', 'tw:']`).\n * When provided, `@reference` is only injected into component CSS files that\n * contain at least one of these prefixes. When omitted, `@reference` is injected\n * into all component CSS files that contain `@apply` or `@` directives.\n *\n * @default undefined — inject into all component CSS files with `@apply`\n */\n prefixes?: string[];\n };\n}\n\n/**\n * TypeScript file extension regex\n * Match .(c or m)ts, .ts extensions with an optional ? for query params\n * Ignore .tsx extensions\n */\nconst TS_EXT_REGEX = /\\.[cm]?(ts)[^x]?\\??/;\nconst classNames = new Map();\n\ninterface DeclarationFile {\n declarationFileDir: string;\n declarationPath: string;\n data: string;\n}\n\n/**\n * Builds a resolved stylePreprocessor function from plugin options.\n * If `tailwindCss` is provided, creates an auto-reference injector.\n * If `stylePreprocessor` is also provided, chains them (tailwind first, then user).\n */\nfunction buildStylePreprocessor(\n options?: PluginOptions,\n): ((code: string, filename: string) => string) | undefined {\n const userPreprocessor = options?.stylePreprocessor;\n const tw = options?.tailwindCss;\n\n if (!tw && !userPreprocessor) {\n return undefined;\n }\n\n // Build the Tailwind @reference injector\n let tailwindPreprocessor:\n | ((code: string, filename: string) => string)\n | undefined;\n\n if (tw) {\n const rootStylesheet = tw.rootStylesheet;\n const prefixes = tw.prefixes;\n debugTailwind('configured', { rootStylesheet, prefixes });\n\n tailwindPreprocessor = (code: string, filename: string): string => {\n // Skip if already has @reference or is a root Tailwind file\n if (\n code.includes('@reference') ||\n code.includes('@import \"tailwindcss\"') ||\n code.includes(\"@import 'tailwindcss'\")\n ) {\n debugTailwind('skip (already has @reference or is root)', { filename });\n return code;\n }\n\n // Check if the file uses Tailwind utilities\n const needsReference = prefixes\n ? prefixes.some((prefix) => code.includes(prefix))\n : code.includes('@apply');\n\n if (!needsReference) {\n debugTailwind('skip (no Tailwind usage detected)', { filename });\n return code;\n }\n\n debugTailwind('injected @reference', { filename });\n const refPath = relative(dirname(filename), rootStylesheet);\n return `@reference \"${refPath}\";\\n${code}`;\n };\n }\n\n // Chain: tailwind preprocessor first, then user preprocessor\n if (tailwindPreprocessor && userPreprocessor) {\n debugTailwind('chained with user stylePreprocessor');\n return (code: string, filename: string) => {\n const intermediate = tailwindPreprocessor!(code, filename);\n return userPreprocessor(intermediate, filename);\n };\n }\n\n return tailwindPreprocessor ?? userPreprocessor;\n}\n\nexport function angular(options?: PluginOptions): Plugin[] {\n applyDebugOption(options?.debug);\n\n /**\n * Normalize plugin options so defaults\n * are used for values not provided.\n */\n const pluginOptions = {\n tsconfigGetter: createTsConfigGetter(options?.tsconfig),\n workspaceRoot: options?.workspaceRoot ?? process.cwd(),\n inlineStylesExtension: options?.inlineStylesExtension ?? 'css',\n advanced: {\n tsTransformers: {\n before: options?.advanced?.tsTransformers?.before ?? [],\n after: options?.advanced?.tsTransformers?.after ?? [],\n afterDeclarations:\n options?.advanced?.tsTransformers?.afterDeclarations ?? [],\n },\n },\n supportedBrowsers: options?.supportedBrowsers ?? ['safari 15'],\n jit: options?.jit,\n include: options?.include ?? [],\n additionalContentDirs: options?.additionalContentDirs ?? [],\n liveReload: options?.liveReload ?? false,\n disableTypeChecking: options?.disableTypeChecking ?? true,\n fileReplacements: options?.fileReplacements ?? [],\n useAngularCompilationAPI:\n options?.experimental?.useAngularCompilationAPI ?? false,\n stylePreprocessor: buildStylePreprocessor(options),\n };\n\n let resolvedConfig: ResolvedConfig;\n // Store config context needed for getTsConfigPath resolution\n let tsConfigResolutionContext: {\n root: string;\n isProd: boolean;\n isLib: boolean;\n } | null = null;\n\n const ts = require('typescript');\n let builder: ts.BuilderProgram | ts.EmitAndSemanticDiagnosticsBuilderProgram;\n let nextProgram: NgtscProgram | undefined;\n // Caches (always rebuild Angular program per user request)\n const tsconfigOptionsCache = new Map<\n string,\n { options: ts.CompilerOptions; rootNames: string[] }\n >();\n let cachedHost: ts.CompilerHost | undefined;\n let cachedHostKey: string | undefined;\n let includeCache: string[] = [];\n function invalidateFsCaches() {\n includeCache = [];\n }\n function invalidateTsconfigCaches() {\n // `readConfiguration` caches the root file list, so hot-added pages can be\n // missing from Angular's compilation program until we clear this state.\n tsconfigOptionsCache.clear();\n cachedHost = undefined;\n cachedHostKey = undefined;\n }\n let watchMode = false;\n let testWatchMode = isTestWatchMode();\n let inlineComponentStyles: Map<string, string> | undefined;\n let externalComponentStyles: Map<string, string> | undefined;\n const sourceFileCache: SourceFileCacheType = new SourceFileCache();\n const isTest = process.env['NODE_ENV'] === 'test' || !!process.env['VITEST'];\n const isVitestVscode = !!process.env['VITEST_VSCODE'];\n const isStackBlitz = !!process.versions['webcontainer'];\n const isAstroIntegration = process.env['ANALOG_ASTRO'] === 'true';\n\n const jit =\n typeof pluginOptions?.jit !== 'undefined' ? pluginOptions.jit : isTest;\n let viteServer: ViteDevServer | undefined;\n\n const styleUrlsResolver = new StyleUrlsResolver();\n const templateUrlsResolver = new TemplateUrlsResolver();\n let outputFile: ((file: string) => void) | undefined;\n const outputFiles = new Map<string, EmitFileResult>();\n const fileEmitter = (file: string) => {\n outputFile?.(file);\n return outputFiles.get(normalizePath(file));\n };\n let initialCompilation = false;\n const declarationFiles: DeclarationFile[] = [];\n const fileTransformMap = new Map<string, string>();\n let styleTransform: (\n code: string,\n filename: string,\n ) => Promise<vite.PreprocessCSSResult>;\n let pendingCompilation: Promise<void> | null;\n let compilationLock = Promise.resolve();\n // Persistent Angular Compilation API instance. Kept alive across rebuilds so\n // Angular can diff previous state and emit `templateUpdates` for HMR.\n // Previously the compilation was recreated on every pass, which meant Angular\n // never had prior state and could never produce HMR payloads.\n let angularCompilation:\n | Awaited<ReturnType<typeof createAngularCompilationType>>\n | undefined;\n\n function angularPlugin(): Plugin {\n let isProd = false;\n\n if (angularFullVersion < 190000 || isTest) {\n pluginOptions.liveReload = false;\n debugHmr('liveReload disabled', {\n angularVersion: angularFullVersion,\n isTest,\n });\n }\n\n // liveReload and fileReplacements guards were previously here and forced\n // both options off when useAngularCompilationAPI was enabled. Those guards\n // have been removed because:\n // - liveReload: the persistent compilation instance (above) now gives\n // Angular the prior state it needs to emit `templateUpdates` for HMR\n // - fileReplacements: Angular's AngularHostOptions already accepts a\n // `fileReplacements` record — we now convert and pass it through in\n // `performAngularCompilation` via `toAngularCompilationFileReplacements`\n if (pluginOptions.useAngularCompilationAPI) {\n if (angularFullVersion < 200100) {\n pluginOptions.useAngularCompilationAPI = false;\n debugCompilationApi(\n 'disabled: Angular version %s < 20.1',\n angularFullVersion,\n );\n console.warn(\n '[@analogjs/vite-plugin-angular]: The Angular Compilation API is only available with Angular v20.1 and later',\n );\n } else {\n debugCompilationApi('enabled (Angular %s)', angularFullVersion);\n }\n }\n\n return {\n name: '@analogjs/vite-plugin-angular',\n async config(config, { command }) {\n activateDeferredDebug(command);\n watchMode = command === 'serve';\n isProd =\n config.mode === 'production' ||\n process.env['NODE_ENV'] === 'production';\n\n // Store the config context for later resolution in configResolved\n tsConfigResolutionContext = {\n root: config.root || '.',\n isProd,\n isLib: !!config?.build?.lib,\n };\n\n // Do a preliminary resolution for esbuild plugin (before configResolved)\n const preliminaryTsConfigPath = resolveTsConfigPath();\n\n const esbuild = pluginOptions.useAngularCompilationAPI\n ? undefined\n : (config.esbuild ?? false);\n const oxc = pluginOptions.useAngularCompilationAPI\n ? undefined\n : (config.oxc ?? false);\n if (pluginOptions.useAngularCompilationAPI) {\n debugCompilationApi(\n 'esbuild/oxc disabled, Angular handles transforms',\n );\n }\n\n const defineOptions = {\n ngJitMode: 'false',\n ngI18nClosureMode: 'false',\n ...(watchMode ? {} : { ngDevMode: 'false' }),\n };\n const useRolldown = isRolldown();\n const jsTransformConfigKey = getJsTransformConfigKey();\n const jsTransformConfigValue =\n jsTransformConfigKey === 'oxc' ? oxc : esbuild;\n\n const rolldownOptions: vite.DepOptimizationOptions['rolldownOptions'] =\n {\n plugins: [\n createRolldownCompilerPlugin(\n {\n tsconfig: preliminaryTsConfigPath,\n sourcemap: !isProd,\n advancedOptimizations: isProd,\n jit,\n incremental: watchMode,\n },\n // Astro manages the transformer lifecycle externally.\n !isAstroIntegration,\n ),\n ],\n };\n\n const esbuildOptions: vite.DepOptimizationOptions['esbuildOptions'] = {\n plugins: [\n createCompilerPlugin(\n {\n tsconfig: preliminaryTsConfigPath,\n sourcemap: !isProd,\n advancedOptimizations: isProd,\n jit,\n incremental: watchMode,\n },\n isTest,\n !isAstroIntegration,\n ),\n ],\n define: defineOptions,\n };\n\n return {\n [jsTransformConfigKey]: jsTransformConfigValue,\n optimizeDeps: {\n include: ['rxjs/operators', 'rxjs'],\n exclude: ['@angular/platform-server'],\n ...(useRolldown ? { rolldownOptions } : { esbuildOptions }),\n },\n resolve: {\n conditions: [\n 'style',\n ...(config.resolve?.conditions || defaultClientConditions),\n ],\n },\n };\n },\n configResolved(config) {\n resolvedConfig = config;\n\n if (pluginOptions.useAngularCompilationAPI) {\n externalComponentStyles = new Map();\n inlineComponentStyles = new Map();\n debugStyles('style maps initialized (Angular Compilation API)');\n }\n\n if (!jit) {\n styleTransform = (code: string, filename: string) =>\n preprocessCSS(code, filename, config);\n }\n\n if (isTest) {\n // set test watch mode\n // - vite override from vitest-angular\n // - @nx/vite executor set server.watch explicitly to undefined (watch)/null (watch=false)\n // - vite config for test.watch variable\n // - vitest watch mode detected from the command line\n testWatchMode =\n !(config.server.watch === null) ||\n (config as any).test?.watch === true ||\n testWatchMode;\n }\n },\n configureServer(server) {\n viteServer = server;\n // Add/unlink changes the TypeScript program shape, not just file\n // contents, so we need to invalidate both include discovery and the\n // cached tsconfig root names before recompiling.\n const invalidateCompilationOnFsChange = createFsWatcherCacheInvalidator(\n invalidateFsCaches,\n invalidateTsconfigCaches,\n () => performCompilation(resolvedConfig),\n );\n server.watcher.on('add', invalidateCompilationOnFsChange);\n server.watcher.on('unlink', invalidateCompilationOnFsChange);\n server.watcher.on('change', (file) => {\n if (file.includes('tsconfig')) {\n invalidateTsconfigCaches();\n }\n });\n },\n async buildStart() {\n // Defer the first compilation in test mode\n if (!isVitestVscode) {\n await performCompilation(resolvedConfig);\n pendingCompilation = null;\n\n initialCompilation = true;\n }\n },\n async handleHotUpdate(ctx) {\n if (TS_EXT_REGEX.test(ctx.file)) {\n const [fileId] = ctx.file.split('?');\n debugHmr('TS file changed', { file: ctx.file, fileId });\n\n pendingCompilation = performCompilation(resolvedConfig, [fileId]);\n\n let result;\n\n if (pluginOptions.liveReload) {\n await pendingCompilation;\n pendingCompilation = null;\n result = fileEmitter(fileId);\n debugHmr('TS file emitted', {\n fileId,\n hmrEligible: !!result?.hmrEligible,\n hasClassName: !!classNames.get(fileId),\n });\n }\n\n if (\n pluginOptions.liveReload &&\n result?.hmrEligible &&\n classNames.get(fileId)\n ) {\n const relativeFileId = `${normalizePath(\n relative(process.cwd(), fileId),\n )}@${classNames.get(fileId)}`;\n\n debugHmr('sending component update', { relativeFileId });\n sendHMRComponentUpdate(ctx.server, relativeFileId);\n\n return ctx.modules.map((mod) => {\n if (mod.id === ctx.file) {\n return markModuleSelfAccepting(mod);\n }\n\n return mod;\n });\n }\n }\n\n if (/\\.(html|htm|css|less|sass|scss)$/.test(ctx.file)) {\n debugHmr('resource file changed', { file: ctx.file });\n fileTransformMap.delete(ctx.file.split('?')[0]);\n /**\n * Check to see if this was a direct request\n * for an external resource (styles, html).\n */\n const isDirect = ctx.modules.find(\n (mod) => ctx.file === mod.file && mod.id?.includes('?direct'),\n );\n const isInline = ctx.modules.find(\n (mod) => ctx.file === mod.file && mod.id?.includes('?inline'),\n );\n\n if (isDirect || isInline) {\n if (pluginOptions.liveReload && isDirect?.id && isDirect.file) {\n const isComponentStyle =\n isDirect.type === 'css' && isComponentStyleSheet(isDirect.id);\n if (isComponentStyle) {\n const { encapsulation } = getComponentStyleSheetMeta(\n isDirect.id,\n );\n debugStyles('HMR: component stylesheet changed', {\n file: isDirect.file,\n encapsulation,\n });\n\n // Track if the component uses ShadowDOM encapsulation\n // Shadow DOM components currently require a full reload.\n // Vite's CSS hot replacement does not support shadow root searching.\n if (encapsulation !== 'shadow') {\n ctx.server.ws.send({\n type: 'update',\n updates: [\n {\n type: 'css-update',\n timestamp: Date.now(),\n path: isDirect.url,\n acceptedPath: isDirect.file,\n },\n ],\n });\n\n return ctx.modules\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 \"hmr update *.component.scss, *.component.scss?direct&ngcomp=xyz&e=x\"\n return mod.file !== ctx.file || mod.id !== isDirect.id;\n })\n .map((mod) => {\n if (mod.file === ctx.file) {\n return markModuleSelfAccepting(mod);\n }\n return mod;\n }) as ModuleNode[];\n }\n }\n }\n return ctx.modules;\n }\n\n const mods: ModuleNode[] = [];\n const updates: string[] = [];\n ctx.modules.forEach((mod) => {\n mod.importers.forEach((imp) => {\n ctx.server.moduleGraph.invalidateModule(imp);\n\n if (pluginOptions.liveReload && classNames.get(imp.id)) {\n updates.push(imp.id as string);\n } else {\n mods.push(imp);\n }\n });\n });\n\n pendingCompilation = performCompilation(resolvedConfig, [\n ...mods.map((mod) => mod.id as string),\n ...updates,\n ]);\n\n if (updates.length > 0) {\n await pendingCompilation;\n pendingCompilation = null;\n\n debugHmr('resource importer component updates', {\n file: ctx.file,\n updateCount: updates.length,\n });\n updates.forEach((updateId) => {\n const impRelativeFileId = `${normalizePath(\n relative(process.cwd(), updateId),\n )}@${classNames.get(updateId)}`;\n\n sendHMRComponentUpdate(ctx.server, impRelativeFileId);\n });\n\n return ctx.modules.map((mod) => {\n if (mod.id === ctx.file) {\n return markModuleSelfAccepting(mod);\n }\n\n return mod;\n });\n }\n\n return mods;\n }\n\n // clear HMR updates with a full reload\n debugHmr('full reload — unrecognized file type', { file: ctx.file });\n classNames.clear();\n return ctx.modules;\n },\n resolveId(id, importer) {\n if (jit && id.startsWith('angular:jit:')) {\n const path = id.split(';')[1];\n return `${normalizePath(\n resolve(dirname(importer as string), path),\n )}?${id.includes(':style') ? 'inline' : 'raw'}`;\n }\n\n // Map angular external styleUrls to the source file\n if (isComponentStyleSheet(id)) {\n const filename = getFilenameFromPath(id);\n const componentStyles = externalComponentStyles?.get(filename);\n if (componentStyles) {\n debugStyles('resolveId: mapped external stylesheet', {\n filename,\n resolvedPath: componentStyles,\n });\n return componentStyles + new URL(id, 'http://localhost').search;\n }\n }\n\n return undefined;\n },\n async load(id) {\n // Map angular inline styles to the source text\n if (isComponentStyleSheet(id)) {\n const filename = getFilenameFromPath(id);\n const componentStyles = inlineComponentStyles?.get(filename);\n if (componentStyles) {\n debugStyles('load: served inline component stylesheet', {\n filename,\n length: componentStyles.length,\n });\n return componentStyles;\n }\n }\n\n return;\n },\n transform: {\n filter: {\n id: {\n include: [TS_EXT_REGEX],\n exclude: [/node_modules/, 'type=script', '@ng/component'],\n },\n },\n async handler(code, id) {\n /**\n * Check for options.transformFilter\n */\n if (\n options?.transformFilter &&\n !(options?.transformFilter(code, id) ?? true)\n ) {\n return;\n }\n\n if (pluginOptions.useAngularCompilationAPI) {\n const isAngular =\n /(Component|Directive|Pipe|Injectable|NgModule)\\(/.test(code);\n\n if (!isAngular) {\n debugCompilationApi('transform skip (non-Angular file)', { id });\n return;\n }\n }\n\n /**\n * Skip transforming content files\n */\n if (id.includes('?') && id.includes('analog-content-')) {\n return;\n }\n\n /**\n * Encapsulate component stylesheets that use emulated encapsulation\n */\n if (pluginOptions.liveReload && isComponentStyleSheet(id)) {\n const { encapsulation, componentId } =\n getComponentStyleSheetMeta(id);\n if (encapsulation === 'emulated' && componentId) {\n debugStyles('applying emulated view encapsulation', {\n stylesheet: id.split('?')[0],\n componentId,\n });\n const encapsulated = ngCompiler.encapsulateStyle(\n code,\n componentId,\n );\n return {\n code: encapsulated,\n map: null,\n };\n }\n }\n\n if (id.includes('.ts?')) {\n // Strip the query string off the ID\n // in case of a dynamically loaded file\n id = id.replace(/\\?(.*)/, '');\n }\n\n fileTransformMap.set(id, code);\n\n /**\n * Re-analyze on each transform\n * for test(Vitest)\n */\n if (isTest) {\n if (isVitestVscode && !initialCompilation) {\n // Do full initial compilation\n pendingCompilation = performCompilation(resolvedConfig);\n initialCompilation = true;\n }\n\n const tsMod = viteServer?.moduleGraph.getModuleById(id);\n if (tsMod) {\n const invalidated = tsMod.lastInvalidationTimestamp;\n\n if (testWatchMode && invalidated) {\n pendingCompilation = performCompilation(resolvedConfig, [id]);\n }\n }\n }\n\n const hasComponent = code.includes('@Component');\n debugCompiler('transform', {\n id,\n codeLength: code.length,\n hasComponent,\n });\n const templateUrls = hasComponent\n ? templateUrlsResolver.resolve(code, id)\n : [];\n const styleUrls = hasComponent\n ? styleUrlsResolver.resolve(code, id)\n : [];\n\n if (hasComponent && watchMode) {\n for (const urlSet of [...templateUrls, ...styleUrls]) {\n // `urlSet` is a string where a relative path is joined with an\n // absolute path using the `|` symbol.\n // For example: `./app.component.html|/home/projects/analog/src/app/app.component.html`.\n const [, absoluteFileUrl] = urlSet.split('|');\n this.addWatchFile(absoluteFileUrl);\n }\n }\n\n if (pendingCompilation) {\n await pendingCompilation;\n pendingCompilation = null;\n }\n\n const typescriptResult = fileEmitter(id);\n\n if (\n typescriptResult?.warnings &&\n typescriptResult?.warnings.length > 0\n ) {\n this.warn(`${typescriptResult.warnings.join('\\n')}`);\n }\n\n if (typescriptResult?.errors && typescriptResult?.errors.length > 0) {\n this.error(`${typescriptResult.errors.join('\\n')}`);\n }\n\n // return fileEmitter\n let data = typescriptResult?.content ?? '';\n\n if (jit && data.includes('angular:jit:')) {\n data = data.replace(\n /angular:jit:style:inline;/g,\n 'virtual:angular:jit:style:inline;',\n );\n\n templateUrls.forEach((templateUrlSet) => {\n const [templateFile, resolvedTemplateUrl] =\n templateUrlSet.split('|');\n data = data.replace(\n `angular:jit:template:file;${templateFile}`,\n `${resolvedTemplateUrl}?raw`,\n );\n });\n\n styleUrls.forEach((styleUrlSet) => {\n const [styleFile, resolvedStyleUrl] = styleUrlSet.split('|');\n data = data.replace(\n `angular:jit:style:file;${styleFile}`,\n `${resolvedStyleUrl}?inline`,\n );\n });\n }\n\n return {\n code: data,\n map: null,\n };\n },\n },\n closeBundle() {\n declarationFiles.forEach(\n ({ declarationFileDir, declarationPath, data }) => {\n mkdirSync(declarationFileDir, { recursive: true });\n writeFileSync(declarationPath, data, 'utf-8');\n },\n );\n // Tear down the persistent compilation instance at end of build so it\n // does not leak memory across unrelated Vite invocations.\n angularCompilation?.close?.();\n angularCompilation = undefined;\n },\n };\n }\n\n return [\n replaceFiles(pluginOptions.fileReplacements, pluginOptions.workspaceRoot),\n angularPlugin(),\n pluginOptions.liveReload && liveReloadPlugin({ classNames, fileEmitter }),\n ...(isTest && !isStackBlitz ? angularVitestPlugins() : []),\n (jit &&\n jitPlugin({\n inlineStylesExtension: pluginOptions.inlineStylesExtension,\n })) as Plugin,\n buildOptimizerPlugin({\n supportedBrowsers: pluginOptions.supportedBrowsers,\n jit,\n }),\n routerPlugin(),\n angularFullVersion < 190004 && pendingTasksPlugin(),\n nxFolderPlugin(),\n ].filter(Boolean) as Plugin[];\n\n function findIncludes() {\n const workspaceRoot = normalizePath(resolve(pluginOptions.workspaceRoot));\n\n // Map include patterns to absolute workspace paths\n const globs = [\n ...pluginOptions.include.map((glob) => `${workspaceRoot}${glob}`),\n ];\n\n // Discover TypeScript files using tinyglobby\n return globSync(globs, {\n dot: true,\n absolute: true,\n });\n }\n\n function createTsConfigGetter(tsconfigOrGetter?: string | (() => string)) {\n if (typeof tsconfigOrGetter === 'function') {\n return tsconfigOrGetter;\n }\n\n return () => tsconfigOrGetter || '';\n }\n\n function getTsConfigPath(\n root: string,\n tsconfig: string,\n isProd: boolean,\n isTest: boolean,\n isLib: boolean,\n ) {\n if (tsconfig && isAbsolute(tsconfig)) {\n if (!existsSync(tsconfig)) {\n console.error(\n `[@analogjs/vite-plugin-angular]: Unable to resolve tsconfig at ${tsconfig}. This causes compilation issues. Check the path or set the \"tsconfig\" property with an absolute path.`,\n );\n }\n\n return tsconfig;\n }\n\n let tsconfigFilePath = './tsconfig.app.json';\n\n if (isLib) {\n tsconfigFilePath = isProd\n ? './tsconfig.lib.prod.json'\n : './tsconfig.lib.json';\n }\n\n if (isTest) {\n tsconfigFilePath = './tsconfig.spec.json';\n }\n\n if (tsconfig) {\n tsconfigFilePath = tsconfig;\n }\n\n const resolvedPath = resolve(root, tsconfigFilePath);\n\n if (!existsSync(resolvedPath)) {\n console.error(\n `[@analogjs/vite-plugin-angular]: Unable to resolve tsconfig at ${resolvedPath}. This causes compilation issues. Check the path or set the \"tsconfig\" property with an absolute path.`,\n );\n }\n\n return resolvedPath;\n }\n\n function resolveTsConfigPath() {\n const tsconfigValue = pluginOptions.tsconfigGetter();\n\n return getTsConfigPath(\n tsConfigResolutionContext!.root,\n tsconfigValue,\n tsConfigResolutionContext!.isProd,\n isTest,\n tsConfigResolutionContext!.isLib,\n );\n }\n\n /**\n * Perform compilation using Angular's private Compilation API.\n *\n * Key differences from the standard `performCompilation` path:\n * 1. The compilation instance is reused across rebuilds (nullish-coalescing\n * assignment below) so Angular retains prior state and can diff it to\n * produce `templateUpdates` for HMR.\n * 2. `ids` (modified files) are forwarded to both the source-file cache and\n * `angularCompilation.update()` so that incremental re-analysis is\n * scoped to what actually changed.\n * 3. `fileReplacements` are converted and passed into Angular's host via\n * `toAngularCompilationFileReplacements`.\n * 4. `templateUpdates` from the compilation result are mapped back to\n * file-level HMR metadata (`hmrUpdateCode`, `hmrEligible`, `classNames`).\n */\n async function performAngularCompilation(\n config: ResolvedConfig,\n ids?: string[],\n ) {\n // Reuse the existing instance so Angular can diff against prior state.\n angularCompilation ??= await (\n createAngularCompilation as typeof createAngularCompilationType\n )(!!pluginOptions.jit, false);\n const modifiedFiles = ids?.length\n ? new Set(ids.map((file) => normalizePath(file)))\n : undefined;\n if (modifiedFiles?.size) {\n sourceFileCache.invalidate(modifiedFiles);\n }\n // Notify Angular of modified files before re-initialization so it can\n // scope its incremental analysis.\n if (modifiedFiles?.size && angularCompilation.update) {\n debugCompilationApi('incremental update', {\n files: [...modifiedFiles],\n });\n await angularCompilation.update(modifiedFiles);\n }\n\n const resolvedTsConfigPath = resolveTsConfigPath();\n const compilationResult = await angularCompilation.initialize(\n resolvedTsConfigPath,\n {\n // Convert Analog's browser-style `{ replace, with }` entries into the\n // `Record<string, string>` shape that Angular's AngularHostOptions\n // expects. SSR-only replacements (`{ replace, ssr }`) are intentionally\n // excluded — they stay on the Vite runtime side.\n fileReplacements: toAngularCompilationFileReplacements(\n pluginOptions.fileReplacements,\n pluginOptions.workspaceRoot,\n ),\n modifiedFiles,\n async transformStylesheet(\n data,\n containingFile,\n resourceFile,\n order,\n className,\n ) {\n const filename =\n resourceFile ??\n containingFile.replace(\n '.ts',\n `.${pluginOptions.inlineStylesExtension}`,\n );\n\n // Apply any user-defined stylesheet preprocessing before Vite transforms it.\n const preprocessedData = pluginOptions.stylePreprocessor\n ? (pluginOptions.stylePreprocessor(data, filename) ?? data)\n : data;\n\n if (pluginOptions.liveReload && watchMode) {\n // Store the preprocessed (but not yet CSS-transformed) data so that\n // Vite's serve-time pipeline handles PostCSS / Tailwind processing\n // exactly once when the load hook returns this CSS. Running\n // preprocessCSS() here would strip directives like @reference before\n // the CSS re-enters the transform pipeline, causing plugins such as\n // @tailwindcss/vite to fail on the second pass.\n // Guard must match the externalRuntimeStyles condition (line ~927)\n // because the Angular compiler only emits external style references\n // when externalRuntimeStyles is enabled.\n const id = createHash('sha256')\n .update(containingFile)\n .update(className as string)\n .update(String(order))\n .update(preprocessedData)\n .digest('hex');\n const stylesheetId = id + '.' + pluginOptions.inlineStylesExtension;\n inlineComponentStyles!.set(stylesheetId, preprocessedData);\n\n debugStyles('stylesheet deferred to Vite pipeline (liveReload)', {\n stylesheetId,\n resourceFile: resourceFile ?? '(inline)',\n });\n\n return stylesheetId;\n }\n\n // Non-liveReload: the CSS is returned directly to the Angular\n // compiler and never re-enters Vite's pipeline, so we must run\n // preprocessCSS() eagerly here.\n debugStyles(\n 'stylesheet processed inline via preprocessCSS (no liveReload)',\n {\n filename,\n resourceFile: resourceFile ?? '(inline)',\n dataLength: preprocessedData.length,\n },\n );\n let stylesheetResult;\n\n try {\n stylesheetResult = await preprocessCSS(\n preprocessedData,\n `${filename}?direct`,\n resolvedConfig,\n );\n } catch (e) {\n console.error(`${e}`);\n }\n\n return stylesheetResult?.code || '';\n },\n processWebWorker(workerFile, containingFile) {\n return '';\n },\n },\n (tsCompilerOptions) => {\n if (pluginOptions.liveReload && watchMode) {\n tsCompilerOptions['_enableHmr'] = true;\n tsCompilerOptions['externalRuntimeStyles'] = true;\n // Workaround for https://github.com/angular/angular/issues/59310\n // Force extra instructions to be generated for HMR w/defer\n tsCompilerOptions['supportTestBed'] = true;\n }\n\n debugCompiler('tsCompilerOptions (compilation API)', {\n liveReload: pluginOptions.liveReload,\n watchMode,\n externalRuntimeStyles: !!tsCompilerOptions['externalRuntimeStyles'],\n hmr: !!tsCompilerOptions['_enableHmr'],\n });\n\n if (tsCompilerOptions.compilationMode === 'partial') {\n // These options can't be false in partial mode\n tsCompilerOptions['supportTestBed'] = true;\n tsCompilerOptions['supportJitMode'] = true;\n }\n\n if (!isTest && config.build?.lib) {\n tsCompilerOptions['declaration'] = true;\n tsCompilerOptions['declarationMap'] = watchMode;\n tsCompilerOptions['inlineSources'] = true;\n }\n\n if (isTest) {\n // Allow `TestBed.overrideXXX()` APIs.\n tsCompilerOptions['supportTestBed'] = true;\n }\n\n return tsCompilerOptions;\n },\n );\n\n compilationResult.externalStylesheets?.forEach((value, key) => {\n externalComponentStyles?.set(`${value}.css`, key);\n debugStyles('external stylesheet registered for resolveId mapping', {\n filename: `${value}.css`,\n resolvedPath: key,\n });\n });\n\n const diagnostics = await angularCompilation.diagnoseFiles(\n pluginOptions.disableTypeChecking\n ? DiagnosticModes.All & ~DiagnosticModes.Semantic\n : DiagnosticModes.All,\n );\n\n const errors = diagnostics.errors?.length ? diagnostics.errors : [];\n const warnings = diagnostics.warnings?.length ? diagnostics.warnings : [];\n // Angular encodes template updates as `encodedFilePath@ClassName` keys.\n // `mapTemplateUpdatesToFiles` decodes them back to absolute file paths so\n // we can attach HMR metadata to the correct `EmitFileResult` below.\n const templateUpdates = mapTemplateUpdatesToFiles(\n compilationResult.templateUpdates,\n );\n if (templateUpdates.size > 0) {\n debugHmr('compilation API template updates', {\n count: templateUpdates.size,\n files: [...templateUpdates.keys()],\n });\n }\n\n for (const file of await angularCompilation.emitAffectedFiles()) {\n const normalizedFilename = normalizePath(file.filename);\n const templateUpdate = templateUpdates.get(normalizedFilename);\n\n if (templateUpdate) {\n classNames.set(normalizedFilename, templateUpdate.className);\n }\n\n // Surface Angular's HMR payloads into Analog's existing live-reload\n // flow via the `hmrUpdateCode` / `hmrEligible` fields.\n outputFiles.set(normalizedFilename, {\n content: file.contents,\n dependencies: [],\n errors: errors.map((error: { text?: string }) => error.text || ''),\n warnings: warnings.map(\n (warning: { text?: string }) => warning.text || '',\n ),\n hmrUpdateCode: templateUpdate?.code,\n hmrEligible: !!templateUpdate?.code,\n });\n }\n }\n\n async function performCompilation(config: ResolvedConfig, ids?: string[]) {\n let resolve: (() => unknown) | undefined;\n const previousLock = compilationLock;\n compilationLock = new Promise<void>((r) => {\n resolve = r;\n });\n try {\n await previousLock;\n await _doPerformCompilation(config, ids);\n } finally {\n resolve!();\n }\n }\n\n /**\n * This method share mutable state and performs the actual compilation work.\n * It should not be called concurrently. Use `performCompilation` which wraps this method in a lock to ensure only one compilation runs at a time.\n */\n async function _doPerformCompilation(config: ResolvedConfig, ids?: string[]) {\n // Forward `ids` (modified files) so the Compilation API path can do\n // incremental re-analysis instead of a full recompile on every change.\n if (pluginOptions.useAngularCompilationAPI) {\n debugCompilationApi('using compilation API path', {\n modifiedFiles: ids?.length ?? 0,\n });\n await performAngularCompilation(config, ids);\n return;\n }\n\n const isProd = config.mode === 'production';\n const modifiedFiles = new Set<string>(ids ?? []);\n sourceFileCache.invalidate(modifiedFiles);\n\n if (ids?.length) {\n for (const id of ids || []) {\n fileTransformMap.delete(id);\n }\n }\n\n // Cached include discovery (invalidated only on FS events)\n if (pluginOptions.include.length > 0 && includeCache.length === 0) {\n includeCache = findIncludes();\n }\n\n const resolvedTsConfigPath = resolveTsConfigPath();\n const tsconfigKey = [\n resolvedTsConfigPath,\n isProd ? 'prod' : 'dev',\n isTest ? 'test' : 'app',\n config.build?.lib ? 'lib' : 'nolib',\n ].join('|');\n let cached = tsconfigOptionsCache.get(tsconfigKey);\n\n if (!cached) {\n const read = compilerCli.readConfiguration(resolvedTsConfigPath, {\n suppressOutputPathCheck: true,\n outDir: undefined,\n sourceMap: false,\n inlineSourceMap: !isProd,\n inlineSources: !isProd,\n declaration: false,\n declarationMap: false,\n allowEmptyCodegenFiles: false,\n annotationsAs: 'decorators',\n enableResourceInlining: false,\n noEmitOnError: false,\n mapRoot: undefined,\n sourceRoot: undefined,\n supportTestBed: false,\n supportJitMode: false,\n });\n cached = { options: read.options, rootNames: read.rootNames };\n tsconfigOptionsCache.set(tsconfigKey, cached);\n }\n\n // Clone options before mutation (preserve cache purity)\n const tsCompilerOptions = { ...cached.options };\n let rootNames = [...cached.rootNames];\n\n if (pluginOptions.liveReload && watchMode) {\n tsCompilerOptions['_enableHmr'] = true;\n tsCompilerOptions['externalRuntimeStyles'] = true;\n // Workaround for https://github.com/angular/angular/issues/59310\n // Force extra instructions to be generated for HMR w/defer\n tsCompilerOptions['supportTestBed'] = true;\n }\n\n debugCompiler('tsCompilerOptions (NgtscProgram path)', {\n externalRuntimeStyles: !!tsCompilerOptions['externalRuntimeStyles'],\n hmr: !!tsCompilerOptions['_enableHmr'],\n });\n\n if (tsCompilerOptions['compilationMode'] === 'partial') {\n // These options can't be false in partial mode\n tsCompilerOptions['supportTestBed'] = true;\n tsCompilerOptions['supportJitMode'] = true;\n }\n\n if (!isTest && config.build?.lib) {\n tsCompilerOptions['declaration'] = true;\n tsCompilerOptions['declarationMap'] = watchMode;\n tsCompilerOptions['inlineSources'] = true;\n }\n\n if (isTest) {\n // Allow `TestBed.overrideXXX()` APIs.\n tsCompilerOptions['supportTestBed'] = true;\n }\n\n const replacements = pluginOptions.fileReplacements.map((rp) =>\n join(\n pluginOptions.workspaceRoot,\n (rp as FileReplacementSSR).ssr || (rp as FileReplacementWith).with,\n ),\n );\n // Merge + dedupe root names\n rootNames = [...new Set([...rootNames, ...includeCache, ...replacements])];\n const hostKey = JSON.stringify(tsCompilerOptions);\n let host: ts.CompilerHost;\n\n if (cachedHost && cachedHostKey === hostKey) {\n host = cachedHost;\n } else {\n host = ts.createIncrementalCompilerHost(tsCompilerOptions, {\n ...ts.sys,\n readFile(path: string, encoding: string) {\n if (fileTransformMap.has(path)) {\n return fileTransformMap.get(path);\n }\n\n const file = ts.sys.readFile.call(null, path, encoding);\n\n if (file) {\n fileTransformMap.set(path, file);\n }\n\n return file;\n },\n });\n cachedHost = host;\n cachedHostKey = hostKey;\n\n // Only store cache if in watch mode\n if (watchMode) {\n augmentHostWithCaching(host, sourceFileCache);\n }\n }\n\n if (!jit) {\n const externalizeStyles = !!tsCompilerOptions['externalRuntimeStyles'];\n inlineComponentStyles = externalizeStyles ? new Map() : undefined;\n externalComponentStyles = externalizeStyles ? new Map() : undefined;\n debugStyles('style maps initialized (NgtscProgram path)', {\n externalizeStyles,\n });\n augmentHostWithResources(host, styleTransform, {\n inlineStylesExtension: pluginOptions.inlineStylesExtension,\n isProd,\n inlineComponentStyles,\n externalComponentStyles,\n sourceFileCache,\n stylePreprocessor: pluginOptions.stylePreprocessor,\n });\n }\n\n /**\n * Creates a new NgtscProgram to analyze/re-analyze\n * the source files and create a file emitter.\n * This is shared between an initial build and a hot update.\n */\n let typeScriptProgram: ts.Program;\n let angularCompiler: NgtscProgram['compiler'];\n const oldBuilder =\n builder ?? ts.readBuilderProgram(tsCompilerOptions, host);\n\n if (!jit) {\n // Create the Angular specific program that contains the Angular compiler\n const angularProgram: NgtscProgram = new compilerCli.NgtscProgram(\n rootNames,\n tsCompilerOptions,\n host,\n nextProgram,\n );\n angularCompiler = angularProgram.compiler;\n typeScriptProgram = angularProgram.compiler.getCurrentProgram();\n augmentProgramWithVersioning(typeScriptProgram);\n\n builder = ts.createEmitAndSemanticDiagnosticsBuilderProgram(\n typeScriptProgram,\n host,\n oldBuilder as ts.EmitAndSemanticDiagnosticsBuilderProgram,\n );\n\n nextProgram = angularProgram;\n } else {\n builder = ts.createEmitAndSemanticDiagnosticsBuilderProgram(\n rootNames,\n tsCompilerOptions,\n host,\n oldBuilder as ts.EmitAndSemanticDiagnosticsBuilderProgram,\n );\n\n typeScriptProgram = builder.getProgram();\n }\n\n if (!watchMode) {\n // When not in watch mode, the startup cost of the incremental analysis can be avoided by\n // using an abstract builder that only wraps a TypeScript program.\n builder = ts.createAbstractBuilder(typeScriptProgram, host, oldBuilder);\n }\n\n if (angularCompiler!) {\n await angularCompiler.analyzeAsync();\n }\n\n const beforeTransformers = jit\n ? [\n compilerCli.constructorParametersDownlevelTransform(\n builder.getProgram(),\n ),\n createJitResourceTransformer(() =>\n builder.getProgram().getTypeChecker(),\n ),\n ]\n : [];\n\n const transformers = mergeTransformers(\n { before: beforeTransformers },\n jit ? {} : angularCompiler!.prepareEmit().transformers,\n );\n\n const fileMetadata = getFileMetadata(\n builder,\n angularCompiler!,\n pluginOptions.liveReload,\n pluginOptions.disableTypeChecking,\n );\n\n const writeFileCallback: ts.WriteFileCallback = (\n _filename,\n content,\n _a,\n _b,\n sourceFiles,\n ) => {\n if (!sourceFiles?.length) {\n return;\n }\n\n const filename = normalizePath(sourceFiles[0].fileName);\n\n if (filename.includes('ngtypecheck.ts') || filename.includes('.d.')) {\n return;\n }\n\n const metadata = watchMode ? fileMetadata(filename) : {};\n\n outputFiles.set(filename, {\n content,\n dependencies: [],\n errors: metadata.errors,\n warnings: metadata.warnings,\n hmrUpdateCode: metadata.hmrUpdateCode,\n hmrEligible: metadata.hmrEligible,\n });\n };\n\n const writeOutputFile = (id: string) => {\n const sourceFile = builder.getSourceFile(id);\n if (!sourceFile) {\n return;\n }\n\n let content = '';\n builder.emit(\n sourceFile,\n (filename, data) => {\n if (/\\.[cm]?js$/.test(filename)) {\n content = data;\n }\n\n if (\n !watchMode &&\n !isTest &&\n /\\.d\\.ts/.test(filename) &&\n !filename.includes('.ngtypecheck.')\n ) {\n // output to library root instead /src\n const declarationPath = resolve(\n config.root,\n config.build.outDir,\n relative(config.root, filename),\n ).replace('/src/', '/');\n\n const declarationFileDir = declarationPath\n .replace(basename(filename), '')\n .replace('/src/', '/');\n\n declarationFiles.push({\n declarationFileDir,\n declarationPath,\n data,\n });\n }\n },\n undefined /* cancellationToken */,\n undefined /* emitOnlyDtsFiles */,\n transformers,\n );\n\n writeFileCallback(id, content, false, undefined, [sourceFile]);\n\n if (angularCompiler) {\n angularCompiler.incrementalCompilation.recordSuccessfulEmit(sourceFile);\n }\n };\n\n if (watchMode) {\n if (ids && ids.length > 0) {\n ids.forEach((id) => writeOutputFile(id));\n } else {\n /**\n * Only block the server from starting up\n * during testing.\n */\n if (isTest) {\n // TypeScript will loop until there are no more affected files in the program\n while (\n (\n builder as ts.EmitAndSemanticDiagnosticsBuilderProgram\n ).emitNextAffectedFile(\n writeFileCallback,\n undefined,\n undefined,\n transformers,\n )\n ) {\n /* empty */\n }\n }\n }\n }\n\n if (!isTest) {\n /**\n * Perf: Output files on demand so the dev server\n * isn't blocked when emitting files.\n */\n outputFile = writeOutputFile;\n }\n }\n}\n\nexport function createFsWatcherCacheInvalidator(\n invalidateFsCaches: () => void,\n invalidateTsconfigCaches: () => void,\n performCompilation: () => Promise<void>,\n): () => Promise<void> {\n return async (): Promise<void> => {\n invalidateFsCaches();\n invalidateTsconfigCaches();\n await performCompilation();\n };\n}\n\n/**\n * Convert Analog/Angular CLI-style file replacements into the flat record\n * expected by `AngularHostOptions.fileReplacements`.\n *\n * Only browser replacements (`{ replace, with }`) are converted. SSR-only\n * replacements (`{ replace, ssr }`) are left for the Vite runtime plugin to\n * handle — they should not be baked into the Angular compilation host because\n * that would apply them to both browser and server builds.\n *\n * Relative paths are resolved against `workspaceRoot` so that the host\n * receives the same absolute paths it would get from the Angular CLI.\n */\nexport function toAngularCompilationFileReplacements(\n replacements: FileReplacement[],\n workspaceRoot: string,\n): Record<string, string> | undefined {\n const mappedReplacements = replacements.flatMap((replacement) => {\n // Skip SSR-only entries — they use `ssr` instead of `with`.\n if (!('with' in replacement)) {\n return [];\n }\n\n return [\n [\n isAbsolute(replacement.replace)\n ? replacement.replace\n : resolve(workspaceRoot, replacement.replace),\n isAbsolute(replacement.with)\n ? replacement.with\n : resolve(workspaceRoot, replacement.with),\n ] as const,\n ];\n });\n\n return mappedReplacements.length\n ? Object.fromEntries(mappedReplacements)\n : undefined;\n}\n\n/**\n * Map Angular's `templateUpdates` (keyed by `encodedFilePath@ClassName`)\n * back to absolute file paths with their associated HMR code and component\n * class name.\n *\n * Angular's private Compilation API emits template update keys in the form\n * `encodeURIComponent(relativePath + '@' + className)`. We decode and resolve\n * them so the caller can look up updates by the same normalized absolute path\n * used elsewhere in the plugin (`outputFiles`, `classNames`, etc.).\n */\nexport function mapTemplateUpdatesToFiles(\n templateUpdates: ReadonlyMap<string, string> | undefined,\n): Map<\n string,\n {\n className: string;\n code: string;\n }\n> {\n const updatesByFile = new Map<string, { className: string; code: string }>();\n\n templateUpdates?.forEach((code, encodedUpdateId) => {\n const [file, className = ''] =\n decodeURIComponent(encodedUpdateId).split('@');\n const resolvedFile = normalizePath(resolve(process.cwd(), file));\n\n updatesByFile.set(resolvedFile, {\n className,\n code,\n });\n });\n\n return updatesByFile;\n}\n\nfunction sendHMRComponentUpdate(server: ViteDevServer, id: string) {\n server.ws.send('angular:component-update', {\n id: encodeURIComponent(id),\n timestamp: Date.now(),\n });\n\n classNames.delete(id);\n}\n\nexport function getFileMetadata(\n program: ts.BuilderProgram,\n angularCompiler?: NgtscProgram['compiler'],\n liveReload?: boolean,\n disableTypeChecking?: boolean,\n) {\n const ts = require('typescript');\n return (\n file: string,\n ): {\n errors?: string[];\n warnings?: (string | ts.DiagnosticMessageChain)[];\n hmrUpdateCode?: string | null;\n hmrEligible?: boolean;\n } => {\n const sourceFile = program.getSourceFile(file);\n if (!sourceFile) {\n return {};\n }\n\n const diagnostics = getDiagnosticsForSourceFile(\n sourceFile,\n !!disableTypeChecking,\n program,\n angularCompiler,\n );\n\n const errors = diagnostics\n .filter((d) => d.category === ts.DiagnosticCategory?.Error)\n .map((d) =>\n typeof d.messageText === 'object'\n ? d.messageText.messageText\n : d.messageText,\n );\n\n const warnings = diagnostics\n .filter((d) => d.category === ts.DiagnosticCategory?.Warning)\n .map((d) => d.messageText);\n\n let hmrUpdateCode: string | null | undefined = undefined;\n\n let hmrEligible = false;\n if (liveReload) {\n for (const node of sourceFile.statements) {\n if (ts.isClassDeclaration(node) && (node as any).name != null) {\n hmrUpdateCode = angularCompiler?.emitHmrUpdateModule(node as any);\n if (hmrUpdateCode) {\n const className = (node as any).name.getText();\n classNames.set(file, className);\n hmrEligible = true;\n debugHmr('NgtscProgram emitHmrUpdateModule', { file, className });\n }\n }\n }\n }\n\n return { errors, warnings, hmrUpdateCode, hmrEligible };\n };\n}\n\nfunction getDiagnosticsForSourceFile(\n sourceFile: ts.SourceFile,\n disableTypeChecking: boolean,\n program: ts.BuilderProgram,\n angularCompiler?: NgtscProgram['compiler'],\n) {\n const syntacticDiagnostics = program.getSyntacticDiagnostics(sourceFile);\n\n if (disableTypeChecking) {\n // Syntax errors are cheap to compute and the app will not run if there are any\n // So always show these types of errors regardless if type checking is disabled\n return syntacticDiagnostics;\n }\n\n const semanticDiagnostics = program.getSemanticDiagnostics(sourceFile);\n const angularDiagnostics = angularCompiler\n ? angularCompiler.getDiagnosticsForFile(sourceFile, 1)\n : [];\n return [\n ...syntacticDiagnostics,\n ...semanticDiagnostics,\n ...angularDiagnostics,\n ];\n}\n\nfunction markModuleSelfAccepting(mod: ModuleNode): ModuleNode {\n // support Vite 6\n if ('_clientModule' in mod) {\n (mod as any)['_clientModule'].isSelfAccepting = true;\n }\n\n return {\n ...mod,\n isSelfAccepting: true,\n } as ModuleNode;\n}\n\nfunction isComponentStyleSheet(id: string): boolean {\n return id.includes('ngcomp=');\n}\n\nfunction getComponentStyleSheetMeta(id: string): {\n componentId: string;\n encapsulation: 'emulated' | 'shadow' | 'none';\n} {\n const params = new URL(id, 'http://localhost').searchParams;\n const encapsulationMapping = {\n '0': 'emulated',\n '2': 'none',\n '3': 'shadow',\n };\n return {\n componentId: params.get('ngcomp')!,\n encapsulation: encapsulationMapping[\n params.get('e') as keyof typeof encapsulationMapping\n ] as 'emulated' | 'shadow' | 'none',\n };\n}\n\n/**\n * Removes leading / and query string from a url path\n * e.g. /foo.scss?direct&ngcomp=ng-c3153525609&e=0 returns foo.scss\n * @param id\n */\nfunction getFilenameFromPath(id: string): string {\n return new URL(id, 'http://localhost').pathname.replace(/^\\//, '');\n}\n\n/**\n * Checks for vitest run from the command line\n * @returns boolean\n */\nexport function isTestWatchMode(args: string[] = process.argv): boolean {\n // vitest --run\n const hasRun = args.find((arg) => arg.includes('--run'));\n if (hasRun) {\n return false;\n }\n\n // vitest --no-run\n const hasNoRun = args.find((arg) => arg.includes('--no-run'));\n if (hasNoRun) {\n return true;\n }\n\n // check for --watch=false or --no-watch\n const hasWatch = args.find((arg) => arg.includes('watch'));\n if (hasWatch && ['false', 'no'].some((neg) => hasWatch.includes(neg))) {\n return false;\n }\n\n // check for --watch false\n const watchIndex = args.findIndex((arg) => arg.includes('watch'));\n const watchArg = args[watchIndex + 1];\n if (watchArg && watchArg === 'false') {\n return false;\n }\n\n return true;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;AAk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AY,EAAE,GACpD,EAAE;AACN,QAAO;EACL,GAAG;EACH,GAAG;EACH,GAAG;EACJ;;AAGH,SAAS,wBAAwB,KAA6B;AAE5D,KAAI,mBAAmB,IACpB,KAAY,iBAAiB,kBAAkB;AAGlD,QAAO;EACL,GAAG;EACH,iBAAiB;EAClB;;AAGH,SAAS,sBAAsB,IAAqB;AAClD,QAAO,GAAG,SAAS,UAAU;;AAG/B,SAAS,2BAA2B,IAGlC;CACA,MAAM,SAAS,IAAI,IAAI,IAAI,mBAAmB,CAAC;AAM/C,QAAO;EACL,aAAa,OAAO,IAAI,SAAS;EACjC,eAP2B;GAC3B,KAAK;GACL,KAAK;GACL,KAAK;GACN,CAIG,OAAO,IAAI,IAAI;EAElB;;;;;;;AAQH,SAAS,oBAAoB,IAAoB;AAC/C,QAAO,IAAI,IAAI,IAAI,mBAAmB,CAAC,SAAS,QAAQ,OAAO,GAAG;;;;;;AAOpE,SAAgB,gBAAgB,OAAiB,QAAQ,MAAe;AAGtE,KADe,KAAK,MAAM,QAAQ,IAAI,SAAS,QAAQ,CAAC,CAEtD,QAAO;AAKT,KADiB,KAAK,MAAM,QAAQ,IAAI,SAAS,WAAW,CAAC,CAE3D,QAAO;CAIT,MAAM,WAAW,KAAK,MAAM,QAAQ,IAAI,SAAS,QAAQ,CAAC;AAC1D,KAAI,YAAY,CAAC,SAAS,KAAK,CAAC,MAAM,QAAQ,SAAS,SAAS,IAAI,CAAC,CACnE,QAAO;CAKT,MAAM,WAAW,KADE,KAAK,WAAW,QAAQ,IAAI,SAAS,QAAQ,CAAC,GAC9B;AACnC,KAAI,YAAY,aAAa,QAC3B,QAAO;AAGT,QAAO"}
package/src/lib/host.js CHANGED
@@ -1,3 +1,4 @@
1
+ import { debugStyles } from "./utils/debug.js";
1
2
  import path from "node:path";
2
3
  import { normalizePath } from "vite";
3
4
  import { createHash } from "node:crypto";
@@ -20,8 +21,17 @@ function augmentHostWithResources(host, transform, options) {
20
21
  if (options.inlineComponentStyles) {
21
22
  const stylesheetId = createHash("sha256").update(context.containingFile).update(context.className).update(String(context.order)).update(preprocessedData).digest("hex") + "." + options.inlineStylesExtension;
22
23
  options.inlineComponentStyles.set(stylesheetId, preprocessedData);
24
+ debugStyles("NgtscProgram: stylesheet deferred to Vite pipeline (liveReload)", {
25
+ stylesheetId,
26
+ resourceFile: context.resourceFile ?? "(inline)"
27
+ });
23
28
  return { content: stylesheetId };
24
29
  }
30
+ debugStyles("NgtscProgram: stylesheet processed inline via transform (no liveReload)", {
31
+ filename,
32
+ resourceFile: context.resourceFile ?? "(inline)",
33
+ dataLength: preprocessedData.length
34
+ });
25
35
  let stylesheetResult;
26
36
  try {
27
37
  stylesheetResult = await transform(preprocessedData, `${filename}?direct`);
@@ -37,6 +47,11 @@ function augmentHostWithResources(host, transform, options) {
37
47
  externalId ??= createHash("sha256").update(resolvedPath).digest("hex");
38
48
  const filename = externalId + path.extname(resolvedPath);
39
49
  options.externalComponentStyles.set(filename, resolvedPath);
50
+ debugStyles("NgtscProgram: external stylesheet ID mapped for resolveId", {
51
+ resourceName,
52
+ resolvedPath,
53
+ filename
54
+ });
40
55
  return filename;
41
56
  };
42
57
  }
@@ -1 +1 @@
1
- {"version":3,"file":"host.js","names":[],"sources":["../../../src/lib/host.ts"],"sourcesContent":["import type { CompilerHost } from '@angular/compiler-cli';\nimport { normalizePath } from 'vite';\n\nimport * as ts from 'typescript';\n\nimport { createHash } from 'node:crypto';\nimport path from 'node:path';\nimport type { StylePreprocessor } from './style-preprocessor.js';\nimport type { SourceFileCache } from './utils/source-file-cache.js';\n\nexport function augmentHostWithResources(\n host: ts.CompilerHost,\n transform: (\n code: string,\n id: string,\n options?: { ssr?: boolean },\n ) => ReturnType<any> | null,\n options: {\n inlineStylesExtension: string;\n isProd?: boolean;\n inlineComponentStyles?: Map<string, string>;\n externalComponentStyles?: Map<string, string>;\n sourceFileCache?: SourceFileCache;\n stylePreprocessor?: StylePreprocessor;\n },\n): void {\n const resourceHost = host as CompilerHost;\n\n resourceHost.readResource = async function (fileName: string) {\n const filePath = normalizePath(fileName);\n\n const content = (this as any).readFile(filePath);\n\n if (content === undefined) {\n throw new Error('Unable to locate component resource: ' + fileName);\n }\n\n return content;\n };\n\n resourceHost.getModifiedResourceFiles = function () {\n return options?.sourceFileCache?.modifiedFiles;\n };\n\n resourceHost.transformResource = async function (data, context) {\n // Only style resources are supported currently\n if (context.type !== 'style') {\n return null;\n }\n\n const filename =\n context.resourceFile ??\n context.containingFile.replace(\n '.ts',\n `.${options?.inlineStylesExtension}`,\n );\n const preprocessedData = options.stylePreprocessor\n ? (options.stylePreprocessor(data, filename) ?? data)\n : data;\n\n // liveReload path: store preprocessed CSS for Vite's serve-time pipeline.\n // CSS must NOT be transformed here — the load hook returns it into\n // Vite's transform pipeline where PostCSS / Tailwind process it once.\n if (options.inlineComponentStyles) {\n const id = createHash('sha256')\n .update(context.containingFile)\n .update(context.className)\n .update(String(context.order))\n .update(preprocessedData)\n .digest('hex');\n const stylesheetId = id + '.' + options.inlineStylesExtension;\n options.inlineComponentStyles.set(stylesheetId, preprocessedData);\n return { content: stylesheetId };\n }\n\n // Non-liveReload: CSS is returned directly to the Angular compiler\n // and never re-enters Vite's pipeline, so transform eagerly.\n let stylesheetResult;\n\n try {\n stylesheetResult = await transform(\n preprocessedData,\n `${filename}?direct`,\n );\n } catch (e) {\n console.error(`${e}`);\n }\n\n return { content: stylesheetResult?.code || '' };\n };\n\n resourceHost.resourceNameToFileName = function (\n resourceName,\n containingFile,\n ) {\n const resolvedPath = path.join(path.dirname(containingFile), resourceName);\n\n // All resource names that have template file extensions are assumed to be templates\n if (!options.externalComponentStyles || !hasStyleExtension(resolvedPath)) {\n return resolvedPath;\n }\n\n // For external stylesheets, create a unique identifier and store the mapping\n let externalId = options.externalComponentStyles.get(resolvedPath);\n externalId ??= createHash('sha256').update(resolvedPath).digest('hex');\n\n const filename = externalId + path.extname(resolvedPath);\n\n options.externalComponentStyles.set(filename, resolvedPath);\n\n return filename;\n };\n}\n\nexport function augmentProgramWithVersioning(program: ts.Program): void {\n const baseGetSourceFiles = program.getSourceFiles;\n program.getSourceFiles = function (...parameters) {\n const files: readonly (ts.SourceFile & { version?: string })[] =\n baseGetSourceFiles(...parameters);\n\n for (const file of files) {\n file.version ??= createHash('sha256').update(file.text).digest('hex');\n }\n\n return files;\n };\n}\n\nexport function augmentHostWithCaching(\n host: ts.CompilerHost,\n cache: Map<string, ts.SourceFile>,\n): void {\n const baseGetSourceFile = host.getSourceFile;\n host.getSourceFile = function (\n fileName,\n languageVersion,\n onError,\n shouldCreateNewSourceFile,\n ...parameters\n ) {\n if (!shouldCreateNewSourceFile && cache.has(fileName)) {\n return cache.get(fileName);\n }\n\n const file = baseGetSourceFile.call(\n host,\n fileName,\n languageVersion,\n onError,\n true,\n ...parameters,\n );\n\n if (file) {\n cache.set(fileName, file);\n }\n\n return file;\n };\n}\n\nexport function mergeTransformers(\n first: ts.CustomTransformers,\n second: ts.CustomTransformers,\n): ts.CustomTransformers {\n const result: ts.CustomTransformers = {};\n\n if (first.before || second.before) {\n result.before = [...(first.before || []), ...(second.before || [])];\n }\n\n if (first.after || second.after) {\n result.after = [...(first.after || []), ...(second.after || [])];\n }\n\n if (first.afterDeclarations || second.afterDeclarations) {\n result.afterDeclarations = [\n ...(first.afterDeclarations || []),\n ...(second.afterDeclarations || []),\n ];\n }\n\n return result;\n}\n\nfunction hasStyleExtension(file: string): boolean {\n const extension = path.extname(file).toLowerCase();\n\n switch (extension) {\n case '.css':\n case '.scss':\n return true;\n default:\n return false;\n }\n}\n"],"mappings":";;;;AAUA,SAAgB,yBACd,MACA,WAKA,SAQM;CACN,MAAM,eAAe;AAErB,cAAa,eAAe,eAAgB,UAAkB;EAC5D,MAAM,WAAW,cAAc,SAAS;EAExC,MAAM,UAAW,KAAa,SAAS,SAAS;AAEhD,MAAI,YAAY,KAAA,EACd,OAAM,IAAI,MAAM,0CAA0C,SAAS;AAGrE,SAAO;;AAGT,cAAa,2BAA2B,W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,QAAQ,MACjB,MAAK,YAAY,WAAW,SAAS,CAAC,OAAO,KAAK,KAAK,CAAC,OAAO,MAAM;AAGvE,SAAO;;;AAIX,SAAgB,uBACd,MACA,OACM;CACN,MAAM,oBAAoB,KAAK;AAC/B,MAAK,gBAAgB,SACnB,UACA,iBACA,SACA,2BACA,GAAG,YACH;AACA,MAAI,CAAC,6BAA6B,MAAM,IAAI,SAAS,CACnD,QAAO,MAAM,IAAI,SAAS;EAG5B,MAAM,OAAO,kBAAkB,KAC7B,MACA,UACA,iBACA,SACA,MACA,GAAG,WACJ;AAED,MAAI,KACF,OAAM,IAAI,UAAU,KAAK;AAG3B,SAAO;;;AAIX,SAAgB,kBACd,OACA,QACuB;CACvB,MAAM,SAAgC,EAAE;AAExC,KAAI,MAAM,UAAU,OAAO,OACzB,QAAO,SAAS,CAAC,GAAI,MAAM,UAAU,EAAE,EAAG,GAAI,OAAO,UAAU,EAAE,CAAE;AAGrE,KAAI,MAAM,SAAS,OAAO,MACxB,QAAO,QAAQ,CAAC,GAAI,MAAM,SAAS,EAAE,EAAG,GAAI,OAAO,SAAS,EAAE,CAAE;AAGlE,KAAI,MAAM,qBAAqB,OAAO,kBACpC,QAAO,oBAAoB,CACzB,GAAI,MAAM,qBAAqB,EAAE,EACjC,GAAI,OAAO,qBAAqB,EAAE,CACnC;AAGH,QAAO;;AAGT,SAAS,kBAAkB,MAAuB;AAGhD,SAFkB,KAAK,QAAQ,KAAK,CAAC,aAAa,EAElD;EACE,KAAK;EACL,KAAK,QACH,QAAO;EACT,QACE,QAAO"}
1
+ {"version":3,"file":"host.js","names":[],"sources":["../../../src/lib/host.ts"],"sourcesContent":["import type { CompilerHost } from '@angular/compiler-cli';\nimport { normalizePath } from 'vite';\n\nimport * as ts from 'typescript';\n\nimport { createHash } from 'node:crypto';\nimport path from 'node:path';\nimport type { StylePreprocessor } from './style-preprocessor.js';\nimport { debugStyles } from './utils/debug.js';\nimport type { SourceFileCache } from './utils/source-file-cache.js';\n\nexport function augmentHostWithResources(\n host: ts.CompilerHost,\n transform: (\n code: string,\n id: string,\n options?: { ssr?: boolean },\n ) => ReturnType<any> | null,\n options: {\n inlineStylesExtension: string;\n isProd?: boolean;\n inlineComponentStyles?: Map<string, string>;\n externalComponentStyles?: Map<string, string>;\n sourceFileCache?: SourceFileCache;\n stylePreprocessor?: StylePreprocessor;\n },\n): void {\n const resourceHost = host as CompilerHost;\n\n resourceHost.readResource = async function (fileName: string) {\n const filePath = normalizePath(fileName);\n\n const content = (this as any).readFile(filePath);\n\n if (content === undefined) {\n throw new Error('Unable to locate component resource: ' + fileName);\n }\n\n return content;\n };\n\n resourceHost.getModifiedResourceFiles = function () {\n return options?.sourceFileCache?.modifiedFiles;\n };\n\n resourceHost.transformResource = async function (data, context) {\n // Only style resources are supported currently\n if (context.type !== 'style') {\n return null;\n }\n\n const filename =\n context.resourceFile ??\n context.containingFile.replace(\n '.ts',\n `.${options?.inlineStylesExtension}`,\n );\n const preprocessedData = options.stylePreprocessor\n ? (options.stylePreprocessor(data, filename) ?? data)\n : data;\n\n // liveReload path: store preprocessed CSS for Vite's serve-time pipeline.\n // CSS must NOT be transformed here — the load hook returns it into\n // Vite's transform pipeline where PostCSS / Tailwind process it once.\n if (options.inlineComponentStyles) {\n const id = createHash('sha256')\n .update(context.containingFile)\n .update(context.className)\n .update(String(context.order))\n .update(preprocessedData)\n .digest('hex');\n const stylesheetId = id + '.' + options.inlineStylesExtension;\n options.inlineComponentStyles.set(stylesheetId, preprocessedData);\n debugStyles(\n 'NgtscProgram: stylesheet deferred to Vite pipeline (liveReload)',\n {\n stylesheetId,\n resourceFile: context.resourceFile ?? '(inline)',\n },\n );\n return { content: stylesheetId };\n }\n\n // Non-liveReload: CSS is returned directly to the Angular compiler\n // and never re-enters Vite's pipeline, so transform eagerly.\n debugStyles(\n 'NgtscProgram: stylesheet processed inline via transform (no liveReload)',\n {\n filename,\n resourceFile: context.resourceFile ?? '(inline)',\n dataLength: preprocessedData.length,\n },\n );\n let stylesheetResult;\n\n try {\n stylesheetResult = await transform(\n preprocessedData,\n `${filename}?direct`,\n );\n } catch (e) {\n console.error(`${e}`);\n }\n\n return { content: stylesheetResult?.code || '' };\n };\n\n resourceHost.resourceNameToFileName = function (\n resourceName,\n containingFile,\n ) {\n const resolvedPath = path.join(path.dirname(containingFile), resourceName);\n\n // All resource names that have template file extensions are assumed to be templates\n if (!options.externalComponentStyles || !hasStyleExtension(resolvedPath)) {\n return resolvedPath;\n }\n\n // For external stylesheets, create a unique identifier and store the mapping\n let externalId = options.externalComponentStyles.get(resolvedPath);\n externalId ??= createHash('sha256').update(resolvedPath).digest('hex');\n\n const filename = externalId + path.extname(resolvedPath);\n\n options.externalComponentStyles.set(filename, resolvedPath);\n debugStyles('NgtscProgram: external stylesheet ID mapped for resolveId', {\n resourceName,\n resolvedPath,\n filename,\n });\n\n return filename;\n };\n}\n\nexport function augmentProgramWithVersioning(program: ts.Program): void {\n const baseGetSourceFiles = program.getSourceFiles;\n program.getSourceFiles = function (...parameters) {\n const files: readonly (ts.SourceFile & { version?: string })[] =\n baseGetSourceFiles(...parameters);\n\n for (const file of files) {\n file.version ??= createHash('sha256').update(file.text).digest('hex');\n }\n\n return files;\n };\n}\n\nexport function augmentHostWithCaching(\n host: ts.CompilerHost,\n cache: Map<string, ts.SourceFile>,\n): void {\n const baseGetSourceFile = host.getSourceFile;\n host.getSourceFile = function (\n fileName,\n languageVersion,\n onError,\n shouldCreateNewSourceFile,\n ...parameters\n ) {\n if (!shouldCreateNewSourceFile && cache.has(fileName)) {\n return cache.get(fileName);\n }\n\n const file = baseGetSourceFile.call(\n host,\n fileName,\n languageVersion,\n onError,\n true,\n ...parameters,\n );\n\n if (file) {\n cache.set(fileName, file);\n }\n\n return file;\n };\n}\n\nexport function mergeTransformers(\n first: ts.CustomTransformers,\n second: ts.CustomTransformers,\n): ts.CustomTransformers {\n const result: ts.CustomTransformers = {};\n\n if (first.before || second.before) {\n result.before = [...(first.before || []), ...(second.before || [])];\n }\n\n if (first.after || second.after) {\n result.after = [...(first.after || []), ...(second.after || [])];\n }\n\n if (first.afterDeclarations || second.afterDeclarations) {\n result.afterDeclarations = [\n ...(first.afterDeclarations || []),\n ...(second.afterDeclarations || []),\n ];\n }\n\n return result;\n}\n\nfunction hasStyleExtension(file: string): boolean {\n const extension = path.extname(file).toLowerCase();\n\n switch (extension) {\n case '.css':\n case '.scss':\n return true;\n default:\n return false;\n }\n}\n"],"mappings":";;;;;AAWA,SAAgB,yBACd,MACA,WAKA,SAQM;CACN,MAAM,eAAe;AAErB,cAAa,eAAe,eAAgB,UAAkB;EAC5D,MAAM,WAAW,cAAc,SAAS;EAExC,MAAM,UAAW,KAAa,SAAS,SAAS;AAEhD,MAAI,YAAY,KAAA,EACd,OAAM,IAAI,MAAM,0CAA0C,SAAS;AAGrE,SAAO;;AAGT,cAAa,2BAA2B,WAAY;AAClD,SAAO,SAAS,iBAAiB;;AAGnC,cAAa,oBAAoB,eAAgB,MAAM,SAAS;AAE9D,MAAI,QAAQ,SAAS,QACnB,QAAO;EAGT,MAAM,WACJ,QAAQ,gBACR,QAAQ,eAAe,QACrB,OACA,IAAI,SAAS,wBACd;EACH,MAAM,mBAAmB,QAAQ,oBAC5B,QAAQ,kBAAkB,MAAM,SAAS,IAAI,OAC9C;AAKJ,MAAI,QAAQ,uBAAuB;GAOjC,MAAM,eANK,WAAW,SAAS,CAC5B,OAAO,QAAQ,eAAe,CAC9B,OAAO,QAAQ,UAAU,CACzB,OAAO,OAAO,QAAQ,MAAM,CAAC,CAC7B,OAAO,iBAAiB,CACxB,OAAO,MAAM,GACU,MAAM,QAAQ;AACxC,WAAQ,sBAAsB,IAAI,cAAc,iBAAiB;AACjE,eACE,mEACA;IACE;IACA,cAAc,QAAQ,gBAAgB;IACvC,CACF;AACD,UAAO,EAAE,SAAS,cAAc;;AAKlC,cACE,2EACA;GACE;GACA,cAAc,QAAQ,gBAAgB;GACtC,YAAY,iBAAiB;GAC9B,CACF;EACD,IAAI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O,SAAS,CAAC,GAAI,MAAM,UAAU,EAAE,EAAG,GAAI,OAAO,UAAU,EAAE,CAAE;AAGrE,KAAI,MAAM,SAAS,OAAO,MACxB,QAAO,QAAQ,CAAC,GAAI,MAAM,SAAS,EAAE,EAAG,GAAI,OAAO,SAAS,EAAE,CAAE;AAGlE,KAAI,MAAM,qBAAqB,OAAO,kBACpC,QAAO,oBAAoB,CACzB,GAAI,MAAM,qBAAqB,EAAE,EACjC,GAAI,OAAO,qBAAqB,EAAE,CACnC;AAGH,QAAO;;AAGT,SAAS,kBAAkB,MAAuB;AAGhD,SAFkB,KAAK,QAAQ,KAAK,CAAC,aAAa,EAElD;EACE,KAAK;EACL,KAAK,QACH,QAAO;EACT,QACE,QAAO"}
@@ -1,3 +1,4 @@
1
+ import { debugHmr } from "./utils/debug.js";
1
2
  import { resolve } from "node:path";
2
3
  import { normalizePath } from "vite";
3
4
  //#region packages/vite-plugin-angular/src/lib/live-reload-plugin.ts
@@ -23,12 +24,17 @@ function liveReloadPlugin({ classNames, fileEmitter }) {
23
24
  const [fileId] = decodeURIComponent(componentId).split("@");
24
25
  const resolvedId = normalizePath(resolve(process.cwd(), fileId));
25
26
  if (!(!!server.moduleGraph.getModuleById(resolvedId)?.lastInvalidationTimestamp && classNames.get(resolvedId))) {
27
+ debugHmr("middleware: skipped (not invalidated)", { resolvedId });
26
28
  res.setHeader("Content-Type", "text/javascript");
27
29
  res.setHeader("Cache-Control", "no-cache");
28
30
  res.end("");
29
31
  return;
30
32
  }
31
33
  const result = fileEmitter(resolvedId);
34
+ debugHmr("middleware: served component update", {
35
+ resolvedId,
36
+ hasCode: !!result?.hmrUpdateCode
37
+ });
32
38
  res.setHeader("Content-Type", "text/javascript");
33
39
  res.setHeader("Cache-Control", "no-cache");
34
40
  res.end(`${result?.hmrUpdateCode || ""}`);
@@ -1 +1 @@
1
- {"version":3,"file":"live-reload-plugin.js","names":[],"sources":["../../../src/lib/live-reload-plugin.ts"],"sourcesContent":["import { resolve } from 'node:path';\nimport { ServerResponse } from 'node:http';\nimport { Connect, normalizePath, Plugin, ViteDevServer } from 'vite';\n\nimport { EmitFileResult } from './models.js';\n\nconst ANGULAR_COMPONENT_PREFIX = '/@ng/component';\nconst FILE_PREFIX = 'file:';\n\nexport function liveReloadPlugin({\n classNames,\n fileEmitter,\n}: {\n classNames: Map<string, string>;\n fileEmitter: (file: string) => EmitFileResult | undefined;\n}): Plugin {\n return {\n name: 'analogjs-live-reload-plugin',\n apply: 'serve',\n configureServer(server: ViteDevServer) {\n const angularComponentMiddleware: Connect.HandleFunction = async (\n req: Connect.IncomingMessage,\n res: ServerResponse<Connect.IncomingMessage>,\n next: Connect.NextFunction,\n ) => {\n if (req.url === undefined || res.writableEnded) {\n return;\n }\n\n if (!req.url.includes(ANGULAR_COMPONENT_PREFIX)) {\n next();\n\n return;\n }\n\n const requestUrl = new URL(req.url, 'http://localhost');\n const componentId = requestUrl.searchParams.get('c');\n\n if (!componentId) {\n res.statusCode = 400;\n res.end();\n\n return;\n }\n\n const [fileId] = decodeURIComponent(componentId).split('@');\n const resolvedId = normalizePath(resolve(process.cwd(), fileId));\n const invalidated =\n !!server.moduleGraph.getModuleById(resolvedId)\n ?.lastInvalidationTimestamp && classNames.get(resolvedId);\n\n // don't send an HMR update until the file has been invalidated\n if (!invalidated) {\n res.setHeader('Content-Type', 'text/javascript');\n res.setHeader('Cache-Control', 'no-cache');\n res.end('');\n return;\n }\n\n const result = fileEmitter(resolvedId);\n res.setHeader('Content-Type', 'text/javascript');\n res.setHeader('Cache-Control', 'no-cache');\n res.end(`${result?.hmrUpdateCode || ''}`);\n };\n\n server.middlewares.use(angularComponentMiddleware);\n },\n resolveId(id, _importer, options) {\n if (\n options?.ssr &&\n id.startsWith(FILE_PREFIX) &&\n id.includes(ANGULAR_COMPONENT_PREFIX)\n ) {\n return `\\0${id}`;\n }\n\n return undefined;\n },\n load(id, options) {\n if (options?.ssr && id.includes(ANGULAR_COMPONENT_PREFIX)) {\n const requestUrl = new URL(id.slice(1), 'http://localhost');\n const componentId = requestUrl.searchParams.get('c');\n\n if (!componentId) {\n return;\n }\n\n const result = fileEmitter(\n normalizePath(\n resolve(\n process.cwd(),\n decodeURIComponent(componentId).split('@')[0],\n ),\n ),\n );\n\n return result?.hmrUpdateCode || '';\n }\n\n return;\n },\n };\n}\n"],"mappings":";;;AAMA,IAAM,2BAA2B;AACjC,IAAM,cAAc;AAEpB,SAAgB,iBAAiB,EAC/B,YACA,eAIS;AACT,QAAO;EACL,MAAM;EACN,OAAO;EACP,gBAAgB,QAAuB;GACrC,MAAM,6BAAqD,OACzD,KACA,KACA,SACG;AACH,QAAI,IAAI,QAAQ,KAAA,KAAa,IAAI,cAC/B;AAGF,QAAI,CAAC,IAAI,IAAI,SAAS,yBAAyB,EAAE;AAC/C,WAAM;AAEN;;IAIF,MAAM,cADa,IAAI,IAAI,IAAI,KAAK,mBAAmB,CACxB,aAAa,IAAI,IAAI;AAEpD,QAAI,CAAC,aAAa;AAChB,SAAI,aAAa;AACjB,SAAI,KAAK;AAET;;IAGF,MAAM,CAAC,UAAU,mBAAmB,YAAY,CAAC,MAAM,IAAI;IAC3D,MAAM,aAAa,cAAc,QAAQ,QAAQ,KAAK,EAAE,OAAO,CAAC;AAMhE,QAAI,EAJF,CAAC,CAAC,OAAO,YAAY,cAAc,WAAW,EAC1C,6BAA6B,WAAW,IAAI,WAAW,GAG3C;AAChB,SAAI,UAAU,gBAAgB,kBAAkB;AAChD,SAAI,UAAU,iBAAiB,WAAW;AAC1C,SAAI,IAAI,GAAG;AACX;;IAGF,MAAM,SAAS,YAAY,WAAW;AACtC,QAAI,UAAU,gBAAgB,kBAAkB;AAChD,QAAI,UAAU,iBAAiB,WAAW;AAC1C,QAAI,IAAI,GAAG,QAAQ,iBAAiB,KAAK;;AAG3C,UAAO,YAAY,IAAI,2BAA2B;;EAEpD,UAAU,IAAI,WAAW,SAAS;AAChC,OACE,SAAS,OACT,GAAG,WAAW,YAAY,IAC1B,GAAG,SAAS,yBAAyB,CAErC,QAAO,KAAK;;EAKhB,KAAK,IAAI,SAAS;AAChB,OAAI,SAAS,OAAO,GAAG,SAAS,yBAAyB,EAAE;IAEzD,MAAM,cADa,IAAI,IAAI,GAAG,MAAM,EAAE,EAAE,mBAAmB,CAC5B,aAAa,IAAI,IAAI;AAEpD,QAAI,CAAC,YACH;AAYF,WATe,YACb,cACE,QACE,QAAQ,KAAK,EACb,mBAAmB,YAAY,CAAC,MAAM,IAAI,CAAC,GAC5C,CACF,CACF,EAEc,iBAAiB;;;EAKrC"}
1
+ {"version":3,"file":"live-reload-plugin.js","names":[],"sources":["../../../src/lib/live-reload-plugin.ts"],"sourcesContent":["import { resolve } from 'node:path';\nimport { ServerResponse } from 'node:http';\nimport { Connect, normalizePath, Plugin, ViteDevServer } from 'vite';\n\nimport { EmitFileResult } from './models.js';\nimport { debugHmr } from './utils/debug.js';\n\nconst ANGULAR_COMPONENT_PREFIX = '/@ng/component';\nconst FILE_PREFIX = 'file:';\n\nexport function liveReloadPlugin({\n classNames,\n fileEmitter,\n}: {\n classNames: Map<string, string>;\n fileEmitter: (file: string) => EmitFileResult | undefined;\n}): Plugin {\n return {\n name: 'analogjs-live-reload-plugin',\n apply: 'serve',\n configureServer(server: ViteDevServer) {\n const angularComponentMiddleware: Connect.HandleFunction = async (\n req: Connect.IncomingMessage,\n res: ServerResponse<Connect.IncomingMessage>,\n next: Connect.NextFunction,\n ) => {\n if (req.url === undefined || res.writableEnded) {\n return;\n }\n\n if (!req.url.includes(ANGULAR_COMPONENT_PREFIX)) {\n next();\n\n return;\n }\n\n const requestUrl = new URL(req.url, 'http://localhost');\n const componentId = requestUrl.searchParams.get('c');\n\n if (!componentId) {\n res.statusCode = 400;\n res.end();\n\n return;\n }\n\n const [fileId] = decodeURIComponent(componentId).split('@');\n const resolvedId = normalizePath(resolve(process.cwd(), fileId));\n const invalidated =\n !!server.moduleGraph.getModuleById(resolvedId)\n ?.lastInvalidationTimestamp && classNames.get(resolvedId);\n\n // don't send an HMR update until the file has been invalidated\n if (!invalidated) {\n debugHmr('middleware: skipped (not invalidated)', { resolvedId });\n res.setHeader('Content-Type', 'text/javascript');\n res.setHeader('Cache-Control', 'no-cache');\n res.end('');\n return;\n }\n\n const result = fileEmitter(resolvedId);\n debugHmr('middleware: served component update', {\n resolvedId,\n hasCode: !!result?.hmrUpdateCode,\n });\n res.setHeader('Content-Type', 'text/javascript');\n res.setHeader('Cache-Control', 'no-cache');\n res.end(`${result?.hmrUpdateCode || ''}`);\n };\n\n server.middlewares.use(angularComponentMiddleware);\n },\n resolveId(id, _importer, options) {\n if (\n options?.ssr &&\n id.startsWith(FILE_PREFIX) &&\n id.includes(ANGULAR_COMPONENT_PREFIX)\n ) {\n return `\\0${id}`;\n }\n\n return undefined;\n },\n load(id, options) {\n if (options?.ssr && id.includes(ANGULAR_COMPONENT_PREFIX)) {\n const requestUrl = new URL(id.slice(1), 'http://localhost');\n const componentId = requestUrl.searchParams.get('c');\n\n if (!componentId) {\n return;\n }\n\n const result = fileEmitter(\n normalizePath(\n resolve(\n process.cwd(),\n decodeURIComponent(componentId).split('@')[0],\n ),\n ),\n );\n\n return result?.hmrUpdateCode || '';\n }\n\n return;\n },\n };\n}\n"],"mappings":";;;;AAOA,IAAM,2BAA2B;AACjC,IAAM,cAAc;AAEpB,SAAgB,iBAAiB,EAC/B,YACA,eAIS;AACT,QAAO;EACL,MAAM;EACN,OAAO;EACP,gBAAgB,QAAuB;GACrC,MAAM,6BAAqD,OACzD,KACA,KACA,SACG;AACH,QAAI,IAAI,QAAQ,KAAA,KAAa,IAAI,cAC/B;AAGF,QAAI,CAAC,IAAI,IAAI,SAAS,yBAAyB,EAAE;AAC/C,WAAM;AAEN;;IAIF,MAAM,cADa,IAAI,IAAI,IAAI,KAAK,mBAAmB,CACxB,aAAa,IAAI,IAAI;AAEpD,QAAI,CAAC,aAAa;AAChB,SAAI,aAAa;AACjB,SAAI,KAAK;AAET;;IAGF,MAAM,CAAC,UAAU,mBAAmB,YAAY,CAAC,MAAM,IAAI;IAC3D,MAAM,aAAa,cAAc,QAAQ,QAAQ,KAAK,EAAE,OAAO,CAAC;AAMhE,QAAI,EAJF,CAAC,CAAC,OAAO,YAAY,cAAc,WAAW,EAC1C,6BAA6B,WAAW,IAAI,WAAW,GAG3C;AAChB,cAAS,yCAAyC,EAAE,YAAY,CAAC;AACjE,SAAI,UAAU,gBAAgB,kBAAkB;AAChD,SAAI,UAAU,iBAAiB,WAAW;AAC1C,SAAI,IAAI,GAAG;AACX;;IAGF,MAAM,SAAS,YAAY,WAAW;AACtC,aAAS,uCAAuC;KAC9C;KACA,SAAS,CAAC,CAAC,QAAQ;KACpB,CAAC;AACF,QAAI,UAAU,gBAAgB,kBAAkB;AAChD,QAAI,UAAU,iBAAiB,WAAW;AAC1C,QAAI,IAAI,GAAG,QAAQ,iBAAiB,KAAK;;AAG3C,UAAO,YAAY,IAAI,2BAA2B;;EAEpD,UAAU,IAAI,WAAW,SAAS;AAChC,OACE,SAAS,OACT,GAAG,WAAW,YAAY,IAC1B,GAAG,SAAS,yBAAyB,CAErC,QAAO,KAAK;;EAKhB,KAAK,IAAI,SAAS;AAChB,OAAI,SAAS,OAAO,GAAG,SAAS,yBAAyB,EAAE;IAEzD,MAAM,cADa,IAAI,IAAI,GAAG,MAAM,EAAE,EAAE,mBAAmB,CAC5B,aAAa,IAAI,IAAI;AAEpD,QAAI,CAAC,YACH;AAYF,WATe,YACb,cACE,QACE,QAAQ,KAAK,EACb,mBAAmB,YAAY,CAAC,MAAM,IAAI,CAAC,GAC5C,CACF,CACF,EAEc,iBAAiB;;;EAKrC"}
@@ -0,0 +1,39 @@
1
+ export declare const debugHmr: unknown;
2
+ export declare const debugStyles: unknown;
3
+ export declare const debugCompiler: unknown;
4
+ export declare const debugCompilationApi: unknown;
5
+ export declare const debugTailwind: unknown;
6
+ export type DebugScope = "analog:angular:*" | "analog:angular:hmr" | "analog:angular:styles" | "analog:angular:compiler" | "analog:angular:compilation-api" | "analog:angular:tailwind" | (string & {});
7
+ export type DebugMode = "build" | "dev";
8
+ export interface DebugModeOptions {
9
+ scopes?: boolean | DebugScope[];
10
+ mode?: DebugMode;
11
+ }
12
+ export type DebugOption = boolean | DebugScope[] | DebugModeOptions | DebugModeOptions[];
13
+ /**
14
+ * Translates the user-facing `debug` plugin option into obug namespace
15
+ * activations. Called once during the Vite plugin config hook.
16
+ *
17
+ * Additive — does not replace namespaces already enabled via the DEBUG
18
+ * env var or localStorage.debug.
19
+ *
20
+ * When an object with `mode` is provided, activation is deferred until
21
+ * {@link activateDeferredDebug} is called from a Vite config hook.
22
+ *
23
+ * Accepts an array of objects to enable different scopes per command:
24
+ * ```ts
25
+ * debug: [
26
+ * { scopes: ['analog:angular:hmr'], mode: 'dev' },
27
+ * { scopes: ['analog:angular:compiler'], mode: 'build' },
28
+ * ]
29
+ * ```
30
+ */
31
+ export declare function applyDebugOption(debug: DebugOption | undefined): void;
32
+ /**
33
+ * Called from a Vite config hook once `command` is known.
34
+ * Maps Vite's `'serve'` to `'dev'` and `'build'` to `'build'`.
35
+ * Idempotent — clears pending state after the first call.
36
+ */
37
+ export declare function activateDeferredDebug(command: "build" | "serve"): void;
38
+ /** @internal test-only reset */
39
+ export declare function _resetDeferredDebug(): void;
@@ -0,0 +1,74 @@
1
+ import { createDebug, enable } from "obug";
2
+ //#region packages/vite-plugin-angular/src/lib/utils/debug.ts
3
+ var debugHmr = createDebug("analog:angular:hmr");
4
+ var debugStyles = createDebug("analog:angular:styles");
5
+ var debugCompiler = createDebug("analog:angular:compiler");
6
+ var debugCompilationApi = createDebug("analog:angular:compilation-api");
7
+ var debugTailwind = createDebug("analog:angular:tailwind");
8
+ var pendingDebug = [];
9
+ function resolveNamespaces(scopes, fallback) {
10
+ if (scopes === true || scopes === void 0) return fallback;
11
+ if (Array.isArray(scopes) && scopes.length) return scopes.join(",");
12
+ return null;
13
+ }
14
+ function applyEntry(entry, fallback) {
15
+ if (!entry.mode) {
16
+ const ns = resolveNamespaces(entry.scopes ?? true, fallback);
17
+ if (ns) enable(ns);
18
+ } else pendingDebug.push(entry);
19
+ }
20
+ /**
21
+ * Translates the user-facing `debug` plugin option into obug namespace
22
+ * activations. Called once during the Vite plugin config hook.
23
+ *
24
+ * Additive — does not replace namespaces already enabled via the DEBUG
25
+ * env var or localStorage.debug.
26
+ *
27
+ * When an object with `mode` is provided, activation is deferred until
28
+ * {@link activateDeferredDebug} is called from a Vite config hook.
29
+ *
30
+ * Accepts an array of objects to enable different scopes per command:
31
+ * ```ts
32
+ * debug: [
33
+ * { scopes: ['analog:angular:hmr'], mode: 'dev' },
34
+ * { scopes: ['analog:angular:compiler'], mode: 'build' },
35
+ * ]
36
+ * ```
37
+ */
38
+ function applyDebugOption(debug) {
39
+ if (debug == null || debug === false) return;
40
+ if (typeof debug === "boolean") {
41
+ const ns = resolveNamespaces(debug, "analog:angular:*");
42
+ if (ns) enable(ns);
43
+ return;
44
+ }
45
+ if (Array.isArray(debug)) {
46
+ if (debug.length === 0) return;
47
+ if (typeof debug[0] === "string") {
48
+ const ns = debug.join(",");
49
+ if (ns) enable(ns);
50
+ return;
51
+ }
52
+ for (const entry of debug) applyEntry(entry, "analog:angular:*");
53
+ return;
54
+ }
55
+ applyEntry(debug, "analog:angular:*");
56
+ }
57
+ /**
58
+ * Called from a Vite config hook once `command` is known.
59
+ * Maps Vite's `'serve'` to `'dev'` and `'build'` to `'build'`.
60
+ * Idempotent — clears pending state after the first call.
61
+ */
62
+ function activateDeferredDebug(command) {
63
+ if (pendingDebug.length === 0) return;
64
+ const currentMode = command === "serve" ? "dev" : "build";
65
+ for (const entry of pendingDebug) if (entry.mode === currentMode) {
66
+ const ns = resolveNamespaces(entry.scopes ?? true, "analog:angular:*");
67
+ if (ns) enable(ns);
68
+ }
69
+ pendingDebug = [];
70
+ }
71
+ //#endregion
72
+ export { activateDeferredDebug, applyDebugOption, debugCompilationApi, debugCompiler, debugHmr, debugStyles, debugTailwind };
73
+
74
+ //# sourceMappingURL=debug.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"debug.js","names":[],"sources":["../../../../src/lib/utils/debug.ts"],"sourcesContent":["import { createDebug, enable } from 'obug';\n\nexport const debugHmr = createDebug('analog:angular:hmr');\nexport const debugStyles = createDebug('analog:angular:styles');\nexport const debugCompiler = createDebug('analog:angular:compiler');\nexport const debugCompilationApi = createDebug(\n 'analog:angular:compilation-api',\n);\nexport const debugTailwind = createDebug('analog:angular:tailwind');\n\nexport type DebugScope =\n | 'analog:angular:*'\n | 'analog:angular:hmr'\n | 'analog:angular:styles'\n | 'analog:angular:compiler'\n | 'analog:angular:compilation-api'\n | 'analog:angular:tailwind'\n | (string & {});\n\nexport type DebugMode = 'build' | 'dev';\n\nexport interface DebugModeOptions {\n scopes?: boolean | DebugScope[];\n mode?: DebugMode;\n}\n\nexport type DebugOption =\n | boolean\n | DebugScope[]\n | DebugModeOptions\n | DebugModeOptions[];\n\nlet pendingDebug: DebugModeOptions[] = [];\n\nfunction resolveNamespaces(\n scopes: boolean | string[] | undefined,\n fallback: string,\n): string | null {\n if (scopes === true || scopes === undefined) return fallback;\n if (Array.isArray(scopes) && scopes.length) return scopes.join(',');\n return null;\n}\n\nfunction applyEntry(entry: DebugModeOptions, fallback: string): void {\n if (!entry.mode) {\n const ns = resolveNamespaces(entry.scopes ?? true, fallback);\n if (ns) enable(ns);\n } else {\n pendingDebug.push(entry);\n }\n}\n\n/**\n * Translates the user-facing `debug` plugin option into obug namespace\n * activations. Called once during the Vite plugin config hook.\n *\n * Additive — does not replace namespaces already enabled via the DEBUG\n * env var or localStorage.debug.\n *\n * When an object with `mode` is provided, activation is deferred until\n * {@link activateDeferredDebug} is called from a Vite config hook.\n *\n * Accepts an array of objects to enable different scopes per command:\n * ```ts\n * debug: [\n * { scopes: ['analog:angular:hmr'], mode: 'dev' },\n * { scopes: ['analog:angular:compiler'], mode: 'build' },\n * ]\n * ```\n */\nexport function applyDebugOption(debug: DebugOption | undefined): void {\n if (debug == null || debug === false) return;\n\n if (typeof debug === 'boolean') {\n const ns = resolveNamespaces(debug, 'analog:angular:*');\n if (ns) enable(ns);\n return;\n }\n\n if (Array.isArray(debug)) {\n if (debug.length === 0) return;\n\n if (typeof debug[0] === 'string') {\n const ns = (debug as string[]).join(',');\n if (ns) enable(ns);\n return;\n }\n\n for (const entry of debug as DebugModeOptions[]) {\n applyEntry(entry, 'analog:angular:*');\n }\n return;\n }\n\n applyEntry(debug, 'analog:angular:*');\n}\n\n/**\n * Called from a Vite config hook once `command` is known.\n * Maps Vite's `'serve'` to `'dev'` and `'build'` to `'build'`.\n * Idempotent — clears pending state after the first call.\n */\nexport function activateDeferredDebug(command: 'build' | 'serve'): void {\n if (pendingDebug.length === 0) return;\n\n const currentMode = command === 'serve' ? 'dev' : 'build';\n\n for (const entry of pendingDebug) {\n if (entry.mode === currentMode) {\n const ns = resolveNamespaces(entry.scopes ?? true, 'analog:angular:*');\n if (ns) enable(ns);\n }\n }\n\n pendingDebug = [];\n}\n\n/** @internal test-only reset */\nexport function _resetDeferredDebug(): void {\n pendingDebug = [];\n}\n"],"mappings":";;AAEA,IAAa,WAAW,YAAY,qBAAqB;AACzD,IAAa,cAAc,YAAY,wBAAwB;AAC/D,IAAa,gBAAgB,YAAY,0BAA0B;AACnE,IAAa,sBAAsB,YACjC,iCACD;AACD,IAAa,gBAAgB,YAAY,0BAA0B;AAwBnE,IAAI,eAAmC,EAAE;AAEzC,SAAS,kBACP,QACA,UACe;AACf,KAAI,WAAW,QAAQ,WAAW,KAAA,EAAW,QAAO;AACpD,KAAI,MAAM,QAAQ,OAAO,IAAI,OAAO,OAAQ,QAAO,OAAO,KAAK,IAAI;AACnE,QAAO;;AAGT,SAAS,WAAW,OAAyB,UAAwB;AACnE,KAAI,CAAC,MAAM,MAAM;EACf,MAAM,KAAK,kBAAkB,MAAM,UAAU,MAAM,SAAS;AAC5D,MAAI,GAAI,QAAO,GAAG;OAElB,cAAa,KAAK,MAAM;;;;;;;;;;;;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