@analogjs/vite-plugin-angular 3.0.0-beta.4 → 3.0.0-beta.41

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (116) hide show
  1. package/ngp/LICENSE +21 -0
  2. package/ngp/api.mjs +46048 -0
  3. package/ngp/build.json +4 -0
  4. package/ngp/ng_analyze.cjs +504 -0
  5. package/ngp/ng_analyze_bg.wasm +0 -0
  6. package/package.json +1 -1
  7. package/src/lib/analog-plugin-interop.js +1 -1
  8. package/src/lib/angular-build-context.d.ts +215 -0
  9. package/src/lib/angular-build-context.js +361 -0
  10. package/src/lib/angular-build-context.js.map +1 -0
  11. package/src/lib/angular-build-optimizer-plugin.d.ts +6 -4
  12. package/src/lib/angular-build-optimizer-plugin.js +10 -5
  13. package/src/lib/angular-build-optimizer-plugin.js.map +1 -1
  14. package/src/lib/angular-jit-plugin.d.ts +5 -3
  15. package/src/lib/angular-jit-plugin.js +14 -6
  16. package/src/lib/angular-jit-plugin.js.map +1 -1
  17. package/src/lib/angular-vite-plugin.d.ts +6 -109
  18. package/src/lib/angular-vite-plugin.js +8 -1246
  19. package/src/lib/angular-vite-plugin.js.map +1 -1
  20. package/src/lib/angular-vitest-plugin.d.ts +3 -2
  21. package/src/lib/angular-vitest-plugin.js +6 -3
  22. package/src/lib/angular-vitest-plugin.js.map +1 -1
  23. package/src/lib/companion-plugins.d.ts +7 -0
  24. package/src/lib/companion-plugins.js +38 -0
  25. package/src/lib/companion-plugins.js.map +1 -0
  26. package/src/lib/compilation-api/compilation-api-plugin.d.ts +11 -2
  27. package/src/lib/compilation-api/compilation-api-plugin.js +154 -282
  28. package/src/lib/compilation-api/compilation-api-plugin.js.map +1 -1
  29. package/src/lib/compiler/compile.d.ts +1 -1
  30. package/src/lib/compiler/compile.js +158 -143
  31. package/src/lib/compiler/compile.js.map +1 -1
  32. package/src/lib/compiler/defer.d.ts +2 -3
  33. package/src/lib/compiler/defer.js +11 -13
  34. package/src/lib/compiler/defer.js.map +1 -1
  35. package/src/lib/compiler/dts-reader.d.ts +6 -1
  36. package/src/lib/compiler/dts-reader.js +19 -10
  37. package/src/lib/compiler/dts-reader.js.map +1 -1
  38. package/src/lib/compiler/hmr.d.ts +4 -0
  39. package/src/lib/compiler/hmr.js +7 -2
  40. package/src/lib/compiler/hmr.js.map +1 -1
  41. package/src/lib/compiler/index.d.ts +2 -2
  42. package/src/lib/compiler/index.js +4 -4
  43. package/src/lib/compiler/jit-metadata.d.ts +3 -1
  44. package/src/lib/compiler/jit-metadata.js +10 -8
  45. package/src/lib/compiler/jit-metadata.js.map +1 -1
  46. package/src/lib/compiler/jit-transform.js +2 -2
  47. package/src/lib/compiler/jit-transform.js.map +1 -1
  48. package/src/lib/compiler/js-emitter.d.ts +0 -3
  49. package/src/lib/compiler/js-emitter.js +3 -21
  50. package/src/lib/compiler/js-emitter.js.map +1 -1
  51. package/src/lib/compiler/registry.d.ts +7 -1
  52. package/src/lib/compiler/registry.js +23 -3
  53. package/src/lib/compiler/registry.js.map +1 -1
  54. package/src/lib/compiler/resource-inliner.d.ts +8 -9
  55. package/src/lib/compiler/resource-inliner.js +10 -18
  56. package/src/lib/compiler/resource-inliner.js.map +1 -1
  57. package/src/lib/compiler/style-ast.d.ts +9 -1
  58. package/src/lib/compiler/style-ast.js +26 -5
  59. package/src/lib/compiler/style-ast.js.map +1 -1
  60. package/src/lib/compiler/type-elision.d.ts +4 -3
  61. package/src/lib/compiler/type-elision.js +10 -11
  62. package/src/lib/compiler/type-elision.js.map +1 -1
  63. package/src/lib/compiler/utils.d.ts +14 -7
  64. package/src/lib/compiler/utils.js +38 -9
  65. package/src/lib/compiler/utils.js.map +1 -1
  66. package/src/lib/component-styles-plugin.d.ts +52 -0
  67. package/src/lib/component-styles-plugin.js +353 -0
  68. package/src/lib/component-styles-plugin.js.map +1 -0
  69. package/src/lib/compose-angular-plugins.d.ts +12 -0
  70. package/src/lib/compose-angular-plugins.js +31 -0
  71. package/src/lib/compose-angular-plugins.js.map +1 -0
  72. package/src/lib/dev-server-mode-plugin.d.ts +7 -0
  73. package/src/lib/dev-server-mode-plugin.js +23 -0
  74. package/src/lib/dev-server-mode-plugin.js.map +1 -0
  75. package/src/lib/fast-compile-plugin.d.ts +6 -1
  76. package/src/lib/fast-compile-plugin.js +209 -79
  77. package/src/lib/fast-compile-plugin.js.map +1 -1
  78. package/src/lib/host.d.ts +3 -0
  79. package/src/lib/host.js +4 -2
  80. package/src/lib/host.js.map +1 -1
  81. package/src/lib/live-reload-plugin.d.ts +6 -3
  82. package/src/lib/live-reload-plugin.js +13 -6
  83. package/src/lib/live-reload-plugin.js.map +1 -1
  84. package/src/lib/ngp-compile-plugin.d.ts +4 -0
  85. package/src/lib/ngp-compile-plugin.js +410 -0
  86. package/src/lib/ngp-compile-plugin.js.map +1 -0
  87. package/src/lib/ngtsc-compile-plugin.d.ts +23 -0
  88. package/src/lib/ngtsc-compile-plugin.js +763 -0
  89. package/src/lib/ngtsc-compile-plugin.js.map +1 -0
  90. package/src/lib/nx-folder-plugin.d.ts +6 -5
  91. package/src/lib/nx-folder-plugin.js +12 -7
  92. package/src/lib/nx-folder-plugin.js.map +1 -1
  93. package/src/lib/plugins/file-replacements.plugin.d.ts +6 -0
  94. package/src/lib/plugins/file-replacements.plugin.js +1 -0
  95. package/src/lib/plugins/file-replacements.plugin.js.map +1 -1
  96. package/src/lib/router-plugin.d.ts +5 -1
  97. package/src/lib/router-plugin.js +13 -4
  98. package/src/lib/router-plugin.js.map +1 -1
  99. package/src/lib/utils/compilation-shared.js +1 -1
  100. package/src/lib/utils/devkit.js +1 -1
  101. package/src/lib/utils/hmr-component-updates.d.ts +7 -0
  102. package/src/lib/utils/hmr-component-updates.js +87 -0
  103. package/src/lib/utils/hmr-component-updates.js.map +1 -0
  104. package/src/lib/utils/lsp-type-checker.d.ts +55 -0
  105. package/src/lib/utils/lsp-type-checker.js +502 -0
  106. package/src/lib/utils/lsp-type-checker.js.map +1 -0
  107. package/src/lib/utils/plugin-config.d.ts +15 -8
  108. package/src/lib/utils/plugin-config.js +18 -5
  109. package/src/lib/utils/plugin-config.js.map +1 -1
  110. package/src/lib/utils/stylesheet-warning.d.ts +2 -0
  111. package/src/lib/utils/stylesheet-warning.js +11 -0
  112. package/src/lib/utils/stylesheet-warning.js.map +1 -0
  113. package/src/lib/utils/tsconfig-resolver.js +1 -1
  114. package/src/lib/virtual-modules-plugin.d.ts +11 -3
  115. package/src/lib/virtual-modules-plugin.js +43 -12
  116. package/src/lib/virtual-modules-plugin.js.map +1 -1
