auklet 0.0.15 → 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 (105) hide show
  1. package/bin/entry.cjs +4 -6
  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.d.ts +2 -6
  24. package/dist/build/tsdownConfig.js +1 -4
  25. package/dist/config.d.ts +37 -37
  26. package/dist/config.js +38 -41
  27. package/dist/configLoader.d.ts +2 -7
  28. package/dist/configLoader.js +59 -64
  29. package/dist/css/config.js +8 -8
  30. package/dist/css/constants.d.ts +6 -6
  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 +20 -31
  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 +5 -8
  44. package/dist/css/core/style/specifier.js +21 -18
  45. package/dist/css/core/styleImports/collector.d.ts +17 -25
  46. package/dist/css/core/styleImports/collector.js +162 -201
  47. package/dist/css/core/styleImports/sourceReference.d.ts +8 -16
  48. package/dist/css/core/styleImports/sourceReference.js +153 -173
  49. package/dist/css/core/styleModuleEntryPlanner.d.ts +21 -24
  50. package/dist/css/core/styleModuleEntryPlanner.js +44 -61
  51. package/dist/css/core/stylePackageContext.d.ts +16 -20
  52. package/dist/css/core/stylePackageContext.js +33 -49
  53. package/dist/css/core/styleProcessor.d.ts +12 -12
  54. package/dist/css/core/styleProcessor.js +105 -104
  55. package/dist/css/core/workspaceStyleResolver.d.ts +9 -15
  56. package/dist/css/core/workspaceStyleResolver.js +62 -72
  57. package/dist/css/production/builder.d.ts +9 -16
  58. package/dist/css/production/builder.js +51 -57
  59. package/dist/css/production/format/componentWriter.d.ts +8 -8
  60. package/dist/css/production/format/componentWriter.js +45 -66
  61. package/dist/css/production/format/entryWriter.d.ts +5 -9
  62. package/dist/css/production/format/entryWriter.js +36 -49
  63. package/dist/css/production/format/externalWriter.d.ts +6 -6
  64. package/dist/css/production/format/externalWriter.js +21 -33
  65. package/dist/css/production/format/moduleWriter.d.ts +5 -5
  66. package/dist/css/production/format/moduleWriter.js +23 -26
  67. package/dist/css/production/format/shared.d.ts +8 -15
  68. package/dist/css/production/format/shared.js +5 -6
  69. package/dist/css/production/format/sourceWriter.d.ts +3 -3
  70. package/dist/css/production/format/sourceWriter.js +11 -11
  71. package/dist/css/production/format/themeWriter.d.ts +8 -14
  72. package/dist/css/production/format/themeWriter.js +56 -71
  73. package/dist/css/production/moduleOutputWriter.d.ts +18 -21
  74. package/dist/css/production/moduleOutputWriter.js +56 -65
  75. package/dist/css/production/packageEntryWriter.d.ts +12 -15
  76. package/dist/css/production/packageEntryWriter.js +42 -45
  77. package/dist/css/vite/hmr.d.ts +11 -11
  78. package/dist/css/vite/hmr.js +93 -109
  79. package/dist/css/vite/moduleGraph/devDependency.d.ts +7 -12
  80. package/dist/css/vite/moduleGraph/devDependency.js +8 -8
  81. package/dist/css/vite/moduleGraph/graph.d.ts +20 -24
  82. package/dist/css/vite/moduleGraph/graph.js +49 -64
  83. package/dist/css/vite/moduleGraph/loadResult.d.ts +3 -5
  84. package/dist/css/vite/moduleGraph/loadResult.js +7 -9
  85. package/dist/css/vite/moduleGraph/packageSource/monorepo.d.ts +7 -0
  86. package/dist/css/vite/moduleGraph/packageSource/monorepo.js +72 -0
  87. package/dist/css/vite/moduleGraph/packageSource/types.d.ts +11 -0
  88. package/dist/css/vite/moduleGraph/packageSource/types.js +0 -0
  89. package/dist/css/vite/moduleGraph/requestCache.d.ts +47 -61
  90. package/dist/css/vite/moduleGraph/requestCache.js +51 -84
  91. package/dist/css/vite/moduleGraph/styleCodeFactory.d.ts +15 -18
  92. package/dist/css/vite/moduleGraph/styleCodeFactory.js +182 -263
  93. package/dist/css/vite/moduleGraph/styleId.d.ts +3 -6
  94. package/dist/css/vite/moduleGraph/styleId.js +12 -11
  95. package/dist/css/vite/moduleGraph/types.d.ts +11 -13
  96. package/dist/css/vite/vitePlugin.d.ts +16 -20
  97. package/dist/css/vite/vitePlugin.js +111 -110
  98. package/dist/css/watch/watcher.d.ts +15 -21
  99. package/dist/css/watch/watcher.js +83 -80
  100. package/dist/index.d.ts +3 -25
  101. package/dist/index.js +2 -9
  102. package/dist/types.d.ts +59 -62
  103. package/dist/utils.d.ts +3 -7
  104. package/dist/utils.js +50 -47
  105. package/package.json +31 -32
