auklet 0.0.16 → 0.0.18
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 +37 -1
- package/dist/build/bundleConfig.d.ts +1 -4
- package/dist/build/bundleConfig.js +59 -71
- package/dist/build/cleanOutput.d.ts +2 -8
- package/dist/build/cleanOutput.js +7 -7
- package/dist/build/moduleConfig.d.ts +1 -3
- package/dist/build/moduleConfig.js +21 -40
- package/dist/build/runTsdown.d.ts +2 -5
- package/dist/build/runTsdown.js +18 -23
- package/dist/build/tsdown/common.d.ts +17 -28
- package/dist/build/tsdown/common.js +22 -25
- package/dist/build/tsdown/context.d.ts +16 -20
- package/dist/build/tsdown/context.js +41 -45
- package/dist/build/tsdown/define.d.ts +2 -7
- package/dist/build/tsdown/define.js +13 -22
- package/dist/build/tsdown/dependencies.d.ts +4 -12
- package/dist/build/tsdown/dependencies.js +47 -51
- package/dist/build/tsdown/entries.d.ts +4 -6
- package/dist/build/tsdown/entries.js +39 -38
- package/dist/build/tsdown/parseModuleId.d.ts +4 -4
- package/dist/build/tsdown/parseModuleId.js +92 -77
- package/dist/build/tsdown/types.d.ts +24 -31
- package/dist/build/tsdownConfig.js +1 -4
- package/dist/config.d.ts +37 -37
- package/dist/config.js +38 -41
- package/dist/configLoader.d.ts +2 -7
- package/dist/configLoader.js +59 -64
- package/dist/css/config.js +8 -8
- package/dist/css/constants.d.ts +7 -7
- package/dist/css/constants.js +1 -1
- package/dist/css/core/resolvers/packageImports.d.ts +1 -5
- package/dist/css/core/resolvers/packageImports.js +35 -40
- package/dist/css/core/resolvers/relative.d.ts +1 -4
- package/dist/css/core/resolvers/relative.js +3 -2
- package/dist/css/core/resolvers/tsconfigPaths.d.ts +1 -5
- package/dist/css/core/resolvers/tsconfigPaths.js +59 -66
- package/dist/css/core/style/dependencies.d.ts +6 -16
- package/dist/css/core/style/dependencies.js +35 -38
- package/dist/css/core/style/entries.d.ts +35 -58
- package/dist/css/core/style/entries.js +22 -33
- package/dist/css/core/style/files.d.ts +2 -7
- package/dist/css/core/style/files.js +11 -11
- package/dist/css/core/style/specifier.d.ts +41 -8
- package/dist/css/core/style/specifier.js +107 -18
- package/dist/css/core/styleImports/autoImportRules.d.ts +13 -0
- package/dist/css/core/styleImports/autoImportRules.js +68 -0
- package/dist/css/core/styleImports/collector.d.ts +12 -25
- package/dist/css/core/styleImports/collector.js +101 -206
- package/dist/css/core/styleImports/sourceImportExportAnalyzer.d.ts +11 -0
- package/dist/css/core/styleImports/sourceImportExportAnalyzer.js +173 -0
- package/dist/css/core/styleModuleEntryPlanner.d.ts +21 -24
- package/dist/css/core/styleModuleEntryPlanner.js +45 -62
- package/dist/css/core/stylePackageContext.d.ts +16 -20
- package/dist/css/core/stylePackageContext.js +33 -49
- package/dist/css/core/styleProcessor.js +105 -104
- package/dist/css/core/workspaceStyleResolver.d.ts +8 -15
- package/dist/css/core/workspaceStyleResolver.js +34 -76
- package/dist/css/production/builder.d.ts +9 -16
- package/dist/css/production/builder.js +51 -57
- package/dist/css/production/format/entryWriter.js +36 -49
- package/dist/css/production/format/externalWriter.js +21 -33
- package/dist/css/production/format/{componentWriter.d.ts → moduleEntryWriter.d.ts} +1 -1
- package/dist/css/production/format/moduleEntryWriter.js +48 -0
- package/dist/css/production/format/moduleWriter.js +23 -26
- package/dist/css/production/format/shared.d.ts +8 -15
- package/dist/css/production/format/shared.js +4 -9
- package/dist/css/production/format/sourceWriter.js +11 -11
- package/dist/css/production/format/themeWriter.js +56 -71
- package/dist/css/production/moduleOutputWriter.d.ts +18 -21
- package/dist/css/production/moduleOutputWriter.js +58 -67
- package/dist/css/production/packageEntryWriter.d.ts +12 -15
- package/dist/css/production/packageEntryWriter.js +42 -45
- package/dist/css/vite/hmr.d.ts +11 -11
- package/dist/css/vite/hmr.js +93 -109
- package/dist/css/vite/moduleGraph/devDependency.d.ts +7 -12
- package/dist/css/vite/moduleGraph/devDependency.js +8 -8
- package/dist/css/vite/moduleGraph/graph.d.ts +20 -23
- package/dist/css/vite/moduleGraph/graph.js +51 -50
- package/dist/css/vite/moduleGraph/loadResult.d.ts +3 -5
- package/dist/css/vite/moduleGraph/loadResult.js +7 -9
- package/dist/css/vite/moduleGraph/packageSource/monorepo.d.ts +16 -7
- package/dist/css/vite/moduleGraph/packageSource/monorepo.js +60 -68
- package/dist/css/vite/moduleGraph/packageSource/singlePackage.d.ts +21 -0
- package/dist/css/vite/moduleGraph/packageSource/singlePackage.js +63 -0
- package/dist/css/vite/moduleGraph/packageSource/types.d.ts +7 -7
- package/dist/css/vite/moduleGraph/requestCache.d.ts +46 -57
- package/dist/css/vite/moduleGraph/requestCache.js +53 -51
- package/dist/css/vite/moduleGraph/styleCodeFactory.d.ts +15 -18
- package/dist/css/vite/moduleGraph/styleCodeFactory.js +173 -264
- package/dist/css/vite/moduleGraph/styleId.d.ts +3 -6
- package/dist/css/vite/moduleGraph/styleId.js +12 -11
- package/dist/css/vite/moduleGraph/types.d.ts +11 -14
- package/dist/css/vite/vitePlugin.d.ts +16 -20
- package/dist/css/vite/vitePlugin.js +117 -109
- package/dist/css/watch/watcher.d.ts +15 -21
- package/dist/css/watch/watcher.js +84 -81
- package/dist/index.d.ts +3 -25
- package/dist/index.js +2 -9
- package/dist/types.d.ts +59 -62
- package/dist/utils.d.ts +3 -7
- package/dist/utils.js +50 -47
- package/package.json +31 -33
- package/dist/css/core/styleImports/sourceReference.d.ts +0 -19
- package/dist/css/core/styleImports/sourceReference.js +0 -193
- package/dist/css/production/format/componentWriter.js +0 -71
|
@@ -2,54 +2,51 @@ import path from 'node:path';
|
|
|
2
2
|
import { isArray } from 'aidly';
|
|
3
3
|
import { joinDependencySpecifier } from '#auklet/css/core/style/specifier';
|
|
4
4
|
export function getGlobalStyleDependencies(config) {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
dependencies.push(joinDependencySpecifier(packageName, globalDependency));
|
|
5
|
+
const dependencies = [];
|
|
6
|
+
for (const [packageName, dependency] of Object.entries(config.styles.dependencies)) {
|
|
7
|
+
const globalDependencies = isArray(dependency.entry)
|
|
8
|
+
? dependency.entry
|
|
9
|
+
: dependency.entry
|
|
10
|
+
? [dependency.entry]
|
|
11
|
+
: [];
|
|
12
|
+
for (const globalDependency of globalDependencies) {
|
|
13
|
+
dependencies.push(joinDependencySpecifier(packageName, globalDependency));
|
|
14
|
+
}
|
|
16
15
|
}
|
|
17
|
-
|
|
18
|
-
return dependencies;
|
|
16
|
+
return dependencies;
|
|
19
17
|
}
|
|
20
18
|
export function getExternalStyleDependencies(config) {
|
|
21
|
-
|
|
19
|
+
return getGlobalStyleDependencies(config);
|
|
22
20
|
}
|
|
23
21
|
export function getThemeStyleDependencies(config, themeName) {
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
return dependencies;
|
|
22
|
+
const dependencies = [];
|
|
23
|
+
for (const [packageName, dependency] of Object.entries(config.styles.dependencies)) {
|
|
24
|
+
const themeDependency = dependency.themes?.[themeName];
|
|
25
|
+
if (!themeDependency)
|
|
26
|
+
continue;
|
|
27
|
+
dependencies.push(joinDependencySpecifier(packageName, themeDependency));
|
|
28
|
+
}
|
|
29
|
+
return dependencies;
|
|
33
30
|
}
|
|
34
31
|
export function getThemeNames(config) {
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
32
|
+
const names = new Set(Object.keys(config.styles.themes));
|
|
33
|
+
for (const dependency of Object.values(config.styles.dependencies)) {
|
|
34
|
+
for (const themeName of Object.keys(dependency.themes ?? {})) {
|
|
35
|
+
names.add(themeName);
|
|
36
|
+
}
|
|
39
37
|
}
|
|
40
|
-
|
|
41
|
-
return [...names];
|
|
38
|
+
return [...names];
|
|
42
39
|
}
|
|
43
40
|
export function getThemeStyleEntries(config) {
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
41
|
+
return Object.entries(config.styles.themes).map(([themeName, file]) => ({
|
|
42
|
+
themeName,
|
|
43
|
+
file,
|
|
44
|
+
}));
|
|
48
45
|
}
|
|
49
46
|
export function resolveThemeStyleFiles(config, packageRoot) {
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
47
|
+
const themeFiles = new Map();
|
|
48
|
+
for (const { themeName, file } of getThemeStyleEntries(config)) {
|
|
49
|
+
themeFiles.set(themeName, path.resolve(packageRoot, file));
|
|
50
|
+
}
|
|
51
|
+
return themeFiles;
|
|
55
52
|
}
|
|
@@ -1,75 +1,52 @@
|
|
|
1
1
|
import type { StylePackageContext } from '#auklet/css/core/stylePackageContext';
|
|
2
2
|
import type { NormalizedAukletConfig } from '#auklet/types';
|
|
3
3
|
type StyleModulePart = {
|
|
4
|
-
|
|
4
|
+
type: 'module';
|
|
5
5
|
};
|
|
6
6
|
type StyleThemesPart = {
|
|
7
|
-
|
|
8
|
-
|
|
7
|
+
type: 'themes';
|
|
8
|
+
themeNames: Array<string>;
|
|
9
9
|
};
|
|
10
10
|
type DependenciesPart = {
|
|
11
|
-
|
|
12
|
-
|
|
11
|
+
type: 'dependencies';
|
|
12
|
+
specifiers: Array<string>;
|
|
13
13
|
};
|
|
14
14
|
type ThemePart = {
|
|
15
|
-
|
|
16
|
-
|
|
15
|
+
type: 'theme';
|
|
16
|
+
themeName: string;
|
|
17
17
|
};
|
|
18
18
|
export type ExternalEntryPart = DependenciesPart;
|
|
19
19
|
export type ThemeEntryPart = DependenciesPart | ThemePart;
|
|
20
|
-
export type StyleEntryPart =
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
}
|
|
33
|
-
| {
|
|
34
|
-
type: 'module';
|
|
35
|
-
themeNames?: undefined;
|
|
36
|
-
}
|
|
37
|
-
)[];
|
|
38
|
-
export declare function createThemeEntryParts(
|
|
39
|
-
config: NormalizedAukletConfig,
|
|
40
|
-
themeName: string,
|
|
41
|
-
options?: {
|
|
20
|
+
export type StyleEntryPart = DependenciesPart | StyleThemesPart | StyleModulePart;
|
|
21
|
+
export declare function createStyleEntryParts(config: NormalizedAukletConfig): ({
|
|
22
|
+
type: "dependencies";
|
|
23
|
+
specifiers: string[];
|
|
24
|
+
} | {
|
|
25
|
+
type: "themes";
|
|
26
|
+
themeNames: string[];
|
|
27
|
+
} | {
|
|
28
|
+
type: "module";
|
|
29
|
+
themeNames?: undefined;
|
|
30
|
+
})[];
|
|
31
|
+
export declare function createThemeEntryParts(config: NormalizedAukletConfig, themeName: string, options?: {
|
|
42
32
|
includeDependencies?: boolean;
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
)[];
|
|
51
|
-
export declare function createExternalEntryParts(
|
|
52
|
-
config: NormalizedAukletConfig,
|
|
53
|
-
): {
|
|
54
|
-
type: 'dependencies';
|
|
55
|
-
specifiers: string[];
|
|
33
|
+
}): (ThemePart | {
|
|
34
|
+
type: "dependencies";
|
|
35
|
+
specifiers: string[];
|
|
36
|
+
})[];
|
|
37
|
+
export declare function createExternalEntryParts(config: NormalizedAukletConfig): {
|
|
38
|
+
type: "dependencies";
|
|
39
|
+
specifiers: string[];
|
|
56
40
|
}[];
|
|
57
|
-
export declare function collectModuleStyleImports(
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
sourceDir: string,
|
|
63
|
-
): {
|
|
64
|
-
sourceDir: string;
|
|
65
|
-
moduleStyleImports: string[];
|
|
66
|
-
ownStyleFiles: string[];
|
|
41
|
+
export declare function collectModuleStyleImports(packageContext: StylePackageContext): Map<string, string[]>;
|
|
42
|
+
export declare function createModuleStyleEntryPlan(packageContext: StylePackageContext, sourceDir: string): {
|
|
43
|
+
sourceDir: string;
|
|
44
|
+
moduleStyleImports: string[];
|
|
45
|
+
ownStyleFiles: string[];
|
|
67
46
|
};
|
|
68
|
-
export declare function
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
moduleStyleImports: string[];
|
|
73
|
-
ownStyleFiles: string[];
|
|
47
|
+
export declare function createModuleStyleEntryPlans(packageContext: StylePackageContext): {
|
|
48
|
+
sourceDir: string;
|
|
49
|
+
moduleStyleImports: string[];
|
|
50
|
+
ownStyleFiles: string[];
|
|
74
51
|
}[];
|
|
75
52
|
export {};
|
|
@@ -1,46 +1,35 @@
|
|
|
1
|
-
import {
|
|
2
|
-
getExternalStyleDependencies,
|
|
3
|
-
getGlobalStyleDependencies,
|
|
4
|
-
getThemeNames,
|
|
5
|
-
getThemeStyleDependencies,
|
|
6
|
-
} from '#auklet/css/core/style/dependencies';
|
|
1
|
+
import { getExternalStyleDependencies, getGlobalStyleDependencies, getThemeNames, getThemeStyleDependencies, } from '#auklet/css/core/style/dependencies';
|
|
7
2
|
import { StyleModuleEntryPlanner } from '#auklet/css/core/styleModuleEntryPlanner';
|
|
8
3
|
const dependenciesPart = (specifiers) => ({ type: 'dependencies', specifiers });
|
|
9
4
|
// 环境无关的 style entry graph。production writer 和 Vite/dev renderer 都从这里取入口语义。
|
|
10
5
|
export function createStyleEntryParts(config) {
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
6
|
+
return [
|
|
7
|
+
dependenciesPart(getGlobalStyleDependencies(config)),
|
|
8
|
+
{ type: 'themes', themeNames: getThemeNames(config) },
|
|
9
|
+
{ type: 'module' },
|
|
10
|
+
];
|
|
16
11
|
}
|
|
17
12
|
export function createThemeEntryParts(config, themeName, options = {}) {
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
13
|
+
const themePart = { type: 'theme', themeName };
|
|
14
|
+
if (options.includeDependencies === false) {
|
|
15
|
+
return [themePart];
|
|
16
|
+
}
|
|
17
|
+
return [
|
|
18
|
+
dependenciesPart(getThemeStyleDependencies(config, themeName)),
|
|
19
|
+
themePart,
|
|
20
|
+
];
|
|
26
21
|
}
|
|
27
22
|
export function createExternalEntryParts(config) {
|
|
28
|
-
|
|
23
|
+
return [
|
|
24
|
+
dependenciesPart(getExternalStyleDependencies(config)),
|
|
25
|
+
];
|
|
29
26
|
}
|
|
30
27
|
export function collectModuleStyleImports(packageContext) {
|
|
31
|
-
|
|
32
|
-
packageContext.sourceFiles,
|
|
33
|
-
packageContext.normalizedConfig,
|
|
34
|
-
);
|
|
28
|
+
return packageContext.importCollector.collect(packageContext.sourceFiles, packageContext.normalizedConfig);
|
|
35
29
|
}
|
|
36
|
-
export function
|
|
37
|
-
|
|
38
|
-
sourceDir,
|
|
39
|
-
collectModuleStyleImports(packageContext),
|
|
40
|
-
);
|
|
30
|
+
export function createModuleStyleEntryPlan(packageContext, sourceDir) {
|
|
31
|
+
return new StyleModuleEntryPlanner(packageContext).createEntry(sourceDir, collectModuleStyleImports(packageContext));
|
|
41
32
|
}
|
|
42
|
-
export function
|
|
43
|
-
|
|
44
|
-
collectModuleStyleImports(packageContext),
|
|
45
|
-
);
|
|
33
|
+
export function createModuleStyleEntryPlans(packageContext) {
|
|
34
|
+
return new StyleModuleEntryPlanner(packageContext).createEntries(collectModuleStyleImports(packageContext));
|
|
46
35
|
}
|
|
@@ -1,8 +1,3 @@
|
|
|
1
|
-
export declare function groupStyleFilesByDir(
|
|
2
|
-
|
|
3
|
-
styleFiles: Array<string>,
|
|
4
|
-
): Map<string, string[]>;
|
|
5
|
-
export declare function createStyleFileKeySet(
|
|
6
|
-
styleFiles: Iterable<string>,
|
|
7
|
-
): Set<string>;
|
|
1
|
+
export declare function groupStyleFilesByDir(sourceRoot: string, styleFiles: Array<string>): Map<string, string[]>;
|
|
2
|
+
export declare function createStyleFileKeySet(styleFiles: Iterable<string>): Set<string>;
|
|
8
3
|
export declare function createStyleFileKey(styleFile: string): string;
|
|
@@ -1,19 +1,19 @@
|
|
|
1
1
|
import path from 'node:path';
|
|
2
2
|
import { getSourceModuleDir, normalizeFileKey } from '#auklet/utils';
|
|
3
3
|
export function groupStyleFilesByDir(sourceRoot, styleFiles) {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
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
13
|
}
|
|
14
14
|
export function createStyleFileKeySet(styleFiles) {
|
|
15
|
-
|
|
15
|
+
return new Set(Array.from(styleFiles, normalizeFileKey));
|
|
16
16
|
}
|
|
17
17
|
export function createStyleFileKey(styleFile) {
|
|
18
|
-
|
|
18
|
+
return normalizeFileKey(styleFile);
|
|
19
19
|
}
|
|
@@ -1,14 +1,47 @@
|
|
|
1
1
|
export type PackageStyleSpecifier = {
|
|
2
|
-
|
|
3
|
-
|
|
2
|
+
packageName: string;
|
|
3
|
+
stylePath: string;
|
|
4
4
|
};
|
|
5
5
|
export declare function parsePackageStyleSpecifier(specifier: string): {
|
|
6
|
-
|
|
7
|
-
|
|
6
|
+
packageName: string;
|
|
7
|
+
stylePath: string;
|
|
8
8
|
} | null;
|
|
9
|
-
export declare function joinDependencySpecifier(
|
|
10
|
-
packageName: string,
|
|
11
|
-
dependencyPath: string,
|
|
12
|
-
): string;
|
|
9
|
+
export declare function joinDependencySpecifier(packageName: string, dependencyPath: string): string;
|
|
13
10
|
export declare function createImportCode(specifiers: Array<string>): string;
|
|
14
11
|
export declare function removeStyleExtension(stylePath: string): string;
|
|
12
|
+
export declare function toRelativeImportSpecifier(fromDir: string, file: string): string;
|
|
13
|
+
export declare function getStylePathOutputFormat(stylePath: string, outputFormats: Array<string>): {
|
|
14
|
+
format: string;
|
|
15
|
+
path: string;
|
|
16
|
+
} | null;
|
|
17
|
+
export declare function createOutputStyleSpecifier(specifier: string, options: {
|
|
18
|
+
currentOutputFormat: string;
|
|
19
|
+
outputFormats: Array<string>;
|
|
20
|
+
}): string;
|
|
21
|
+
export declare function createExternalStyleSpecifier(specifier: string, options: {
|
|
22
|
+
currentOutputFormat: string;
|
|
23
|
+
outputFormats: Array<string>;
|
|
24
|
+
styleDir: string;
|
|
25
|
+
indexStyleFile: string;
|
|
26
|
+
externalStyleFile: string;
|
|
27
|
+
}): string;
|
|
28
|
+
export declare function createDevExternalStyleSpecifier(specifier: string, options: {
|
|
29
|
+
isKnownPackageName: (packageName: string) => boolean;
|
|
30
|
+
styleDir: string;
|
|
31
|
+
indexStyleFile: string;
|
|
32
|
+
externalStyleFile?: string;
|
|
33
|
+
}): string;
|
|
34
|
+
export declare function createOutputModuleStyleSpecifier(specifier: string, styleDir: string): string;
|
|
35
|
+
export declare function createOutputOwnStyleSpecifier(options: {
|
|
36
|
+
sourceRoot: string;
|
|
37
|
+
outputRoot: string;
|
|
38
|
+
styleDir: string;
|
|
39
|
+
}, styleFile: string): string;
|
|
40
|
+
export declare function createDevModuleStyleSpecifier(specifier: string, options: {
|
|
41
|
+
sourceStyleDir: string;
|
|
42
|
+
sourceRoot: string;
|
|
43
|
+
packageName: string;
|
|
44
|
+
styleDir: string;
|
|
45
|
+
indexStyleFile: string;
|
|
46
|
+
mapExternalSpecifier: (specifier: string) => string;
|
|
47
|
+
}): string;
|
|
@@ -1,27 +1,116 @@
|
|
|
1
1
|
import path from 'node:path';
|
|
2
|
+
import { EXTERNAL_ENTRY, STYLE_ENTRY } from '#auklet/css/constants';
|
|
3
|
+
import { POSIX_SEPARATOR, toFsSpecifier, toPosixPath } from '#auklet/utils';
|
|
2
4
|
export function parsePackageStyleSpecifier(specifier) {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
5
|
+
if (specifier.startsWith('.'))
|
|
6
|
+
return null;
|
|
7
|
+
const parts = specifier.split('/');
|
|
8
|
+
const packageName = specifier.startsWith('@')
|
|
9
|
+
? `${parts.shift() ?? ''}/${parts.shift() ?? ''}`
|
|
10
|
+
: (parts.shift() ?? '');
|
|
11
|
+
if (!packageName)
|
|
12
|
+
return null;
|
|
13
|
+
return {
|
|
14
|
+
packageName,
|
|
15
|
+
stylePath: parts.join('/'),
|
|
16
|
+
};
|
|
13
17
|
}
|
|
14
18
|
export function joinDependencySpecifier(packageName, dependencyPath) {
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
+
if (!dependencyPath)
|
|
20
|
+
return packageName;
|
|
21
|
+
return dependencyPath.startsWith('/')
|
|
22
|
+
? `${packageName}${dependencyPath}`
|
|
23
|
+
: `${packageName}/${dependencyPath}`;
|
|
19
24
|
}
|
|
20
25
|
export function createImportCode(specifiers) {
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
26
|
+
return Array.from(new Set(specifiers))
|
|
27
|
+
.map((specifier) => `@import "${specifier}";`)
|
|
28
|
+
.join('\n');
|
|
24
29
|
}
|
|
25
30
|
export function removeStyleExtension(stylePath) {
|
|
26
|
-
|
|
31
|
+
return stylePath.slice(0, -path.extname(stylePath).length);
|
|
32
|
+
}
|
|
33
|
+
export function toRelativeImportSpecifier(fromDir, file) {
|
|
34
|
+
const relative = toPosixPath(path.relative(fromDir, file));
|
|
35
|
+
return relative.startsWith('.') ? relative : `./${relative}`;
|
|
36
|
+
}
|
|
37
|
+
export function getStylePathOutputFormat(stylePath, outputFormats) {
|
|
38
|
+
for (const format of outputFormats) {
|
|
39
|
+
const prefix = `${format}${POSIX_SEPARATOR}`;
|
|
40
|
+
if (!stylePath.startsWith(prefix))
|
|
41
|
+
continue;
|
|
42
|
+
return {
|
|
43
|
+
format,
|
|
44
|
+
path: stylePath.slice(prefix.length),
|
|
45
|
+
};
|
|
46
|
+
}
|
|
47
|
+
return null;
|
|
48
|
+
}
|
|
49
|
+
export function createOutputStyleSpecifier(specifier, options) {
|
|
50
|
+
const parsed = parsePackageStyleSpecifier(specifier);
|
|
51
|
+
if (!parsed)
|
|
52
|
+
return specifier;
|
|
53
|
+
const outputFormat = getStylePathOutputFormat(parsed.stylePath, options.outputFormats);
|
|
54
|
+
if (!outputFormat)
|
|
55
|
+
return specifier;
|
|
56
|
+
return [
|
|
57
|
+
parsed.packageName,
|
|
58
|
+
options.currentOutputFormat,
|
|
59
|
+
outputFormat.path,
|
|
60
|
+
].join(POSIX_SEPARATOR);
|
|
61
|
+
}
|
|
62
|
+
export function createExternalStyleSpecifier(specifier, options) {
|
|
63
|
+
const parsed = parsePackageStyleSpecifier(specifier);
|
|
64
|
+
if (!parsed)
|
|
65
|
+
return specifier;
|
|
66
|
+
if (parsed.stylePath === STYLE_ENTRY) {
|
|
67
|
+
return [parsed.packageName, options.externalStyleFile].join(POSIX_SEPARATOR);
|
|
68
|
+
}
|
|
69
|
+
const outputFormat = getStylePathOutputFormat(parsed.stylePath, options.outputFormats);
|
|
70
|
+
const indexStylePath = [options.styleDir, options.indexStyleFile].join(POSIX_SEPARATOR);
|
|
71
|
+
if (!outputFormat || outputFormat.path !== indexStylePath)
|
|
72
|
+
return specifier;
|
|
73
|
+
return [
|
|
74
|
+
parsed.packageName,
|
|
75
|
+
options.currentOutputFormat,
|
|
76
|
+
options.styleDir,
|
|
77
|
+
options.externalStyleFile,
|
|
78
|
+
].join(POSIX_SEPARATOR);
|
|
79
|
+
}
|
|
80
|
+
export function createDevExternalStyleSpecifier(specifier, options) {
|
|
81
|
+
const parsed = parsePackageStyleSpecifier(specifier);
|
|
82
|
+
if (!parsed)
|
|
83
|
+
return specifier;
|
|
84
|
+
if (!options.isKnownPackageName(parsed.packageName))
|
|
85
|
+
return specifier;
|
|
86
|
+
const indexStylePath = [options.styleDir, options.indexStyleFile].join(POSIX_SEPARATOR);
|
|
87
|
+
if (parsed.stylePath === STYLE_ENTRY || parsed.stylePath === indexStylePath) {
|
|
88
|
+
return [
|
|
89
|
+
parsed.packageName,
|
|
90
|
+
options.externalStyleFile ?? EXTERNAL_ENTRY,
|
|
91
|
+
].join(POSIX_SEPARATOR);
|
|
92
|
+
}
|
|
93
|
+
return specifier;
|
|
94
|
+
}
|
|
95
|
+
export function createOutputModuleStyleSpecifier(specifier, styleDir) {
|
|
96
|
+
if (specifier.startsWith('.'))
|
|
97
|
+
return specifier;
|
|
98
|
+
if (!path.isAbsolute(specifier))
|
|
99
|
+
return specifier;
|
|
100
|
+
return toRelativeImportSpecifier(styleDir, specifier);
|
|
101
|
+
}
|
|
102
|
+
export function createOutputOwnStyleSpecifier(options, styleFile) {
|
|
103
|
+
return toRelativeImportSpecifier(options.styleDir, path.join(options.outputRoot, path.relative(options.sourceRoot, styleFile)));
|
|
104
|
+
}
|
|
105
|
+
export function createDevModuleStyleSpecifier(specifier, options) {
|
|
106
|
+
if (!specifier.startsWith('.')) {
|
|
107
|
+
return options.mapExternalSpecifier(specifier);
|
|
108
|
+
}
|
|
109
|
+
const outputStyleEntry = path.resolve(options.sourceStyleDir, specifier);
|
|
110
|
+
const styleEntrySuffix = `${path.sep}${options.styleDir}${path.sep}${options.indexStyleFile}`;
|
|
111
|
+
if (!outputStyleEntry.endsWith(styleEntrySuffix)) {
|
|
112
|
+
return toFsSpecifier(outputStyleEntry);
|
|
113
|
+
}
|
|
114
|
+
const sourceModuleDir = path.relative(options.sourceRoot, outputStyleEntry.slice(0, -styleEntrySuffix.length));
|
|
115
|
+
return `${options.packageName}/${toPosixPath(sourceModuleDir)}.css`;
|
|
27
116
|
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { NormalizedAukletConfig } from '#auklet/types';
|
|
2
|
+
export type StyleAutoImportRule = {
|
|
3
|
+
packageName: string;
|
|
4
|
+
outputPattern: string;
|
|
5
|
+
};
|
|
6
|
+
export type StyleAutoImportRuleMatch = {
|
|
7
|
+
rule: StyleAutoImportRule;
|
|
8
|
+
values: Array<string>;
|
|
9
|
+
};
|
|
10
|
+
export declare function createStyleAutoImportRules(config: NormalizedAukletConfig): StyleAutoImportRule[];
|
|
11
|
+
export declare function matchStyleAutoImportRules(rules: Array<StyleAutoImportRule>, importPath: string): StyleAutoImportRuleMatch[];
|
|
12
|
+
export declare function createStyleAutoImportSpecifier(rule: StyleAutoImportRule, values: Array<string>, importedName: string): string;
|
|
13
|
+
export declare function createDirectStyleAutoImportSpecifier(rule: StyleAutoImportRule, importPath: string): string | null;
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import { isArray } from 'aidly';
|
|
2
|
+
import { joinDependencySpecifier } from '#auklet/css/core/style/specifier';
|
|
3
|
+
import { POSIX_SEPARATOR } from '#auklet/utils';
|
|
4
|
+
const GLOBSTAR_TOKEN = '**';
|
|
5
|
+
export function createStyleAutoImportRules(config) {
|
|
6
|
+
const rules = [];
|
|
7
|
+
for (const [packageName, dependency] of Object.entries(config.styles.dependencies)) {
|
|
8
|
+
const dependencyPaths = isArray(dependency.components)
|
|
9
|
+
? dependency.components
|
|
10
|
+
: dependency.components
|
|
11
|
+
? [dependency.components]
|
|
12
|
+
: [];
|
|
13
|
+
for (const dependencyPath of dependencyPaths) {
|
|
14
|
+
rules.push({
|
|
15
|
+
packageName,
|
|
16
|
+
outputPattern: joinDependencySpecifier(packageName, dependencyPath),
|
|
17
|
+
});
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
return rules;
|
|
21
|
+
}
|
|
22
|
+
export function matchStyleAutoImportRules(rules, importPath) {
|
|
23
|
+
const matches = [];
|
|
24
|
+
for (const rule of rules) {
|
|
25
|
+
if (importPath !== rule.packageName &&
|
|
26
|
+
!importPath.startsWith(`${rule.packageName}${POSIX_SEPARATOR}`)) {
|
|
27
|
+
continue;
|
|
28
|
+
}
|
|
29
|
+
matches.push({
|
|
30
|
+
rule,
|
|
31
|
+
values: getImportPathValues(rule.packageName, importPath),
|
|
32
|
+
});
|
|
33
|
+
}
|
|
34
|
+
return matches;
|
|
35
|
+
}
|
|
36
|
+
export function createStyleAutoImportSpecifier(rule, values, importedName) {
|
|
37
|
+
const pathValues = [...values];
|
|
38
|
+
return rule.outputPattern.replace(/\*\*|\*/g, (token) => {
|
|
39
|
+
const matchedValue = pathValues.shift();
|
|
40
|
+
if (matchedValue)
|
|
41
|
+
return matchedValue;
|
|
42
|
+
if (token === GLOBSTAR_TOKEN)
|
|
43
|
+
return importedName;
|
|
44
|
+
return matchedValue ?? importedName;
|
|
45
|
+
});
|
|
46
|
+
}
|
|
47
|
+
export function createDirectStyleAutoImportSpecifier(rule, importPath) {
|
|
48
|
+
const wildcardIndex = rule.outputPattern.indexOf('*');
|
|
49
|
+
if (wildcardIndex < 0) {
|
|
50
|
+
return null;
|
|
51
|
+
}
|
|
52
|
+
const wildcardLength = rule.outputPattern.startsWith(GLOBSTAR_TOKEN, wildcardIndex)
|
|
53
|
+
? GLOBSTAR_TOKEN.length
|
|
54
|
+
: 1;
|
|
55
|
+
const prefix = rule.outputPattern.slice(0, wildcardIndex);
|
|
56
|
+
const suffix = rule.outputPattern.slice(wildcardIndex + wildcardLength);
|
|
57
|
+
if (!importPath.startsWith(prefix)) {
|
|
58
|
+
return null;
|
|
59
|
+
}
|
|
60
|
+
return `${importPath}${suffix}`;
|
|
61
|
+
}
|
|
62
|
+
const getImportPathValues = (packageName, importPath) => {
|
|
63
|
+
return importPath
|
|
64
|
+
.slice(packageName.length)
|
|
65
|
+
.replace(new RegExp(`^${POSIX_SEPARATOR}`), '')
|
|
66
|
+
.split(POSIX_SEPARATOR)
|
|
67
|
+
.filter(Boolean);
|
|
68
|
+
};
|
|
@@ -1,29 +1,16 @@
|
|
|
1
1
|
import type { NormalizedAukletConfig } from '#auklet/types';
|
|
2
2
|
import type { WorkspaceStyleResolver } from '#auklet/css/core/workspaceStyleResolver';
|
|
3
3
|
export declare class ModuleStyleImportCollector {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
config: NormalizedAukletConfig,
|
|
17
|
-
): Map<string, string[]>;
|
|
18
|
-
private collectSourceImportStyle;
|
|
19
|
-
private resolveSourceImportStyleEntry;
|
|
20
|
-
private isInsideSourceRoot;
|
|
21
|
-
private resolveSourceImportPaths;
|
|
22
|
-
private toSourceBase;
|
|
23
|
-
private toRelativeSpecifier;
|
|
24
|
-
private createAutoImportRules;
|
|
25
|
-
private matchAutoImportRules;
|
|
26
|
-
private getImportPathValues;
|
|
27
|
-
private createStyleSpecifier;
|
|
28
|
-
private createDirectStyleSpecifier;
|
|
4
|
+
private readonly srcRoot;
|
|
5
|
+
private readonly packageRoot;
|
|
6
|
+
private readonly resolver;
|
|
7
|
+
private readonly styleExtensions;
|
|
8
|
+
constructor(srcRoot: string, packageRoot: string, resolver: WorkspaceStyleResolver, styleExtensions?: Array<string>);
|
|
9
|
+
collect(files: Array<string>, config: NormalizedAukletConfig): Map<string, string[]>;
|
|
10
|
+
private collectSourceImportStyle;
|
|
11
|
+
private resolveSourceImportStyleEntry;
|
|
12
|
+
private isInsideSourceRoot;
|
|
13
|
+
private resolveSourceImportPaths;
|
|
14
|
+
private toSourceBase;
|
|
15
|
+
private toRelativeSpecifier;
|
|
29
16
|
}
|