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.
- package/README.md +37 -1
- package/dist/build/bundleConfig.d.ts +1 -4
- package/dist/build/bundleConfig.js +59 -71
- package/dist/build/cleanOutput.d.ts +2 -8
- package/dist/build/cleanOutput.js +7 -7
- package/dist/build/moduleConfig.d.ts +1 -3
- package/dist/build/moduleConfig.js +21 -40
- package/dist/build/runTsdown.d.ts +2 -5
- package/dist/build/runTsdown.js +18 -23
- package/dist/build/tsdown/common.d.ts +17 -28
- package/dist/build/tsdown/common.js +22 -25
- package/dist/build/tsdown/context.d.ts +16 -20
- package/dist/build/tsdown/context.js +41 -45
- package/dist/build/tsdown/define.d.ts +2 -7
- package/dist/build/tsdown/define.js +13 -22
- package/dist/build/tsdown/dependencies.d.ts +4 -12
- package/dist/build/tsdown/dependencies.js +47 -51
- package/dist/build/tsdown/entries.d.ts +4 -6
- package/dist/build/tsdown/entries.js +39 -38
- package/dist/build/tsdown/parseModuleId.d.ts +4 -4
- package/dist/build/tsdown/parseModuleId.js +92 -77
- package/dist/build/tsdown/types.d.ts +24 -31
- package/dist/build/tsdownConfig.js +1 -4
- package/dist/config.d.ts +37 -37
- package/dist/config.js +38 -41
- package/dist/configLoader.d.ts +2 -7
- package/dist/configLoader.js +59 -64
- package/dist/css/config.js +8 -8
- package/dist/css/constants.d.ts +7 -7
- package/dist/css/constants.js +1 -1
- package/dist/css/core/resolvers/packageImports.d.ts +1 -5
- package/dist/css/core/resolvers/packageImports.js +35 -40
- package/dist/css/core/resolvers/relative.d.ts +1 -4
- package/dist/css/core/resolvers/relative.js +3 -2
- package/dist/css/core/resolvers/tsconfigPaths.d.ts +1 -5
- package/dist/css/core/resolvers/tsconfigPaths.js +59 -66
- package/dist/css/core/style/dependencies.d.ts +6 -16
- package/dist/css/core/style/dependencies.js +35 -38
- package/dist/css/core/style/entries.d.ts +35 -58
- package/dist/css/core/style/entries.js +22 -33
- package/dist/css/core/style/files.d.ts +2 -7
- package/dist/css/core/style/files.js +11 -11
- package/dist/css/core/style/specifier.d.ts +41 -8
- package/dist/css/core/style/specifier.js +107 -18
- package/dist/css/core/styleImports/autoImportRules.d.ts +13 -0
- package/dist/css/core/styleImports/autoImportRules.js +68 -0
- package/dist/css/core/styleImports/collector.d.ts +12 -25
- package/dist/css/core/styleImports/collector.js +101 -206
- package/dist/css/core/styleImports/sourceImportExportAnalyzer.d.ts +11 -0
- package/dist/css/core/styleImports/sourceImportExportAnalyzer.js +173 -0
- package/dist/css/core/styleModuleEntryPlanner.d.ts +21 -24
- package/dist/css/core/styleModuleEntryPlanner.js +45 -62
- package/dist/css/core/stylePackageContext.d.ts +16 -20
- package/dist/css/core/stylePackageContext.js +33 -49
- package/dist/css/core/styleProcessor.js +105 -104
- package/dist/css/core/workspaceStyleResolver.d.ts +8 -15
- package/dist/css/core/workspaceStyleResolver.js +34 -76
- package/dist/css/production/builder.d.ts +9 -16
- package/dist/css/production/builder.js +51 -57
- package/dist/css/production/format/entryWriter.js +36 -49
- package/dist/css/production/format/externalWriter.js +21 -33
- package/dist/css/production/format/{componentWriter.d.ts → moduleEntryWriter.d.ts} +1 -1
- package/dist/css/production/format/moduleEntryWriter.js +48 -0
- package/dist/css/production/format/moduleWriter.js +23 -26
- package/dist/css/production/format/shared.d.ts +8 -15
- package/dist/css/production/format/shared.js +4 -9
- package/dist/css/production/format/sourceWriter.js +11 -11
- package/dist/css/production/format/themeWriter.js +56 -71
- package/dist/css/production/moduleOutputWriter.d.ts +18 -21
- package/dist/css/production/moduleOutputWriter.js +58 -67
- package/dist/css/production/packageEntryWriter.d.ts +12 -15
- package/dist/css/production/packageEntryWriter.js +42 -45
- package/dist/css/vite/hmr.d.ts +11 -11
- package/dist/css/vite/hmr.js +93 -109
- package/dist/css/vite/moduleGraph/devDependency.d.ts +7 -12
- package/dist/css/vite/moduleGraph/devDependency.js +8 -8
- package/dist/css/vite/moduleGraph/graph.d.ts +20 -23
- package/dist/css/vite/moduleGraph/graph.js +51 -50
- package/dist/css/vite/moduleGraph/loadResult.d.ts +3 -5
- package/dist/css/vite/moduleGraph/loadResult.js +7 -9
- package/dist/css/vite/moduleGraph/packageSource/monorepo.d.ts +16 -7
- package/dist/css/vite/moduleGraph/packageSource/monorepo.js +60 -68
- package/dist/css/vite/moduleGraph/packageSource/singlePackage.d.ts +21 -0
- package/dist/css/vite/moduleGraph/packageSource/singlePackage.js +63 -0
- package/dist/css/vite/moduleGraph/packageSource/types.d.ts +7 -7
- package/dist/css/vite/moduleGraph/requestCache.d.ts +46 -57
- package/dist/css/vite/moduleGraph/requestCache.js +53 -51
- package/dist/css/vite/moduleGraph/styleCodeFactory.d.ts +15 -18
- package/dist/css/vite/moduleGraph/styleCodeFactory.js +173 -264
- package/dist/css/vite/moduleGraph/styleId.d.ts +3 -6
- package/dist/css/vite/moduleGraph/styleId.js +12 -11
- package/dist/css/vite/moduleGraph/types.d.ts +11 -14
- package/dist/css/vite/vitePlugin.d.ts +16 -20
- package/dist/css/vite/vitePlugin.js +117 -109
- package/dist/css/watch/watcher.d.ts +15 -21
- package/dist/css/watch/watcher.js +84 -81
- package/dist/index.d.ts +3 -25
- package/dist/index.js +2 -9
- package/dist/types.d.ts +59 -62
- package/dist/utils.d.ts +3 -7
- package/dist/utils.js +50 -47
- package/package.json +31 -33
- package/dist/css/core/styleImports/sourceReference.d.ts +0 -19
- package/dist/css/core/styleImports/sourceReference.js +0 -193
- package/dist/css/production/format/componentWriter.js +0 -71
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import path from 'node:path';
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
2
|
+
import { createModuleStyleEntryPlans } from '#auklet/css/core/style/entries';
|
|
3
|
+
import { ModuleStyleEntryWriter } from '#auklet/css/production/format/moduleEntryWriter';
|
|
4
4
|
import { StyleEntryWriter } from '#auklet/css/production/format/entryWriter';
|
|
5
5
|
import { ExternalStyleWriter } from '#auklet/css/production/format/externalWriter';
|
|
6
6
|
import { ModuleStyleWriter } from '#auklet/css/production/format/moduleWriter';
|
|
@@ -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
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
11
|
+
config;
|
|
12
|
+
context;
|
|
13
|
+
packageContext;
|
|
14
|
+
sourceWriter;
|
|
15
|
+
themeWriter;
|
|
16
|
+
externalWriter;
|
|
17
|
+
moduleWriter;
|
|
18
|
+
entryWriter;
|
|
19
|
+
moduleEntryWriter;
|
|
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.moduleEntryWriter = new ModuleStyleEntryWriter(options);
|
|
30
|
+
}
|
|
31
|
+
write() {
|
|
32
|
+
const moduleEntries = this.createModuleEntries();
|
|
33
|
+
const outputs = [];
|
|
34
|
+
for (const format of this.config.output.outputFormats) {
|
|
35
|
+
outputs.push(...this.writeFormat(format, moduleEntries));
|
|
36
|
+
}
|
|
37
|
+
return outputs;
|
|
38
|
+
}
|
|
39
|
+
get outputRoot() {
|
|
40
|
+
return path.join(this.context.packageRoot, this.context.outputDir);
|
|
41
|
+
}
|
|
42
|
+
createModuleEntries() {
|
|
43
|
+
return createModuleStyleEntryPlans(this.packageContext);
|
|
44
|
+
}
|
|
45
|
+
writeFormat(format, moduleEntries) {
|
|
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 moduleStyleEntries = this.moduleEntryWriter.write(outRoot, moduleEntries);
|
|
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(...moduleStyleEntries);
|
|
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
|
-
|
|
8
|
-
|
|
9
|
-
|
|
4
|
+
config: ModuleStyleBuildConfig;
|
|
5
|
+
context: ResolvedModuleStyleBuildContext;
|
|
6
|
+
packageContext: StylePackageContext;
|
|
10
7
|
};
|
|
11
8
|
export declare class PackageStyleEntryWriter {
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
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
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
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
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
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
|
-
|
|
38
|
-
|
|
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
|
}
|
package/dist/css/vite/hmr.d.ts
CHANGED
|
@@ -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
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
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
|
}
|
package/dist/css/vite/hmr.js
CHANGED
|
@@ -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
|
-
|
|
14
|
+
return `/@id/${id.replace('\0', '__x00__')}`;
|
|
15
15
|
};
|
|
16
16
|
const getRelativeFile = (file) => {
|
|
17
|
-
|
|
17
|
+
return path.relative(process.cwd(), file);
|
|
18
18
|
};
|
|
19
19
|
const invalidateVirtualModules = (server, graph) => {
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
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
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
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
|
-
|
|
39
|
+
return Array.from(virtualIdsByDependency.get(normalizeFileKey(file)) ?? []);
|
|
41
40
|
};
|
|
42
41
|
const getDependencyVirtualModules = (virtualIdsByDependency, server, file) => {
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
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
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
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
|
-
|
|
86
|
-
|
|
55
|
+
trackVirtualStyleDependency(file, virtualId) {
|
|
56
|
+
addVirtualStyleDependency(this.virtualIdsByDependency, file, virtualId);
|
|
87
57
|
}
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
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
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
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
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
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
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
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
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
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(): Promise<string[]>;
|
|
17
|
+
createPackageStyleCode(parsed: PackageStyleId): Promise<{
|
|
18
|
+
code: string;
|
|
19
|
+
watchFiles: string[];
|
|
20
|
+
}>;
|
|
21
|
+
private createRequestCache;
|
|
25
22
|
}
|