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.
Files changed (95) hide show
  1. package/dist/build/bundleConfig.d.ts +1 -4
  2. package/dist/build/bundleConfig.js +59 -71
  3. package/dist/build/cleanOutput.d.ts +2 -8
  4. package/dist/build/cleanOutput.js +7 -7
  5. package/dist/build/moduleConfig.d.ts +1 -3
  6. package/dist/build/moduleConfig.js +21 -40
  7. package/dist/build/runTsdown.d.ts +2 -5
  8. package/dist/build/runTsdown.js +18 -23
  9. package/dist/build/tsdown/common.d.ts +17 -28
  10. package/dist/build/tsdown/common.js +22 -25
  11. package/dist/build/tsdown/context.d.ts +16 -20
  12. package/dist/build/tsdown/context.js +41 -45
  13. package/dist/build/tsdown/define.d.ts +2 -7
  14. package/dist/build/tsdown/define.js +13 -22
  15. package/dist/build/tsdown/dependencies.d.ts +4 -12
  16. package/dist/build/tsdown/dependencies.js +47 -51
  17. package/dist/build/tsdown/entries.d.ts +4 -6
  18. package/dist/build/tsdown/entries.js +39 -38
  19. package/dist/build/tsdown/parseModuleId.d.ts +4 -4
  20. package/dist/build/tsdown/parseModuleId.js +92 -77
  21. package/dist/build/tsdown/types.d.ts +24 -31
  22. package/dist/build/tsdownConfig.js +1 -4
  23. package/dist/config.d.ts +37 -37
  24. package/dist/config.js +38 -41
  25. package/dist/configLoader.d.ts +2 -7
  26. package/dist/configLoader.js +59 -64
  27. package/dist/css/config.js +8 -8
  28. package/dist/css/constants.d.ts +6 -6
  29. package/dist/css/core/resolvers/packageImports.d.ts +1 -5
  30. package/dist/css/core/resolvers/packageImports.js +35 -40
  31. package/dist/css/core/resolvers/relative.d.ts +1 -4
  32. package/dist/css/core/resolvers/relative.js +3 -2
  33. package/dist/css/core/resolvers/tsconfigPaths.d.ts +1 -5
  34. package/dist/css/core/resolvers/tsconfigPaths.js +59 -66
  35. package/dist/css/core/style/dependencies.d.ts +6 -16
  36. package/dist/css/core/style/dependencies.js +35 -38
  37. package/dist/css/core/style/entries.d.ts +35 -58
  38. package/dist/css/core/style/entries.js +20 -31
  39. package/dist/css/core/style/files.d.ts +2 -7
  40. package/dist/css/core/style/files.js +11 -11
  41. package/dist/css/core/style/specifier.d.ts +5 -8
  42. package/dist/css/core/style/specifier.js +21 -18
  43. package/dist/css/core/styleImports/collector.d.ts +17 -25
  44. package/dist/css/core/styleImports/collector.js +162 -201
  45. package/dist/css/core/styleImports/sourceReference.d.ts +8 -16
  46. package/dist/css/core/styleImports/sourceReference.js +153 -173
  47. package/dist/css/core/styleModuleEntryPlanner.d.ts +21 -24
  48. package/dist/css/core/styleModuleEntryPlanner.js +44 -61
  49. package/dist/css/core/stylePackageContext.d.ts +16 -20
  50. package/dist/css/core/stylePackageContext.js +33 -49
  51. package/dist/css/core/styleProcessor.js +105 -104
  52. package/dist/css/core/workspaceStyleResolver.d.ts +9 -15
  53. package/dist/css/core/workspaceStyleResolver.js +62 -72
  54. package/dist/css/production/builder.d.ts +9 -16
  55. package/dist/css/production/builder.js +51 -57
  56. package/dist/css/production/format/componentWriter.js +45 -66
  57. package/dist/css/production/format/entryWriter.js +36 -49
  58. package/dist/css/production/format/externalWriter.js +21 -33
  59. package/dist/css/production/format/moduleWriter.js +23 -26
  60. package/dist/css/production/format/shared.d.ts +8 -15
  61. package/dist/css/production/format/shared.js +5 -6
  62. package/dist/css/production/format/sourceWriter.js +11 -11
  63. package/dist/css/production/format/themeWriter.js +56 -71
  64. package/dist/css/production/moduleOutputWriter.d.ts +18 -21
  65. package/dist/css/production/moduleOutputWriter.js +56 -65
  66. package/dist/css/production/packageEntryWriter.d.ts +12 -15
  67. package/dist/css/production/packageEntryWriter.js +42 -45
  68. package/dist/css/vite/hmr.d.ts +11 -11
  69. package/dist/css/vite/hmr.js +93 -109
  70. package/dist/css/vite/moduleGraph/devDependency.d.ts +7 -12
  71. package/dist/css/vite/moduleGraph/devDependency.js +8 -8
  72. package/dist/css/vite/moduleGraph/graph.d.ts +20 -23
  73. package/dist/css/vite/moduleGraph/graph.js +46 -49
  74. package/dist/css/vite/moduleGraph/loadResult.d.ts +3 -5
  75. package/dist/css/vite/moduleGraph/loadResult.js +7 -9
  76. package/dist/css/vite/moduleGraph/packageSource/monorepo.d.ts +4 -6
  77. package/dist/css/vite/moduleGraph/packageSource/monorepo.js +59 -64
  78. package/dist/css/vite/moduleGraph/packageSource/types.d.ts +7 -7
  79. package/dist/css/vite/moduleGraph/requestCache.d.ts +46 -57
  80. package/dist/css/vite/moduleGraph/requestCache.js +53 -51
  81. package/dist/css/vite/moduleGraph/styleCodeFactory.d.ts +15 -18
  82. package/dist/css/vite/moduleGraph/styleCodeFactory.js +182 -263
  83. package/dist/css/vite/moduleGraph/styleId.d.ts +3 -6
  84. package/dist/css/vite/moduleGraph/styleId.js +12 -11
  85. package/dist/css/vite/moduleGraph/types.d.ts +11 -14
  86. package/dist/css/vite/vitePlugin.d.ts +16 -20
  87. package/dist/css/vite/vitePlugin.js +110 -109
  88. package/dist/css/watch/watcher.d.ts +15 -21
  89. package/dist/css/watch/watcher.js +83 -80
  90. package/dist/index.d.ts +3 -25
  91. package/dist/index.js +2 -9
  92. package/dist/types.d.ts +59 -62
  93. package/dist/utils.d.ts +3 -7
  94. package/dist/utils.js +50 -47
  95. 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
