@analogjs/vite-plugin-angular 3.0.0-alpha.25 → 3.0.0-alpha.26
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 +0 -1
- package/src/index.js.map +1 -1
- package/src/lib/angular-vite-plugin.d.ts +9 -0
- package/src/lib/angular-vite-plugin.js +54 -23
- package/src/lib/angular-vite-plugin.js.map +1 -1
- package/src/lib/host.d.ts +1 -1
- package/src/lib/host.js +20 -6
- package/src/lib/host.js.map +1 -1
- package/src/lib/style-pipeline.d.ts +15 -0
- package/src/lib/style-pipeline.js +31 -0
- package/src/lib/style-pipeline.js.map +1 -0
- package/src/lib/style-preprocessor.d.ts +35 -1
- package/src/lib/style-preprocessor.js +35 -0
- package/src/lib/style-preprocessor.js.map +1 -0
- package/src/lib/stylesheet-registry.d.ts +17 -3
- package/src/lib/stylesheet-registry.js +46 -5
- package/src/lib/stylesheet-registry.js.map +1 -1
- package/src/lib/utils/debug.d.ts +2 -1
- package/src/lib/utils/debug.js +3 -1
- package/src/lib/utils/debug.js.map +1 -1
package/package.json
CHANGED
package/src/index.d.ts
CHANGED
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 type { PluginOptions } from './lib/angular-vite-plugin.js';\
|
|
1
|
+
{"version":3,"file":"index.js","names":[],"sources":["../../src/index.ts"],"sourcesContent":["import { angular } from './lib/angular-vite-plugin.js';\nexport type { PluginOptions } from './lib/angular-vite-plugin.js';\n\nexport default angular;\n"],"mappings":";;AAGA,IAAA,cAAe"}
|
|
@@ -5,6 +5,7 @@ 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
7
|
import { AnalogStylesheetRegistry } from "./stylesheet-registry.js";
|
|
8
|
+
import { type AngularStylePipelineOptions } from "./style-pipeline.js";
|
|
8
9
|
export declare enum DiagnosticModes {
|
|
9
10
|
None = 0,
|
|
10
11
|
Option = 1,
|
|
@@ -69,6 +70,14 @@ export interface PluginOptions {
|
|
|
69
70
|
*/
|
|
70
71
|
stylePreprocessor?: StylePreprocessor;
|
|
71
72
|
/**
|
|
73
|
+
* Experimental Angular stylesheet-resource hooks for community-maintained
|
|
74
|
+
* style-pipeline plugins.
|
|
75
|
+
*
|
|
76
|
+
* These hooks run inside the Angular resource pipeline, which is the seam a
|
|
77
|
+
* standalone Vite plugin cannot own on its own.
|
|
78
|
+
*/
|
|
79
|
+
stylePipeline?: AngularStylePipelineOptions;
|
|
80
|
+
/**
|
|
72
81
|
* First-class Tailwind CSS v4 integration for Angular component styles.
|
|
73
82
|
*
|
|
74
83
|
* Angular's compiler processes component CSS through Vite's `preprocessCSS()`,
|
|
@@ -5,7 +5,8 @@ import { activateDeferredDebug, applyDebugOption, debugCompilationApi, debugComp
|
|
|
5
5
|
import { jitPlugin } from "./angular-jit-plugin.js";
|
|
6
6
|
import { createCompilerPlugin, createRolldownCompilerPlugin } from "./compiler-plugin.js";
|
|
7
7
|
import { StyleUrlsResolver, TemplateUrlsResolver, getAngularComponentMetadata } from "./component-resolvers.js";
|
|
8
|
-
import {
|
|
8
|
+
import { composeStylePreprocessors, normalizeStylesheetDependencies } from "./style-preprocessor.js";
|
|
9
|
+
import { AnalogStylesheetRegistry, preprocessStylesheet, preprocessStylesheetResult, registerStylesheetContent, rewriteRelativeCssImports } from "./stylesheet-registry.js";
|
|
9
10
|
import { augmentHostWithCaching, augmentHostWithResources, augmentProgramWithVersioning, mergeTransformers } from "./host.js";
|
|
10
11
|
import { angularVitestPlugins } from "./angular-vitest-plugin.js";
|
|
11
12
|
import { pendingTasksPlugin } from "./angular-pending-tasks.plugin.js";
|
|
@@ -13,6 +14,7 @@ import { liveReloadPlugin } from "./live-reload-plugin.js";
|
|
|
13
14
|
import { nxFolderPlugin } from "./nx-folder-plugin.js";
|
|
14
15
|
import { replaceFiles } from "./plugins/file-replacements.plugin.js";
|
|
15
16
|
import { routerPlugin } from "./router-plugin.js";
|
|
17
|
+
import { configureStylePipelineRegistry, stylePipelinePreprocessorFromPlugins } from "./style-pipeline.js";
|
|
16
18
|
import { union } from "es-toolkit";
|
|
17
19
|
import { createHash } from "node:crypto";
|
|
18
20
|
import { existsSync, mkdirSync, readFileSync, statSync, writeFileSync } from "node:fs";
|
|
@@ -76,8 +78,9 @@ function isIgnoredHmrFile(file) {
|
|
|
76
78
|
*/
|
|
77
79
|
function buildStylePreprocessor(options) {
|
|
78
80
|
const userPreprocessor = options?.stylePreprocessor;
|
|
81
|
+
const stylePipelinePreprocessor = stylePipelinePreprocessorFromPlugins(options?.stylePipeline);
|
|
79
82
|
const tw = options?.tailwindCss;
|
|
80
|
-
if (!tw && !userPreprocessor) return;
|
|
83
|
+
if (!tw && !userPreprocessor && !stylePipelinePreprocessor) return;
|
|
81
84
|
let tailwindPreprocessor;
|
|
82
85
|
if (tw) {
|
|
83
86
|
const rootStylesheet = tw.rootStylesheet;
|
|
@@ -100,13 +103,12 @@ function buildStylePreprocessor(options) {
|
|
|
100
103
|
return `@reference "${rootStylesheet}";\n${code}`;
|
|
101
104
|
};
|
|
102
105
|
}
|
|
103
|
-
if (tailwindPreprocessor && userPreprocessor)
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
return tailwindPreprocessor ?? userPreprocessor;
|
|
106
|
+
if (tailwindPreprocessor && (stylePipelinePreprocessor || userPreprocessor)) debugTailwind("chained with style pipeline or user stylePreprocessor");
|
|
107
|
+
return composeStylePreprocessors([
|
|
108
|
+
tailwindPreprocessor,
|
|
109
|
+
stylePipelinePreprocessor,
|
|
110
|
+
userPreprocessor
|
|
111
|
+
]);
|
|
110
112
|
}
|
|
111
113
|
function angular(options) {
|
|
112
114
|
applyDebugOption(options?.debug, options?.workspaceRoot);
|
|
@@ -385,6 +387,7 @@ function angular(options) {
|
|
|
385
387
|
if (pluginOptions.hasTailwindCss) validateTailwindConfig(config, watchMode);
|
|
386
388
|
if (pluginOptions.useAngularCompilationAPI) {
|
|
387
389
|
stylesheetRegistry = new AnalogStylesheetRegistry();
|
|
390
|
+
configureStylePipelineRegistry(pluginOptions.stylePipeline, stylesheetRegistry, { workspaceRoot: pluginOptions.workspaceRoot });
|
|
388
391
|
debugStyles("stylesheet registry initialized (Angular Compilation API)");
|
|
389
392
|
}
|
|
390
393
|
if (!jit) styleTransform = (code, filename) => preprocessCSS(code, filename, config);
|
|
@@ -1044,11 +1047,14 @@ function angular(options) {
|
|
|
1044
1047
|
modifiedFiles,
|
|
1045
1048
|
async transformStylesheet(data, containingFile, resourceFile, order, className) {
|
|
1046
1049
|
const filename = resourceFile ?? containingFile.replace(".ts", `.${pluginOptions.inlineStylesExtension}`);
|
|
1047
|
-
const
|
|
1050
|
+
const preprocessed = preprocessStylesheetResult(data, filename, pluginOptions.stylePreprocessor);
|
|
1048
1051
|
if (shouldEnableHmr() && className && containingFile) classNames.set(normalizePath(containingFile), className);
|
|
1049
1052
|
if (shouldExternalizeStyles()) {
|
|
1050
1053
|
const stylesheetId = registerStylesheetContent(stylesheetRegistry, {
|
|
1051
|
-
code:
|
|
1054
|
+
code: preprocessed.code,
|
|
1055
|
+
dependencies: normalizeStylesheetDependencies(preprocessed.dependencies),
|
|
1056
|
+
diagnostics: preprocessed.diagnostics,
|
|
1057
|
+
tags: preprocessed.tags,
|
|
1052
1058
|
containingFile,
|
|
1053
1059
|
className,
|
|
1054
1060
|
order,
|
|
@@ -1063,18 +1069,21 @@ function angular(options) {
|
|
|
1063
1069
|
stylesheetId,
|
|
1064
1070
|
filename,
|
|
1065
1071
|
resourceFile: resourceFile ?? "(inline)",
|
|
1066
|
-
|
|
1072
|
+
dependencies: preprocessed.dependencies,
|
|
1073
|
+
diagnostics: preprocessed.diagnostics,
|
|
1074
|
+
tags: preprocessed.tags,
|
|
1075
|
+
...describeStylesheetContent(preprocessed.code)
|
|
1067
1076
|
});
|
|
1068
1077
|
return stylesheetId;
|
|
1069
1078
|
}
|
|
1070
1079
|
debugStyles("stylesheet processed inline via preprocessCSS", {
|
|
1071
1080
|
filename,
|
|
1072
1081
|
resourceFile: resourceFile ?? "(inline)",
|
|
1073
|
-
dataLength:
|
|
1082
|
+
dataLength: preprocessed.code.length
|
|
1074
1083
|
});
|
|
1075
1084
|
let stylesheetResult;
|
|
1076
1085
|
try {
|
|
1077
|
-
stylesheetResult = await preprocessCSS(
|
|
1086
|
+
stylesheetResult = await preprocessCSS(preprocessed.code, `${filename}?direct`, resolvedConfig);
|
|
1078
1087
|
} catch (e) {
|
|
1079
1088
|
debugStyles("preprocessCSS error", {
|
|
1080
1089
|
filename,
|
|
@@ -1131,33 +1140,39 @@ function angular(options) {
|
|
|
1131
1140
|
stylesheetRegistry?.registerExternalRequest(angularHash, key);
|
|
1132
1141
|
if (stylesheetRegistry && pluginOptions.stylePreprocessor && existsSync(key)) try {
|
|
1133
1142
|
const rawCss = readFileSync(key, "utf-8");
|
|
1134
|
-
|
|
1143
|
+
const preprocessed = preprocessStylesheetResult(rawCss, key, pluginOptions.stylePreprocessor);
|
|
1135
1144
|
debugStylesV("external stylesheet raw snapshot", {
|
|
1136
1145
|
angularHash,
|
|
1137
1146
|
resolvedPath: key,
|
|
1138
1147
|
mtimeMs: safeStatMtimeMs(key),
|
|
1139
1148
|
...describeStylesheetContent(rawCss)
|
|
1140
1149
|
});
|
|
1141
|
-
|
|
1150
|
+
const servedCss = rewriteRelativeCssImports(preprocessed.code, key);
|
|
1142
1151
|
stylesheetRegistry.registerServedStylesheet({
|
|
1143
1152
|
publicId: angularHash,
|
|
1144
1153
|
sourcePath: key,
|
|
1145
1154
|
originalCode: rawCss,
|
|
1146
|
-
normalizedCode:
|
|
1155
|
+
normalizedCode: servedCss,
|
|
1156
|
+
dependencies: normalizeStylesheetDependencies(preprocessed.dependencies),
|
|
1157
|
+
diagnostics: preprocessed.diagnostics,
|
|
1158
|
+
tags: preprocessed.tags
|
|
1147
1159
|
}, [
|
|
1148
1160
|
key,
|
|
1149
1161
|
normalizePath(key),
|
|
1150
1162
|
basename(key),
|
|
1151
1163
|
key.replace(/^\//, "")
|
|
1152
1164
|
]);
|
|
1153
|
-
if (
|
|
1165
|
+
if (servedCss && servedCss !== rawCss) {
|
|
1154
1166
|
preprocessStats.injected++;
|
|
1155
1167
|
debugStylesV("preprocessed external stylesheet for Tailwind @reference", {
|
|
1156
1168
|
angularHash,
|
|
1157
1169
|
resolvedPath: key,
|
|
1158
1170
|
mtimeMs: safeStatMtimeMs(key),
|
|
1159
1171
|
raw: describeStylesheetContent(rawCss),
|
|
1160
|
-
served: describeStylesheetContent(
|
|
1172
|
+
served: describeStylesheetContent(servedCss),
|
|
1173
|
+
dependencies: preprocessed.dependencies,
|
|
1174
|
+
diagnostics: preprocessed.diagnostics,
|
|
1175
|
+
tags: preprocessed.tags
|
|
1161
1176
|
});
|
|
1162
1177
|
} else {
|
|
1163
1178
|
preprocessStats.skipped++;
|
|
@@ -1166,7 +1181,10 @@ function angular(options) {
|
|
|
1166
1181
|
resolvedPath: key,
|
|
1167
1182
|
mtimeMs: safeStatMtimeMs(key),
|
|
1168
1183
|
raw: describeStylesheetContent(rawCss),
|
|
1169
|
-
served: describeStylesheetContent(
|
|
1184
|
+
served: describeStylesheetContent(servedCss),
|
|
1185
|
+
dependencies: preprocessed.dependencies,
|
|
1186
|
+
diagnostics: preprocessed.diagnostics,
|
|
1187
|
+
tags: preprocessed.tags,
|
|
1170
1188
|
hint: "Registry mapping is still registered so Angular component stylesheet HMR can track and refresh this file even when preprocessing makes no textual changes."
|
|
1171
1189
|
});
|
|
1172
1190
|
}
|
|
@@ -1318,6 +1336,7 @@ function angular(options) {
|
|
|
1318
1336
|
if (!jit) {
|
|
1319
1337
|
const externalizeStyles = !!tsCompilerOptions["externalRuntimeStyles"];
|
|
1320
1338
|
stylesheetRegistry = externalizeStyles ? new AnalogStylesheetRegistry() : void 0;
|
|
1339
|
+
if (stylesheetRegistry) configureStylePipelineRegistry(pluginOptions.stylePipeline, stylesheetRegistry, { workspaceRoot: pluginOptions.workspaceRoot });
|
|
1321
1340
|
debugStyles("stylesheet registry initialized (NgtscProgram path)", { externalizeStyles });
|
|
1322
1341
|
augmentHostWithResources(host, styleTransform, {
|
|
1323
1342
|
inlineStylesExtension: pluginOptions.inlineStylesExtension,
|
|
@@ -1524,13 +1543,16 @@ function refreshStylesheetRegistryForFile(file, stylesheetRegistry, stylePreproc
|
|
|
1524
1543
|
const publicIds = stylesheetRegistry.getPublicIdsForSource(normalizedFile);
|
|
1525
1544
|
if (publicIds.length === 0) return;
|
|
1526
1545
|
const rawCss = readFileSync(normalizedFile, "utf-8");
|
|
1527
|
-
|
|
1528
|
-
servedCss = rewriteRelativeCssImports(
|
|
1546
|
+
const preprocessed = preprocessStylesheetResult(rawCss, normalizedFile, stylePreprocessor);
|
|
1547
|
+
const servedCss = rewriteRelativeCssImports(preprocessed.code, normalizedFile);
|
|
1529
1548
|
for (const publicId of publicIds) stylesheetRegistry.registerServedStylesheet({
|
|
1530
1549
|
publicId,
|
|
1531
1550
|
sourcePath: normalizedFile,
|
|
1532
1551
|
originalCode: rawCss,
|
|
1533
|
-
normalizedCode: servedCss
|
|
1552
|
+
normalizedCode: servedCss,
|
|
1553
|
+
dependencies: normalizeStylesheetDependencies(preprocessed.dependencies),
|
|
1554
|
+
diagnostics: preprocessed.diagnostics,
|
|
1555
|
+
tags: preprocessed.tags
|
|
1534
1556
|
}, [
|
|
1535
1557
|
normalizedFile,
|
|
1536
1558
|
normalizePath(normalizedFile),
|
|
@@ -1540,6 +1562,9 @@ function refreshStylesheetRegistryForFile(file, stylesheetRegistry, stylePreproc
|
|
|
1540
1562
|
debugStylesV("stylesheet registry refreshed from source file", {
|
|
1541
1563
|
file: normalizedFile,
|
|
1542
1564
|
publicIds,
|
|
1565
|
+
dependencies: preprocessed.dependencies,
|
|
1566
|
+
diagnostics: preprocessed.diagnostics,
|
|
1567
|
+
tags: preprocessed.tags,
|
|
1543
1568
|
source: describeStylesheetContent(rawCss),
|
|
1544
1569
|
served: describeStylesheetContent(servedCss)
|
|
1545
1570
|
});
|
|
@@ -1552,6 +1577,9 @@ function diagnoseComponentStylesheetPipeline(changedFile, directModule, styleshe
|
|
|
1552
1577
|
const sourcePath = directRequestPath ? stylesheetRegistry?.resolveExternalSource(directRequestPath) ?? stylesheetRegistry?.resolveExternalSource(directRequestPath.replace(/^\//, "")) : normalizedFile;
|
|
1553
1578
|
const registryCode = directRequestPath ? stylesheetRegistry?.getServedContent(directRequestPath) : void 0;
|
|
1554
1579
|
const trackedRequestIds = stylesheetRegistry?.getRequestIdsForSource(sourcePath ?? "") ?? [];
|
|
1580
|
+
const dependencies = stylesheetRegistry?.getDependenciesForSource(sourcePath ?? "") ?? [];
|
|
1581
|
+
const diagnostics = stylesheetRegistry?.getDiagnosticsForSource(sourcePath ?? "") ?? [];
|
|
1582
|
+
const tags = stylesheetRegistry?.getTagsForSource(sourcePath ?? "") ?? [];
|
|
1555
1583
|
const anomalies = [];
|
|
1556
1584
|
const hints = [];
|
|
1557
1585
|
if (!sourceExists) {
|
|
@@ -1587,6 +1615,9 @@ function diagnoseComponentStylesheetPipeline(changedFile, directModule, styleshe
|
|
|
1587
1615
|
sourcePath,
|
|
1588
1616
|
source: sourceCode ? describeStylesheetContent(rewriteRelativeCssImports(preprocessStylesheet(sourceCode, normalizedFile, stylePreprocessor), normalizedFile)) : void 0,
|
|
1589
1617
|
registry: registryCode ? describeStylesheetContent(registryCode) : void 0,
|
|
1618
|
+
dependencies,
|
|
1619
|
+
diagnostics,
|
|
1620
|
+
tags,
|
|
1590
1621
|
directModuleId: directModule.id,
|
|
1591
1622
|
directModuleUrl: directModule.url,
|
|
1592
1623
|
trackedRequestIds,
|