@analogjs/vite-plugin-angular 3.0.0-alpha.3 → 3.0.0-alpha.30

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 (97) hide show
  1. package/migrations/migrate-setup-vitest/migrate-setup-vitest.d.ts +2 -0
  2. package/migrations/migrate-setup-vitest/migrate-setup-vitest.js +49 -0
  3. package/migrations/migrate-setup-vitest/migrate-setup-vitest.js.map +1 -0
  4. package/migrations/migration.json +7 -1
  5. package/migrations/migrations.json +9 -0
  6. package/migrations/update-3-0-0/migrate-setup-vitest.d.ts +2 -0
  7. package/migrations/update-3-0-0/migrate-setup-vitest.js +36 -0
  8. package/migrations/update-3-0-0/migrate-setup-vitest.js.map +1 -0
  9. package/package.json +24 -12
  10. package/src/index.d.ts +3 -2
  11. package/src/index.js +6 -2
  12. package/src/index.js.map +1 -1
  13. package/src/lib/angular-build-optimizer-plugin.d.ts +4 -4
  14. package/src/lib/angular-build-optimizer-plugin.js +48 -62
  15. package/src/lib/angular-build-optimizer-plugin.js.map +1 -1
  16. package/src/lib/angular-jit-plugin.d.ts +3 -3
  17. package/src/lib/angular-jit-plugin.js +37 -37
  18. package/src/lib/angular-jit-plugin.js.map +1 -1
  19. package/src/lib/angular-pending-tasks.plugin.d.ts +7 -7
  20. package/src/lib/angular-pending-tasks.plugin.js +17 -18
  21. package/src/lib/angular-pending-tasks.plugin.js.map +1 -1
  22. package/src/lib/angular-vite-plugin.d.ts +224 -40
  23. package/src/lib/angular-vite-plugin.js +1929 -964
  24. package/src/lib/angular-vite-plugin.js.map +1 -1
  25. package/src/lib/angular-vitest-plugin.d.ts +19 -15
  26. package/src/lib/angular-vitest-plugin.js +99 -114
  27. package/src/lib/angular-vitest-plugin.js.map +1 -1
  28. package/src/lib/compiler-plugin.d.ts +11 -11
  29. package/src/lib/compiler-plugin.js +43 -44
  30. package/src/lib/compiler-plugin.js.map +1 -1
  31. package/src/lib/component-resolvers.d.ts +23 -5
  32. package/src/lib/component-resolvers.js +153 -63
  33. package/src/lib/component-resolvers.js.map +1 -1
  34. package/src/lib/host.d.ts +10 -8
  35. package/src/lib/host.js +109 -101
  36. package/src/lib/host.js.map +1 -1
  37. package/src/lib/live-reload-plugin.d.ts +5 -5
  38. package/src/lib/live-reload-plugin.js +57 -62
  39. package/src/lib/live-reload-plugin.js.map +1 -1
  40. package/src/lib/models.d.ts +9 -9
  41. package/src/lib/nx-folder-plugin.d.ts +5 -5
  42. package/src/lib/nx-folder-plugin.js +18 -16
  43. package/src/lib/nx-folder-plugin.js.map +1 -1
  44. package/src/lib/plugins/file-replacements.plugin.d.ts +4 -4
  45. package/src/lib/plugins/file-replacements.plugin.js +40 -62
  46. package/src/lib/plugins/file-replacements.plugin.js.map +1 -1
  47. package/src/lib/router-plugin.d.ts +1 -1
  48. package/src/lib/router-plugin.js +23 -23
  49. package/src/lib/router-plugin.js.map +1 -1
  50. package/src/lib/style-pipeline.d.ts +15 -0
  51. package/src/lib/style-pipeline.js +31 -0
  52. package/src/lib/style-pipeline.js.map +1 -0
  53. package/src/lib/style-preprocessor.d.ts +35 -0
  54. package/src/lib/style-preprocessor.js +35 -0
  55. package/src/lib/style-preprocessor.js.map +1 -0
  56. package/src/lib/stylesheet-registry.d.ts +73 -0
  57. package/src/lib/stylesheet-registry.js +168 -0
  58. package/src/lib/stylesheet-registry.js.map +1 -0
  59. package/src/lib/tools/package.json +2 -7
  60. package/src/lib/tools/src/builders/vite/vite-build.impl.js +31 -38
  61. package/src/lib/tools/src/builders/vite/vite-build.impl.js.map +1 -1
  62. package/src/lib/tools/src/builders/vite-dev-server/dev-server.impl.js +51 -62
  63. package/src/lib/tools/src/builders/vite-dev-server/dev-server.impl.js.map +1 -1
  64. package/src/lib/tools/src/index.js +0 -2
  65. package/src/lib/utils/compiler-plugin-options.d.ts +11 -11
  66. package/src/lib/utils/debug-harness.d.ts +23 -0
  67. package/src/lib/utils/debug-harness.js +88 -0
  68. package/src/lib/utils/debug-harness.js.map +1 -0
  69. package/src/lib/utils/debug-log-file.d.ts +5 -0
  70. package/src/lib/utils/debug-log-file.js +56 -0
  71. package/src/lib/utils/debug-log-file.js.map +1 -0
  72. package/src/lib/utils/debug.d.ts +26 -0
  73. package/src/lib/utils/debug.js +35 -0
  74. package/src/lib/utils/debug.js.map +1 -0
  75. package/src/lib/utils/devkit.d.ts +6 -6
  76. package/src/lib/utils/devkit.js +34 -38
  77. package/src/lib/utils/devkit.js.map +1 -1
  78. package/src/lib/utils/hmr-candidates.d.ts +28 -28
  79. package/src/lib/utils/rolldown.d.ts +2 -0
  80. package/src/lib/utils/rolldown.js +12 -0
  81. package/src/lib/utils/rolldown.js.map +1 -0
  82. package/src/lib/utils/source-file-cache.d.ts +8 -15
  83. package/src/lib/utils/source-file-cache.js +35 -37
  84. package/src/lib/utils/source-file-cache.js.map +1 -1
  85. package/src/test-setup.d.ts +2 -0
  86. package/setup-vitest.d.ts +0 -4
  87. package/setup-vitest.js +0 -215
  88. package/setup-vitest.js.map +0 -1
  89. package/src/lib/models.js +0 -1
  90. package/src/lib/models.js.map +0 -1
  91. package/src/lib/tools/README.md +0 -3
  92. package/src/lib/tools/src/index.d.ts +0 -0
  93. package/src/lib/tools/src/index.js.map +0 -1
  94. package/src/lib/utils/compiler-plugin-options.js +0 -1
  95. package/src/lib/utils/compiler-plugin-options.js.map +0 -1
  96. package/src/lib/utils/hmr-candidates.js +0 -272
  97. package/src/lib/utils/hmr-candidates.js.map +0 -1
