@analogjs/vite-plugin-angular 3.0.0-alpha.23 → 3.0.0-alpha.25

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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@analogjs/vite-plugin-angular",
3
- "version": "3.0.0-alpha.23",
3
+ "version": "3.0.0-alpha.25",
4
4
  "description": "Vite Plugin for Angular",
5
5
  "type": "module",
6
6
  "keywords": [
@@ -36,10 +36,11 @@
36
36
  }
37
37
  },
38
38
  "dependencies": {
39
+ "es-toolkit": "^1.45.1",
39
40
  "obug": "^2.1.1",
40
- "oxc-parser": "^0.121.0",
41
+ "oxc-parser": "^0.123.0",
41
42
  "oxc-resolver": "^11.19.1",
42
- "rolldown": "^1.0.0-rc.12",
43
+ "rolldown": "^1.0.0-rc.13",
43
44
  "tinyglobby": "^0.2.15"
44
45
  },
45
46
  "builders": "./src/lib/tools/builders.json",
@@ -1,5 +1,6 @@
1
- import { preprocessCSS } from "vite";
1
+ import { debugStyles } from "./utils/debug.js";
2
2
  import { createHash } from "node:crypto";
3
+ import { preprocessCSS } from "vite";
3
4
  //#region packages/vite-plugin-angular/src/lib/angular-jit-plugin.ts
