@analogjs/vite-plugin-angular 3.0.0-beta.6 → 3.0.0-beta.61

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (161) hide show
  1. package/migrations/migrate-setup-vitest/migrate-setup-vitest.js +3 -3
  2. package/migrations/migrate-setup-vitest/migrate-setup-vitest.js.map +1 -1
  3. package/ngp/LICENSE +21 -0
  4. package/ngp/api.mjs +46806 -0
  5. package/ngp/build.json +4 -0
  6. package/ngp/ng_analyze.cjs +601 -0
  7. package/ngp/ng_analyze_bg.wasm +0 -0
  8. package/package.json +5 -2
  9. package/src/index.d.ts +2 -0
  10. package/src/index.js +4 -3
  11. package/src/index.js.map +1 -1
  12. package/src/lib/analog-plugin-interop.js +2 -3
  13. package/src/lib/angular-build-context.d.ts +215 -0
  14. package/src/lib/angular-build-context.js +360 -0
  15. package/src/lib/angular-build-context.js.map +1 -0
  16. package/src/lib/angular-build-optimizer-plugin.d.ts +6 -4
  17. package/src/lib/angular-build-optimizer-plugin.js +25 -11
  18. package/src/lib/angular-build-optimizer-plugin.js.map +1 -1
  19. package/src/lib/angular-jit-plugin.d.ts +5 -3
  20. package/src/lib/angular-jit-plugin.js +16 -9
  21. package/src/lib/angular-jit-plugin.js.map +1 -1
  22. package/src/lib/angular-vite-plugin.d.ts +6 -109
  23. package/src/lib/angular-vite-plugin.js +9 -1251
  24. package/src/lib/angular-vite-plugin.js.map +1 -1
  25. package/src/lib/angular-vitest-plugin.d.ts +3 -2
  26. package/src/lib/angular-vitest-plugin.js +7 -5
  27. package/src/lib/angular-vitest-plugin.js.map +1 -1
  28. package/src/lib/companion-plugins.d.ts +7 -0
  29. package/src/lib/companion-plugins.js +37 -0
  30. package/src/lib/companion-plugins.js.map +1 -0
  31. package/src/lib/compilation-api/compilation-api-plugin.d.ts +11 -2
  32. package/src/lib/compilation-api/compilation-api-plugin.js +156 -285
  33. package/src/lib/compilation-api/compilation-api-plugin.js.map +1 -1
  34. package/src/lib/compilation-api/index.js +1 -2
  35. package/src/lib/compiler/angular-version.js +0 -1
  36. package/src/lib/compiler/class-field-lowering.js +1 -2
  37. package/src/lib/compiler/compile.d.ts +1 -1
  38. package/src/lib/compiler/compile.js +224 -151
  39. package/src/lib/compiler/compile.js.map +1 -1
  40. package/src/lib/compiler/constants.js +1 -2
  41. package/src/lib/compiler/debug.js +1 -2
  42. package/src/lib/compiler/defer.d.ts +2 -3
  43. package/src/lib/compiler/defer.js +13 -16
  44. package/src/lib/compiler/defer.js.map +1 -1
  45. package/src/lib/compiler/dts-reader.d.ts +6 -1
  46. package/src/lib/compiler/dts-reader.js +20 -12
  47. package/src/lib/compiler/dts-reader.js.map +1 -1
  48. package/src/lib/compiler/hmr.d.ts +4 -0
  49. package/src/lib/compiler/hmr.js +8 -4
  50. package/src/lib/compiler/hmr.js.map +1 -1
  51. package/src/lib/compiler/index.d.ts +2 -2
  52. package/src/lib/compiler/index.js +6 -6
  53. package/src/lib/compiler/jit-metadata.js +1 -2
  54. package/src/lib/compiler/jit-transform.js +37 -15
  55. package/src/lib/compiler/jit-transform.js.map +1 -1
  56. package/src/lib/compiler/js-emitter.d.ts +0 -3
  57. package/src/lib/compiler/js-emitter.js +4 -23
  58. package/src/lib/compiler/js-emitter.js.map +1 -1
  59. package/src/lib/compiler/metadata.js +2 -3
  60. package/src/lib/compiler/registry.d.ts +7 -1
  61. package/src/lib/compiler/registry.js +24 -5
  62. package/src/lib/compiler/registry.js.map +1 -1
  63. package/src/lib/compiler/resource-inliner.d.ts +8 -9
  64. package/src/lib/compiler/resource-inliner.js +11 -20
  65. package/src/lib/compiler/resource-inliner.js.map +1 -1
  66. package/src/lib/compiler/style-ast.d.ts +22 -1
  67. package/src/lib/compiler/style-ast.js +37 -20
  68. package/src/lib/compiler/style-ast.js.map +1 -1
  69. package/src/lib/compiler/type-elision.d.ts +4 -3
  70. package/src/lib/compiler/type-elision.js +11 -13
  71. package/src/lib/compiler/type-elision.js.map +1 -1
  72. package/src/lib/compiler/utils.d.ts +9 -7
  73. package/src/lib/compiler/utils.js +50 -11
  74. package/src/lib/compiler/utils.js.map +1 -1
  75. package/src/lib/compiler-plugin.js +1 -2
  76. package/src/lib/component-resolvers.js +1 -2
  77. package/src/lib/component-scanner.d.ts +74 -0
  78. package/src/lib/component-scanner.js +177 -0
  79. package/src/lib/component-scanner.js.map +1 -0
  80. package/src/lib/component-styles-plugin.d.ts +52 -0
  81. package/src/lib/component-styles-plugin.js +352 -0
  82. package/src/lib/component-styles-plugin.js.map +1 -0
  83. package/src/lib/compose-angular-plugins.d.ts +12 -0
  84. package/src/lib/compose-angular-plugins.js +30 -0
  85. package/src/lib/compose-angular-plugins.js.map +1 -0
  86. package/src/lib/dev-server-mode-plugin.d.ts +7 -0
  87. package/src/lib/dev-server-mode-plugin.js +22 -0
  88. package/src/lib/dev-server-mode-plugin.js.map +1 -0
  89. package/src/lib/encapsulation-plugin.js +1 -2
  90. package/src/lib/fast-compile-api.d.ts +62 -0
  91. package/src/lib/fast-compile-api.js +11 -0
  92. package/src/lib/fast-compile-api.js.map +1 -0
  93. package/src/lib/fast-compile-plugin.d.ts +6 -1
  94. package/src/lib/fast-compile-plugin.js +169 -110
  95. package/src/lib/fast-compile-plugin.js.map +1 -1
  96. package/src/lib/host.d.ts +3 -0
  97. package/src/lib/host.js +5 -4
  98. package/src/lib/host.js.map +1 -1
  99. package/src/lib/hot-update-batch.js +1 -2
  100. package/src/lib/live-reload-plugin.d.ts +6 -3
  101. package/src/lib/live-reload-plugin.js +14 -8
  102. package/src/lib/live-reload-plugin.js.map +1 -1
  103. package/src/lib/ngp-compile-api.d.ts +55 -0
  104. package/src/lib/ngp-compile-api.js +11 -0
  105. package/src/lib/ngp-compile-api.js.map +1 -0
  106. package/src/lib/ngp-compile-plugin.d.ts +4 -0
  107. package/src/lib/ngp-compile-plugin.js +672 -0
  108. package/src/lib/ngp-compile-plugin.js.map +1 -0
  109. package/src/lib/ngtsc-compile-plugin.d.ts +23 -0
  110. package/src/lib/ngtsc-compile-plugin.js +776 -0
  111. package/src/lib/ngtsc-compile-plugin.js.map +1 -0
  112. package/src/lib/nx-folder-plugin.d.ts +6 -5
  113. package/src/lib/nx-folder-plugin.js +13 -9
  114. package/src/lib/nx-folder-plugin.js.map +1 -1
  115. package/src/lib/plugins/file-replacements.plugin.d.ts +6 -0
  116. package/src/lib/plugins/file-replacements.plugin.js +2 -2
  117. package/src/lib/plugins/file-replacements.plugin.js.map +1 -1
  118. package/src/lib/router-plugin.d.ts +5 -1
  119. package/src/lib/router-plugin.js +14 -6
  120. package/src/lib/router-plugin.js.map +1 -1
  121. package/src/lib/style-preprocessor.js +1 -2
  122. package/src/lib/stylesheet-registry.js +1 -2
  123. package/src/lib/stylesheet-registry.js.map +1 -1
  124. package/src/lib/tools/src/builders/vite/vite-build.impl.js +2 -3
  125. package/src/lib/tools/src/builders/vite/vite-build.impl.js.map +1 -1
  126. package/src/lib/tools/src/builders/vite-dev-server/dev-server.impl.js +1 -2
  127. package/src/lib/tools/src/builders/vite-dev-server/dev-server.impl.js.map +1 -1
  128. package/src/lib/utils/compilation-shared.js +3 -4
  129. package/src/lib/utils/css-extension-resolver.js +1 -2
  130. package/src/lib/utils/css-preprocessor-workers.js +1 -2
  131. package/src/lib/utils/debug-harness.js +1 -2
  132. package/src/lib/utils/debug-log-file.js +1 -2
  133. package/src/lib/utils/debug.js +1 -2
  134. package/src/lib/utils/devkit.js +2 -3
  135. package/src/lib/utils/hmr-component-updates.d.ts +7 -0
  136. package/src/lib/utils/hmr-component-updates.js +86 -0
  137. package/src/lib/utils/hmr-component-updates.js.map +1 -0
  138. package/src/lib/utils/jit-inline-styles.js +1 -2
  139. package/src/lib/utils/lsp-type-checker.d.ts +75 -0
  140. package/src/lib/utils/lsp-type-checker.js +532 -0
  141. package/src/lib/utils/lsp-type-checker.js.map +1 -0
  142. package/src/lib/utils/ngp-host-fs.d.ts +43 -0
  143. package/src/lib/utils/ngp-host-fs.js +128 -0
  144. package/src/lib/utils/ngp-host-fs.js.map +1 -0
  145. package/src/lib/utils/plugin-config.d.ts +15 -8
  146. package/src/lib/utils/plugin-config.js +19 -7
  147. package/src/lib/utils/plugin-config.js.map +1 -1
  148. package/src/lib/utils/rolldown.js +1 -2
  149. package/src/lib/utils/safe-module-paths.js +1 -2
  150. package/src/lib/utils/stylesheet-warning.d.ts +2 -0
  151. package/src/lib/utils/stylesheet-warning.js +10 -0
  152. package/src/lib/utils/stylesheet-warning.js.map +1 -0
  153. package/src/lib/utils/transform-cache.js +1 -2
  154. package/src/lib/utils/transform-cache.js.map +1 -1
  155. package/src/lib/utils/tsconfig-resolver.js +2 -3
  156. package/src/lib/utils/virtual-ids.js +1 -2
  157. package/src/lib/utils/virtual-resources.js +1 -2
  158. package/src/lib/utils/virtual-resources.js.map +1 -1
  159. package/src/lib/virtual-modules-plugin.d.ts +11 -3
  160. package/src/lib/virtual-modules-plugin.js +70 -15
  161. package/src/lib/virtual-modules-plugin.js.map +1 -1