@@ -1,48 +1,232 @@
1
- import { NgtscProgram } from '@angular/compiler-cli';
2
- import * as ts from 'typescript';
3
- import { Plugin } from 'vite';
4
- import { FileReplacement } from './plugins/file-replacements.plugin.js';
1
+ import { NgtscProgram } from "@angular/compiler-cli";
2
+ import * as ts from "typescript";
3
+ import { ModuleNode, Plugin, ViteDevServer } from "vite";
4
+ import type { StylePreprocessor } from "./style-preprocessor.js";
5
+ import { type DebugOption } from "./utils/debug.js";
6
+ import { FileReplacement } from "./plugins/file-replacements.plugin.js";
7
+ import { AnalogStylesheetRegistry } from "./stylesheet-registry.js";
8
+ import { type AngularStylePipelineOptions } from "./style-pipeline.js";
5
9
  export declare enum DiagnosticModes {
6
- None = 0,
7
- Option = 1,
8
- Syntactic = 2,
9
- Semantic = 4,
10
- All = 7
10
+ None = 0,
11
+ Option = 1,
12
+ Syntactic = 2,
13
+ Semantic = 4,
14
+ All = 7
11
15
  }
12
16
  export interface PluginOptions {
13
- tsconfig?: string | (() => string);
14
- workspaceRoot?: string;
15
- inlineStylesExtension?: string;
16
- jit?: boolean;
17
- advanced?: {
18
- /**
19
- * Custom TypeScript transformers that are run before Angular compilation
20
- */
21
- tsTransformers?: ts.CustomTransformers;
22
- };
23
- supportedBrowsers?: string[];
24
- transformFilter?: (code: string, id: string) => boolean;
25
- /**
26
- * Additional files to include in compilation
27
- */
28
- include?: string[];
29
- additionalContentDirs?: string[];
30
- liveReload?: boolean;
31
- disableTypeChecking?: boolean;
32
- fileReplacements?: FileReplacement[];
33
- experimental?: {
34
- useAngularCompilationAPI?: boolean;
35
- };
17
+ tsconfig?: string | (() => string);
18
+ workspaceRoot?: string;
19
+ inlineStylesExtension?: string;
20
+ jit?: boolean;
21
+ advanced?: {
22
+ /**
23
+ * Custom TypeScript transformers that are run before Angular compilation
24
+ */
25
+ tsTransformers?: ts.CustomTransformers;
26
+ };
27
+ supportedBrowsers?: string[];
28
+ transformFilter?: (code: string, id: string) => boolean;
29
+ /**
30
+ * Additional files to include in compilation
31
+ */
32
+ include?: string[];
33
+ additionalContentDirs?: string[];
34
+ /**
35
+ * Enables Angular's HMR during development/watch mode.
36
+ *
37
+ * Defaults to `true` for watch mode. Set to `false` to disable HMR while
38
+ * keeping other stylesheet externalization behavior available when needed.
39
+ */
40
+ hmr?: boolean;
41
+ /**
42
+ * @deprecated Use `hmr` instead. Kept as a compatibility alias.
43
+ */
44
+ liveReload?: boolean;
45
+ disableTypeChecking?: boolean;
46
+ fileReplacements?: FileReplacement[];
47
+ experimental?: {
48
+ useAngularCompilationAPI?: boolean;
49
+ };
50
+ /**
51
+ * Enable debug logging for specific scopes.
52
+ *
53
+ * - `true` → enables all `analog:angular:*` scopes
54
+ * - `string[]` → enables listed namespaces (e.g. `['analog:angular:tailwind']`)
55
+ * - `{ scopes?, mode? }` → object form with optional `mode: 'build' | 'dev'`
56
+ * to restrict output to a specific Vite command (omit for both)
57
+ *
58
+ * Also responds to the `DEBUG` env var (Node.js) or `localStorage.debug`
59
+ * (browser), using the `obug` convention.
60
+ */
61
+ debug?: DebugOption;
62
+ /**
63
+ * Optional preprocessor that transforms component CSS before it enters Vite's
64
+ * preprocessCSS pipeline. Runs on every component stylesheet (both external
65
+ * `.component.css` files and inline `styles: [...]` blocks).
66
+ *
67
+ * @param code - Raw CSS content of the component stylesheet
68
+ * @param filename - Resolved file path of the stylesheet (or containing .ts file for inline styles)
69
+ * @returns Transformed CSS string, or the original code if no transformation is needed
70
+ */
71
+ stylePreprocessor?: StylePreprocessor;
72
+ /**
73
+ * Experimental Angular stylesheet-resource hooks for community-maintained
74
+ * style-pipeline plugins.
75
+ *
76
+ * These hooks run inside the Angular resource pipeline, which is the seam a
77
+ * standalone Vite plugin cannot own on its own.
78
+ */
79
+ stylePipeline?: AngularStylePipelineOptions;
80
+ /**
81
+ * First-class Tailwind CSS v4 integration for Angular component styles.
82
+ *
83
+ * Angular's compiler processes component CSS through Vite's `preprocessCSS()`,
84
+ * which runs `@tailwindcss/vite` — but each component stylesheet is processed
85
+ * in isolation without access to the root Tailwind configuration (prefix, @theme,
86
+ * @custom-variant, @plugin definitions). This causes errors like:
87
+ *
88
+ * "Cannot apply utility class `sa:grid` because the `sa` variant does not exist"
89
+ *
90
+ * The `tailwindCss` option solves this by auto-injecting a `@reference` directive
91
+ * into every component CSS file that uses Tailwind utilities, pointing it to the
92
+ * root Tailwind stylesheet so `@tailwindcss/vite` can resolve the full configuration.
93
+ *
94
+ * @example Basic usage — reference a root Tailwind CSS file:
95
+ * ```ts
96
+ * import { resolve } from 'node:path';
97
+ *
98
+ * angular({
99
+ * tailwindCss: {
100
+ * rootStylesheet: resolve(__dirname, 'src/styles/tailwind.css'),
101
+ * },
102
+ * })
103
+ * ```
104
+ *
105
+ * @example With prefix detection — only inject for files using specific prefixes:
106
+ * ```ts
107
+ * angular({
108
+ * tailwindCss: {
109
+ * rootStylesheet: resolve(__dirname, 'src/styles/tailwind.css'),
110
+ * // Only inject @reference into files that use these prefixed classes
111
+ * prefixes: ['sa:', 'tw:'],
112
+ * },
113
+ * })
114
+ * ```
115
+ *
116
+ * @example AnalogJS platform — passed through the `vite` option:
117
+ * ```ts
118
+ * analog({
119
+ * vite: {
120
+ * tailwindCss: {
121
+ * rootStylesheet: resolve(__dirname, '../../../libs/meritos/tailwind.config.css'),
122
+ * },
123
+ * },
124
+ * })
125
+ * ```
126
+ */
127
+ tailwindCss?: {
128
+ /**
129
+ * Absolute path to the root Tailwind CSS file that contains `@import "tailwindcss"`,
130
+ * `@theme`, `@custom-variant`, and `@plugin` definitions.
131
+ *
132
+ * A `@reference` directive pointing to this file will be auto-injected into
133
+ * component CSS files that use Tailwind utilities.
134
+ */
135
+ rootStylesheet: string;
136
+ /**
137
+ * Optional list of class prefixes to detect (e.g. `['sa:', 'tw:']`).
138
+ * When provided, `@reference` is only injected into component CSS files that
139
+ * contain at least one of these prefixes. When omitted, `@reference` is injected
140
+ * into all component CSS files that contain `@apply` or `@` directives.
141
+ *
142
+ * @default undefined — inject into all component CSS files with `@apply`
143
+ */
144
+ prefixes?: string[];
145
+ };
36
146
  }
