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
@@ -3,52 +3,49 @@ import { writeStyleFile } from '#auklet/css/production/format/shared';
3
3
  import { getGlobalStyleDependencies } from '#auklet/css/core/style/dependencies';
4
4
  // Builds the package-level style entry at `dist/index.css` by aggregating local themes, dependencies, and source styles.
5
5
  export class PackageStyleEntryWriter {
6
- config;
7
- context;
8
- packageContext;
9
- resolver;
10
- styleProcessor;
11
- constructor(options) {
12
- this.config = options.config;
13
- this.context = options.context;
14
- this.packageContext = options.packageContext;
15
- this.resolver = options.packageContext.resolver;
16
- this.styleProcessor = options.packageContext.styleProcessor;
17
- }
18
- write() {
19
- const seen = new Set();
20
- const root = this.styleProcessor.createRoot();
21
- for (const stylePath of this.packageContext.themeFiles.values()) {
22
- const content = this.styleProcessor.readStyleFile(stylePath, seen);
23
- if (content.trim()) {
24
- this.styleProcessor.appendStyleContent(root, content, stylePath);
25
- }
6
+ config;
7
+ context;
8
+ packageContext;
9
+ resolver;
10
+ styleProcessor;
11
+ constructor(options) {
12
+ this.config = options.config;
13
+ this.context = options.context;
14
+ this.packageContext = options.packageContext;
15
+ this.resolver = options.packageContext.resolver;
16
+ this.styleProcessor = options.packageContext.styleProcessor;
26
17
  }
27
- for (const specifier of getGlobalStyleDependencies(
28
- this.packageContext.normalizedConfig,
29
- )) {
30
- const stylePath = this.resolver.resolveStyleDependency(specifier);
31
- if (!stylePath) continue;
32
- const content = this.styleProcessor.readStyleFile(stylePath, seen);
33
- if (content.trim()) {
34
- this.styleProcessor.appendStyleContent(root, content, stylePath);
35
- }
18
+ write() {
19
+ const seen = new Set();
20
+ const root = this.styleProcessor.createRoot();
21
+ for (const stylePath of this.packageContext.themeFiles.values()) {
22
+ const content = this.styleProcessor.readStyleFile(stylePath, seen);
23
+ if (content.trim()) {
24
+ this.styleProcessor.appendStyleContent(root, content, stylePath);
25
+ }
26
+ }
27
+ for (const specifier of getGlobalStyleDependencies(this.packageContext.normalizedConfig)) {
28
+ const stylePath = this.resolver.resolveStyleDependency(specifier);
29
+ if (!stylePath)
30
+ continue;
31
+ const content = this.styleProcessor.readStyleFile(stylePath, seen);
32
+ if (content.trim()) {
33
+ this.styleProcessor.appendStyleContent(root, content, stylePath);
34
+ }
35
+ }
36
+ for (const styleFile of this.packageContext.styleFiles) {
37
+ const content = this.styleProcessor.readStyleFile(styleFile, seen);
38
+ if (content.trim()) {
39
+ this.styleProcessor.appendStyleContent(root, content, styleFile);
40
+ }
41
+ }
42
+ if (!root.nodes?.length)
43
+ return null;
44
+ const target = path.join(this.outputRoot, this.config.output.indexStyleFile);
45
+ writeStyleFile(target, this.styleProcessor.stringify(root));
46
+ return target;
36
47
  }
37
- for (const styleFile of this.packageContext.styleFiles) {
38
- const content = this.styleProcessor.readStyleFile(styleFile, seen);
39
- if (content.trim()) {
40
- this.styleProcessor.appendStyleContent(root, content, styleFile);
41
- }
48
+ get outputRoot() {
49
+ return path.join(this.context.packageRoot, this.context.outputDir);
42
50
  }
43
- if (!root.nodes?.length) return null;
44
- const target = path.join(
45
- this.outputRoot,
46
- this.config.output.indexStyleFile,
47
- );
48
- writeStyleFile(target, this.styleProcessor.stringify(root));
49
- return target;
50
- }
51
- get outputRoot() {
52
- return path.join(this.context.packageRoot, this.context.outputDir);
53
- }
54
51
  }
@@ -1,15 +1,15 @@
1
1
  import type { HotUpdateOptions, ViteDevServer } from 'vite';
2
2
  import type { ModuleStyleGraph } from '#auklet/css/vite/moduleGraph/graph';
3
3
  export declare class AukletStyleHmr {
4
- private readonly graph;
5
- private readonly lastUpdateTimes;
6
- private suppressFullReloadUntil;
7
- private readonly virtualIdsByDependency;
8
- constructor(graph: () => ModuleStyleGraph);
9
- trackVirtualStyleDependency(file: string, virtualId: string): void;
10
- installFullReloadGuard(server: Pick<ViteDevServer, 'ws'>): void;
11
- handleStyleHotUpdate(context: HotUpdateOptions): never[] | undefined;
12
- private suppressFullReload;
13
- private shouldSuppressFullReload;
14
- private isDuplicateUpdate;
4
+ private readonly graph;
5
+ private readonly lastUpdateTimes;
6
+ private suppressFullReloadUntil;
7
+ private readonly virtualIdsByDependency;
8
+ constructor(graph: () => ModuleStyleGraph);
9
+ trackVirtualStyleDependency(file: string, virtualId: string): void;
10
+ installFullReloadGuard(server: Pick<ViteDevServer, 'ws'>): void;
11
+ handleStyleHotUpdate(context: HotUpdateOptions): never[] | undefined;
12
+ private suppressFullReload;
13
+ private shouldSuppressFullReload;
14
+ private isDuplicateUpdate;
15
15
  }
@@ -11,130 +11,114 @@ const HMR_LOG_PREFIX = '[auklet:css:vite]';
11
11
  const FULL_RELOAD_SUPPRESS_MS = 100;
12
12
  const DUPLICATE_UPDATE_IGNORE_MS = 500;
13
13
  const toBrowserVirtualPath = (id) => {
14
- return `/@id/${id.replace('\0', '__x00__')}`;
14
+ return `/@id/${id.replace('\0', '__x00__')}`;
15
15
  };
16
16
  const getRelativeFile = (file) => {
17
- return path.relative(process.cwd(), file);
17
+ return path.relative(process.cwd(), file);
18
18
  };
19
19
  const invalidateVirtualModules = (server, graph) => {
20
- const modules = [];
21
- for (const packageName of graph.getPackageNames()) {
22
- for (const entry of ['style.css', 'external.css', 'module.css']) {
23
- const module = server.moduleGraph.getModuleById(
24
- `\0auklet-css:${packageName}/${entry}`,
25
- );
26
- if (!module) continue;
27
- server.moduleGraph.invalidateModule(module);
28
- modules.push(module);
20
+ const modules = [];
21
+ for (const packageName of graph.getPackageNames()) {
22
+ for (const entry of ['style.css', 'external.css', 'module.css']) {
23
+ const module = server.moduleGraph.getModuleById(`\0auklet-css:${packageName}/${entry}`);
24
+ if (!module)
25
+ continue;
26
+ server.moduleGraph.invalidateModule(module);
27
+ modules.push(module);
28
+ }
29
29
  }
30
- }
31
- return modules;
30
+ return modules;
32
31
  };
33
32
  const addVirtualStyleDependency = (virtualIdsByDependency, file, virtualId) => {
34
- const normalizedFile = normalizeFileKey(file);
35
- const values = virtualIdsByDependency.get(normalizedFile) ?? new Set();
36
- values.add(virtualId);
37
- virtualIdsByDependency.set(normalizedFile, values);
33
+ const normalizedFile = normalizeFileKey(file);
34
+ const values = virtualIdsByDependency.get(normalizedFile) ?? new Set();
35
+ values.add(virtualId);
36
+ virtualIdsByDependency.set(normalizedFile, values);
38
37
  };
39
38
  const getDependencyVirtualIds = (virtualIdsByDependency, file) => {
40
- return Array.from(virtualIdsByDependency.get(normalizeFileKey(file)) ?? []);
39
+ return Array.from(virtualIdsByDependency.get(normalizeFileKey(file)) ?? []);
41
40
  };
42
41
  const getDependencyVirtualModules = (virtualIdsByDependency, server, file) => {
43
- return getDependencyVirtualIds(virtualIdsByDependency, file).flatMap((id) => {
44
- const module = server.moduleGraph.getModuleById(id);
45
- return module ? [module] : [];
46
- });
42
+ return getDependencyVirtualIds(virtualIdsByDependency, file).flatMap((id) => {
43
+ const module = server.moduleGraph.getModuleById(id);
44
+ return module ? [module] : [];
45
+ });
47
46
  };
48
47
  export class AukletStyleHmr {
49
- graph;
50
- lastUpdateTimes = new Map();
51
- suppressFullReloadUntil = 0;
52
- virtualIdsByDependency = new Map();
53
- constructor(graph) {
54
- this.graph = graph;
55
- }
56
- trackVirtualStyleDependency(file, virtualId) {
57
- addVirtualStyleDependency(this.virtualIdsByDependency, file, virtualId);
58
- }
59
- installFullReloadGuard(server) {
60
- const send = server.ws.send.bind(server.ws);
61
- server.ws.send = (payload, data) => {
62
- if (
63
- typeof payload !== 'string' &&
64
- payload.type === 'full-reload' &&
65
- this.shouldSuppressFullReload()
66
- ) {
67
- console.info(`${HMR_LOG_PREFIX} suppressed package css full-reload`);
68
- return;
69
- }
70
- if (typeof payload === 'string') {
71
- send(payload, data);
72
- return;
73
- }
74
- send(payload);
75
- };
76
- }
77
- handleStyleHotUpdate(context) {
78
- const graph = this.graph();
79
- if (
80
- !graph.isSourceGraphFile(context.file) ||
81
- !graph.isStyleFile(context.file)
82
- ) {
83
- return;
48
+ graph;
49
+ lastUpdateTimes = new Map();
50
+ suppressFullReloadUntil = 0;
51
+ virtualIdsByDependency = new Map();
52
+ constructor(graph) {
53
+ this.graph = graph;
84
54
  }
85
- if (this.isDuplicateUpdate(context.file)) {
86
- return [];
55
+ trackVirtualStyleDependency(file, virtualId) {
56
+ addVirtualStyleDependency(this.virtualIdsByDependency, file, virtualId);
87
57
  }
88
- this.suppressFullReload();
89
- const virtualIds = getDependencyVirtualIds(
90
- this.virtualIdsByDependency,
91
- context.file,
92
- );
93
- const modules = getDependencyVirtualModules(
94
- this.virtualIdsByDependency,
95
- context.server,
96
- context.file,
97
- );
98
- for (const module of modules) {
99
- context.server.moduleGraph.invalidateModule(module);
58
+ installFullReloadGuard(server) {
59
+ const send = server.ws.send.bind(server.ws);
60
+ server.ws.send = ((payload, data) => {
61
+ if (typeof payload !== 'string' &&
62
+ payload.type === 'full-reload' &&
63
+ this.shouldSuppressFullReload()) {
64
+ console.info(`${HMR_LOG_PREFIX} suppressed package css full-reload`);
65
+ return;
66
+ }
67
+ if (typeof payload === 'string') {
68
+ send(payload, data);
69
+ return;
70
+ }
71
+ send(payload);
72
+ });
100
73
  }
101
- invalidateVirtualModules(context.server, graph);
102
- const updates = virtualIds.map((id) => {
103
- const browserPath = toBrowserVirtualPath(id);
104
- return {
105
- type: 'js-update',
106
- path: browserPath,
107
- acceptedPath: browserPath,
108
- timestamp: context.timestamp,
109
- explicitImportRequired: false,
110
- isWithinCircularImport: false,
111
- };
112
- });
113
- console.info(
114
- `${HMR_LOG_PREFIX} package css hmr ${getRelativeFile(
115
- context.file,
116
- )} tracked=${virtualIds.length} updates=${updates.length}`,
117
- );
118
- if (updates.length) {
119
- context.server.ws.send({
120
- type: 'update',
121
- updates,
122
- });
74
+ handleStyleHotUpdate(context) {
75
+ const graph = this.graph();
76
+ if (!graph.isSourceGraphFile(context.file) ||
77
+ !graph.isStyleFile(context.file)) {
78
+ return;
79
+ }
80
+ if (this.isDuplicateUpdate(context.file)) {
81
+ return [];
82
+ }
83
+ this.suppressFullReload();
84
+ const virtualIds = getDependencyVirtualIds(this.virtualIdsByDependency, context.file);
85
+ const modules = getDependencyVirtualModules(this.virtualIdsByDependency, context.server, context.file);
86
+ for (const module of modules) {
87
+ context.server.moduleGraph.invalidateModule(module);
88
+ }
89
+ invalidateVirtualModules(context.server, graph);
90
+ const updates = virtualIds.map((id) => {
91
+ const browserPath = toBrowserVirtualPath(id);
92
+ return {
93
+ type: 'js-update',
94
+ path: browserPath,
95
+ acceptedPath: browserPath,
96
+ timestamp: context.timestamp,
97
+ explicitImportRequired: false,
98
+ isWithinCircularImport: false,
99
+ };
100
+ });
101
+ console.info(`${HMR_LOG_PREFIX} package css hmr ${getRelativeFile(context.file)} tracked=${virtualIds.length} updates=${updates.length}`);
102
+ if (updates.length) {
103
+ context.server.ws.send({
104
+ type: 'update',
105
+ updates,
106
+ });
107
+ }
108
+ return [];
109
+ }
110
+ suppressFullReload() {
111
+ this.suppressFullReloadUntil = Date.now() + FULL_RELOAD_SUPPRESS_MS;
112
+ }
113
+ shouldSuppressFullReload() {
114
+ return Date.now() <= this.suppressFullReloadUntil;
115
+ }
116
+ isDuplicateUpdate(file) {
117
+ const now = Date.now();
118
+ const normalizedFile = normalizeFileKey(file);
119
+ const lastUpdateTime = this.lastUpdateTimes.get(normalizedFile) ?? 0;
120
+ const isDuplicate = now - lastUpdateTime < DUPLICATE_UPDATE_IGNORE_MS;
121
+ this.lastUpdateTimes.set(normalizedFile, now);
122
+ return isDuplicate;
123
123
  }
124
- return [];
125
- }
126
- suppressFullReload() {
127
- this.suppressFullReloadUntil = Date.now() + FULL_RELOAD_SUPPRESS_MS;
128
- }
129
- shouldSuppressFullReload() {
130
- return Date.now() <= this.suppressFullReloadUntil;
131
- }
132
- isDuplicateUpdate(file) {
133
- const now = Date.now();
134
- const normalizedFile = normalizeFileKey(file);
135
- const lastUpdateTime = this.lastUpdateTimes.get(normalizedFile) ?? 0;
136
- const isDuplicate = now - lastUpdateTime < DUPLICATE_UPDATE_IGNORE_MS;
137
- this.lastUpdateTimes.set(normalizedFile, now);
138
- return isDuplicate;
139
- }
140
124
  }
@@ -1,13 +1,8 @@
1
1
  import type { PackageStyleContext } from '#auklet/css/vite/moduleGraph/requestCache';
2
- export declare function toDevDependencyImportSpecifier(
3
- context: PackageStyleContext,
4
- specifier: string,
5
- ):
6
- | {
7
- specifier: string;
8
- watchFile?: undefined;
9
- }
10
- | {
11
- specifier: string;
12
- watchFile: string;
13
- };
2
+ export declare function toDevDependencyImportSpecifier(context: PackageStyleContext, specifier: string): {
3
+ specifier: string;
4
+ watchFile?: undefined;
5
+ } | {
6
+ specifier: string;
7
+ watchFile: string;
8
+ };
@@ -1,12 +1,12 @@
1
1
  import { toFsSpecifier } from '#auklet/utils';
2
2
  // 在 Vite 虚拟 CSS 中,第三方 CSS 依赖要用声明它的包作为解析根。
3
3
  export function toDevDependencyImportSpecifier(context, specifier) {
4
- if (specifier.startsWith('.') || specifier.startsWith('/')) {
5
- return { specifier };
6
- }
7
- const resolved = context.resolver.resolveStyleDependency(specifier);
8
- return {
9
- specifier: toFsSpecifier(resolved),
10
- watchFile: resolved,
11
- };
4
+ if (specifier.startsWith('.') || specifier.startsWith('/')) {
5
+ return { specifier };
6
+ }
7
+ const resolved = context.resolver.resolveStyleDependency(specifier);
8
+ return {
9
+ specifier: toFsSpecifier(resolved),
10
+ watchFile: resolved,
11
+ };
12
12
  }
@@ -1,25 +1,22 @@
1
- import type {
2
- ModuleStyleGraphOptions,
3
- PackageStyleId,
4
- } from '#auklet/css/vite/moduleGraph/types';
1
+ import type { ModuleStyleGraphOptions, PackageStyleId } from '#auklet/css/vite/moduleGraph/types';
5
2
  export declare class ModuleStyleGraph {
6
- private readonly config;
7
- private readonly packageSource;
8
- private readonly styleCodeFactory;
9
- private readonly loadAukletConfig;
10
- constructor(options: ModuleStyleGraphOptions);
11
- parsePackageStyleId(id: string): {
12
- packageName: string;
13
- stylePath: string;
14
- } | null;
15
- isSourceGraphFile(file: string): boolean;
16
- isStyleConfigFile(file: string): boolean;
17
- isStyleFile(file: string): boolean;
18
- getPackageNames(): string[];
19
- getWatchRoots(): string[];
20
- createPackageStyleCode(parsed: PackageStyleId): Promise<{
21
- code: string;
22
- watchFiles: string[];
23
- }>;
24
- private createRequestCache;
3
+ private readonly config;
4
+ private readonly packageSource;
5
+ private readonly styleCodeFactory;
6
+ private readonly loadAukletConfig;
7
+ constructor(options: ModuleStyleGraphOptions);
8
+ parsePackageStyleId(id: string): {
9
+ packageName: string;
10
+ stylePath: string;
11
+ } | null;
12
+ isSourceGraphFile(file: string): boolean;
13
+ isStyleConfigFile(file: string): boolean;
14
+ isStyleFile(file: string): boolean;
15
+ getPackageNames(): string[];
16
+ getWatchRoots(): string[];
17
+ createPackageStyleCode(parsed: PackageStyleId): Promise<{
18
+ code: string;
19
+ watchFiles: string[];
20
+ }>;
21
+ private createRequestCache;
25
22
  }
@@ -9,53 +9,50 @@ import { createMonorepoPackageSource } from '#auklet/css/vite/moduleGraph/packag
9
9
  import { normalizeFileKey } from '#auklet/utils';
10
10
  // package style graph 的对外门面,负责 package source、watch 边界和请求分发。
11
11
  export class ModuleStyleGraph {
12
- config;
13
- packageSource;
14
- styleCodeFactory;
15
- loadAukletConfig;
16
- constructor(options) {
17
- this.config = options.config ?? moduleStyleBuildConfig;
18
- const mode = options.mode ?? 'monorepo';
19
- if (mode === 'package') {
20
- throw new Error('[auklet:css] package mode is not supported yet.');
21
- }
22
- this.packageSource = createMonorepoPackageSource({
23
- workspaceRoot: normalizeFileKey(options.workspaceRoot),
24
- packagesDir: options.packagesDir ?? 'packages',
25
- styleExtensions: this.config.styleExtensions,
26
- });
27
- this.loadAukletConfig = options.loadAukletConfig ?? loadAukletConfig;
28
- this.styleCodeFactory = new StyleCodeFactory(this.config);
29
- }
30
- parsePackageStyleId(id) {
31
- return parsePackageStyleId(id, this.getPackageNames());
32
- }
33
- isSourceGraphFile(file) {
34
- return this.packageSource.isSourceGraphFile(file);
35
- }
36
- isStyleConfigFile(file) {
37
- return normalizeFileKey(file).endsWith(aukletConfigFile);
38
- }
39
- isStyleFile(file) {
40
- return this.config.styleExtensions.includes(path.extname(file));
41
- }
42
- getPackageNames() {
43
- return this.packageSource.getPackageNames();
44
- }
45
- getWatchRoots() {
46
- return this.packageSource.getWatchRoots();
47
- }
48
- createPackageStyleCode(parsed) {
49
- return this.styleCodeFactory.createPackageStyleCode(
50
- parsed,
51
- this.createRequestCache(),
52
- );
53
- }
54
- createRequestCache() {
55
- return new ModuleStyleGraphRequestCache({
56
- packageSource: this.packageSource,
57
- config: this.config,
58
- loadAukletConfig: this.loadAukletConfig,
59
- });
60
- }
12
+ config;
13
+ packageSource;
14
+ styleCodeFactory;
15
+ loadAukletConfig;
16
+ constructor(options) {
17
+ this.config = options.config ?? moduleStyleBuildConfig;
18
+ const mode = options.mode ?? 'monorepo';
19
+ if (mode === 'package') {
20
+ throw new Error('[auklet:css] package mode is not supported yet.');
21
+ }
22
+ this.packageSource = createMonorepoPackageSource({
23
+ workspaceRoot: normalizeFileKey(options.workspaceRoot),
24
+ packagesDir: options.packagesDir ?? 'packages',
25
+ styleExtensions: this.config.styleExtensions,
26
+ });
27
+ this.loadAukletConfig = options.loadAukletConfig ?? loadAukletConfig;
28
+ this.styleCodeFactory = new StyleCodeFactory(this.config);
29
+ }
30
+ parsePackageStyleId(id) {
31
+ return parsePackageStyleId(id, this.getPackageNames());
32
+ }
33
+ isSourceGraphFile(file) {
34
+ return this.packageSource.isSourceGraphFile(file);
35
+ }
36
+ isStyleConfigFile(file) {
37
+ return normalizeFileKey(file).endsWith(aukletConfigFile);
38
+ }
39
+ isStyleFile(file) {
40
+ return this.config.styleExtensions.includes(path.extname(file));
41
+ }
42
+ getPackageNames() {
43
+ return this.packageSource.getPackageNames();
44
+ }
45
+ getWatchRoots() {
46
+ return this.packageSource.getWatchRoots();
47
+ }
48
+ createPackageStyleCode(parsed) {
49
+ return this.styleCodeFactory.createPackageStyleCode(parsed, this.createRequestCache());
50
+ }
51
+ createRequestCache() {
52
+ return new ModuleStyleGraphRequestCache({
53
+ packageSource: this.packageSource,
54
+ config: this.config,
55
+ loadAukletConfig: this.loadAukletConfig,
56
+ });
57
+ }
61
58
  }
@@ -1,7 +1,5 @@
1
1
  import type { PackageStyleLoadResult } from '#auklet/css/vite/moduleGraph/types';
2
- export declare function mergeLoadResults(
3
- ...results: Array<PackageStyleLoadResult>
4
- ): {
5
- code: string;
6
- watchFiles: string[];
2
+ export declare function mergeLoadResults(...results: Array<PackageStyleLoadResult>): {
3
+ code: string;
4
+ watchFiles: string[];
7
5
  };
@@ -1,12 +1,10 @@
1
1
  // 合并递归 style graph 加载结果,同时保留 CSS 顺序并去重 watch files。
2
2
  export function mergeLoadResults(...results) {
3
- return {
4
- code: results
5
- .map((result) => result.code)
6
- .filter((code) => code.trim())
7
- .join('\n'),
8
- watchFiles: Array.from(
9
- new Set(results.flatMap((result) => result.watchFiles)),
10
- ),
11
- };
3
+ return {
4
+ code: results
5
+ .map((result) => result.code)
6
+ .filter((code) => code.trim())
7
+ .join('\n'),
8
+ watchFiles: Array.from(new Set(results.flatMap((result) => result.watchFiles))),
9
+ };
12
10
  }
@@ -1,9 +1,7 @@
1
1
  import type { StylePackageSource } from '#auklet/css/vite/moduleGraph/packageSource/types';
2
2
  export type MonorepoPackageSourceOptions = {
3
- workspaceRoot: string;
4
- packagesDir: string;
5
- styleExtensions: Array<string>;
3
+ workspaceRoot: string;
4
+ packagesDir: string;
5
+ styleExtensions: Array<string>;
6
6
  };
7
- export declare function createMonorepoPackageSource(
8
- options: MonorepoPackageSourceOptions,
9
- ): StylePackageSource;
7
+ export declare function createMonorepoPackageSource(options: MonorepoPackageSourceOptions): StylePackageSource;