@@ -1,25 +1,32 @@
1
- import { TS_EXT_REGEX, createDepOptimizerConfig, getTsConfigPath, isProdMode } from "./utils/plugin-config.js";
2
1
  import { discoverAnalogIntegrations } from "./analog-plugin-interop.js";
2
+ import { preprocessStylesheet } from "./stylesheet-registry.js";
3
+ import { isIgnoredHmrFile } from "./utils/compilation-shared.js";
4
+ import { isRolldown } from "./utils/rolldown.js";
5
+ import { EXCLUDED_TS_EXT_REGEX, TS_EXT_REGEX, createDepOptimizerConfig, getTsConfigPath, isProdMode } from "./utils/plugin-config.js";
6
+ import { reportStylesheetError } from "./utils/stylesheet-warning.js";
7
+ import { TsconfigResolver } from "./utils/tsconfig-resolver.js";
8
+ import { createAngularBuildContext, isAngularBuildContext } from "./angular-build-context.js";
3
9
  import { releaseCssPreprocessorWorkers } from "./utils/css-preprocessor-workers.js";
4
- import { toVirtualRawId } from "./utils/virtual-ids.js";
5
- import { loadVirtualRawModule, rewriteHtmlRawImport } from "./utils/virtual-resources.js";
10
+ import { loadAngularVirtualModule, resolveAngularVirtualId } from "./virtual-modules-plugin.js";
6
11
  import { ANGULAR_DECORATOR_CALL_RE } from "./compiler/constants.js";
