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.
Files changed (105) hide show
  1. package/README.md +37 -1
  2. package/dist/build/bundleConfig.d.ts +1 -4
  3. package/dist/build/bundleConfig.js +59 -71
  4. package/dist/build/cleanOutput.d.ts +2 -8
  5. package/dist/build/cleanOutput.js +7 -7
  6. package/dist/build/moduleConfig.d.ts +1 -3
  7. package/dist/build/moduleConfig.js +21 -40
  8. package/dist/build/runTsdown.d.ts +2 -5
  9. package/dist/build/runTsdown.js +18 -23
  10. package/dist/build/tsdown/common.d.ts +17 -28
  11. package/dist/build/tsdown/common.js +22 -25
  12. package/dist/build/tsdown/context.d.ts +16 -20
  13. package/dist/build/tsdown/context.js +41 -45
  14. package/dist/build/tsdown/define.d.ts +2 -7
  15. package/dist/build/tsdown/define.js +13 -22
  16. package/dist/build/tsdown/dependencies.d.ts +4 -12
  17. package/dist/build/tsdown/dependencies.js +47 -51
  18. package/dist/build/tsdown/entries.d.ts +4 -6
  19. package/dist/build/tsdown/entries.js +39 -38
  20. package/dist/build/tsdown/parseModuleId.d.ts +4 -4
  21. package/dist/build/tsdown/parseModuleId.js +92 -77
  22. package/dist/build/tsdown/types.d.ts +24 -31
  23. package/dist/build/tsdownConfig.js +1 -4
  24. package/dist/config.d.ts +37 -37
  25. package/dist/config.js +38 -41
  26. package/dist/configLoader.d.ts +2 -7
  27. package/dist/configLoader.js +59 -64
  28. package/dist/css/config.js +8 -8
  29. package/dist/css/constants.d.ts +7 -7
  30. package/dist/css/constants.js +1 -1
  31. package/dist/css/core/resolvers/packageImports.d.ts +1 -5
  32. package/dist/css/core/resolvers/packageImports.js +35 -40
  33. package/dist/css/core/resolvers/relative.d.ts +1 -4
  34. package/dist/css/core/resolvers/relative.js +3 -2
  35. package/dist/css/core/resolvers/tsconfigPaths.d.ts +1 -5
  36. package/dist/css/core/resolvers/tsconfigPaths.js +59 -66
  37. package/dist/css/core/style/dependencies.d.ts +6 -16
  38. package/dist/css/core/style/dependencies.js +35 -38
  39. package/dist/css/core/style/entries.d.ts +35 -58
  40. package/dist/css/core/style/entries.js +22 -33
  41. package/dist/css/core/style/files.d.ts +2 -7
  42. package/dist/css/core/style/files.js +11 -11
  43. package/dist/css/core/style/specifier.d.ts +41 -8
  44. package/dist/css/core/style/specifier.js +107 -18
  45. package/dist/css/core/styleImports/autoImportRules.d.ts +13 -0
  46. package/dist/css/core/styleImports/autoImportRules.js +68 -0
  47. package/dist/css/core/styleImports/collector.d.ts +12 -25
  48. package/dist/css/core/styleImports/collector.js +101 -206
  49. package/dist/css/core/styleImports/sourceImportExportAnalyzer.d.ts +11 -0
  50. package/dist/css/core/styleImports/sourceImportExportAnalyzer.js +173 -0
  51. package/dist/css/core/styleModuleEntryPlanner.d.ts +21 -24
  52. package/dist/css/core/styleModuleEntryPlanner.js +45 -62
  53. package/dist/css/core/stylePackageContext.d.ts +16 -20
  54. package/dist/css/core/stylePackageContext.js +33 -49
  55. package/dist/css/core/styleProcessor.js +105 -104
  56. package/dist/css/core/workspaceStyleResolver.d.ts +8 -15
  57. package/dist/css/core/workspaceStyleResolver.js +34 -76
  58. package/dist/css/production/builder.d.ts +9 -16
  59. package/dist/css/production/builder.js +51 -57
  60. package/dist/css/production/format/entryWriter.js +36 -49
  61. package/dist/css/production/format/externalWriter.js +21 -33
  62. package/dist/css/production/format/{componentWriter.d.ts → moduleEntryWriter.d.ts} +1 -1
  63. package/dist/css/production/format/moduleEntryWriter.js +48 -0
  64. package/dist/css/production/format/moduleWriter.js +23 -26
  65. package/dist/css/production/format/shared.d.ts +8 -15
  66. package/dist/css/production/format/shared.js +4 -9
  67. package/dist/css/production/format/sourceWriter.js +11 -11
  68. package/dist/css/production/format/themeWriter.js +56 -71
  69. package/dist/css/production/moduleOutputWriter.d.ts +18 -21
  70. package/dist/css/production/moduleOutputWriter.js +58 -67
  71. package/dist/css/production/packageEntryWriter.d.ts +12 -15
  72. package/dist/css/production/packageEntryWriter.js +42 -45
  73. package/dist/css/vite/hmr.d.ts +11 -11
  74. package/dist/css/vite/hmr.js +93 -109
  75. package/dist/css/vite/moduleGraph/devDependency.d.ts +7 -12
  76. package/dist/css/vite/moduleGraph/devDependency.js +8 -8
  77. package/dist/css/vite/moduleGraph/graph.d.ts +20 -23
  78. package/dist/css/vite/moduleGraph/graph.js +51 -50
  79. package/dist/css/vite/moduleGraph/loadResult.d.ts +3 -5
  80. package/dist/css/vite/moduleGraph/loadResult.js +7 -9
  81. package/dist/css/vite/moduleGraph/packageSource/monorepo.d.ts +16 -7
  82. package/dist/css/vite/moduleGraph/packageSource/monorepo.js +60 -68
  83. package/dist/css/vite/moduleGraph/packageSource/singlePackage.d.ts +21 -0
  84. package/dist/css/vite/moduleGraph/packageSource/singlePackage.js +63 -0
  85. package/dist/css/vite/moduleGraph/packageSource/types.d.ts +7 -7
  86. package/dist/css/vite/moduleGraph/requestCache.d.ts +46 -57
  87. package/dist/css/vite/moduleGraph/requestCache.js +53 -51
  88. package/dist/css/vite/moduleGraph/styleCodeFactory.d.ts +15 -18
  89. package/dist/css/vite/moduleGraph/styleCodeFactory.js +173 -264
  90. package/dist/css/vite/moduleGraph/styleId.d.ts +3 -6
  91. package/dist/css/vite/moduleGraph/styleId.js +12 -11
  92. package/dist/css/vite/moduleGraph/types.d.ts +11 -14
  93. package/dist/css/vite/vitePlugin.d.ts +16 -20
  94. package/dist/css/vite/vitePlugin.js +117 -109
  95. package/dist/css/watch/watcher.d.ts +15 -21
  96. package/dist/css/watch/watcher.js +84 -81
  97. package/dist/index.d.ts +3 -25
  98. package/dist/index.js +2 -9
  99. package/dist/types.d.ts +59 -62
  100. package/dist/utils.d.ts +3 -7
  101. package/dist/utils.js +50 -47
  102. package/package.json +31 -33
  103. package/dist/css/core/styleImports/sourceReference.d.ts +0 -19
  104. package/dist/css/core/styleImports/sourceReference.js +0 -193
  105. 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