@@ -1,25 +1,33 @@
1
+ import { parseOxc } from "./compiler/utils.js";
2
+ import { createAngularBuildContext, isAngularBuildContext } from "./angular-build-context.js";
3
+ import "./compiler/index.js";
4
+ import { reportStylesheetError } from "./utils/stylesheet-warning.js";
1
5
  import { TS_EXT_REGEX, createDepOptimizerConfig, getTsConfigPath, isProdMode } from "./utils/plugin-config.js";
2
- import { discoverAnalogIntegrations } from "./analog-plugin-interop.js";
6
+ import { isIgnoredHmrFile } from "./utils/compilation-shared.js";
3
7
  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";
8
+ import { isRolldown } from "./utils/rolldown.js";
9
+ import { TsconfigResolver } from "./utils/tsconfig-resolver.js";
10
+ import { ComponentScanner } from "./component-scanner.js";
6
11
  import { ANGULAR_DECORATOR_CALL_RE } from "./compiler/constants.js";
7
- import { debugCompile, debugRegistry } from "./compiler/debug.js";
12
+ import { preprocessStylesheet } from "./stylesheet-registry.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, collectRelativeReExports } 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
- import "./compiler/index.js";
15
- import { markStylePathSafe } from "./utils/safe-module-paths.js";
20
+ import { discoverAnalogIntegrations } from "./analog-plugin-interop.js";
21
+ import { loadAngularVirtualModule, resolveAngularVirtualId } from "./virtual-modules-plugin.js";
16
22
  import { promises } from "node:fs";