7
- import { debugCompile, debugRegistry } from "./compiler/debug.js";
12
+ import { parseOxc } from "./compiler/utils.js";
13
+ import { debugRegistry } from "./compiler/debug.js";
8
14
  import { compile } from "./compiler/compile.js";
9
- import { scanFile } from "./compiler/registry.js";
10
- import { collectAllImports, collectImportedPackages, collectRelativeReExports, scanPackageDts } from "./compiler/dts-reader.js";
15
+ import { declaresNonStandaloneComponent, scanFile } from "./compiler/registry.js";
16
+ import { collectAllImports, collectImportedPackages, collectReExports, collectRelativeReExports, scanPackageDts } from "./compiler/dts-reader.js";
11
17
  import { jitTransform } from "./compiler/jit-transform.js";
12
18
  import { generateHmrCode } from "./compiler/hmr.js";
13
19
  import { extractInlineStyles, inlineResourceUrls } from "./compiler/resource-inliner.js";
14
20
  import "./compiler/index.js";
15
- import { markStylePathSafe } from "./utils/safe-module-paths.js";
16
21
  import { promises } from "node:fs";
17
- import { dirname, isAbsolute, resolve } from "node:path";
22
+ import { dirname, resolve } from "node:path";
18
23
  import * as vite from "vite";
19
24
  import { normalizePath, preprocessCSS } from "vite";
20
25
  import * as compilerCli from "@angular/compiler-cli";
21
- import { parseSync } from "oxc-parser";
22
26
  //#region packages/vite-plugin-angular/src/lib/fast-compile-plugin.ts
27
+ function isFastCompilePluginOptions(value) {
28
+ return typeof value === "object" && value !== null && !isAngularBuildContext(value) && "tsconfigGetter" in value && typeof value.tsconfigGetter === "function";
29
+ }
23
30
  /**
24
31
  * Directory that `compilerOptions.paths` targets resolve against. Mirrors
25
32
  * TypeScript: `baseUrl` when set, otherwise the directory of the config
@@ -29,17 +36,34 @@ import { parseSync } from "oxc-parser";
29
36
  function getPathsBasePath(options, fallback) {
30
37
  return options?.baseUrl ?? options?.pathsBasePath ?? fallback;
31
38
  }
32
- function fastCompilePlugin(pluginOptions) {
39
+ function fastCompilePlugin(optionsOrCtx) {
40
+ const sharedCtx = isAngularBuildContext(optionsOrCtx) ? optionsOrCtx : isFastCompilePluginOptions(optionsOrCtx) ? void 0 : createAngularBuildContext({
41
+ ...optionsOrCtx,
42
+ compilationBackend: "fast"
43
+ });
44
+ const pluginOptions = sharedCtx ? sharedCtx.options : optionsOrCtx;
45
+ const tsconfigResolver = sharedCtx?.tsconfigResolver ?? new TsconfigResolver({
46
+ workspaceRoot: pluginOptions.workspaceRoot,
47
+ include: pluginOptions.include ?? [],
48
+ liveReload: pluginOptions.liveReload,
49
+ isTest: pluginOptions.isTest
50
+ });
33
51
  let resolvedConfig;
34
52
  let transformFilter;
35
53
  let componentRegistries = [];
54
+ let stylePreprocessor;
36
55
  let tsConfigResolutionContext = null;
37
56
  let watchMode = false;
38
57
  const registry = /* @__PURE__ */ new Map();
