@analogjs/vite-plugin-angular 3.0.0-alpha.70 → 3.0.0-alpha.71

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.70",
3
+ "version": "3.0.0-alpha.71",
4
4
  "description": "Vite Plugin for Angular",
5
5
  "type": "module",
6
6
  "keywords": [
package/src/index.d.ts CHANGED
@@ -1,4 +1,6 @@
1
1
  import { angular } from "./lib/angular-vite-plugin.js";
2
2
  export { angular } from "./lib/angular-vite-plugin.js";
3
3
  export type { PluginOptions } from "./lib/angular-vite-plugin.js";
4
+ export type { AnalogIntegrationPlugin, AnalogPluginContext, AnalogPluginHooks } from "./lib/analog-plugin-interop.js";
5
+ export type { StylePreprocessor, StylesheetTransformContext, StylesheetTransformResult } from "./lib/style-preprocessor.js";
4
6
  export default angular;
package/src/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","names":[],"sources":["../../src/index.ts"],"sourcesContent":["import { angular } from './lib/angular-vite-plugin.js';\nexport { angular } from './lib/angular-vite-plugin.js';\nexport type { PluginOptions } from './lib/angular-vite-plugin.js';\n\nexport default angular;\n"],"mappings":";;AAIA,IAAA,cAAe"}
1
+ {"version":3,"file":"index.js","names":[],"sources":["../../src/index.ts"],"sourcesContent":["import { angular } from './lib/angular-vite-plugin.js';\nexport { angular } from './lib/angular-vite-plugin.js';\nexport type { PluginOptions } from './lib/angular-vite-plugin.js';\nexport type {\n AnalogIntegrationPlugin,\n AnalogPluginContext,\n AnalogPluginHooks,\n} from './lib/analog-plugin-interop.js';\nexport type {\n StylePreprocessor,\n StylesheetTransformContext,\n StylesheetTransformResult,\n} from './lib/style-preprocessor.js';\n\nexport default angular;\n"],"mappings":";;AAcA,IAAA,cAAe"}
@@ -0,0 +1,40 @@
1
+ import type { Plugin, ResolvedConfig } from "vite";
2
+ import { type StylePreprocessor } from "./style-preprocessor.js";
3
+ /**
4
+ * Narrow framework context handed to a Vite plugin's `analog.setup()` hook.
5
+ * Only grows when a concrete integration needs another seam.
6
+ */
7
+ export interface AnalogPluginContext {
8
+ /**
9
+ * Registers a pre-transform that runs on every Angular component stylesheet
10
+ * before it enters Vite's `preprocessCSS` pipeline.
11
+ */
12
+ registerStylePreprocessor(preprocessor: StylePreprocessor): void;
13
+ }
14
+ export interface AnalogPluginHooks {
15
+ setup?(context: AnalogPluginContext): void | Promise<void>;
16
+ }
17
+ /**
18
+ * A normal Vite plugin that optionally exposes an `analog` setup hook.
19
+ * Discovery is structural (`plugin.analog?.setup`), so this type is a DX aid
20
+ * rather than a requirement.
21
+ */
22
+ export type AnalogIntegrationPlugin = Plugin & {
23
+ analog?: AnalogPluginHooks;
24
+ };
25
+ export interface AnalogIntegrations {
26
+ stylePreprocessor?: StylePreprocessor;
27
+ }
28
+ /**
29
+ * Runs every `analog.setup()` hook found in the resolved Vite plugin list,
30
+ * once per resolved config, and composes the registrations in plugin order.
31
+ */
32
+ export declare function discoverAnalogIntegrations(config: ResolvedConfig): Promise<AnalogIntegrations>;
33
+ export declare function runAnalogSetupHooks(plugins: readonly Plugin[]): Promise<AnalogIntegrations>;
34
+ /**
35
+ * Resolves the stylesheet preprocessor a compilation path should use:
36
+ * plugin-registered preprocessors first, then the chain configured through
37
+ * `angular()` options (Tailwind reference injection, `stylePipeline`,
38
+ * `stylePreprocessor`).
39
+ */
40
+ export declare function resolveStylePreprocessor(config: ResolvedConfig, configured?: StylePreprocessor): Promise<StylePreprocessor | undefined>;
@@ -0,0 +1,61 @@
1
+ import { debugStylePipeline } from "./utils/debug.js";
2
+ import { composeStylePreprocessors } from "./style-preprocessor.js";
3
+ //#region packages/vite-plugin-angular/src/lib/analog-plugin-interop.ts
4
+ var integrationsByConfig = /* @__PURE__ */ new WeakMap();
5
+ /**
6
+ * Runs every `analog.setup()` hook found in the resolved Vite plugin list,
7
+ * once per resolved config, and composes the registrations in plugin order.
8
+ */
9
+ function discoverAnalogIntegrations(config) {
10
+ let pending = integrationsByConfig.get(config);
11
+ if (!pending) {
12
+ pending = runAnalogSetupHooks(config.plugins ?? []);
13
+ integrationsByConfig.set(config, pending);
14
+ }
15
+ return pending;
16
+ }
17
+ async function runAnalogSetupHooks(plugins) {
18
+ const preprocessors = [];
19
+ for (const plugin of plugins) {
20
+ if (typeof plugin.analog?.setup !== "function") continue;
21
+ const registeredBefore = preprocessors.length;
22
+ const context = { registerStylePreprocessor(preprocessor) {
23
+ preprocessors.push(wrapStylePreprocessor(plugin.name, preprocessor));
24
+ } };
25
+ try {
26
+ await plugin.analog.setup(context);
27
+ } catch (error) {
28
+ throw new Error(`[analog] analog.setup() from plugin "${plugin.name}" failed: ${describeError(error)}`);
29
+ }
30
+ debugStylePipeline("analog.setup() completed", {
31
+ plugin: plugin.name,
32
+ stylePreprocessors: preprocessors.length - registeredBefore
33
+ });
34
+ }
35
+ return { stylePreprocessor: composeStylePreprocessors(preprocessors) };
36
+ }
37
+ /**
38
+ * Resolves the stylesheet preprocessor a compilation path should use:
39
+ * plugin-registered preprocessors first, then the chain configured through
40
+ * `angular()` options (Tailwind reference injection, `stylePipeline`,
41
+ * `stylePreprocessor`).
42
+ */
43
+ async function resolveStylePreprocessor(config, configured) {
44
+ return composeStylePreprocessors([(await discoverAnalogIntegrations(config)).stylePreprocessor, configured]);
45
+ }
46
+ function wrapStylePreprocessor(pluginName, preprocessor) {
47
+ return (code, filename, context) => {
48
+ try {
49
+ return preprocessor(code, filename, context);
50
+ } catch (error) {
51
+ throw new Error(`[analog] Style preprocessor from plugin "${pluginName}" failed for "${filename}": ${describeError(error)}`);
52
+ }
53
+ };
54
+ }
55
+ function describeError(error) {
56
+ return error instanceof Error ? error.message : String(error);
57
+ }
58
+ //#endregion
59
+ export { resolveStylePreprocessor };
60
+
61
+ //# sourceMappingURL=analog-plugin-interop.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"analog-plugin-interop.js","names":[],"sources":["../../../src/lib/analog-plugin-interop.ts"],"sourcesContent":["import type { Plugin, ResolvedConfig } from 'vite';\nimport {\n composeStylePreprocessors,\n type StylePreprocessor,\n} from './style-preprocessor.js';\nimport { debugStylePipeline } from './utils/debug.js';\n\n/**\n * Narrow framework context handed to a Vite plugin's `analog.setup()` hook.\n * Only grows when a concrete integration needs another seam.\n */\nexport interface AnalogPluginContext {\n /**\n * Registers a pre-transform that runs on every Angular component stylesheet\n * before it enters Vite's `preprocessCSS` pipeline.\n */\n registerStylePreprocessor(preprocessor: StylePreprocessor): void;\n}\n\nexport interface AnalogPluginHooks {\n setup?(context: AnalogPluginContext): void | Promise<void>;\n}\n\n/**\n * A normal Vite plugin that optionally exposes an `analog` setup hook.\n * Discovery is structural (`plugin.analog?.setup`), so this type is a DX aid\n * rather than a requirement.\n */\nexport type AnalogIntegrationPlugin = Plugin & { analog?: AnalogPluginHooks };\n\nexport interface AnalogIntegrations {\n stylePreprocessor?: StylePreprocessor;\n}\n\nconst integrationsByConfig = new WeakMap<\n ResolvedConfig,\n Promise<AnalogIntegrations>\n>();\n\n/**\n * Runs every `analog.setup()` hook found in the resolved Vite plugin list,\n * once per resolved config, and composes the registrations in plugin order.\n */\nexport function discoverAnalogIntegrations(\n config: ResolvedConfig,\n): Promise<AnalogIntegrations> {\n let pending = integrationsByConfig.get(config);\n if (!pending) {\n pending = runAnalogSetupHooks(config.plugins ?? []);\n integrationsByConfig.set(config, pending);\n }\n return pending;\n}\n\nexport async function runAnalogSetupHooks(\n plugins: readonly Plugin[],\n): Promise<AnalogIntegrations> {\n const preprocessors: StylePreprocessor[] = [];\n\n for (const plugin of plugins as readonly AnalogIntegrationPlugin[]) {\n if (typeof plugin.analog?.setup !== 'function') {\n continue;\n }\n\n const registeredBefore = preprocessors.length;\n const context: AnalogPluginContext = {\n registerStylePreprocessor(preprocessor) {\n preprocessors.push(wrapStylePreprocessor(plugin.name, preprocessor));\n },\n };\n\n try {\n await plugin.analog.setup(context);\n } catch (error) {\n throw new Error(\n `[analog] analog.setup() from plugin \"${plugin.name}\" failed: ${describeError(error)}`,\n );\n }\n\n debugStylePipeline('analog.setup() completed', {\n plugin: plugin.name,\n stylePreprocessors: preprocessors.length - registeredBefore,\n });\n }\n\n return { stylePreprocessor: composeStylePreprocessors(preprocessors) };\n}\n\n/**\n * Resolves the stylesheet preprocessor a compilation path should use:\n * plugin-registered preprocessors first, then the chain configured through\n * `angular()` options (Tailwind reference injection, `stylePipeline`,\n * `stylePreprocessor`).\n */\nexport async function resolveStylePreprocessor(\n config: ResolvedConfig,\n configured?: StylePreprocessor,\n): Promise<StylePreprocessor | undefined> {\n const integrations = await discoverAnalogIntegrations(config);\n return composeStylePreprocessors([\n integrations.stylePreprocessor,\n configured,\n ]);\n}\n\nfunction wrapStylePreprocessor(\n pluginName: string,\n preprocessor: StylePreprocessor,\n): StylePreprocessor {\n return (code, filename, context) => {\n try {\n return preprocessor(code, filename, context);\n } catch (error) {\n throw new Error(\n `[analog] Style preprocessor from plugin \"${pluginName}\" failed for \"${filename}\": ${describeError(error)}`,\n );\n }\n };\n}\n\nfunction describeError(error: unknown): string {\n return error instanceof Error ? error.message : String(error);\n}\n"],"mappings":";;;AAkCA,IAAM,uCAAuB,IAAI,SAG9B;;;;;AAMH,SAAgB,2BACd,QAC6B;CAC7B,IAAI,UAAU,qBAAqB,IAAI,OAAO;AAC9C,KAAI,CAAC,SAAS;AACZ,YAAU,oBAAoB,OAAO,WAAW,EAAE,CAAC;AACnD,uBAAqB,IAAI,QAAQ,QAAQ;;AAE3C,QAAO;;AAGT,eAAsB,oBACpB,SAC6B;CAC7B,MAAM,gBAAqC,EAAE;AAE7C,MAAK,MAAM,UAAU,SAA+C;AAClE,MAAI,OAAO,OAAO,QAAQ,UAAU,WAClC;EAGF,MAAM,mBAAmB,cAAc;EACvC,MAAM,UAA+B,EACnC,0BAA0B,cAAc;AACtC,iBAAc,KAAK,sBAAsB,OAAO,MAAM,aAAa,CAAC;KAEvE;AAED,MAAI;AACF,SAAM,OAAO,OAAO,MAAM,QAAQ;WAC3B,OAAO;AACd,SAAM,IAAI,MACR,wCAAwC,OAAO,KAAK,YAAY,cAAc,MAAM,GACrF;;AAGH,qBAAmB,4BAA4B;GAC7C,QAAQ,OAAO;GACf,oBAAoB,cAAc,SAAS;GAC5C,CAAC;;AAGJ,QAAO,EAAE,mBAAmB,0BAA0B,cAAc,EAAE;;;;;;;;AASxE,eAAsB,yBACpB,QACA,YACwC;AAExC,QAAO,0BAA0B,EADZ,MAAM,2BAA2B,OAAO,EAE9C,mBACb,WACD,CAAC;;AAGJ,SAAS,sBACP,YACA,cACmB;AACnB,SAAQ,MAAM,UAAU,YAAY;AAClC,MAAI;AACF,UAAO,aAAa,MAAM,UAAU,QAAQ;WACrC,OAAO;AACd,SAAM,IAAI,MACR,4CAA4C,WAAW,gBAAgB,SAAS,KAAK,cAAc,MAAM,GAC1G;;;;AAKP,SAAS,cAAc,OAAwB;AAC7C,QAAO,iBAAiB,QAAQ,MAAM,UAAU,OAAO,MAAM"}
@@ -1,15 +1,21 @@
1
1
  import { getJitInlineStyles } from "./utils/jit-inline-styles.js";
2
2
  import { debugStyles } from "./utils/debug.js";
3
3
  import { isTailwindReferenceError } from "./utils/tailwind-reference.js";
4
+ import { resolveStylePreprocessor } from "./analog-plugin-interop.js";
5
+ import { preprocessStylesheet } from "./stylesheet-registry.js";
4
6
  import { preprocessCSS } from "vite";
5
7
  //#region packages/vite-plugin-angular/src/lib/angular-jit-plugin.ts
6
8
  function jitPlugin({ inlineStylesExtension }) {
7
9
  let config;
10
+ let stylePreprocessor;
8
11
  return {
9
12
  name: "@analogjs/vite-plugin-angular-jit",
10
13
  configResolved(_config) {
11
14
  config = _config;
12
15
  },
16
+ async buildStart() {
17
+ stylePreprocessor = await resolveStylePreprocessor(config);
18
+ },
13
19
  resolveId(id) {
14
20
  if (id.startsWith("virtual:angular")) return `\0${id}`;
15
21
  },
@@ -19,9 +25,14 @@ function jitPlugin({ inlineStylesExtension }) {
19
25
  const encodedStyles = getJitInlineStyles(styleIdHash);
20
26
  if (encodedStyles === void 0) return;
21
27
  const decodedStyles = Buffer.from(decodeURIComponent(encodedStyles), "base64").toString();
28
+ const filename = `${styleIdHash}.${inlineStylesExtension}`;
29
+ const preprocessed = preprocessStylesheet(decodedStyles, filename, stylePreprocessor, {
30
+ filename,
31
+ inline: true
32
+ });
22
33
  let styles = "";
23
34
  try {
24
- styles = (await preprocessCSS(decodedStyles, `${styleIdHash}.${inlineStylesExtension}?direct`, config))?.code;
35
+ styles = (await preprocessCSS(preprocessed, `${filename}?direct`, config))?.code;
25
36
  } catch (e) {
26
37
  if (isTailwindReferenceError(e)) throw e;
27
38
  const errorMessage = e instanceof Error ? e.message : String(e);
@@ -1 +1 @@
1
- {"version":3,"file":"angular-jit-plugin.js","names":[],"sources":["../../../src/lib/angular-jit-plugin.ts"],"sourcesContent":["import { Plugin, ResolvedConfig, preprocessCSS } from 'vite';\nimport {\n JIT_INLINE_STYLE_PREFIX,\n getJitInlineStyles,\n} from './utils/jit-inline-styles.js';\nimport { debugStyles } from './utils/debug.js';\nimport { isTailwindReferenceError } from './utils/tailwind-reference.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(JIT_INLINE_STYLE_PREFIX)) {\n const styleIdHash = id.split('style:inline;')[1];\n const encodedStyles = getJitInlineStyles(styleIdHash);\n\n if (encodedStyles === undefined) {\n return;\n }\n\n const decodedStyles = Buffer.from(\n decodeURIComponent(encodedStyles),\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 if (isTailwindReferenceError(e)) {\n throw e;\n }\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":";;;;;AAQA,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,SAAA,oCAAiC,EAAE;IACxC,MAAM,cAAc,GAAG,MAAM,gBAAgB,CAAC;IAC9C,MAAM,gBAAgB,mBAAmB,YAAY;AAErD,QAAI,kBAAkB,KAAA,EACpB;IAGF,MAAM,gBAAgB,OAAO,KAC3B,mBAAmB,cAAc,EACjC,SACD,CAAC,UAAU;IAEZ,IAAI,SAA6B;AAEjC,QAAI;AAMF,eALiB,MAAM,cACrB,eACA,GAAG,YAAY,GAAG,sBAAsB,UACxC,OACD,GACkB;aACZ,GAAG;AACV,SAAI,yBAAyB,EAAE,CAC7B,OAAM;KAER,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
+ {"version":3,"file":"angular-jit-plugin.js","names":[],"sources":["../../../src/lib/angular-jit-plugin.ts"],"sourcesContent":["import { Plugin, ResolvedConfig, preprocessCSS } from 'vite';\nimport {\n JIT_INLINE_STYLE_PREFIX,\n getJitInlineStyles,\n} from './utils/jit-inline-styles.js';\nimport { debugStyles } from './utils/debug.js';\nimport { isTailwindReferenceError } from './utils/tailwind-reference.js';\nimport { resolveStylePreprocessor } from './analog-plugin-interop.js';\nimport { preprocessStylesheet } from './stylesheet-registry.js';\nimport type { StylePreprocessor } from './style-preprocessor.js';\n\nexport function jitPlugin({\n inlineStylesExtension,\n}: {\n inlineStylesExtension: string;\n}): Plugin {\n let config: ResolvedConfig;\n let stylePreprocessor: StylePreprocessor | undefined;\n\n return {\n name: '@analogjs/vite-plugin-angular-jit',\n configResolved(_config) {\n config = _config;\n },\n async buildStart() {\n stylePreprocessor = await resolveStylePreprocessor(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(JIT_INLINE_STYLE_PREFIX)) {\n const styleIdHash = id.split('style:inline;')[1];\n const encodedStyles = getJitInlineStyles(styleIdHash);\n\n if (encodedStyles === undefined) {\n return;\n }\n\n const decodedStyles = Buffer.from(\n decodeURIComponent(encodedStyles),\n 'base64',\n ).toString();\n const filename = `${styleIdHash}.${inlineStylesExtension}`;\n const preprocessed = preprocessStylesheet(\n decodedStyles,\n filename,\n stylePreprocessor,\n { filename, inline: true },\n );\n\n let styles: string | undefined = '';\n\n try {\n const compiled = await preprocessCSS(\n preprocessed,\n `${filename}?direct`,\n config,\n );\n styles = compiled?.code;\n } catch (e) {\n if (isTailwindReferenceError(e)) {\n throw e;\n }\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":";;;;;;;AAWA,SAAgB,UAAU,EACxB,yBAGS;CACT,IAAI;CACJ,IAAI;AAEJ,QAAO;EACL,MAAM;EACN,eAAe,SAAS;AACtB,YAAS;;EAEX,MAAM,aAAa;AACjB,uBAAoB,MAAM,yBAAyB,OAAO;;EAE5D,UAAU,IAAY;AACpB,OAAI,GAAG,WAAW,kBAAkB,CAClC,QAAO,KAAK;;EAKhB,MAAM,KAAK,IAAY;AACrB,OAAI,GAAG,SAAA,oCAAiC,EAAE;IACxC,MAAM,cAAc,GAAG,MAAM,gBAAgB,CAAC;IAC9C,MAAM,gBAAgB,mBAAmB,YAAY;AAErD,QAAI,kBAAkB,KAAA,EACpB;IAGF,MAAM,gBAAgB,OAAO,KAC3B,mBAAmB,cAAc,EACjC,SACD,CAAC,UAAU;IACZ,MAAM,WAAW,GAAG,YAAY,GAAG;IACnC,MAAM,eAAe,qBACnB,eACA,UACA,mBACA;KAAE;KAAU,QAAQ;KAAM,CAC3B;IAED,IAAI,SAA6B;AAEjC,QAAI;AAMF,eALiB,MAAM,cACrB,cACA,GAAG,SAAS,UACZ,OACD,GACkB;aACZ,GAAG;AACV,SAAI,yBAAyB,EAAE,CAC7B,OAAM;KAER,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"}
@@ -7,7 +7,6 @@ import { FileReplacement } from "./plugins/file-replacements.plugin.js";
7
7
  import { AnalogStylesheetRegistry } from "./stylesheet-registry.js";
8
8
  import { AngularStylePipelineOptions } from "./style-pipeline.js";
9
9
  export { DiagnosticModes, injectViteIgnoreForHmrMetadata, isIgnoredHmrFile, toAngularCompilationFileReplacements, mapTemplateUpdatesToFiles, refreshStylesheetRegistryForFile, describeStylesheetContent, isTestWatchMode } from "./utils/compilation-shared.js";
10
- export { findStaticClassAndBoundClassConflicts, findBoundClassAndNgClassConflicts } from "./template-class-binding-guard-plugin.js";
11
10
  export { buildStylePreprocessor } from "./tailwind-plugin.js";
12
11
  export interface PluginOptions {
13
12
  tsconfig?: string | (() => string);
@@ -152,9 +151,7 @@ export interface PluginOptions {
152
151
  prefixes?: string[];
153
152
  };
154
153
  }
155
- export declare function evictDeletedFileMetadata(file: string, { removeActiveGraphMetadata, removeStyleOwnerMetadata, classNamesMap, fileTransformMap }: {
156
- removeActiveGraphMetadata: (file: string) => void;
157
- removeStyleOwnerMetadata: (file: string) => void;
154
+ export declare function evictDeletedFileMetadata(file: string, { classNamesMap, fileTransformMap }: {
158
155
  classNamesMap: Map<string, string>;
159
156
  fileTransformMap: Map<string, string>;
160
157
  }): void;
@@ -5,9 +5,10 @@ import { getJsTransformConfigKey, isRolldown } from "./utils/rolldown.js";
5
5
  import { buildOptimizerPlugin } from "./angular-build-optimizer-plugin.js";
6
6
  import { toJitInlineStyleId } from "./utils/jit-inline-styles.js";
7
7
  import { activateDeferredDebug, applyDebugOption, debugCompiler, debugCompilerV, debugEmit, debugEmitV, debugHmr, debugHmrV, debugStyles, debugStylesV } from "./utils/debug.js";
8
- import { jitPlugin } from "./angular-jit-plugin.js";
9
- import { StyleUrlsResolver, TemplateUrlsResolver, getAngularComponentMetadata } from "./component-resolvers.js";
8
+ import { resolveStylePreprocessor } from "./analog-plugin-interop.js";
10
9
  import { AnalogStylesheetRegistry, preprocessStylesheet, rewriteRelativeCssImports } from "./stylesheet-registry.js";
10
+ import { jitPlugin } from "./angular-jit-plugin.js";
11
+ import { StyleUrlsResolver, TemplateUrlsResolver } from "./component-resolvers.js";
11
12
  import { augmentHostWithCaching, augmentHostWithResources, augmentProgramWithVersioning, mergeTransformers } from "./host.js";
12
13
  import { TsconfigResolver } from "./utils/tsconfig-resolver.js";
13
14
  import { configureStylePipelineRegistry } from "./style-pipeline.js";
@@ -20,7 +21,6 @@ import { ANGULAR_DECORATOR_CALL_RE } from "./compiler/constants.js";
20
21
  import "./compiler/index.js";
21
22
  import { markStylePathSafe } from "./utils/safe-module-paths.js";
22
23
  import { fastCompilePlugin } from "./fast-compile-plugin.js";
23
- import { removeActiveGraphMetadata, removeStyleOwnerMetadata, templateClassBindingGuardPlugin } from "./template-class-binding-guard-plugin.js";
24
24
  import { buildStylePreprocessor, tailwindReferencePlugin, validateTailwindConfig } from "./tailwind-plugin.js";
25
25
  import { encapsulationPlugin, getComponentStyleSheetMeta, isComponentStyleSheet } from "./encapsulation-plugin.js";
26
26
  import { virtualModulesPlugin } from "./virtual-modules-plugin.js";
@@ -40,16 +40,15 @@ import { normalizePath, preprocessCSS } from "vite";
40
40
  //#region packages/vite-plugin-angular/src/lib/angular-vite-plugin.ts
41
41
  var require = createRequire(import.meta.url);
42
42
  var classNames = /* @__PURE__ */ new Map();
43
- function evictDeletedFileMetadata(file, { removeActiveGraphMetadata, removeStyleOwnerMetadata, classNamesMap, fileTransformMap }) {
43
+ function evictDeletedFileMetadata(file, { classNamesMap, fileTransformMap }) {
44
44
  const normalizedFile = normalizePath(file.split("?")[0]);
45
- removeActiveGraphMetadata(normalizedFile);
46
- removeStyleOwnerMetadata(normalizedFile);
47
45
  classNamesMap.delete(normalizedFile);
48
46
  fileTransformMap.delete(normalizedFile);
49
47
  }
50
48
  function angular(options) {
51
49
  applyDebugOption(options?.debug, options?.workspaceRoot);
52
50
  const liveReload = options?.liveReload ?? true;
51
+ const configuredStylePreprocessor = buildStylePreprocessor(options);
53
52
  /**
54
53
  * Normalize plugin options so defaults
55
54
  * are used for values not provided.
@@ -75,7 +74,7 @@ function angular(options) {
75
74
  fastCompileMode: options?.fastCompileMode ?? "full",
76
75
  hasTailwindCss: !!options?.tailwindCss,
77
76
  tailwindCss: options?.tailwindCss,
78
- stylePreprocessor: buildStylePreprocessor(options)
77
+ stylePreprocessor: configuredStylePreprocessor
79
78
  };
80
79
  let resolvedConfig;
81
80
  let tsConfigResolutionContext = null;
@@ -102,11 +101,6 @@ function angular(options) {
102
101
  }
103
102
  let watchMode = false;
104
103
  let testWatchMode = isTestWatchMode();
105
- const activeGraphComponentMetadata = /* @__PURE__ */ new Map();
106
- const selectorOwners = /* @__PURE__ */ new Map();
107
- const classNameOwners = /* @__PURE__ */ new Map();
108
- const transformedStyleOwnerMetadata = /* @__PURE__ */ new Map();
109
- const styleSourceOwners = /* @__PURE__ */ new Map();
110
104
  function hasViteHmrTransport() {
111
105
  return resolvedConfig ? resolvedConfig.server.hmr !== false : true;
112
106
  }
@@ -145,14 +139,6 @@ function angular(options) {
145
139
  const jit = typeof pluginOptions?.jit !== "undefined" ? pluginOptions.jit : isTest;
146
140
  let viteServer;
147
141
  const styleUrlsResolver = new StyleUrlsResolver();
148
- const guardContext = {
149
- styleUrlsResolver,
150
- activeGraphComponentMetadata,
151
- selectorOwners,
152
- classNameOwners,
153
- transformedStyleOwnerMetadata,
154
- styleSourceOwners
155
- };
156
142
  const templateUrlsResolver = new TemplateUrlsResolver();
157
143
  let outputFile;
158
144
  const outputFiles = /* @__PURE__ */ new Map();
@@ -284,8 +270,6 @@ function angular(options) {
284
270
  server.watcher.on("add", invalidateCompilationOnFsChange);
285
271
  server.watcher.on("unlink", (file) => {
286
272
  evictDeletedFileMetadata(file, {
287
- removeActiveGraphMetadata: (f) => removeActiveGraphMetadata(guardContext, f),
288
- removeStyleOwnerMetadata: (f) => removeStyleOwnerMetadata(guardContext, f),
289
273
  classNamesMap: classNames,
290
274
  fileTransformMap
291
275
  });
@@ -440,52 +424,18 @@ function angular(options) {
440
424
  directId: isDirect.id,
441
425
  trackedRequestIds: stylesheetRegistry?.getRequestIdsForSource(ctx.file) ?? []
442
426
  });
443
- const ownerModules = findStyleOwnerModules(ctx.server, ctx.file, styleSourceOwners);
444
- debugHmrV("component stylesheet owner fallback lookup", {
445
- file: ctx.file,
446
- ownerCount: ownerModules.length,
447
- ownerIds: ownerModules.map((mod) => mod.id),
448
- ownerFiles: [...styleSourceOwners.get(normalizePath(ctx.file)) ?? []]
449
- });
450
- if (ownerModules.length > 0) {
451
- pendingCompilation = performCompilation(resolvedConfig, [...ownerModules.map((mod) => mod.id).filter(Boolean)]);
452
- await pendingCompilation;
453
- pendingCompilation = null;
454
- const updates = ownerModules.map((mod) => mod.id).filter((id) => !!id && !!classNames.get(id));
455
- const derivedUpdates = ownerModules.map((mod) => mod.id).filter((id) => !!id).flatMap((ownerId) => resolveComponentClassNamesForStyleOwner(ownerId, ctx.file).map((className) => ({
456
- ownerId,
457
- className,
458
- via: "raw-component-metadata"
459
- })));
460
- debugHmrV("component stylesheet owner fallback compilation", {
461
- file: ctx.file,
462
- ownerIds: ownerModules.map((mod) => mod.id),
463
- updateIds: updates,
464
- classNames: updates.map((id) => ({
465
- id,
466
- className: classNames.get(id)
467
- })),
468
- derivedUpdates
469
- });
470
- if (derivedUpdates.length > 0) debugHmrV("component stylesheet owner fallback derived updates", {
471
- file: ctx.file,
472
- updates: derivedUpdates,
473
- hint: "Angular did not repopulate classNames during CSS-only owner recompilation, so Analog derived component identities from raw component metadata."
474
- });
475
- }
476
427
  logComponentStylesheetHmrOutcome({
477
428
  file: ctx.file,
478
429
  encapsulation,
479
430
  diagnosis: stylesheetDiagnosis,
480
431
  outcome: "full-reload",
481
432
  directModuleId: isDirect.id,
482
- wrapperIds: wrapperModules.map((mod) => mod.id),
483
- ownerIds: ownerModules.map((mod) => mod.id)
433
+ wrapperIds: wrapperModules.map((mod) => mod.id)
484
434
  });
485
435
  sendFullReload(ctx.server, {
486
436
  file: ctx.file,
487
437
  encapsulation,
488
- reason: wrapperModules.length === 0 ? "missing-wrapper-module-and-no-owner-updates" : "shadow-encapsulation",
438
+ reason: wrapperModules.length === 0 ? "missing-wrapper-module" : "shadow-encapsulation",
489
439
  directId: isDirect.id,
490
440
  trackedRequestIds: stylesheetRegistry?.getRequestIdsForSource(ctx.file) ?? []
491
441
  });
@@ -799,7 +749,6 @@ function angular(options) {
799
749
  cssExtensionStyleResolverPlugin(),
800
750
  replaceFiles(pluginOptions.fileReplacements, pluginOptions.workspaceRoot),
801
751
  virtualModulesPlugin({ jit }),
802
- templateClassBindingGuardPlugin(guardContext),
803
752
  pluginOptions.hasTailwindCss && tailwindReferencePlugin({ tailwindCss: pluginOptions.tailwindCss }),
804
753
  pluginOptions.liveReload && liveReloadPlugin({
805
754
  classNames,
@@ -833,6 +782,7 @@ function angular(options) {
833
782
  });
834
783
  try {
835
784
  await previousLock;
785
+ pluginOptions.stylePreprocessor = await resolveStylePreprocessor(config, configuredStylePreprocessor);
836
786
  await _doPerformCompilation(config, ids);
837
787
  } finally {
838
788
  resolve();
@@ -1181,12 +1131,6 @@ function sendFullReload(server, details) {
1181
1131
  server.ws.send("analog:debug-full-reload", details);
1182
1132
  server.ws.send({ type: "full-reload" });
1183
1133
  }
1184
- function resolveComponentClassNamesForStyleOwner(ownerFile, sourcePath) {
1185
- if (!existsSync(ownerFile)) return [];
1186
- const components = getAngularComponentMetadata(readFileSync(ownerFile, "utf-8"));
1187
- const normalizedSourcePath = normalizePath(sourcePath);
1188
- return components.filter((component) => component.styleUrls.some((styleUrl) => normalizePath(resolve(dirname(ownerFile), styleUrl)) === normalizedSourcePath)).map((component) => component.className);
1189
- }
1190
1134
  function logComponentStylesheetHmrOutcome(details) {
1191
1135
  const pitfalls = [];
1192
1136
  const rejectedPreferredPaths = [];
@@ -1194,7 +1138,6 @@ function logComponentStylesheetHmrOutcome(details) {
1194
1138
  if (details.encapsulation === "shadow") {
1195
1139
  pitfalls.push("shadow-encapsulation");
1196
1140
  rejectedPreferredPaths.push("css-update");
1197
- rejectedPreferredPaths.push("owner-component-update");
1198
1141
  hints.push("Shadow DOM styles cannot rely on Vite CSS patching because Angular applies them inside a shadow root.");
1199
1142
  }
1200
1143
  if (details.diagnosis.anomalies.includes("wrapper_not_yet_tracked")) {
@@ -1207,27 +1150,12 @@ function logComponentStylesheetHmrOutcome(details) {
1207
1150
  rejectedPreferredPaths.push("css-update");
1208
1151
  hints.push("A wrapper request id is known, but Vite could not resolve a live wrapper module for targeted CSS HMR.");
1209
1152
  }
1210
- if ((details.ownerIds?.filter(Boolean).length ?? 0) === 0) {
1211
- pitfalls.push("no-owner-modules");
1212
- if (details.outcome === "full-reload") {
1213
- rejectedPreferredPaths.push("owner-component-update");
1214
- hints.push("No owning TS component modules were available in the module graph for owner-based fallback.");
1215
- }
1216
- } else if ((details.updateIds?.length ?? 0) === 0) {
1217
- pitfalls.push("owner-modules-without-class-identities");
1218
- if (details.outcome === "full-reload") {
1219
- rejectedPreferredPaths.push("owner-component-update");
1220
- hints.push("Owner modules were found, but Angular did not expose component class identities after recompilation, so no targeted component update could be sent.");
1221
- }
1222
- }
1223
1153
  debugHmrV("component stylesheet hmr outcome", {
1224
1154
  file: details.file,
1225
1155
  outcome: details.outcome,
1226
1156
  encapsulation: details.encapsulation,
1227
1157
  directModuleId: details.directModuleId,
1228
1158
  wrapperIds: details.wrapperIds ?? [],
1229
- ownerIds: details.ownerIds ?? [],
1230
- updateIds: details.updateIds ?? [],
1231
1159
  preferredPath: details.encapsulation === "shadow" ? "full-reload" : "css-update",
1232
1160
  rejectedPreferredPaths: [...new Set(rejectedPreferredPaths)],
1233
1161
  pitfalls: [...new Set(pitfalls)],
@@ -1243,15 +1171,6 @@ function findTemplateOwnerModules(server, resourceFile) {
1243
1171
  });
1244
1172
  return [...modules.values()];
1245
1173
  }
1246
- function findStyleOwnerModules(server, resourceFile, styleSourceOwners) {
1247
- const normalizedResourceFile = normalizePath(resourceFile.split("?")[0]);
1248
- const candidateOwnerFiles = [...styleSourceOwners.get(normalizedResourceFile) ?? []];
1249
- const modules = /* @__PURE__ */ new Map();
1250
- for (const ownerFile of candidateOwnerFiles) server.moduleGraph.getModulesByFile(ownerFile)?.forEach((mod) => {
1251
- if (mod.id) modules.set(mod.id, mod);
1252
- });
1253
- return [...modules.values()];
1254
- }
1255
1174
  /**
1256
1175
  * @internal
1257
1176
  */