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
|
@@ -0,0 +1,362 @@
|
|
|
1
|
+
import path from 'node:path';
|
|
2
|
+
import { aukletConfigFile } from '#auklet/config';
|
|
3
|
+
import { loadAukletConfig } from '#auklet/configLoader';
|
|
4
|
+
import { moduleStyleBuildConfig } from '#auklet/css/config';
|
|
5
|
+
import { ModuleStyleGraphRequestCache } from '#auklet/css/core/moduleGraphRequestCache';
|
|
6
|
+
import { StyleModuleEntryPlanner } from '#auklet/css/core/styleModuleEntryPlanner';
|
|
7
|
+
import {
|
|
8
|
+
EXTERNAL_ENTRY,
|
|
9
|
+
MODULE_ENTRY,
|
|
10
|
+
STYLE_ENTRY,
|
|
11
|
+
THEMES_ENTRY_PREFIX,
|
|
12
|
+
} from '#auklet/css/constants';
|
|
13
|
+
import {
|
|
14
|
+
createExternalEntryParts,
|
|
15
|
+
createStyleEntryParts,
|
|
16
|
+
createThemeEntryParts,
|
|
17
|
+
} from '#auklet/css/core/style/plan';
|
|
18
|
+
import {
|
|
19
|
+
createImportCode,
|
|
20
|
+
parsePackageStyleSpecifier,
|
|
21
|
+
removeStyleExtension,
|
|
22
|
+
} from '#auklet/css/core/style/specifier';
|
|
23
|
+
import {
|
|
24
|
+
normalizeFileKey,
|
|
25
|
+
toFsSpecifier,
|
|
26
|
+
toPosixPath,
|
|
27
|
+
toWatchPath,
|
|
28
|
+
} from '#auklet/utils';
|
|
29
|
+
const mergeLoadResults = (...results) => {
|
|
30
|
+
return {
|
|
31
|
+
code: results
|
|
32
|
+
.map((result) => result.code)
|
|
33
|
+
.filter((code) => code.trim())
|
|
34
|
+
.join('\n'),
|
|
35
|
+
watchFiles: Array.from(
|
|
36
|
+
new Set(results.flatMap((result) => result.watchFiles)),
|
|
37
|
+
),
|
|
38
|
+
};
|
|
39
|
+
};
|
|
40
|
+
export class ModuleStyleGraph {
|
|
41
|
+
config;
|
|
42
|
+
workspaceRoot;
|
|
43
|
+
packagesDir;
|
|
44
|
+
loadAukletConfig;
|
|
45
|
+
constructor(options) {
|
|
46
|
+
this.config = options.config ?? moduleStyleBuildConfig;
|
|
47
|
+
this.workspaceRoot = normalizeFileKey(options.workspaceRoot);
|
|
48
|
+
this.packagesDir = options.packagesDir ?? 'packages';
|
|
49
|
+
this.loadAukletConfig = options.loadAukletConfig ?? loadAukletConfig;
|
|
50
|
+
}
|
|
51
|
+
parsePackageStyleId(id) {
|
|
52
|
+
return parsePackageStyleId(id, this.getWorkspacePackageNames());
|
|
53
|
+
}
|
|
54
|
+
isWorkspaceSourceGraphFile(file) {
|
|
55
|
+
const normalizedFile = normalizeFileKey(file);
|
|
56
|
+
const packagesRoot = normalizeFileKey(
|
|
57
|
+
path.join(this.workspaceRoot, this.packagesDir),
|
|
58
|
+
);
|
|
59
|
+
if (!normalizedFile.startsWith(`${packagesRoot}/`)) {
|
|
60
|
+
return false;
|
|
61
|
+
}
|
|
62
|
+
if (normalizedFile.endsWith(aukletConfigFile)) return true;
|
|
63
|
+
if (normalizedFile.endsWith('.ts') || normalizedFile.endsWith('.tsx')) {
|
|
64
|
+
return true;
|
|
65
|
+
}
|
|
66
|
+
return this.config.styleExtensions.some((extension) =>
|
|
67
|
+
normalizedFile.endsWith(extension),
|
|
68
|
+
);
|
|
69
|
+
}
|
|
70
|
+
isStyleConfigFile(file) {
|
|
71
|
+
return normalizeFileKey(file).endsWith(aukletConfigFile);
|
|
72
|
+
}
|
|
73
|
+
isStyleFile(file) {
|
|
74
|
+
return this.config.styleExtensions.includes(path.extname(file));
|
|
75
|
+
}
|
|
76
|
+
getWorkspacePackageNames() {
|
|
77
|
+
return this.createRequestCache().getWorkspacePackageNames();
|
|
78
|
+
}
|
|
79
|
+
getWatchRoots() {
|
|
80
|
+
const packagesRoot = path.join(this.workspaceRoot, this.packagesDir);
|
|
81
|
+
return [
|
|
82
|
+
toWatchPath(packagesRoot, '*', 'src'),
|
|
83
|
+
toWatchPath(packagesRoot, '*', aukletConfigFile),
|
|
84
|
+
];
|
|
85
|
+
}
|
|
86
|
+
async createPackageStyleCode(parsed) {
|
|
87
|
+
return this.createPackageStyleCodeWithCache(
|
|
88
|
+
parsed,
|
|
89
|
+
this.createRequestCache(),
|
|
90
|
+
);
|
|
91
|
+
}
|
|
92
|
+
async createPackageStyleCodeWithCache(parsed, cache) {
|
|
93
|
+
const context = await cache.getContext(parsed);
|
|
94
|
+
if (!context) {
|
|
95
|
+
return {
|
|
96
|
+
code: '',
|
|
97
|
+
watchFiles: [],
|
|
98
|
+
};
|
|
99
|
+
}
|
|
100
|
+
if (parsed.stylePath === STYLE_ENTRY) {
|
|
101
|
+
return this.createStyleCode(context, cache);
|
|
102
|
+
}
|
|
103
|
+
if (parsed.stylePath === EXTERNAL_ENTRY) {
|
|
104
|
+
return this.createExternalStyleCode(context, cache);
|
|
105
|
+
}
|
|
106
|
+
if (parsed.stylePath === MODULE_ENTRY) {
|
|
107
|
+
return this.createModuleStyleCode(context);
|
|
108
|
+
}
|
|
109
|
+
if (parsed.stylePath.startsWith(THEMES_ENTRY_PREFIX)) {
|
|
110
|
+
return this.createThemeStyleCode(context, cache, [
|
|
111
|
+
removeStyleExtension(
|
|
112
|
+
parsed.stylePath.slice(THEMES_ENTRY_PREFIX.length),
|
|
113
|
+
),
|
|
114
|
+
]);
|
|
115
|
+
}
|
|
116
|
+
return this.createSourceModuleStyleCode(context, cache, parsed.stylePath);
|
|
117
|
+
}
|
|
118
|
+
async createStyleCode(context, cache) {
|
|
119
|
+
const results = [];
|
|
120
|
+
for (const part of createStyleEntryParts(context.normalizedConfig)) {
|
|
121
|
+
if (part.type === 'dependencies') {
|
|
122
|
+
results.push(
|
|
123
|
+
await this.createDependencyStyleCode(context, cache, part.specifiers),
|
|
124
|
+
);
|
|
125
|
+
continue;
|
|
126
|
+
}
|
|
127
|
+
if (part.type === 'themes') {
|
|
128
|
+
results.push(
|
|
129
|
+
await this.createThemeStyleCode(
|
|
130
|
+
context,
|
|
131
|
+
cache,
|
|
132
|
+
part.themeNames,
|
|
133
|
+
false,
|
|
134
|
+
),
|
|
135
|
+
);
|
|
136
|
+
continue;
|
|
137
|
+
}
|
|
138
|
+
results.push(this.createModuleStyleCode(context));
|
|
139
|
+
}
|
|
140
|
+
return mergeLoadResults(...results);
|
|
141
|
+
}
|
|
142
|
+
async createDependencyStyleCode(
|
|
143
|
+
context,
|
|
144
|
+
cache,
|
|
145
|
+
specifiers,
|
|
146
|
+
mapSpecifier = (specifier) => specifier,
|
|
147
|
+
) {
|
|
148
|
+
const results = [];
|
|
149
|
+
const imports = [];
|
|
150
|
+
for (const specifier of specifiers) {
|
|
151
|
+
const outputSpecifier = mapSpecifier(specifier);
|
|
152
|
+
const parsed = this.parsePackageStyleIdInRequest(outputSpecifier, cache);
|
|
153
|
+
if (parsed) {
|
|
154
|
+
results.push(await this.createPackageStyleCodeWithCache(parsed, cache));
|
|
155
|
+
continue;
|
|
156
|
+
}
|
|
157
|
+
imports.push(outputSpecifier);
|
|
158
|
+
}
|
|
159
|
+
return mergeLoadResults(
|
|
160
|
+
{
|
|
161
|
+
code: createImportCode(imports),
|
|
162
|
+
watchFiles: [context.configPath],
|
|
163
|
+
},
|
|
164
|
+
...results,
|
|
165
|
+
);
|
|
166
|
+
}
|
|
167
|
+
async createExternalStyleCode(context, cache) {
|
|
168
|
+
const results = [];
|
|
169
|
+
for (const part of createExternalEntryParts(context.normalizedConfig)) {
|
|
170
|
+
if (part.type === 'dependencies') {
|
|
171
|
+
results.push(
|
|
172
|
+
await this.createDependencyStyleCode(
|
|
173
|
+
context,
|
|
174
|
+
cache,
|
|
175
|
+
part.specifiers,
|
|
176
|
+
(specifier) => this.toDevExternalStyleSpecifier(specifier, cache),
|
|
177
|
+
),
|
|
178
|
+
);
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
return mergeLoadResults(...results);
|
|
182
|
+
}
|
|
183
|
+
async createThemeStyleCode(
|
|
184
|
+
context,
|
|
185
|
+
cache,
|
|
186
|
+
themeNames,
|
|
187
|
+
includeDependencies = true,
|
|
188
|
+
) {
|
|
189
|
+
const { themeFiles } = context.packageContext;
|
|
190
|
+
const targetThemeNames = themeNames ?? context.packageContext.themeNames;
|
|
191
|
+
const root = context.styleProcessor.createRoot();
|
|
192
|
+
const watchFiles = [context.configPath, ...themeFiles.values()];
|
|
193
|
+
const dependencyResults = [];
|
|
194
|
+
for (const themeName of targetThemeNames) {
|
|
195
|
+
for (const part of createThemeEntryParts(
|
|
196
|
+
context.normalizedConfig,
|
|
197
|
+
themeName,
|
|
198
|
+
{
|
|
199
|
+
includeDependencies,
|
|
200
|
+
},
|
|
201
|
+
)) {
|
|
202
|
+
if (part.type === 'dependencies') {
|
|
203
|
+
dependencyResults.push(
|
|
204
|
+
await this.createDependencyStyleCode(
|
|
205
|
+
context,
|
|
206
|
+
cache,
|
|
207
|
+
part.specifiers,
|
|
208
|
+
),
|
|
209
|
+
);
|
|
210
|
+
continue;
|
|
211
|
+
}
|
|
212
|
+
const themeFile = themeFiles.get(part.themeName);
|
|
213
|
+
if (!themeFile) continue;
|
|
214
|
+
const content = context.styleProcessor.readStyleFile(themeFile);
|
|
215
|
+
if (content.trim()) {
|
|
216
|
+
context.styleProcessor.appendStyleContent(root, content, themeFile);
|
|
217
|
+
}
|
|
218
|
+
}
|
|
219
|
+
}
|
|
220
|
+
return mergeLoadResults(
|
|
221
|
+
{
|
|
222
|
+
code: '',
|
|
223
|
+
watchFiles,
|
|
224
|
+
},
|
|
225
|
+
...dependencyResults,
|
|
226
|
+
{
|
|
227
|
+
code: root.nodes?.length ? context.styleProcessor.stringify(root) : '',
|
|
228
|
+
watchFiles: [],
|
|
229
|
+
},
|
|
230
|
+
);
|
|
231
|
+
}
|
|
232
|
+
createModuleStyleCode(context) {
|
|
233
|
+
const { styleFiles } = context.packageContext;
|
|
234
|
+
const root = context.styleProcessor.createRoot();
|
|
235
|
+
const seen = new Set();
|
|
236
|
+
for (const styleFile of styleFiles) {
|
|
237
|
+
const content = context.styleProcessor.readStyleFile(styleFile, seen);
|
|
238
|
+
if (content.trim()) {
|
|
239
|
+
context.styleProcessor.appendStyleContent(root, content, styleFile);
|
|
240
|
+
}
|
|
241
|
+
}
|
|
242
|
+
return {
|
|
243
|
+
code: root.nodes?.length ? context.styleProcessor.stringify(root) : '',
|
|
244
|
+
watchFiles: [context.configPath, ...styleFiles],
|
|
245
|
+
};
|
|
246
|
+
}
|
|
247
|
+
async createSourceModuleStyleCode(context, cache, stylePath) {
|
|
248
|
+
const sourceModuleDir = removeStyleExtension(stylePath);
|
|
249
|
+
const { styleFiles, sourceFiles } = context.packageContext;
|
|
250
|
+
const moduleStyleImports = context.packageContext.importCollector.collect(
|
|
251
|
+
sourceFiles,
|
|
252
|
+
context.normalizedConfig,
|
|
253
|
+
);
|
|
254
|
+
const entry = new StyleModuleEntryPlanner(
|
|
255
|
+
context.packageContext,
|
|
256
|
+
).createEntry(sourceModuleDir, moduleStyleImports);
|
|
257
|
+
const sourceStyleDir = path.join(
|
|
258
|
+
context.sourceRoot,
|
|
259
|
+
sourceModuleDir,
|
|
260
|
+
this.config.output.styleDir,
|
|
261
|
+
);
|
|
262
|
+
const moduleStyleResults = [];
|
|
263
|
+
const moduleStyleSpecifiers = [];
|
|
264
|
+
for (const specifier of entry.moduleStyleImports) {
|
|
265
|
+
const result = this.toDevModuleImportSpecifier(
|
|
266
|
+
context,
|
|
267
|
+
cache,
|
|
268
|
+
sourceStyleDir,
|
|
269
|
+
specifier,
|
|
270
|
+
);
|
|
271
|
+
const parsed = this.parsePackageStyleIdInRequest(result, cache);
|
|
272
|
+
if (parsed) {
|
|
273
|
+
moduleStyleResults.push(
|
|
274
|
+
await this.createPackageStyleCodeWithCache(parsed, cache),
|
|
275
|
+
);
|
|
276
|
+
continue;
|
|
277
|
+
}
|
|
278
|
+
moduleStyleSpecifiers.push(result);
|
|
279
|
+
}
|
|
280
|
+
const root = context.styleProcessor.createRoot();
|
|
281
|
+
const seen = new Set();
|
|
282
|
+
for (const ownStyleFile of entry.ownStyleFiles) {
|
|
283
|
+
const content = context.styleProcessor.readStyleFile(ownStyleFile, seen);
|
|
284
|
+
if (content.trim()) {
|
|
285
|
+
context.styleProcessor.appendStyleContent(root, content, ownStyleFile);
|
|
286
|
+
}
|
|
287
|
+
}
|
|
288
|
+
const ownStyleCode = root.nodes?.length
|
|
289
|
+
? context.styleProcessor.stringify(root)
|
|
290
|
+
: '';
|
|
291
|
+
return mergeLoadResults(...moduleStyleResults, {
|
|
292
|
+
code: [createImportCode(moduleStyleSpecifiers), ownStyleCode]
|
|
293
|
+
.filter((code) => code.trim())
|
|
294
|
+
.join('\n'),
|
|
295
|
+
watchFiles: [
|
|
296
|
+
context.configPath,
|
|
297
|
+
...styleFiles,
|
|
298
|
+
...sourceFiles.filter((file) => /\.(ts|tsx)$/.test(file)),
|
|
299
|
+
],
|
|
300
|
+
});
|
|
301
|
+
}
|
|
302
|
+
toDevModuleImportSpecifier(context, cache, sourceStyleDir, specifier) {
|
|
303
|
+
if (!specifier.startsWith('.')) {
|
|
304
|
+
return this.toDevExternalStyleSpecifier(specifier, cache);
|
|
305
|
+
}
|
|
306
|
+
const outputStyleEntry = path.resolve(sourceStyleDir, specifier);
|
|
307
|
+
const styleEntrySuffix = `${path.sep}${this.config.output.styleDir}${path.sep}${this.config.output.indexStyleFile}`;
|
|
308
|
+
if (!outputStyleEntry.endsWith(styleEntrySuffix)) {
|
|
309
|
+
return toFsSpecifier(outputStyleEntry);
|
|
310
|
+
}
|
|
311
|
+
const sourceModuleDir = path.relative(
|
|
312
|
+
context.sourceRoot,
|
|
313
|
+
outputStyleEntry.slice(0, -styleEntrySuffix.length),
|
|
314
|
+
);
|
|
315
|
+
return `${context.packageName}/${toPosixPath(sourceModuleDir)}.css`;
|
|
316
|
+
}
|
|
317
|
+
toDevExternalStyleSpecifier(specifier, cache) {
|
|
318
|
+
const parsed = parsePackageStyleSpecifier(specifier);
|
|
319
|
+
if (!parsed) return specifier;
|
|
320
|
+
if (this.isWorkspacePackageName(parsed.packageName, cache)) {
|
|
321
|
+
if (parsed.stylePath === STYLE_ENTRY) {
|
|
322
|
+
return `${parsed.packageName}/${EXTERNAL_ENTRY}`;
|
|
323
|
+
}
|
|
324
|
+
if (
|
|
325
|
+
parsed.stylePath ===
|
|
326
|
+
[this.config.output.styleDir, this.config.output.indexStyleFile].join(
|
|
327
|
+
'/',
|
|
328
|
+
)
|
|
329
|
+
) {
|
|
330
|
+
return `${parsed.packageName}/${EXTERNAL_ENTRY}`;
|
|
331
|
+
}
|
|
332
|
+
}
|
|
333
|
+
return specifier;
|
|
334
|
+
}
|
|
335
|
+
parsePackageStyleIdInRequest(id, cache) {
|
|
336
|
+
return parsePackageStyleId(id, cache.getWorkspacePackageNames());
|
|
337
|
+
}
|
|
338
|
+
isWorkspacePackageName(packageName, cache) {
|
|
339
|
+
return cache.isWorkspacePackageName(packageName);
|
|
340
|
+
}
|
|
341
|
+
createRequestCache() {
|
|
342
|
+
return new ModuleStyleGraphRequestCache({
|
|
343
|
+
workspaceRoot: this.workspaceRoot,
|
|
344
|
+
packagesDir: this.packagesDir,
|
|
345
|
+
config: this.config,
|
|
346
|
+
loadAukletConfig: this.loadAukletConfig,
|
|
347
|
+
});
|
|
348
|
+
}
|
|
349
|
+
}
|
|
350
|
+
export function parsePackageStyleId(id, packageNames) {
|
|
351
|
+
if (!id.endsWith('.css')) {
|
|
352
|
+
return null;
|
|
353
|
+
}
|
|
354
|
+
const packageName = [...packageNames]
|
|
355
|
+
.sort((left, right) => right.length - left.length)
|
|
356
|
+
.find((name) => id.startsWith(`${name}/`));
|
|
357
|
+
if (!packageName) return null;
|
|
358
|
+
return {
|
|
359
|
+
packageName,
|
|
360
|
+
stylePath: id.slice(packageName.length + 1),
|
|
361
|
+
};
|
|
362
|
+
}
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
import { StylePackageContext } from '#auklet/css/core/stylePackageContext';
|
|
2
|
+
import type {
|
|
3
|
+
AukletConfig,
|
|
4
|
+
ModuleStyleBuildConfig,
|
|
5
|
+
NormalizedAukletConfig,
|
|
6
|
+
ResolvedModuleStyleBuildContext,
|
|
7
|
+
} from '#auklet/types';
|
|
8
|
+
import type { StyleProcessor } from '#auklet/css/core/styleProcessor';
|
|
9
|
+
import type { WorkspaceStyleResolver } from '#auklet/css/core/workspaceStyleResolver';
|
|
10
|
+
import type { PackageStyleId } from '#auklet/css/core/moduleGraph';
|
|
11
|
+
export type PackageStyleContext = {
|
|
12
|
+
normalizedConfig: NormalizedAukletConfig;
|
|
13
|
+
context: ResolvedModuleStyleBuildContext;
|
|
14
|
+
packageContext: StylePackageContext;
|
|
15
|
+
packageName: string;
|
|
16
|
+
configPath: string;
|
|
17
|
+
resolver: WorkspaceStyleResolver;
|
|
18
|
+
sourceRoot: string;
|
|
19
|
+
styleProcessor: StyleProcessor;
|
|
20
|
+
};
|
|
21
|
+
export type LoadAukletConfig = (
|
|
22
|
+
packageRoot: string,
|
|
23
|
+
options?: {
|
|
24
|
+
cacheBust?: boolean;
|
|
25
|
+
},
|
|
26
|
+
) => Promise<AukletConfig>;
|
|
27
|
+
export type ModuleStyleGraphRequestCacheOptions = {
|
|
28
|
+
workspaceRoot: string;
|
|
29
|
+
packagesDir: string;
|
|
30
|
+
config: ModuleStyleBuildConfig;
|
|
31
|
+
loadAukletConfig?: LoadAukletConfig;
|
|
32
|
+
};
|
|
33
|
+
export declare class ModuleStyleGraphRequestCache {
|
|
34
|
+
private readonly options;
|
|
35
|
+
private workspacePackages?;
|
|
36
|
+
private workspacePackageNames?;
|
|
37
|
+
private readonly contexts;
|
|
38
|
+
private readonly loadAukletConfig;
|
|
39
|
+
constructor(options: ModuleStyleGraphRequestCacheOptions);
|
|
40
|
+
getWorkspacePackageNames(): string[];
|
|
41
|
+
isWorkspacePackageName(packageName: string): boolean;
|
|
42
|
+
getContext(parsed: PackageStyleId): Promise<
|
|
43
|
+
| PackageStyleContext
|
|
44
|
+
| {
|
|
45
|
+
normalizedConfig: {
|
|
46
|
+
source: string;
|
|
47
|
+
output: string;
|
|
48
|
+
modules: boolean;
|
|
49
|
+
build: {
|
|
50
|
+
formats: Array<import('#auklet/types').PackageBuildFormat>;
|
|
51
|
+
target: import('#auklet/types').PackageBuildTarget;
|
|
52
|
+
platform: import('#auklet/types').PackageBuildPlatform;
|
|
53
|
+
banner?: string;
|
|
54
|
+
externals?: Array<string>;
|
|
55
|
+
tsconfig?: string;
|
|
56
|
+
};
|
|
57
|
+
styles: {
|
|
58
|
+
themes: {};
|
|
59
|
+
dependencies: {
|
|
60
|
+
[k: string]: {
|
|
61
|
+
entry: string | string[] | undefined;
|
|
62
|
+
themes: Record<string, string> | undefined;
|
|
63
|
+
components: string | string[] | undefined;
|
|
64
|
+
};
|
|
65
|
+
};
|
|
66
|
+
};
|
|
67
|
+
};
|
|
68
|
+
context: ResolvedModuleStyleBuildContext;
|
|
69
|
+
packageContext: StylePackageContext;
|
|
70
|
+
packageName: string;
|
|
71
|
+
configPath: string;
|
|
72
|
+
resolver: WorkspaceStyleResolver;
|
|
73
|
+
sourceRoot: string;
|
|
74
|
+
styleProcessor: StyleProcessor;
|
|
75
|
+
}
|
|
76
|
+
| null
|
|
77
|
+
>;
|
|
78
|
+
private createContext;
|
|
79
|
+
private getWorkspacePackages;
|
|
80
|
+
}
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
import fs from 'node:fs';
|
|
2
|
+
import path from 'node:path';
|
|
3
|
+
import { aukletConfigFile, normalizeAukletConfig } from '#auklet/config';
|
|
4
|
+
import { loadAukletConfig } from '#auklet/configLoader';
|
|
5
|
+
import { StylePackageContext } from '#auklet/css/core/stylePackageContext';
|
|
6
|
+
export class ModuleStyleGraphRequestCache {
|
|
7
|
+
options;
|
|
8
|
+
workspacePackages;
|
|
9
|
+
workspacePackageNames;
|
|
10
|
+
contexts = new Map();
|
|
11
|
+
loadAukletConfig;
|
|
12
|
+
constructor(options) {
|
|
13
|
+
this.options = options;
|
|
14
|
+
this.loadAukletConfig = options.loadAukletConfig ?? loadAukletConfig;
|
|
15
|
+
}
|
|
16
|
+
getWorkspacePackageNames() {
|
|
17
|
+
this.workspacePackageNames ??= this.getWorkspacePackages().map(
|
|
18
|
+
(item) => item.packageName,
|
|
19
|
+
);
|
|
20
|
+
return this.workspacePackageNames;
|
|
21
|
+
}
|
|
22
|
+
isWorkspacePackageName(packageName) {
|
|
23
|
+
return this.getWorkspacePackageNames().includes(packageName);
|
|
24
|
+
}
|
|
25
|
+
async getContext(parsed) {
|
|
26
|
+
const cachedContext = this.contexts.get(parsed.packageName);
|
|
27
|
+
if (cachedContext) return cachedContext;
|
|
28
|
+
const context = this.createContext(parsed);
|
|
29
|
+
this.contexts.set(parsed.packageName, context);
|
|
30
|
+
return context;
|
|
31
|
+
}
|
|
32
|
+
async createContext(parsed) {
|
|
33
|
+
const workspacePackage = this.getWorkspacePackages().find(
|
|
34
|
+
(item) => item.packageName === parsed.packageName,
|
|
35
|
+
);
|
|
36
|
+
if (!workspacePackage) return null;
|
|
37
|
+
const packageRoot = workspacePackage.packageRoot;
|
|
38
|
+
if (!fs.existsSync(packageRoot)) return null;
|
|
39
|
+
const rawConfig = await this.loadAukletConfig(packageRoot, {
|
|
40
|
+
cacheBust: true,
|
|
41
|
+
});
|
|
42
|
+
const normalizedConfig = normalizeAukletConfig(rawConfig);
|
|
43
|
+
const context = {
|
|
44
|
+
packageRoot,
|
|
45
|
+
sourceDir: normalizedConfig.source,
|
|
46
|
+
outputDir: normalizedConfig.output,
|
|
47
|
+
};
|
|
48
|
+
const packageContext = new StylePackageContext({
|
|
49
|
+
config: this.options.config,
|
|
50
|
+
context,
|
|
51
|
+
normalizedConfig,
|
|
52
|
+
});
|
|
53
|
+
return {
|
|
54
|
+
normalizedConfig,
|
|
55
|
+
context,
|
|
56
|
+
packageContext,
|
|
57
|
+
packageName: parsed.packageName,
|
|
58
|
+
configPath: path.join(packageRoot, aukletConfigFile),
|
|
59
|
+
resolver: packageContext.resolver,
|
|
60
|
+
sourceRoot: packageContext.sourceRoot,
|
|
61
|
+
styleProcessor: packageContext.styleProcessor,
|
|
62
|
+
};
|
|
63
|
+
}
|
|
64
|
+
getWorkspacePackages() {
|
|
65
|
+
if (this.workspacePackages) return this.workspacePackages;
|
|
66
|
+
const packagesRoot = path.join(
|
|
67
|
+
this.options.workspaceRoot,
|
|
68
|
+
this.options.packagesDir,
|
|
69
|
+
);
|
|
70
|
+
if (!fs.existsSync(packagesRoot)) {
|
|
71
|
+
this.workspacePackages = [];
|
|
72
|
+
return this.workspacePackages;
|
|
73
|
+
}
|
|
74
|
+
this.workspacePackages = fs
|
|
75
|
+
.readdirSync(packagesRoot, { withFileTypes: true })
|
|
76
|
+
.filter((entry) => entry.isDirectory())
|
|
77
|
+
.flatMap((entry) => {
|
|
78
|
+
const packageRoot = path.join(packagesRoot, entry.name);
|
|
79
|
+
const packageJsonPath = path.join(packageRoot, 'package.json');
|
|
80
|
+
if (!fs.existsSync(packageJsonPath)) return [];
|
|
81
|
+
const pkg = JSON.parse(fs.readFileSync(packageJsonPath, 'utf8'));
|
|
82
|
+
if (!pkg.name) return [];
|
|
83
|
+
return [
|
|
84
|
+
{
|
|
85
|
+
packageName: pkg.name,
|
|
86
|
+
packageRoot,
|
|
87
|
+
},
|
|
88
|
+
];
|
|
89
|
+
});
|
|
90
|
+
return this.workspacePackages;
|
|
91
|
+
}
|
|
92
|
+
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { NormalizedAukletConfig } from '#auklet/types';
|
|
2
2
|
import type { WorkspaceStyleResolver } from '#auklet/css/core/workspaceStyleResolver';
|
|
3
3
|
export declare class ModuleStyleImportCollector {
|
|
4
4
|
private readonly srcRoot;
|
|
@@ -12,7 +12,10 @@ export declare class ModuleStyleImportCollector {
|
|
|
12
12
|
resolver: WorkspaceStyleResolver,
|
|
13
13
|
styleExtensions?: Array<string>,
|
|
14
14
|
);
|
|
15
|
-
collect(
|
|
15
|
+
collect(
|
|
16
|
+
files: Array<string>,
|
|
17
|
+
config: NormalizedAukletConfig,
|
|
18
|
+
): Map<string, string[]>;
|
|
16
19
|
private getImportDeclarations;
|
|
17
20
|
private collectSourceImportStyle;
|
|
18
21
|
private resolveSourceImportStyleEntry;
|
|
@@ -24,6 +27,5 @@ export declare class ModuleStyleImportCollector {
|
|
|
24
27
|
private getImportPathValues;
|
|
25
28
|
private createStyleSpecifier;
|
|
26
29
|
private createDirectStyleSpecifier;
|
|
27
|
-
private joinDependencySpecifier;
|
|
28
30
|
private getImportedNames;
|
|
29
31
|
}
|