@analogjs/vite-plugin-angular 3.0.0-beta.52 → 3.0.0-beta.54

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-beta.52",
3
+ "version": "3.0.0-beta.54",
4
4
  "description": "Vite Plugin for Angular",
5
5
  "type": "module",
6
6
  "keywords": [
@@ -9,8 +9,8 @@ import { releaseCssPreprocessorWorkers } from "./utils/css-preprocessor-workers.
9
9
  import { loadAngularVirtualModule, resolveAngularVirtualId } from "./virtual-modules-plugin.js";
10
10
  import { ComponentScanner } from "./component-scanner.js";
11
11
  import { findHmrComponentUpdates } from "./utils/hmr-component-updates.js";
12
+ import { canonicalPath, createNgpHostFs, fromWasmPath, toWasmPath } from "./utils/ngp-host-fs.js";
12
13
  import { LspTypeChecker } from "./utils/lsp-type-checker.js";
13
- import { canonicalPath, createNgpHostFs } from "./utils/ngp-host-fs.js";
14
14
  import { existsSync, promises, realpathSync } from "node:fs";
15
15
  import { createRequire } from "node:module";
16
16
  import { dirname, resolve } from "node:path";
@@ -81,6 +81,8 @@ function ngpCompilePlugin(optionsOrCtx) {
81
81
  let compiler;
82
82
  let typeChecker;
83
83
  let api;
84
+ let toAnalyzerPath = (path) => path;
85
+ let fromAnalyzerPath = vite.normalizePath;
84
86
  const filesByPath = /* @__PURE__ */ new Map();
85
87
  const chunkContexts = /* @__PURE__ */ new Map();
86
88
  const output = /* @__PURE__ */ new Map();
@@ -212,7 +214,10 @@ function ngpCompilePlugin(optionsOrCtx) {
212
214
  }));
213
215
  if (updates.length === 0) return;
214
216
  for (const { filePath, content } of updates) analyzed.set(filePath, content);
215
- await enqueueIndex(() => analyzer.updateFileContent(updates));
217
+ await enqueueIndex(() => analyzer.updateFileContent(updates.map(({ filePath, content }) => ({
218
+ filePath: toAnalyzerPath(filePath),
219
+ content
220
+ }))));
216
221
  }
217
222
  /** Reads a source file, or `undefined` if it was removed. */
218
223
  function readSource(file) {
@@ -229,7 +234,7 @@ function ngpCompilePlugin(optionsOrCtx) {
229
234
  if (!sourceModule) return;
230
235
  analyzed.set(programFile, sourceModule.lowered.code);
231
236
  await enqueueIndex(() => analyzer.invalidateFiles([{
232
- filePath: programFile,
237
+ filePath: toAnalyzerPath(programFile),
233
238
  updateType: FILE_CREATED
234
239
  }]));
235
240
  }
@@ -240,7 +245,7 @@ function ngpCompilePlugin(optionsOrCtx) {
240
245
  analyzed.delete(programFile);
241
246
  if (!sourceModules.delete(programFile)) return;
242
247
  await enqueueIndex(() => analyzer.invalidateFiles([{
243
- filePath: programFile,
248
+ filePath: toAnalyzerPath(programFile),
244
249
  updateType: FILE_DELETED
245
250
  }]));
246
251
  }
@@ -273,7 +278,8 @@ function ngpCompilePlugin(optionsOrCtx) {
273
278
  hasEmitted: compilerApi.hasEmitted
274
279
  });
