auklet 0.0.1 → 0.0.3
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/README.md +207 -0
- package/bin/entry.cjs +136 -0
- package/dist/build/runTsdown.d.ts +8 -0
- package/dist/build/runTsdown.js +36 -0
- package/dist/build/tsdownConfig.d.ts +12 -0
- package/dist/build/tsdownConfig.js +223 -0
- package/dist/config.d.ts +8 -0
- package/dist/config.js +14 -0
- package/dist/configLoader.d.ts +8 -0
- package/dist/configLoader.js +85 -0
- package/dist/css/core/config.d.ts +2 -0
- package/dist/css/core/config.js +11 -0
- package/dist/css/core/constants.d.ts +3 -0
- package/dist/css/core/constants.js +3 -0
- package/dist/css/core/moduleCssGraph.d.ts +51 -0
- package/dist/css/core/moduleCssGraph.js +416 -0
- package/dist/css/core/moduleStyleImportCollector.d.ts +29 -0
- package/dist/css/core/moduleStyleImportCollector.js +285 -0
- package/dist/css/core/path.d.ts +4 -0
- package/dist/css/core/path.js +26 -0
- package/dist/css/core/styleEntry.d.ts +45 -0
- package/dist/css/core/styleEntry.js +108 -0
- package/dist/css/core/styleProcessor.d.ts +16 -0
- package/dist/css/core/styleProcessor.js +123 -0
- package/dist/css/core/workspaceStyleResolver.d.ts +18 -0
- package/dist/css/core/workspaceStyleResolver.js +100 -0
- package/dist/css/production/moduleCssBuilder.d.ts +33 -0
- package/dist/css/production/moduleCssBuilder.js +445 -0
- package/dist/css/vite/hmr.d.ts +15 -0
- package/dist/css/vite/hmr.js +153 -0
- package/dist/css/vite/vitePlugin.d.ts +24 -0
- package/dist/css/vite/vitePlugin.js +140 -0
- package/dist/css/watch/moduleCssWatcher.d.ts +19 -0
- package/dist/css/watch/moduleCssWatcher.js +106 -0
- package/dist/index.d.ts +26 -0
- package/dist/index.js +12 -0
- package/dist/types.d.ts +58 -0
- package/dist/types.js +0 -0
- package/dist/utils.d.ts +20 -0
- package/dist/utils.js +59 -0
- package/package.json +80 -8
- package/index.js +0 -1
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
import path from 'node:path';
|
|
2
|
+
import { createRequire } from 'node:module';
|
|
3
|
+
import { POSIX_SEPARATOR } from '#auklet/utils';
|
|
4
|
+
const NODE_MODULES_DIR = 'node_modules';
|
|
5
|
+
const PACKAGE_STYLE_FILE = 'style.css';
|
|
6
|
+
export class WorkspaceStyleResolver {
|
|
7
|
+
constructor(config, context) {
|
|
8
|
+
this.config = config;
|
|
9
|
+
this.context = context;
|
|
10
|
+
this.require = createRequire(
|
|
11
|
+
path.join(this.context.packageRoot, 'package.json'),
|
|
12
|
+
);
|
|
13
|
+
}
|
|
14
|
+
resolveStyleDependency(specifier, fromDir = this.context.packageRoot) {
|
|
15
|
+
if (specifier.startsWith('.')) {
|
|
16
|
+
return path.resolve(fromDir, specifier);
|
|
17
|
+
}
|
|
18
|
+
try {
|
|
19
|
+
return this.require.resolve(specifier, {
|
|
20
|
+
paths: [this.context.packageRoot],
|
|
21
|
+
});
|
|
22
|
+
} catch (_a) {
|
|
23
|
+
return path.resolve(
|
|
24
|
+
this.context.packageRoot,
|
|
25
|
+
NODE_MODULES_DIR,
|
|
26
|
+
specifier,
|
|
27
|
+
);
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
toOutputStyleSpecifier(specifier, outRoot) {
|
|
31
|
+
const parsed = this.parsePackageStyleSpecifier(specifier);
|
|
32
|
+
if (!parsed) return specifier;
|
|
33
|
+
const { packageName, stylePath } = parsed;
|
|
34
|
+
const currentOutputFormat = path.basename(outRoot);
|
|
35
|
+
const outputFormat = this.getStylePathOutputFormat(stylePath);
|
|
36
|
+
if (outputFormat) {
|
|
37
|
+
return [packageName, currentOutputFormat, outputFormat.path].join(
|
|
38
|
+
POSIX_SEPARATOR,
|
|
39
|
+
);
|
|
40
|
+
}
|
|
41
|
+
return specifier;
|
|
42
|
+
}
|
|
43
|
+
toExternalStyleSpecifier(specifier, outRoot) {
|
|
44
|
+
const parsed = this.parsePackageStyleSpecifier(specifier);
|
|
45
|
+
if (!parsed) return specifier;
|
|
46
|
+
const { packageName, stylePath } = parsed;
|
|
47
|
+
const currentOutputFormat = path.basename(outRoot);
|
|
48
|
+
const outputFormat = this.getStylePathOutputFormat(stylePath);
|
|
49
|
+
if (stylePath === PACKAGE_STYLE_FILE) {
|
|
50
|
+
return [packageName, this.config.output.externalCssFile].join(
|
|
51
|
+
POSIX_SEPARATOR,
|
|
52
|
+
);
|
|
53
|
+
}
|
|
54
|
+
if (
|
|
55
|
+
outputFormat &&
|
|
56
|
+
outputFormat.path ===
|
|
57
|
+
[this.config.output.styleDir, this.config.output.indexCssFile].join(
|
|
58
|
+
POSIX_SEPARATOR,
|
|
59
|
+
)
|
|
60
|
+
) {
|
|
61
|
+
return [
|
|
62
|
+
packageName,
|
|
63
|
+
currentOutputFormat,
|
|
64
|
+
this.config.output.styleDir,
|
|
65
|
+
this.config.output.externalCssFile,
|
|
66
|
+
].join(POSIX_SEPARATOR);
|
|
67
|
+
}
|
|
68
|
+
return specifier;
|
|
69
|
+
}
|
|
70
|
+
getStylePathOutputFormat(stylePath) {
|
|
71
|
+
for (const format of this.config.output.outputFormats) {
|
|
72
|
+
const prefix = `${format}${POSIX_SEPARATOR}`;
|
|
73
|
+
if (!stylePath.startsWith(prefix)) continue;
|
|
74
|
+
return {
|
|
75
|
+
format,
|
|
76
|
+
path: stylePath.slice(prefix.length),
|
|
77
|
+
};
|
|
78
|
+
}
|
|
79
|
+
return null;
|
|
80
|
+
}
|
|
81
|
+
parsePackageStyleSpecifier(specifier) {
|
|
82
|
+
var _a, _b, _c;
|
|
83
|
+
if (specifier.startsWith('.')) return null;
|
|
84
|
+
const parts = specifier.split(POSIX_SEPARATOR);
|
|
85
|
+
const packageName = specifier.startsWith('@')
|
|
86
|
+
? `${
|
|
87
|
+
(_a = parts.shift()) !== null && _a !== void 0 ? _a : ''
|
|
88
|
+
}${POSIX_SEPARATOR}${
|
|
89
|
+
(_b = parts.shift()) !== null && _b !== void 0 ? _b : ''
|
|
90
|
+
}`
|
|
91
|
+
: (_c = parts.shift()) !== null && _c !== void 0
|
|
92
|
+
? _c
|
|
93
|
+
: '';
|
|
94
|
+
if (!packageName) return null;
|
|
95
|
+
return {
|
|
96
|
+
packageName,
|
|
97
|
+
stylePath: parts.join(POSIX_SEPARATOR),
|
|
98
|
+
};
|
|
99
|
+
}
|
|
100
|
+
}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import type {
|
|
2
|
+
ModuleCssBuildConfig,
|
|
3
|
+
ModuleCssBuildContext,
|
|
4
|
+
ModuleCssBuildOptions,
|
|
5
|
+
} from '#auklet/types';
|
|
6
|
+
export declare class ModuleCssBuilder {
|
|
7
|
+
private readonly config;
|
|
8
|
+
private readonly context;
|
|
9
|
+
private readonly logger?;
|
|
10
|
+
private srcRoot;
|
|
11
|
+
private resolver;
|
|
12
|
+
private styleProcessor;
|
|
13
|
+
private importCollector;
|
|
14
|
+
constructor(context?: ModuleCssBuildContext, config?: ModuleCssBuildConfig);
|
|
15
|
+
build(options?: ModuleCssBuildOptions): Promise<void>;
|
|
16
|
+
private getStyleFiles;
|
|
17
|
+
private createBuildContext;
|
|
18
|
+
private applyContext;
|
|
19
|
+
private copyStyleFiles;
|
|
20
|
+
private writePackageStyles;
|
|
21
|
+
private writeEntryStyle;
|
|
22
|
+
private writeThemeStyles;
|
|
23
|
+
private writeThemeEntries;
|
|
24
|
+
private cleanThemeStyles;
|
|
25
|
+
private writeModuleStyle;
|
|
26
|
+
private writeExternalStyle;
|
|
27
|
+
private writeComponentStyleEntries;
|
|
28
|
+
private getSourceModuleDirs;
|
|
29
|
+
private getOwnStyleDirs;
|
|
30
|
+
private getModuleStyleSpecifiers;
|
|
31
|
+
private getDirStyleSpecifiers;
|
|
32
|
+
private toRelativeImportSpecifier;
|
|
33
|
+
}
|
|
@@ -0,0 +1,445 @@
|
|
|
1
|
+
import fs from 'node:fs';
|
|
2
|
+
import path from 'node:path';
|
|
3
|
+
import { moduleCssBuildConfig } from '#auklet/css/core/config';
|
|
4
|
+
import { aukletDefaultCssOptions } from '#auklet/config';
|
|
5
|
+
import { StyleProcessor } from '#auklet/css/core/styleProcessor';
|
|
6
|
+
import { ModuleStyleImportCollector } from '#auklet/css/core/moduleStyleImportCollector';
|
|
7
|
+
import {
|
|
8
|
+
THEMES_DIR,
|
|
9
|
+
createStyleFileKey,
|
|
10
|
+
createStyleFileKeySet,
|
|
11
|
+
groupStyleFilesByDir,
|
|
12
|
+
getExternalStyleDependencies,
|
|
13
|
+
getGlobalStyleDependencies,
|
|
14
|
+
getThemeStyleDependencies,
|
|
15
|
+
resolveThemeStyleFiles,
|
|
16
|
+
} from '#auklet/css/core/styleEntry';
|
|
17
|
+
import { WorkspaceStyleResolver } from '#auklet/css/core/workspaceStyleResolver';
|
|
18
|
+
import { fileWalker, getSourceModuleDir, toPosixPath } from '#auklet/utils';
|
|
19
|
+
const EMPTY_MODULE_STYLE_ENTRY_COMMENT =
|
|
20
|
+
'/* Empty style entry kept so automated tooling can resolve this module CSS path. */\n';
|
|
21
|
+
export class ModuleCssBuilder {
|
|
22
|
+
constructor(context = {}, config = moduleCssBuildConfig) {
|
|
23
|
+
this.config = config;
|
|
24
|
+
this.context = {
|
|
25
|
+
packageRoot: process.cwd(),
|
|
26
|
+
sourceDir: context.sourceDir,
|
|
27
|
+
outputDir: context.outputDir,
|
|
28
|
+
...context,
|
|
29
|
+
};
|
|
30
|
+
this.logger = context.logger;
|
|
31
|
+
this.applyContext(this.createBuildContext({}));
|
|
32
|
+
}
|
|
33
|
+
async build(options = {}) {
|
|
34
|
+
var _a, _b, _c, _d, _e, _f;
|
|
35
|
+
const cssOptions =
|
|
36
|
+
(_b =
|
|
37
|
+
(_a = options.aukletConfig) !== null && _a !== void 0
|
|
38
|
+
? _a
|
|
39
|
+
: this.context.aukletConfig) !== null && _b !== void 0
|
|
40
|
+
? _b
|
|
41
|
+
: {};
|
|
42
|
+
const logger =
|
|
43
|
+
(_c = options.logger) !== null && _c !== void 0 ? _c : this.logger;
|
|
44
|
+
const context = this.createBuildContext(cssOptions);
|
|
45
|
+
this.applyContext(context);
|
|
46
|
+
(_d = logger === null || logger === void 0 ? void 0 : logger.log) ===
|
|
47
|
+
null || _d === void 0
|
|
48
|
+
? void 0
|
|
49
|
+
: _d.call(
|
|
50
|
+
logger,
|
|
51
|
+
`[auklet:css] build ${path.basename(context.packageRoot)}`,
|
|
52
|
+
);
|
|
53
|
+
const sourceFiles = fileWalker(this.srcRoot);
|
|
54
|
+
const themeFiles = resolveThemeStyleFiles(cssOptions, context.packageRoot);
|
|
55
|
+
const themeFileKeys = createStyleFileKeySet(themeFiles.values());
|
|
56
|
+
const styleFiles = this.getStyleFiles(sourceFiles).filter(
|
|
57
|
+
(styleFile) => !themeFileKeys.has(createStyleFileKey(styleFile)),
|
|
58
|
+
);
|
|
59
|
+
const moduleStyleImports = this.importCollector.collect(
|
|
60
|
+
sourceFiles,
|
|
61
|
+
cssOptions,
|
|
62
|
+
);
|
|
63
|
+
const outputs = [];
|
|
64
|
+
const packageStyle = this.writePackageStyles(
|
|
65
|
+
styleFiles,
|
|
66
|
+
themeFiles,
|
|
67
|
+
cssOptions,
|
|
68
|
+
context,
|
|
69
|
+
);
|
|
70
|
+
if (packageStyle) outputs.push(packageStyle);
|
|
71
|
+
for (const format of this.config.output.outputFormats) {
|
|
72
|
+
const outRoot = path.join(context.packageRoot, context.outputDir, format);
|
|
73
|
+
this.cleanThemeStyles(outRoot);
|
|
74
|
+
this.copyStyleFiles(styleFiles, outRoot);
|
|
75
|
+
const themeStyles = this.writeThemeStyles(themeFiles, outRoot);
|
|
76
|
+
const themeEntries = this.writeThemeEntries(
|
|
77
|
+
themeStyles,
|
|
78
|
+
outRoot,
|
|
79
|
+
cssOptions,
|
|
80
|
+
);
|
|
81
|
+
const externalStyle = this.writeExternalStyle(outRoot, cssOptions);
|
|
82
|
+
const moduleStyle = this.writeModuleStyle(styleFiles, outRoot);
|
|
83
|
+
const entryStyle = this.writeEntryStyle(
|
|
84
|
+
outRoot,
|
|
85
|
+
cssOptions,
|
|
86
|
+
themeStyles.map((themeStyle) => themeStyle.file),
|
|
87
|
+
moduleStyle,
|
|
88
|
+
);
|
|
89
|
+
outputs.push(...themeStyles.map((themeStyle) => themeStyle.file));
|
|
90
|
+
outputs.push(...themeEntries);
|
|
91
|
+
if (externalStyle) outputs.push(externalStyle);
|
|
92
|
+
if (moduleStyle) outputs.push(moduleStyle);
|
|
93
|
+
if (entryStyle) outputs.push(entryStyle);
|
|
94
|
+
outputs.push(
|
|
95
|
+
...this.writeComponentStyleEntries(
|
|
96
|
+
sourceFiles,
|
|
97
|
+
styleFiles,
|
|
98
|
+
outRoot,
|
|
99
|
+
moduleStyleImports,
|
|
100
|
+
),
|
|
101
|
+
);
|
|
102
|
+
}
|
|
103
|
+
(_e = logger === null || logger === void 0 ? void 0 : logger.log) ===
|
|
104
|
+
null || _e === void 0
|
|
105
|
+
? void 0
|
|
106
|
+
: _e.call(
|
|
107
|
+
logger,
|
|
108
|
+
`[auklet:css] ${styleFiles.length} source style file(s), ${outputs.length} output entry file(s)`,
|
|
109
|
+
);
|
|
110
|
+
for (const output of outputs) {
|
|
111
|
+
(_f = logger === null || logger === void 0 ? void 0 : logger.log) ===
|
|
112
|
+
null || _f === void 0
|
|
113
|
+
? void 0
|
|
114
|
+
: _f.call(
|
|
115
|
+
logger,
|
|
116
|
+
`[auklet:css] + ${toPosixPath(
|
|
117
|
+
path.relative(context.packageRoot, output),
|
|
118
|
+
)}`,
|
|
119
|
+
);
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
getStyleFiles(files) {
|
|
123
|
+
return files.filter((file) =>
|
|
124
|
+
this.config.styleExtensions.includes(path.extname(file)),
|
|
125
|
+
);
|
|
126
|
+
}
|
|
127
|
+
createBuildContext(cssOptions) {
|
|
128
|
+
var _a, _b, _c, _d;
|
|
129
|
+
return {
|
|
130
|
+
packageRoot: this.context.packageRoot,
|
|
131
|
+
sourceDir:
|
|
132
|
+
(_b =
|
|
133
|
+
(_a = cssOptions.sourceDir) !== null && _a !== void 0
|
|
134
|
+
? _a
|
|
135
|
+
: this.context.sourceDir) !== null && _b !== void 0
|
|
136
|
+
? _b
|
|
137
|
+
: aukletDefaultCssOptions.sourceDir,
|
|
138
|
+
outputDir:
|
|
139
|
+
(_d =
|
|
140
|
+
(_c = cssOptions.outputDir) !== null && _c !== void 0
|
|
141
|
+
? _c
|
|
142
|
+
: this.context.outputDir) !== null && _d !== void 0
|
|
143
|
+
? _d
|
|
144
|
+
: aukletDefaultCssOptions.outputDir,
|
|
145
|
+
};
|
|
146
|
+
}
|
|
147
|
+
applyContext(context) {
|
|
148
|
+
this.srcRoot = path.join(context.packageRoot, context.sourceDir);
|
|
149
|
+
this.resolver = new WorkspaceStyleResolver(this.config, context);
|
|
150
|
+
this.styleProcessor = new StyleProcessor(this.config, this.resolver);
|
|
151
|
+
this.importCollector = new ModuleStyleImportCollector(
|
|
152
|
+
this.srcRoot,
|
|
153
|
+
context.packageRoot,
|
|
154
|
+
this.resolver,
|
|
155
|
+
this.config.styleExtensions,
|
|
156
|
+
);
|
|
157
|
+
}
|
|
158
|
+
copyStyleFiles(files, outRoot) {
|
|
159
|
+
for (const sourceFile of files) {
|
|
160
|
+
const relative = path.relative(this.srcRoot, sourceFile);
|
|
161
|
+
const target = path.join(outRoot, relative);
|
|
162
|
+
fs.mkdirSync(path.dirname(target), { recursive: true });
|
|
163
|
+
fs.copyFileSync(sourceFile, target);
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
writePackageStyles(styleFiles, themeFiles, buildConfig, context) {
|
|
167
|
+
var _a;
|
|
168
|
+
const seen = new Set();
|
|
169
|
+
const root = this.styleProcessor.createRoot();
|
|
170
|
+
for (const cssPath of themeFiles.values()) {
|
|
171
|
+
const content = this.styleProcessor.readStyleFile(cssPath, seen);
|
|
172
|
+
if (content.trim()) {
|
|
173
|
+
this.styleProcessor.appendStyleContent(root, content, cssPath);
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
for (const specifier of getGlobalStyleDependencies(buildConfig)) {
|
|
177
|
+
const cssPath = this.resolver.resolveStyleDependency(specifier);
|
|
178
|
+
if (!cssPath) continue;
|
|
179
|
+
const content = this.styleProcessor.readStyleFile(cssPath, seen);
|
|
180
|
+
if (content.trim()) {
|
|
181
|
+
this.styleProcessor.appendStyleContent(root, content, cssPath);
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
for (const styleFile of styleFiles) {
|
|
185
|
+
const content = this.styleProcessor.readStyleFile(styleFile, seen);
|
|
186
|
+
if (content.trim()) {
|
|
187
|
+
this.styleProcessor.appendStyleContent(root, content, styleFile);
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
if (!((_a = root.nodes) === null || _a === void 0 ? void 0 : _a.length))
|
|
191
|
+
return null;
|
|
192
|
+
fs.mkdirSync(path.join(context.packageRoot, context.outputDir), {
|
|
193
|
+
recursive: true,
|
|
194
|
+
});
|
|
195
|
+
const target = path.join(
|
|
196
|
+
context.packageRoot,
|
|
197
|
+
context.outputDir,
|
|
198
|
+
this.config.output.indexCssFile,
|
|
199
|
+
);
|
|
200
|
+
fs.writeFileSync(target, this.styleProcessor.stringify(root));
|
|
201
|
+
return target;
|
|
202
|
+
}
|
|
203
|
+
writeEntryStyle(outRoot, buildConfig, themeStyles, moduleStyle) {
|
|
204
|
+
var _a;
|
|
205
|
+
const target = path.join(
|
|
206
|
+
outRoot,
|
|
207
|
+
this.config.output.styleDir,
|
|
208
|
+
this.config.output.indexCssFile,
|
|
209
|
+
);
|
|
210
|
+
const root = this.styleProcessor.createRoot();
|
|
211
|
+
const styleDir = path.dirname(target);
|
|
212
|
+
for (const specifier of getGlobalStyleDependencies(buildConfig)) {
|
|
213
|
+
this.styleProcessor.appendImportRule(root, specifier);
|
|
214
|
+
}
|
|
215
|
+
for (const style of [...themeStyles, moduleStyle]) {
|
|
216
|
+
if (!style) continue;
|
|
217
|
+
this.styleProcessor.appendImportRule(
|
|
218
|
+
root,
|
|
219
|
+
this.toRelativeImportSpecifier(styleDir, style),
|
|
220
|
+
);
|
|
221
|
+
}
|
|
222
|
+
if (!((_a = root.nodes) === null || _a === void 0 ? void 0 : _a.length))
|
|
223
|
+
return null;
|
|
224
|
+
fs.mkdirSync(path.dirname(target), { recursive: true });
|
|
225
|
+
fs.writeFileSync(target, this.styleProcessor.stringify(root));
|
|
226
|
+
return target;
|
|
227
|
+
}
|
|
228
|
+
writeThemeStyles(themeFiles, outRoot) {
|
|
229
|
+
var _a;
|
|
230
|
+
const outputs = [];
|
|
231
|
+
const themesDir = path.join(
|
|
232
|
+
outRoot,
|
|
233
|
+
this.config.output.styleDir,
|
|
234
|
+
THEMES_DIR,
|
|
235
|
+
);
|
|
236
|
+
for (const [themeName, cssPath] of themeFiles) {
|
|
237
|
+
const root = this.styleProcessor.createRoot();
|
|
238
|
+
const content = this.styleProcessor.readStyleFile(cssPath);
|
|
239
|
+
if (content.trim()) {
|
|
240
|
+
this.styleProcessor.appendStyleContent(root, content, cssPath);
|
|
241
|
+
}
|
|
242
|
+
const target = path.join(themesDir, `${themeName}.css`);
|
|
243
|
+
fs.mkdirSync(path.dirname(target), { recursive: true });
|
|
244
|
+
fs.writeFileSync(
|
|
245
|
+
target,
|
|
246
|
+
((_a = root.nodes) === null || _a === void 0 ? void 0 : _a.length)
|
|
247
|
+
? this.styleProcessor.stringify(root)
|
|
248
|
+
: '',
|
|
249
|
+
);
|
|
250
|
+
outputs.push({ themeName, file: target });
|
|
251
|
+
}
|
|
252
|
+
return outputs;
|
|
253
|
+
}
|
|
254
|
+
writeThemeEntries(themeStyles, outRoot, buildConfig) {
|
|
255
|
+
const outputs = [];
|
|
256
|
+
const themesDir = path.join(outRoot, THEMES_DIR);
|
|
257
|
+
for (const { themeName, file } of themeStyles) {
|
|
258
|
+
const target = path.join(themesDir, `${themeName}.css`);
|
|
259
|
+
const root = this.styleProcessor.createRoot();
|
|
260
|
+
const targetDir = path.dirname(target);
|
|
261
|
+
for (const specifier of getThemeStyleDependencies(
|
|
262
|
+
buildConfig,
|
|
263
|
+
themeName,
|
|
264
|
+
)) {
|
|
265
|
+
this.styleProcessor.appendImportRule(root, specifier);
|
|
266
|
+
}
|
|
267
|
+
this.styleProcessor.appendImportRule(
|
|
268
|
+
root,
|
|
269
|
+
this.toRelativeImportSpecifier(targetDir, file),
|
|
270
|
+
);
|
|
271
|
+
fs.mkdirSync(targetDir, { recursive: true });
|
|
272
|
+
fs.writeFileSync(target, this.styleProcessor.stringify(root));
|
|
273
|
+
outputs.push(target);
|
|
274
|
+
}
|
|
275
|
+
return outputs;
|
|
276
|
+
}
|
|
277
|
+
cleanThemeStyles(outRoot) {
|
|
278
|
+
fs.rmSync(path.join(outRoot, THEMES_DIR), {
|
|
279
|
+
recursive: true,
|
|
280
|
+
force: true,
|
|
281
|
+
});
|
|
282
|
+
fs.rmSync(path.join(outRoot, this.config.output.styleDir, THEMES_DIR), {
|
|
283
|
+
recursive: true,
|
|
284
|
+
force: true,
|
|
285
|
+
});
|
|
286
|
+
}
|
|
287
|
+
writeModuleStyle(styleFiles, outRoot) {
|
|
288
|
+
var _a;
|
|
289
|
+
const target = path.join(
|
|
290
|
+
outRoot,
|
|
291
|
+
this.config.output.styleDir,
|
|
292
|
+
this.config.output.moduleCssFile,
|
|
293
|
+
);
|
|
294
|
+
const seen = new Set();
|
|
295
|
+
const root = this.styleProcessor.createRoot();
|
|
296
|
+
for (const styleFile of styleFiles) {
|
|
297
|
+
const content = this.styleProcessor.readStyleFile(styleFile, seen);
|
|
298
|
+
if (content.trim()) {
|
|
299
|
+
this.styleProcessor.appendStyleContent(root, content, styleFile);
|
|
300
|
+
}
|
|
301
|
+
}
|
|
302
|
+
if (!((_a = root.nodes) === null || _a === void 0 ? void 0 : _a.length))
|
|
303
|
+
return null;
|
|
304
|
+
fs.mkdirSync(path.dirname(target), { recursive: true });
|
|
305
|
+
fs.writeFileSync(target, this.styleProcessor.stringify(root));
|
|
306
|
+
return target;
|
|
307
|
+
}
|
|
308
|
+
writeExternalStyle(outRoot, buildConfig) {
|
|
309
|
+
var _a;
|
|
310
|
+
const target = path.join(
|
|
311
|
+
outRoot,
|
|
312
|
+
this.config.output.styleDir,
|
|
313
|
+
this.config.output.externalCssFile,
|
|
314
|
+
);
|
|
315
|
+
const root = this.styleProcessor.createRoot();
|
|
316
|
+
for (const specifier of getExternalStyleDependencies(buildConfig)) {
|
|
317
|
+
this.styleProcessor.appendImportRule(
|
|
318
|
+
root,
|
|
319
|
+
this.resolver.toExternalStyleSpecifier(specifier, outRoot),
|
|
320
|
+
);
|
|
321
|
+
}
|
|
322
|
+
fs.mkdirSync(path.dirname(target), { recursive: true });
|
|
323
|
+
fs.writeFileSync(
|
|
324
|
+
target,
|
|
325
|
+
((_a = root.nodes) === null || _a === void 0 ? void 0 : _a.length)
|
|
326
|
+
? this.styleProcessor.stringify(root)
|
|
327
|
+
: '',
|
|
328
|
+
);
|
|
329
|
+
return target;
|
|
330
|
+
}
|
|
331
|
+
writeComponentStyleEntries(
|
|
332
|
+
sourceFiles,
|
|
333
|
+
styleFiles,
|
|
334
|
+
outRoot,
|
|
335
|
+
moduleStyleImports,
|
|
336
|
+
) {
|
|
337
|
+
var _a, _b, _c;
|
|
338
|
+
const styleFilesByDir = groupStyleFilesByDir(this.srcRoot, styleFiles);
|
|
339
|
+
const importedStyleFiles =
|
|
340
|
+
this.styleProcessor.collectImportedStyleFiles(styleFiles);
|
|
341
|
+
const sourceModuleDirs = this.getSourceModuleDirs(sourceFiles);
|
|
342
|
+
const ownStyleDirs = this.getOwnStyleDirs(
|
|
343
|
+
styleFilesByDir,
|
|
344
|
+
importedStyleFiles,
|
|
345
|
+
);
|
|
346
|
+
const sourceDirs = Array.from(
|
|
347
|
+
new Set([
|
|
348
|
+
...sourceModuleDirs,
|
|
349
|
+
...ownStyleDirs,
|
|
350
|
+
...moduleStyleImports.keys(),
|
|
351
|
+
]),
|
|
352
|
+
);
|
|
353
|
+
const outputs = [];
|
|
354
|
+
for (const sourceDir of sourceDirs) {
|
|
355
|
+
if (sourceDir === '.') continue;
|
|
356
|
+
const dirStyleFiles =
|
|
357
|
+
(_a = styleFilesByDir.get(sourceDir)) !== null && _a !== void 0
|
|
358
|
+
? _a
|
|
359
|
+
: [];
|
|
360
|
+
const styleDir = path.join(
|
|
361
|
+
outRoot,
|
|
362
|
+
sourceDir,
|
|
363
|
+
this.config.output.styleDir,
|
|
364
|
+
);
|
|
365
|
+
const target = path.join(styleDir, this.config.output.indexCssFile);
|
|
366
|
+
const moduleStyleSpecifiers = this.getModuleStyleSpecifiers(
|
|
367
|
+
(_b = moduleStyleImports.get(sourceDir)) !== null && _b !== void 0
|
|
368
|
+
? _b
|
|
369
|
+
: [],
|
|
370
|
+
styleDir,
|
|
371
|
+
);
|
|
372
|
+
const dirStyleSpecifiers = this.getDirStyleSpecifiers(
|
|
373
|
+
dirStyleFiles,
|
|
374
|
+
importedStyleFiles,
|
|
375
|
+
styleDir,
|
|
376
|
+
outRoot,
|
|
377
|
+
);
|
|
378
|
+
const sourceStyleSpecifiers = [
|
|
379
|
+
...moduleStyleSpecifiers,
|
|
380
|
+
...dirStyleSpecifiers,
|
|
381
|
+
];
|
|
382
|
+
const root = this.styleProcessor.createRoot();
|
|
383
|
+
const seen = new Set();
|
|
384
|
+
for (const specifier of sourceStyleSpecifiers) {
|
|
385
|
+
if (seen.has(specifier)) continue;
|
|
386
|
+
seen.add(specifier);
|
|
387
|
+
this.styleProcessor.appendImportRule(
|
|
388
|
+
root,
|
|
389
|
+
this.resolver.toOutputStyleSpecifier(specifier, outRoot),
|
|
390
|
+
);
|
|
391
|
+
}
|
|
392
|
+
fs.mkdirSync(styleDir, { recursive: true });
|
|
393
|
+
fs.writeFileSync(
|
|
394
|
+
target,
|
|
395
|
+
((_c = root.nodes) === null || _c === void 0 ? void 0 : _c.length)
|
|
396
|
+
? this.styleProcessor.stringify(root)
|
|
397
|
+
: EMPTY_MODULE_STYLE_ENTRY_COMMENT,
|
|
398
|
+
);
|
|
399
|
+
outputs.push(target);
|
|
400
|
+
}
|
|
401
|
+
return outputs;
|
|
402
|
+
}
|
|
403
|
+
getSourceModuleDirs(sourceFiles) {
|
|
404
|
+
return sourceFiles
|
|
405
|
+
.filter((sourceFile) => sourceFile.endsWith('.tsx'))
|
|
406
|
+
.map((sourceFile) => {
|
|
407
|
+
return getSourceModuleDir(path.relative(this.srcRoot, sourceFile));
|
|
408
|
+
})
|
|
409
|
+
.filter((sourceModuleDir) => {
|
|
410
|
+
return toPosixPath(sourceModuleDir).split('/').length === 2;
|
|
411
|
+
});
|
|
412
|
+
}
|
|
413
|
+
getOwnStyleDirs(styleFilesByDir, importedStyleFiles) {
|
|
414
|
+
return Array.from(styleFilesByDir.entries())
|
|
415
|
+
.filter(([, dirStyleFiles]) =>
|
|
416
|
+
dirStyleFiles.some(
|
|
417
|
+
(styleFile) => !importedStyleFiles.has(path.resolve(styleFile)),
|
|
418
|
+
),
|
|
419
|
+
)
|
|
420
|
+
.map(([sourceDir]) => sourceDir);
|
|
421
|
+
}
|
|
422
|
+
getModuleStyleSpecifiers(specifiers, styleDir) {
|
|
423
|
+
return specifiers.map((specifier) => {
|
|
424
|
+
if (specifier.startsWith('.')) return specifier;
|
|
425
|
+
if (!path.isAbsolute(specifier)) return specifier;
|
|
426
|
+
return toPosixPath(path.relative(styleDir, specifier));
|
|
427
|
+
});
|
|
428
|
+
}
|
|
429
|
+
getDirStyleSpecifiers(dirStyleFiles, importedStyleFiles, styleDir, outRoot) {
|
|
430
|
+
return dirStyleFiles
|
|
431
|
+
.filter((styleFile) => !importedStyleFiles.has(path.resolve(styleFile)))
|
|
432
|
+
.map((styleFile) =>
|
|
433
|
+
toPosixPath(
|
|
434
|
+
path.relative(
|
|
435
|
+
styleDir,
|
|
436
|
+
path.join(outRoot, path.relative(this.srcRoot, styleFile)),
|
|
437
|
+
),
|
|
438
|
+
),
|
|
439
|
+
);
|
|
440
|
+
}
|
|
441
|
+
toRelativeImportSpecifier(fromDir, file) {
|
|
442
|
+
const relative = toPosixPath(path.relative(fromDir, file));
|
|
443
|
+
return relative.startsWith('.') ? relative : `./${relative}`;
|
|
444
|
+
}
|
|
445
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { HotUpdateOptions, ViteDevServer } from 'vite';
|
|
2
|
+
import type { ModuleCssGraph } from '#auklet/css/core/moduleCssGraph';
|
|
3
|
+
export declare class AukletCssHmr {
|
|
4
|
+
private readonly graph;
|
|
5
|
+
private readonly lastUpdateTimes;
|
|
6
|
+
private suppressFullReloadUntil;
|
|
7
|
+
private readonly virtualIdsByDependency;
|
|
8
|
+
constructor(graph: () => ModuleCssGraph);
|
|
9
|
+
trackVirtualCssDependency(file: string, virtualId: string): void;
|
|
10
|
+
installFullReloadGuard(server: Pick<ViteDevServer, 'ws'>): void;
|
|
11
|
+
handleStyleHotUpdate(context: HotUpdateOptions): never[] | undefined;
|
|
12
|
+
private suppressFullReload;
|
|
13
|
+
private shouldSuppressFullReload;
|
|
14
|
+
private isDuplicateUpdate;
|
|
15
|
+
}
|