@analogjs/vite-plugin-angular 3.0.0-alpha.2 → 3.0.0-alpha.20

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 (79) 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/package.json +8 -11
  6. package/src/index.d.ts +3 -2
  7. package/src/index.js +6 -2
  8. package/src/index.js.map +1 -1
  9. package/src/lib/angular-build-optimizer-plugin.d.ts +4 -4
  10. package/src/lib/angular-build-optimizer-plugin.js +48 -62
  11. package/src/lib/angular-build-optimizer-plugin.js.map +1 -1
  12. package/src/lib/angular-jit-plugin.d.ts +3 -3
  13. package/src/lib/angular-jit-plugin.js +31 -37
  14. package/src/lib/angular-jit-plugin.js.map +1 -1
  15. package/src/lib/angular-pending-tasks.plugin.d.ts +7 -7
  16. package/src/lib/angular-pending-tasks.plugin.js +17 -18
  17. package/src/lib/angular-pending-tasks.plugin.js.map +1 -1
  18. package/src/lib/angular-vite-plugin.d.ts +145 -45
  19. package/src/lib/angular-vite-plugin.js +822 -963
  20. package/src/lib/angular-vite-plugin.js.map +1 -1
  21. package/src/lib/angular-vitest-plugin.d.ts +20 -16
  22. package/src/lib/angular-vitest-plugin.js +88 -114
  23. package/src/lib/angular-vitest-plugin.js.map +1 -1
  24. package/src/lib/compiler-plugin.d.ts +11 -11
  25. package/src/lib/compiler-plugin.js +43 -44
  26. package/src/lib/compiler-plugin.js.map +1 -1
  27. package/src/lib/component-resolvers.d.ts +8 -6
  28. package/src/lib/component-resolvers.js +93 -64
  29. package/src/lib/component-resolvers.js.map +1 -1
  30. package/src/lib/host.d.ts +10 -8
  31. package/src/lib/host.js +70 -101
  32. package/src/lib/host.js.map +1 -1
  33. package/src/lib/live-reload-plugin.d.ts +5 -5
  34. package/src/lib/live-reload-plugin.js +51 -62
  35. package/src/lib/live-reload-plugin.js.map +1 -1
  36. package/src/lib/models.d.ts +9 -9
  37. package/src/lib/nx-folder-plugin.d.ts +5 -5
  38. package/src/lib/nx-folder-plugin.js +18 -16
  39. package/src/lib/nx-folder-plugin.js.map +1 -1
  40. package/src/lib/plugins/file-replacements.plugin.d.ts +4 -4
  41. package/src/lib/plugins/file-replacements.plugin.js +35 -62
  42. package/src/lib/plugins/file-replacements.plugin.js.map +1 -1
  43. package/src/lib/router-plugin.d.ts +1 -1
  44. package/src/lib/router-plugin.js +23 -23
  45. package/src/lib/router-plugin.js.map +1 -1
  46. package/src/lib/style-preprocessor.d.ts +1 -0
  47. package/src/lib/tools/package.json +2 -7
  48. package/src/lib/tools/src/builders/vite/vite-build.impl.js +31 -35
  49. package/src/lib/tools/src/builders/vite/vite-build.impl.js.map +1 -1
  50. package/src/lib/tools/src/builders/vite-dev-server/dev-server.impl.js +51 -59
  51. package/src/lib/tools/src/builders/vite-dev-server/dev-server.impl.js.map +1 -1
  52. package/src/lib/tools/src/index.js +0 -1
  53. package/src/lib/utils/compiler-plugin-options.d.ts +11 -11
  54. package/src/lib/utils/devkit.d.ts +4 -4
  55. package/src/lib/utils/devkit.js +34 -38
  56. package/src/lib/utils/devkit.js.map +1 -1
  57. package/src/lib/utils/hmr-candidates.d.ts +28 -28
  58. package/src/lib/utils/rolldown.d.ts +2 -0
  59. package/src/lib/utils/rolldown.js +12 -0
  60. package/src/lib/utils/rolldown.js.map +1 -0
  61. package/src/lib/utils/source-file-cache.d.ts +8 -15
  62. package/src/lib/utils/source-file-cache.js +35 -37
  63. package/src/lib/utils/source-file-cache.js.map +1 -1
  64. package/src/test-setup.d.ts +2 -0
  65. package/setup-vitest.d.ts +0 -4
  66. package/setup-vitest.js +0 -217
  67. package/setup-vitest.js.map +0 -1
  68. package/src/lib/models.js +0 -1
  69. package/src/lib/models.js.map +0 -1
  70. package/src/lib/tools/README.md +0 -3
  71. package/src/lib/tools/src/index.d.ts +0 -0
  72. package/src/lib/tools/src/index.js.map +0 -1
  73. package/src/lib/utils/compiler-plugin-options.js +0 -1
  74. package/src/lib/utils/compiler-plugin-options.js.map +0 -1
  75. package/src/lib/utils/hmr-candidates.js +0 -272
  76. package/src/lib/utils/hmr-candidates.js.map +0 -1
  77. package/vite.config.d.ts +0 -2
  78. package/vite.config.js +0 -22
  79. package/vite.config.js.map +0 -1
