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.
Files changed (42) hide show
  1. package/README.md +207 -0
  2. package/bin/entry.cjs +136 -0
  3. package/dist/build/runTsdown.d.ts +8 -0
  4. package/dist/build/runTsdown.js +36 -0
  5. package/dist/build/tsdownConfig.d.ts +12 -0
  6. package/dist/build/tsdownConfig.js +223 -0
  7. package/dist/config.d.ts +8 -0
  8. package/dist/config.js +14 -0
  9. package/dist/configLoader.d.ts +8 -0
  10. package/dist/configLoader.js +85 -0
  11. package/dist/css/core/config.d.ts +2 -0
  12. package/dist/css/core/config.js +11 -0
  13. package/dist/css/core/constants.d.ts +3 -0
  14. package/dist/css/core/constants.js +3 -0
  15. package/dist/css/core/moduleCssGraph.d.ts +51 -0
  16. package/dist/css/core/moduleCssGraph.js +416 -0
  17. package/dist/css/core/moduleStyleImportCollector.d.ts +29 -0
  18. package/dist/css/core/moduleStyleImportCollector.js +285 -0
  19. package/dist/css/core/path.d.ts +4 -0
  20. package/dist/css/core/path.js +26 -0
  21. package/dist/css/core/styleEntry.d.ts +45 -0
  22. package/dist/css/core/styleEntry.js +108 -0
  23. package/dist/css/core/styleProcessor.d.ts +16 -0
  24. package/dist/css/core/styleProcessor.js +123 -0
  25. package/dist/css/core/workspaceStyleResolver.d.ts +18 -0
  26. package/dist/css/core/workspaceStyleResolver.js +100 -0
  27. package/dist/css/production/moduleCssBuilder.d.ts +33 -0
  28. package/dist/css/production/moduleCssBuilder.js +445 -0
  29. package/dist/css/vite/hmr.d.ts +15 -0
  30. package/dist/css/vite/hmr.js +153 -0
  31. package/dist/css/vite/vitePlugin.d.ts +24 -0
  32. package/dist/css/vite/vitePlugin.js +140 -0
  33. package/dist/css/watch/moduleCssWatcher.d.ts +19 -0
  34. package/dist/css/watch/moduleCssWatcher.js +106 -0
  35. package/dist/index.d.ts +26 -0
  36. package/dist/index.js +12 -0
  37. package/dist/types.d.ts +58 -0
  38. package/dist/types.js +0 -0
  39. package/dist/utils.d.ts +20 -0
  40. package/dist/utils.js +59 -0
  41. package/package.json +80 -8
  42. package/index.js +0 -1
