auklet 0.0.2 → 0.0.4
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 +81 -42
- package/bin/entry.cjs +33 -11
- package/dist/build/runTsdown.js +2 -3
- package/dist/build/tsdownConfig.d.ts +138 -2
- package/dist/build/tsdownConfig.js +108 -63
- package/dist/config.d.ts +39 -2
- package/dist/config.js +44 -3
- package/dist/configLoader.js +1 -2
- package/dist/css/config.d.ts +2 -0
- package/dist/css/config.js +10 -0
- package/dist/css/constants.d.ts +6 -0
- package/dist/css/constants.js +6 -0
- package/dist/css/core/moduleGraph.d.ts +55 -0
- package/dist/css/core/moduleGraph.js +362 -0
- package/dist/css/core/moduleGraphRequestCache.d.ts +80 -0
- package/dist/css/core/moduleGraphRequestCache.js +92 -0
- package/dist/css/core/moduleStyleImportCollector.d.ts +5 -3
- package/dist/css/core/moduleStyleImportCollector.js +27 -45
- package/dist/css/core/style/dependencies.d.ts +20 -0
- package/dist/css/core/style/dependencies.js +55 -0
- package/dist/css/core/style/files.d.ts +8 -0
- package/dist/css/core/style/files.js +19 -0
- package/dist/css/core/style/plan.d.ts +59 -0
- package/dist/css/core/style/plan.js +27 -0
- package/dist/css/core/style/specifier.d.ts +14 -0
- package/dist/css/core/style/specifier.js +27 -0
- package/dist/css/core/styleModuleEntryPlanner.d.ts +29 -0
- package/dist/css/core/styleModuleEntryPlanner.js +66 -0
- package/dist/css/core/stylePackageContext.d.ts +27 -0
- package/dist/css/core/stylePackageContext.js +57 -0
- package/dist/css/core/styleProcessor.d.ts +3 -3
- package/dist/css/core/styleProcessor.js +21 -41
- package/dist/css/core/workspaceStyleResolver.d.ts +4 -5
- package/dist/css/core/workspaceStyleResolver.js +12 -28
- package/dist/css/production/builder.d.ts +18 -0
- package/dist/css/production/builder.js +68 -0
- package/dist/css/production/format/componentWriter.d.ts +12 -0
- package/dist/css/production/format/componentWriter.js +67 -0
- package/dist/css/production/format/entryWriter.d.ts +12 -0
- package/dist/css/production/format/entryWriter.js +54 -0
- package/dist/css/production/format/externalWriter.d.ts +9 -0
- package/dist/css/production/format/externalWriter.js +39 -0
- package/dist/css/production/format/moduleWriter.d.ts +8 -0
- package/dist/css/production/format/moduleWriter.js +31 -0
- package/dist/css/production/format/shared.d.ts +20 -0
- package/dist/css/production/format/shared.js +8 -0
- package/dist/css/production/format/sourceWriter.d.ts +6 -0
- package/dist/css/production/format/sourceWriter.js +16 -0
- package/dist/css/production/format/themeWriter.d.ts +16 -0
- package/dist/css/production/format/themeWriter.js +80 -0
- package/dist/css/production/moduleOutputWriter.d.ts +26 -0
- package/dist/css/production/moduleOutputWriter.js +83 -0
- package/dist/css/production/packageEntryWriter.d.ts +20 -0
- package/dist/css/production/packageEntryWriter.js +55 -0
- package/dist/css/vite/hmr.d.ts +4 -4
- package/dist/css/vite/hmr.js +14 -27
- package/dist/css/vite/vitePlugin.d.ts +5 -5
- package/dist/css/vite/vitePlugin.js +21 -30
- package/dist/css/watch/{moduleCssWatcher.d.ts → watcher.d.ts} +7 -4
- package/dist/css/watch/watcher.js +82 -0
- package/dist/index.d.ts +17 -12
- package/dist/index.js +8 -4
- package/dist/types.d.ts +41 -23
- package/dist/utils.d.ts +5 -1
- package/dist/utils.js +37 -12
- package/package.json +12 -9
- package/dist/css/core/config.d.ts +0 -2
- package/dist/css/core/config.js +0 -18
- package/dist/css/core/constants.d.ts +0 -3
- package/dist/css/core/constants.js +0 -3
- package/dist/css/core/moduleCssGraph.d.ts +0 -51
- package/dist/css/core/moduleCssGraph.js +0 -412
- package/dist/css/core/path.d.ts +0 -4
- package/dist/css/core/path.js +0 -26
- package/dist/css/core/styleEntry.d.ts +0 -45
- package/dist/css/core/styleEntry.js +0 -108
- package/dist/css/production/moduleCssBuilder.d.ts +0 -33
- package/dist/css/production/moduleCssBuilder.js +0 -444
- package/dist/css/watch/moduleCssWatcher.js +0 -106
|
@@ -1,412 +0,0 @@
|
|
|
1
|
-
import fs from 'node:fs';
|
|
2
|
-
import path from 'node:path';
|
|
3
|
-
import { aukletConfigFile } from '#auklet/config';
|
|
4
|
-
import { loadAukletConfig } from '#auklet/configLoader';
|
|
5
|
-
import { moduleCssBuildConfig } from '#auklet/css/core/config';
|
|
6
|
-
import { ModuleStyleImportCollector } from '#auklet/css/core/moduleStyleImportCollector';
|
|
7
|
-
import {
|
|
8
|
-
normalizeCssFileKey,
|
|
9
|
-
toCssFsSpecifier,
|
|
10
|
-
toCssWatchPath,
|
|
11
|
-
} from '#auklet/css/core/path';
|
|
12
|
-
import {
|
|
13
|
-
createImportCode,
|
|
14
|
-
EXTERNAL_ENTRY,
|
|
15
|
-
createStyleFileKey,
|
|
16
|
-
createStyleFileKeySet,
|
|
17
|
-
getExternalStyleDependencies,
|
|
18
|
-
getGlobalStyleDependencies,
|
|
19
|
-
getThemeStyleDependencies,
|
|
20
|
-
groupStyleFilesByDir,
|
|
21
|
-
MODULE_ENTRY,
|
|
22
|
-
parsePackageStyleSpecifier,
|
|
23
|
-
removeCssExtension,
|
|
24
|
-
resolveThemeStyleFiles,
|
|
25
|
-
STYLE_ENTRY,
|
|
26
|
-
THEMES_ENTRY_PREFIX,
|
|
27
|
-
} from '#auklet/css/core/styleEntry';
|
|
28
|
-
import { StyleProcessor } from '#auklet/css/core/styleProcessor';
|
|
29
|
-
import { WorkspaceStyleResolver } from '#auklet/css/core/workspaceStyleResolver';
|
|
30
|
-
import { fileWalker, toPosixPath } from '#auklet/utils';
|
|
31
|
-
const mergeLoadResults = (...results) => {
|
|
32
|
-
return {
|
|
33
|
-
code: results
|
|
34
|
-
.map((result) => result.code)
|
|
35
|
-
.filter((code) => code.trim())
|
|
36
|
-
.join('\n'),
|
|
37
|
-
watchFiles: Array.from(
|
|
38
|
-
new Set(results.flatMap((result) => result.watchFiles)),
|
|
39
|
-
),
|
|
40
|
-
};
|
|
41
|
-
};
|
|
42
|
-
export class ModuleCssGraph {
|
|
43
|
-
constructor(options) {
|
|
44
|
-
var _a, _b, _c;
|
|
45
|
-
this.config =
|
|
46
|
-
(_a = options.config) !== null && _a !== void 0
|
|
47
|
-
? _a
|
|
48
|
-
: moduleCssBuildConfig;
|
|
49
|
-
this.workspaceRoot = normalizeCssFileKey(options.workspaceRoot);
|
|
50
|
-
this.packagesDir =
|
|
51
|
-
(_b = options.packagesDir) !== null && _b !== void 0 ? _b : 'packages';
|
|
52
|
-
this.loadAukletConfig =
|
|
53
|
-
(_c = options.loadAukletConfig) !== null && _c !== void 0
|
|
54
|
-
? _c
|
|
55
|
-
: loadAukletConfig;
|
|
56
|
-
}
|
|
57
|
-
parsePackageCssId(id) {
|
|
58
|
-
return parsePackageCssId(id, this.getWorkspacePackageNames());
|
|
59
|
-
}
|
|
60
|
-
isWorkspaceSourceGraphFile(file) {
|
|
61
|
-
const normalizedFile = normalizeCssFileKey(file);
|
|
62
|
-
const packagesRoot = normalizeCssFileKey(
|
|
63
|
-
path.join(this.workspaceRoot, this.packagesDir),
|
|
64
|
-
);
|
|
65
|
-
if (!normalizedFile.startsWith(`${packagesRoot}/`)) {
|
|
66
|
-
return false;
|
|
67
|
-
}
|
|
68
|
-
if (normalizedFile.endsWith(aukletConfigFile)) return true;
|
|
69
|
-
if (normalizedFile.endsWith('.ts') || normalizedFile.endsWith('.tsx')) {
|
|
70
|
-
return true;
|
|
71
|
-
}
|
|
72
|
-
return Object.keys(this.config.styleExtensions).some((extension) =>
|
|
73
|
-
normalizedFile.endsWith(extension),
|
|
74
|
-
);
|
|
75
|
-
}
|
|
76
|
-
isCssConfigFile(file) {
|
|
77
|
-
return normalizeCssFileKey(file).endsWith(aukletConfigFile);
|
|
78
|
-
}
|
|
79
|
-
isStyleFile(file) {
|
|
80
|
-
return Boolean(this.config.styleExtensions[path.extname(file)]);
|
|
81
|
-
}
|
|
82
|
-
getWorkspacePackageNames() {
|
|
83
|
-
return this.getWorkspacePackages().map((item) => item.packageName);
|
|
84
|
-
}
|
|
85
|
-
getWatchRoots() {
|
|
86
|
-
const packagesRoot = path.join(this.workspaceRoot, this.packagesDir);
|
|
87
|
-
return [
|
|
88
|
-
toCssWatchPath(packagesRoot, '*', 'src'),
|
|
89
|
-
toCssWatchPath(packagesRoot, '*', aukletConfigFile),
|
|
90
|
-
];
|
|
91
|
-
}
|
|
92
|
-
async createPackageCssCode(parsed) {
|
|
93
|
-
const context = await this.createContext(parsed);
|
|
94
|
-
if (!context) {
|
|
95
|
-
return {
|
|
96
|
-
code: '',
|
|
97
|
-
watchFiles: [],
|
|
98
|
-
};
|
|
99
|
-
}
|
|
100
|
-
if (parsed.cssPath === STYLE_ENTRY) {
|
|
101
|
-
return this.createStyleCssCode(context);
|
|
102
|
-
}
|
|
103
|
-
if (parsed.cssPath === EXTERNAL_ENTRY) {
|
|
104
|
-
return this.createExternalCssCode(context);
|
|
105
|
-
}
|
|
106
|
-
if (parsed.cssPath === MODULE_ENTRY) {
|
|
107
|
-
return this.createModuleCssCode(context);
|
|
108
|
-
}
|
|
109
|
-
if (parsed.cssPath.startsWith(THEMES_ENTRY_PREFIX)) {
|
|
110
|
-
return this.createThemeCssCode(context, parsed.cssPath);
|
|
111
|
-
}
|
|
112
|
-
return this.createSourceModuleCssCode(context, parsed.cssPath);
|
|
113
|
-
}
|
|
114
|
-
async createContext(parsed) {
|
|
115
|
-
var _a, _b;
|
|
116
|
-
const workspacePackage = this.getWorkspacePackages().find(
|
|
117
|
-
(item) => item.packageName === parsed.packageName,
|
|
118
|
-
);
|
|
119
|
-
if (!workspacePackage) return null;
|
|
120
|
-
const packageRoot = workspacePackage.packageRoot;
|
|
121
|
-
if (!fs.existsSync(packageRoot)) return null;
|
|
122
|
-
const cssOptions = await this.loadAukletConfig(packageRoot, {
|
|
123
|
-
cacheBust: true,
|
|
124
|
-
});
|
|
125
|
-
const context = {
|
|
126
|
-
packageRoot,
|
|
127
|
-
sourceDir:
|
|
128
|
-
(_a = cssOptions.sourceDir) !== null && _a !== void 0 ? _a : 'src',
|
|
129
|
-
outputDir:
|
|
130
|
-
(_b = cssOptions.outputDir) !== null && _b !== void 0 ? _b : 'dist',
|
|
131
|
-
};
|
|
132
|
-
const sourceRoot = path.join(packageRoot, context.sourceDir);
|
|
133
|
-
const resolver = new WorkspaceStyleResolver(this.config, context);
|
|
134
|
-
const styleProcessor = new StyleProcessor(this.config, resolver);
|
|
135
|
-
return {
|
|
136
|
-
cssOptions,
|
|
137
|
-
context,
|
|
138
|
-
packageName: parsed.packageName,
|
|
139
|
-
configPath: path.join(packageRoot, aukletConfigFile),
|
|
140
|
-
resolver,
|
|
141
|
-
sourceRoot,
|
|
142
|
-
styleProcessor,
|
|
143
|
-
};
|
|
144
|
-
}
|
|
145
|
-
async createStyleCssCode(context) {
|
|
146
|
-
const dependencies = await this.createStyleDependencyCssCode(context);
|
|
147
|
-
const themes = await this.createThemeCssCode(context, undefined, false);
|
|
148
|
-
const module = this.createModuleCssCode(context);
|
|
149
|
-
return mergeLoadResults(dependencies, themes, module);
|
|
150
|
-
}
|
|
151
|
-
async createStyleDependencyCssCode(context) {
|
|
152
|
-
const results = [];
|
|
153
|
-
const imports = [];
|
|
154
|
-
for (const specifier of getGlobalStyleDependencies(context.cssOptions)) {
|
|
155
|
-
const parsed = this.parsePackageCssId(specifier);
|
|
156
|
-
if (parsed) {
|
|
157
|
-
results.push(await this.createPackageCssCode(parsed));
|
|
158
|
-
continue;
|
|
159
|
-
}
|
|
160
|
-
imports.push(specifier);
|
|
161
|
-
}
|
|
162
|
-
return mergeLoadResults(
|
|
163
|
-
{
|
|
164
|
-
code: createImportCode(imports),
|
|
165
|
-
watchFiles: [context.configPath],
|
|
166
|
-
},
|
|
167
|
-
...results,
|
|
168
|
-
);
|
|
169
|
-
}
|
|
170
|
-
async createExternalCssCode(context) {
|
|
171
|
-
const results = [];
|
|
172
|
-
const imports = [];
|
|
173
|
-
for (const specifier of getExternalStyleDependencies(context.cssOptions)) {
|
|
174
|
-
const external = this.toDevExternalStyleSpecifier(specifier);
|
|
175
|
-
const parsed = this.parsePackageCssId(external);
|
|
176
|
-
if (parsed) {
|
|
177
|
-
results.push(await this.createPackageCssCode(parsed));
|
|
178
|
-
continue;
|
|
179
|
-
}
|
|
180
|
-
imports.push(external);
|
|
181
|
-
}
|
|
182
|
-
return mergeLoadResults(
|
|
183
|
-
{
|
|
184
|
-
code: createImportCode(imports),
|
|
185
|
-
watchFiles: [context.configPath],
|
|
186
|
-
},
|
|
187
|
-
...results,
|
|
188
|
-
);
|
|
189
|
-
}
|
|
190
|
-
async createThemeCssCode(context, cssPath, includeDependencies = true) {
|
|
191
|
-
var _a;
|
|
192
|
-
const themeFiles = this.getThemeStyleFiles(context);
|
|
193
|
-
const targetThemeName = cssPath
|
|
194
|
-
? removeCssExtension(cssPath.slice(THEMES_ENTRY_PREFIX.length))
|
|
195
|
-
: null;
|
|
196
|
-
const root = context.styleProcessor.createRoot();
|
|
197
|
-
const watchFiles = [context.configPath, ...themeFiles.values()];
|
|
198
|
-
const dependencyResults = [];
|
|
199
|
-
const imports = [];
|
|
200
|
-
for (const [themeName, themeFile] of themeFiles) {
|
|
201
|
-
if (targetThemeName && themeName !== targetThemeName) continue;
|
|
202
|
-
if (includeDependencies) {
|
|
203
|
-
for (const specifier of getThemeStyleDependencies(
|
|
204
|
-
context.cssOptions,
|
|
205
|
-
themeName,
|
|
206
|
-
)) {
|
|
207
|
-
const parsed = this.parsePackageCssId(specifier);
|
|
208
|
-
if (!parsed) {
|
|
209
|
-
imports.push(specifier);
|
|
210
|
-
continue;
|
|
211
|
-
}
|
|
212
|
-
dependencyResults.push(await this.createPackageCssCode(parsed));
|
|
213
|
-
}
|
|
214
|
-
}
|
|
215
|
-
const content = context.styleProcessor.readStyleFile(themeFile);
|
|
216
|
-
if (content.trim()) {
|
|
217
|
-
context.styleProcessor.appendStyleContent(root, content, themeFile);
|
|
218
|
-
}
|
|
219
|
-
}
|
|
220
|
-
return mergeLoadResults(
|
|
221
|
-
{
|
|
222
|
-
code: createImportCode(imports),
|
|
223
|
-
watchFiles,
|
|
224
|
-
},
|
|
225
|
-
...dependencyResults,
|
|
226
|
-
{
|
|
227
|
-
code: ((_a = root.nodes) === null || _a === void 0 ? void 0 : _a.length)
|
|
228
|
-
? context.styleProcessor.stringify(root)
|
|
229
|
-
: '',
|
|
230
|
-
watchFiles: [],
|
|
231
|
-
},
|
|
232
|
-
);
|
|
233
|
-
}
|
|
234
|
-
getThemeStyleFiles(context) {
|
|
235
|
-
return resolveThemeStyleFiles(
|
|
236
|
-
context.cssOptions,
|
|
237
|
-
context.context.packageRoot,
|
|
238
|
-
);
|
|
239
|
-
}
|
|
240
|
-
createModuleCssCode(context) {
|
|
241
|
-
var _a;
|
|
242
|
-
const themeFiles = this.getThemeStyleFiles(context);
|
|
243
|
-
const themeFileKeys = createStyleFileKeySet(themeFiles.values());
|
|
244
|
-
const styleFiles = this.getStyleFiles(context.sourceRoot).filter(
|
|
245
|
-
(styleFile) => !themeFileKeys.has(createStyleFileKey(styleFile)),
|
|
246
|
-
);
|
|
247
|
-
const root = context.styleProcessor.createRoot();
|
|
248
|
-
const seen = new Set();
|
|
249
|
-
for (const styleFile of styleFiles) {
|
|
250
|
-
const content = context.styleProcessor.readStyleFile(styleFile, seen);
|
|
251
|
-
if (content.trim()) {
|
|
252
|
-
context.styleProcessor.appendStyleContent(root, content, styleFile);
|
|
253
|
-
}
|
|
254
|
-
}
|
|
255
|
-
return {
|
|
256
|
-
code: ((_a = root.nodes) === null || _a === void 0 ? void 0 : _a.length)
|
|
257
|
-
? context.styleProcessor.stringify(root)
|
|
258
|
-
: '',
|
|
259
|
-
watchFiles: [context.configPath, ...styleFiles],
|
|
260
|
-
};
|
|
261
|
-
}
|
|
262
|
-
async createSourceModuleCssCode(context, cssPath) {
|
|
263
|
-
var _a, _b, _c;
|
|
264
|
-
const sourceModuleDir = removeCssExtension(cssPath);
|
|
265
|
-
const themeFiles = this.getThemeStyleFiles(context);
|
|
266
|
-
const themeFileKeys = createStyleFileKeySet(themeFiles.values());
|
|
267
|
-
const styleFiles = this.getStyleFiles(context.sourceRoot).filter(
|
|
268
|
-
(styleFile) => !themeFileKeys.has(createStyleFileKey(styleFile)),
|
|
269
|
-
);
|
|
270
|
-
const styleFilesByDir = groupStyleFilesByDir(
|
|
271
|
-
context.sourceRoot,
|
|
272
|
-
styleFiles,
|
|
273
|
-
);
|
|
274
|
-
const importedStyleFiles =
|
|
275
|
-
context.styleProcessor.collectImportedStyleFiles(styleFiles);
|
|
276
|
-
const importCollector = new ModuleStyleImportCollector(
|
|
277
|
-
context.sourceRoot,
|
|
278
|
-
context.context.packageRoot,
|
|
279
|
-
context.resolver,
|
|
280
|
-
Object.keys(this.config.styleExtensions),
|
|
281
|
-
);
|
|
282
|
-
const sourceFiles = fileWalker(context.sourceRoot);
|
|
283
|
-
const moduleStyleImports = importCollector.collect(
|
|
284
|
-
sourceFiles,
|
|
285
|
-
context.cssOptions,
|
|
286
|
-
);
|
|
287
|
-
const sourceStyleDir = path.join(
|
|
288
|
-
context.sourceRoot,
|
|
289
|
-
sourceModuleDir,
|
|
290
|
-
this.config.output.styleDir,
|
|
291
|
-
);
|
|
292
|
-
const moduleStyleResults = [];
|
|
293
|
-
const moduleStyleSpecifiers = [];
|
|
294
|
-
for (const specifier of (_a = moduleStyleImports.get(sourceModuleDir)) !==
|
|
295
|
-
null && _a !== void 0
|
|
296
|
-
? _a
|
|
297
|
-
: []) {
|
|
298
|
-
const result = this.toDevModuleImportSpecifier(
|
|
299
|
-
context,
|
|
300
|
-
sourceStyleDir,
|
|
301
|
-
specifier,
|
|
302
|
-
);
|
|
303
|
-
const parsed = this.parsePackageCssId(result);
|
|
304
|
-
if (parsed) {
|
|
305
|
-
moduleStyleResults.push(await this.createPackageCssCode(parsed));
|
|
306
|
-
continue;
|
|
307
|
-
}
|
|
308
|
-
moduleStyleSpecifiers.push(result);
|
|
309
|
-
}
|
|
310
|
-
const ownStyleFiles = (
|
|
311
|
-
(_b = styleFilesByDir.get(sourceModuleDir)) !== null && _b !== void 0
|
|
312
|
-
? _b
|
|
313
|
-
: []
|
|
314
|
-
).filter((styleFile) => !importedStyleFiles.has(path.resolve(styleFile)));
|
|
315
|
-
const root = context.styleProcessor.createRoot();
|
|
316
|
-
const seen = new Set();
|
|
317
|
-
for (const ownStyleFile of ownStyleFiles) {
|
|
318
|
-
const content = context.styleProcessor.readStyleFile(ownStyleFile, seen);
|
|
319
|
-
if (content.trim()) {
|
|
320
|
-
context.styleProcessor.appendStyleContent(root, content, ownStyleFile);
|
|
321
|
-
}
|
|
322
|
-
}
|
|
323
|
-
const ownStyleCode = (
|
|
324
|
-
(_c = root.nodes) === null || _c === void 0 ? void 0 : _c.length
|
|
325
|
-
)
|
|
326
|
-
? context.styleProcessor.stringify(root)
|
|
327
|
-
: '';
|
|
328
|
-
return mergeLoadResults(...moduleStyleResults, {
|
|
329
|
-
code: [createImportCode(moduleStyleSpecifiers), ownStyleCode]
|
|
330
|
-
.filter((code) => code.trim())
|
|
331
|
-
.join('\n'),
|
|
332
|
-
watchFiles: [
|
|
333
|
-
context.configPath,
|
|
334
|
-
...styleFiles,
|
|
335
|
-
...sourceFiles.filter((file) => /\.(ts|tsx)$/.test(file)),
|
|
336
|
-
],
|
|
337
|
-
});
|
|
338
|
-
}
|
|
339
|
-
getStyleFiles(sourceRoot) {
|
|
340
|
-
if (!fs.existsSync(sourceRoot)) return [];
|
|
341
|
-
return fileWalker(sourceRoot).filter((file) =>
|
|
342
|
-
Boolean(this.config.styleExtensions[path.extname(file)]),
|
|
343
|
-
);
|
|
344
|
-
}
|
|
345
|
-
toDevModuleImportSpecifier(context, sourceStyleDir, specifier) {
|
|
346
|
-
if (!specifier.startsWith('.')) {
|
|
347
|
-
return this.toDevExternalStyleSpecifier(specifier);
|
|
348
|
-
}
|
|
349
|
-
const outputStyleEntry = path.resolve(sourceStyleDir, specifier);
|
|
350
|
-
const styleEntrySuffix = `${path.sep}${this.config.output.styleDir}${path.sep}${this.config.output.indexCssFile}`;
|
|
351
|
-
if (!outputStyleEntry.endsWith(styleEntrySuffix)) {
|
|
352
|
-
return toCssFsSpecifier(outputStyleEntry);
|
|
353
|
-
}
|
|
354
|
-
const sourceModuleDir = path.relative(
|
|
355
|
-
context.sourceRoot,
|
|
356
|
-
outputStyleEntry.slice(0, -styleEntrySuffix.length),
|
|
357
|
-
);
|
|
358
|
-
return `${context.packageName}/${toPosixPath(sourceModuleDir)}.css`;
|
|
359
|
-
}
|
|
360
|
-
toDevExternalStyleSpecifier(specifier) {
|
|
361
|
-
const parsed = parsePackageStyleSpecifier(specifier);
|
|
362
|
-
if (!parsed) return specifier;
|
|
363
|
-
if (this.isWorkspacePackageName(parsed.packageName)) {
|
|
364
|
-
if (parsed.stylePath === STYLE_ENTRY) {
|
|
365
|
-
return `${parsed.packageName}/${EXTERNAL_ENTRY}`;
|
|
366
|
-
}
|
|
367
|
-
if (
|
|
368
|
-
parsed.stylePath ===
|
|
369
|
-
[this.config.output.styleDir, this.config.output.indexCssFile].join('/')
|
|
370
|
-
) {
|
|
371
|
-
return `${parsed.packageName}/${EXTERNAL_ENTRY}`;
|
|
372
|
-
}
|
|
373
|
-
}
|
|
374
|
-
return specifier;
|
|
375
|
-
}
|
|
376
|
-
isWorkspacePackageName(packageName) {
|
|
377
|
-
return this.getWorkspacePackageNames().includes(packageName);
|
|
378
|
-
}
|
|
379
|
-
getWorkspacePackages() {
|
|
380
|
-
const packagesRoot = path.join(this.workspaceRoot, this.packagesDir);
|
|
381
|
-
if (!fs.existsSync(packagesRoot)) return [];
|
|
382
|
-
return fs
|
|
383
|
-
.readdirSync(packagesRoot, { withFileTypes: true })
|
|
384
|
-
.filter((entry) => entry.isDirectory())
|
|
385
|
-
.flatMap((entry) => {
|
|
386
|
-
const packageRoot = path.join(packagesRoot, entry.name);
|
|
387
|
-
const packageJsonPath = path.join(packageRoot, 'package.json');
|
|
388
|
-
if (!fs.existsSync(packageJsonPath)) return [];
|
|
389
|
-
const pkg = JSON.parse(fs.readFileSync(packageJsonPath, 'utf8'));
|
|
390
|
-
if (!pkg.name) return [];
|
|
391
|
-
return [
|
|
392
|
-
{
|
|
393
|
-
packageName: pkg.name,
|
|
394
|
-
packageRoot,
|
|
395
|
-
},
|
|
396
|
-
];
|
|
397
|
-
});
|
|
398
|
-
}
|
|
399
|
-
}
|
|
400
|
-
export function parsePackageCssId(id, packageNames) {
|
|
401
|
-
if (!id.endsWith('.css')) {
|
|
402
|
-
return null;
|
|
403
|
-
}
|
|
404
|
-
const packageName = [...packageNames]
|
|
405
|
-
.sort((left, right) => right.length - left.length)
|
|
406
|
-
.find((name) => id.startsWith(`${name}/`));
|
|
407
|
-
if (!packageName) return null;
|
|
408
|
-
return {
|
|
409
|
-
packageName,
|
|
410
|
-
cssPath: id.slice(packageName.length + 1),
|
|
411
|
-
};
|
|
412
|
-
}
|
package/dist/css/core/path.d.ts
DELETED
|
@@ -1,4 +0,0 @@
|
|
|
1
|
-
export declare function isWindowsAbsolutePath(file: string): boolean;
|
|
2
|
-
export declare function normalizeCssFileKey(file: string): string;
|
|
3
|
-
export declare function toCssFsSpecifier(file: string): string;
|
|
4
|
-
export declare function toCssWatchPath(...parts: Array<string>): string;
|
package/dist/css/core/path.js
DELETED
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
import fs from 'node:fs';
|
|
2
|
-
import path from 'node:path';
|
|
3
|
-
import { toPosixPath } from '#auklet/utils';
|
|
4
|
-
const WINDOWS_ABSOLUTE_PATH_RE = /^[a-zA-Z]:[\\/]/;
|
|
5
|
-
export function isWindowsAbsolutePath(file) {
|
|
6
|
-
return WINDOWS_ABSOLUTE_PATH_RE.test(file);
|
|
7
|
-
}
|
|
8
|
-
export function normalizeCssFileKey(file) {
|
|
9
|
-
if (process.platform !== 'win32' && isWindowsAbsolutePath(file)) {
|
|
10
|
-
return toPosixPath(file);
|
|
11
|
-
}
|
|
12
|
-
const resolved = path.resolve(file);
|
|
13
|
-
const realpath = fs.existsSync(resolved)
|
|
14
|
-
? fs.realpathSync.native(resolved)
|
|
15
|
-
: resolved;
|
|
16
|
-
return toPosixPath(realpath);
|
|
17
|
-
}
|
|
18
|
-
export function toCssFsSpecifier(file) {
|
|
19
|
-
return path.posix.join('/@fs', normalizeCssFileKey(file));
|
|
20
|
-
}
|
|
21
|
-
export function toCssWatchPath(...parts) {
|
|
22
|
-
if (parts[0] && isWindowsAbsolutePath(parts[0])) {
|
|
23
|
-
return toPosixPath(path.win32.join(...parts));
|
|
24
|
-
}
|
|
25
|
-
return toPosixPath(path.join(...parts));
|
|
26
|
-
}
|
|
@@ -1,45 +0,0 @@
|
|
|
1
|
-
import type { CssOptions } from '#auklet/types';
|
|
2
|
-
export declare const STYLE_ENTRY = 'style.css';
|
|
3
|
-
export declare const EXTERNAL_ENTRY = 'external.css';
|
|
4
|
-
export declare const MODULE_ENTRY = 'module.css';
|
|
5
|
-
export declare const THEMES_DIR = 'themes';
|
|
6
|
-
export declare const THEMES_ENTRY_PREFIX = 'themes/';
|
|
7
|
-
export type PackageStyleSpecifier = {
|
|
8
|
-
packageName: string;
|
|
9
|
-
stylePath: string;
|
|
10
|
-
};
|
|
11
|
-
export declare function groupStyleFilesByDir(
|
|
12
|
-
sourceRoot: string,
|
|
13
|
-
styleFiles: Array<string>,
|
|
14
|
-
): Map<string, string[]>;
|
|
15
|
-
export declare function getGlobalStyleDependencies(
|
|
16
|
-
cssOptions: CssOptions,
|
|
17
|
-
): string[];
|
|
18
|
-
export declare function getExternalStyleDependencies(
|
|
19
|
-
cssOptions: CssOptions,
|
|
20
|
-
): string[];
|
|
21
|
-
export declare function getThemeStyleDependencies(
|
|
22
|
-
cssOptions: CssOptions,
|
|
23
|
-
themeName: string,
|
|
24
|
-
): string[];
|
|
25
|
-
export declare function getThemeStyleEntries(cssOptions: CssOptions): {
|
|
26
|
-
themeName: string;
|
|
27
|
-
file: string;
|
|
28
|
-
}[];
|
|
29
|
-
export declare function resolveThemeStyleFiles(
|
|
30
|
-
cssOptions: CssOptions,
|
|
31
|
-
packageRoot: string,
|
|
32
|
-
): Map<string, string>;
|
|
33
|
-
export declare function createStyleFileKeySet(
|
|
34
|
-
styleFiles: Iterable<string>,
|
|
35
|
-
): Set<string>;
|
|
36
|
-
export declare function createStyleFileKey(styleFile: string): string;
|
|
37
|
-
export declare function parsePackageStyleSpecifier(
|
|
38
|
-
specifier: string,
|
|
39
|
-
): PackageStyleSpecifier | null;
|
|
40
|
-
export declare function joinDependencySpecifier(
|
|
41
|
-
packageName: string,
|
|
42
|
-
dependencyPath: string,
|
|
43
|
-
): string;
|
|
44
|
-
export declare function createImportCode(specifiers: Array<string>): string;
|
|
45
|
-
export declare function removeCssExtension(cssPath: string): string;
|
|
@@ -1,108 +0,0 @@
|
|
|
1
|
-
import path from 'node:path';
|
|
2
|
-
import { isArray } from 'aidly';
|
|
3
|
-
import { getSourceModuleDir } from '#auklet/utils';
|
|
4
|
-
import { normalizeCssFileKey } from '#auklet/css/core/path';
|
|
5
|
-
export const STYLE_ENTRY = 'style.css';
|
|
6
|
-
export const EXTERNAL_ENTRY = 'external.css';
|
|
7
|
-
export const MODULE_ENTRY = 'module.css';
|
|
8
|
-
export const THEMES_DIR = 'themes';
|
|
9
|
-
export const THEMES_ENTRY_PREFIX = 'themes/';
|
|
10
|
-
export function groupStyleFilesByDir(sourceRoot, styleFiles) {
|
|
11
|
-
var _a;
|
|
12
|
-
const styleFilesByDir = new Map();
|
|
13
|
-
for (const styleFile of styleFiles) {
|
|
14
|
-
const sourceRelative = path.relative(sourceRoot, styleFile);
|
|
15
|
-
const sourceDir = getSourceModuleDir(sourceRelative);
|
|
16
|
-
const values =
|
|
17
|
-
(_a = styleFilesByDir.get(sourceDir)) !== null && _a !== void 0 ? _a : [];
|
|
18
|
-
values.push(styleFile);
|
|
19
|
-
styleFilesByDir.set(sourceDir, values);
|
|
20
|
-
}
|
|
21
|
-
return styleFilesByDir;
|
|
22
|
-
}
|
|
23
|
-
export function getGlobalStyleDependencies(cssOptions) {
|
|
24
|
-
var _a;
|
|
25
|
-
const dependencies = [];
|
|
26
|
-
for (const [packageName, dependency] of Object.entries(
|
|
27
|
-
(_a = cssOptions.cssDependencies) !== null && _a !== void 0 ? _a : {},
|
|
28
|
-
)) {
|
|
29
|
-
const globalDependencies = isArray(dependency.global)
|
|
30
|
-
? dependency.global
|
|
31
|
-
: [dependency.global].filter((value) => Boolean(value));
|
|
32
|
-
for (const globalDependency of globalDependencies) {
|
|
33
|
-
dependencies.push(joinDependencySpecifier(packageName, globalDependency));
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
|
-
return dependencies;
|
|
37
|
-
}
|
|
38
|
-
export function getExternalStyleDependencies(cssOptions) {
|
|
39
|
-
return getGlobalStyleDependencies(cssOptions);
|
|
40
|
-
}
|
|
41
|
-
export function getThemeStyleDependencies(cssOptions, themeName) {
|
|
42
|
-
var _a, _b;
|
|
43
|
-
const dependencies = [];
|
|
44
|
-
for (const [packageName, dependency] of Object.entries(
|
|
45
|
-
(_a = cssOptions.cssDependencies) !== null && _a !== void 0 ? _a : {},
|
|
46
|
-
)) {
|
|
47
|
-
const themeDependency =
|
|
48
|
-
(_b = dependency.themes) === null || _b === void 0
|
|
49
|
-
? void 0
|
|
50
|
-
: _b[themeName];
|
|
51
|
-
if (!themeDependency) continue;
|
|
52
|
-
dependencies.push(joinDependencySpecifier(packageName, themeDependency));
|
|
53
|
-
}
|
|
54
|
-
return dependencies;
|
|
55
|
-
}
|
|
56
|
-
export function getThemeStyleEntries(cssOptions) {
|
|
57
|
-
var _a;
|
|
58
|
-
return Object.entries(
|
|
59
|
-
(_a = cssOptions.themes) !== null && _a !== void 0 ? _a : {},
|
|
60
|
-
).map(([themeName, file]) => ({
|
|
61
|
-
themeName,
|
|
62
|
-
file,
|
|
63
|
-
}));
|
|
64
|
-
}
|
|
65
|
-
export function resolveThemeStyleFiles(cssOptions, packageRoot) {
|
|
66
|
-
const themeFiles = new Map();
|
|
67
|
-
for (const { themeName, file } of getThemeStyleEntries(cssOptions)) {
|
|
68
|
-
themeFiles.set(themeName, path.resolve(packageRoot, file));
|
|
69
|
-
}
|
|
70
|
-
return themeFiles;
|
|
71
|
-
}
|
|
72
|
-
export function createStyleFileKeySet(styleFiles) {
|
|
73
|
-
return new Set(Array.from(styleFiles, normalizeCssFileKey));
|
|
74
|
-
}
|
|
75
|
-
export function createStyleFileKey(styleFile) {
|
|
76
|
-
return normalizeCssFileKey(styleFile);
|
|
77
|
-
}
|
|
78
|
-
export function parsePackageStyleSpecifier(specifier) {
|
|
79
|
-
var _a, _b, _c;
|
|
80
|
-
if (specifier.startsWith('.')) return null;
|
|
81
|
-
const parts = specifier.split('/');
|
|
82
|
-
const packageName = specifier.startsWith('@')
|
|
83
|
-
? `${(_a = parts.shift()) !== null && _a !== void 0 ? _a : ''}/${
|
|
84
|
-
(_b = parts.shift()) !== null && _b !== void 0 ? _b : ''
|
|
85
|
-
}`
|
|
86
|
-
: (_c = parts.shift()) !== null && _c !== void 0
|
|
87
|
-
? _c
|
|
88
|
-
: '';
|
|
89
|
-
if (!packageName) return null;
|
|
90
|
-
return {
|
|
91
|
-
packageName,
|
|
92
|
-
stylePath: parts.join('/'),
|
|
93
|
-
};
|
|
94
|
-
}
|
|
95
|
-
export function joinDependencySpecifier(packageName, dependencyPath) {
|
|
96
|
-
if (!dependencyPath) return packageName;
|
|
97
|
-
return dependencyPath.startsWith('/')
|
|
98
|
-
? `${packageName}${dependencyPath}`
|
|
99
|
-
: `${packageName}/${dependencyPath}`;
|
|
100
|
-
}
|
|
101
|
-
export function createImportCode(specifiers) {
|
|
102
|
-
return Array.from(new Set(specifiers))
|
|
103
|
-
.map((specifier) => `@import "${specifier}";`)
|
|
104
|
-
.join('\n');
|
|
105
|
-
}
|
|
106
|
-
export function removeCssExtension(cssPath) {
|
|
107
|
-
return cssPath.slice(0, -path.extname(cssPath).length);
|
|
108
|
-
}
|
|
@@ -1,33 +0,0 @@
|
|
|
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
|
-
}
|