@@ -1,53 +1,153 @@
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 { Plugin } from "vite";
4
+ import type { StylePreprocessor } from "./style-preprocessor.js";
5
+ import { FileReplacement } from "./plugins/file-replacements.plugin.js";
5
6
  export declare enum DiagnosticModes {
6
- None = 0,
7
- Option = 1,
8
- Syntactic = 2,
9
- Semantic = 4,
10
- All = 7
7
+ None = 0,
8
+ Option = 1,
9
+ Syntactic = 2,
10
+ Semantic = 4,
11
+ All = 7
11
12
  }
12
13
  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
- };
14
+ tsconfig?: string | (() => string);
15
+ workspaceRoot?: string;
16
+ inlineStylesExtension?: string;
17
+ jit?: boolean;
18
+ advanced?: {
19
+ /**
20
+ * Custom TypeScript transformers that are run before Angular compilation
21
+ */
22
+ tsTransformers?: ts.CustomTransformers;
23
+ };
24
+ supportedBrowsers?: string[];
25
+ transformFilter?: (code: string, id: string) => boolean;
26
+ /**
27
+ * Additional files to include in compilation
28
+ */
29
+ include?: string[];
30
+ additionalContentDirs?: string[];
31
+ liveReload?: boolean;
32
+ disableTypeChecking?: boolean;
33
+ fileReplacements?: FileReplacement[];
34
+ experimental?: {
35
+ useAngularCompilationAPI?: boolean;
36
+ };
37
+ /**
38
+ * Optional preprocessor that transforms component CSS before it enters Vite's
39
+ * preprocessCSS pipeline. Runs on every component stylesheet (both external
40
+ * `.component.css` files and inline `styles: [...]` blocks).
41
+ *
42
+ * @param code - Raw CSS content of the component stylesheet
43
+ * @param filename - Resolved file path of the stylesheet (or containing .ts file for inline styles)
44
+ * @returns Transformed CSS string, or the original code if no transformation is needed
45
+ */
46
+ stylePreprocessor?: StylePreprocessor;
47
+ /**
48
+ * First-class Tailwind CSS v4 integration for Angular component styles.
49
+ *
50
+ * Angular's compiler processes component CSS through Vite's `preprocessCSS()`,
51
+ * which runs `@tailwindcss/vite` — but each component stylesheet is processed
52
+ * in isolation without access to the root Tailwind configuration (prefix, @theme,
53
+ * @custom-variant, @plugin definitions). This causes errors like:
54
+ *
55
+ * "Cannot apply utility class `sa:grid` because the `sa` variant does not exist"
56
+ *
57
+ * The `tailwindCss` option solves this by auto-injecting a `@reference` directive
58
+ * into every component CSS file that uses Tailwind utilities, pointing it to the
59
+ * root Tailwind stylesheet so `@tailwindcss/vite` can resolve the full configuration.
60
+ *
61
+ * @example Basic usage — reference a root Tailwind CSS file:
62
+ * ```ts
63
+ * import { resolve } from 'node:path';
64
+ *
65
+ * angular({
66
+ * tailwindCss: {
67
+ * rootStylesheet: resolve(__dirname, 'src/styles/tailwind.css'),
68
+ * },
69
+ * })
70
+ * ```
71
+ *
72
+ * @example With prefix detection — only inject for files using specific prefixes:
73
+ * ```ts
74
+ * angular({
75
+ * tailwindCss: {
76
+ * rootStylesheet: resolve(__dirname, 'src/styles/tailwind.css'),
77
+ * // Only inject @reference into files that use these prefixed classes
78
+ * prefixes: ['sa:', 'tw:'],
79
+ * },
80
+ * })
81
+ * ```
82
+ *
83
+ * @example AnalogJS platform — passed through the `vite` option:
84
+ * ```ts
85
+ * analog({
86
+ * vite: {
87
+ * tailwindCss: {
88
+ * rootStylesheet: resolve(__dirname, '../../../libs/meritos/tailwind.config.css'),
89
+ * },
90
+ * },
91
+ * })
92
+ * ```
93
+ */
94
+ tailwindCss?: {
95
+ /**
96
+ * Absolute path to the root Tailwind CSS file that contains `@import "tailwindcss"`,
97
+ * `@theme`, `@custom-variant`, and `@plugin` definitions.
98
+ *
99
+ * A `@reference` directive pointing to this file will be auto-injected into
100
+ * component CSS files that use Tailwind utilities.
101
+ */
102
+ rootStylesheet: string;
103
+ /**
104
+ * Optional list of class prefixes to detect (e.g. `['sa:', 'tw:']`).
105
+ * When provided, `@reference` is only injected into component CSS files that
106
+ * contain at least one of these prefixes. When omitted, `@reference` is injected
107
+ * into all component CSS files that contain `@apply` or `@` directives.
108
+ *
109
+ * @default undefined — inject into all component CSS files with `@apply`
110
+ */
111
+ prefixes?: string[];
112
+ };
36
113
  }