39
58
  const resourceToSource = /* @__PURE__ */ new Map();
40
59
  const scannedDtsPackages = /* @__PURE__ */ new Set();
60
+ const emittedMaps = /* @__PURE__ */ new Map();
41
61
  let projectRoot = "";
42
62
  let useDefineForClassFields = true;
63
+ let tsConfig;
64
+ const lazyScans = /* @__PURE__ */ new Map();
65
+ const importersByFile = /* @__PURE__ */ new Map();
66
+ let projectScan;
43
67
  /**
44
68
  * Scan a file into the registry, then recursively walk its relative
45
69
  * `export *` / `export { … } from './x'` chain so any underlying
@@ -69,7 +93,7 @@ function fastCompilePlugin(pluginOptions) {
69
93
  }
70
94
  let program;
71
95
  try {
72
- program = parseSync(file, code).program;
96
+ program = parseOxc(file, code).program;
73
97
  } catch {
74
98
  program = void 0;
75
99
  }
@@ -94,14 +118,23 @@ function fastCompilePlugin(pluginOptions) {
94
118
  }
95
119
  }
96
120
  async function initFastCompile() {
121
+ emittedMaps.clear();
97
122
  if (pluginOptions.jit) return;
98
123
  registry.clear();
99
124
  scannedDtsPackages.clear();
125
+ lazyScans.clear();
126
+ importersByFile.clear();
127
+ projectScan = void 0;
100
128
  const resolvedTsConfigPath = resolveTsConfigPath();
101
129
  projectRoot = dirname(resolvedTsConfigPath);
102
- const config = compilerCli.readConfiguration(resolvedTsConfigPath);
103
- useDefineForClassFields = config.options?.useDefineForClassFields ?? true;
104
- const candidates = new Set(config.rootNames);
130
+ tsConfig = compilerCli.readConfiguration(resolvedTsConfigPath);
131
+ useDefineForClassFields = tsConfig.options?.useDefineForClassFields ?? true;
132
+ }
133
+ /** Scan all source files reachable from the tsconfig into the registry. */
134
+ async function scanProject() {
135
+ const config = tsConfig;
136
+ const extraIncludes = tsconfigResolver.ensureIncludeCache();
137
+ const candidates = /* @__PURE__ */ new Set([...config.rootNames, ...extraIncludes]);
105
138
  const tsPaths = config.options?.paths;
106
139
  const baseUrl = getPathsBasePath(config.options, projectRoot);
107
140
  const fileContents = /* @__PURE__ */ new Map();
@@ -172,7 +205,7 @@ function fastCompilePlugin(pluginOptions) {
172
205
  }
173
206
  let program;
174
207
  try {
175
- program = parseSync(file, code).program;
208
+ program = parseOxc(file, code).program;
176
209
  } catch {
177
210
  program = void 0;
178
211
  }
@@ -201,7 +234,8 @@ function fastCompilePlugin(pluginOptions) {
201
234
  }));
202
235
  await Promise.all(targets.filter((t) => !!t).map((t) => walkImports(t)));
203
236
  };
204
- await Promise.all(config.rootNames.map((file) => walkImports(file)));
237
+ const walkRoots = [.../* @__PURE__ */ new Set([...config.rootNames, ...extraIncludes])];
238
+ await Promise.all(walkRoots.map((file) => walkImports(file)));
205
239
  const buildStartVisited = /* @__PURE__ */ new Set();
206
240
  if (tsPaths) {
207
241
  const barrelCandidates = [];
@@ -223,7 +257,67 @@ function fastCompilePlugin(pluginOptions) {
223
257
  } catch {}
224
258
  }
225
259
  }