- private readonly config;
6
- constructor(config: ModuleStyleBuildConfig);
7
- createPackageStyleCode(
8
- parsed: PackageStyleId,
9
- cache: ModuleStyleGraphRequestCache,
10
- ): Promise<{
11
- code: string;
12
- watchFiles: string[];
13
- }>;
14
- private createStyleCode;
15
- private createDependencyStyleCode;
16
- private createExternalStyleCode;
17
- private createThemeStyleCode;
18
- private createModuleStyleCode;
19
- private createSourceModuleStyleCode;
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
- 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';
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
- 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
- };
10
+ config;
11
+ constructor(config) {
12
+ this.config = config;
36
13
  }
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);
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
- if (parsed.stylePath === MODULE_ENTRY) {
44
- return this.createModuleStyleCode(context);
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
- 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
- ]);
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
- 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));
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
- 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
- }
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
- 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
- );
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
- 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;
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 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);
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
- 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
- }
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
- 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);
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
- 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);
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
- 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
- }
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
- 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
+ root: 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, 'root' | 'mode'>> & Omit<ModuleStyleGraphOptions, 'root'>;
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): Promise<void>;
16
+ hotUpdate: {
17
+ order: "pre";
18
+ handler(context: HotUpdateOptions): never[] | undefined;
19
+ };
24
20
  };