17
- import { dirname, isAbsolute, resolve } from "node:path";
23
+ import { dirname, resolve } from "node:path";
18
24
  import * as vite from "vite";
19
25
  import { normalizePath, preprocessCSS } from "vite";
20
26
  import * as compilerCli from "@angular/compiler-cli";
21
- import { parseSync } from "oxc-parser";
22
- //#region packages/vite-plugin-angular/src/lib/fast-compile-plugin.ts
27
+ // packages/vite-plugin-angular/src/lib/fast-compile-plugin.ts
28
+ function isFastCompilePluginOptions(value) {
29
+ return typeof value === "object" && value !== null && !isAngularBuildContext(value) && "tsconfigGetter" in value && typeof value.tsconfigGetter === "function";
30
+ }
23
31
  /**
24
32
  * Directory that `compilerOptions.paths` targets resolve against. Mirrors
25
33
  * TypeScript: `baseUrl` when set, otherwise the directory of the config
@@ -29,17 +37,31 @@ import { parseSync } from "oxc-parser";
29
37
  function getPathsBasePath(options, fallback) {
30
38
  return options?.baseUrl ?? options?.pathsBasePath ?? fallback;
31
39
  }
32
- function fastCompilePlugin(pluginOptions) {
40
+ function fastCompilePlugin(optionsOrCtx) {
41
+ const sharedCtx = isAngularBuildContext(optionsOrCtx) ? optionsOrCtx : isFastCompilePluginOptions(optionsOrCtx) ? void 0 : createAngularBuildContext({
42
+ ...optionsOrCtx,
43
+ compilationBackend: "fast"
44
+ });
45
+ const pluginOptions = sharedCtx ? sharedCtx.options : optionsOrCtx;
46
+ const scanner = new ComponentScanner();
47
+ const registry = scanner.registry;
48
+ const tsconfigResolver = sharedCtx?.tsconfigResolver ?? new TsconfigResolver({
49
+ workspaceRoot: pluginOptions.workspaceRoot,
50
+ include: pluginOptions.include ?? [],
51
+ liveReload: pluginOptions.liveReload,
52
+ isTest: pluginOptions.isTest
53
+ });
33
54
  let resolvedConfig;
34
55
  let transformFilter;
35
56
  let componentRegistries = [];
57
+ let stylePreprocessor;
36
58
  let tsConfigResolutionContext = null;
37
59
  let watchMode = false;
38
- const registry = /* @__PURE__ */ new Map();
39
60
  const resourceToSource = /* @__PURE__ */ new Map();