37
114
  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?: undefined;
40
- warnings?: undefined;
41
- hmrUpdateCode?: undefined;
42
- hmrEligible?: undefined;
43
- } | {
44
- errors: string[];
45
- warnings: (string | ts.DiagnosticMessageChain)[];
46
- hmrUpdateCode: string | null | undefined;
47
- hmrEligible: boolean;
115
+ export declare function createFsWatcherCacheInvalidator(invalidateFsCaches: () => void, invalidateTsconfigCaches: () => void, performCompilation: () => Promise<void>): () => Promise<void>;
116
+ /**
117
+ * Convert Analog/Angular CLI-style file replacements into the flat record
118
+ * expected by `AngularHostOptions.fileReplacements`.
119
+ *
120
+ * Only browser replacements (`{ replace, with }`) are converted. SSR-only
121
+ * replacements (`{ replace, ssr }`) are left for the Vite runtime plugin to
122
+ * handle they should not be baked into the Angular compilation host because
123
+ * that would apply them to both browser and server builds.
124
+ *
125
+ * Relative paths are resolved against `workspaceRoot` so that the host
126
+ * receives the same absolute paths it would get from the Angular CLI.
127
+ */
128
+ export declare function toAngularCompilationFileReplacements(replacements: FileReplacement[], workspaceRoot: string): Record<string, string> | undefined;
129
+ /**
130
+ * Map Angular's `templateUpdates` (keyed by `encodedFilePath@ClassName`)
131
+ * back to absolute file paths with their associated HMR code and component
132
+ * class name.
133
+ *
134
+ * Angular's private Compilation API emits template update keys in the form
135
+ * `encodeURIComponent(relativePath + '@' + className)`. We decode and resolve
136
+ * them so the caller can look up updates by the same normalized absolute path
137
+ * used elsewhere in the plugin (`outputFiles`, `classNames`, etc.).
138
+ */
139
+ export declare function mapTemplateUpdatesToFiles(templateUpdates: ReadonlyMap<string, string> | undefined): Map<string, {
140
+ className: string;
141
+ code: string;
142
+ }>;
143
+ export declare function getFileMetadata(program: ts.BuilderProgram, angularCompiler?: NgtscProgram["compiler"], liveReload?: boolean, disableTypeChecking?: boolean): (file: string) => {
144
+ errors?: string[];
145
+ warnings?: (string | ts.DiagnosticMessageChain)[];
146
+ hmrUpdateCode?: string | null;
147
+ hmrEligible?: boolean;
48
148
  };
49
149
  /**
50
- * Checks for vitest run from the command line
51
- * @returns boolean
52
- */
150
+ * Checks for vitest run from the command line
151
+ * @returns boolean
152
+ */
53
153
  export declare function isTestWatchMode(args?: string[]): boolean;