auklet 0.1.8 → 0.1.9
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/dist/css/vite/hmr.js +2 -15
- package/dist/css/vite/moduleGraph/graph.d.ts +5 -1
- package/dist/css/vite/moduleGraph/graph.js +30 -7
- package/dist/css/vite/moduleGraph/requestCache.d.ts +1 -0
- package/dist/css/vite/moduleGraph/requestCache.js +3 -0
- package/dist/css/vite/vitePlugin.js +6 -1
- package/package.json +1 -1
package/dist/css/vite/hmr.js
CHANGED
|
@@ -11,19 +11,6 @@ const toBrowserVirtualPath = (id) => {
|
|
|
11
11
|
const getRelativeFile = (file) => {
|
|
12
12
|
return path.relative(process.cwd(), file);
|
|
13
13
|
};
|
|
14
|
-
const invalidateVirtualModules = (server, graph) => {
|
|
15
|
-
const modules = [];
|
|
16
|
-
for (const packageName of graph.getPackageNames()) {
|
|
17
|
-
for (const entry of ['style.css', 'external.css', 'module.css']) {
|
|
18
|
-
const module = server.moduleGraph.getModuleById(`\0auklet-css:${packageName}/${entry}`);
|
|
19
|
-
if (!module)
|
|
20
|
-
continue;
|
|
21
|
-
server.moduleGraph.invalidateModule(module);
|
|
22
|
-
modules.push(module);
|
|
23
|
-
}
|
|
24
|
-
}
|
|
25
|
-
return modules;
|
|
26
|
-
};
|
|
27
14
|
const addVirtualStyleDependency = (virtualIdsByDependency, file, virtualId) => {
|
|
28
15
|
const normalizedFile = normalizeFileKey(file);
|
|
29
16
|
const values = virtualIdsByDependency.get(normalizedFile) ?? new Set();
|
|
@@ -72,16 +59,16 @@ export class AukletStyleHmr {
|
|
|
72
59
|
!graph.isStyleFile(context.file)) {
|
|
73
60
|
return;
|
|
74
61
|
}
|
|
62
|
+
this.suppressFullReload();
|
|
63
|
+
graph.invalidateFile(context.file);
|
|
75
64
|
if (this.isDuplicateUpdate(context.file)) {
|
|
76
65
|
return [];
|
|
77
66
|
}
|
|
78
|
-
this.suppressFullReload();
|
|
79
67
|
const virtualIds = getDependencyVirtualIds(this.virtualIdsByDependency, context.file);
|
|
80
68
|
const modules = getDependencyVirtualModules(this.virtualIdsByDependency, context.server, context.file);
|
|
81
69
|
for (const module of modules) {
|
|
82
70
|
context.server.moduleGraph.invalidateModule(module);
|
|
83
71
|
}
|
|
84
|
-
invalidateVirtualModules(context.server, graph);
|
|
85
72
|
const updates = virtualIds.map((id) => {
|
|
86
73
|
const browserPath = toBrowserVirtualPath(id);
|
|
87
74
|
return {
|
|
@@ -3,6 +3,7 @@ export declare class ModuleStyleGraph {
|
|
|
3
3
|
private readonly config;
|
|
4
4
|
private readonly packageSource;
|
|
5
5
|
private readonly styleCodeFactory;
|
|
6
|
+
private readonly requestCache;
|
|
6
7
|
private readonly loadAukletConfig;
|
|
7
8
|
constructor(options: ModuleStyleGraphOptions);
|
|
8
9
|
parsePackageStyleId(id: string): {
|
|
@@ -18,5 +19,8 @@ export declare class ModuleStyleGraph {
|
|
|
18
19
|
code: string;
|
|
19
20
|
watchFiles: string[];
|
|
20
21
|
}>;
|
|
21
|
-
|
|
22
|
+
invalidatePackage(packageName: string): void;
|
|
23
|
+
invalidateFile(file: string): string | null;
|
|
24
|
+
isSourceModuleFile(file: string): boolean;
|
|
25
|
+
private isPackageFile;
|
|
22
26
|
}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import path from 'node:path';
|
|
2
2
|
import { isAukletConfigFile } from '#auklet/config';
|
|
3
3
|
import { loadAukletConfig } from '#auklet/configLoader';
|
|
4
|
+
import { SOURCE_MODULE_RE } from '#auklet/css/constants';
|
|
4
5
|
import { moduleStyleBuildConfig } from '#auklet/css/config';
|
|
5
6
|
import { parsePackageStyleId } from '#auklet/css/vite/moduleGraph/styleId';
|
|
6
7
|
import { StyleCodeFactory } from '#auklet/css/vite/moduleGraph/styleCodeFactory';
|
|
@@ -13,6 +14,7 @@ export class ModuleStyleGraph {
|
|
|
13
14
|
config;
|
|
14
15
|
packageSource;
|
|
15
16
|
styleCodeFactory;
|
|
17
|
+
requestCache;
|
|
16
18
|
loadAukletConfig;
|
|
17
19
|
constructor(options) {
|
|
18
20
|
this.config = options.config ?? moduleStyleBuildConfig;
|
|
@@ -29,6 +31,11 @@ export class ModuleStyleGraph {
|
|
|
29
31
|
styleExtensions: this.config.styleExtensions,
|
|
30
32
|
loadAukletConfig: this.loadAukletConfig,
|
|
31
33
|
});
|
|
34
|
+
this.requestCache = new ModuleStyleGraphRequestCache({
|
|
35
|
+
packageSource: this.packageSource,
|
|
36
|
+
config: this.config,
|
|
37
|
+
loadAukletConfig: this.loadAukletConfig,
|
|
38
|
+
});
|
|
32
39
|
}
|
|
33
40
|
parsePackageStyleId(id) {
|
|
34
41
|
return parsePackageStyleId(id, this.getPackageNames());
|
|
@@ -49,13 +56,29 @@ export class ModuleStyleGraph {
|
|
|
49
56
|
return this.packageSource.getWatchRoots();
|
|
50
57
|
}
|
|
51
58
|
createPackageStyleCode(parsed) {
|
|
52
|
-
return this.styleCodeFactory.createPackageStyleCode(parsed, this.
|
|
59
|
+
return this.styleCodeFactory.createPackageStyleCode(parsed, this.requestCache);
|
|
53
60
|
}
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
61
|
+
invalidatePackage(packageName) {
|
|
62
|
+
this.requestCache.invalidatePackage(packageName);
|
|
63
|
+
}
|
|
64
|
+
invalidateFile(file) {
|
|
65
|
+
if (!this.isSourceGraphFile(file))
|
|
66
|
+
return null;
|
|
67
|
+
const normalizedFile = normalizeFileKey(file);
|
|
68
|
+
const stylePackage = this.packageSource
|
|
69
|
+
.getPackages()
|
|
70
|
+
.find((item) => this.isPackageFile(item.packageRoot, normalizedFile));
|
|
71
|
+
if (!stylePackage)
|
|
72
|
+
return null;
|
|
73
|
+
this.invalidatePackage(stylePackage.packageName);
|
|
74
|
+
return stylePackage.packageName;
|
|
75
|
+
}
|
|
76
|
+
isSourceModuleFile(file) {
|
|
77
|
+
return SOURCE_MODULE_RE.test(normalizeFileKey(file));
|
|
78
|
+
}
|
|
79
|
+
isPackageFile(packageRoot, file) {
|
|
80
|
+
const normalizedPackageRoot = normalizeFileKey(packageRoot);
|
|
81
|
+
return (file === normalizedPackageRoot ||
|
|
82
|
+
file.startsWith(`${normalizedPackageRoot}/`));
|
|
60
83
|
}
|
|
61
84
|
}
|
|
@@ -24,6 +24,9 @@ export class ModuleStyleGraphRequestCache {
|
|
|
24
24
|
this.contexts.set(parsed.packageName, context);
|
|
25
25
|
return context;
|
|
26
26
|
}
|
|
27
|
+
invalidatePackage(packageName) {
|
|
28
|
+
this.contexts.delete(packageName);
|
|
29
|
+
}
|
|
27
30
|
async createContext(parsed) {
|
|
28
31
|
const stylePackage = this.options.packageSource
|
|
29
32
|
.getPackages()
|
|
@@ -106,6 +106,7 @@ export function aukletStylePlugin(options = {}) {
|
|
|
106
106
|
const invalidateStyleGraph = (file) => {
|
|
107
107
|
if (!graph.isSourceGraphFile(file))
|
|
108
108
|
return false;
|
|
109
|
+
graph.invalidateFile(file);
|
|
109
110
|
invalidateVirtualModules(server, graph);
|
|
110
111
|
return true;
|
|
111
112
|
};
|
|
@@ -116,7 +117,7 @@ export function aukletStylePlugin(options = {}) {
|
|
|
116
117
|
};
|
|
117
118
|
const handleSourceAddOrUnlink = (file) => {
|
|
118
119
|
if (graph.isStyleFile(file)) {
|
|
119
|
-
|
|
120
|
+
reloadStyleGraph(file);
|
|
120
121
|
return;
|
|
121
122
|
}
|
|
122
123
|
reloadStyleGraph(file);
|
|
@@ -126,6 +127,10 @@ export function aukletStylePlugin(options = {}) {
|
|
|
126
127
|
server.watcher.on('change', (file) => {
|
|
127
128
|
if (graph.isStyleConfigFile(file)) {
|
|
128
129
|
reloadStyleGraph(file);
|
|
130
|
+
return;
|
|
131
|
+
}
|
|
132
|
+
if (graph.isSourceModuleFile(file)) {
|
|
133
|
+
reloadStyleGraph(file);
|
|
129
134
|
}
|
|
130
135
|
});
|
|
131
136
|
},
|