@@ -1,26 +1,23 @@
1
1
  import type { StylePackageContext } from '#auklet/css/core/stylePackageContext';
2
- import type {
3
- ModuleStyleBuildConfig,
4
- ResolvedModuleStyleBuildContext,
5
- } from '#auklet/types';
2
+ import type { ModuleStyleBuildConfig, ResolvedModuleStyleBuildContext } from '#auklet/types';
6
3
  export type ModuleStyleOutputWriterOptions = {
7
- config: ModuleStyleBuildConfig;
8
- context: ResolvedModuleStyleBuildContext;
9
- packageContext: StylePackageContext;
4
+ config: ModuleStyleBuildConfig;
5
+ context: ResolvedModuleStyleBuildContext;
6
+ packageContext: StylePackageContext;
10
7
  };
11
8
  export declare class ModuleStyleOutputWriter {
12
- private readonly config;
13
- private readonly context;
14
- private readonly packageContext;
15
- private readonly sourceWriter;
16
- private readonly themeWriter;
17
- private readonly externalWriter;
18
- private readonly moduleWriter;
19
- private readonly entryWriter;
20
- private readonly componentWriter;
21
- constructor(options: ModuleStyleOutputWriterOptions);
22
- write(): string[];
23
- private get outputRoot();
24
- private createComponentEntries;
25
- private writeFormat;
9
+ private readonly config;
10
+ private readonly context;
11
+ private readonly packageContext;
12
+ private readonly sourceWriter;
13
+ private readonly themeWriter;
14
+ private readonly externalWriter;
15
+ private readonly moduleWriter;
16
+ private readonly entryWriter;
17
+ private readonly componentWriter;
18
+ constructor(options: ModuleStyleOutputWriterOptions);
19
+ write(): string[];
20
+ private get outputRoot();
21
+ private createComponentEntries;
22
+ private writeFormat;
26
23
  }
@@ -8,70 +8,61 @@ import { SourceStyleFileWriter } from '#auklet/css/production/format/sourceWrite
8
8
  import { ThemeStyleWriter } from '#auklet/css/production/format/themeWriter';
9
9
  // Coordinates all module-mode style output under format directories such as `dist/es` and `dist/lib`.
