vite-userscript-plugin 0.4.0 → 0.5.0

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/hmr.d.ts CHANGED
@@ -1 +1 @@
1
- declare const ws: WebSocket;
1
+ declare function HRM(): void;
package/dist/hmr.js CHANGED
@@ -1,11 +1,22 @@
1
1
  "use strict";
2
- const ws = new WebSocket('ws://localhost:__PORT__');
3
- ws.addEventListener('message', () => {
4
- location.reload();
5
- });
6
- ws.addEventListener('open', () => {
7
- const { script } = GM_info;
8
- console.group(`${script.name} / ${script.version}`);
9
- console.log(GM_info);
10
- console.groupEnd();
11
- });
2
+ function HRM() {
3
+ const ws = new WebSocket('ws://localhost:__PORT__');
4
+ ws.addEventListener('open', () => {
5
+ console.clear();
6
+ const { script } = GM_info;
7
+ console.group(`${script.name}@${script.version}`);
8
+ console.log(GM_info);
9
+ console.groupEnd();
10
+ });
11
+ ws.addEventListener('close', (event) => {
12
+ console.warn('Socket is closed. Reconnect will be attempted in 1 second.', event.reason);
13
+ setTimeout(HRM, 1000);
14
+ });
15
+ ws.addEventListener('error', () => {
16
+ ws.close();
17
+ });
18
+ ws.addEventListener('message', () => {
19
+ location.reload();
20
+ });
21
+ }
22
+ HRM();
package/dist/index.js CHANGED
@@ -86,10 +86,9 @@ function UserscriptPlugin(config) {
86
86
  : [...(config.metadata.grant ?? []), 'GM_addStyle', 'GM_info']);
87
87
  // prettier-ignore-end
88
88
  if (isBuildWatch) {
89
+ const hmrFile = readFileSync(resolve(dirname(fileURLToPath(import.meta.url)), 'hmr.js'), 'utf8');
89
90
  const hmrScript = await transform({
90
- file: `
91
- ${readFileSync(resolve(dirname(fileURLToPath(import.meta.url)), 'hmr.js'), 'utf8')}
92
- `.replace('__PORT__', port.toString()),
91
+ file: hmrFile.replace('__PORT__', port.toString()),
93
92
  name: hmrPath,
94
93
  loader: 'js'
95
94
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "vite-userscript-plugin",
3
- "version": "0.4.0",
3
+ "version": "0.5.0",
4
4
  "type": "module",
5
5
  "types": "./dist/index.d.ts",
6
6
  "main": "./dist/index.js",