auklet 0.0.16 → 0.0.17
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/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 +6 -6
- 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 +20 -31
- 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 +5 -8
- package/dist/css/core/style/specifier.js +21 -18
- package/dist/css/core/styleImports/collector.d.ts +17 -25
- package/dist/css/core/styleImports/collector.js +162 -201
- package/dist/css/core/styleImports/sourceReference.d.ts +8 -16
- package/dist/css/core/styleImports/sourceReference.js +153 -173
- package/dist/css/core/styleModuleEntryPlanner.d.ts +21 -24
- package/dist/css/core/styleModuleEntryPlanner.js +44 -61
- 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 +9 -15
- package/dist/css/core/workspaceStyleResolver.js +62 -72
- package/dist/css/production/builder.d.ts +9 -16
- package/dist/css/production/builder.js +51 -57
- package/dist/css/production/format/componentWriter.js +45 -66
- package/dist/css/production/format/entryWriter.js +36 -49
- package/dist/css/production/format/externalWriter.js +21 -33
- 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 +5 -6
- 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 +56 -65
- 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 +46 -49
- 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 +4 -6
- package/dist/css/vite/moduleGraph/packageSource/monorepo.js +59 -64
- 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 +182 -263
- 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 +110 -109
- package/dist/css/watch/watcher.d.ts +15 -21
- package/dist/css/watch/watcher.js +83 -80
- 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
|
@@ -2,283 +2,202 @@ 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';
|
|
5
|
+
import { EXTERNAL_ENTRY, MODULE_ENTRY, STYLE_ENTRY, THEMES_ENTRY_PREFIX, } from '#auklet/css/constants';
|
|
6
|
+
import { createComponentStyleEntryPlan, createExternalEntryParts, createStyleEntryParts, createThemeEntryParts, } from '#auklet/css/core/style/entries';
|
|
7
|
+
import { createImportCode, parsePackageStyleSpecifier, removeStyleExtension, } from '#auklet/css/core/style/specifier';
|
|
22
8
|
import { toFsSpecifier, toPosixPath } from '#auklet/utils';
|
|
23
9
|
// 生成 Vite/dev 虚拟 CSS;production writer 共享入口语义,但写入真实文件。
|
|
24
10
|
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
|
-
};
|
|
11
|
+
config;
|
|
12
|
+
constructor(config) {
|
|
13
|
+
this.config = config;
|
|
36
14
|
}
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
15
|
+
async createPackageStyleCode(parsed, cache) {
|
|
16
|
+
const context = await cache.getContext(parsed);
|
|
17
|
+
if (!context) {
|
|
18
|
+
return {
|
|
19
|
+
code: '',
|
|
20
|
+
watchFiles: [],
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
if (parsed.stylePath === STYLE_ENTRY) {
|
|
24
|
+
return this.createStyleCode(context, cache);
|
|
25
|
+
}
|
|
26
|
+
if (parsed.stylePath === EXTERNAL_ENTRY) {
|
|
27
|
+
return this.createExternalStyleCode(context, cache);
|
|
28
|
+
}
|
|
29
|
+
if (parsed.stylePath === MODULE_ENTRY) {
|
|
30
|
+
return this.createModuleStyleCode(context);
|
|
31
|
+
}
|
|
32
|
+
if (parsed.stylePath.startsWith(THEMES_ENTRY_PREFIX)) {
|
|
33
|
+
return this.createThemeStyleCode(context, cache, [
|
|
34
|
+
removeStyleExtension(parsed.stylePath.slice(THEMES_ENTRY_PREFIX.length)),
|
|
35
|
+
]);
|
|
36
|
+
}
|
|
37
|
+
return this.createSourceModuleStyleCode(context, cache, parsed.stylePath);
|
|
42
38
|
}
|
|
43
|
-
|
|
44
|
-
|
|
39
|
+
async createStyleCode(context, cache) {
|
|
40
|
+
const results = [];
|
|
41
|
+
for (const part of createStyleEntryParts(context.normalizedConfig)) {
|
|
42
|
+
if (part.type === 'dependencies') {
|
|
43
|
+
results.push(await this.createDependencyStyleCode(context, cache, part.specifiers));
|
|
44
|
+
continue;
|
|
45
|
+
}
|
|
46
|
+
if (part.type === 'themes') {
|
|
47
|
+
results.push(await this.createThemeStyleCode(context, cache, part.themeNames, false));
|
|
48
|
+
continue;
|
|
49
|
+
}
|
|
50
|
+
results.push(this.createModuleStyleCode(context));
|
|
51
|
+
}
|
|
52
|
+
return mergeLoadResults(...results);
|
|
45
53
|
}
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
)
|
|
51
|
-
|
|
54
|
+
async createDependencyStyleCode(context, cache, specifiers, mapSpecifier = (specifier) => specifier) {
|
|
55
|
+
const results = [];
|
|
56
|
+
const imports = [];
|
|
57
|
+
const watchFiles = [context.configPath];
|
|
58
|
+
for (const specifier of specifiers) {
|
|
59
|
+
const outputSpecifier = mapSpecifier(specifier);
|
|
60
|
+
const parsed = this.parsePackageStyleIdInRequest(outputSpecifier, cache);
|
|
61
|
+
if (parsed) {
|
|
62
|
+
results.push(await this.createPackageStyleCode(parsed, cache));
|
|
63
|
+
continue;
|
|
64
|
+
}
|
|
65
|
+
const resolvedSpecifier = toDevDependencyImportSpecifier(context, outputSpecifier);
|
|
66
|
+
imports.push(resolvedSpecifier.specifier);
|
|
67
|
+
if (resolvedSpecifier.watchFile) {
|
|
68
|
+
watchFiles.push(resolvedSpecifier.watchFile);
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
return mergeLoadResults({
|
|
72
|
+
code: createImportCode(imports),
|
|
73
|
+
watchFiles,
|
|
74
|
+
}, ...results);
|
|
52
75
|
}
|
|
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));
|
|
76
|
+
async createExternalStyleCode(context, cache) {
|
|
77
|
+
const results = [];
|
|
78
|
+
for (const part of createExternalEntryParts(context.normalizedConfig)) {
|
|
79
|
+
results.push(await this.createDependencyStyleCode(context, cache, part.specifiers, (specifier) => this.toDevExternalStyleSpecifier(specifier, cache)));
|
|
80
|
+
}
|
|
81
|
+
return mergeLoadResults(...results);
|
|
76
82
|
}
|
|
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
|
-
|
|
83
|
+
async createThemeStyleCode(context, cache, themeNames, includeDependencies = true) {
|
|
84
|
+
const { themeFiles } = context.packageContext;
|
|
85
|
+
const targetThemeNames = themeNames ?? context.packageContext.themeNames;
|
|
86
|
+
const root = context.styleProcessor.createRoot();
|
|
87
|
+
const watchFiles = [context.configPath, ...themeFiles.values()];
|
|
88
|
+
const dependencyResults = [];
|
|
89
|
+
for (const themeName of targetThemeNames) {
|
|
90
|
+
for (const part of createThemeEntryParts(context.normalizedConfig, themeName, {
|
|
91
|
+
includeDependencies,
|
|
92
|
+
})) {
|
|
93
|
+
if (part.type === 'dependencies') {
|
|
94
|
+
dependencyResults.push(await this.createDependencyStyleCode(context, cache, part.specifiers));
|
|
95
|
+
continue;
|
|
96
|
+
}
|
|
97
|
+
const themeFile = themeFiles.get(part.themeName);
|
|
98
|
+
if (!themeFile)
|
|
99
|
+
continue;
|
|
100
|
+
const content = context.styleProcessor.readStyleFile(themeFile);
|
|
101
|
+
if (content.trim()) {
|
|
102
|
+
context.styleProcessor.appendStyleContent(root, content, themeFile);
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
return mergeLoadResults({
|
|
107
|
+
code: '',
|
|
108
|
+
watchFiles,
|
|
109
|
+
}, ...dependencyResults, {
|
|
110
|
+
code: root.nodes?.length ? context.styleProcessor.stringify(root) : '',
|
|
111
|
+
watchFiles: [],
|
|
112
|
+
});
|
|
103
113
|
}
|
|
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
|
-
);
|
|
114
|
+
createModuleStyleCode(context) {
|
|
115
|
+
const { styleFiles } = context.packageContext;
|
|
116
|
+
const root = context.styleProcessor.createRoot();
|
|
117
|
+
const seen = new Set();
|
|
118
|
+
for (const styleFile of styleFiles) {
|
|
119
|
+
const content = context.styleProcessor.readStyleFile(styleFile, seen);
|
|
120
|
+
if (content.trim()) {
|
|
121
|
+
context.styleProcessor.appendStyleContent(root, content, styleFile);
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
return {
|
|
125
|
+
code: root.nodes?.length ? context.styleProcessor.stringify(root) : '',
|
|
126
|
+
watchFiles: [context.configPath, ...styleFiles],
|
|
127
|
+
};
|
|
123
128
|
}
|
|
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;
|
|
129
|
+
async createSourceModuleStyleCode(context, cache, stylePath) {
|
|
130
|
+
const sourceModuleDir = removeStyleExtension(stylePath);
|
|
131
|
+
const { styleFiles, sourceFiles } = context.packageContext;
|
|
132
|
+
const entry = createComponentStyleEntryPlan(context.packageContext, sourceModuleDir);
|
|
133
|
+
const sourceStyleDir = path.join(context.sourceRoot, sourceModuleDir, this.config.output.styleDir);
|
|
134
|
+
const moduleStyleResults = [];
|
|
135
|
+
const moduleStyleSpecifiers = [];
|
|
136
|
+
const moduleStyleWatchFiles = [];
|
|
137
|
+
for (const specifier of entry.moduleStyleImports) {
|
|
138
|
+
const result = this.toDevModuleImportSpecifier(context, cache, sourceStyleDir, specifier);
|
|
139
|
+
const parsed = this.parsePackageStyleIdInRequest(result, cache);
|
|
140
|
+
if (parsed) {
|
|
141
|
+
moduleStyleResults.push(await this.createPackageStyleCode(parsed, cache));
|
|
142
|
+
continue;
|
|
143
|
+
}
|
|
144
|
+
const resolvedSpecifier = toDevDependencyImportSpecifier(context, result);
|
|
145
|
+
moduleStyleSpecifiers.push(resolvedSpecifier.specifier);
|
|
146
|
+
if (resolvedSpecifier.watchFile) {
|
|
147
|
+
moduleStyleWatchFiles.push(resolvedSpecifier.watchFile);
|
|
148
|
+
}
|
|
154
149
|
}
|
|
155
|
-
const
|
|
156
|
-
|
|
157
|
-
const
|
|
158
|
-
|
|
159
|
-
|
|
150
|
+
const root = context.styleProcessor.createRoot();
|
|
151
|
+
const seen = new Set();
|
|
152
|
+
for (const ownStyleFile of entry.ownStyleFiles) {
|
|
153
|
+
const content = context.styleProcessor.readStyleFile(ownStyleFile, seen);
|
|
154
|
+
if (content.trim()) {
|
|
155
|
+
context.styleProcessor.appendStyleContent(root, content, ownStyleFile);
|
|
156
|
+
}
|
|
160
157
|
}
|
|
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
|
-
}
|
|
158
|
+
const ownStyleCode = root.nodes?.length
|
|
159
|
+
? context.styleProcessor.stringify(root)
|
|
160
|
+
: '';
|
|
161
|
+
return mergeLoadResults(...moduleStyleResults, {
|
|
162
|
+
code: [createImportCode(moduleStyleSpecifiers), ownStyleCode]
|
|
163
|
+
.filter((code) => code.trim())
|
|
164
|
+
.join('\n'),
|
|
165
|
+
watchFiles: [
|
|
166
|
+
context.configPath,
|
|
167
|
+
...styleFiles,
|
|
168
|
+
...moduleStyleWatchFiles,
|
|
169
|
+
...sourceFiles.filter((file) => /\.(ts|tsx)$/.test(file)),
|
|
170
|
+
],
|
|
171
|
+
});
|
|
224
172
|
}
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
return mergeLoadResults(...moduleStyleResults, {
|
|
237
|
-
code: [createImportCode(moduleStyleSpecifiers), ownStyleCode]
|
|
238
|
-
.filter((code) => code.trim())
|
|
239
|
-
.join('\n'),
|
|
240
|
-
watchFiles: [
|
|
241
|
-
context.configPath,
|
|
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);
|
|
173
|
+
toDevModuleImportSpecifier(context, cache, sourceStyleDir, specifier) {
|
|
174
|
+
if (!specifier.startsWith('.')) {
|
|
175
|
+
return this.toDevExternalStyleSpecifier(specifier, cache);
|
|
176
|
+
}
|
|
177
|
+
const outputStyleEntry = path.resolve(sourceStyleDir, specifier);
|
|
178
|
+
const styleEntrySuffix = `${path.sep}${this.config.output.styleDir}${path.sep}${this.config.output.indexStyleFile}`;
|
|
179
|
+
if (!outputStyleEntry.endsWith(styleEntrySuffix)) {
|
|
180
|
+
return toFsSpecifier(outputStyleEntry);
|
|
181
|
+
}
|
|
182
|
+
const sourceModuleDir = path.relative(context.sourceRoot, outputStyleEntry.slice(0, -styleEntrySuffix.length));
|
|
183
|
+
return `${context.packageName}/${toPosixPath(sourceModuleDir)}.css`;
|
|
251
184
|
}
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
185
|
+
toDevExternalStyleSpecifier(specifier, cache) {
|
|
186
|
+
const parsed = parsePackageStyleSpecifier(specifier);
|
|
187
|
+
if (!parsed)
|
|
188
|
+
return specifier;
|
|
189
|
+
if (cache.isKnownPackageName(parsed.packageName)) {
|
|
190
|
+
if (parsed.stylePath === STYLE_ENTRY) {
|
|
191
|
+
return `${parsed.packageName}/${EXTERNAL_ENTRY}`;
|
|
192
|
+
}
|
|
193
|
+
if (parsed.stylePath ===
|
|
194
|
+
[this.config.output.styleDir, this.config.output.indexStyleFile].join('/')) {
|
|
195
|
+
return `${parsed.packageName}/${EXTERNAL_ENTRY}`;
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
return specifier;
|
|
256
199
|
}
|
|
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
|
-
}
|
|
200
|
+
parsePackageStyleIdInRequest(id, cache) {
|
|
201
|
+
return parsePackageStyleId(id, cache.getPackageNames());
|
|
278
202
|
}
|
|
279
|
-
return specifier;
|
|
280
|
-
}
|
|
281
|
-
parsePackageStyleIdInRequest(id, cache) {
|
|
282
|
-
return parsePackageStyleId(id, cache.getPackageNames());
|
|
283
|
-
}
|
|
284
203
|
}
|
|
@@ -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
|
+
workspaceRoot: 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, 'workspaceRoot' | 'mode'>> & Omit<ModuleStyleGraphOptions, 'workspaceRoot'>;
|
|
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): void;
|
|
16
|
+
hotUpdate: {
|
|
17
|
+
order: "pre";
|
|
18
|
+
handler(context: HotUpdateOptions): never[] | undefined;
|
|
19
|
+
};
|
|
24
20
|
};
|