10
10
  export class ModuleStyleOutputWriter {
11
- config;
12
- context;
13
- packageContext;
14
- sourceWriter;
15
- themeWriter;
16
- externalWriter;
17
- moduleWriter;
18
- entryWriter;
19
- componentWriter;
20
- constructor(options) {
21
- this.config = options.config;
22
- this.context = options.context;
23
- this.packageContext = options.packageContext;
24
- this.sourceWriter = new SourceStyleFileWriter(options);
25
- this.themeWriter = new ThemeStyleWriter(options);
26
- this.externalWriter = new ExternalStyleWriter(options);
27
- this.moduleWriter = new ModuleStyleWriter(options);
28
- this.entryWriter = new StyleEntryWriter(options);
29
- this.componentWriter = new ComponentStyleEntryWriter(options);
30
- }
31
- write() {
32
- const componentEntries = this.createComponentEntries();
33
- const outputs = [];
34
- for (const format of this.config.output.outputFormats) {
35
- outputs.push(...this.writeFormat(format, componentEntries));
11
+ config;
12
+ context;
13
+ packageContext;
14
+ sourceWriter;
15
+ themeWriter;
16
+ externalWriter;
17
+ moduleWriter;
18
+ entryWriter;
19
+ componentWriter;
20
+ constructor(options) {
21
+ this.config = options.config;
22
+ this.context = options.context;
23
+ this.packageContext = options.packageContext;
24
+ this.sourceWriter = new SourceStyleFileWriter(options);
25
+ this.themeWriter = new ThemeStyleWriter(options);
26
+ this.externalWriter = new ExternalStyleWriter(options);
27
+ this.moduleWriter = new ModuleStyleWriter(options);
28
+ this.entryWriter = new StyleEntryWriter(options);
29
+ this.componentWriter = new ComponentStyleEntryWriter(options);
30
+ }
31
+ write() {
32
+ const componentEntries = this.createComponentEntries();
33
+ const outputs = [];
34
+ for (const format of this.config.output.outputFormats) {
35
+ outputs.push(...this.writeFormat(format, componentEntries));
36
+ }
37
+ return outputs;
38
+ }
39
+ get outputRoot() {
40
+ return path.join(this.context.packageRoot, this.context.outputDir);
41
+ }
42
+ createComponentEntries() {
43
+ return createComponentStyleEntryPlans(this.packageContext);
44
+ }
45
+ writeFormat(format, componentEntries) {
46
+ const outRoot = path.join(this.outputRoot, format);
47
+ const outputs = [];
48
+ this.themeWriter.clean(outRoot);
49
+ this.sourceWriter.copy(this.packageContext.styleFiles, outRoot);
50
+ const themeStyles = this.themeWriter.writeThemeStyles(outRoot);
51
+ const themeStyleMap = new Map(themeStyles.map((themeStyle) => [themeStyle.themeName, themeStyle.file]));
52
+ const themeEntries = this.themeWriter.writeThemeEntries(themeStyleMap, outRoot);
53
+ const externalStyle = this.externalWriter.write(outRoot);
54
+ const moduleStyle = this.moduleWriter.write(outRoot);
55
+ const entryStyle = this.entryWriter.write(outRoot, themeStyleMap, moduleStyle);
56
+ const componentStyles = this.componentWriter.write(outRoot, componentEntries);
57
+ outputs.push(...themeStyles.map((themeStyle) => themeStyle.file));
58
+ outputs.push(...themeEntries);
59
+ if (externalStyle)
60
+ outputs.push(externalStyle);
61
+ if (moduleStyle)
62
+ outputs.push(moduleStyle);
63
+ if (entryStyle)
64
+ outputs.push(entryStyle);
65
+ outputs.push(...componentStyles);
66
+ return outputs;
36
67
  }
37
- return outputs;
38
- }
39
- get outputRoot() {
40
- return path.join(this.context.packageRoot, this.context.outputDir);
41
- }
42
- createComponentEntries() {
43
- return createComponentStyleEntryPlans(this.packageContext);
44
- }
45
- writeFormat(format, componentEntries) {
46
- const outRoot = path.join(this.outputRoot, format);
47
- const outputs = [];
48
- this.themeWriter.clean(outRoot);
49
- this.sourceWriter.copy(this.packageContext.styleFiles, outRoot);
50
- const themeStyles = this.themeWriter.writeThemeStyles(outRoot);
51
- const themeStyleMap = new Map(
52
- themeStyles.map((themeStyle) => [themeStyle.themeName, themeStyle.file]),
53
- );
54
- const themeEntries = this.themeWriter.writeThemeEntries(
55
- themeStyleMap,
56
- outRoot,
57
- );
58
- const externalStyle = this.externalWriter.write(outRoot);
59
- const moduleStyle = this.moduleWriter.write(outRoot);
60
- const entryStyle = this.entryWriter.write(
61
- outRoot,
62
- themeStyleMap,
63
- moduleStyle,
64
- );
65
- const componentStyles = this.componentWriter.write(
66
- outRoot,
67
- componentEntries,
68
- );
69
- outputs.push(...themeStyles.map((themeStyle) => themeStyle.file));
70
- outputs.push(...themeEntries);
71
- if (externalStyle) outputs.push(externalStyle);
72
- if (moduleStyle) outputs.push(moduleStyle);
73
- if (entryStyle) outputs.push(entryStyle);
74
- outputs.push(...componentStyles);
75
- return outputs;
76
- }
77
68
  }
@@ -1,20 +1,17 @@
1
1
  import type { StylePackageContext } from '#auklet/css/core/stylePackageContext';
2
- import type {
3
- ModuleStyleBuildConfig,
4
- ResolvedModuleStyleBuildContext,
5
- } from '#auklet/types';
2
+ import type { ModuleStyleBuildConfig, ResolvedModuleStyleBuildContext } from '#auklet/types';
6
3
  export type PackageStyleEntryWriterOptions = {
7
- config: ModuleStyleBuildConfig;
8
- context: ResolvedModuleStyleBuildContext;
9
- packageContext: StylePackageContext;
4
+ config: ModuleStyleBuildConfig;
5
+ context: ResolvedModuleStyleBuildContext;
6
+ packageContext: StylePackageContext;
10
7
  };
11
8
  export declare class PackageStyleEntryWriter {
12
- private readonly config;
13
- private readonly context;
14
- private readonly packageContext;
15
- private readonly resolver;
16
- private readonly styleProcessor;
17
- constructor(options: PackageStyleEntryWriterOptions);
18
- write(): string | null;
19
- private get outputRoot();
9
+ private readonly config;
10
+ private readonly context;
11
+ private readonly packageContext;
12
+ private readonly resolver;
13
+ private readonly styleProcessor;
14
+ constructor(options: PackageStyleEntryWriterOptions);
15
+ write(): string | null;
16
+ private get outputRoot();
20
17
  }
@@ -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.getWorkspacePackageNames()) {
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.isWorkspaceSourceGraphFile(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,26 +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 workspaceRoot;
8
- private readonly packagesDir;
9
- private readonly styleCodeFactory;
10
- private readonly loadAukletConfig;
11
- constructor(options: ModuleStyleGraphOptions);
12
- parsePackageStyleId(id: string): {
13
- packageName: string;
14
- stylePath: string;
15
- } | null;
16
- isWorkspaceSourceGraphFile(file: string): boolean;
17
- isStyleConfigFile(file: string): boolean;
18
- isStyleFile(file: string): boolean;
19
- getWorkspacePackageNames(): string[];
20
- getWatchRoots(): string[];
21
- createPackageStyleCode(parsed: PackageStyleId): Promise<{
22
- code: string;
23
- watchFiles: string[];
24
- }>;
25
- 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;
26
22
  }