@analogjs/vite-plugin-angular 3.0.0-alpha.70 → 3.0.0-alpha.72
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 +1 -1
- package/src/index.d.ts +2 -0
- package/src/index.js.map +1 -1
- package/src/lib/analog-plugin-interop.d.ts +49 -0
- package/src/lib/analog-plugin-interop.js +75 -0
- package/src/lib/analog-plugin-interop.js.map +1 -0
- package/src/lib/angular-jit-plugin.js +12 -1
- package/src/lib/angular-jit-plugin.js.map +1 -1
- package/src/lib/angular-vite-plugin.d.ts +1 -4
- package/src/lib/angular-vite-plugin.js +14 -91
- package/src/lib/angular-vite-plugin.js.map +1 -1
- package/src/lib/compilation-api/compilation-api-plugin.js +8 -1
- package/src/lib/compilation-api/compilation-api-plugin.js.map +1 -1
- package/src/lib/component-resolvers.js +1 -47
- package/src/lib/component-resolvers.js.map +1 -1
- package/src/lib/template-class-binding-guard-plugin.d.ts +0 -30
- package/src/lib/template-class-binding-guard-plugin.js +0 -237
- package/src/lib/template-class-binding-guard-plugin.js.map +0 -1
package/package.json
CHANGED
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":";;
|
|
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,49 @@
|
|
|
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
|
+
* Requests that component styles are externalized in dev and watch mode so
|
|
15
|
+
* they run through Vite's CSS plugin pipeline (for example
|
|
16
|
+
* `@tailwindcss/vite`) instead of being inlined through `preprocessCSS`,
|
|
17
|
+
* which only runs PostCSS and CSS preprocessors. Production builds keep
|
|
18
|
+
* inlining component styles.
|
|
19
|
+
*/
|
|
20
|
+
externalizeComponentStyles(): void;
|
|
21
|
+
}
|
|
22
|
+
export interface AnalogPluginHooks {
|
|
23
|
+
setup?(context: AnalogPluginContext): void | Promise<void>;
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* A normal Vite plugin that optionally exposes an `analog` setup hook.
|
|
27
|
+
* Discovery is structural (`plugin.analog?.setup`), so this type is a DX aid
|
|
28
|
+
* rather than a requirement.
|
|
29
|
+
*/
|
|
30
|
+
export type AnalogIntegrationPlugin = Plugin & {
|
|
31
|
+
analog?: AnalogPluginHooks;
|
|
32
|
+
};
|
|
33
|
+
export interface AnalogIntegrations {
|
|
34
|
+
stylePreprocessor?: StylePreprocessor;
|
|
35
|
+
externalizeStyles: boolean;
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Runs every `analog.setup()` hook found in the resolved Vite plugin list,
|
|
39
|
+
* once per resolved config, and composes the registrations in plugin order.
|
|
40
|
+
*/
|
|
41
|
+
export declare function discoverAnalogIntegrations(config: ResolvedConfig): Promise<AnalogIntegrations>;
|
|
42
|
+
export declare function runAnalogSetupHooks(plugins: readonly Plugin[]): Promise<AnalogIntegrations>;
|
|
43
|
+
/**
|
|
44
|
+
* Resolves what a compilation path needs from the discovered integrations:
|
|
45
|
+
* the stylesheet preprocessor chain (plugin-registered preprocessors first,
|
|
46
|
+
* then the chain configured through `angular()` options) and whether any
|
|
47
|
+
* plugin asked for externalized component styles.
|
|
48
|
+
*/
|
|
49
|
+
export declare function resolveAnalogIntegrations(config: ResolvedConfig, configured?: StylePreprocessor): Promise<AnalogIntegrations>;
|
|
@@ -0,0 +1,75 @@
|
|
|
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
|
+
let externalizeStyles = false;
|
|
20
|
+
for (const plugin of plugins) {
|
|
21
|
+
if (typeof plugin.analog?.setup !== "function") continue;
|
|
22
|
+
const registeredBefore = preprocessors.length;
|
|
23
|
+
const context = {
|
|
24
|
+
registerStylePreprocessor(preprocessor) {
|
|
25
|
+
preprocessors.push(wrapStylePreprocessor(plugin.name, preprocessor));
|
|
26
|
+
},
|
|
27
|
+
externalizeComponentStyles() {
|
|
28
|
+
externalizeStyles = true;
|
|
29
|
+
}
|
|
30
|
+
};
|
|
31
|
+
try {
|
|
32
|
+
await plugin.analog.setup(context);
|
|
33
|
+
} catch (error) {
|
|
34
|
+
throw new Error(`[analog] analog.setup() from plugin "${plugin.name}" failed: ${describeError(error)}`);
|
|
35
|
+
}
|
|
36
|
+
debugStylePipeline("analog.setup() completed", {
|
|
37
|
+
plugin: plugin.name,
|
|
38
|
+
stylePreprocessors: preprocessors.length - registeredBefore,
|
|
39
|
+
externalizeStyles
|
|
40
|
+
});
|
|
41
|
+
}
|
|
42
|
+
return {
|
|
43
|
+
stylePreprocessor: composeStylePreprocessors(preprocessors),
|
|
44
|
+
externalizeStyles
|
|
45
|
+
};
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* Resolves what a compilation path needs from the discovered integrations:
|
|
49
|
+
* the stylesheet preprocessor chain (plugin-registered preprocessors first,
|
|
50
|
+
* then the chain configured through `angular()` options) and whether any
|
|
51
|
+
* plugin asked for externalized component styles.
|
|
52
|
+
*/
|
|
53
|
+
async function resolveAnalogIntegrations(config, configured) {
|
|
54
|
+
const integrations = await discoverAnalogIntegrations(config);
|
|
55
|
+
return {
|
|
56
|
+
stylePreprocessor: composeStylePreprocessors([integrations.stylePreprocessor, configured]),
|
|
57
|
+
externalizeStyles: integrations.externalizeStyles
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
function wrapStylePreprocessor(pluginName, preprocessor) {
|
|
61
|
+
return (code, filename, context) => {
|
|
62
|
+
try {
|
|
63
|
+
return preprocessor(code, filename, context);
|
|
64
|
+
} catch (error) {
|
|
65
|
+
throw new Error(`[analog] Style preprocessor from plugin "${pluginName}" failed for "${filename}": ${describeError(error)}`);
|
|
66
|
+
}
|
|
67
|
+
};
|
|
68
|
+
}
|
|
69
|
+
function describeError(error) {
|
|
70
|
+
return error instanceof Error ? error.message : String(error);
|
|
71
|
+
}
|
|
72
|
+
//#endregion
|
|
73
|
+
export { resolveAnalogIntegrations };
|
|
74
|
+
|
|
75
|
+
//# 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 * Requests that component styles are externalized in dev and watch mode so\n * they run through Vite's CSS plugin pipeline (for example\n * `@tailwindcss/vite`) instead of being inlined through `preprocessCSS`,\n * which only runs PostCSS and CSS preprocessors. Production builds keep\n * inlining component styles.\n */\n externalizeComponentStyles(): 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 externalizeStyles: boolean;\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 let externalizeStyles = false;\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 externalizeComponentStyles() {\n externalizeStyles = true;\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 externalizeStyles,\n });\n }\n\n return {\n stylePreprocessor: composeStylePreprocessors(preprocessors),\n externalizeStyles,\n };\n}\n\n/**\n * Resolves what a compilation path needs from the discovered integrations:\n * the stylesheet preprocessor chain (plugin-registered preprocessors first,\n * then the chain configured through `angular()` options) and whether any\n * plugin asked for externalized component styles.\n */\nexport async function resolveAnalogIntegrations(\n config: ResolvedConfig,\n configured?: StylePreprocessor,\n): Promise<AnalogIntegrations> {\n const integrations = await discoverAnalogIntegrations(config);\n return {\n stylePreprocessor: composeStylePreprocessors([\n integrations.stylePreprocessor,\n configured,\n ]),\n externalizeStyles: integrations.externalizeStyles,\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":";;;AA2CA,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;CAC7C,IAAI,oBAAoB;AAExB,MAAK,MAAM,UAAU,SAA+C;AAClE,MAAI,OAAO,OAAO,QAAQ,UAAU,WAClC;EAGF,MAAM,mBAAmB,cAAc;EACvC,MAAM,UAA+B;GACnC,0BAA0B,cAAc;AACtC,kBAAc,KAAK,sBAAsB,OAAO,MAAM,aAAa,CAAC;;GAEtE,6BAA6B;AAC3B,wBAAoB;;GAEvB;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;GAC3C;GACD,CAAC;;AAGJ,QAAO;EACL,mBAAmB,0BAA0B,cAAc;EAC3D;EACD;;;;;;;;AASH,eAAsB,0BACpB,QACA,YAC6B;CAC7B,MAAM,eAAe,MAAM,2BAA2B,OAAO;AAC7D,QAAO;EACL,mBAAmB,0BAA0B,CAC3C,aAAa,mBACb,WACD,CAAC;EACF,mBAAmB,aAAa;EACjC;;AAGH,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 { resolveAnalogIntegrations } 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 resolveAnalogIntegrations(config)).stylePreprocessor;
|
|
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(
|
|
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
|
|
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 { resolveAnalogIntegrations } 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 resolveAnalogIntegrations(config))\n .stylePreprocessor;\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,wBAAqB,MAAM,0BAA0B,OAAO,EACzD;;EAEL,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, {
|
|
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 {
|
|
9
|
-
import { StyleUrlsResolver, TemplateUrlsResolver, getAngularComponentMetadata } from "./component-resolvers.js";
|
|
8
|
+
import { resolveAnalogIntegrations } 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,16 @@ 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, {
|
|
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);
|
|
52
|
+
let externalizeStylesRequested = false;
|
|
53
53
|
/**
|
|
54
54
|
* Normalize plugin options so defaults
|
|
55
55
|
* are used for values not provided.
|
|
@@ -75,7 +75,7 @@ function angular(options) {
|
|
|
75
75
|
fastCompileMode: options?.fastCompileMode ?? "full",
|
|
76
76
|
hasTailwindCss: !!options?.tailwindCss,
|
|
77
77
|
tailwindCss: options?.tailwindCss,
|
|
78
|
-
stylePreprocessor:
|
|
78
|
+
stylePreprocessor: configuredStylePreprocessor
|
|
79
79
|
};
|
|
80
80
|
let resolvedConfig;
|
|
81
81
|
let tsConfigResolutionContext = null;
|
|
@@ -102,11 +102,6 @@ function angular(options) {
|
|
|
102
102
|
}
|
|
103
103
|
let watchMode = false;
|
|
104
104
|
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
105
|
function hasViteHmrTransport() {
|
|
111
106
|
return resolvedConfig ? resolvedConfig.server.hmr !== false : true;
|
|
112
107
|
}
|
|
@@ -131,7 +126,7 @@ function angular(options) {
|
|
|
131
126
|
*/
|
|
132
127
|
function shouldExternalizeStyles() {
|
|
133
128
|
if (!(isTest ? testWatchMode : watchMode)) return false;
|
|
134
|
-
return !!(shouldEnableLiveReload() || pluginOptions.hasTailwindCss);
|
|
129
|
+
return !!(shouldEnableLiveReload() || pluginOptions.hasTailwindCss || externalizeStylesRequested);
|
|
135
130
|
}
|
|
136
131
|
function validateNoDuplicateAnalogPlugins(config) {
|
|
137
132
|
const analogInstances = (config.plugins ?? []).filter((p) => p.name === "@analogjs/vite-plugin-angular");
|
|
@@ -145,14 +140,6 @@ function angular(options) {
|
|
|
145
140
|
const jit = typeof pluginOptions?.jit !== "undefined" ? pluginOptions.jit : isTest;
|
|
146
141
|
let viteServer;
|
|
147
142
|
const styleUrlsResolver = new StyleUrlsResolver();
|
|
148
|
-
const guardContext = {
|
|
149
|
-
styleUrlsResolver,
|
|
150
|
-
activeGraphComponentMetadata,
|
|
151
|
-
selectorOwners,
|
|
152
|
-
classNameOwners,
|
|
153
|
-
transformedStyleOwnerMetadata,
|
|
154
|
-
styleSourceOwners
|
|
155
|
-
};
|
|
156
143
|
const templateUrlsResolver = new TemplateUrlsResolver();
|
|
157
144
|
let outputFile;
|
|
158
145
|
const outputFiles = /* @__PURE__ */ new Map();
|
|
@@ -284,8 +271,6 @@ function angular(options) {
|
|
|
284
271
|
server.watcher.on("add", invalidateCompilationOnFsChange);
|
|
285
272
|
server.watcher.on("unlink", (file) => {
|
|
286
273
|
evictDeletedFileMetadata(file, {
|
|
287
|
-
removeActiveGraphMetadata: (f) => removeActiveGraphMetadata(guardContext, f),
|
|
288
|
-
removeStyleOwnerMetadata: (f) => removeStyleOwnerMetadata(guardContext, f),
|
|
289
274
|
classNamesMap: classNames,
|
|
290
275
|
fileTransformMap
|
|
291
276
|
});
|
|
@@ -440,52 +425,18 @@ function angular(options) {
|
|
|
440
425
|
directId: isDirect.id,
|
|
441
426
|
trackedRequestIds: stylesheetRegistry?.getRequestIdsForSource(ctx.file) ?? []
|
|
442
427
|
});
|
|
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
428
|
logComponentStylesheetHmrOutcome({
|
|
477
429
|
file: ctx.file,
|
|
478
430
|
encapsulation,
|
|
479
431
|
diagnosis: stylesheetDiagnosis,
|
|
480
432
|
outcome: "full-reload",
|
|
481
433
|
directModuleId: isDirect.id,
|
|
482
|
-
wrapperIds: wrapperModules.map((mod) => mod.id)
|
|
483
|
-
ownerIds: ownerModules.map((mod) => mod.id)
|
|
434
|
+
wrapperIds: wrapperModules.map((mod) => mod.id)
|
|
484
435
|
});
|
|
485
436
|
sendFullReload(ctx.server, {
|
|
486
437
|
file: ctx.file,
|
|
487
438
|
encapsulation,
|
|
488
|
-
reason: wrapperModules.length === 0 ? "missing-wrapper-module
|
|
439
|
+
reason: wrapperModules.length === 0 ? "missing-wrapper-module" : "shadow-encapsulation",
|
|
489
440
|
directId: isDirect.id,
|
|
490
441
|
trackedRequestIds: stylesheetRegistry?.getRequestIdsForSource(ctx.file) ?? []
|
|
491
442
|
});
|
|
@@ -799,7 +750,6 @@ function angular(options) {
|
|
|
799
750
|
cssExtensionStyleResolverPlugin(),
|
|
800
751
|
replaceFiles(pluginOptions.fileReplacements, pluginOptions.workspaceRoot),
|
|
801
752
|
virtualModulesPlugin({ jit }),
|
|
802
|
-
templateClassBindingGuardPlugin(guardContext),
|
|
803
753
|
pluginOptions.hasTailwindCss && tailwindReferencePlugin({ tailwindCss: pluginOptions.tailwindCss }),
|
|
804
754
|
pluginOptions.liveReload && liveReloadPlugin({
|
|
805
755
|
classNames,
|
|
@@ -833,6 +783,9 @@ function angular(options) {
|
|
|
833
783
|
});
|
|
834
784
|
try {
|
|
835
785
|
await previousLock;
|
|
786
|
+
const integrations = await resolveAnalogIntegrations(config, configuredStylePreprocessor);
|
|
787
|
+
pluginOptions.stylePreprocessor = integrations.stylePreprocessor;
|
|
788
|
+
externalizeStylesRequested = integrations.externalizeStyles;
|
|
836
789
|
await _doPerformCompilation(config, ids);
|
|
837
790
|
} finally {
|
|
838
791
|
resolve();
|
|
@@ -859,6 +812,7 @@ function angular(options) {
|
|
|
859
812
|
debugCompiler("tsCompilerOptions (NgtscProgram path)", {
|
|
860
813
|
liveReload: pluginOptions.liveReload,
|
|
861
814
|
viteHmr: hasViteHmrTransport(),
|
|
815
|
+
externalizeStylesRequested,
|
|
862
816
|
shouldExternalize: shouldExternalizeStyles(),
|
|
863
817
|
externalRuntimeStyles: !!tsCompilerOptions["externalRuntimeStyles"],
|
|
864
818
|
hmrEnabled: !!tsCompilerOptions["_enableHmr"]
|
|
@@ -1181,12 +1135,6 @@ function sendFullReload(server, details) {
|
|
|
1181
1135
|
server.ws.send("analog:debug-full-reload", details);
|
|
1182
1136
|
server.ws.send({ type: "full-reload" });
|
|
1183
1137
|
}
|
|
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
1138
|
function logComponentStylesheetHmrOutcome(details) {
|
|
1191
1139
|
const pitfalls = [];
|
|
1192
1140
|
const rejectedPreferredPaths = [];
|
|
@@ -1194,7 +1142,6 @@ function logComponentStylesheetHmrOutcome(details) {
|
|
|
1194
1142
|
if (details.encapsulation === "shadow") {
|
|
1195
1143
|
pitfalls.push("shadow-encapsulation");
|
|
1196
1144
|
rejectedPreferredPaths.push("css-update");
|
|
1197
|
-
rejectedPreferredPaths.push("owner-component-update");
|
|
1198
1145
|
hints.push("Shadow DOM styles cannot rely on Vite CSS patching because Angular applies them inside a shadow root.");
|
|
1199
1146
|
}
|
|
1200
1147
|
if (details.diagnosis.anomalies.includes("wrapper_not_yet_tracked")) {
|
|
@@ -1207,27 +1154,12 @@ function logComponentStylesheetHmrOutcome(details) {
|
|
|
1207
1154
|
rejectedPreferredPaths.push("css-update");
|
|
1208
1155
|
hints.push("A wrapper request id is known, but Vite could not resolve a live wrapper module for targeted CSS HMR.");
|
|
1209
1156
|
}
|
|
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
1157
|
debugHmrV("component stylesheet hmr outcome", {
|
|
1224
1158
|
file: details.file,
|
|
1225
1159
|
outcome: details.outcome,
|
|
1226
1160
|
encapsulation: details.encapsulation,
|
|
1227
1161
|
directModuleId: details.directModuleId,
|
|
1228
1162
|
wrapperIds: details.wrapperIds ?? [],
|
|
1229
|
-
ownerIds: details.ownerIds ?? [],
|
|
1230
|
-
updateIds: details.updateIds ?? [],
|
|
1231
1163
|
preferredPath: details.encapsulation === "shadow" ? "full-reload" : "css-update",
|
|
1232
1164
|
rejectedPreferredPaths: [...new Set(rejectedPreferredPaths)],
|
|
1233
1165
|
pitfalls: [...new Set(pitfalls)],
|
|
@@ -1243,15 +1175,6 @@ function findTemplateOwnerModules(server, resourceFile) {
|
|
|
1243
1175
|
});
|
|
1244
1176
|
return [...modules.values()];
|
|
1245
1177
|
}
|
|
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
1178
|
/**
|
|
1256
1179
|
* @internal
|
|
1257
1180
|
*/
|