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,22 +2,19 @@ import type { ModuleStyleBuildConfig } from '#auklet/types';
|
|
|
2
2
|
import type { ModuleStyleGraphRequestCache } from '#auklet/css/vite/moduleGraph/requestCache';
|
|
3
3
|
import type { PackageStyleId } from '#auklet/css/vite/moduleGraph/types';
|
|
4
4
|
export declare class StyleCodeFactory {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
private toDevModuleImportSpecifier;
|
|
21
|
-
private toDevExternalStyleSpecifier;
|
|
22
|
-
private parsePackageStyleIdInRequest;
|
|
5
|
+
private readonly config;
|
|
6
|
+
constructor(config: ModuleStyleBuildConfig);
|
|
7
|
+
createPackageStyleCode(parsed: PackageStyleId, cache: ModuleStyleGraphRequestCache): Promise<{
|
|
8
|
+
code: string;
|
|
9
|
+
watchFiles: string[];
|
|
10
|
+
}>;
|
|
11
|
+
private createStyleCode;
|
|
12
|
+
private createDependencyStyleCode;
|
|
13
|
+
private createExternalStyleCode;
|
|
14
|
+
private createThemeStyleCode;
|
|
15
|
+
private createModuleStyleCode;
|
|
16
|
+
private createSourceModuleStyleCode;
|
|
17
|
+
private toDevModuleImportSpecifier;
|
|
18
|
+
private toDevExternalStyleSpecifier;
|
|
19
|
+
private parsePackageStyleIdInRequest;
|
|
23
20
|
}
|
|
@@ -2,283 +2,192 @@ import path from 'node:path';
|
|
|
2
2
|
import { mergeLoadResults } from '#auklet/css/vite/moduleGraph/loadResult';
|
|
3
3
|
import { parsePackageStyleId } from '#auklet/css/vite/moduleGraph/styleId';
|
|
4
4
|
import { toDevDependencyImportSpecifier } from '#auklet/css/vite/moduleGraph/devDependency';
|
|
5
|
-
import {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
STYLE_ENTRY,
|
|
9
|
-
THEMES_ENTRY_PREFIX,
|
|
10
|
-
} from '#auklet/css/constants';
|
|
11
|
-
import {
|
|
12
|
-
createComponentStyleEntryPlan,
|
|
13
|
-
createExternalEntryParts,
|
|
14
|
-
createStyleEntryParts,
|
|
15
|
-
createThemeEntryParts,
|
|
16
|
-
} from '#auklet/css/core/style/entries';
|
|
17
|
-
import {
|
|
18
|
-
createImportCode,
|
|
19
|
-
parsePackageStyleSpecifier,
|
|
20
|
-
removeStyleExtension,
|
|
21
|
-
} from '#auklet/css/core/style/specifier';
|
|
22
|
-
import { toFsSpecifier, toPosixPath } from '#auklet/utils';
|
|
5
|
+
import { EXTERNAL_ENTRY, MODULE_ENTRY, STYLE_ENTRY, THEMES_ENTRY_PREFIX, } from '#auklet/css/constants';
|
|
6
|
+
import { createModuleStyleEntryPlan, createExternalEntryParts, createStyleEntryParts, createThemeEntryParts, } from '#auklet/css/core/style/entries';
|
|
7
|
+
import { createDevExternalStyleSpecifier, createDevModuleStyleSpecifier, createImportCode, removeStyleExtension, } from '#auklet/css/core/style/specifier';
|
|
23
8
|
// 生成 Vite/dev 虚拟 CSS;production writer 共享入口语义,但写入真实文件。
|
|
24
9
|
export class StyleCodeFactory {
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
}
|
|
29
|
-
async createPackageStyleCode(parsed, cache) {
|
|
30
|
-
const context = await cache.getContext(parsed);
|
|
31
|
-
if (!context) {
|
|
32
|
-
return {
|
|
33
|
-
code: '',
|
|
34
|
-
watchFiles: [],
|
|
35
|
-
};
|
|
10
|
+
config;
|
|
11
|
+
constructor(config) {
|
|
12
|
+
this.config = config;
|
|
36
13
|
}
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
14
|
+
async createPackageStyleCode(parsed, cache) {
|
|
15
|
+
const context = await cache.getContext(parsed);
|
|
16
|
+
if (!context) {
|
|
17
|
+
return {
|
|
18
|
+
code: '',
|
|
19
|
+
watchFiles: [],
|
|
20
|
+
};
|
|
21
|
+
}
|
|
22
|
+
if (parsed.stylePath === STYLE_ENTRY) {
|
|
23
|
+
return this.createStyleCode(context, cache);
|
|
24
|
+
}
|
|
25
|
+
if (parsed.stylePath === EXTERNAL_ENTRY) {
|
|
26
|
+
return this.createExternalStyleCode(context, cache);
|
|
27
|
+
}
|
|
28
|
+
if (parsed.stylePath === MODULE_ENTRY) {
|
|
29
|
+
return this.createModuleStyleCode(context);
|
|
30
|
+
}
|
|
31
|
+
if (parsed.stylePath.startsWith(THEMES_ENTRY_PREFIX)) {
|
|
32
|
+
return this.createThemeStyleCode(context, cache, [
|
|
33
|
+
removeStyleExtension(parsed.stylePath.slice(THEMES_ENTRY_PREFIX.length)),
|
|
34
|
+
]);
|
|
35
|
+
}
|
|
36
|
+
return this.createSourceModuleStyleCode(context, cache, parsed.stylePath);
|
|
42
37
|
}
|
|
43
|
-
|
|
44
|
-
|
|
38
|
+
async createStyleCode(context, cache) {
|
|
39
|
+
const results = [];
|
|
40
|
+
for (const part of createStyleEntryParts(context.normalizedConfig)) {
|
|
41
|
+
if (part.type === 'dependencies') {
|
|
42
|
+
results.push(await this.createDependencyStyleCode(context, cache, part.specifiers));
|
|
43
|
+
continue;
|
|
44
|
+
}
|
|
45
|
+
if (part.type === 'themes') {
|
|
46
|
+
results.push(await this.createThemeStyleCode(context, cache, part.themeNames, false));
|
|
47
|
+
continue;
|
|
48
|
+
}
|
|
49
|
+
results.push(this.createModuleStyleCode(context));
|
|
50
|
+
}
|
|
51
|
+
return mergeLoadResults(...results);
|
|
45
52
|
}
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
)
|
|
51
|
-
|
|
53
|
+
async createDependencyStyleCode(context, cache, specifiers, mapSpecifier = (specifier) => specifier) {
|
|
54
|
+
const results = [];
|
|
55
|
+
const imports = [];
|
|
56
|
+
const watchFiles = [context.configPath];
|
|
57
|
+
for (const specifier of specifiers) {
|
|
58
|
+
const outputSpecifier = mapSpecifier(specifier);
|
|
59
|
+
const parsed = this.parsePackageStyleIdInRequest(outputSpecifier, cache);
|
|
60
|
+
if (parsed) {
|
|
61
|
+
results.push(await this.createPackageStyleCode(parsed, cache));
|
|
62
|
+
continue;
|
|
63
|
+
}
|
|
64
|
+
const resolvedSpecifier = toDevDependencyImportSpecifier(context, outputSpecifier);
|
|
65
|
+
imports.push(resolvedSpecifier.specifier);
|
|
66
|
+
if (resolvedSpecifier.watchFile) {
|
|
67
|
+
watchFiles.push(resolvedSpecifier.watchFile);
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
return mergeLoadResults({
|
|
71
|
+
code: createImportCode(imports),
|
|
72
|
+
watchFiles,
|
|
73
|
+
}, ...results);
|
|
52
74
|
}
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
results.push(
|
|
60
|
-
await this.createDependencyStyleCode(context, cache, part.specifiers),
|
|
61
|
-
);
|
|
62
|
-
continue;
|
|
63
|
-
}
|
|
64
|
-
if (part.type === 'themes') {
|
|
65
|
-
results.push(
|
|
66
|
-
await this.createThemeStyleCode(
|
|
67
|
-
context,
|
|
68
|
-
cache,
|
|
69
|
-
part.themeNames,
|
|
70
|
-
false,
|
|
71
|
-
),
|
|
72
|
-
);
|
|
73
|
-
continue;
|
|
74
|
-
}
|
|
75
|
-
results.push(this.createModuleStyleCode(context));
|
|
75
|
+
async createExternalStyleCode(context, cache) {
|
|
76
|
+
const results = [];
|
|
77
|
+
for (const part of createExternalEntryParts(context.normalizedConfig)) {
|
|
78
|
+
results.push(await this.createDependencyStyleCode(context, cache, part.specifiers, (specifier) => this.toDevExternalStyleSpecifier(specifier, cache)));
|
|
79
|
+
}
|
|
80
|
+
return mergeLoadResults(...results);
|
|
76
81
|
}
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
82
|
+
async createThemeStyleCode(context, cache, themeNames, includeDependencies = true) {
|
|
83
|
+
const { themeFiles } = context.packageContext;
|
|
84
|
+
const targetThemeNames = themeNames ?? context.packageContext.themeNames;
|
|
85
|
+
const root = context.styleProcessor.createRoot();
|
|
86
|
+
const watchFiles = [context.configPath, ...themeFiles.values()];
|
|
87
|
+
const dependencyResults = [];
|
|
88
|
+
for (const themeName of targetThemeNames) {
|
|
89
|
+
for (const part of createThemeEntryParts(context.normalizedConfig, themeName, {
|
|
90
|
+
includeDependencies,
|
|
91
|
+
})) {
|
|
92
|
+
if (part.type === 'dependencies') {
|
|
93
|
+
dependencyResults.push(await this.createDependencyStyleCode(context, cache, part.specifiers));
|
|
94
|
+
continue;
|
|
95
|
+
}
|
|
96
|
+
const themeFile = themeFiles.get(part.themeName);
|
|
97
|
+
if (!themeFile)
|
|
98
|
+
continue;
|
|
99
|
+
const content = context.styleProcessor.readStyleFile(themeFile);
|
|
100
|
+
if (content.trim()) {
|
|
101
|
+
context.styleProcessor.appendStyleContent(root, content, themeFile);
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
return mergeLoadResults({
|
|
106
|
+
code: '',
|
|
107
|
+
watchFiles,
|
|
108
|
+
}, ...dependencyResults, {
|
|
109
|
+
code: root.nodes?.length ? context.styleProcessor.stringify(root) : '',
|
|
110
|
+
watchFiles: [],
|
|
111
|
+
});
|
|
103
112
|
}
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
cache,
|
|
119
|
-
part.specifiers,
|
|
120
|
-
(specifier) => this.toDevExternalStyleSpecifier(specifier, cache),
|
|
121
|
-
),
|
|
122
|
-
);
|
|
113
|
+
createModuleStyleCode(context) {
|
|
114
|
+
const { styleFiles } = context.packageContext;
|
|
115
|
+
const root = context.styleProcessor.createRoot();
|
|
116
|
+
const seen = new Set();
|
|
117
|
+
for (const styleFile of styleFiles) {
|
|
118
|
+
const content = context.styleProcessor.readStyleFile(styleFile, seen);
|
|
119
|
+
if (content.trim()) {
|
|
120
|
+
context.styleProcessor.appendStyleContent(root, content, styleFile);
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
return {
|
|
124
|
+
code: root.nodes?.length ? context.styleProcessor.stringify(root) : '',
|
|
125
|
+
watchFiles: [context.configPath, ...styleFiles],
|
|
126
|
+
};
|
|
123
127
|
}
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
)) {
|
|
145
|
-
if (part.type === 'dependencies') {
|
|
146
|
-
dependencyResults.push(
|
|
147
|
-
await this.createDependencyStyleCode(
|
|
148
|
-
context,
|
|
149
|
-
cache,
|
|
150
|
-
part.specifiers,
|
|
151
|
-
),
|
|
152
|
-
);
|
|
153
|
-
continue;
|
|
128
|
+
async createSourceModuleStyleCode(context, cache, stylePath) {
|
|
129
|
+
const sourceModuleDir = removeStyleExtension(stylePath);
|
|
130
|
+
const { styleFiles, sourceFiles } = context.packageContext;
|
|
131
|
+
const entry = createModuleStyleEntryPlan(context.packageContext, sourceModuleDir);
|
|
132
|
+
const sourceStyleDir = path.join(context.sourceRoot, sourceModuleDir, this.config.output.styleDir);
|
|
133
|
+
const moduleStyleResults = [];
|
|
134
|
+
const moduleStyleSpecifiers = [];
|
|
135
|
+
const moduleStyleWatchFiles = [];
|
|
136
|
+
for (const specifier of entry.moduleStyleImports) {
|
|
137
|
+
const result = this.toDevModuleImportSpecifier(specifier, context, cache, sourceStyleDir);
|
|
138
|
+
const parsed = this.parsePackageStyleIdInRequest(result, cache);
|
|
139
|
+
if (parsed) {
|
|
140
|
+
moduleStyleResults.push(await this.createPackageStyleCode(parsed, cache));
|
|
141
|
+
continue;
|
|
142
|
+
}
|
|
143
|
+
const resolvedSpecifier = toDevDependencyImportSpecifier(context, result);
|
|
144
|
+
moduleStyleSpecifiers.push(resolvedSpecifier.specifier);
|
|
145
|
+
if (resolvedSpecifier.watchFile) {
|
|
146
|
+
moduleStyleWatchFiles.push(resolvedSpecifier.watchFile);
|
|
147
|
+
}
|
|
154
148
|
}
|
|
155
|
-
const
|
|
156
|
-
|
|
157
|
-
const
|
|
158
|
-
|
|
159
|
-
|
|
149
|
+
const root = context.styleProcessor.createRoot();
|
|
150
|
+
const seen = new Set();
|
|
151
|
+
for (const ownStyleFile of entry.ownStyleFiles) {
|
|
152
|
+
const content = context.styleProcessor.readStyleFile(ownStyleFile, seen);
|
|
153
|
+
if (content.trim()) {
|
|
154
|
+
context.styleProcessor.appendStyleContent(root, content, ownStyleFile);
|
|
155
|
+
}
|
|
160
156
|
}
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
createModuleStyleCode(context) {
|
|
176
|
-
const { styleFiles } = context.packageContext;
|
|
177
|
-
const root = context.styleProcessor.createRoot();
|
|
178
|
-
const seen = new Set();
|
|
179
|
-
for (const styleFile of styleFiles) {
|
|
180
|
-
const content = context.styleProcessor.readStyleFile(styleFile, seen);
|
|
181
|
-
if (content.trim()) {
|
|
182
|
-
context.styleProcessor.appendStyleContent(root, content, styleFile);
|
|
183
|
-
}
|
|
184
|
-
}
|
|
185
|
-
return {
|
|
186
|
-
code: root.nodes?.length ? context.styleProcessor.stringify(root) : '',
|
|
187
|
-
watchFiles: [context.configPath, ...styleFiles],
|
|
188
|
-
};
|
|
189
|
-
}
|
|
190
|
-
async createSourceModuleStyleCode(context, cache, stylePath) {
|
|
191
|
-
const sourceModuleDir = removeStyleExtension(stylePath);
|
|
192
|
-
const { styleFiles, sourceFiles } = context.packageContext;
|
|
193
|
-
const entry = createComponentStyleEntryPlan(
|
|
194
|
-
context.packageContext,
|
|
195
|
-
sourceModuleDir,
|
|
196
|
-
);
|
|
197
|
-
const sourceStyleDir = path.join(
|
|
198
|
-
context.sourceRoot,
|
|
199
|
-
sourceModuleDir,
|
|
200
|
-
this.config.output.styleDir,
|
|
201
|
-
);
|
|
202
|
-
const moduleStyleResults = [];
|
|
203
|
-
const moduleStyleSpecifiers = [];
|
|
204
|
-
const moduleStyleWatchFiles = [];
|
|
205
|
-
for (const specifier of entry.moduleStyleImports) {
|
|
206
|
-
const result = this.toDevModuleImportSpecifier(
|
|
207
|
-
context,
|
|
208
|
-
cache,
|
|
209
|
-
sourceStyleDir,
|
|
210
|
-
specifier,
|
|
211
|
-
);
|
|
212
|
-
const parsed = this.parsePackageStyleIdInRequest(result, cache);
|
|
213
|
-
if (parsed) {
|
|
214
|
-
moduleStyleResults.push(
|
|
215
|
-
await this.createPackageStyleCode(parsed, cache),
|
|
216
|
-
);
|
|
217
|
-
continue;
|
|
218
|
-
}
|
|
219
|
-
const resolvedSpecifier = toDevDependencyImportSpecifier(context, result);
|
|
220
|
-
moduleStyleSpecifiers.push(resolvedSpecifier.specifier);
|
|
221
|
-
if (resolvedSpecifier.watchFile) {
|
|
222
|
-
moduleStyleWatchFiles.push(resolvedSpecifier.watchFile);
|
|
223
|
-
}
|
|
224
|
-
}
|
|
225
|
-
const root = context.styleProcessor.createRoot();
|
|
226
|
-
const seen = new Set();
|
|
227
|
-
for (const ownStyleFile of entry.ownStyleFiles) {
|
|
228
|
-
const content = context.styleProcessor.readStyleFile(ownStyleFile, seen);
|
|
229
|
-
if (content.trim()) {
|
|
230
|
-
context.styleProcessor.appendStyleContent(root, content, ownStyleFile);
|
|
231
|
-
}
|
|
157
|
+
const ownStyleCode = root.nodes?.length
|
|
158
|
+
? context.styleProcessor.stringify(root)
|
|
159
|
+
: '';
|
|
160
|
+
return mergeLoadResults(...moduleStyleResults, {
|
|
161
|
+
code: [createImportCode(moduleStyleSpecifiers), ownStyleCode]
|
|
162
|
+
.filter((code) => code.trim())
|
|
163
|
+
.join('\n'),
|
|
164
|
+
watchFiles: [
|
|
165
|
+
context.configPath,
|
|
166
|
+
...styleFiles,
|
|
167
|
+
...moduleStyleWatchFiles,
|
|
168
|
+
...sourceFiles.filter((file) => /\.(ts|tsx)$/.test(file)),
|
|
169
|
+
],
|
|
170
|
+
});
|
|
232
171
|
}
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
...styleFiles,
|
|
243
|
-
...moduleStyleWatchFiles,
|
|
244
|
-
...sourceFiles.filter((file) => /\.(ts|tsx)$/.test(file)),
|
|
245
|
-
],
|
|
246
|
-
});
|
|
247
|
-
}
|
|
248
|
-
toDevModuleImportSpecifier(context, cache, sourceStyleDir, specifier) {
|
|
249
|
-
if (!specifier.startsWith('.')) {
|
|
250
|
-
return this.toDevExternalStyleSpecifier(specifier, cache);
|
|
172
|
+
toDevModuleImportSpecifier(specifier, context, cache, sourceStyleDir) {
|
|
173
|
+
return createDevModuleStyleSpecifier(specifier, {
|
|
174
|
+
sourceStyleDir,
|
|
175
|
+
sourceRoot: context.sourceRoot,
|
|
176
|
+
packageName: context.packageName,
|
|
177
|
+
styleDir: this.config.output.styleDir,
|
|
178
|
+
indexStyleFile: this.config.output.indexStyleFile,
|
|
179
|
+
mapExternalSpecifier: (externalSpecifier) => this.toDevExternalStyleSpecifier(externalSpecifier, cache),
|
|
180
|
+
});
|
|
251
181
|
}
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
182
|
+
toDevExternalStyleSpecifier(specifier, cache) {
|
|
183
|
+
return createDevExternalStyleSpecifier(specifier, {
|
|
184
|
+
isKnownPackageName: (packageName) => cache.isKnownPackageName(packageName),
|
|
185
|
+
styleDir: this.config.output.styleDir,
|
|
186
|
+
indexStyleFile: this.config.output.indexStyleFile,
|
|
187
|
+
externalStyleFile: EXTERNAL_ENTRY,
|
|
188
|
+
});
|
|
256
189
|
}
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
outputStyleEntry.slice(0, -styleEntrySuffix.length),
|
|
260
|
-
);
|
|
261
|
-
return `${context.packageName}/${toPosixPath(sourceModuleDir)}.css`;
|
|
262
|
-
}
|
|
263
|
-
toDevExternalStyleSpecifier(specifier, cache) {
|
|
264
|
-
const parsed = parsePackageStyleSpecifier(specifier);
|
|
265
|
-
if (!parsed) return specifier;
|
|
266
|
-
if (cache.isKnownPackageName(parsed.packageName)) {
|
|
267
|
-
if (parsed.stylePath === STYLE_ENTRY) {
|
|
268
|
-
return `${parsed.packageName}/${EXTERNAL_ENTRY}`;
|
|
269
|
-
}
|
|
270
|
-
if (
|
|
271
|
-
parsed.stylePath ===
|
|
272
|
-
[this.config.output.styleDir, this.config.output.indexStyleFile].join(
|
|
273
|
-
'/',
|
|
274
|
-
)
|
|
275
|
-
) {
|
|
276
|
-
return `${parsed.packageName}/${EXTERNAL_ENTRY}`;
|
|
277
|
-
}
|
|
190
|
+
parsePackageStyleIdInRequest(id, cache) {
|
|
191
|
+
return parsePackageStyleId(id, cache.getPackageNames());
|
|
278
192
|
}
|
|
279
|
-
return specifier;
|
|
280
|
-
}
|
|
281
|
-
parsePackageStyleIdInRequest(id, cache) {
|
|
282
|
-
return parsePackageStyleId(id, cache.getPackageNames());
|
|
283
|
-
}
|
|
284
193
|
}
|
|
@@ -1,7 +1,4 @@
|
|
|
1
|
-
export declare function parsePackageStyleId(
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
): {
|
|
5
|
-
packageName: string;
|
|
6
|
-
stylePath: string;
|
|
1
|
+
export declare function parsePackageStyleId(id: string, packageNames: Array<string>): {
|
|
2
|
+
packageName: string;
|
|
3
|
+
stylePath: string;
|
|
7
4
|
} | null;
|
|
@@ -1,14 +1,15 @@
|
|
|
1
1
|
// 根据已知 workspace 包名解析 package CSS id,并优先匹配最长包名。
|
|
2
2
|
export function parsePackageStyleId(id, packageNames) {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
3
|
+
if (!id.endsWith('.css')) {
|
|
4
|
+
return null;
|
|
5
|
+
}
|
|
6
|
+
const packageName = [...packageNames]
|
|
7
|
+
.sort((left, right) => right.length - left.length)
|
|
8
|
+
.find((name) => id.startsWith(`${name}/`));
|
|
9
|
+
if (!packageName)
|
|
10
|
+
return null;
|
|
11
|
+
return {
|
|
12
|
+
packageName,
|
|
13
|
+
stylePath: id.slice(packageName.length + 1),
|
|
14
|
+
};
|
|
14
15
|
}
|
|
@@ -1,22 +1,19 @@
|
|
|
1
1
|
import type { AukletConfig, ModuleStyleBuildConfig } from '#auklet/types';
|
|
2
2
|
export interface ModuleStyleGraphOptions {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
3
|
+
root: string;
|
|
4
|
+
packagesDir?: string;
|
|
5
|
+
mode?: 'monorepo' | 'package';
|
|
6
|
+
config?: ModuleStyleBuildConfig;
|
|
7
|
+
loadAukletConfig?: LoadAukletConfig;
|
|
8
8
|
}
|
|
9
9
|
export type PackageStyleId = {
|
|
10
|
-
|
|
11
|
-
|
|
10
|
+
packageName: string;
|
|
11
|
+
stylePath: string;
|
|
12
12
|
};
|
|
13
13
|
export type PackageStyleLoadResult = {
|
|
14
|
-
|
|
15
|
-
|
|
14
|
+
code: string;
|
|
15
|
+
watchFiles: Array<string>;
|
|
16
16
|
};
|
|
17
|
-
export type LoadAukletConfig = (
|
|
18
|
-
packageRoot: string,
|
|
19
|
-
options?: {
|
|
17
|
+
export type LoadAukletConfig = (packageRoot: string, options?: {
|
|
20
18
|
cacheBust?: boolean;
|
|
21
|
-
|
|
22
|
-
) => Promise<AukletConfig>;
|
|
19
|
+
}) => Promise<AukletConfig>;
|
|
@@ -1,24 +1,20 @@
|
|
|
1
1
|
import type { HotUpdateOptions, ViteDevServer } from 'vite';
|
|
2
2
|
import type { ModuleStyleGraphOptions } from '#auklet/css/vite/moduleGraph/types';
|
|
3
|
-
export type AukletStylePluginOptions = Partial<
|
|
4
|
-
Pick<ModuleStyleGraphOptions, 'workspaceRoot' | 'mode'>
|
|
5
|
-
> &
|
|
6
|
-
Omit<ModuleStyleGraphOptions, 'workspaceRoot'>;
|
|
3
|
+
export type AukletStylePluginOptions = Partial<Pick<ModuleStyleGraphOptions, 'root' | 'mode'>> & Omit<ModuleStyleGraphOptions, 'root'>;
|
|
7
4
|
export declare function aukletStylePlugin(options?: AukletStylePluginOptions): {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
id: string
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
};
|
|
5
|
+
name: string;
|
|
6
|
+
apply: "serve";
|
|
7
|
+
enforce: "pre";
|
|
8
|
+
configResolved(config: {
|
|
9
|
+
root: string;
|
|
10
|
+
}): void;
|
|
11
|
+
resolveId(id: string): string | null;
|
|
12
|
+
load(this: {
|
|
13
|
+
addWatchFile?: (file: string) => void;
|
|
14
|
+
}, id: string): Promise<string | null>;
|
|
15
|
+
configureServer(server: ViteDevServer): Promise<void>;
|
|
16
|
+
hotUpdate: {
|
|
17
|
+
order: "pre";
|
|
18
|
+
handler(context: HotUpdateOptions): never[] | undefined;
|
|
19
|
+
};
|
|
24
20
|
};
|