226
- async function handleFastCompileTransform(code, id) {
260
+ /**
261
+ * Scan the source files `id` imports into the registry on demand and record
262
+ * `id` as their importer, so a metadata change in any of them recompiles it.
263
+ */
264
+ async function resolveImportedDeclarations(code, id, program, resolveImport) {
265
+ await Promise.all(collectAllImports(code, id, program).map(async (spec) => {
266
+ const file = await resolveImport(spec, id);
267
+ if (!file) return;
268
+ for (const scanned of await scanOnDemand(file, resolveImport)) {
269
+ let importers = importersByFile.get(scanned);
270
+ if (!importers) {
271
+ importers = /* @__PURE__ */ new Set();
272
+ importersByFile.set(scanned, importers);
273
+ }
274
+ importers.add(id);
275
+ }
276
+ }));
277
+ }
278
+ function scanOnDemand(file, resolveImport) {
279
+ let scan = lazyScans.get(file);
280
+ if (!scan) {
281
+ scan = scanWithReExports(file, resolveImport);
282
+ lazyScans.set(file, scan);
283
+ }
284
+ return scan;
285
+ }
286
+ /**
287
+ * Scan a file and everything it re-exports, resolving specifiers through
288
+ * Vite so path aliases work. Tuple barrels and NgModules can list classes
289
+ * their file imports without re-exporting, so their imports are followed
290
+ * too. Returns every file scanned.
291
+ */
292
+ async function scanWithReExports(file, resolveImport) {
293
+ const visited = /* @__PURE__ */ new Set();
294
+ const visit = async (current) => {
295
+ if (visited.has(current)) return;
296
+ visited.add(current);
297
+ let code;
298
+ let program;
299
+ try {
300
+ code = await promises.readFile(current, "utf-8");
301
+ program = parseOxc(current, code).program;
302
+ } catch {
303
+ return;
304
+ }
305
+ const entries = scanFile(code, current, program);
306
+ for (const entry of entries) if (!registry.has(entry.className)) registry.set(entry.className, entry);
307
+ ensureDtsRegistryForSource(code, current, program);
308
+ const specifiers = entries.some((e) => e.kind === "tuple" || e.kind === "ngmodule") ? collectAllImports(code, current, program) : collectReExports(code, current, program);
309
+ for (const spec of specifiers) {
310
+ const dep = await resolveImport(spec, current);
311
+ if (dep) await visit(dep);
312
+ }
313
+ };
314
+ await visit(file);
315
+ return visited;
316
+ }
317
+ function registryEntriesOf(file) {
318
+ return [...registry.values()].filter((e) => e.fileName === file);
319
+ }
320
+ async function handleFastCompileTransform(code, id, resolveImport) {
227
321
  if (!ANGULAR_DECORATOR_CALL_RE.test(code)) {
228
322
  const stripped = vite.transformWithOxc ? await vite.transformWithOxc(code, id, {
229
323
  lang: "ts",
@@ -262,35 +356,44 @@ function fastCompilePlugin(pluginOptions) {
262
356
  }
263
357
  const inlined = await inlineResourceUrls(code, id);
264
358
  code = inlined.code;
265
- const { styleExtensions } = inlined;
359
+ const { stylePaths } = inlined;
266
360
  for (const dep of inlined.resourceDependencies) resourceToSource.set(dep, id);
267
- const { program: oxcProgram } = parseSync(id, code);
361
+ const { program: oxcProgram } = parseOxc(id, code);
268
362
  let resolvedInlineStyles;
269
- const inlineExt = pluginOptions.inlineStylesExtension;
270
- const styleNeedsPreprocess = (ext) => ext !== "" && ext !== "css";
271
- if (styleNeedsPreprocess(inlineExt) || styleExtensions.size > 0) {
272
- const styleStrings = extractInlineStyles(code, id, oxcProgram);
273
- if (styleStrings.length > 0) {
274
- resolvedInlineStyles = /* @__PURE__ */ new Map();
275
- for (let i = 0; i < styleStrings.length; i++) {
276
- const ext = styleExtensions.get(i) ?? inlineExt;
277
- if (!styleNeedsPreprocess(ext)) continue;
278
- try {
279
- const fakePath = id.replace(/\.ts$/, `.inline-${i}.${ext}`);
280
- const processed = await preprocessCSS(styleStrings[i], fakePath, resolvedConfig);
281
- resolvedInlineStyles.set(i, processed.code);
282
- } catch (e) {
283
- if (debugCompile.enabled) debugCompile("inline style #%d preprocessing failed in %s: %s", i, id, e?.message);
284
- }
363
+ const styleStrings = extractInlineStyles(code, id, oxcProgram);
364
+ if (styleStrings.length > 0) {
365
+ resolvedInlineStyles = /* @__PURE__ */ new Map();
366
+ const activeConfig = sharedCtx?.resolvedConfig ?? resolvedConfig;
367
+ const activeStylePreprocessor = sharedCtx?.stylePreprocessor ?? stylePreprocessor;
368
+ for (let i = 0; i < styleStrings.length; i++) {
369
+ const stylePath = stylePaths.get(i) ?? id.replace(/\.ts$/, `.inline-${i}.${pluginOptions.inlineStylesExtension || "css"}`);
370
+ try {
371
+ const preprocessed = preprocessStylesheet(styleStrings[i], stylePath, activeStylePreprocessor, {
372
+ filename: stylePath,
373
+ containingFile: id,
374
+ order: i,
375
+ inline: !stylePaths.has(i)
376
+ });
377
+ const processed = await preprocessCSS(preprocessed, stylePath, activeConfig);
378
+ resolvedInlineStyles.set(i, processed.code);
379
+ } catch (e) {
380
+ reportStylesheetError(activeConfig?.logger, stylePath, e, activeConfig?.command === "build");
285
381
  }
286
- if (resolvedInlineStyles.size === 0) resolvedInlineStyles = void 0;
287
382
  }
383
+ if (resolvedInlineStyles.size === 0) resolvedInlineStyles = void 0;
288
384
  }
289
385
  ensureDtsRegistryForSource(code, id, oxcProgram);
386
+ for (const entry of scanFile(code, id, oxcProgram)) registry.set(entry.className, entry);
387
+ await resolveImportedDeclarations(code, id, oxcProgram, resolveImport);
388
+ if (declaresNonStandaloneComponent(oxcProgram)) {
389
+ projectScan ??= scanProject();
390
+ await projectScan;
391
+ }
392
+ const activeComponentRegistries = sharedCtx ? sharedCtx.componentRegistries : componentRegistries;
290
393
  let compileRegistry = registry;
291
- if (componentRegistries.some((external) => external.size > 0)) {
394
+ if (activeComponentRegistries.some((external) => external.size > 0)) {
292
395
  compileRegistry = new Map(registry);
293
- for (const external of componentRegistries) for (const [k, v] of external) compileRegistry.set(k, v);
396
+ for (const external of activeComponentRegistries) for (const [k, v] of external) compileRegistry.set(k, v);
294
397
  }
295
398
  const result = compile(code, id, {
296
399
  registry: compileRegistry,
@@ -312,8 +415,8 @@ function fastCompilePlugin(pluginOptions) {
312
415
  sourcemap: true
313
416
  }, result.map);
314
417
  let outputCode = stripped.code;
315
- if (watchMode && pluginOptions.liveReload) {
316
- const fileDeclarations = [...registry.values()].filter((e) => e.fileName === id);
418
+ if ((sharedCtx ? sharedCtx.watchMode : watchMode) && pluginOptions.liveReload) {
419
+ const fileDeclarations = registryEntriesOf(id);
317
420
  if (fileDeclarations.length > 0) {
318
421
  const localDepClassNames = fileDeclarations.map((e) => e.className);
319
422
  outputCode += generateHmrCode(fileDeclarations, localDepClassNames);
@@ -325,17 +428,38 @@ function fastCompilePlugin(pluginOptions) {
325
428
  };
326
429
  }
327
430
  function resolveTsConfigPath() {
328
- const { root, isProd, isLib } = tsConfigResolutionContext;
329
- return getTsConfigPath(root, pluginOptions.tsconfigGetter(), isProd, pluginOptions.isTest, isLib, pluginOptions.workspaceRoot);
431
+ if (sharedCtx) return sharedCtx.resolveTsConfigPath();
432
+ const resolution = tsConfigResolutionContext ?? {
433
+ root: resolvedConfig?.root || ".",
434
+ isProd: isProdMode(resolvedConfig?.mode),
435
+ isLib: !!resolvedConfig?.build?.lib
436
+ };
437
+ return getTsConfigPath(resolution.root, pluginOptions.tsconfigGetter(), resolution.isProd, pluginOptions.isTest, resolution.isLib, pluginOptions.workspaceRoot);
330
438
  }
439
+ const compilerApi = {
440
+ angularCompiler: true,
441
+ getTsConfigPath: resolveTsConfigPath,
442
+ getSourceMap: (id) => emittedMaps.get(normalizePath(id)),
443
+ hasEmitted: (id) => emittedMaps.has(normalizePath(id))
444
+ };
445
+ sharedCtx?.registerCompiler({
446
+ name: "@analogjs/vite-plugin-angular-fast-compile",
447
+ getTsConfigPath: compilerApi.getTsConfigPath,
448
+ getSourceMap: compilerApi.getSourceMap,
449
+ hasEmitted: compilerApi.hasEmitted
450
+ });
331
451
  return {
332
452
  name: "@analogjs/vite-plugin-angular-fast-compile",
333
- api: { getTsConfigPath: resolveTsConfigPath },
453
+ api: compilerApi,
334
454
  enforce: "pre",
335
- async config(config, { command }) {
455
+ async config(config, { command, mode }) {
336
456
  watchMode = command === "serve";
337
457
  const isProd = isProdMode(config.mode);
338
- tsConfigResolutionContext = {
458
+ if (sharedCtx) sharedCtx.initConfig(config, {
459
+ command,
460
+ mode
461
+ });
462
+ else tsConfigResolutionContext = {
339
463
  root: config.root || ".",
340
464
  isProd,
341
465
  isLib: !!config?.build?.lib
@@ -350,28 +474,36 @@ function fastCompilePlugin(pluginOptions) {
350
474
  isAstroIntegration: pluginOptions.isAstroIntegration
351
475
  });
352
476
  return {
353
- ...vite.rolldownVersion ? { oxc: {} } : { esbuild: false },
477
+ ...isRolldown() ? { oxc: {} } : { esbuild: false },
354
478
  ...depOptimizer
355
479
  };
356
480
  },
357
481
  async configResolved(config) {
358
482
  resolvedConfig = config;
359
- const integrations = await discoverAnalogIntegrations(config);
360
- transformFilter = integrations.transformFilter;
361
- componentRegistries = integrations.componentRegistries;
362
- },
363
- configureServer(server) {
364
- server.watcher.on("add", async (filePath) => {
365
- if (filePath.endsWith(".ts") && !filePath.endsWith(".spec.ts") && !filePath.endsWith(".d.ts")) await scanBarrelExports(filePath, /* @__PURE__ */ new Set(), true);
366
- });
483
+ if (sharedCtx) {
484
+ const integrations = await sharedCtx.resolveConfig(config);
485
+ transformFilter = integrations.transformFilter;
486
+ componentRegistries = integrations.componentRegistries;
487
+ stylePreprocessor = integrations.stylePreprocessor;
488
+ } else {
489
+ const integrations = await discoverAnalogIntegrations(config);
490
+ transformFilter = integrations.transformFilter;
491
+ componentRegistries = integrations.componentRegistries;
492
+ stylePreprocessor = integrations.stylePreprocessor;
493
+ tsconfigResolver.setIntegrationIncludes(integrations.include);
494
+ }
367
495
  },
368
496
  async buildStart() {
369
497
  await initFastCompile();
370
498
  },
371
499
  closeBundle() {
372
- if (!watchMode) releaseCssPreprocessorWorkers();
500
+ if (!(sharedCtx ? sharedCtx.watchMode : watchMode)) {
501
+ emittedMaps.clear();
502
+ releaseCssPreprocessorWorkers();
503
+ }
373
504
  },
374
505
  async handleHotUpdate(ctx) {
506
+ if (sharedCtx ? sharedCtx.hmr.isIgnoredFile(ctx.file) : isIgnoredHmrFile(ctx.file)) return [];
375
507
  if (resourceToSource.has(ctx.file)) {
376
508
  const parentSource = resourceToSource.get(ctx.file);
377
509
  const parentModule = ctx.server.moduleGraph.getModuleById(parentSource);
@@ -379,35 +511,25 @@ function fastCompilePlugin(pluginOptions) {
379
511
  }
380
512
  if (TS_EXT_REGEX.test(ctx.file)) {
381
513
  const [fileId] = ctx.file.split("?");
382
- const oldEntries = [...registry.entries()].filter(([_, v]) => v.fileName === fileId).map(([k]) => k);
383
- for (const key of oldEntries) registry.delete(key);
514
+ const oldEntries = registryEntriesOf(fileId);
515
+ for (const entry of oldEntries) registry.delete(entry.className);
384
516
  await scanBarrelExports(fileId, /* @__PURE__ */ new Set(), true);
517
+ lazyScans.clear();
518
+ if (JSON.stringify(oldEntries) !== JSON.stringify(registryEntriesOf(fileId))) {
519
+ const importerModules = [...importersByFile.get(fileId) ?? []].flatMap((importer) => [...ctx.server.moduleGraph.getModulesByFile(importer) ?? []]);
520
+ return [...ctx.modules, ...importerModules];
521
+ }
385
522
  }
386
523
  return ctx.modules;
387
524
  },
388
525
  resolveId(id, importer) {
389
- if (id.startsWith("virtual:@analogjs/vite-plugin-angular:raw:")) return `\0${id}`;
390
- if (pluginOptions.jit && id.startsWith("angular:jit:")) {
391
- const filePath = normalizePath(resolve(dirname(importer), id.split(";")[1]));
392
- if (id.includes(":style")) {
393
- markStylePathSafe(resolvedConfig, filePath);
394
- return filePath + "?inline";
395
- }
396
- return toVirtualRawId(filePath);
397
- }
398
- const rawRewrite = rewriteHtmlRawImport(id, importer);
399
- if (rawRewrite) return rawRewrite;
400
- if (/\.(css|scss|sass|less)\?inline$/.test(id) && importer) {
401
- const filePath = id.split("?")[0];
402
- const resolved = isAbsolute(filePath) ? normalizePath(filePath) : normalizePath(resolve(dirname(importer), filePath));
403
- markStylePathSafe(resolvedConfig, resolved);
404
- return resolved + "?inline";
405
- }
526
+ return resolveAngularVirtualId(id, importer, {
527
+ jit: pluginOptions.jit,
528
+ resolvedConfig: sharedCtx?.resolvedConfig ?? resolvedConfig
529
+ });
406
530
  },
407
531
  async load(id) {
408
- const rawModule = await loadVirtualRawModule(this, id);
409
- if (rawModule !== void 0) return rawModule;
410
- if (/\.(css|scss|sass|less)\?inline$/.test(id)) markStylePathSafe(resolvedConfig, id.split("?")[0]);
532
+ return loadAngularVirtualModule(this, id, sharedCtx?.resolvedConfig ?? resolvedConfig);
411
533
  },
412
534
  transform: {
413
535
  filter: { id: {
@@ -420,9 +542,17 @@ function fastCompilePlugin(pluginOptions) {
420
542
  ]
421
543
  } },
422
544
  async handler(code, id) {
423
- if (transformFilter && !transformFilter(code, id)) return;
545
+ const activeTransformFilter = sharedCtx?.transformFilter ?? transformFilter;
546
+ if (activeTransformFilter && !activeTransformFilter(code, id)) return;
424
547
  if (id.includes(".ts?")) id = id.replace(/\?(.*)/, "");
425
- return handleFastCompileTransform(code, id);
548
+ const transformed = await handleFastCompileTransform(code, id, async (spec, importer) => {
549
+ const resolved = await this.resolve(spec, importer, { skipSelf: true });
550
+ if (!resolved || resolved.external) return null;
551
+ const file = normalizePath(resolved.id.split("?")[0]);
552
+ return TS_EXT_REGEX.test(file) && !EXCLUDED_TS_EXT_REGEX.test(file) && !file.includes("/node_modules/") ? file : null;
553
+ });
554
+ if (transformed?.map) emittedMaps.set(normalizePath(id), typeof transformed.map === "string" ? transformed.map : JSON.stringify(transformed.map));
555
+ return transformed;
426
556
  }
427
557
  }
428
558
  };