@@ -0,0 +1,85 @@
1
+ import fs from 'node:fs';
2
+ import path from 'node:path';
3
+ import { fileURLToPath, pathToFileURL } from 'node:url';
4
+ import ts from 'typescript';
5
+ import { aukletConfigFile } from '#auklet/config';
6
+ const importAukletConfigModule = async (configPath, href) => {
7
+ try {
8
+ return await import(href);
9
+ } catch (error) {
10
+ if (!isUnknownTsExtensionError(error) || !configPath.endsWith('.ts')) {
11
+ throw error;
12
+ }
13
+ return importTsOptionsModule(href);
14
+ }
15
+ };
16
+ const importTsOptionsModule = async (href) => {
17
+ const configPath = fileURLToPath(href);
18
+ const source = fs.readFileSync(configPath, 'utf8');
19
+ const output = ts.transpileModule(source, {
20
+ compilerOptions: {
21
+ esModuleInterop: true,
22
+ module: ts.ModuleKind.ESNext,
23
+ target: ts.ScriptTarget.ES2020,
24
+ },
25
+ fileName: configPath,
26
+ });
27
+ const tempFile = path.join(
28
+ path.dirname(configPath),
29
+ `.auklet.config.${process.pid}.${Date.now()}.mjs`,
30
+ );
31
+ fs.writeFileSync(tempFile, output.outputText);
32
+ try {
33
+ return await import(pathToFileURL(tempFile).href);
34
+ } finally {
35
+ fs.rmSync(tempFile, { force: true });
36
+ }
37
+ };
38
+ const isUnknownTsExtensionError = (error) => {
39
+ return (
40
+ error instanceof TypeError &&
41
+ 'code' in error &&
42
+ error.code === 'ERR_UNKNOWN_FILE_EXTENSION'
43
+ );
44
+ };
45
+ const asRecord = (value) => {
46
+ if (!value || typeof value !== 'object' || Array.isArray(value)) {
47
+ return null;
48
+ }
49
+ return value;
50
+ };
51
+ export function resolveAukletConfigModule(module) {
52
+ const candidates = [
53
+ module,
54
+ asRecord(module.default),
55
+ asRecord(module['module.exports']),
56
+ ];
57
+ for (const candidate of candidates) {
58
+ if (!candidate) continue;
59
+ const config = asRecord(candidate.config);
60
+ if (config) {
61
+ return config;
62
+ }
63
+ }
64
+ return {};
65
+ }
66
+ export async function loadAukletConfig(packageRoot, options = {}) {
67
+ var _a;
68
+ const configPath = path.join(
69
+ packageRoot,
70
+ (_a = options.configFile) !== null && _a !== void 0 ? _a : aukletConfigFile,
71
+ );
72
+ if (!fs.existsSync(configPath)) {
73
+ return {};
74
+ }
75
+ const url = pathToFileURL(configPath);
76
+ if (options.cacheBust) {
77
+ url.searchParams.set('t', Date.now().toString());
78
+ }
79
+ if (configPath.endsWith('.ts')) {
80
+ const module = await importTsOptionsModule(url.href);
81
+ return resolveAukletConfigModule(module);
82
+ }
83
+ const module = await importAukletConfigModule(configPath, url.href);
84
+ return resolveAukletConfigModule(module);
85
+ }
@@ -0,0 +1,2 @@
1
+ import type { ModuleCssBuildConfig } from '#auklet/types';
2
+ export declare const moduleCssBuildConfig: ModuleCssBuildConfig;
@@ -0,0 +1,11 @@
1
+ const CSS_EXTENSION = '.css';
2
+ export const moduleCssBuildConfig = {
3
+ output: {
4
+ styleDir: 'style',
5
+ indexCssFile: 'index.css',
6
+ moduleCssFile: 'module.css',
7
+ externalCssFile: 'external.css',
8
+ outputFormats: ['es', 'lib'],
9
+ },
10
+ styleExtensions: [CSS_EXTENSION],
11
+ };
@@ -0,0 +1,3 @@
1
+ export declare const IMPORT_AT_RULE = 'import';
2
+ export declare const LINE_SEPARATOR = '\n';
3
+ export declare const RELATIVE_IMPORT_PREFIX = '.';
@@ -0,0 +1,3 @@
1
+ export const IMPORT_AT_RULE = 'import';
2
+ export const LINE_SEPARATOR = '\n';
3
+ export const RELATIVE_IMPORT_PREFIX = '.';
@@ -0,0 +1,51 @@
1
+ import type { AukletConfig, ModuleCssBuildConfig } from '#auklet/types';
2
+ export interface ModuleCssGraphOptions {
3
+ workspaceRoot: string;
4
+ packagesDir?: string;
5
+ config?: ModuleCssBuildConfig;
6
+ loadAukletConfig?: (
7
+ packageRoot: string,
8
+ options?: {
9
+ cacheBust?: boolean;
10
+ },
11
+ ) => Promise<AukletConfig>;
12
+ }
13
+ export type PackageCssId = {
14
+ packageName: string;
15
+ cssPath: string;
16
+ };
17
+ export type PackageCssLoadResult = {
18
+ code: string;
19
+ watchFiles: Array<string>;
20
+ };
21
+ export declare class ModuleCssGraph {
22
+ private readonly config;
23
+ private readonly workspaceRoot;
24
+ private readonly packagesDir;
25
+ private readonly loadAukletConfig;
26
+ constructor(options: ModuleCssGraphOptions);
27
+ parsePackageCssId(id: string): PackageCssId | null;
28
+ isWorkspaceSourceGraphFile(file: string): boolean;
29
+ isCssConfigFile(file: string): boolean;
30
+ isStyleFile(file: string): boolean;
31
+ getWorkspacePackageNames(): string[];
32
+ getWatchRoots(): string[];
33
+ createPackageCssCode(parsed: PackageCssId): Promise<PackageCssLoadResult>;
34
+ private createContext;
35
+ private createStyleCssCode;
36
+ private createStyleDependencyCssCode;
37
+ private createExternalCssCode;
38
+ private createThemeCssCode;
39
+ private getThemeStyleFiles;
40
+ private createModuleCssCode;
41
+ private createSourceModuleCssCode;
42
+ private getStyleFiles;
43
+ private toDevModuleImportSpecifier;
44
+ private toDevExternalStyleSpecifier;
45
+ private isWorkspacePackageName;
46
+ private getWorkspacePackages;
47
+ }
48
+ export declare function parsePackageCssId(
49
+ id: string,
50
+ packageNames: Array<string>,
51
+ ): PackageCssId | null;
@@ -0,0 +1,416 @@
1
+ import fs from 'node:fs';
2
+ import path from 'node:path';
3
+ import { aukletConfigFile, aukletDefaultCssOptions } 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 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 this.config.styleExtensions.includes(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
129
+ ? _a
130
+ : aukletDefaultCssOptions.sourceDir,
131
+ outputDir:
132
+ (_b = cssOptions.outputDir) !== null && _b !== void 0
133
+ ? _b
134
+ : aukletDefaultCssOptions.outputDir,
135
+ };
136
+ const sourceRoot = path.join(packageRoot, context.sourceDir);
137
+ const resolver = new WorkspaceStyleResolver(this.config, context);
138
+ const styleProcessor = new StyleProcessor(this.config, resolver);
139
+ return {
140
+ cssOptions,
141
+ context,
142
+ packageName: parsed.packageName,
143
+ configPath: path.join(packageRoot, aukletConfigFile),
144
+ resolver,
145
+ sourceRoot,
146
+ styleProcessor,
147
+ };
148
+ }
149
+ async createStyleCssCode(context) {
150
+ const dependencies = await this.createStyleDependencyCssCode(context);
151
+ const themes = await this.createThemeCssCode(context, undefined, false);
152
+ const module = this.createModuleCssCode(context);
153
+ return mergeLoadResults(dependencies, themes, module);
154
+ }
155
+ async createStyleDependencyCssCode(context) {
156
+ const results = [];
157
+ const imports = [];
158
+ for (const specifier of getGlobalStyleDependencies(context.cssOptions)) {
159
+ const parsed = this.parsePackageCssId(specifier);
160
+ if (parsed) {
161
+ results.push(await this.createPackageCssCode(parsed));
162
+ continue;
163
+ }
164
+ imports.push(specifier);
165
+ }
166
+ return mergeLoadResults(
167
+ {
168
+ code: createImportCode(imports),
169
+ watchFiles: [context.configPath],
170
+ },
171
+ ...results,
172
+ );
173
+ }
174
+ async createExternalCssCode(context) {
175
+ const results = [];
176
+ const imports = [];
177
+ for (const specifier of getExternalStyleDependencies(context.cssOptions)) {
178
+ const external = this.toDevExternalStyleSpecifier(specifier);
179
+ const parsed = this.parsePackageCssId(external);
180
+ if (parsed) {
181
+ results.push(await this.createPackageCssCode(parsed));
182
+ continue;
183
+ }
184
+ imports.push(external);
185
+ }
186
+ return mergeLoadResults(
187
+ {
188
+ code: createImportCode(imports),
189
+ watchFiles: [context.configPath],
190
+ },
191
+ ...results,
192
+ );
193
+ }
194
+ async createThemeCssCode(context, cssPath, includeDependencies = true) {
195
+ var _a;
196
+ const themeFiles = this.getThemeStyleFiles(context);
197
+ const targetThemeName = cssPath
198
+ ? removeCssExtension(cssPath.slice(THEMES_ENTRY_PREFIX.length))
199
+ : null;
200
+ const root = context.styleProcessor.createRoot();
201
+ const watchFiles = [context.configPath, ...themeFiles.values()];
202
+ const dependencyResults = [];
203
+ const imports = [];
204
+ for (const [themeName, themeFile] of themeFiles) {
205
+ if (targetThemeName && themeName !== targetThemeName) continue;
206
+ if (includeDependencies) {
207
+ for (const specifier of getThemeStyleDependencies(
208
+ context.cssOptions,
209
+ themeName,
210
+ )) {
211
+ const parsed = this.parsePackageCssId(specifier);
212
+ if (!parsed) {
213
+ imports.push(specifier);
214
+ continue;
215
+ }
216
+ dependencyResults.push(await this.createPackageCssCode(parsed));
217
+ }
218
+ }
219
+ const content = context.styleProcessor.readStyleFile(themeFile);
220
+ if (content.trim()) {
221
+ context.styleProcessor.appendStyleContent(root, content, themeFile);
222
+ }
223
+ }
224
+ return mergeLoadResults(
225
+ {
226
+ code: createImportCode(imports),
227
+ watchFiles,
228
+ },
229
+ ...dependencyResults,
230
+ {
231
+ code: ((_a = root.nodes) === null || _a === void 0 ? void 0 : _a.length)
232
+ ? context.styleProcessor.stringify(root)
233
+ : '',
234
+ watchFiles: [],
235
+ },
236
+ );
237
+ }
238
+ getThemeStyleFiles(context) {
239
+ return resolveThemeStyleFiles(
240
+ context.cssOptions,
241
+ context.context.packageRoot,
242
+ );
243
+ }
244
+ createModuleCssCode(context) {
245
+ var _a;
246
+ const themeFiles = this.getThemeStyleFiles(context);
247
+ const themeFileKeys = createStyleFileKeySet(themeFiles.values());
248
+ const styleFiles = this.getStyleFiles(context.sourceRoot).filter(
249
+ (styleFile) => !themeFileKeys.has(createStyleFileKey(styleFile)),
250
+ );
251
+ const root = context.styleProcessor.createRoot();
252
+ const seen = new Set();
253
+ for (const styleFile of styleFiles) {
254
+ const content = context.styleProcessor.readStyleFile(styleFile, seen);
255
+ if (content.trim()) {
256
+ context.styleProcessor.appendStyleContent(root, content, styleFile);
257
+ }
258
+ }
259
+ return {
260
+ code: ((_a = root.nodes) === null || _a === void 0 ? void 0 : _a.length)
261
+ ? context.styleProcessor.stringify(root)
262
+ : '',
263
+ watchFiles: [context.configPath, ...styleFiles],
264
+ };
265
+ }
266
+ async createSourceModuleCssCode(context, cssPath) {
267
+ var _a, _b, _c;
268
+ const sourceModuleDir = removeCssExtension(cssPath);
269
+ const themeFiles = this.getThemeStyleFiles(context);
270
+ const themeFileKeys = createStyleFileKeySet(themeFiles.values());
271
+ const styleFiles = this.getStyleFiles(context.sourceRoot).filter(
272
+ (styleFile) => !themeFileKeys.has(createStyleFileKey(styleFile)),
273
+ );
274
+ const styleFilesByDir = groupStyleFilesByDir(
275
+ context.sourceRoot,
276
+ styleFiles,
277
+ );
278
+ const importedStyleFiles =
279
+ context.styleProcessor.collectImportedStyleFiles(styleFiles);
280
+ const importCollector = new ModuleStyleImportCollector(
281
+ context.sourceRoot,
282
+ context.context.packageRoot,
283
+ context.resolver,
284
+ this.config.styleExtensions,
285
+ );
286
+ const sourceFiles = fileWalker(context.sourceRoot);
287
+ const moduleStyleImports = importCollector.collect(
288
+ sourceFiles,
289
+ context.cssOptions,
290
+ );
291
+ const sourceStyleDir = path.join(
292
+ context.sourceRoot,
293
+ sourceModuleDir,
294
+ this.config.output.styleDir,
295
+ );
296
+ const moduleStyleResults = [];
297
+ const moduleStyleSpecifiers = [];
298
+ for (const specifier of (_a = moduleStyleImports.get(sourceModuleDir)) !==
299
+ null && _a !== void 0
300
+ ? _a
301
+ : []) {
302
+ const result = this.toDevModuleImportSpecifier(
303
+ context,
304
+ sourceStyleDir,
305
+ specifier,
306
+ );
307
+ const parsed = this.parsePackageCssId(result);
308
+ if (parsed) {
309
+ moduleStyleResults.push(await this.createPackageCssCode(parsed));
310
+ continue;
311
+ }
312
+ moduleStyleSpecifiers.push(result);
313
+ }
314
+ const ownStyleFiles = (
315
+ (_b = styleFilesByDir.get(sourceModuleDir)) !== null && _b !== void 0
316
+ ? _b
317
+ : []
318
+ ).filter((styleFile) => !importedStyleFiles.has(path.resolve(styleFile)));
319
+ const root = context.styleProcessor.createRoot();
320
+ const seen = new Set();
321
+ for (const ownStyleFile of ownStyleFiles) {
322
+ const content = context.styleProcessor.readStyleFile(ownStyleFile, seen);
323
+ if (content.trim()) {
324
+ context.styleProcessor.appendStyleContent(root, content, ownStyleFile);
325
+ }
326
+ }
327
+ const ownStyleCode = (
328
+ (_c = root.nodes) === null || _c === void 0 ? void 0 : _c.length
329
+ )
330
+ ? context.styleProcessor.stringify(root)
331
+ : '';
332
+ return mergeLoadResults(...moduleStyleResults, {
333
+ code: [createImportCode(moduleStyleSpecifiers), ownStyleCode]
334
+ .filter((code) => code.trim())
335
+ .join('\n'),
336
+ watchFiles: [
337
+ context.configPath,
338
+ ...styleFiles,
339
+ ...sourceFiles.filter((file) => /\.(ts|tsx)$/.test(file)),
340
+ ],
341
+ });
342
+ }
343
+ getStyleFiles(sourceRoot) {
344
+ if (!fs.existsSync(sourceRoot)) return [];
345
+ return fileWalker(sourceRoot).filter((file) =>
346
+ this.config.styleExtensions.includes(path.extname(file)),
347
+ );
348
+ }
349
+ toDevModuleImportSpecifier(context, sourceStyleDir, specifier) {
350
+ if (!specifier.startsWith('.')) {
351
+ return this.toDevExternalStyleSpecifier(specifier);
352
+ }
353
+ const outputStyleEntry = path.resolve(sourceStyleDir, specifier);
354
+ const styleEntrySuffix = `${path.sep}${this.config.output.styleDir}${path.sep}${this.config.output.indexCssFile}`;
355
+ if (!outputStyleEntry.endsWith(styleEntrySuffix)) {
356
+ return toCssFsSpecifier(outputStyleEntry);
357
+ }
358
+ const sourceModuleDir = path.relative(
359
+ context.sourceRoot,
360
+ outputStyleEntry.slice(0, -styleEntrySuffix.length),
361
+ );
362
+ return `${context.packageName}/${toPosixPath(sourceModuleDir)}.css`;
363
+ }
364
+ toDevExternalStyleSpecifier(specifier) {
365
+ const parsed = parsePackageStyleSpecifier(specifier);
366
+ if (!parsed) return specifier;
367
+ if (this.isWorkspacePackageName(parsed.packageName)) {
368
+ if (parsed.stylePath === STYLE_ENTRY) {
369
+ return `${parsed.packageName}/${EXTERNAL_ENTRY}`;
370
+ }
371
+ if (
372
+ parsed.stylePath ===
373
+ [this.config.output.styleDir, this.config.output.indexCssFile].join('/')
374
+ ) {
375
+ return `${parsed.packageName}/${EXTERNAL_ENTRY}`;
376
+ }
377
+ }
378
+ return specifier;
379
+ }
380
+ isWorkspacePackageName(packageName) {
381
+ return this.getWorkspacePackageNames().includes(packageName);
382
+ }
383
+ getWorkspacePackages() {
384
+ const packagesRoot = path.join(this.workspaceRoot, this.packagesDir);
385
+ if (!fs.existsSync(packagesRoot)) return [];
386
+ return fs
387
+ .readdirSync(packagesRoot, { withFileTypes: true })
388
+ .filter((entry) => entry.isDirectory())
389
+ .flatMap((entry) => {
390
+ const packageRoot = path.join(packagesRoot, entry.name);
391
+ const packageJsonPath = path.join(packageRoot, 'package.json');
392
+ if (!fs.existsSync(packageJsonPath)) return [];
393
+ const pkg = JSON.parse(fs.readFileSync(packageJsonPath, 'utf8'));
394
+ if (!pkg.name) return [];
395
+ return [
396
+ {
397
+ packageName: pkg.name,
398
+ packageRoot,
399
+ },
400
+ ];
401
+ });
402
+ }
403
+ }
404
+ export function parsePackageCssId(id, packageNames) {
405
+ if (!id.endsWith('.css')) {
406
+ return null;
407
+ }
408
+ const packageName = [...packageNames]
409
+ .sort((left, right) => right.length - left.length)
410
+ .find((name) => id.startsWith(`${name}/`));
411
+ if (!packageName) return null;
412
+ return {
413
+ packageName,
414
+ cssPath: id.slice(packageName.length + 1),
415
+ };
416
+ }
@@ -0,0 +1,29 @@
1
+ import type { CssOptions } from '#auklet/types';
2
+ import type { WorkspaceStyleResolver } from '#auklet/css/core/workspaceStyleResolver';
3
+ export declare class ModuleStyleImportCollector {
4
+ private readonly srcRoot;
5
+ private readonly packageRoot;
6
+ private readonly resolver;
7
+ private readonly styleExtensions;
8
+ private readonly sourceImportAliasRules;
9
+ constructor(
10
+ srcRoot: string,
11
+ packageRoot: string,
12
+ resolver: WorkspaceStyleResolver,
13
+ styleExtensions?: Array<string>,
14
+ );
15
+ collect(files: Array<string>, cssOptions: CssOptions): Map<string, string[]>;
16
+ private getImportDeclarations;
17
+ private collectSourceImportStyle;
18
+ private resolveSourceImportStyleEntry;
19
+ private resolveSourceImportPath;
20
+ private createSourceImportAliasRules;
21
+ private toRelativeSpecifier;
22
+ private createAutoImportRules;
23
+ private matchAutoImportRules;
24
+ private getImportPathValues;
25
+ private createStyleSpecifier;
26
+ private createDirectStyleSpecifier;
27
+ private joinDependencySpecifier;
28
+ private getImportedNames;
29
+ }