auklet 0.2.2 → 0.2.3

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.
@@ -7,6 +7,7 @@ export declare class AukletStyleHmr {
7
7
  private readonly virtualIdsByDependency;
8
8
  constructor(graph: () => ModuleStyleGraph);
9
9
  trackVirtualStyleDependency(file: string, virtualId: string): void;
10
+ hasTrackedStyleDependency(file: string): boolean;
10
11
  installFullReloadGuard(server: Pick<ViteDevServer, 'ws'>): void;
11
12
  handleStyleHotUpdate(context: HotUpdateOptions): never[] | undefined;
12
13
  handleSourceModuleChange(server: Pick<ViteDevServer, 'moduleGraph' | 'ws'>, file: string): boolean;
@@ -50,6 +50,9 @@ export class AukletStyleHmr {
50
50
  trackVirtualStyleDependency(file, virtualId) {
51
51
  addVirtualStyleDependency(this.virtualIdsByDependency, file, virtualId);
52
52
  }
53
+ hasTrackedStyleDependency(file) {
54
+ return (getDependencyVirtualIds(this.virtualIdsByDependency, file).length > 0);
55
+ }
53
56
  installFullReloadGuard(server) {
54
57
  const send = server.ws.send.bind(server.ws);
55
58
  server.ws.send = ((payload, data) => {
@@ -115,21 +115,24 @@ export function aukletStylePlugin(options = {}) {
115
115
  return;
116
116
  server.ws.send({ type: 'full-reload' });
117
117
  };
118
- const handleSourceAddOrUnlink = (file) => {
119
- if (graph.isStyleFile(file)) {
120
- reloadStyleGraph(file);
121
- return;
122
- }
123
- reloadStyleGraph(file);
124
- };
125
- server.watcher.on('add', handleSourceAddOrUnlink);
126
- server.watcher.on('unlink', handleSourceAddOrUnlink);
118
+ server.watcher.on('add', reloadStyleGraph);
119
+ server.watcher.on('unlink', reloadStyleGraph);
127
120
  server.watcher.on('change', (file) => {
128
121
  if (graph.isStyleConfigFile(file)) {
129
122
  reloadStyleGraph(file);
130
- return;
131
123
  }
132
- if (graph.isSourceModuleFile(file)) {
124
+ else if (graph.isStyleFile(file) &&
125
+ hmr.hasTrackedStyleDependency(file)) {
126
+ hmr.handleStyleHotUpdate({
127
+ file,
128
+ modules: [],
129
+ server,
130
+ timestamp: Date.now(),
131
+ type: 'update',
132
+ read: async () => '',
133
+ });
134
+ }
135
+ else if (graph.isSourceModuleFile(file)) {
133
136
  hmr.handleSourceModuleChange(server, file);
134
137
  }
135
138
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "auklet",
3
- "version": "0.2.2",
3
+ "version": "0.2.3",
4
4
  "type": "module",
5
5
  "author": "chentao.arthur",
6
6
  "description": "Build utilities for TypeScript packages and module CSS output.",