147
+ export declare function normalizeIncludeGlob(workspaceRoot: string, glob: string): string;
148
+ export declare function evictDeletedFileMetadata(file: string, { removeActiveGraphMetadata, removeStyleOwnerMetadata, classNamesMap, fileTransformMap }: {
149
+ removeActiveGraphMetadata: (file: string) => void;
150
+ removeStyleOwnerMetadata: (file: string) => void;
151
+ classNamesMap: Map<string, string>;
152
+ fileTransformMap: Map<string, string>;
153
+ }): void;
154
+ export declare function injectViteIgnoreForHmrMetadata(code: string): string;
155
+ export declare function isIgnoredHmrFile(file: string): boolean;
37
156
  export declare function angular(options?: PluginOptions): Plugin[];
38
- export declare function getFileMetadata(program: ts.BuilderProgram, angularCompiler?: NgtscProgram['compiler'], liveReload?: boolean, disableTypeChecking?: boolean): (file: string) => {
39
- errors?: string[];
40
- warnings?: (string | ts.DiagnosticMessageChain)[];
41
- hmrUpdateCode?: string | null;
42
- hmrEligible?: boolean;
157
+ export declare function createFsWatcherCacheInvalidator(invalidateFsCaches: () => void, invalidateTsconfigCaches: () => void, performCompilation: () => Promise<void>): () => Promise<void>;
158
+ /**
159
+ * Convert Analog/Angular CLI-style file replacements into the flat record
160
+ * expected by `AngularHostOptions.fileReplacements`.
161
+ *
162
+ * Only browser replacements (`{ replace, with }`) are converted. SSR-only
163
+ * replacements (`{ replace, ssr }`) are left for the Vite runtime plugin to
164
+ * handle — they should not be baked into the Angular compilation host because
165
+ * that would apply them to both browser and server builds.
166
+ *
167
+ * Relative paths are resolved against `workspaceRoot` so that the host
168
+ * receives the same absolute paths it would get from the Angular CLI.
169
+ */
170
+ export declare function toAngularCompilationFileReplacements(replacements: FileReplacement[], workspaceRoot: string): Record<string, string> | undefined;
171
+ /**
172
+ * Map Angular's `templateUpdates` (keyed by `encodedFilePath@ClassName`)
173
+ * back to absolute file paths with their associated HMR code and component
174
+ * class name.
175
+ *
176
+ * Angular's private Compilation API emits template update keys in the form
177
+ * `encodeURIComponent(relativePath + '@' + className)`. We decode and resolve
178
+ * them so the caller can look up updates by the same normalized absolute path
179
+ * used elsewhere in the plugin (`outputFiles`, `classNames`, etc.).
180
+ */
181
+ export declare function mapTemplateUpdatesToFiles(templateUpdates: ReadonlyMap<string, string> | undefined): Map<string, {
182
+ className: string;
183
+ code: string;
184
+ }>;
185
+ /**
186
+ * Returns every live Vite module that can legitimately represent a changed
187
+ * Angular resource file.
188
+ *
189
+ * For normal files, `getModulesByFile()` is enough. For Angular component
190
+ * stylesheets, it is not: the browser often holds virtual hashed requests
191
+ * (`/abc123.css?direct&ngcomp=...` and `/abc123.css?ngcomp=...`) that are no
192
+ * longer discoverable from the original source path alone. We therefore merge:
193
+ * - watcher event modules
194
+ * - module-graph modules by source file
195
+ * - registry-tracked live request ids resolved back through the module graph
196
+ */
197
+ export declare function getModulesForChangedFile(server: ViteDevServer, file: string, eventModules?: readonly ModuleNode[], stylesheetRegistry?: AnalogStylesheetRegistry): Promise<ModuleNode[]>;
198
+ export declare function isModuleForChangedResource(mod: ModuleNode, changedFile: string, stylesheetRegistry?: AnalogStylesheetRegistry): boolean;
199
+ /**
200
+ * Refreshes any already-served stylesheet records that map back to a changed
201
+ * source file.
202
+ *
203
+ * This is the critical bridge for externalized Angular component styles during
204
+ * HMR. Angular's resource watcher can notice that `/src/...component.css`
205
+ * changed before Angular recompilation has had a chance to repopulate the
206
+ * stylesheet registry. If we emit a CSS update against the existing virtual
207
+ * stylesheet id without first refreshing the registry content, the browser gets
208
+ * a hot update containing stale CSS. By rewriting the existing served records
209
+ * from disk up front, HMR always pushes the latest source content.
210
+ */
211
+ export declare function refreshStylesheetRegistryForFile(file: string, stylesheetRegistry?: AnalogStylesheetRegistry, stylePreprocessor?: StylePreprocessor): void;
212
+ export declare function findComponentStylesheetWrapperModules(server: ViteDevServer, changedFile: string, directModule: ModuleNode, fileModules: ModuleNode[], stylesheetRegistry?: AnalogStylesheetRegistry): Promise<ModuleNode[]>;
213
+ interface TemplateClassBindingIssue {
214
+ line: number;
215
+ column: number;
216
+ snippet: string;
217
+ }
218
+ export declare function findStaticClassAndBoundClassConflicts(template: string): TemplateClassBindingIssue[];
219
+ export declare function findBoundClassAndNgClassConflicts(template: string): TemplateClassBindingIssue[];
220
+ export declare function findTemplateOwnerModules(server: ViteDevServer, resourceFile: string): ModuleNode[];
221
+ export declare function getFileMetadata(program: ts.BuilderProgram, angularCompiler?: NgtscProgram["compiler"], hmrEnabled?: boolean, disableTypeChecking?: boolean): (file: string) => {
222
+ errors?: string[];
223
+ warnings?: (string | ts.DiagnosticMessageChain)[];
224
+ hmrUpdateCode?: string | null;
225
+ hmrEligible?: boolean;
43
226
  };
44
227
  /**
45
- * Checks for vitest run from the command line
46
- * @returns boolean
47
- */
228
+ * Checks for vitest run from the command line
229
+ * @returns boolean
230
+ */
48
231
  export declare function isTestWatchMode(args?: string[]): boolean;
232
+ export {};