auklet 0.0.3 → 0.0.5

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