4
5
  function jitPlugin({ inlineStylesExtension }) {
5
6
  let config;
@@ -20,7 +21,12 @@ function jitPlugin({ inlineStylesExtension }) {
20
21
  try {
21
22
  styles = (await preprocessCSS(decodedStyles, `${styleIdHash}.${inlineStylesExtension}?direct`, config))?.code;
22
23
  } catch (e) {
23
- console.error(`${e}`);
24
+ const errorMessage = e instanceof Error ? e.message : String(e);
25
+ debugStyles("jit css compilation error", {
26
+ styleIdHash,
27
+ error: errorMessage
28
+ });
29
+ console.warn("[@analogjs/vite-plugin-angular]: Failed to preprocess inline JIT stylesheet %s. Returning an empty stylesheet instead. %s", styleIdHash, errorMessage);
24
30
  }
25
31
  return `export default \`${styles}\``;
26
32
  }
@@ -1 +1 @@
1
- {"version":3,"file":"angular-jit-plugin.js","names":[],"sources":["../../../src/lib/angular-jit-plugin.ts"],"sourcesContent":["import { createHash } from 'node:crypto';\nimport { Plugin, ResolvedConfig, preprocessCSS } from 'vite';\n\nexport function jitPlugin({\n inlineStylesExtension,\n}: {\n inlineStylesExtension: string;\n}): Plugin {\n let config: ResolvedConfig;\n\n return {\n name: '@analogjs/vite-plugin-angular-jit',\n configResolved(_config) {\n config = _config;\n },\n resolveId(id: string) {\n if (id.startsWith('virtual:angular')) {\n return `\\0${id}`;\n }\n\n return;\n },\n async load(id: string) {\n if (id.includes('virtual:angular:jit:style:inline;')) {\n const styleId = id.split('style:inline;')[1];\n // styleId may exceed 255 bytes of base64-encoded content, limit to 16\n const styleIdHash = createHash('sha256')\n .update(styleId)\n .digest('hex')\n .slice(0, 16);\n\n const decodedStyles = Buffer.from(\n decodeURIComponent(styleId),\n 'base64',\n ).toString();\n\n let styles: string | undefined = '';\n\n try {\n const compiled = await preprocessCSS(\n decodedStyles,\n `${styleIdHash}.${inlineStylesExtension}?direct`,\n config,\n );\n styles = compiled?.code;\n } catch (e) {\n console.error(`${e}`);\n }\n\n return `export default \\`${styles}\\``;\n }\n\n return;\n },\n };\n}\n"],"mappings":";;;AAGA,SAAgB,UAAU,EACxB,yBAGS;CACT,IAAI;AAEJ,QAAO;EACL,MAAM;EACN,eAAe,SAAS;AACtB,YAAS;;EAEX,UAAU,IAAY;AACpB,OAAI,GAAG,WAAW,kBAAkB,CAClC,QAAO,KAAK;;EAKhB,MAAM,KAAK,IAAY;AACrB,OAAI,GAAG,SAAS,oCAAoC,EAAE;IACpD,MAAM,UAAU,GAAG,MAAM,gBAAgB,CAAC;IAE1C,MAAM,cAAc,WAAW,SAAS,CACrC,OAAO,QAAQ,CACf,OAAO,MAAM,CACb,MAAM,GAAG,GAAG;IAEf,MAAM,gBAAgB,OAAO,KAC3B,mBAAmB,QAAQ,EAC3B,SACD,CAAC,UAAU;IAEZ,IAAI,SAA6B;AAEjC,QAAI;AAMF,eALiB,MAAM,cACrB,eACA,GAAG,YAAY,GAAG,sBAAsB,UACxC,OACD,GACkB;aACZ,GAAG;AACV,aAAQ,MAAM,GAAG,IAAI;;AAGvB,WAAO,oBAAoB,OAAO;;;EAKvC"}
1
+ {"version":3,"file":"angular-jit-plugin.js","names":[],"sources":["../../../src/lib/angular-jit-plugin.ts"],"sourcesContent":["import { createHash } from 'node:crypto';\nimport { Plugin, ResolvedConfig, preprocessCSS } from 'vite';\nimport { debugStyles } from './utils/debug.js';\n\nexport function jitPlugin({\n inlineStylesExtension,\n}: {\n inlineStylesExtension: string;\n}): Plugin {\n let config: ResolvedConfig;\n\n return {\n name: '@analogjs/vite-plugin-angular-jit',\n configResolved(_config) {\n config = _config;\n },\n resolveId(id: string) {\n if (id.startsWith('virtual:angular')) {\n return `\\0${id}`;\n }\n\n return;\n },\n async load(id: string) {\n if (id.includes('virtual:angular:jit:style:inline;')) {\n const styleId = id.split('style:inline;')[1];\n // styleId may exceed 255 bytes of base64-encoded content, limit to 16\n const styleIdHash = createHash('sha256')\n .update(styleId)\n .digest('hex')\n .slice(0, 16);\n\n const decodedStyles = Buffer.from(\n decodeURIComponent(styleId),\n 'base64',\n ).toString();\n\n let styles: string | undefined = '';\n\n try {\n const compiled = await preprocessCSS(\n decodedStyles,\n `${styleIdHash}.${inlineStylesExtension}?direct`,\n config,\n );\n styles = compiled?.code;\n } catch (e) {\n const errorMessage = e instanceof Error ? e.message : String(e);\n debugStyles('jit css compilation error', {\n styleIdHash,\n error: errorMessage,\n });\n console.warn(\n '[@analogjs/vite-plugin-angular]: Failed to preprocess inline JIT stylesheet %s. Returning an empty stylesheet instead. %s',\n styleIdHash,\n errorMessage,\n );\n }\n\n return `export default \\`${styles}\\``;\n }\n\n return;\n },\n };\n}\n"],"mappings":";;;;AAIA,SAAgB,UAAU,EACxB,yBAGS;CACT,IAAI;AAEJ,QAAO;EACL,MAAM;EACN,eAAe,SAAS;AACtB,YAAS;;EAEX,UAAU,IAAY;AACpB,OAAI,GAAG,WAAW,kBAAkB,CAClC,QAAO,KAAK;;EAKhB,MAAM,KAAK,IAAY;AACrB,OAAI,GAAG,SAAS,oCAAoC,EAAE;IACpD,MAAM,UAAU,GAAG,MAAM,gBAAgB,CAAC;IAE1C,MAAM,cAAc,WAAW,SAAS,CACrC,OAAO,QAAQ,CACf,OAAO,MAAM,CACb,MAAM,GAAG,GAAG;IAEf,MAAM,gBAAgB,OAAO,KAC3B,mBAAmB,QAAQ,EAC3B,SACD,CAAC,UAAU;IAEZ,IAAI,SAA6B;AAEjC,QAAI;AAMF,eALiB,MAAM,cACrB,eACA,GAAG,YAAY,GAAG,sBAAsB,UACxC,OACD,GACkB;aACZ,GAAG;KACV,MAAM,eAAe,aAAa,QAAQ,EAAE,UAAU,OAAO,EAAE;AAC/D,iBAAY,6BAA6B;MACvC;MACA,OAAO;MACR,CAAC;AACF,aAAQ,KACN,6HACA,aACA,aACD;;AAGH,WAAO,oBAAoB,OAAO;;;EAKvC"}
@@ -1,9 +1,10 @@
1
1
  import { NgtscProgram } from "@angular/compiler-cli";
2
2
  import * as ts from "typescript";
3
- import { Plugin } from "vite";
3
+ import { ModuleNode, Plugin, ViteDevServer } from "vite";
4
4
  import type { StylePreprocessor } from "./style-preprocessor.js";
5
5
  import { type DebugOption } from "./utils/debug.js";
6
6
  import { FileReplacement } from "./plugins/file-replacements.plugin.js";
7
+ import { AnalogStylesheetRegistry } from "./stylesheet-registry.js";
7
8
  export declare enum DiagnosticModes {
8
9
  None = 0,
9
10
  Option = 1,
@@ -29,6 +30,16 @@ export interface PluginOptions {
29
30
  */
30
31
  include?: string[];
31
32
  additionalContentDirs?: string[];
33
+ /**
34
+ * Enables Angular's HMR during development/watch mode.
35
+ *
36
+ * Defaults to `true` for watch mode. Set to `false` to disable HMR while
37
+ * keeping other stylesheet externalization behavior available when needed.
38
+ */
39
+ hmr?: boolean;
40
+ /**
41
+ * @deprecated Use `hmr` instead. Kept as a compatibility alias.
42
+ */
32
43
  liveReload?: boolean;
33
44
  disableTypeChecking?: boolean;
34
45
  fileReplacements?: FileReplacement[];
@@ -39,7 +50,7 @@ export interface PluginOptions {
39
50
  * Enable debug logging for specific scopes.
40
51
  *
41
52
  * - `true` → enables all `analog:angular:*` scopes
42
- * - `string[]` → enables listed namespaces (e.g. `['analog:angular:compiler']`)
53
+ * - `string[]` → enables listed namespaces (e.g. `['analog:angular:tailwind']`)
43
54
  * - `{ scopes?, mode? }` → object form with optional `mode: 'build' | 'dev'`
44
55
  * to restrict output to a specific Vite command (omit for both)
45
56
  *
@@ -124,6 +135,15 @@ export interface PluginOptions {
124
135
  prefixes?: string[];
125
136
  };
126
137
  }
138
+ export declare function normalizeIncludeGlob(workspaceRoot: string, glob: string): string;
139
+ export declare function evictDeletedFileMetadata(file: string, { removeActiveGraphMetadata, removeStyleOwnerMetadata, classNamesMap, fileTransformMap }: {
140
+ removeActiveGraphMetadata: (file: string) => void;
141
+ removeStyleOwnerMetadata: (file: string) => void;
142
+ classNamesMap: Map<string, string>;
143
+ fileTransformMap: Map<string, string>;
144
+ }): void;
145
+ export declare function injectViteIgnoreForHmrMetadata(code: string): string;
146
+ export declare function isIgnoredHmrFile(file: string): boolean;
127
147
  export declare function angular(options?: PluginOptions): Plugin[];
128
148
  export declare function createFsWatcherCacheInvalidator(invalidateFsCaches: () => void, invalidateTsconfigCaches: () => void, performCompilation: () => Promise<void>): () => Promise<void>;
129
149
  /**
@@ -153,7 +173,43 @@ export declare function mapTemplateUpdatesToFiles(templateUpdates: ReadonlyMap<s
153
173
  className: string;
154
174
  code: string;
155
175
  }>;
156
- export declare function getFileMetadata(program: ts.BuilderProgram, angularCompiler?: NgtscProgram["compiler"], liveReload?: boolean, disableTypeChecking?: boolean): (file: string) => {
176
+ /**
177
+ * Returns every live Vite module that can legitimately represent a changed
178
+ * Angular resource file.
179
+ *
180
+ * For normal files, `getModulesByFile()` is enough. For Angular component
181
+ * stylesheets, it is not: the browser often holds virtual hashed requests
182
+ * (`/abc123.css?direct&ngcomp=...` and `/abc123.css?ngcomp=...`) that are no
183
+ * longer discoverable from the original source path alone. We therefore merge:
184
+ * - watcher event modules
185
+ * - module-graph modules by source file
186
+ * - registry-tracked live request ids resolved back through the module graph
187
+ */
188
+ export declare function getModulesForChangedFile(server: ViteDevServer, file: string, eventModules?: readonly ModuleNode[], stylesheetRegistry?: AnalogStylesheetRegistry): Promise<ModuleNode[]>;
189
+ export declare function isModuleForChangedResource(mod: ModuleNode, changedFile: string, stylesheetRegistry?: AnalogStylesheetRegistry): boolean;
190
+ /**
191
+ * Refreshes any already-served stylesheet records that map back to a changed
192
+ * source file.
193
+ *
194
+ * This is the critical bridge for externalized Angular component styles during
195
+ * HMR. Angular's resource watcher can notice that `/src/...component.css`
196
+ * changed before Angular recompilation has had a chance to repopulate the
197
+ * stylesheet registry. If we emit a CSS update against the existing virtual
198
+ * stylesheet id without first refreshing the registry content, the browser gets
199
+ * a hot update containing stale CSS. By rewriting the existing served records
200
+ * from disk up front, HMR always pushes the latest source content.
201
+ */
202
+ export declare function refreshStylesheetRegistryForFile(file: string, stylesheetRegistry?: AnalogStylesheetRegistry, stylePreprocessor?: StylePreprocessor): void;
203
+ export declare function findComponentStylesheetWrapperModules(server: ViteDevServer, changedFile: string, directModule: ModuleNode, fileModules: ModuleNode[], stylesheetRegistry?: AnalogStylesheetRegistry): Promise<ModuleNode[]>;
204
+ interface TemplateClassBindingIssue {
205
+ line: number;
206
+ column: number;
207
+ snippet: string;
208
+ }
209
+ export declare function findStaticClassAndBoundClassConflicts(template: string): TemplateClassBindingIssue[];
210
+ export declare function findBoundClassAndNgClassConflicts(template: string): TemplateClassBindingIssue[];
211
+ export declare function findTemplateOwnerModules(server: ViteDevServer, resourceFile: string): ModuleNode[];
212
+ export declare function getFileMetadata(program: ts.BuilderProgram, angularCompiler?: NgtscProgram["compiler"], hmrEnabled?: boolean, disableTypeChecking?: boolean): (file: string) => {
157
213
  errors?: string[];
158
214
  warnings?: (string | ts.DiagnosticMessageChain)[];
159
215
  hmrUpdateCode?: string | null;
@@ -164,3 +220,4 @@ export declare function getFileMetadata(program: ts.BuilderProgram, angularCompi
164
220
  * @returns boolean
165
221
  */
166
222
  export declare function isTestWatchMode(args?: string[]): boolean;
223
+ export {};