auklet 0.0.3 → 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 +38 -6
- package/dist/config.js +43 -7
- 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 +18 -35
- 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 +15 -12
- package/dist/index.js +6 -5
- package/dist/types.d.ts +40 -20
- package/dist/utils.d.ts +5 -1
- package/dist/utils.js +37 -12
- package/package.json +19 -14
- package/dist/css/core/config.d.ts +0 -2
- package/dist/css/core/config.js +0 -11
- 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 -416
- 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 -445
- package/dist/css/watch/moduleCssWatcher.js +0 -106
|
@@ -2,6 +2,7 @@ import fs from 'node:fs';
|
|
|
2
2
|
import path from 'node:path';
|
|
3
3
|
import ts from 'typescript';
|
|
4
4
|
import { isArray } from 'aidly';
|
|
5
|
+
import { joinDependencySpecifier } from '#auklet/css/core/style/specifier';
|
|
5
6
|
import {
|
|
6
7
|
appendUniqueMapValue,
|
|
7
8
|
getSourceModuleDir,
|
|
@@ -11,6 +12,11 @@ import {
|
|
|
11
12
|
} from '#auklet/utils';
|
|
12
13
|
const GLOBSTAR_TOKEN = '**';
|
|
13
14
|
export class ModuleStyleImportCollector {
|
|
15
|
+
srcRoot;
|
|
16
|
+
packageRoot;
|
|
17
|
+
resolver;
|
|
18
|
+
styleExtensions;
|
|
19
|
+
sourceImportAliasRules;
|
|
14
20
|
constructor(srcRoot, packageRoot, resolver, styleExtensions = ['.css']) {
|
|
15
21
|
this.srcRoot = srcRoot;
|
|
16
22
|
this.packageRoot = packageRoot;
|
|
@@ -18,9 +24,9 @@ export class ModuleStyleImportCollector {
|
|
|
18
24
|
this.styleExtensions = styleExtensions;
|
|
19
25
|
this.sourceImportAliasRules = this.createSourceImportAliasRules();
|
|
20
26
|
}
|
|
21
|
-
collect(files,
|
|
27
|
+
collect(files, config) {
|
|
22
28
|
const entries = new Map();
|
|
23
|
-
const rules = this.createAutoImportRules(
|
|
29
|
+
const rules = this.createAutoImportRules(config);
|
|
24
30
|
for (const file of files) {
|
|
25
31
|
if (!SOURCE_MODULE_RE.test(file) || SOURCE_DECLARATION_RE.test(file)) {
|
|
26
32
|
continue;
|
|
@@ -40,11 +46,13 @@ export class ModuleStyleImportCollector {
|
|
|
40
46
|
const importPath = item.importPath;
|
|
41
47
|
const ruleMatches = this.matchAutoImportRules(rules, importPath);
|
|
42
48
|
if (!ruleMatches.length) continue;
|
|
43
|
-
const directSpecifiers = ruleMatches
|
|
44
|
-
.
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
49
|
+
const directSpecifiers = ruleMatches.flatMap((ruleMatch) => {
|
|
50
|
+
const specifier = this.createDirectStyleSpecifier(
|
|
51
|
+
ruleMatch.rule,
|
|
52
|
+
importPath,
|
|
53
|
+
);
|
|
54
|
+
return specifier ? [specifier] : [];
|
|
55
|
+
});
|
|
48
56
|
if (directSpecifiers.length) {
|
|
49
57
|
for (const specifier of directSpecifiers) {
|
|
50
58
|
const cssFile = this.resolver.resolveStyleDependency(specifier);
|
|
@@ -97,13 +105,7 @@ export class ModuleStyleImportCollector {
|
|
|
97
105
|
return imports;
|
|
98
106
|
}
|
|
99
107
|
collectSourceImportStyle(entries, sourceDir, sourceModuleDir, item) {
|
|
100
|
-
|
|
101
|
-
if (
|
|
102
|
-
(_a = item.importClause) === null || _a === void 0
|
|
103
|
-
? void 0
|
|
104
|
-
: _a.isTypeOnly
|
|
105
|
-
)
|
|
106
|
-
return;
|
|
108
|
+
if (item.importClause?.isTypeOnly) return;
|
|
107
109
|
const importedStyleEntry = this.resolveSourceImportStyleEntry(
|
|
108
110
|
sourceDir,
|
|
109
111
|
item.importPath,
|
|
@@ -145,14 +147,11 @@ export class ModuleStyleImportCollector {
|
|
|
145
147
|
return null;
|
|
146
148
|
}
|
|
147
149
|
createSourceImportAliasRules() {
|
|
148
|
-
var _a;
|
|
149
150
|
const packageJsonPath = path.join(this.packageRoot, 'package.json');
|
|
150
151
|
if (!fs.existsSync(packageJsonPath)) return [];
|
|
151
152
|
const packageJson = JSON.parse(fs.readFileSync(packageJsonPath, 'utf8'));
|
|
152
153
|
const rules = [];
|
|
153
|
-
for (const [name, target] of Object.entries(
|
|
154
|
-
(_a = packageJson.imports) !== null && _a !== void 0 ? _a : {},
|
|
155
|
-
)) {
|
|
154
|
+
for (const [name, target] of Object.entries(packageJson.imports ?? {})) {
|
|
156
155
|
if (
|
|
157
156
|
!name.endsWith(`${POSIX_SEPARATOR}*`) ||
|
|
158
157
|
typeof target !== 'string' ||
|
|
@@ -170,22 +169,20 @@ export class ModuleStyleImportCollector {
|
|
|
170
169
|
const relative = path.relative(fromDir, file).split(path.sep).join('/');
|
|
171
170
|
return relative.startsWith('.') ? relative : `./${relative}`;
|
|
172
171
|
}
|
|
173
|
-
createAutoImportRules(
|
|
174
|
-
var _a;
|
|
172
|
+
createAutoImportRules(config) {
|
|
175
173
|
const rules = [];
|
|
176
174
|
for (const [packageName, dependency] of Object.entries(
|
|
177
|
-
|
|
175
|
+
config.styles.dependencies,
|
|
178
176
|
)) {
|
|
179
|
-
const dependencyPaths = isArray(dependency.
|
|
180
|
-
? dependency.
|
|
181
|
-
:
|
|
177
|
+
const dependencyPaths = isArray(dependency.components)
|
|
178
|
+
? dependency.components
|
|
179
|
+
: dependency.components
|
|
180
|
+
? [dependency.components]
|
|
181
|
+
: [];
|
|
182
182
|
for (const dependencyPath of dependencyPaths) {
|
|
183
183
|
rules.push({
|
|
184
184
|
packageName,
|
|
185
|
-
outputPattern:
|
|
186
|
-
packageName,
|
|
187
|
-
dependencyPath,
|
|
188
|
-
),
|
|
185
|
+
outputPattern: joinDependencySpecifier(packageName, dependencyPath),
|
|
189
186
|
});
|
|
190
187
|
}
|
|
191
188
|
}
|
|
@@ -220,9 +217,7 @@ export class ModuleStyleImportCollector {
|
|
|
220
217
|
const matchedValue = pathValues.shift();
|
|
221
218
|
if (matchedValue) return matchedValue;
|
|
222
219
|
if (token === GLOBSTAR_TOKEN) return importedName;
|
|
223
|
-
return matchedValue
|
|
224
|
-
? matchedValue
|
|
225
|
-
: importedName;
|
|
220
|
+
return matchedValue ?? importedName;
|
|
226
221
|
});
|
|
227
222
|
}
|
|
228
223
|
createDirectStyleSpecifier(rule, importPath) {
|
|
@@ -243,15 +238,7 @@ export class ModuleStyleImportCollector {
|
|
|
243
238
|
}
|
|
244
239
|
return `${importPath}${suffix}`;
|
|
245
240
|
}
|
|
246
|
-
joinDependencySpecifier(packageName, dependencyPath) {
|
|
247
|
-
if (!dependencyPath) return packageName;
|
|
248
|
-
if (dependencyPath.startsWith(POSIX_SEPARATOR)) {
|
|
249
|
-
return `${packageName}${dependencyPath}`;
|
|
250
|
-
}
|
|
251
|
-
return `${packageName}${POSIX_SEPARATOR}${dependencyPath}`;
|
|
252
|
-
}
|
|
253
241
|
getImportedNames(file, item) {
|
|
254
|
-
var _a;
|
|
255
242
|
const importClause = item.importClause;
|
|
256
243
|
if (!importClause || importClause.isTypeOnly) {
|
|
257
244
|
return [];
|
|
@@ -273,12 +260,7 @@ export class ModuleStyleImportCollector {
|
|
|
273
260
|
}
|
|
274
261
|
for (const element of namedBindings.elements) {
|
|
275
262
|
if (element.isTypeOnly) continue;
|
|
276
|
-
names.push(
|
|
277
|
-
((_a = element.propertyName) !== null && _a !== void 0
|
|
278
|
-
? _a
|
|
279
|
-
: element.name
|
|
280
|
-
).text,
|
|
281
|
-
);
|
|
263
|
+
names.push((element.propertyName ?? element.name).text);
|
|
282
264
|
}
|
|
283
265
|
return names;
|
|
284
266
|
}
|
|
@@ -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 {};
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import {
|
|
2
|
+
getExternalStyleDependencies,
|
|
3
|
+
getGlobalStyleDependencies,
|
|
4
|
+
getThemeNames,
|
|
5
|
+
getThemeStyleDependencies,
|
|
6
|
+
} from '#auklet/css/core/style/dependencies';
|
|
7
|
+
const dependenciesPart = (specifiers) => ({ type: 'dependencies', specifiers });
|
|
8
|
+
export function createStyleEntryParts(config) {
|
|
9
|
+
return [
|
|
10
|
+
dependenciesPart(getGlobalStyleDependencies(config)),
|
|
11
|
+
{ type: 'themes', themeNames: getThemeNames(config) },
|
|
12
|
+
{ type: 'module' },
|
|
13
|
+
];
|
|
14
|
+
}
|
|
15
|
+
export function createThemeEntryParts(config, themeName, options = {}) {
|
|
16
|
+
const themePart = { type: 'theme', themeName };
|
|
17
|
+
if (options.includeDependencies === false) {
|
|
18
|
+
return [themePart];
|
|
19
|
+
}
|
|
20
|
+
return [
|
|
21
|
+
dependenciesPart(getThemeStyleDependencies(config, themeName)),
|
|
22
|
+
themePart,
|
|
23
|
+
];
|
|
24
|
+
}
|
|
25
|
+
export function createExternalEntryParts(config) {
|
|
26
|
+
return [dependenciesPart(getExternalStyleDependencies(config))];
|
|
27
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
export type PackageStyleSpecifier = {
|
|
2
|
+
packageName: string;
|
|
3
|
+
stylePath: string;
|
|
4
|
+
};
|
|
5
|
+
export declare function parsePackageStyleSpecifier(specifier: string): {
|
|
6
|
+
packageName: string;
|
|
7
|
+
stylePath: string;
|
|
8
|
+
} | null;
|
|
9
|
+
export declare function joinDependencySpecifier(
|
|
10
|
+
packageName: string,
|
|
11
|
+
dependencyPath: string,
|
|
12
|
+
): string;
|
|
13
|
+
export declare function createImportCode(specifiers: Array<string>): string;
|
|
14
|
+
export declare function removeStyleExtension(stylePath: string): string;
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import path from 'node:path';
|
|
2
|
+
export function parsePackageStyleSpecifier(specifier) {
|
|
3
|
+
if (specifier.startsWith('.')) return null;
|
|
4
|
+
const parts = specifier.split('/');
|
|
5
|
+
const packageName = specifier.startsWith('@')
|
|
6
|
+
? `${parts.shift() ?? ''}/${parts.shift() ?? ''}`
|
|
7
|
+
: parts.shift() ?? '';
|
|
8
|
+
if (!packageName) return null;
|
|
9
|
+
return {
|
|
10
|
+
packageName,
|
|
11
|
+
stylePath: parts.join('/'),
|
|
12
|
+
};
|
|
13
|
+
}
|
|
14
|
+
export function joinDependencySpecifier(packageName, dependencyPath) {
|
|
15
|
+
if (!dependencyPath) return packageName;
|
|
16
|
+
return dependencyPath.startsWith('/')
|
|
17
|
+
? `${packageName}${dependencyPath}`
|
|
18
|
+
: `${packageName}/${dependencyPath}`;
|
|
19
|
+
}
|
|
20
|
+
export function createImportCode(specifiers) {
|
|
21
|
+
return Array.from(new Set(specifiers))
|
|
22
|
+
.map((specifier) => `@import "${specifier}";`)
|
|
23
|
+
.join('\n');
|
|
24
|
+
}
|
|
25
|
+
export function removeStyleExtension(stylePath) {
|
|
26
|
+
return stylePath.slice(0, -path.extname(stylePath).length);
|
|
27
|
+
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import type { StylePackageContext } from '#auklet/css/core/stylePackageContext';
|
|
2
|
+
export type ModuleStyleEntryPlan = {
|
|
3
|
+
sourceDir: string;
|
|
4
|
+
moduleStyleImports: Array<string>;
|
|
5
|
+
ownStyleFiles: Array<string>;
|
|
6
|
+
};
|
|
7
|
+
export declare class StyleModuleEntryPlanner {
|
|
8
|
+
private readonly packageContext;
|
|
9
|
+
private readonly styleFilesByDir;
|
|
10
|
+
private readonly importedStyleFiles;
|
|
11
|
+
constructor(packageContext: StylePackageContext);
|
|
12
|
+
createEntries(moduleStyleImports: Map<string, Array<string>>): {
|
|
13
|
+
sourceDir: string;
|
|
14
|
+
moduleStyleImports: string[];
|
|
15
|
+
ownStyleFiles: string[];
|
|
16
|
+
}[];
|
|
17
|
+
createEntry(
|
|
18
|
+
sourceDir: string,
|
|
19
|
+
moduleStyleImports: Map<string, Array<string>>,
|
|
20
|
+
): {
|
|
21
|
+
sourceDir: string;
|
|
22
|
+
moduleStyleImports: string[];
|
|
23
|
+
ownStyleFiles: string[];
|
|
24
|
+
};
|
|
25
|
+
private getSourceDirs;
|
|
26
|
+
private getSourceModuleDirs;
|
|
27
|
+
private getOwnStyleDirs;
|
|
28
|
+
private getOwnStyleFiles;
|
|
29
|
+
}
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import path from 'node:path';
|
|
2
|
+
import { groupStyleFilesByDir } from '#auklet/css/core/style/files';
|
|
3
|
+
import { getSourceModuleDir, toPosixPath } from '#auklet/utils';
|
|
4
|
+
export class StyleModuleEntryPlanner {
|
|
5
|
+
packageContext;
|
|
6
|
+
styleFilesByDir;
|
|
7
|
+
importedStyleFiles;
|
|
8
|
+
constructor(packageContext) {
|
|
9
|
+
this.packageContext = packageContext;
|
|
10
|
+
this.styleFilesByDir = groupStyleFilesByDir(
|
|
11
|
+
this.packageContext.sourceRoot,
|
|
12
|
+
this.packageContext.styleFiles,
|
|
13
|
+
);
|
|
14
|
+
this.importedStyleFiles =
|
|
15
|
+
this.packageContext.styleProcessor.collectImportedStyleFiles(
|
|
16
|
+
this.packageContext.styleFiles,
|
|
17
|
+
);
|
|
18
|
+
}
|
|
19
|
+
createEntries(moduleStyleImports) {
|
|
20
|
+
return this.getSourceDirs(moduleStyleImports).map((sourceDir) =>
|
|
21
|
+
this.createEntry(sourceDir, moduleStyleImports),
|
|
22
|
+
);
|
|
23
|
+
}
|
|
24
|
+
createEntry(sourceDir, moduleStyleImports) {
|
|
25
|
+
return {
|
|
26
|
+
sourceDir,
|
|
27
|
+
moduleStyleImports: moduleStyleImports.get(sourceDir) ?? [],
|
|
28
|
+
ownStyleFiles: this.getOwnStyleFiles(sourceDir),
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
getSourceDirs(moduleStyleImports) {
|
|
32
|
+
return Array.from(
|
|
33
|
+
new Set([
|
|
34
|
+
...this.getSourceModuleDirs(),
|
|
35
|
+
...this.getOwnStyleDirs(),
|
|
36
|
+
...moduleStyleImports.keys(),
|
|
37
|
+
]),
|
|
38
|
+
).filter((sourceDir) => sourceDir !== '.');
|
|
39
|
+
}
|
|
40
|
+
getSourceModuleDirs() {
|
|
41
|
+
return this.packageContext.sourceFiles
|
|
42
|
+
.filter((sourceFile) => sourceFile.endsWith('.tsx'))
|
|
43
|
+
.map((sourceFile) => {
|
|
44
|
+
return getSourceModuleDir(
|
|
45
|
+
path.relative(this.packageContext.sourceRoot, sourceFile),
|
|
46
|
+
);
|
|
47
|
+
})
|
|
48
|
+
.filter((sourceModuleDir) => {
|
|
49
|
+
return toPosixPath(sourceModuleDir).split('/').length === 2;
|
|
50
|
+
});
|
|
51
|
+
}
|
|
52
|
+
getOwnStyleDirs() {
|
|
53
|
+
return Array.from(this.styleFilesByDir.entries())
|
|
54
|
+
.filter(([, dirStyleFiles]) =>
|
|
55
|
+
dirStyleFiles.some(
|
|
56
|
+
(styleFile) => !this.importedStyleFiles.has(path.resolve(styleFile)),
|
|
57
|
+
),
|
|
58
|
+
)
|
|
59
|
+
.map(([sourceDir]) => sourceDir);
|
|
60
|
+
}
|
|
61
|
+
getOwnStyleFiles(sourceDir) {
|
|
62
|
+
return (this.styleFilesByDir.get(sourceDir) ?? []).filter(
|
|
63
|
+
(styleFile) => !this.importedStyleFiles.has(path.resolve(styleFile)),
|
|
64
|
+
);
|
|
65
|
+
}
|
|
66
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { ModuleStyleImportCollector } from '#auklet/css/core/moduleStyleImportCollector';
|
|
2
|
+
import { StyleProcessor } from '#auklet/css/core/styleProcessor';
|
|
3
|
+
import { WorkspaceStyleResolver } from '#auklet/css/core/workspaceStyleResolver';
|
|
4
|
+
import type {
|
|
5
|
+
ModuleStyleBuildConfig,
|
|
6
|
+
NormalizedAukletConfig,
|
|
7
|
+
ResolvedModuleStyleBuildContext,
|
|
8
|
+
} from '#auklet/types';
|
|
9
|
+
export type StylePackageContextOptions = {
|
|
10
|
+
config: ModuleStyleBuildConfig;
|
|
11
|
+
context: ResolvedModuleStyleBuildContext;
|
|
12
|
+
normalizedConfig: NormalizedAukletConfig;
|
|
13
|
+
};
|
|
14
|
+
export declare class StylePackageContext {
|
|
15
|
+
private readonly options;
|
|
16
|
+
readonly normalizedConfig: NormalizedAukletConfig;
|
|
17
|
+
readonly sourceRoot: string;
|
|
18
|
+
readonly resolver: WorkspaceStyleResolver;
|
|
19
|
+
readonly styleProcessor: StyleProcessor;
|
|
20
|
+
readonly importCollector: ModuleStyleImportCollector;
|
|
21
|
+
readonly sourceFiles: Array<string>;
|
|
22
|
+
readonly themeFiles: Map<string, string>;
|
|
23
|
+
readonly themeNames: Array<string>;
|
|
24
|
+
readonly styleFiles: Array<string>;
|
|
25
|
+
constructor(options: StylePackageContextOptions);
|
|
26
|
+
getStyleFiles(files: Array<string>): string[];
|
|
27
|
+
}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import fs from 'node:fs';
|
|
2
|
+
import path from 'node:path';
|
|
3
|
+
import { ModuleStyleImportCollector } from '#auklet/css/core/moduleStyleImportCollector';
|
|
4
|
+
import { StyleProcessor } from '#auklet/css/core/styleProcessor';
|
|
5
|
+
import { WorkspaceStyleResolver } from '#auklet/css/core/workspaceStyleResolver';
|
|
6
|
+
import {
|
|
7
|
+
createStyleFileKey,
|
|
8
|
+
createStyleFileKeySet,
|
|
9
|
+
} from '#auklet/css/core/style/files';
|
|
10
|
+
import {
|
|
11
|
+
getThemeNames,
|
|
12
|
+
resolveThemeStyleFiles,
|
|
13
|
+
} from '#auklet/css/core/style/dependencies';
|
|
14
|
+
import { fileWalker } from '#auklet/utils';
|
|
15
|
+
export class StylePackageContext {
|
|
16
|
+
options;
|
|
17
|
+
normalizedConfig;
|
|
18
|
+
sourceRoot;
|
|
19
|
+
resolver;
|
|
20
|
+
styleProcessor;
|
|
21
|
+
importCollector;
|
|
22
|
+
sourceFiles;
|
|
23
|
+
themeFiles;
|
|
24
|
+
themeNames;
|
|
25
|
+
styleFiles;
|
|
26
|
+
constructor(options) {
|
|
27
|
+
this.options = options;
|
|
28
|
+
const { config, context, normalizedConfig } = this.options;
|
|
29
|
+
this.normalizedConfig = normalizedConfig;
|
|
30
|
+
this.sourceRoot = path.join(context.packageRoot, context.sourceDir);
|
|
31
|
+
this.resolver = new WorkspaceStyleResolver(config, context);
|
|
32
|
+
this.styleProcessor = new StyleProcessor(config, this.resolver);
|
|
33
|
+
this.importCollector = new ModuleStyleImportCollector(
|
|
34
|
+
this.sourceRoot,
|
|
35
|
+
context.packageRoot,
|
|
36
|
+
this.resolver,
|
|
37
|
+
config.styleExtensions,
|
|
38
|
+
);
|
|
39
|
+
this.sourceFiles = fs.existsSync(this.sourceRoot)
|
|
40
|
+
? fileWalker(this.sourceRoot)
|
|
41
|
+
: [];
|
|
42
|
+
this.themeFiles = resolveThemeStyleFiles(
|
|
43
|
+
normalizedConfig,
|
|
44
|
+
context.packageRoot,
|
|
45
|
+
);
|
|
46
|
+
this.themeNames = getThemeNames(normalizedConfig);
|
|
47
|
+
this.styleFiles = this.getStyleFiles(this.sourceFiles);
|
|
48
|
+
}
|
|
49
|
+
getStyleFiles(files) {
|
|
50
|
+
const themeFileKeys = createStyleFileKeySet(this.themeFiles.values());
|
|
51
|
+
return files
|
|
52
|
+
.filter((file) =>
|
|
53
|
+
this.options.config.styleExtensions.includes(path.extname(file)),
|
|
54
|
+
)
|
|
55
|
+
.filter((styleFile) => !themeFileKeys.has(createStyleFileKey(styleFile)));
|
|
56
|
+
}
|
|
57
|
+
}
|
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
import postcss, { type Root } from 'postcss';
|
|
2
|
-
import type {
|
|
2
|
+
import type { ModuleStyleBuildConfig } from '#auklet/types';
|
|
3
3
|
import type { WorkspaceStyleResolver } from '#auklet/css/core/workspaceStyleResolver';
|
|
4
4
|
export declare class StyleProcessor {
|
|
5
5
|
private readonly config;
|
|
6
6
|
private readonly resolver;
|
|
7
|
-
constructor(config:
|
|
7
|
+
constructor(config: ModuleStyleBuildConfig, resolver: WorkspaceStyleResolver);
|
|
8
8
|
createRoot(): postcss.Root;
|
|
9
9
|
appendImportRule(root: Root, specifier: string): void;
|
|
10
10
|
stringify(root: Root): string;
|
|
11
11
|
appendStyleContent(target: Root, content: string, from: string): void;
|
|
12
|
-
readStyleFile(
|
|
12
|
+
readStyleFile(stylePath: string, seen?: Set<string>): string;
|
|
13
13
|
collectImportedStyleFiles(styleFiles: Array<string>): Set<string>;
|
|
14
14
|
private parse;
|
|
15
15
|
private parseImportSpecifier;
|