275
280
  async function prepareResources(file, watch) {
276
- watch(file.filePath);
281
+ const hostFilePath = fromAnalyzerPath(file.filePath);
282
+ watch(hostFilePath);
277
283
  const activeConfig = sharedCtx?.resolvedConfig ?? resolvedConfig;
278
284
  const activeStylePreprocessor = sharedCtx?.stylePreprocessor ?? stylePreprocessor;
279
285
  return {
@@ -281,12 +287,12 @@ function ngpCompilePlugin(optionsOrCtx) {
281
287
  classes: await Promise.all(file.classes.map(async (metadata, classIndex) => {
282
288
  const component = metadata.component;
283
289
  if (!component) return metadata;
284
- if (component.templateUrl) watch(component.templateUrl.resolvedPath);
285
- for (const style of component.styleUrls ?? []) watch(style.resolvedPath);
290
+ if (component.templateUrl) watch(fromAnalyzerPath(component.templateUrl.resolvedPath));
291
+ for (const style of component.styleUrls ?? []) watch(fromAnalyzerPath(style.resolvedPath));
286
292
  const preprocess = async (content, path, order, inline) => {
287
293
  const preprocessed = preprocessStylesheet(content, path, activeStylePreprocessor, {
288
294
  filename: path,
289
- containingFile: file.filePath,
295
+ containingFile: hostFilePath,
290
296
  resourceFile: inline ? void 0 : path,
291
297
  className: metadata.className,
292
298
  order,
@@ -300,8 +306,8 @@ function ngpCompilePlugin(optionsOrCtx) {
300
306
  ...metadata,
301
307
  component: {
302
308
  ...component,
303
- styles: component.styles && await Promise.all(component.styles.map((style, index) => preprocess(style, `${file.filePath}.inline-${classIndex}-${index}.${options.inlineStylesExtension}`, index, true))),
304
- stylesFromUrls: component.stylesFromUrls && await Promise.all(component.stylesFromUrls.map((style, index) => preprocess(style, component.styleUrls[index].resolvedPath, index, false)))
309
+ styles: component.styles && await Promise.all(component.styles.map((style, index) => preprocess(style, `${hostFilePath}.inline-${classIndex}-${index}.${options.inlineStylesExtension}`, index, true))),
310
+ stylesFromUrls: component.stylesFromUrls && await Promise.all(component.stylesFromUrls.map((style, index) => preprocess(style, fromAnalyzerPath(component.styleUrls[index].resolvedPath), index, false)))
305
311
  }
306
312
  };
307
313
  }))
@@ -311,7 +317,7 @@ function ngpCompilePlugin(optionsOrCtx) {
311
317
  if (update) {
312
318
  const invalidated = await update();
313
319
  for (const filePath of invalidated) {
314
- output.delete(vite.normalizePath(filePath));
320
+ output.delete(fromAnalyzerPath(filePath));
315
321
  compiler.fileCache.delete(filePath);
316
322
  }
317
323
  chunkContexts.clear();
@@ -330,7 +336,7 @@ function ngpCompilePlugin(optionsOrCtx) {
330
336
  const chunks = update ? compiler.analyzeOptimizedDelta() : compiler.analyzeOptimized();
331
337
  for await (const chunk of chunks) {
332
338
  for (const file of chunk.files) {
333
- const normPath = vite.normalizePath(file.filePath);
339
+ const normPath = fromAnalyzerPath(file.filePath);
334
340
  filesByPath.set(normPath, {
335
341
  file,
336
342
  chunk
@@ -339,7 +345,7 @@ function ngpCompilePlugin(optionsOrCtx) {
339
345
  compiler.fileCache.delete(file.filePath);
340
346
  }
341
347
  for (const removed of chunk.removedFiles ?? []) {
342
- const normPath = vite.normalizePath(removed);
348
+ const normPath = fromAnalyzerPath(removed);
343
349
  filesByPath.delete(normPath);
344
350
  output.delete(normPath);
345
351
  }
@@ -395,7 +401,7 @@ function ngpCompilePlugin(optionsOrCtx) {
395
401
  const { file, content, result } = await processFile(normPath, compiler, watch);
396
402
  const errors = [...file.diagnostics ?? [], ...result.diagnostics ?? []].filter((diagnostic) => diagnostic.category === 1);
397
403
  if (errors.length) throw new Error(`${sourceFileOf(normPath)}: ${errors.map((error) => error.messageText).join("\n")}`);
398
- if (options.disableTypeChecking !== true) await checkTypes(file.filePath, content, result.tcb?.code);
404
+ if (options.disableTypeChecking !== true) await checkTypes(fromAnalyzerPath(file.filePath), content, result.tcb?.code);
399
405
  return result;
400
406
  })();
401
407
  output.set(normPath, task);
@@ -430,13 +436,12 @@ function ngpCompilePlugin(optionsOrCtx) {
430
436
  const codes = await Promise.all(updates.map(({ file, className }) => emitHmrUpdate(file, className)));
431
437
  if (codes.some((code) => !code)) return false;
432
438
  updates.forEach(({ file, className }, index) => {
433
- const sourceFile = sourceModules.get(file)?.sourceFile;
434
- const moduleFile = sourceFile ?? file;
439
+ const moduleFile = sourceModules.get(file)?.sourceFile ?? file;
435
440
  hmrUpdateCode.set(`${moduleFile}@${className}`, codes[index]);
436
441
  componentUpdates.classNames.set(moduleFile, className);
437
442
  server.moduleGraph.getModulesByFile(moduleFile)?.forEach((mod) => server.moduleGraph.invalidateModule(mod));
438
443
  server.ws.send("angular:component-update", {
439
- id: encodeURIComponent(`${sourceFile ?? filesByPath.get(file).file.filePath}@${className}`),
444
+ id: encodeURIComponent(`${moduleFile}@${className}`),
440
445
  timestamp: Date.now()
441
446
  });
442
447
  });
@@ -524,12 +529,15 @@ function ngpCompilePlugin(optionsOrCtx) {
524
529
  const tsconfig = resolveTsConfigPath();
525
530
  const hasSourceFormats = sourceFormats.length > 0;
526
531
  const ngp = await loadNgp(tsconfig, hasSourceFormats);
532
+ const isWasm = ngp.analyzerOptions.backend === "wasm";
533
+ toAnalyzerPath = isWasm ? toWasmPath : (path) => path;
534
+ fromAnalyzerPath = isWasm ? fromWasmPath : vite.normalizePath;
527
535
  api = ngp.api;
528
536
  if (hasSourceFormats) await lowerSourceModules(dirname(tsconfig), (specifier, importer) => this.resolve(specifier, importer, { skipSelf: true }));
529
- analyzer = await api.createAnalyzer(tsconfig, {
537
+ analyzer = await api.createAnalyzer(toAnalyzerPath(tsconfig), {
530
538
  ...ngp.analyzerOptions,
531
539
  enableHmr: hmr,
532
- hostFs: hasSourceFormats ? createNgpHostFs((path) => sourceModules.get(path)?.lowered.code) : void 0
540
+ hostFs: hasSourceFormats || isWasm ? createNgpHostFs(hasSourceFormats ? (path) => sourceModules.get(path)?.lowered.code : void 0) : void 0
533
541
  });
534
542
  pending = indexChunks();
535
543
  }
@@ -585,14 +593,17 @@ function ngpCompilePlugin(optionsOrCtx) {
585
593
  if (filesByPath.has(compiledFile) && sources.get(compiledFile) !== compiledCode) {
586
594
  if (lowered) analyzed.set(compiledFile, compiledCode);
587
595
  await enqueueIndex(() => analyzer.updateFileContent([{
588
- filePath: compiledFile,
596
+ filePath: toAnalyzerPath(compiledFile),
589
597
  content: compiledCode
590
598
  }]));
591
599
  result = await compileFile(compiledFile, watch);
592
600
  } else if (!result && lowered) this.error(`${filePath} is not part of the TypeScript program of ${resolveTsConfigPath()}. Import it, or add it to the tsconfig's \`include\`.`);
593
601
  else if (!result && options.disableTypeChecking !== true) await checkTypes(filePath, code);
594
602
  let source = result?.magicString.toString() ?? code;
595
- if (lowered && result) source = source.replaceAll(encodeURIComponent(`${filesByPath.get(compiledFile).file.filePath}@`), encodeURIComponent(`${filePath}@`));
603
+ if (result) {
604
+ const analyzerFile = filesByPath.get(compiledFile).file.filePath;
605
+ if (analyzerFile !== filePath) source = source.replaceAll(encodeURIComponent(`${analyzerFile}@`), encodeURIComponent(`${filePath}@`));
606
+ }
596
607
  const map = result?.magicString.generateMap({
597
608
  source: compiledFile,
598
609
  includeContent: true,
@@ -617,7 +628,7 @@ function ngpCompilePlugin(optionsOrCtx) {
617
628
  const lowered = programFile ? sourceModules.get(programFile)?.lowered : void 0;
618
629
  const componentUpdates = hmr && !lowered?.error && relowered.every((file) => file === programFile) ? await findComponentUpdates(programFile ?? normPath, lowered ? () => lowered.code : ctx.read) : [];
619
630
  if (!programFile) await enqueueIndex(() => analyzer.invalidateFiles([{
620
- filePath: ctx.file,
631
+ filePath: toAnalyzerPath(ctx.file),
621
632
  updateType: FILE_CHANGED
622
633
  }]));
623
634
  await syncProgramFiles();
@@ -1 +1 @@
1
- {"version":3,"file":"ngp-compile-plugin.js","names":[],"sources":["../../../src/lib/ngp-compile-plugin.ts"],"sourcesContent":["import * as compilerCli from '@angular/compiler-cli';\nimport { existsSync, promises as fsPromises, realpathSync } from 'node:fs';\nimport { createRequire } from 'node:module';\nimport { dirname, resolve } from 'node:path';\nimport { fileURLToPath, pathToFileURL } from 'node:url';\nimport type MagicString from 'magic-string';\nimport { glob } from 'tinyglobby';\nimport * as vite from 'vite';\nimport {\n discoverAnalogIntegrations,\n type ComponentRegistryEntries,\n type TransformFilter,\n} from './analog-plugin-interop.js';\nimport {\n createAngularBuildContext,\n isAngularBuildContext,\n type AngularBuildContext,\n type AngularBuildContextOptions,\n} from './angular-build-context.js';\nimport { ComponentScanner } from './component-scanner.js';\nimport type { FastCompileResolve } from './fast-compile-api.js';\nimport type { FastCompilePluginOptions } from './fast-compile-plugin.js';\nimport type {\n NgpCompileApi,\n NgpLoweredModule,\n NgpSourceFormat,\n} from './ngp-compile-api.js';\nimport type { StylePreprocessor } from './style-preprocessor.js';\nimport { preprocessStylesheet } from './stylesheet-registry.js';\nimport { isIgnoredHmrFile } from './utils/compilation-shared.js';\nimport {\n createDepOptimizerConfig,\n getTsConfigPath,\n isProdMode,\n TS_EXT_REGEX,\n type TsConfigResolutionContext,\n} from './utils/plugin-config.js';\nimport { releaseCssPreprocessorWorkers } from './utils/css-preprocessor-workers.js';\nimport { angularFullVersion } from './utils/devkit.js';\nimport { findHmrComponentUpdates } from './utils/hmr-component-updates.js';\nimport {\n LspTypeChecker,\n type FileChangeType,\n type SourceLocation,\n} from './utils/lsp-type-checker.js';\nimport {\n canonicalPath,\n createNgpHostFs,\n type NgpHostFs,\n} from './utils/ngp-host-fs.js';\nimport { isRolldown } from './utils/rolldown.js';\nimport type { ComponentUpdates } from './live-reload-plugin.js';\nimport {\n loadAngularVirtualModule,\n resolveAngularVirtualId,\n} from './virtual-modules-plugin.js';\n\n// The unpublished NGP API is loaded at runtime. Model only the surface we use.\ninterface NgpDiagnostic {\n category: number;\n messageText: string;\n}\n\ninterface NgpFile {\n filePath: string;\n diagnostics?: NgpDiagnostic[];\n classes: {\n className?: string;\n component?: {\n templateUrl?: { resolvedPath: string };\n styleUrls?: { resolvedPath: string }[];\n stylesFromUrls?: string[];\n styles?: string[];\n };\n }[];\n}\n\ninterface NgpChunk {\n files: NgpFile[];\n removedFiles?: string[];\n}\n\ninterface NgpResult {\n magicString: MagicString;\n diagnostics?: NgpDiagnostic[];\n tcb?: { code: string } | null;\n hmrUpdateModule?: string | null;\n}\n\ninterface NgpAnalyzer {\n getFileContent(path: string): Promise<string>;\n updateFileContent(\n updates: { filePath: string; content: string }[],\n ): Promise<string[]>;\n invalidateFiles(\n updates: { filePath: string; updateType: number }[],\n ): Promise<string[]>;\n close(): void;\n}\n\ninterface NgpCompiler {\n // Parsed templates by file, cleared by NGP's own update methods\n fileCache: Map<string, unknown>;\n analyzeOptimized(): AsyncIterable<NgpChunk>;\n analyzeOptimizedDelta(): AsyncIterable<NgpChunk>;\n prepareChunk(chunk: NgpChunk): Promise<unknown>;\n processFile(\n path: string,\n content: string,\n ...args: [undefined, NgpFile, unknown] | [NgpFile, unknown]\n ): Promise<NgpResult>;\n}\n\ninterface ComponentUpdate {\n file: string;\n className: string;\n}\n\ninterface NgpAnalyzerOptions {\n nativeBinding?: string;\n backend?: 'wasm';\n wasmBinding?: string;\n enableHmr?: boolean;\n hostFs?: NgpHostFs;\n}\n\n/** NGP's `FileUpdateType`. */\nconst FILE_CREATED = 0;\nconst FILE_DELETED = 1;\nconst FILE_CHANGED = 2;\n\n/** A module of a registered source format, lowered to its program file. */\ninterface SourceModule {\n sourceFile: string;\n /** The source it was lowered from. */\n source: string;\n format: NgpSourceFormat;\n lowered: NgpLoweredModule;\n}\n\ninterface NgpApi {\n createAnalyzer(\n tsconfig: string,\n options: NgpAnalyzerOptions,\n ): Promise<NgpAnalyzer>;\n HybridCompiler: new (\n analyzer: NgpAnalyzer,\n options: Record<string, unknown> & {\n optimize: boolean;\n enableHmr: boolean;\n },\n ) => NgpCompiler;\n buildTypeCheckingConfig(options: Record<string, unknown>): unknown;\n}\n\nfunction isFastCompileOptions(\n value: unknown,\n): value is FastCompilePluginOptions {\n return (\n typeof value === 'object' &&\n value !== null &&\n !isAngularBuildContext(value) &&\n 'tsconfigGetter' in value &&\n typeof (value as FastCompilePluginOptions).tsconfigGetter === 'function'\n );\n}\n\n// Interim NGP build bundled with this package until @angular/ngp is published\nconst BUNDLED_NGP = new URL('../../ngp/', import.meta.url);\n\n/**\n * @param needsHostFs Whether source formats are registered, which only the\n * WebAssembly backend can read through `hostFs`.\n */\nasync function loadNgp(\n tsconfig: string,\n needsHostFs: boolean,\n): Promise<{ api: NgpApi; analyzerOptions: NgpAnalyzerOptions }> {\n const nativeBinding = process.env['ANALOG_NGP_NATIVE_BINDING'];\n if (nativeBinding && needsHostFs) {\n throw new Error(\n \"[@analogjs/vite-plugin-angular]: Source formats such as TSRX can't be compiled with a native NGP analyzer build. Unset ANALOG_NGP_NATIVE_BINDING to use NGP's default WebAssembly analyzer.\",\n );\n }\n let modulePath = process.env['ANALOG_NGP_COMPILER'];\n if (!modulePath) {\n try {\n modulePath = createRequire(tsconfig).resolve('@angular/ngp');\n } catch {\n if (angularFullVersion < 220200) {\n throw new Error(\n \"[@analogjs/vite-plugin-angular]: compilation: 'ngp' requires Angular v22.2 or later.\",\n );\n }\n return {\n api: await import(new URL('api.mjs', BUNDLED_NGP).href),\n analyzerOptions: nativeBinding\n ? { nativeBinding }\n : {\n backend: 'wasm',\n wasmBinding: fileURLToPath(\n new URL('ng_analyze.cjs', BUNDLED_NGP),\n ),\n },\n };\n }\n }\n return {\n api: await import(pathToFileURL(resolve(modulePath)).href),\n analyzerOptions: nativeBinding\n ? { nativeBinding }\n : needsHostFs\n ? { backend: 'wasm' }\n : {},\n };\n}\n\nfunction transpile(\n source: string,\n filePath: string,\n map?: Parameters<typeof vite.transformWithEsbuild>[3],\n) {\n return vite.transformWithOxc\n ? vite.transformWithOxc(\n source,\n filePath,\n { lang: 'ts', sourcemap: true },\n map,\n )\n : vite.transformWithEsbuild(\n source,\n filePath,\n { loader: 'ts', sourcemap: true },\n map,\n );\n}\n\nexport function ngpCompilePlugin(\n optionsOrCtx?:\n | AngularBuildContext\n | FastCompilePluginOptions\n | AngularBuildContextOptions,\n): vite.Plugin {\n const sharedCtx = isAngularBuildContext(optionsOrCtx)\n ? optionsOrCtx\n : isFastCompileOptions(optionsOrCtx)\n ? undefined\n : createAngularBuildContext({\n jit: false,\n ...optionsOrCtx,\n compilationBackend: 'ngp',\n });\n\n const options: FastCompilePluginOptions = sharedCtx\n ? sharedCtx.options\n : (optionsOrCtx as FastCompilePluginOptions);\n\n if (options.jit || options.fastCompileMode === 'partial') {\n throw new Error(\n \"compilation: 'ngp' requires jit: false and fastCompileMode: 'full'.\",\n );\n }\n\n let configContext: TsConfigResolutionContext | undefined;\n let resolvedConfig: vite.ResolvedConfig;\n let transformFilter: TransformFilter | undefined;\n let componentRegistries: ComponentRegistryEntries[] = [];\n let stylePreprocessor: StylePreprocessor | undefined;\n let watchMode = false;\n let hmr = false;\n let activeBuilds = 0;\n let analyzer: NgpAnalyzer | undefined;\n let compiler: NgpCompiler | undefined;\n let typeChecker: LspTypeChecker | undefined;\n let api: NgpApi;\n const filesByPath = new Map<string, { file: NgpFile; chunk: NgpChunk }>();\n const chunkContexts = new Map<NgpChunk, Promise<unknown>>();\n const output = new Map<string, Promise<NgpResult>>();\n const emittedMaps = new Map<string, string>();\n // Last compiled source of each file, compared on edits for HMR\n const sources = new Map<string, string>();\n // Watched files mapped to the source files that depend on them\n const dependents = new Map<string, Set<string>>();\n const hmrUpdateCode = new Map<string, string>();\n const classNames = sharedCtx\n ? sharedCtx.hmr.classNames\n : new Map<string, string>();\n const fileEmitter = (file: string, className: string) => ({\n hmrUpdateCode: hmrUpdateCode.get(`${file}@${className}`),\n });\n sharedCtx?.hmr.setFileEmitter(fileEmitter);\n\n const componentUpdates: ComponentUpdates = {\n classNames,\n fileEmitter,\n };\n let pending = Promise.resolve();\n const excluded = [\n /node_modules/,\n /[?&]raw\\b/,\n /type=script/,\n /@ng\\/component/,\n ];\n const filter = vite.createFilter(TS_EXT_REGEX, excluded);\n const sourceFilter = vite.createFilter(null, excluded);\n\n // Source formats registered through `api.ngp`, the component registry their\n // lowering looks selectors up in, and their modules by program file\n // (`x.tsrx` → `x.tsrx.ts`)\n const sourceFormats: NgpSourceFormat[] = [];\n const scanner = new ComponentScanner();\n const sourceModules = new Map<string, SourceModule>();\n // Per program file: how often it was removed, which cancels a lowering in\n // progress, and the lowered code the analyzer has\n const removals = new Map<string, number>();\n const analyzed = new Map<string, string>();\n // Which modules of each format NGP compiles: its `include` under the tsconfig's directory\n const includes = new Map<NgpSourceFormat, (file: string) => boolean>();\n const moduleFormatOf = (file: string): NgpSourceFormat | undefined =>\n sourceFormats.find(\n (format) => format.test(file) && includes.get(format)?.(file),\n );\n let devServer: vite.ViteDevServer | undefined;\n // The program files a file change lowered again, for the hot update after it\n const reloweredByChange = new Map<string, string[]>();\n const programFileOf = (file: string): string | undefined => {\n const programFile = `${file}.ts`;\n return sourceModules.has(programFile) ? programFile : undefined;\n };\n const sourceFileOf = (file: string): string =>\n sourceModules.get(file)?.sourceFile ?? file;\n\n function resolveTsConfigPath(): string {\n if (sharedCtx) {\n return sharedCtx.resolveTsConfigPath();\n }\n const ctx = configContext ?? {\n root: resolvedConfig?.root || '.',\n isProd: isProdMode(resolvedConfig?.mode),\n isLib: !!resolvedConfig?.build?.lib,\n };\n return getTsConfigPath(\n ctx.root,\n options.tsconfigGetter(),\n ctx.isProd,\n options.isTest,\n ctx.isLib,\n options.workspaceRoot,\n );\n }\n\n const ngp: NgpCompileApi = {\n registerSourceFormat(format) {\n if (!sourceFormats.includes(format)) {\n sourceFormats.push(format);\n scanner.registerSourceFormat(format);\n }\n },\n };\n\n const compilerApi = {\n angularCompiler: true as const,\n getTsConfigPath: resolveTsConfigPath,\n getSourceMap: (id: string): string | undefined =>\n emittedMaps.get(vite.normalizePath(id)),\n hasEmitted: (id: string): boolean =>\n filesByPath.has(vite.normalizePath(id)),\n output,\n ready: (): Promise<void> => pending,\n componentUpdates,\n ngp,\n };\n\n /** Lowers a module of a source format. Returns whether its TypeScript changed. */\n async function lowerSourceModule(\n sourceFile: string,\n source: string,\n format: NgpSourceFormat,\n resolve: FastCompileResolve,\n ): Promise<boolean> {\n const programFile = `${sourceFile}.ts`;\n if (existsSync(programFile)) {\n throw new Error(\n `[@analogjs/vite-plugin-angular]: ${programFile} has the name NGP compiles ${sourceFile} as. Rename one of them.`,\n );\n }\n const removed = removals.get(programFile);\n const lowered = await format.lower(source, sourceFile, {\n scanImports: (specifiers) =>\n scanner.scanImports(specifiers, sourceFile, resolve),\n resolveSelector: (className) =>\n scanner.lookupSelector(\n className,\n sharedCtx?.componentRegistries ?? componentRegistries,\n ),\n });\n // Removed while it was lowered\n if (removals.get(programFile) !== removed) return false;\n const changed =\n sourceModules.get(programFile)?.lowered.code !== lowered.code;\n sourceModules.set(programFile, { sourceFile, source, format, lowered });\n return changed;\n }\n\n /** Lowers every module of the registered source formats under `root`. */\n async function lowerSourceModules(\n root: string,\n resolve: FastCompileResolve,\n ): Promise<void> {\n scanner.reset(root);\n sourceModules.clear();\n const sourceRoot = vite.normalizePath(realpathSync(root));\n await Promise.all(\n sourceFormats.map(async (format) => {\n includes.set(\n format,\n vite.createFilter(format.include, '**/node_modules/**', {\n resolve: sourceRoot,\n }),\n );\n const files = await glob(format.include, {\n cwd: sourceRoot,\n absolute: true,\n ignore: ['**/node_modules/**'],\n });\n await Promise.all(\n files.map(async (file) => {\n const sourceFile = canonicalPath(file);\n const source = await fsPromises.readFile(sourceFile, 'utf-8');\n await lowerSourceModule(sourceFile, source, format, resolve);\n }),\n );\n }),\n );\n // The analyzer reads them through `hostFs` when it's created\n analyzed.clear();\n for (const [programFile, { lowered }] of sourceModules) {\n analyzed.set(programFile, lowered.code);\n }\n }\n\n /**\n * Lowers the source modules a change to `file` affects again: the module\n * itself, and those that looked up selectors in it. Returns the program\n * files whose TypeScript changed.\n */\n async function relowerSourceModules(\n file: string,\n resolve: FastCompileResolve,\n ): Promise<string[]> {\n const affected = [file, ...(scanner.importersByFile.get(file) ?? [])]\n .map(programFileOf)\n .filter((programFile) => programFile !== undefined);\n scanner.invalidate(file);\n const changed = await Promise.all(\n affected.map(async (programFile) => {\n const sourceModule = sourceModules.get(programFile);\n if (!sourceModule) return [];\n const { sourceFile, format } = sourceModule;\n const source = await readSource(sourceFile);\n if (source === undefined) return [];\n const relowered = await lowerSourceModule(\n sourceFile,\n source,\n format,\n resolve,\n );\n return relowered ? [programFile] : [];\n }),\n );\n return changed.flat();\n }\n\n // Lowering and the analyzer updates that follow it, one change at a time, so\n // the modules a change lowers again reach the analyzer together\n let sourceWork: Promise<unknown> = Promise.resolve();\n function withSourceLock<T>(work: () => Promise<T>): Promise<T> {\n const run = sourceWork.catch(() => undefined).then(work);\n sourceWork = run;\n return run;\n }\n\n /** Sends the analyzer the lowered modules it doesn't have yet. */\n async function syncProgramFiles(): Promise<void> {\n const updates = [...sourceModules]\n .filter(\n ([filePath, { lowered }]) => analyzed.get(filePath) !== lowered.code,\n )\n .map(([filePath, { lowered }]) => ({ filePath, content: lowered.code }));\n if (updates.length === 0) return;\n for (const { filePath, content } of updates)\n analyzed.set(filePath, content);\n await enqueueIndex(() => analyzer!.updateFileContent(updates));\n }\n\n /** Reads a source file, or `undefined` if it was removed. */\n function readSource(file: string): Promise<string | undefined> {\n return fsPromises\n .readFile(file, 'utf-8')\n .catch((error: NodeJS.ErrnoException) => {\n if (error.code === 'ENOENT') return undefined;\n throw error;\n });\n }\n\n /** Lowers a module added after the build started, if NGP compiles it. */\n async function addSourceModule(\n sourceFile: string,\n format: NgpSourceFormat,\n source: string,\n resolve: FastCompileResolve,\n ): Promise<void> {\n const programFile = `${sourceFile}.ts`;\n await lowerSourceModule(sourceFile, source, format, resolve);\n const sourceModule = sourceModules.get(programFile);\n // Removed while it was lowered\n if (!sourceModule) return;\n // The analyzer reads it through `hostFs`\n analyzed.set(programFile, sourceModule.lowered.code);\n await enqueueIndex(() =>\n analyzer!.invalidateFiles([\n { filePath: programFile, updateType: FILE_CREATED },\n ]),\n );\n }\n\n /** Drops a removed module, and any lowering of it still in progress. */\n async function removeSourceModule(sourceFile: string): Promise<void> {\n const programFile = `${sourceFile}.ts`;\n removals.set(programFile, (removals.get(programFile) ?? 0) + 1);\n analyzed.delete(programFile);\n if (!sourceModules.delete(programFile)) return;\n await enqueueIndex(() =>\n analyzer!.invalidateFiles([\n { filePath: programFile, updateType: FILE_DELETED },\n ]),\n );\n }\n\n /**\n * Lowers a module for its transform, as fast compile does on every\n * transform, so the selectors it looks up are current. A transform that\n * started before a hot update can carry the previous code; it compiles the\n * latest lowering instead.\n */\n async function lowerForTransform(\n sourceFile: string,\n format: NgpSourceFormat,\n code: string,\n resolve: FastCompileResolve,\n ): Promise<NgpLoweredModule | undefined> {\n const programFile = `${sourceFile}.ts`;\n if (!sourceModules.has(programFile)) {\n // Requested before its `create` event, or added during `vite build --watch`\n await addSourceModule(sourceFile, format, code, resolve);\n } else if (code === (await readSource(sourceFile))) {\n await lowerSourceModule(sourceFile, code, format, resolve);\n }\n return sourceModules.get(programFile)?.lowered;\n }\n\n /** Maps a type error in a program file to the source module's location. */\n function toSourceLocation(location: SourceLocation): SourceLocation {\n const sourceModule = sourceModules.get(vite.normalizePath(location.file));\n const mapped = sourceModule?.lowered.toSourceLocation(\n location.line - 1,\n location.character - 1,\n );\n return mapped\n ? {\n file: sourceModule!.sourceFile,\n line: mapped.line + 1,\n character: mapped.column + 1,\n }\n : location;\n }\n\n sharedCtx?.registerCompiler({\n name: '@analogjs/vite-plugin-angular-ngp',\n getTsConfigPath: compilerApi.getTsConfigPath,\n getSourceMap: compilerApi.getSourceMap,\n hasEmitted: compilerApi.hasEmitted,\n });\n\n async function prepareResources(\n file: NgpFile,\n watch: (path: string) => void,\n ): Promise<NgpFile> {\n watch(file.filePath);\n const activeConfig = sharedCtx?.resolvedConfig ?? resolvedConfig;\n const activeStylePreprocessor =\n sharedCtx?.stylePreprocessor ?? stylePreprocessor;\n\n return {\n ...file,\n classes: await Promise.all(\n file.classes.map(async (metadata, classIndex) => {\n const component = metadata.component;\n if (!component) return metadata;\n if (component.templateUrl) watch(component.templateUrl.resolvedPath);\n for (const style of component.styleUrls ?? [])\n watch(style.resolvedPath);\n const preprocess = async (\n content: string,\n path: string,\n order: number,\n inline: boolean,\n ) => {\n const preprocessed = preprocessStylesheet(\n content,\n path,\n activeStylePreprocessor,\n {\n filename: path,\n containingFile: file.filePath,\n resourceFile: inline ? undefined : path,\n className: metadata.className,\n order,\n inline,\n },\n );\n const result = await vite.preprocessCSS(\n preprocessed,\n path,\n activeConfig,\n );\n result.deps?.forEach(watch);\n return result.code;\n };\n return {\n ...metadata,\n component: {\n ...component,\n styles:\n component.styles &&\n (await Promise.all(\n component.styles.map((style, index) =>\n preprocess(\n style,\n `${file.filePath}.inline-${classIndex}-${index}.${options.inlineStylesExtension}`,\n index,\n true,\n ),\n ),\n )),\n stylesFromUrls:\n component.stylesFromUrls &&\n (await Promise.all(\n component.stylesFromUrls.map((style, index) =>\n preprocess(\n style,\n component.styleUrls![index].resolvedPath,\n index,\n false,\n ),\n ),\n )),\n },\n };\n }),\n ),\n };\n }\n\n async function indexChunks(update?: () => Promise<string[]>): Promise<void> {\n if (update) {\n const invalidated = await update();\n for (const filePath of invalidated) {\n output.delete(vite.normalizePath(filePath));\n compiler!.fileCache.delete(filePath);\n }\n chunkContexts.clear();\n } else {\n filesByPath.clear();\n chunkContexts.clear();\n output.clear();\n const angularOptions = compilerCli.readConfiguration(\n resolveTsConfigPath(),\n ).options as Record<string, unknown>;\n compiler = new api.HybridCompiler(analyzer!, {\n ...angularOptions,\n optimize: true,\n enableHmr: hmr,\n tcbConfig: api.buildTypeCheckingConfig(angularOptions),\n });\n }\n const chunks = update\n ? compiler!.analyzeOptimizedDelta()\n : compiler!.analyzeOptimized();\n for await (const chunk of chunks) {\n for (const file of chunk.files) {\n const normPath = vite.normalizePath(file.filePath);\n filesByPath.set(normPath, { file, chunk });\n output.delete(normPath);\n compiler!.fileCache.delete(file.filePath);\n }\n for (const removed of chunk.removedFiles ?? []) {\n const normPath = vite.normalizePath(removed);\n filesByPath.delete(normPath);\n output.delete(normPath);\n }\n }\n }\n\n function enqueueIndex(update: () => Promise<string[]>): Promise<void> {\n pending = pending.catch(() => {}).then(() => indexChunks(update));\n return pending;\n }\n\n function getChunkContext(chunk: NgpChunk): Promise<unknown> {\n let context = chunkContexts.get(chunk);\n if (!context) {\n context = compiler!.prepareChunk(chunk);\n chunkContexts.set(chunk, context);\n }\n return context;\n }\n\n async function checkTypes(\n filePath: string,\n sourceCode: string,\n tcbCode?: string | null,\n ): Promise<void> {\n typeChecker ??= new LspTypeChecker(\n resolveTsConfigPath(),\n options.typeChecker,\n {\n inMemoryFiles: () =>\n new Map(\n [...sourceModules].map(([file, { lowered }]) => [\n file,\n lowered.code,\n ]),\n ),\n mapLocation: toSourceLocation,\n },\n );\n typeChecker.queueFile(filePath, sourceCode, tcbCode);\n if (!watchMode) return;\n const typeErrors = await typeChecker.flushQueue(true);\n if (typeErrors.length) {\n throw new Error(typeErrors.join('\\n'));\n }\n }\n\n async function processFile(\n normPath: string,\n activeCompiler: NgpCompiler,\n watch: (path: string) => void,\n ) {\n const { file: analyzed, chunk } = filesByPath.get(normPath)!;\n const [file, context, content] = await Promise.all([\n prepareResources(analyzed, (path) => {\n const key = sourceFileOf(vite.normalizePath(path));\n dependents.set(key, (dependents.get(key) ?? new Set()).add(normPath));\n watch(key);\n }),\n getChunkContext(chunk),\n analyzer!.getFileContent(analyzed.filePath),\n ]);\n sources.set(normPath, content);\n const result =\n activeCompiler.processFile.length >= 5\n ? await activeCompiler.processFile(\n file.filePath,\n content,\n undefined,\n file,\n context,\n )\n : await activeCompiler.processFile(\n file.filePath,\n content,\n file,\n context,\n );\n return { file, content, result };\n }\n\n function compileFile(\n normPath: string,\n watch: (path: string) => void,\n ): Promise<NgpResult> | undefined {\n if (!filesByPath.has(normPath)) return undefined;\n let task = output.get(normPath);\n if (!task) {\n task = (async () => {\n // Analyzer updates queued before this compile land first\n await pending;\n if (!filesByPath.has(normPath)) {\n throw new Error(`${sourceFileOf(normPath)} was removed.`);\n }\n const { file, content, result } = await processFile(\n normPath,\n compiler!,\n watch,\n );\n const errors = [\n ...(file.diagnostics ?? []),\n ...(result.diagnostics ?? []),\n ].filter((diagnostic) => diagnostic.category === 1);\n if (errors.length) {\n throw new Error(\n `${sourceFileOf(normPath)}: ${errors.map((error) => error.messageText).join('\\n')}`,\n );\n }\n if (options.disableTypeChecking !== true) {\n await checkTypes(file.filePath, content, result.tcb?.code);\n }\n return result;\n })();\n output.set(normPath, task);\n }\n return task;\n }\n\n function componentNames(normPath: string): string[] {\n return (filesByPath.get(normPath)?.file.classes ?? []).flatMap(\n ({ className, component }) => (component && className ? [className] : []),\n );\n }\n\n // Components to update in place, following the Angular CLI's rule\n async function findComponentUpdates(\n normPath: string,\n read: () => string | Promise<string>,\n ): Promise<ComponentUpdate[]> {\n if (!TS_EXT_REGEX.test(normPath)) {\n return [...(dependents.get(normPath) ?? [])].flatMap((file) =>\n componentNames(file).map((className) => ({ file, className })),\n );\n }\n const stale = sources.get(normPath);\n if (stale === undefined) return [];\n const matchedClassNames = findHmrComponentUpdates(\n normPath,\n stale,\n await read(),\n new Set(componentNames(normPath)),\n );\n return (matchedClassNames ?? []).map((className) => ({\n file: normPath,\n className,\n }));\n }\n\n async function emitHmrUpdate(file: string, className: string) {\n // NGP emits only the update module of the class named by `hmrUpdateTarget`,\n // and only when it doesn't reuse the file's previously processed output\n const target = Object.assign(\n Object.create(Object.getPrototypeOf(compiler)),\n compiler,\n { hmrUpdateTarget: className, reuseProcessedFiles: false },\n );\n const { result } = await processFile(file, target, () => {});\n return (\n result.hmrUpdateModule &&\n (await transpile(result.hmrUpdateModule, file)).code\n );\n }\n\n async function sendComponentUpdates(\n updates: ComponentUpdate[],\n server: vite.ViteDevServer,\n ): Promise<boolean> {\n try {\n for (const file of new Set(updates.map((update) => update.file))) {\n await compileFile(file, () => {});\n }\n const codes = await Promise.all(\n updates.map(({ file, className }) => emitHmrUpdate(file, className)),\n );\n if (codes.some((code) => !code)) return false;\n updates.forEach(({ file, className }, index) => {\n // Components of a source module update through the module itself\n const sourceFile = sourceModules.get(file)?.sourceFile;\n const moduleFile = sourceFile ?? file;\n hmrUpdateCode.set(`${moduleFile}@${className}`, codes[index]!);\n componentUpdates.classNames.set(moduleFile, className);\n server.moduleGraph\n .getModulesByFile(moduleFile)\n ?.forEach((mod) => server.moduleGraph.invalidateModule(mod));\n server.ws.send('angular:component-update', {\n id: encodeURIComponent(\n `${sourceFile ?? filesByPath.get(file)!.file.filePath}@${className}`,\n ),\n timestamp: Date.now(),\n });\n });\n return true;\n } catch {\n // A full reload reports the compilation error\n return false;\n }\n }\n\n return {\n name: '@analogjs/vite-plugin-angular-ngp',\n enforce: 'pre',\n api: compilerApi,\n config(config, { command, mode }) {\n watchMode = command === 'serve';\n const isProd = isProdMode(config.mode);\n if (sharedCtx) {\n sharedCtx.initConfig(config, { command, mode });\n } else {\n configContext = {\n root: config.root || '.',\n isProd,\n isLib: !!config.build?.lib,\n };\n }\n const depOptimizer = createDepOptimizerConfig({\n tsconfig: resolveTsConfigPath(),\n isProd,\n jit: false,\n watchMode,\n isTest: options.isTest,\n isAstroIntegration: options.isAstroIntegration,\n });\n return {\n ...(isRolldown() ? { oxc: {} as any } : { esbuild: false }),\n ...depOptimizer,\n };\n },\n async configResolved(config) {\n resolvedConfig = config;\n hmr =\n watchMode &&\n options.liveReload &&\n !options.isTest &&\n config.server.hmr !== false;\n const integrations = sharedCtx\n ? await sharedCtx.resolveConfig(config)\n : await discoverAnalogIntegrations(config);\n transformFilter = integrations.transformFilter;\n componentRegistries = integrations.componentRegistries;\n stylePreprocessor = integrations.stylePreprocessor;\n },\n configureServer(server) {\n const changeTypes: Record<string, FileChangeType> = {\n add: 1,\n change: 2,\n unlink: 3,\n };\n devServer = server;\n server.watcher.on('all', (event, path) => {\n const type = changeTypes[event];\n if (type) typeChecker?.notifyFileChanged(path, type);\n });\n server.httpServer?.on('close', () => {\n typeChecker?.close();\n typeChecker = undefined;\n analyzer?.close();\n analyzer = undefined;\n compiler = undefined;\n });\n },\n // Runs on the dev server with or without HMR, and in `vite build --watch`\n async watchChange(id, { event }) {\n if (!analyzer || sourceFormats.length === 0) return;\n const file = canonicalPath(id);\n const resolve: FastCompileResolve = (spec, importer) =>\n this.resolve(spec, importer, { skipSelf: true });\n await withSourceLock(async () => {\n scanner.invalidate(file);\n const format = moduleFormatOf(file);\n if (event === 'update') {\n reloweredByChange.set(\n file,\n await relowerSourceModules(file, resolve),\n );\n } else if (event === 'delete') {\n await removeSourceModule(file);\n } else if (\n event === 'create' &&\n format &&\n !sourceModules.has(`${file}.ts`)\n ) {\n const source = await readSource(file);\n if (source !== undefined) {\n await addSourceModule(file, format, source, resolve);\n }\n }\n await syncProgramFiles();\n });\n // Modules that looked up selectors in `file` lower again when transformed\n for (const importer of scanner.importersByFile.get(file) ?? []) {\n devServer?.moduleGraph\n .getModulesByFile(importer)\n ?.forEach((mod) => devServer!.moduleGraph.invalidateModule(mod));\n }\n },\n async buildStart() {\n activeBuilds++;\n if (!analyzer) {\n const tsconfig = resolveTsConfigPath();\n const hasSourceFormats = sourceFormats.length > 0;\n const ngp = await loadNgp(tsconfig, hasSourceFormats);\n api = ngp.api;\n if (hasSourceFormats) {\n await lowerSourceModules(dirname(tsconfig), (specifier, importer) =>\n this.resolve(specifier, importer, { skipSelf: true }),\n );\n }\n analyzer = await api.createAnalyzer(tsconfig, {\n ...ngp.analyzerOptions,\n enableHmr: hmr,\n hostFs: hasSourceFormats\n ? createNgpHostFs((path) => sourceModules.get(path)?.lowered.code)\n : undefined,\n });\n pending = indexChunks();\n }\n await pending;\n for (const path of dependents.keys()) {\n this.addWatchFile(path);\n }\n },\n resolveId(id, importer) {\n return resolveAngularVirtualId(id, importer, {\n jit: false,\n resolvedConfig: sharedCtx?.resolvedConfig ?? resolvedConfig,\n });\n },\n async load(id) {\n return loadAngularVirtualModule(\n this,\n id,\n sharedCtx?.resolvedConfig ?? resolvedConfig,\n );\n },\n async transform(code, id) {\n const activeTransformFilter =\n sharedCtx?.transformFilter ?? transformFilter;\n const filePath = vite.normalizePath(id.split('?')[0]);\n const sourceFormat = scanner.sourceFormatOf(filePath);\n if (\n !(sourceFormat ? sourceFilter(id) : filter(id)) ||\n activeTransformFilter?.(code, id) === false\n ) {\n return;\n }\n await pending;\n let lowered: NgpLoweredModule | undefined;\n let compiledFile = filePath;\n if (sourceFormat) {\n const sourceFile = canonicalPath(filePath);\n const format = moduleFormatOf(sourceFile);\n if (!format) {\n this.error(\n `${filePath} is outside ${dirname(resolveTsConfigPath())}, where '${sourceFormat.name}' modules are compiled from.`,\n );\n }\n lowered = await withSourceLock(async () => {\n const result = await lowerForTransform(\n sourceFile,\n format,\n code,\n (spec, importer) =>\n this.resolve(spec, importer, { skipSelf: true }),\n );\n await syncProgramFiles();\n return result;\n });\n if (!lowered) {\n this.error(`${filePath} was removed while it was compiled.`);\n }\n if (lowered.error) {\n this.error({\n message: lowered.error.message,\n id: filePath,\n loc: lowered.error.loc && { file: filePath, ...lowered.error.loc },\n });\n }\n compiledFile = `${sourceFile}.ts`;\n // Transform the module again when a component it looked up changes\n for (const dependency of scanner.dependenciesOf(sourceFile)) {\n this.addWatchFile(dependency);\n }\n }\n const compiledCode = lowered ? lowered.code : code;\n const watch = (path: string) => this.addWatchFile(path);\n let result: NgpResult | undefined;\n try {\n result = await compileFile(compiledFile, watch);\n } catch (error) {\n // A failed compile stays cached until its file is updated, so only\n // report it if it compiled this content\n if (\n !sources.has(compiledFile) ||\n sources.get(compiledFile) === compiledCode\n ) {\n throw error;\n }\n }\n if (\n filesByPath.has(compiledFile) &&\n sources.get(compiledFile) !== compiledCode\n ) {\n if (lowered) analyzed.set(compiledFile, compiledCode);\n await enqueueIndex(() =>\n analyzer!.updateFileContent([\n { filePath: compiledFile, content: compiledCode },\n ]),\n );\n result = await compileFile(compiledFile, watch);\n } else if (!result && lowered) {\n this.error(\n `${filePath} is not part of the TypeScript program of ${resolveTsConfigPath()}. Import it, or add it to the tsconfig's \\`include\\`.`,\n );\n } else if (!result && options.disableTypeChecking !== true) {\n await checkTypes(filePath, code);\n }\n let source = result?.magicString.toString() ?? code;\n if (lowered && result) {\n // Component HMR ids name the program file; the dev server knows the module\n source = source.replaceAll(\n encodeURIComponent(\n `${filesByPath.get(compiledFile)!.file.filePath}@`,\n ),\n encodeURIComponent(`${filePath}@`),\n );\n }\n const map = result?.magicString.generateMap({\n source: compiledFile,\n includeContent: true,\n hires: true,\n });\n const transpiled = await transpile(source, compiledFile, map);\n const outputMap =\n lowered && transpiled.map\n ? lowered.mapToSource(JSON.stringify(transpiled.map))\n : transpiled.map;\n if (outputMap) {\n emittedMaps.set(\n filePath,\n typeof outputMap === 'string' ? outputMap : JSON.stringify(outputMap),\n );\n }\n return {\n code: transpiled.code,\n map: outputMap as vite.Rollup.SourceMapInput,\n };\n },\n async handleHotUpdate(ctx) {\n if (\n sharedCtx\n ? sharedCtx.hmr.isIgnoredFile(ctx.file)\n : isIgnoredHmrFile(ctx.file)\n ) {\n return [];\n }\n const normPath = vite.normalizePath(ctx.file);\n const sourceFile = canonicalPath(ctx.file);\n const programFile = programFileOf(sourceFile);\n const updates = await withSourceLock(async () => {\n // Lowered again in `watchChange`, which runs first\n const relowered = reloweredByChange.get(sourceFile) ?? [];\n reloweredByChange.delete(sourceFile);\n const lowered = programFile\n ? sourceModules.get(programFile)?.lowered\n : undefined;\n // In place only for a module that lowered without errors, which no\n // other module was lowered again against\n const componentUpdates =\n hmr &&\n !lowered?.error &&\n relowered.every((file) => file === programFile)\n ? await findComponentUpdates(\n programFile ?? normPath,\n lowered ? () => lowered.code : ctx.read,\n )\n : [];\n if (!programFile) {\n await enqueueIndex(() =>\n analyzer!.invalidateFiles([\n { filePath: ctx.file, updateType: FILE_CHANGED },\n ]),\n );\n }\n await syncProgramFiles();\n return componentUpdates;\n });\n if (updates.length && (await sendComponentUpdates(updates, ctx.server))) {\n return [];\n }\n hmrUpdateCode.clear();\n componentUpdates.classNames.clear();\n ctx.server.moduleGraph.invalidateAll();\n ctx.server.ws.send({ type: 'full-reload' });\n return [];\n },\n async buildEnd(error) {\n if (error || watchMode || !typeChecker) return;\n const typeErrors = await typeChecker.flushQueue();\n if (typeErrors.length) {\n throw new Error(typeErrors.join('\\n'));\n }\n },\n async closeBundle() {\n activeBuilds = Math.max(0, activeBuilds - 1);\n if (watchMode || activeBuilds > 0) return;\n await pending.catch(() => {});\n typeChecker?.close();\n typeChecker = undefined;\n analyzer?.close();\n analyzer = undefined;\n compiler = undefined;\n filesByPath.clear();\n chunkContexts.clear();\n output.clear();\n emittedMaps.clear();\n sources.clear();\n dependents.clear();\n sourceModules.clear();\n analyzed.clear();\n releaseCssPreprocessorWorkers();\n },\n };\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;AA+HA,IAAM,eAAe;AACrB,IAAM,eAAe;AACrB,IAAM,eAAe;AA0BrB,SAAS,qBACP,OACmC;CACnC,OACE,OAAO,UAAU,YACjB,UAAU,QACV,CAAC,sBAAsB,KAAK,KAC5B,oBAAoB,SACpB,OAAQ,MAAmC,mBAAmB;AAElE;AAGA,IAAM,cAAc,IAAA,IAAA,cAAA,KAAA,YAAA,GAAA;;;;;AAMpB,eAAe,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B,WAAW,KAAA;GACX,WAAW,KAAA;GACX,YAAY,MAAM;GAClB,cAAc,MAAM;GACpB,OAAO,MAAM;GACb,YAAY,MAAM;GAClB,QAAQ,MAAM;GACd,WAAW,MAAM;GACjB,cAAc,MAAM;GACpB,SAAS,MAAM;GACf,8BAA8B;EAChC;CACF;AACF"}
1
+ {"version":3,"file":"ngp-compile-plugin.js","names":[],"sources":["../../../src/lib/ngp-compile-plugin.ts"],"sourcesContent":["import * as compilerCli from '@angular/compiler-cli';\nimport { existsSync, promises as fsPromises, realpathSync } from 'node:fs';\nimport { createRequire } from 'node:module';\nimport { dirname, resolve } from 'node:path';\nimport { fileURLToPath, pathToFileURL } from 'node:url';\nimport type MagicString from 'magic-string';\nimport { glob } from 'tinyglobby';\nimport * as vite from 'vite';\nimport {\n discoverAnalogIntegrations,\n type ComponentRegistryEntries,\n type TransformFilter,\n} from './analog-plugin-interop.js';\nimport {\n createAngularBuildContext,\n isAngularBuildContext,\n type AngularBuildContext,\n type AngularBuildContextOptions,\n} from './angular-build-context.js';\nimport { ComponentScanner } from './component-scanner.js';\nimport type { FastCompileResolve } from './fast-compile-api.js';\nimport type { FastCompilePluginOptions } from './fast-compile-plugin.js';\nimport type {\n NgpCompileApi,\n NgpLoweredModule,\n NgpSourceFormat,\n} from './ngp-compile-api.js';\nimport type { StylePreprocessor } from './style-preprocessor.js';\nimport { preprocessStylesheet } from './stylesheet-registry.js';\nimport { isIgnoredHmrFile } from './utils/compilation-shared.js';\nimport {\n createDepOptimizerConfig,\n getTsConfigPath,\n isProdMode,\n TS_EXT_REGEX,\n type TsConfigResolutionContext,\n} from './utils/plugin-config.js';\nimport { releaseCssPreprocessorWorkers } from './utils/css-preprocessor-workers.js';\nimport { angularFullVersion } from './utils/devkit.js';\nimport { findHmrComponentUpdates } from './utils/hmr-component-updates.js';\nimport {\n LspTypeChecker,\n type FileChangeType,\n type SourceLocation,\n} from './utils/lsp-type-checker.js';\nimport {\n canonicalPath,\n createNgpHostFs,\n fromWasmPath,\n toWasmPath,\n type NgpHostFs,\n} from './utils/ngp-host-fs.js';\nimport { isRolldown } from './utils/rolldown.js';\nimport type { ComponentUpdates } from './live-reload-plugin.js';\nimport {\n loadAngularVirtualModule,\n resolveAngularVirtualId,\n} from './virtual-modules-plugin.js';\n\n// The unpublished NGP API is loaded at runtime. Model only the surface we use.\ninterface NgpDiagnostic {\n category: number;\n messageText: string;\n}\n\ninterface NgpFile {\n filePath: string;\n diagnostics?: NgpDiagnostic[];\n classes: {\n className?: string;\n component?: {\n templateUrl?: { resolvedPath: string };\n styleUrls?: { resolvedPath: string }[];\n stylesFromUrls?: string[];\n styles?: string[];\n };\n }[];\n}\n\ninterface NgpChunk {\n files: NgpFile[];\n removedFiles?: string[];\n}\n\ninterface NgpResult {\n magicString: MagicString;\n diagnostics?: NgpDiagnostic[];\n tcb?: { code: string } | null;\n hmrUpdateModule?: string | null;\n}\n\ninterface NgpAnalyzer {\n getFileContent(path: string): Promise<string>;\n updateFileContent(\n updates: { filePath: string; content: string }[],\n ): Promise<string[]>;\n invalidateFiles(\n updates: { filePath: string; updateType: number }[],\n ): Promise<string[]>;\n close(): void;\n}\n\ninterface NgpCompiler {\n // Parsed templates by file, cleared by NGP's own update methods\n fileCache: Map<string, unknown>;\n analyzeOptimized(): AsyncIterable<NgpChunk>;\n analyzeOptimizedDelta(): AsyncIterable<NgpChunk>;\n prepareChunk(chunk: NgpChunk): Promise<unknown>;\n processFile(\n path: string,\n content: string,\n ...args: [undefined, NgpFile, unknown] | [NgpFile, unknown]\n ): Promise<NgpResult>;\n}\n\ninterface ComponentUpdate {\n file: string;\n className: string;\n}\n\ninterface NgpAnalyzerOptions {\n nativeBinding?: string;\n backend?: 'wasm';\n wasmBinding?: string;\n enableHmr?: boolean;\n hostFs?: NgpHostFs;\n}\n\n/** NGP's `FileUpdateType`. */\nconst FILE_CREATED = 0;\nconst FILE_DELETED = 1;\nconst FILE_CHANGED = 2;\n\n/** A module of a registered source format, lowered to its program file. */\ninterface SourceModule {\n sourceFile: string;\n /** The source it was lowered from. */\n source: string;\n format: NgpSourceFormat;\n lowered: NgpLoweredModule;\n}\n\ninterface NgpApi {\n createAnalyzer(\n tsconfig: string,\n options: NgpAnalyzerOptions,\n ): Promise<NgpAnalyzer>;\n HybridCompiler: new (\n analyzer: NgpAnalyzer,\n options: Record<string, unknown> & {\n optimize: boolean;\n enableHmr: boolean;\n },\n ) => NgpCompiler;\n buildTypeCheckingConfig(options: Record<string, unknown>): unknown;\n}\n\nfunction isFastCompileOptions(\n value: unknown,\n): value is FastCompilePluginOptions {\n return (\n typeof value === 'object' &&\n value !== null &&\n !isAngularBuildContext(value) &&\n 'tsconfigGetter' in value &&\n typeof (value as FastCompilePluginOptions).tsconfigGetter === 'function'\n );\n}\n\n// Interim NGP build bundled with this package until @angular/ngp is published\nconst BUNDLED_NGP = new URL('../../ngp/', import.meta.url);\n\n/**\n * @param needsHostFs Whether source formats are registered, which only the\n * WebAssembly backend can read through `hostFs`.\n */\nasync function loadNgp(\n tsconfig: string,\n needsHostFs: boolean,\n): Promise<{ api: NgpApi; analyzerOptions: NgpAnalyzerOptions }> {\n const nativeBinding = process.env['ANALOG_NGP_NATIVE_BINDING'];\n if (nativeBinding && needsHostFs) {\n throw new Error(\n \"[@analogjs/vite-plugin-angular]: Source formats such as TSRX can't be compiled with a native NGP analyzer build. Unset ANALOG_NGP_NATIVE_BINDING to use NGP's default WebAssembly analyzer.\",\n );\n }\n let modulePath = process.env['ANALOG_NGP_COMPILER'];\n if (!modulePath) {\n try {\n modulePath = createRequire(tsconfig).resolve('@angular/ngp');\n } catch {\n if (angularFullVersion < 220200) {\n throw new Error(\n \"[@analogjs/vite-plugin-angular]: compilation: 'ngp' requires Angular v22.2 or later.\",\n );\n }\n return {\n api: await import(new URL('api.mjs', BUNDLED_NGP).href),\n analyzerOptions: nativeBinding\n ? { nativeBinding }\n : {\n backend: 'wasm',\n wasmBinding: fileURLToPath(\n new URL('ng_analyze.cjs', BUNDLED_NGP),\n ),\n },\n };\n }\n }\n return {\n api: await import(pathToFileURL(resolve(modulePath)).href),\n analyzerOptions: nativeBinding\n ? { nativeBinding }\n : needsHostFs\n ? { backend: 'wasm' }\n : {},\n };\n}\n\nfunction transpile(\n source: string,\n filePath: string,\n map?: Parameters<typeof vite.transformWithEsbuild>[3],\n) {\n return vite.transformWithOxc\n ? vite.transformWithOxc(\n source,\n filePath,\n { lang: 'ts', sourcemap: true },\n map,\n )\n : vite.transformWithEsbuild(\n source,\n filePath,\n { loader: 'ts', sourcemap: true },\n map,\n );\n}\n\nexport function ngpCompilePlugin(\n optionsOrCtx?:\n | AngularBuildContext\n | FastCompilePluginOptions\n | AngularBuildContextOptions,\n): vite.Plugin {\n const sharedCtx = isAngularBuildContext(optionsOrCtx)\n ? optionsOrCtx\n : isFastCompileOptions(optionsOrCtx)\n ? undefined\n : createAngularBuildContext({\n jit: false,\n ...optionsOrCtx,\n compilationBackend: 'ngp',\n });\n\n const options: FastCompilePluginOptions = sharedCtx\n ? sharedCtx.options\n : (optionsOrCtx as FastCompilePluginOptions);\n\n if (options.jit || options.fastCompileMode === 'partial') {\n throw new Error(\n \"compilation: 'ngp' requires jit: false and fastCompileMode: 'full'.\",\n );\n }\n\n let configContext: TsConfigResolutionContext | undefined;\n let resolvedConfig: vite.ResolvedConfig;\n let transformFilter: TransformFilter | undefined;\n let componentRegistries: ComponentRegistryEntries[] = [];\n let stylePreprocessor: StylePreprocessor | undefined;\n let watchMode = false;\n let hmr = false;\n let activeBuilds = 0;\n let analyzer: NgpAnalyzer | undefined;\n let compiler: NgpCompiler | undefined;\n let typeChecker: LspTypeChecker | undefined;\n let api: NgpApi;\n let toAnalyzerPath = (path: string) => path;\n let fromAnalyzerPath = vite.normalizePath;\n const filesByPath = new Map<string, { file: NgpFile; chunk: NgpChunk }>();\n const chunkContexts = new Map<NgpChunk, Promise<unknown>>();\n const output = new Map<string, Promise<NgpResult>>();\n const emittedMaps = new Map<string, string>();\n // Last compiled source of each file, compared on edits for HMR\n const sources = new Map<string, string>();\n // Watched files mapped to the source files that depend on them\n const dependents = new Map<string, Set<string>>();\n const hmrUpdateCode = new Map<string, string>();\n const classNames = sharedCtx\n ? sharedCtx.hmr.classNames\n : new Map<string, string>();\n const fileEmitter = (file: string, className: string) => ({\n hmrUpdateCode: hmrUpdateCode.get(`${file}@${className}`),\n });\n sharedCtx?.hmr.setFileEmitter(fileEmitter);\n\n const componentUpdates: ComponentUpdates = {\n classNames,\n fileEmitter,\n };\n let pending = Promise.resolve();\n const excluded = [\n /node_modules/,\n /[?&]raw\\b/,\n /type=script/,\n /@ng\\/component/,\n ];\n const filter = vite.createFilter(TS_EXT_REGEX, excluded);\n const sourceFilter = vite.createFilter(null, excluded);\n\n // Source formats registered through `api.ngp`, the component registry their\n // lowering looks selectors up in, and their modules by program file\n // (`x.tsrx` → `x.tsrx.ts`)\n const sourceFormats: NgpSourceFormat[] = [];\n const scanner = new ComponentScanner();\n const sourceModules = new Map<string, SourceModule>();\n // Per program file: how often it was removed, which cancels a lowering in\n // progress, and the lowered code the analyzer has\n const removals = new Map<string, number>();\n const analyzed = new Map<string, string>();\n // Which modules of each format NGP compiles: its `include` under the tsconfig's directory\n const includes = new Map<NgpSourceFormat, (file: string) => boolean>();\n const moduleFormatOf = (file: string): NgpSourceFormat | undefined =>\n sourceFormats.find(\n (format) => format.test(file) && includes.get(format)?.(file),\n );\n let devServer: vite.ViteDevServer | undefined;\n // The program files a file change lowered again, for the hot update after it\n const reloweredByChange = new Map<string, string[]>();\n const programFileOf = (file: string): string | undefined => {\n const programFile = `${file}.ts`;\n return sourceModules.has(programFile) ? programFile : undefined;\n };\n const sourceFileOf = (file: string): string =>\n sourceModules.get(file)?.sourceFile ?? file;\n\n function resolveTsConfigPath(): string {\n if (sharedCtx) {\n return sharedCtx.resolveTsConfigPath();\n }\n const ctx = configContext ?? {\n root: resolvedConfig?.root || '.',\n isProd: isProdMode(resolvedConfig?.mode),\n isLib: !!resolvedConfig?.build?.lib,\n };\n return getTsConfigPath(\n ctx.root,\n options.tsconfigGetter(),\n ctx.isProd,\n options.isTest,\n ctx.isLib,\n options.workspaceRoot,\n );\n }\n\n const ngp: NgpCompileApi = {\n registerSourceFormat(format) {\n if (!sourceFormats.includes(format)) {\n sourceFormats.push(format);\n scanner.registerSourceFormat(format);\n }\n },\n };\n\n const compilerApi = {\n angularCompiler: true as const,\n getTsConfigPath: resolveTsConfigPath,\n getSourceMap: (id: string): string | undefined =>\n emittedMaps.get(vite.normalizePath(id)),\n hasEmitted: (id: string): boolean =>\n filesByPath.has(vite.normalizePath(id)),\n output,\n ready: (): Promise<void> => pending,\n componentUpdates,\n ngp,\n };\n\n /** Lowers a module of a source format. Returns whether its TypeScript changed. */\n async function lowerSourceModule(\n sourceFile: string,\n source: string,\n format: NgpSourceFormat,\n resolve: FastCompileResolve,\n ): Promise<boolean> {\n const programFile = `${sourceFile}.ts`;\n if (existsSync(programFile)) {\n throw new Error(\n `[@analogjs/vite-plugin-angular]: ${programFile} has the name NGP compiles ${sourceFile} as. Rename one of them.`,\n );\n }\n const removed = removals.get(programFile);\n const lowered = await format.lower(source, sourceFile, {\n scanImports: (specifiers) =>\n scanner.scanImports(specifiers, sourceFile, resolve),\n resolveSelector: (className) =>\n scanner.lookupSelector(\n className,\n sharedCtx?.componentRegistries ?? componentRegistries,\n ),\n });\n // Removed while it was lowered\n if (removals.get(programFile) !== removed) return false;\n const changed =\n sourceModules.get(programFile)?.lowered.code !== lowered.code;\n sourceModules.set(programFile, { sourceFile, source, format, lowered });\n return changed;\n }\n\n /** Lowers every module of the registered source formats under `root`. */\n async function lowerSourceModules(\n root: string,\n resolve: FastCompileResolve,\n ): Promise<void> {\n scanner.reset(root);\n sourceModules.clear();\n const sourceRoot = vite.normalizePath(realpathSync(root));\n await Promise.all(\n sourceFormats.map(async (format) => {\n includes.set(\n format,\n vite.createFilter(format.include, '**/node_modules/**', {\n resolve: sourceRoot,\n }),\n );\n const files = await glob(format.include, {\n cwd: sourceRoot,\n absolute: true,\n ignore: ['**/node_modules/**'],\n });\n await Promise.all(\n files.map(async (file) => {\n const sourceFile = canonicalPath(file);\n const source = await fsPromises.readFile(sourceFile, 'utf-8');\n await lowerSourceModule(sourceFile, source, format, resolve);\n }),\n );\n }),\n );\n // The analyzer reads them through `hostFs` when it's created\n analyzed.clear();\n for (const [programFile, { lowered }] of sourceModules) {\n analyzed.set(programFile, lowered.code);\n }\n }\n\n /**\n * Lowers the source modules a change to `file` affects again: the module\n * itself, and those that looked up selectors in it. Returns the program\n * files whose TypeScript changed.\n */\n async function relowerSourceModules(\n file: string,\n resolve: FastCompileResolve,\n ): Promise<string[]> {\n const affected = [file, ...(scanner.importersByFile.get(file) ?? [])]\n .map(programFileOf)\n .filter((programFile) => programFile !== undefined);\n scanner.invalidate(file);\n const changed = await Promise.all(\n affected.map(async (programFile) => {\n const sourceModule = sourceModules.get(programFile);\n if (!sourceModule) return [];\n const { sourceFile, format } = sourceModule;\n const source = await readSource(sourceFile);\n if (source === undefined) return [];\n const relowered = await lowerSourceModule(\n sourceFile,\n source,\n format,\n resolve,\n );\n return relowered ? [programFile] : [];\n }),\n );\n return changed.flat();\n }\n\n // Lowering and the analyzer updates that follow it, one change at a time, so\n // the modules a change lowers again reach the analyzer together\n let sourceWork: Promise<unknown> = Promise.resolve();\n function withSourceLock<T>(work: () => Promise<T>): Promise<T> {\n const run = sourceWork.catch(() => undefined).then(work);\n sourceWork = run;\n return run;\n }\n\n /** Sends the analyzer the lowered modules it doesn't have yet. */\n async function syncProgramFiles(): Promise<void> {\n const updates = [...sourceModules]\n .filter(\n ([filePath, { lowered }]) => analyzed.get(filePath) !== lowered.code,\n )\n .map(([filePath, { lowered }]) => ({ filePath, content: lowered.code }));\n if (updates.length === 0) return;\n for (const { filePath, content } of updates)\n analyzed.set(filePath, content);\n await enqueueIndex(() =>\n analyzer!.updateFileContent(\n updates.map(({ filePath, content }) => ({\n filePath: toAnalyzerPath(filePath),\n content,\n })),\n ),\n );\n }\n\n /** Reads a source file, or `undefined` if it was removed. */\n function readSource(file: string): Promise<string | undefined> {\n return fsPromises\n .readFile(file, 'utf-8')\n .catch((error: NodeJS.ErrnoException) => {\n if (error.code === 'ENOENT') return undefined;\n throw error;\n });\n }\n\n /** Lowers a module added after the build started, if NGP compiles it. */\n async function addSourceModule(\n sourceFile: string,\n format: NgpSourceFormat,\n source: string,\n resolve: FastCompileResolve,\n ): Promise<void> {\n const programFile = `${sourceFile}.ts`;\n await lowerSourceModule(sourceFile, source, format, resolve);\n const sourceModule = sourceModules.get(programFile);\n // Removed while it was lowered\n if (!sourceModule) return;\n // The analyzer reads it through `hostFs`\n analyzed.set(programFile, sourceModule.lowered.code);\n await enqueueIndex(() =>\n analyzer!.invalidateFiles([\n { filePath: toAnalyzerPath(programFile), updateType: FILE_CREATED },\n ]),\n );\n }\n\n /** Drops a removed module, and any lowering of it still in progress. */\n async function removeSourceModule(sourceFile: string): Promise<void> {\n const programFile = `${sourceFile}.ts`;\n removals.set(programFile, (removals.get(programFile) ?? 0) + 1);\n analyzed.delete(programFile);\n if (!sourceModules.delete(programFile)) return;\n await enqueueIndex(() =>\n analyzer!.invalidateFiles([\n { filePath: toAnalyzerPath(programFile), updateType: FILE_DELETED },\n ]),\n );\n }\n\n /**\n * Lowers a module for its transform, as fast compile does on every\n * transform, so the selectors it looks up are current. A transform that\n * started before a hot update can carry the previous code; it compiles the\n * latest lowering instead.\n */\n async function lowerForTransform(\n sourceFile: string,\n format: NgpSourceFormat,\n code: string,\n resolve: FastCompileResolve,\n ): Promise<NgpLoweredModule | undefined> {\n const programFile = `${sourceFile}.ts`;\n if (!sourceModules.has(programFile)) {\n // Requested before its `create` event, or added during `vite build --watch`\n await addSourceModule(sourceFile, format, code, resolve);\n } else if (code === (await readSource(sourceFile))) {\n await lowerSourceModule(sourceFile, code, format, resolve);\n }\n return sourceModules.get(programFile)?.lowered;\n }\n\n /** Maps a type error in a program file to the source module's location. */\n function toSourceLocation(location: SourceLocation): SourceLocation {\n const sourceModule = sourceModules.get(vite.normalizePath(location.file));\n const mapped = sourceModule?.lowered.toSourceLocation(\n location.line - 1,\n location.character - 1,\n );\n return mapped\n ? {\n file: sourceModule!.sourceFile,\n line: mapped.line + 1,\n character: mapped.column + 1,\n }\n : location;\n }\n\n sharedCtx?.registerCompiler({\n name: '@analogjs/vite-plugin-angular-ngp',\n getTsConfigPath: compilerApi.getTsConfigPath,\n getSourceMap: compilerApi.getSourceMap,\n hasEmitted: compilerApi.hasEmitted,\n });\n\n async function prepareResources(\n file: NgpFile,\n watch: (path: string) => void,\n ): Promise<NgpFile> {\n const hostFilePath = fromAnalyzerPath(file.filePath);\n watch(hostFilePath);\n const activeConfig = sharedCtx?.resolvedConfig ?? resolvedConfig;\n const activeStylePreprocessor =\n sharedCtx?.stylePreprocessor ?? stylePreprocessor;\n\n return {\n ...file,\n classes: await Promise.all(\n file.classes.map(async (metadata, classIndex) => {\n const component = metadata.component;\n if (!component) return metadata;\n if (component.templateUrl)\n watch(fromAnalyzerPath(component.templateUrl.resolvedPath));\n for (const style of component.styleUrls ?? [])\n watch(fromAnalyzerPath(style.resolvedPath));\n const preprocess = async (\n content: string,\n path: string,\n order: number,\n inline: boolean,\n ) => {\n const preprocessed = preprocessStylesheet(\n content,\n path,\n activeStylePreprocessor,\n {\n filename: path,\n containingFile: hostFilePath,\n resourceFile: inline ? undefined : path,\n className: metadata.className,\n order,\n inline,\n },\n );\n const result = await vite.preprocessCSS(\n preprocessed,\n path,\n activeConfig,\n );\n result.deps?.forEach(watch);\n return result.code;\n };\n return {\n ...metadata,\n component: {\n ...component,\n styles:\n component.styles &&\n (await Promise.all(\n component.styles.map((style, index) =>\n preprocess(\n style,\n `${hostFilePath}.inline-${classIndex}-${index}.${options.inlineStylesExtension}`,\n index,\n true,\n ),\n ),\n )),\n stylesFromUrls:\n component.stylesFromUrls &&\n (await Promise.all(\n component.stylesFromUrls.map((style, index) =>\n preprocess(\n style,\n fromAnalyzerPath(\n component.styleUrls![index].resolvedPath,\n ),\n index,\n false,\n ),\n ),\n )),\n },\n };\n }),\n ),\n };\n }\n\n async function indexChunks(update?: () => Promise<string[]>): Promise<void> {\n if (update) {\n const invalidated = await update();\n for (const filePath of invalidated) {\n output.delete(fromAnalyzerPath(filePath));\n compiler!.fileCache.delete(filePath);\n }\n chunkContexts.clear();\n } else {\n filesByPath.clear();\n chunkContexts.clear();\n output.clear();\n const angularOptions = compilerCli.readConfiguration(\n resolveTsConfigPath(),\n ).options as Record<string, unknown>;\n compiler = new api.HybridCompiler(analyzer!, {\n ...angularOptions,\n optimize: true,\n enableHmr: hmr,\n tcbConfig: api.buildTypeCheckingConfig(angularOptions),\n });\n }\n const chunks = update\n ? compiler!.analyzeOptimizedDelta()\n : compiler!.analyzeOptimized();\n for await (const chunk of chunks) {\n for (const file of chunk.files) {\n const normPath = fromAnalyzerPath(file.filePath);\n filesByPath.set(normPath, { file, chunk });\n output.delete(normPath);\n compiler!.fileCache.delete(file.filePath);\n }\n for (const removed of chunk.removedFiles ?? []) {\n const normPath = fromAnalyzerPath(removed);\n filesByPath.delete(normPath);\n output.delete(normPath);\n }\n }\n }\n\n function enqueueIndex(update: () => Promise<string[]>): Promise<void> {\n pending = pending.catch(() => {}).then(() => indexChunks(update));\n return pending;\n }\n\n function getChunkContext(chunk: NgpChunk): Promise<unknown> {\n let context = chunkContexts.get(chunk);\n if (!context) {\n context = compiler!.prepareChunk(chunk);\n chunkContexts.set(chunk, context);\n }\n return context;\n }\n\n async function checkTypes(\n filePath: string,\n sourceCode: string,\n tcbCode?: string | null,\n ): Promise<void> {\n typeChecker ??= new LspTypeChecker(\n resolveTsConfigPath(),\n options.typeChecker,\n {\n inMemoryFiles: () =>\n new Map(\n [...sourceModules].map(([file, { lowered }]) => [\n file,\n lowered.code,\n ]),\n ),\n mapLocation: toSourceLocation,\n },\n );\n typeChecker.queueFile(filePath, sourceCode, tcbCode);\n if (!watchMode) return;\n const typeErrors = await typeChecker.flushQueue(true);\n if (typeErrors.length) {\n throw new Error(typeErrors.join('\\n'));\n }\n }\n\n async function processFile(\n normPath: string,\n activeCompiler: NgpCompiler,\n watch: (path: string) => void,\n ) {\n const { file: analyzed, chunk } = filesByPath.get(normPath)!;\n const [file, context, content] = await Promise.all([\n prepareResources(analyzed, (path) => {\n const key = sourceFileOf(vite.normalizePath(path));\n dependents.set(key, (dependents.get(key) ?? new Set()).add(normPath));\n watch(key);\n }),\n getChunkContext(chunk),\n analyzer!.getFileContent(analyzed.filePath),\n ]);\n sources.set(normPath, content);\n const result =\n activeCompiler.processFile.length >= 5\n ? await activeCompiler.processFile(\n file.filePath,\n content,\n undefined,\n file,\n context,\n )\n : await activeCompiler.processFile(\n file.filePath,\n content,\n file,\n context,\n );\n return { file, content, result };\n }\n\n function compileFile(\n normPath: string,\n watch: (path: string) => void,\n ): Promise<NgpResult> | undefined {\n if (!filesByPath.has(normPath)) return undefined;\n let task = output.get(normPath);\n if (!task) {\n task = (async () => {\n // Analyzer updates queued before this compile land first\n await pending;\n if (!filesByPath.has(normPath)) {\n throw new Error(`${sourceFileOf(normPath)} was removed.`);\n }\n const { file, content, result } = await processFile(\n normPath,\n compiler!,\n watch,\n );\n const errors = [\n ...(file.diagnostics ?? []),\n ...(result.diagnostics ?? []),\n ].filter((diagnostic) => diagnostic.category === 1);\n if (errors.length) {\n throw new Error(\n `${sourceFileOf(normPath)}: ${errors.map((error) => error.messageText).join('\\n')}`,\n );\n }\n if (options.disableTypeChecking !== true) {\n await checkTypes(\n fromAnalyzerPath(file.filePath),\n content,\n result.tcb?.code,\n );\n }\n return result;\n })();\n output.set(normPath, task);\n }\n return task;\n }\n\n function componentNames(normPath: string): string[] {\n return (filesByPath.get(normPath)?.file.classes ?? []).flatMap(\n ({ className, component }) => (component && className ? [className] : []),\n );\n }\n\n // Components to update in place, following the Angular CLI's rule\n async function findComponentUpdates(\n normPath: string,\n read: () => string | Promise<string>,\n ): Promise<ComponentUpdate[]> {\n if (!TS_EXT_REGEX.test(normPath)) {\n return [...(dependents.get(normPath) ?? [])].flatMap((file) =>\n componentNames(file).map((className) => ({ file, className })),\n );\n }\n const stale = sources.get(normPath);\n if (stale === undefined) return [];\n const matchedClassNames = findHmrComponentUpdates(\n normPath,\n stale,\n await read(),\n new Set(componentNames(normPath)),\n );\n return (matchedClassNames ?? []).map((className) => ({\n file: normPath,\n className,\n }));\n }\n\n async function emitHmrUpdate(file: string, className: string) {\n // NGP emits only the update module of the class named by `hmrUpdateTarget`,\n // and only when it doesn't reuse the file's previously processed output\n const target = Object.assign(\n Object.create(Object.getPrototypeOf(compiler)),\n compiler,\n { hmrUpdateTarget: className, reuseProcessedFiles: false },\n );\n const { result } = await processFile(file, target, () => {});\n return (\n result.hmrUpdateModule &&\n (await transpile(result.hmrUpdateModule, file)).code\n );\n }\n\n async function sendComponentUpdates(\n updates: ComponentUpdate[],\n server: vite.ViteDevServer,\n ): Promise<boolean> {\n try {\n for (const file of new Set(updates.map((update) => update.file))) {\n await compileFile(file, () => {});\n }\n const codes = await Promise.all(\n updates.map(({ file, className }) => emitHmrUpdate(file, className)),\n );\n if (codes.some((code) => !code)) return false;\n updates.forEach(({ file, className }, index) => {\n // Components of a source module update through the module itself\n const sourceFile = sourceModules.get(file)?.sourceFile;\n const moduleFile = sourceFile ?? file;\n hmrUpdateCode.set(`${moduleFile}@${className}`, codes[index]!);\n componentUpdates.classNames.set(moduleFile, className);\n server.moduleGraph\n .getModulesByFile(moduleFile)\n ?.forEach((mod) => server.moduleGraph.invalidateModule(mod));\n server.ws.send('angular:component-update', {\n id: encodeURIComponent(`${moduleFile}@${className}`),\n timestamp: Date.now(),\n });\n });\n return true;\n } catch {\n // A full reload reports the compilation error\n return false;\n }\n }\n\n return {\n name: '@analogjs/vite-plugin-angular-ngp',\n enforce: 'pre',\n api: compilerApi,\n config(config, { command, mode }) {\n watchMode = command === 'serve';\n const isProd = isProdMode(config.mode);\n if (sharedCtx) {\n sharedCtx.initConfig(config, { command, mode });\n } else {\n configContext = {\n root: config.root || '.',\n isProd,\n isLib: !!config.build?.lib,\n };\n }\n const depOptimizer = createDepOptimizerConfig({\n tsconfig: resolveTsConfigPath(),\n isProd,\n jit: false,\n watchMode,\n isTest: options.isTest,\n isAstroIntegration: options.isAstroIntegration,\n });\n return {\n ...(isRolldown() ? { oxc: {} as any } : { esbuild: false }),\n ...depOptimizer,\n };\n },\n async configResolved(config) {\n resolvedConfig = config;\n hmr =\n watchMode &&\n options.liveReload &&\n !options.isTest &&\n config.server.hmr !== false;\n const integrations = sharedCtx\n ? await sharedCtx.resolveConfig(config)\n : await discoverAnalogIntegrations(config);\n transformFilter = integrations.transformFilter;\n componentRegistries = integrations.componentRegistries;\n stylePreprocessor = integrations.stylePreprocessor;\n },\n configureServer(server) {\n const changeTypes: Record<string, FileChangeType> = {\n add: 1,\n change: 2,\n unlink: 3,\n };\n devServer = server;\n server.watcher.on('all', (event, path) => {\n const type = changeTypes[event];\n if (type) typeChecker?.notifyFileChanged(path, type);\n });\n server.httpServer?.on('close', () => {\n typeChecker?.close();\n typeChecker = undefined;\n analyzer?.close();\n analyzer = undefined;\n compiler = undefined;\n });\n },\n // Runs on the dev server with or without HMR, and in `vite build --watch`\n async watchChange(id, { event }) {\n if (!analyzer || sourceFormats.length === 0) return;\n const file = canonicalPath(id);\n const resolve: FastCompileResolve = (spec, importer) =>\n this.resolve(spec, importer, { skipSelf: true });\n await withSourceLock(async () => {\n scanner.invalidate(file);\n const format = moduleFormatOf(file);\n if (event === 'update') {\n reloweredByChange.set(\n file,\n await relowerSourceModules(file, resolve),\n );\n } else if (event === 'delete') {\n await removeSourceModule(file);\n } else if (\n event === 'create' &&\n format &&\n !sourceModules.has(`${file}.ts`)\n ) {\n const source = await readSource(file);\n if (source !== undefined) {\n await addSourceModule(file, format, source, resolve);\n }\n }\n await syncProgramFiles();\n });\n // Modules that looked up selectors in `file` lower again when transformed\n for (const importer of scanner.importersByFile.get(file) ?? []) {\n devServer?.moduleGraph\n .getModulesByFile(importer)\n ?.forEach((mod) => devServer!.moduleGraph.invalidateModule(mod));\n }\n },\n async buildStart() {\n activeBuilds++;\n if (!analyzer) {\n const tsconfig = resolveTsConfigPath();\n const hasSourceFormats = sourceFormats.length > 0;\n const ngp = await loadNgp(tsconfig, hasSourceFormats);\n const isWasm = ngp.analyzerOptions.backend === 'wasm';\n toAnalyzerPath = isWasm ? toWasmPath : (path) => path;\n fromAnalyzerPath = isWasm ? fromWasmPath : vite.normalizePath;\n api = ngp.api;\n if (hasSourceFormats) {\n await lowerSourceModules(dirname(tsconfig), (specifier, importer) =>\n this.resolve(specifier, importer, { skipSelf: true }),\n );\n }\n analyzer = await api.createAnalyzer(toAnalyzerPath(tsconfig), {\n ...ngp.analyzerOptions,\n enableHmr: hmr,\n hostFs:\n hasSourceFormats || isWasm\n ? createNgpHostFs(\n hasSourceFormats\n ? (path) => sourceModules.get(path)?.lowered.code\n : undefined,\n )\n : undefined,\n });\n pending = indexChunks();\n }\n await pending;\n for (const path of dependents.keys()) {\n this.addWatchFile(path);\n }\n },\n resolveId(id, importer) {\n return resolveAngularVirtualId(id, importer, {\n jit: false,\n resolvedConfig: sharedCtx?.resolvedConfig ?? resolvedConfig,\n });\n },\n async load(id) {\n return loadAngularVirtualModule(\n this,\n id,\n sharedCtx?.resolvedConfig ?? resolvedConfig,\n );\n },\n async transform(code, id) {\n const activeTransformFilter =\n sharedCtx?.transformFilter ?? transformFilter;\n const filePath = vite.normalizePath(id.split('?')[0]);\n const sourceFormat = scanner.sourceFormatOf(filePath);\n if (\n !(sourceFormat ? sourceFilter(id) : filter(id)) ||\n activeTransformFilter?.(code, id) === false\n ) {\n return;\n }\n await pending;\n let lowered: NgpLoweredModule | undefined;\n let compiledFile = filePath;\n if (sourceFormat) {\n const sourceFile = canonicalPath(filePath);\n const format = moduleFormatOf(sourceFile);\n if (!format) {\n this.error(\n `${filePath} is outside ${dirname(resolveTsConfigPath())}, where '${sourceFormat.name}' modules are compiled from.`,\n );\n }\n lowered = await withSourceLock(async () => {\n const result = await lowerForTransform(\n sourceFile,\n format,\n code,\n (spec, importer) =>\n this.resolve(spec, importer, { skipSelf: true }),\n );\n await syncProgramFiles();\n return result;\n });\n if (!lowered) {\n this.error(`${filePath} was removed while it was compiled.`);\n }\n if (lowered.error) {\n this.error({\n message: lowered.error.message,\n id: filePath,\n loc: lowered.error.loc && { file: filePath, ...lowered.error.loc },\n });\n }\n compiledFile = `${sourceFile}.ts`;\n // Transform the module again when a component it looked up changes\n for (const dependency of scanner.dependenciesOf(sourceFile)) {\n this.addWatchFile(dependency);\n }\n }\n const compiledCode = lowered ? lowered.code : code;\n const watch = (path: string) => this.addWatchFile(path);\n let result: NgpResult | undefined;\n try {\n result = await compileFile(compiledFile, watch);\n } catch (error) {\n // A failed compile stays cached until its file is updated, so only\n // report it if it compiled this content\n if (\n !sources.has(compiledFile) ||\n sources.get(compiledFile) === compiledCode\n ) {\n throw error;\n }\n }\n if (\n filesByPath.has(compiledFile) &&\n sources.get(compiledFile) !== compiledCode\n ) {\n if (lowered) analyzed.set(compiledFile, compiledCode);\n await enqueueIndex(() =>\n analyzer!.updateFileContent([\n {\n filePath: toAnalyzerPath(compiledFile),\n content: compiledCode,\n },\n ]),\n );\n result = await compileFile(compiledFile, watch);\n } else if (!result && lowered) {\n this.error(\n `${filePath} is not part of the TypeScript program of ${resolveTsConfigPath()}. Import it, or add it to the tsconfig's \\`include\\`.`,\n );\n } else if (!result && options.disableTypeChecking !== true) {\n await checkTypes(filePath, code);\n }\n let source = result?.magicString.toString() ?? code;\n if (result) {\n const analyzerFile = filesByPath.get(compiledFile)!.file.filePath;\n if (analyzerFile !== filePath) {\n // Component HMR ids name the analyzer's file; the dev server knows the module\n source = source.replaceAll(\n encodeURIComponent(`${analyzerFile}@`),\n encodeURIComponent(`${filePath}@`),\n );\n }\n }\n const map = result?.magicString.generateMap({\n source: compiledFile,\n includeContent: true,\n hires: true,\n });\n const transpiled = await transpile(source, compiledFile, map);\n const outputMap =\n lowered && transpiled.map\n ? lowered.mapToSource(JSON.stringify(transpiled.map))\n : transpiled.map;\n if (outputMap) {\n emittedMaps.set(\n filePath,\n typeof outputMap === 'string' ? outputMap : JSON.stringify(outputMap),\n );\n }\n return {\n code: transpiled.code,\n map: outputMap as vite.Rollup.SourceMapInput,\n };\n },\n async handleHotUpdate(ctx) {\n if (\n sharedCtx\n ? sharedCtx.hmr.isIgnoredFile(ctx.file)\n : isIgnoredHmrFile(ctx.file)\n ) {\n return [];\n }\n const normPath = vite.normalizePath(ctx.file);\n const sourceFile = canonicalPath(ctx.file);\n const programFile = programFileOf(sourceFile);\n const updates = await withSourceLock(async () => {\n // Lowered again in `watchChange`, which runs first\n const relowered = reloweredByChange.get(sourceFile) ?? [];\n reloweredByChange.delete(sourceFile);\n const lowered = programFile\n ? sourceModules.get(programFile)?.lowered\n : undefined;\n // In place only for a module that lowered without errors, which no\n // other module was lowered again against\n const componentUpdates =\n hmr &&\n !lowered?.error &&\n relowered.every((file) => file === programFile)\n ? await findComponentUpdates(\n programFile ?? normPath,\n lowered ? () => lowered.code : ctx.read,\n )\n : [];\n if (!programFile) {\n await enqueueIndex(() =>\n analyzer!.invalidateFiles([\n { filePath: toAnalyzerPath(ctx.file), updateType: FILE_CHANGED },\n ]),\n );\n }\n await syncProgramFiles();\n return componentUpdates;\n });\n if (updates.length && (await sendComponentUpdates(updates, ctx.server))) {\n return [];\n }\n hmrUpdateCode.clear();\n componentUpdates.classNames.clear();\n ctx.server.moduleGraph.invalidateAll();\n ctx.server.ws.send({ type: 'full-reload' });\n return [];\n },\n async buildEnd(error) {\n if (error || watchMode || !typeChecker) return;\n const typeErrors = await typeChecker.flushQueue();\n if (typeErrors.length) {\n throw new Error(typeErrors.join('\\n'));\n }\n },\n async closeBundle() {\n activeBuilds = Math.max(0, activeBuilds - 1);\n if (watchMode || activeBuilds > 0) return;\n await pending.catch(() => {});\n typeChecker?.close();\n typeChecker = undefined;\n analyzer?.close();\n analyzer = undefined;\n compiler = undefined;\n filesByPath.clear();\n chunkContexts.clear();\n output.clear();\n emittedMaps.clear();\n sources.clear();\n dependents.clear();\n sourceModules.clear();\n analyzed.clear();\n releaseCssPreprocessorWorkers();\n },\n };\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;AAiIA,IAAM,eAAe;AACrB,IAAM,eAAe;AACrB,IAAM,eAAe;AA0BrB,SAAS,qBACP,OACmC;CACnC,OACE,OAAO,UAAU,YACjB,UAAU,QACV,CAAC,sBAAsB,KAAK,KAC5B,oBAAoB,SACpB,OAAQ,MAAmC,mBAAmB;AAElE;AAGA,IAAM,cAAc,IAAA,IAAA,cAAA,KAAA,YAAA,GAAA;;;;;AAMpB,eAAe,QACb,UACA,aAC+D;CAC/D,MAAM,gBAAgB,QAAQ,IAAI;CAClC,IAAI,iBAAiB,aACnB,MAAM,IAAI,MACR,6LACF;CAEF,IAAI,aAAa,QAAQ,IAAI;CAC7B,IAAI,CAAC,YACH,IAAI;EACF,aAAa,cAAc,QAAQ,CAAC,CAAC,QAAQ,cAAc;CAC7D,QAAQ;EACN,IAAI,qBAAqB,QACvB,MAAM,IAAI,MACR,sFACF;EAEF,OAAO;GACL,KAAK,MAAM,OAAO,IAAI,IAAI,WAAW,WAAW,CAAC,CAAC;GAClD,iBAAiB,gBACb,EAAE,cAAc,IAChB;IACE,SAAS;IACT,aAAa,cACX,IAAI,IAAI,kBAAkB,WAAW,CACvC;GACF;EACN;CACF;CAEF,OAAO;EACL,KAAK,MAAM,OAAO,cAAc,QAAQ,UAAU,CAAC,CAAC,CAAC;EACrD,iBAAiB,gBACb,EAAE,cAAc,IAChB,cACE,EAAE,SAAS,OAAO,IAClB,CAAC;CACT;AACF;AAEA,SAAS,UACP,QACA,UACA,KACA;CACA,OAAO,KAAK,mBACR,KAAK,iBACH,QACA,UACA;EAAE,MAAM;EAAM,WAAW;CAAK,GAC9B,GACF,IACA,KAAK,qBACH,QACA,UACA;EAAE,QAAQ;EAAM,WAAW;CAAK,GAChC,GACF;AACN;AAEA,S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OAAO,IAAI,IACrC,IACA,CAAC;IACP,IAAI,CAAC,aACH,MAAM,mBACJ,SAAU,gBAAgB,CACxB;KAAE,UAAU,eAAe,IAAI,IAAI;KAAG,YAAY;IAAa,CACjE,CAAC,CACH;IAEF,MAAM,iBAAiB;IACvB,OAAO;GACT,CAAC;GACD,IAAI,QAAQ,UAAW,MAAM,qBAAqB,SAAS,IAAI,MAAM,GACnE,OAAO,CAAC;GAEV,cAAc,MAAM;GACpB,iBAAiB,WAAW,MAAM;GAClC,IAAI,OAAO,YAAY,cAAc;GACrC,IAAI,OAAO,GAAG,KAAK,EAAE,MAAM,cAAc,CAAC;GAC1C,OAAO,CAAC;EACV;EACA,MAAM,SAAS,OAAO;GACpB,IAAI,SAAS,aAAa,CAAC,aAAa;GACxC,MAAM,aAAa,MAAM,YAAY,WAAW;GAChD,IAAI,WAAW,QACb,MAAM,IAAI,MAAM,WAAW,KAAK,IAAI,CAAC;EAEzC;EACA,MAAM,cAAc;GAClB,eAAe,KAAK,IAAI,GAAG,eAAe,CAAC;GAC3C,IAAI,aAAa,eAAe,GAAG;GACnC,MAAM,QAAQ,YAAY,CAAC,CAAC;GAC5B,aAAa,MAAM;GACnB,cAAc,KAAA;GACd,UAAU,MAAM;GAChB,WAAW,KAAA;GACX,WAAW,KAAA;GACX,YAAY,MAAM;GAClB,cAAc,MAAM;GACpB,OAAO,MAAM;GACb,YAAY,MAAM;GAClB,QAAQ,MAAM;GACd,WAAW,MAAM;GACjB,cAAc,MAAM;GACpB,SAAS,MAAM;GACf,8BAA8B;EAChC;CACF;AACF"}
@@ -568,24 +568,23 @@ function ngtscCompilePlugin(ctxOrOptions) {
568
568
  }
569
569
  }
570
570
  }
571
+ const importers = fileModules.flatMap((mod) => [...mod.importers]);
572
+ if (importers.length === 0) return [];
573
+ importers.forEach((imp) => hmrCtx.server.moduleGraph.invalidateModule(imp));
574
+ await hotUpdates.schedule(hmrCtx.file, importers.map((imp) => imp.id));
571
575
  const mods = [];
572
576
  const updates = [];
573
- fileModules.forEach((mod) => {
574
- mod.importers.forEach((imp) => {
575
- hmrCtx.server.moduleGraph.invalidateModule(imp);
576
- if (ctx.shouldExternalizeStyles() && imp.id && ctx.hmr.classNames.get(imp.id)) updates.push(imp.id);
577
- else mods.push(imp);
578
- });
577
+ importers.forEach((imp) => {
578
+ if (ctx.shouldExternalizeStyles() && imp.id && ctx.hmr.classNames.get(imp.id)) updates.push(imp.id);
579
+ else mods.push(imp);
579
580
  });
580
581
  debugHmrV("resource importer analysis", {
581
582
  file: hmrCtx.file,
582
583
  fileModuleCount: fileModules.length,
583
- importerCount: fileModules.reduce((count, mod) => count + mod.importers.size, 0),
584
+ importerCount: importers.length,
584
585
  updates,
585
586
  mods: mods.map((mod) => mod.id)
586
587
  });
587
- if (mods.length === 0 && updates.length === 0) return mods;
588
- await hotUpdates.schedule(hmrCtx.file, [...mods.map((mod) => mod.id), ...updates]);
589
588
  if (updates.length > 0) {
590
589
  debugHmr("resource importer component updates", {
591
590
  file: hmrCtx.file,