40
- const scannedDtsPackages = /* @__PURE__ */ new Set();
41
- let projectRoot = "";
61
+ const emittedMaps = /* @__PURE__ */ new Map();
42
62
  let useDefineForClassFields = true;
63
+ let tsConfig;
64
+ let projectScan;
43
65
  /**
44
66
  * Scan a file into the registry, then recursively walk its relative
45
67
  * `export *` / `export { … } from './x'` chain so any underlying
@@ -61,7 +83,7 @@ function fastCompilePlugin(pluginOptions) {
61
83
  visited.add(file);
62
84
  let code;
63
85
  try {
64
- code = fileContents?.get(file) ?? await promises.readFile(file, "utf-8");
86
+ code = fileContents?.get(file) ?? await scanner.readScanSource(file);
65
87
  fileContents?.set(file, code);
66
88
  } catch (e) {
67
89
  if (debugRegistry.enabled) debugRegistry("scanBarrelExports: failed to read %s: %s", file, e?.message);
@@ -69,7 +91,7 @@ function fastCompilePlugin(pluginOptions) {
69
91
  }
70
92
  let program;
71
93
  try {
72
- program = parseSync(file, code).program;
94
+ program = parseOxc(file, code).program;
73
95
  } catch {
74
96
  program = void 0;
75
97
  }
@@ -94,15 +116,22 @@ function fastCompilePlugin(pluginOptions) {
94
116
  }
95
117
  }
96
118
  async function initFastCompile() {
119
+ emittedMaps.clear();
97
120
  if (pluginOptions.jit) return;
98
- registry.clear();
99
- scannedDtsPackages.clear();
121
+ projectScan = void 0;
100
122
  const resolvedTsConfigPath = resolveTsConfigPath();
101
- projectRoot = dirname(resolvedTsConfigPath);
102
- const config = compilerCli.readConfiguration(resolvedTsConfigPath);
103
- useDefineForClassFields = config.options?.useDefineForClassFields ?? true;
104
- const candidates = new Set(config.rootNames);
123
+ const projectRoot = dirname(resolvedTsConfigPath);
124
+ scanner.reset(projectRoot);
125
+ tsConfig = compilerCli.readConfiguration(resolvedTsConfigPath);
126
+ useDefineForClassFields = tsConfig.options?.useDefineForClassFields ?? true;
127
+ }
128
+ /** Scan all source files reachable from the tsconfig into the registry. */
129
+ async function scanProject() {
130
+ const config = tsConfig;
131
+ const extraIncludes = tsconfigResolver.ensureIncludeCache();
132
+ const candidates = /* @__PURE__ */ new Set([...config.rootNames, ...extraIncludes]);
105
133
  const tsPaths = config.options?.paths;
134
+ const projectRoot = scanner.projectRoot;
106
135
  const baseUrl = getPathsBasePath(config.options, projectRoot);
107
136
  const fileContents = /* @__PURE__ */ new Map();
108
137
  const scanResults = /* @__PURE__ */ new Map();
@@ -112,7 +141,7 @@ function fastCompilePlugin(pluginOptions) {
112
141
  }
113
142
  const results = await Promise.all(Array.from(candidates).map(async (file) => {
114
143
  try {
115
- const code = await promises.readFile(file, "utf-8");
144
+ const code = await scanner.readScanSource(file);
116
145
  fileContents.set(file, code);
117
146
  const entries = scanFile(code, file);
118
147
  scanResults.set(file, entries);
@@ -165,14 +194,14 @@ function fastCompilePlugin(pluginOptions) {
165
194
  importWalkVisited.add(file);
166
195
  let code;
167
196
  try {
168
- code = fileContents.get(file) ?? await promises.readFile(file, "utf-8");
197
+ code = fileContents.get(file) ?? await scanner.readScanSource(file);
169
198
  fileContents.set(file, code);
170
199
  } catch {
171
200
  return;
172
201
  }
173
202
  let program;
174
203
  try {
175
- program = parseSync(file, code).program;
204
+ program = parseOxc(file, code).program;
176
205
  } catch {
177
206
  program = void 0;
178
207
  }
@@ -182,13 +211,7 @@ function fastCompilePlugin(pluginOptions) {
182
211
  scanResults.set(file, entries);
183
212
  }
184
213
  for (const entry of entries) if (!registry.has(entry.className)) registry.set(entry.className, entry);
185
- for (const pkg of collectImportedPackages(code, file, program)) {
186
- if (scannedDtsPackages.has(pkg)) continue;
187
- scannedDtsPackages.add(pkg);
188
- try {
189
- for (const entry of scanPackageDts(pkg, projectRoot, scannedDtsPackages)) if (!registry.has(entry.className)) registry.set(entry.className, entry);
190
- } catch {}
191
- }
214
+ scanner.ensureDtsRegistryForSource(code, file, program);
192
215
  const dir = dirname(file);
193
216
  const targets = await Promise.all(collectAllImports(code, file, program).map((spec) => {
194
217
  if (spec.startsWith(".")) return resolveToSource(resolve(dir, spec.replace(/\.(?:js|mjs)$/u, "")));
@@ -201,7 +224,8 @@ function fastCompilePlugin(pluginOptions) {
201
224
  }));
202
225
  await Promise.all(targets.filter((t) => !!t).map((t) => walkImports(t)));
203
226
  };
204
- await Promise.all(config.rootNames.map((file) => walkImports(file)));
227
+ const walkRoots = [.../* @__PURE__ */ new Set([...config.rootNames, ...extraIncludes])];
228
+ await Promise.all(walkRoots.map((file) => walkImports(file)));
205
229
  const buildStartVisited = /* @__PURE__ */ new Set();
206
230
  if (tsPaths) {
207
231
  const barrelCandidates = [];
@@ -213,17 +237,7 @@ function fastCompilePlugin(pluginOptions) {
213
237
  }
214
238
  debugRegistry("initFastCompile done: %d entries from %d candidate files", registry.size, candidates.size);
215
239
  }
216
- function ensureDtsRegistryForSource(code, id, program) {
217
- for (const pkg of collectImportedPackages(code, id, program)) {
218
- if (scannedDtsPackages.has(pkg)) continue;
219
- scannedDtsPackages.add(pkg);
220
- try {
221
- const dtsEntries = scanPackageDts(pkg, projectRoot, scannedDtsPackages);
222
- for (const entry of dtsEntries) if (!registry.has(entry.className)) registry.set(entry.className, entry);
223
- } catch {}
224
- }
225
- }
226
- async function handleFastCompileTransform(code, id) {
240
+ async function handleFastCompileTransform(code, id, resolveImport) {
227
241
  if (!ANGULAR_DECORATOR_CALL_RE.test(code)) {
228
242
  const stripped = vite.transformWithOxc ? await vite.transformWithOxc(code, id, {
229
243
  lang: "ts",
@@ -262,35 +276,44 @@ function fastCompilePlugin(pluginOptions) {
262
276
  }
263
277
  const inlined = await inlineResourceUrls(code, id);
264
278
  code = inlined.code;
265
- const { styleExtensions } = inlined;
279
+ const { stylePaths } = inlined;
266
280
  for (const dep of inlined.resourceDependencies) resourceToSource.set(dep, id);
267
- const { program: oxcProgram } = parseSync(id, code);
281
+ const { program: oxcProgram } = parseOxc(id, code);
268
282
  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
- }
283
+ const styleStrings = extractInlineStyles(code, id, oxcProgram);
284
+ if (styleStrings.length > 0) {
285
+ resolvedInlineStyles = /* @__PURE__ */ new Map();
286
+ const activeConfig = sharedCtx?.resolvedConfig ?? resolvedConfig;
287
+ const activeStylePreprocessor = sharedCtx?.stylePreprocessor ?? stylePreprocessor;
288
+ for (let i = 0; i < styleStrings.length; i++) {
289
+ const stylePath = stylePaths.get(i) ?? (scanner.sourceFormatOf(id) ? id + ".ts" : id).replace(/\.ts$/, `.inline-${i}.${pluginOptions.inlineStylesExtension || "css"}`);
290
+ try {
291
+ const preprocessed = preprocessStylesheet(styleStrings[i], stylePath, activeStylePreprocessor, {
292
+ filename: stylePath,
293
+ containingFile: id,
294
+ order: i,
295
+ inline: !stylePaths.has(i)
296
+ });
297
+ const processed = await preprocessCSS(preprocessed, stylePath, activeConfig);
298
+ resolvedInlineStyles.set(i, processed.code);
299
+ } catch (e) {
300
+ reportStylesheetError(activeConfig?.logger, stylePath, e, activeConfig?.command === "build");
285
301
  }
286
- if (resolvedInlineStyles.size === 0) resolvedInlineStyles = void 0;
287
302
  }
303
+ if (resolvedInlineStyles.size === 0) resolvedInlineStyles = void 0;
304
+ }
305
+ scanner.ensureDtsRegistryForSource(code, id, oxcProgram);
306
+ for (const entry of scanFile(code, id, oxcProgram)) registry.set(entry.className, entry);
307
+ await scanner.resolveImportSpecifiers(collectAllImports(code, id, oxcProgram), id, resolveImport);
308
+ if (declaresNonStandaloneComponent(oxcProgram)) {
309
+ projectScan ??= scanProject();
310
+ await projectScan;
288
311
  }
289
- ensureDtsRegistryForSource(code, id, oxcProgram);
312
+ const activeComponentRegistries = sharedCtx ? sharedCtx.componentRegistries : componentRegistries;
290
313
  let compileRegistry = registry;
291
- if (componentRegistries.some((external) => external.size > 0)) {
314
+ if (activeComponentRegistries.some((external) => external.size > 0)) {
292
315
  compileRegistry = new Map(registry);
293
- for (const external of componentRegistries) for (const [k, v] of external) compileRegistry.set(k, v);
316
+ for (const external of activeComponentRegistries) for (const [k, v] of external) compileRegistry.set(k, v);
294
317
  }
295
318
  const result = compile(code, id, {
296
319
  registry: compileRegistry,
@@ -312,8 +335,8 @@ function fastCompilePlugin(pluginOptions) {
312
335
  sourcemap: true
313
336
  }, result.map);
314
337
  let outputCode = stripped.code;
315
- if (watchMode && pluginOptions.liveReload) {
316
- const fileDeclarations = [...registry.values()].filter((e) => e.fileName === id);
338
+ if ((sharedCtx ? sharedCtx.watchMode : watchMode) && pluginOptions.liveReload) {
339
+ const fileDeclarations = scanner.entriesOf(id);
317
340
  if (fileDeclarations.length > 0) {
318
341
  const localDepClassNames = fileDeclarations.map((e) => e.className);
319
342
  outputCode += generateHmrCode(fileDeclarations, localDepClassNames);
@@ -325,17 +348,53 @@ function fastCompilePlugin(pluginOptions) {
325
348
  };
326
349
  }
327
350
  function resolveTsConfigPath() {
328
- const { root, isProd, isLib } = tsConfigResolutionContext;
329
- return getTsConfigPath(root, pluginOptions.tsconfigGetter(), isProd, pluginOptions.isTest, isLib, pluginOptions.workspaceRoot);
351
+ if (sharedCtx) return sharedCtx.resolveTsConfigPath();
352
+ const resolution = tsConfigResolutionContext ?? {
353
+ root: resolvedConfig?.root || ".",
354
+ isProd: isProdMode(resolvedConfig?.mode),
355
+ isLib: !!resolvedConfig?.build?.lib
356
+ };
357
+ return getTsConfigPath(resolution.root, pluginOptions.tsconfigGetter(), resolution.isProd, pluginOptions.isTest, resolution.isLib, pluginOptions.workspaceRoot);
330
358
  }
359
+ const compilerApi = {
360
+ angularCompiler: true,
361
+ getTsConfigPath: resolveTsConfigPath,
362
+ getSourceMap: (id) => emittedMaps.get(normalizePath(id)),
363
+ hasEmitted: (id) => emittedMaps.has(normalizePath(id)),
364
+ fastCompile: {
365
+ registerSourceFormat: (format) => scanner.registerSourceFormat(format),
366
+ scanImports: (specifiers, importer, resolve) => scanner.scanImports(specifiers, importer, resolve),
367
+ resolveSelector: (className) => scanner.lookupSelector(className, sharedCtx ? sharedCtx.componentRegistries : componentRegistries),
368
+ async compile(code, id, { resolve, mapToSource }) {
369
+ const transformed = await handleFastCompileTransform(code, id, scanner.toResolveImport(resolve));
370
+ if (!transformed) return;
371
+ const map = transformed.map && mapToSource ? mapToSource(transformed.map) : transformed.map ?? null;
372
+ if (map) emittedMaps.set(normalizePath(id), typeof map === "string" ? map : JSON.stringify(map));
373
+ return {
374
+ code: transformed.code,
375
+ map
376
+ };
377
+ }
378
+ }
379
+ };
380
+ sharedCtx?.registerCompiler({
381
+ name: "@analogjs/vite-plugin-angular-fast-compile",
382
+ getTsConfigPath: compilerApi.getTsConfigPath,
383
+ getSourceMap: compilerApi.getSourceMap,
384
+ hasEmitted: compilerApi.hasEmitted
385
+ });
331
386
  return {
332
387
  name: "@analogjs/vite-plugin-angular-fast-compile",
333
- api: { getTsConfigPath: resolveTsConfigPath },
388
+ api: compilerApi,
334
389
  enforce: "pre",
335
- async config(config, { command }) {
390
+ async config(config, { command, mode }) {
336
391
  watchMode = command === "serve";
337
392
  const isProd = isProdMode(config.mode);
338
- tsConfigResolutionContext = {
393
+ if (sharedCtx) sharedCtx.initConfig(config, {
394
+ command,
395
+ mode
396
+ });
397
+ else tsConfigResolutionContext = {
339
398
  root: config.root || ".",
340
399
  isProd,
341
400
  isLib: !!config?.build?.lib
@@ -350,64 +409,61 @@ function fastCompilePlugin(pluginOptions) {
350
409
  isAstroIntegration: pluginOptions.isAstroIntegration
351
410
  });
352
411
  return {
353
- ...vite.rolldownVersion ? { oxc: {} } : { esbuild: false },
412
+ ...isRolldown() ? { oxc: {} } : { esbuild: false },
354
413
  ...depOptimizer
355
414
  };
356
415
  },
357
416
  async configResolved(config) {
358
417
  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
- });
418
+ if (sharedCtx) {
419
+ const integrations = await sharedCtx.resolveConfig(config);
420
+ transformFilter = integrations.transformFilter;
421
+ componentRegistries = integrations.componentRegistries;
422
+ stylePreprocessor = integrations.stylePreprocessor;
423
+ } else {
424
+ const integrations = await discoverAnalogIntegrations(config);
425
+ transformFilter = integrations.transformFilter;
426
+ componentRegistries = integrations.componentRegistries;
427
+ stylePreprocessor = integrations.stylePreprocessor;
428
+ tsconfigResolver.setIntegrationIncludes(integrations.include);
429
+ }
367
430
  },
368
431
  async buildStart() {
369
432
  await initFastCompile();
370
433
  },
371
434
  closeBundle() {
372
- if (!watchMode) releaseCssPreprocessorWorkers();
435
+ if (!(sharedCtx ? sharedCtx.watchMode : watchMode)) {
436
+ emittedMaps.clear();
437
+ releaseCssPreprocessorWorkers();
438
+ }
373
439
  },
374
440
  async handleHotUpdate(ctx) {
441
+ if (sharedCtx ? sharedCtx.hmr.isIgnoredFile(ctx.file) : isIgnoredHmrFile(ctx.file)) return [];
375
442
  if (resourceToSource.has(ctx.file)) {
376
443
  const parentSource = resourceToSource.get(ctx.file);
377
444
  const parentModule = ctx.server.moduleGraph.getModuleById(parentSource);
378
445
  if (parentModule) return [parentModule];
379
446
  }
380
- if (TS_EXT_REGEX.test(ctx.file)) {
447
+ if (scanner.isCompiledSource(ctx.file)) {
381
448
  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);
449
+ const oldEntries = scanner.entriesOf(fileId);
450
+ scanner.invalidate(fileId);
384
451
  await scanBarrelExports(fileId, /* @__PURE__ */ new Set(), true);
452
+ if (JSON.stringify(oldEntries) !== JSON.stringify(scanner.entriesOf(fileId))) {
453
+ const importerModules = [...scanner.importersByFile.get(fileId) ?? []].flatMap((importer) => [...ctx.server.moduleGraph.getModulesByFile(importer) ?? []]);
454
+ return [...ctx.modules, ...importerModules];
455
+ }
385
456
  }
386
457
  return ctx.modules;
387
458
  },
388
459
  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
- }
460
+ return resolveAngularVirtualId(id, importer, {
461
+ jit: pluginOptions.jit,
462
+ resolvedConfig: sharedCtx?.resolvedConfig ?? resolvedConfig
463
+ });
406
464
  },
407
465
  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]);
466
+ return loadAngularVirtualModule(this, id, sharedCtx?.resolvedConfig ?? resolvedConfig);
411
467
  },
412
468
  transform: {
413
469
  filter: { id: {
@@ -420,14 +476,17 @@ function fastCompilePlugin(pluginOptions) {
420
476
  ]
421
477
  } },
422
478
  async handler(code, id) {
423
- if (transformFilter && !transformFilter(code, id)) return;
479
+ const activeTransformFilter = sharedCtx?.transformFilter ?? transformFilter;
480
+ if (activeTransformFilter && !activeTransformFilter(code, id)) return;
424
481
  if (id.includes(".ts?")) id = id.replace(/\?(.*)/, "");
425
- return handleFastCompileTransform(code, id);
482
+ const resolveImport = scanner.toResolveImport((spec, importer) => this.resolve(spec, importer, { skipSelf: true }));
483
+ const transformed = await handleFastCompileTransform(code, id, resolveImport);
484
+ if (transformed?.map) emittedMaps.set(normalizePath(id), typeof transformed.map === "string" ? transformed.map : JSON.stringify(transformed.map));
485
+ return transformed;
426
486
  }
427
487
  }
428
488
  };
429
489
  }
430
- //#endregion
431
490
  export { fastCompilePlugin, getPathsBasePath };
432
491
 
433
492
  //# sourceMappingURL=fast-compile-plugin.js.map