@analogjs/vite-plugin-angular 3.0.0-alpha.92 → 3.0.0-alpha.94

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 (34) hide show
  1. package/README.md +16 -1
  2. package/package.json +1 -1
  3. package/src/lib/angular-vite-plugin.d.ts +1 -1
  4. package/src/lib/angular-vite-plugin.js +35 -18
  5. package/src/lib/angular-vite-plugin.js.map +1 -1
  6. package/src/lib/compilation-api/compilation-api-plugin.js +52 -34
  7. package/src/lib/compilation-api/compilation-api-plugin.js.map +1 -1
  8. package/src/lib/compiler/angular-version.d.ts +2 -0
  9. package/src/lib/compiler/angular-version.js +2 -1
  10. package/src/lib/compiler/angular-version.js.map +1 -1
  11. package/src/lib/compiler/defer.js +2 -0
  12. package/src/lib/compiler/defer.js.map +1 -1
  13. package/src/lib/compiler/js-emitter.js +15 -1
  14. package/src/lib/compiler/js-emitter.js.map +1 -1
  15. package/src/lib/compiler-plugin.js +18 -12
  16. package/src/lib/compiler-plugin.js.map +1 -1
  17. package/src/lib/fast-compile-plugin.js +0 -2
  18. package/src/lib/fast-compile-plugin.js.map +1 -1
  19. package/src/lib/host.d.ts +1 -0
  20. package/src/lib/host.js +19 -1
  21. package/src/lib/host.js.map +1 -1
  22. package/src/lib/hot-update-batch.d.ts +5 -0
  23. package/src/lib/hot-update-batch.js +176 -0
  24. package/src/lib/hot-update-batch.js.map +1 -0
  25. package/src/lib/router-plugin.js +6 -3
  26. package/src/lib/router-plugin.js.map +1 -1
  27. package/src/lib/utils/compilation-shared.d.ts +1 -0
  28. package/src/lib/utils/compilation-shared.js +15 -1
  29. package/src/lib/utils/compilation-shared.js.map +1 -1
  30. package/src/lib/utils/devkit.js +4 -1
  31. package/src/lib/utils/devkit.js.map +1 -1
  32. package/src/lib/utils/plugin-config.d.ts +1 -0
  33. package/src/lib/utils/plugin-config.js +2 -1
  34. package/src/lib/utils/plugin-config.js.map +1 -1
package/README.md CHANGED
@@ -60,7 +60,7 @@ export default defineConfig({
60
60
  });
61
61
  ```
62
62
 
63
- When `fastCompile` is enabled, template and input type errors will not surface during compilation — run `ngc -p tsconfig.app.json --noEmit` as a separate step in your build script to keep full type safety:
63
+ When `fastCompile` is enabled, template and input type errors will not surface during compilation. Run `ngc -p tsconfig.app.json --noEmit` as a separate step in your build script to keep full type safety:
64
64
 
65
65
  ```json