- EXTERNAL_ENTRY,
7
- MODULE_ENTRY,
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
- config;
26
- constructor(config) {
27
- this.config = config;
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
- if (parsed.stylePath === STYLE_ENTRY) {
38
- return this.createStyleCode(context, cache);
39
- }
40
- if (parsed.stylePath === EXTERNAL_ENTRY) {
41
- return this.createExternalStyleCode(context, cache);
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
- if (parsed.stylePath === MODULE_ENTRY) {
44
- return this.createModuleStyleCode(context);
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
- if (parsed.stylePath.startsWith(THEMES_ENTRY_PREFIX)) {
47
- return this.createThemeStyleCode(context, cache, [
48
- removeStyleExtension(
49
- parsed.stylePath.slice(THEMES_ENTRY_PREFIX.length),
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
- return this.createSourceModuleStyleCode(context, cache, parsed.stylePath);
54
- }
55
- async createStyleCode(context, cache) {
56
- const results = [];
57
- for (const part of createStyleEntryParts(context.normalizedConfig)) {
58
- if (part.type === 'dependencies') {
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
- return mergeLoadResults(...results);
78
- }
79
- async createDependencyStyleCode(
80
- context,
81
- cache,
82
- specifiers,
83
- mapSpecifier = (specifier) => specifier,
84
- ) {
85
- const results = [];
86
- const imports = [];
87
- const watchFiles = [context.configPath];
88
- for (const specifier of specifiers) {
89
- const outputSpecifier = mapSpecifier(specifier);
90
- const parsed = this.parsePackageStyleIdInRequest(outputSpecifier, cache);
91
- if (parsed) {
92
- results.push(await this.createPackageStyleCode(parsed, cache));
93
- continue;
94
- }
95
- const resolvedSpecifier = toDevDependencyImportSpecifier(
96
- context,
97
- outputSpecifier,
98
- );
99
- imports.push(resolvedSpecifier.specifier);
100
- if (resolvedSpecifier.watchFile) {
101
- watchFiles.push(resolvedSpecifier.watchFile);
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
- return mergeLoadResults(
105
- {
106
- code: createImportCode(imports),
107
- watchFiles,
108
- },
109
- ...results,
110
- );
111
- }
112
- async createExternalStyleCode(context, cache) {
113
- const results = [];
114
- for (const part of createExternalEntryParts(context.normalizedConfig)) {
115
- results.push(
116
- await this.createDependencyStyleCode(
117
- context,
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
- return mergeLoadResults(...results);
125
- }
126
- async createThemeStyleCode(
127
- context,
128
- cache,
129
- themeNames,
130
- includeDependencies = true,
131
- ) {
132
- const { themeFiles } = context.packageContext;
133
- const targetThemeNames = themeNames ?? context.packageContext.themeNames;
134
- const root = context.styleProcessor.createRoot();
135
- const watchFiles = [context.configPath, ...themeFiles.values()];
136
- const dependencyResults = [];
137
- for (const themeName of targetThemeNames) {
138
- for (const part of createThemeEntryParts(
139
- context.normalizedConfig,
140
- themeName,
141
- {
142
- includeDependencies,
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 themeFile = themeFiles.get(part.themeName);
156
- if (!themeFile) continue;
157
- const content = context.styleProcessor.readStyleFile(themeFile);
158
- if (content.trim()) {
159
- context.styleProcessor.appendStyleContent(root, content, themeFile);
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
- return mergeLoadResults(
164
- {
165
- code: '',
166
- watchFiles,
167
- },
168
- ...dependencyResults,
169
- {
170
- code: root.nodes?.length ? context.styleProcessor.stringify(root) : '',
171
- watchFiles: [],
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
- 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
- }
232
- }
233
- const ownStyleCode = root.nodes?.length
234
- ? context.styleProcessor.stringify(root)
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
- const outputStyleEntry = path.resolve(sourceStyleDir, specifier);
253
- const styleEntrySuffix = `${path.sep}${this.config.output.styleDir}${path.sep}${this.config.output.indexStyleFile}`;
254
- if (!outputStyleEntry.endsWith(styleEntrySuffix)) {
255
- return toFsSpecifier(outputStyleEntry);
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
- const sourceModuleDir = path.relative(
258
- context.sourceRoot,
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
- id: string,
3
- packageNames: Array<string>,
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
- 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) return null;
10
- return {
11
- packageName,
12
- stylePath: id.slice(packageName.length + 1),
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
- workspaceRoot: string;
4
- packagesDir?: string;
5
- mode?: 'monorepo' | 'package';
6
- config?: ModuleStyleBuildConfig;
7
- loadAukletConfig?: LoadAukletConfig;
3
+ workspaceRoot: string;
4
+ packagesDir?: string;
5
+ mode?: 'monorepo' | 'package';
6
+ config?: ModuleStyleBuildConfig;
7
+ loadAukletConfig?: LoadAukletConfig;
8
8
  }
9
9
  export type PackageStyleId = {
10
- packageName: string;
11
- stylePath: string;
10
+ packageName: string;
11
+ stylePath: string;
12
12
  };
13
13
  export type PackageStyleLoadResult = {
14
- code: string;
15
- watchFiles: Array<string>;
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
- name: string;
9
- apply: 'serve';
10
- enforce: 'pre';
11
- configResolved(config: { root: string }): void;
12
- resolveId(id: string): string | null;
13
- load(
14
- this: {
15
- addWatchFile?: (file: string) => void;
16
- },
17
- id: string,
18
- ): Promise<string | null>;
19
- configureServer(server: ViteDevServer): void;
20
- hotUpdate: {
21
- order: 'pre';
22
- handler(context: HotUpdateOptions): never[] | undefined;
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
  };