66
66
  {
@@ -72,6 +72,21 @@ When `fastCompile` is enabled, template and input type errors will not surface d
72
72
 
73
73
  The fast compile path currently passes ~91% of Angular's conformance suite. Behavior and output may change between minor releases.
74
74
 
75
+ ## Vendor Sourcemaps
76
+
77
+ The sourcemaps of dependencies and prebuilt libraries are preserved whenever `build.sourcemap` is enabled.
78
+
79
+ ```ts
80
+ export default defineConfig({
81
+ plugins: [angular()],
82
+ build: { sourcemap: true },
83
+ });
84
+ ```
85
+
86
+ Expect larger sourcemap files, since they now include the mappings for dependency code. The application bundles are unchanged, and builds without `build.sourcemap` are unaffected.
87
+
88
+ Angular's own packages are compiled through a separate path that always discards their sourcemaps, so mappings are not restored for `@angular/*`.
89
+
75
90
  ## Setting up the TypeScript config
76
91
 
77
92
  The integration needs a `tsconfig.app.json` at the root of the project for compilation.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@analogjs/vite-plugin-angular",
3
- "version": "3.0.0-alpha.92",
3
+ "version": "3.0.0-alpha.94",
4
4
  "description": "Vite Plugin for Angular",
5
5
  "type": "module",
6
6
  "keywords": [
@@ -4,7 +4,7 @@ import { ModuleNode, Plugin, ViteDevServer } from "vite";
4
4
  import { type DebugOption } from "./utils/debug.js";
5
5
  import { FileReplacement } from "./plugins/file-replacements.plugin.js";
6
6
  import { AnalogStylesheetRegistry } from "./stylesheet-registry.js";
7
- export { DiagnosticModes, injectViteIgnoreForHmrMetadata, isIgnoredHmrFile, toAngularCompilationFileReplacements, mapTemplateUpdatesToFiles, refreshStylesheetRegistryForFile, describeStylesheetContent, isTestWatchMode } from "./utils/compilation-shared.js";
7
+ export { DiagnosticModes, injectViteIgnoreForHmrMetadata, isIgnoredHmrFile, toAngularCompilationFileReplacements, mapTemplateUpdatesToFiles, refreshStylesheetRegistryForFile, describeStylesheetContent, isTestWatchMode, getBrowserModeCliOverride } from "./utils/compilation-shared.js";
8
8
  export interface PluginOptions {
9
9
  tsconfig?: string | (() => string);
10
10
  workspaceRoot?: string;
@@ -1,12 +1,13 @@
1
1
  import { angularFullVersion, cjt, sourceFileCache } from "./utils/devkit.js";
2
2
  import { activateDeferredDebug, applyDebugOption, debugCompiler, debugCompilerV, debugEmit, debugEmitV, debugHmr, debugHmrV, debugStyles, debugStylesV } from "./utils/debug.js";
3
3
  import { createCompilerPlugin, createRolldownCompilerPlugin } from "./compiler-plugin.js";
4
- import { TS_EXT_REGEX, createTsConfigGetter, getTsConfigPath, isProdMode } from "./utils/plugin-config.js";
4
+ import { EXCLUDED_TS_EXT_REGEX, TS_EXT_REGEX, createTsConfigGetter, getTsConfigPath, isProdMode } from "./utils/plugin-config.js";
5
5
  import { TsconfigResolver } from "./utils/tsconfig-resolver.js";
6
6
  import { getJsTransformConfigKey, isRolldown } from "./utils/rolldown.js";
7
7
  import { AnalogStylesheetRegistry, preprocessStylesheet, rewriteRelativeCssImports } from "./stylesheet-registry.js";
8
8
  import { discoverAnalogIntegrations } from "./analog-plugin-interop.js";
9
- import { describeStylesheetContent, injectViteIgnoreForHmrMetadata, isIgnoredHmrFile, isTestWatchMode } from "./utils/compilation-shared.js";
9
+ import { describeStylesheetContent, getBrowserModeCliOverride, injectViteIgnoreForHmrMetadata, isIgnoredHmrFile, isTestWatchMode } from "./utils/compilation-shared.js";
10
+ import { createHotUpdateBatcher } from "./hot-update-batch.js";
10
11
  import { angularVitestPlugins } from "./angular-vitest-plugin.js";
11
12
  import { buildOptimizerPlugin } from "./angular-build-optimizer-plugin.js";
12
13
  import { toJitInlineStyleId } from "./utils/jit-inline-styles.js";
@@ -22,7 +23,7 @@ import { replaceFiles } from "./plugins/file-replacements.plugin.js";
22
23
  import { cssExtensionStyleResolverPlugin } from "./utils/css-extension-resolver.js";
23
24
  import { loadVirtualRawModule, rewriteHtmlRawImport } from "./utils/virtual-resources.js";
24
25
  import { StyleUrlsResolver, TemplateUrlsResolver } from "./component-resolvers.js";
25
- import { augmentHostWithCaching, augmentHostWithResources, augmentProgramWithVersioning, mergeTransformers } from "./host.js";
26
+ import { augmentHostWithCaching, augmentHostWithModuleResolution, augmentHostWithResources, augmentProgramWithVersioning, mergeTransformers } from "./host.js";
26
27
  import { markStylePathSafe } from "./utils/safe-module-paths.js";
27
28
  import { fastCompilePlugin } from "./fast-compile-plugin.js";
28
29
  import { pendingTasksPlugin } from "./angular-pending-tasks.plugin.js";
@@ -122,6 +123,7 @@ function angular(options) {
122
123
  sourceFileCache$1.invalidate(files);
123
124
  }
124
125
  const isVitestVscode = !!process.env["VITEST_VSCODE"];
126
+ let deferInitialCompilation = isVitestVscode;
125
127
  const isStackBlitz = !!process.versions["webcontainer"];
126
128
  const isAstroIntegration = process.env["ANALOG_ASTRO"] === "true";
127
129
  const jit = typeof pluginOptions?.jit !== "undefined" ? pluginOptions.jit : isTest;
@@ -167,6 +169,7 @@ function angular(options) {
167
169
  let styleTransform;
168
170
  let pendingCompilation;
169
171
  let compilationLock = Promise.resolve();
172
+ const hotUpdates = createHotUpdateBatcher((ids) => performCompilation(resolvedConfig, ids));
170
173
  function angularPlugin() {
171
174
  let isProd = false;
172
175
  if (angularFullVersion < 19e4 && pluginOptions.liveReload) {
@@ -247,12 +250,20 @@ function angular(options) {
247
250
  };
248
251
  }
249
252
  if (!jit) styleTransform = (code, filename) => preprocessCSS(code, filename, config);
250
- if (isTest) testWatchMode = !(config.server.watch === null) || config.test?.watch === true || testWatchMode;
253
+ if (isTest) {
254
+ const browser = config.test?.browser;
255
+ deferInitialCompilation = isVitestVscode || !!browser && (getBrowserModeCliOverride() ?? browser.enabled) === true;
256
+ testWatchMode = !(config.server.watch === null) || config.test?.watch === true || testWatchMode;
257
+ }
251
258
  },
252
259
  configureServer(server) {
253
260
  viteServer = server;
261
+ hotUpdates.configureServer(server);
254
262
  const invalidateCompilationOnFsChange = createFsWatcherCacheInvalidator(invalidateFsCaches, invalidateTsconfigCaches, () => performCompilation(resolvedConfig));
255
- server.watcher.on("add", invalidateCompilationOnFsChange);
263
+ server.watcher.on("add", (file) => {
264
+ if (EXCLUDED_TS_EXT_REGEX.test(file)) invalidateSourceFiles(new Set([normalizePath(file)]));
265
+ return invalidateCompilationOnFsChange();
266
+ });
256
267
  server.watcher.on("unlink", (file) => {
257
268
  const id = normalizePath(file);
258
269
  outputFiles.delete(id);
@@ -269,7 +280,8 @@ function angular(options) {
269
280
  });
270
281
  },
271
282
  async buildStart() {
272
- if (!isVitestVscode) {
283
+ if (!jit) styleTransform = (code, filename) => preprocessCSS(code, filename, resolvedConfig);
284
+ if (!deferInitialCompilation) {
273
285
  pendingCompilation = performCompilation(this.environment?.config ?? resolvedConfig);
274
286
  await pendingCompilation;
275
287
  pendingCompilation = null;
@@ -304,11 +316,17 @@ function angular(options) {
304
316
  file: ctx.file,
305
317
  fileId
306
318
  });
307
- pendingCompilation = performCompilation(resolvedConfig, [fileId]);
319
+ await hotUpdates.schedule(ctx.file, [fileId]);
320
+ if (EXCLUDED_TS_EXT_REGEX.test(fileId)) {
321
+ ctx.server.moduleGraph.invalidateAll();
322
+ ctx.server.ws.send({
323
+ type: "full-reload",
324
+ triggeredBy: fileId
325
+ });
326
+ return [];
327
+ }
308
328
  let result;
309
329
  if (shouldEnableLiveReload()) {
310
- await pendingCompilation;
311
- pendingCompilation = null;
312
330
  result = fileEmitter(fileId);
313
331
  debugHmr("TS file emitted", {
314
332
  fileId,
@@ -461,9 +479,7 @@ function angular(options) {
461
479
  if (ownerModules.length > 0) {
462
480
  const ownerIds = ownerModules.map((mod) => mod.id).filter(Boolean);
463
481
  ownerModules.forEach((mod) => ctx.server.moduleGraph.invalidateModule(mod));
464
- pendingCompilation = performCompilation(resolvedConfig, ownerIds);
465
- await pendingCompilation;
466
- pendingCompilation = null;
482
+ await hotUpdates.schedule(ctx.file, ownerIds);
467
483
  const updates = ownerIds.filter((id) => classNames.get(id));
468
484
  debugHmrV("template owner recompilation result", {
469
485
  file: ctx.file,
@@ -505,10 +521,9 @@ function angular(options) {
505
521
  updates,
506
522
  mods: mods.map((mod) => mod.id)
507
523
  });
508
- pendingCompilation = performCompilation(resolvedConfig, [...mods.map((mod) => mod.id).filter(Boolean), ...updates]);
524
+ if (mods.length === 0 && updates.length === 0) return mods;
525
+ await hotUpdates.schedule(ctx.file, [...mods.map((mod) => mod.id), ...updates]);
509
526
  if (updates.length > 0) {
510
- await pendingCompilation;
511
- pendingCompilation = null;
512
527
  debugHmr("resource importer component updates", {
513
528
  file: ctx.file,
514
529
  updateCount: updates.length
@@ -619,7 +634,7 @@ function angular(options) {
619
634
  * for test(Vitest)
620
635
  */
621
636
  if (isTest) {
622
- if (isVitestVscode && !initialCompilation) {
637
+ if (deferInitialCompilation && !initialCompilation) {
623
638
  pendingCompilation = performCompilation(this.environment?.config ?? resolvedConfig);
624
639
  initialCompilation = true;
625
640
  }
@@ -646,6 +661,7 @@ function angular(options) {
646
661
  await pendingCompilation;
647
662
  pendingCompilation = null;
648
663
  }
664
+ await hotUpdates.wait();
649
665
  const typescriptResult = fileEmitter(id);
650
666
  if (!typescriptResult) {
651
667
  debugCompilerV("transform skip (file not emitted by Angular)", { id });
@@ -703,6 +719,7 @@ function angular(options) {
703
719
  }
704
720
  },
705
721
  closeBundle() {
722
+ hotUpdates.close();
706
723
  declarationFiles.forEach(({ declarationFileDir, declarationPath, data }) => {
707
724
  mkdirSync(declarationFileDir, { recursive: true });
708
725
  writeFileSync(declarationPath, data, "utf-8");
@@ -786,7 +803,6 @@ function angular(options) {
786
803
  * It should not be called concurrently. Use `performCompilation` which wraps this method in a lock to ensure only one compilation runs at a time.
787
804
  */
788
805
  async function _doPerformCompilation(config, ids) {
789
- if (!jit) styleTransform = (code, filename) => preprocessCSS(code, filename, config);
790
806
  const isProd = config.mode === "production";
791
807
  invalidateSourceFiles(new Set(ids ?? []));
792
808
  if (ids?.length) for (const id of ids || []) fileTransformMap.delete(id);
@@ -832,6 +848,7 @@ function angular(options) {
832
848
  return file;
833
849
  }
834
850
  });
851
+ augmentHostWithModuleResolution(host, tsCompilerOptions);
835
852
  cachedHost = host;
836
853
  cachedHostKey = hostKey;
837
854
  if (watchMode) augmentHostWithCaching(host, tsSourceFileCache);
@@ -856,7 +873,7 @@ function angular(options) {
856
873
  */
857
874
  let typeScriptProgram;
858
875
  let angularCompiler;
859
- const oldBuilder = builder ?? ts.readBuilderProgram(tsCompilerOptions, host);
876
+ const oldBuilder = ids?.some((id) => EXCLUDED_TS_EXT_REGEX.test(id)) ? void 0 : builder ?? ts.readBuilderProgram(tsCompilerOptions, host);
860
877
  if (!jit) {
861
878
  const angularProgram = new compilerCli.NgtscProgram(rootNames, tsCompilerOptions, host, nextProgram);
862
879
  angularCompiler = angularProgram.compiler;