@roots/bud-client 6.12.3 → 6.13.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/lib/hot/client.js +28 -37
- package/lib/hot/components/index.js +7 -16
- package/lib/hot/components/indicator/index.js +2 -11
- package/lib/hot/components/indicator/indicator.component.d.ts +1 -1
- package/lib/hot/components/indicator/indicator.controller.d.ts +1 -1
- package/lib/hot/components/indicator/indicator.controller.js +4 -7
- package/lib/hot/components/overlay/index.js +2 -11
- package/lib/hot/components/overlay/overlay.component.js +3 -5
- package/lib/hot/components/overlay/overlay.controller.js +7 -12
- package/lib/hot/events.d.ts +6 -6
- package/lib/hot/events.js +12 -23
- package/lib/hot/index.js +16 -0
- package/lib/hot/options.js +1 -1
- package/{src/index.mts → lib/index.js} +1 -3
- package/lib/intercept/proxy-click-interceptor.js +11 -22
- package/package.json +7 -7
- package/src/hot/client.ts +4 -2
- package/src/hot/index.ts +17 -0
- package/lib/hot/index.cjs +0 -5
- package/lib/hot/index.d.mts +0 -1
- package/lib/hot/index.mjs +0 -17
- package/lib/index.cjs +0 -3
- package/lib/index.d.mts +0 -12
- package/lib/index.mjs +0 -3
- package/src/hot/client.test.ts +0 -78
- package/src/hot/index.cts +0 -7
- package/src/hot/index.mts +0 -9
- /package/lib/hot/{index.d.cts → index.d.ts} +0 -0
- /package/lib/{index.d.cts → index.d.ts} +0 -0
- /package/src/{index.cts → index.ts} +0 -0
package/lib/hot/client.js
CHANGED
|
@@ -1,15 +1,6 @@
|
|
|
1
1
|
/* eslint-disable no-console */
|
|
2
2
|
/* global __resourceQuery */
|
|
3
3
|
/* global __webpack_hash__ */
|
|
4
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
5
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
6
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
7
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
8
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
9
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
10
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
11
|
-
});
|
|
12
|
-
};
|
|
13
4
|
import * as components from './components/index.js';
|
|
14
5
|
import { injectEvents } from './events.js';
|
|
15
6
|
import { makeLogger } from './log.js';
|
|
@@ -17,9 +8,9 @@ import * as clientOptions from './options.js';
|
|
|
17
8
|
/**
|
|
18
9
|
* Initializes bud.js HMR handling
|
|
19
10
|
*/
|
|
20
|
-
export const client = (queryString, webpackHot) =>
|
|
11
|
+
export const client = async (queryString, webpackHot) => {
|
|
21
12
|
/* Guard: EventSource browser support */
|
|
22
|
-
if (typeof
|
|
13
|
+
if (typeof window?.EventSource === `undefined`) {
|
|
23
14
|
console.error(`[bud] hot module reload requires EventSource to work. https://developer.mozilla.org/en-US/docs/Web/API/Server-sent_events#Tools`);
|
|
24
15
|
return false;
|
|
25
16
|
}
|
|
@@ -51,21 +42,19 @@ export const client = (queryString, webpackHot) => __awaiter(void 0, void 0, voi
|
|
|
51
42
|
/**
|
|
52
43
|
* Webpack HMR check handler
|
|
53
44
|
*/
|
|
54
|
-
const check = () =>
|
|
45
|
+
const check = async () => {
|
|
55
46
|
if (webpackHot.status() === `idle`) {
|
|
56
|
-
|
|
57
|
-
requestAnimationFrame(function whenReady() {
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
}
|
|
65
|
-
});
|
|
47
|
+
await webpackHot.check(false);
|
|
48
|
+
requestAnimationFrame(async function whenReady() {
|
|
49
|
+
if (webpackHot.status() === `ready`) {
|
|
50
|
+
await update();
|
|
51
|
+
}
|
|
52
|
+
else {
|
|
53
|
+
requestAnimationFrame(whenReady);
|
|
54
|
+
}
|
|
66
55
|
});
|
|
67
56
|
}
|
|
68
|
-
}
|
|
57
|
+
};
|
|
69
58
|
/**
|
|
70
59
|
* Webpack HMR unaccepted module handler
|
|
71
60
|
*/
|
|
@@ -77,16 +66,16 @@ export const client = (queryString, webpackHot) => __awaiter(void 0, void 0, voi
|
|
|
77
66
|
* Webpack HMR error handler
|
|
78
67
|
*/
|
|
79
68
|
const onErrored = (error) => {
|
|
80
|
-
window.bud.controllers.map(controller => controller
|
|
69
|
+
window.bud.controllers.map(controller => controller?.update({
|
|
81
70
|
errors: [error],
|
|
82
71
|
}));
|
|
83
72
|
};
|
|
84
73
|
/**
|
|
85
74
|
* Webpack HMR update handler
|
|
86
75
|
*/
|
|
87
|
-
const update = () =>
|
|
76
|
+
const update = async () => {
|
|
88
77
|
try {
|
|
89
|
-
|
|
78
|
+
await webpackHot.apply({
|
|
90
79
|
ignoreUnaccepted: true,
|
|
91
80
|
ignoreDeclined: true,
|
|
92
81
|
ignoreErrored: true,
|
|
@@ -95,27 +84,29 @@ export const client = (queryString, webpackHot) => __awaiter(void 0, void 0, voi
|
|
|
95
84
|
onDeclined: onUnacceptedOrDeclined,
|
|
96
85
|
});
|
|
97
86
|
if (!isStale())
|
|
98
|
-
|
|
87
|
+
await check();
|
|
99
88
|
}
|
|
100
89
|
catch (error) {
|
|
101
90
|
logger.error(error);
|
|
102
91
|
}
|
|
103
|
-
}
|
|
92
|
+
};
|
|
104
93
|
/* Instantiate indicator, overlay */
|
|
105
|
-
|
|
94
|
+
try {
|
|
95
|
+
await components.make(options);
|
|
96
|
+
}
|
|
97
|
+
catch (error) { }
|
|
106
98
|
/* Instantiate eventSource */
|
|
107
99
|
const events = injectEvents(EventSource).make(options);
|
|
108
|
-
if (!window.bud.listeners[options.name]) {
|
|
109
|
-
window.bud.listeners[options.name] = (payload) =>
|
|
110
|
-
var _a;
|
|
100
|
+
if (!window.bud.listeners?.[options.name]) {
|
|
101
|
+
window.bud.listeners[options.name] = async (payload) => {
|
|
111
102
|
if (!payload)
|
|
112
103
|
return;
|
|
113
104
|
if (options.reload && payload.action === `reload`)
|
|
114
105
|
return window.location.reload();
|
|
115
106
|
if (payload.name !== options.name)
|
|
116
107
|
return;
|
|
117
|
-
window.bud.controllers.map(controller => controller
|
|
118
|
-
if (
|
|
108
|
+
window.bud.controllers.map(controller => controller?.update(payload));
|
|
109
|
+
if (payload.errors?.length > 0)
|
|
119
110
|
return;
|
|
120
111
|
if (payload.action === `built` || payload.action === `sync`) {
|
|
121
112
|
if (isStale(payload.hash))
|
|
@@ -123,13 +114,13 @@ export const client = (queryString, webpackHot) => __awaiter(void 0, void 0, voi
|
|
|
123
114
|
if (payload.action === `built`) {
|
|
124
115
|
logger.log(`built in ${payload.time}ms`);
|
|
125
116
|
}
|
|
126
|
-
|
|
117
|
+
await check();
|
|
127
118
|
}
|
|
128
|
-
}
|
|
119
|
+
};
|
|
129
120
|
/*
|
|
130
121
|
* Instantiate HMR event source
|
|
131
122
|
* and register client listeners
|
|
132
123
|
*/
|
|
133
124
|
events.addListener(window.bud.listeners[options.name]);
|
|
134
125
|
}
|
|
135
|
-
}
|
|
126
|
+
};
|
|
@@ -1,30 +1,21 @@
|
|
|
1
|
-
|
|
2
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
7
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
|
-
});
|
|
9
|
-
};
|
|
10
|
-
export const make = (options) => __awaiter(void 0, void 0, void 0, function* () {
|
|
1
|
+
export const make = async (options) => {
|
|
11
2
|
if (options.indicator && !customElements.get(`bud-activity-indicator`)) {
|
|
12
|
-
|
|
3
|
+
await import(`./indicator/index.js`)
|
|
13
4
|
.then(makeController)
|
|
14
5
|
.then(maybePushController);
|
|
15
6
|
}
|
|
16
7
|
if (options.overlay && !customElements.get(`bud-error`)) {
|
|
17
|
-
|
|
8
|
+
await import(`./overlay/index.js`)
|
|
18
9
|
.then(makeController)
|
|
19
10
|
.then(maybePushController);
|
|
20
11
|
}
|
|
21
12
|
return window.bud.controllers;
|
|
22
|
-
}
|
|
23
|
-
const makeController = (module) =>
|
|
13
|
+
};
|
|
14
|
+
const makeController = async (module) => {
|
|
24
15
|
if (!module)
|
|
25
16
|
return;
|
|
26
|
-
return
|
|
27
|
-
}
|
|
17
|
+
return await module.make();
|
|
18
|
+
};
|
|
28
19
|
const maybePushController = (controller) => {
|
|
29
20
|
if (!controller)
|
|
30
21
|
return;
|
|
@@ -1,17 +1,8 @@
|
|
|
1
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
7
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
|
-
});
|
|
9
|
-
};
|
|
10
1
|
import { Component } from './indicator.component.js';
|
|
11
2
|
import { Controller } from './indicator.controller.js';
|
|
12
|
-
export const make = () =>
|
|
3
|
+
export const make = async () => {
|
|
13
4
|
if (customElements.get(`bud-activity-indicator`))
|
|
14
5
|
return;
|
|
15
6
|
customElements.define(`bud-activity-indicator`, Component);
|
|
16
7
|
return new Controller();
|
|
17
|
-
}
|
|
8
|
+
};
|
|
@@ -17,29 +17,26 @@ export class Controller {
|
|
|
17
17
|
* Append `bud-error` element to the DOM
|
|
18
18
|
*/
|
|
19
19
|
addNode() {
|
|
20
|
-
var _a;
|
|
21
20
|
if (document.body.querySelector(`bud-activity-indicator`)) {
|
|
22
21
|
if (typeof this.timer.unref === `function`)
|
|
23
22
|
this.timer.unref();
|
|
24
23
|
this.removeNode();
|
|
25
24
|
}
|
|
26
|
-
|
|
25
|
+
document.body?.appendChild(this.node);
|
|
27
26
|
this.timer = setTimeout(this.removeNode, 3000);
|
|
28
27
|
}
|
|
29
28
|
/**
|
|
30
29
|
* Remove `bud-error` element from the DOM (if present)
|
|
31
30
|
*/
|
|
32
31
|
removeNode() {
|
|
33
|
-
|
|
34
|
-
(_a = document.body.querySelector(`bud-activity-indicator`)) === null || _a === void 0 ? void 0 : _a.remove();
|
|
32
|
+
document.body.querySelector(`bud-activity-indicator`)?.remove();
|
|
35
33
|
}
|
|
36
34
|
/**
|
|
37
35
|
* Update activity indicator
|
|
38
36
|
*/
|
|
39
37
|
update(payload) {
|
|
40
|
-
|
|
41
|
-
this.node.toggleAttribute(`has-
|
|
42
|
-
this.node.toggleAttribute(`has-warnings`, ((_b = payload.warnings) === null || _b === void 0 ? void 0 : _b.length) ? true : false);
|
|
38
|
+
this.node.toggleAttribute(`has-errors`, payload.errors?.length ? true : false);
|
|
39
|
+
this.node.toggleAttribute(`has-warnings`, payload.warnings?.length ? true : false);
|
|
43
40
|
this.node.setAttribute(`action`, payload.action);
|
|
44
41
|
this.addNode();
|
|
45
42
|
}
|
|
@@ -1,17 +1,8 @@
|
|
|
1
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
7
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
|
-
});
|
|
9
|
-
};
|
|
10
1
|
import { Component } from './overlay.component.js';
|
|
11
2
|
import { Controller } from './overlay.controller.js';
|
|
12
|
-
export const make = () =>
|
|
3
|
+
export const make = async () => {
|
|
13
4
|
if (customElements.get(`bud-error`))
|
|
14
5
|
return;
|
|
15
6
|
customElements.define(`bud-error`, Component);
|
|
16
7
|
return new Controller();
|
|
17
|
-
}
|
|
8
|
+
};
|
|
@@ -123,9 +123,8 @@ export class Component extends HTMLElement {
|
|
|
123
123
|
return [`message`];
|
|
124
124
|
}
|
|
125
125
|
attributeChangedCallback() {
|
|
126
|
-
var _a, _b, _c;
|
|
127
126
|
if (!this.documentBodyStyle)
|
|
128
|
-
this.documentBodyStyle =
|
|
127
|
+
this.documentBodyStyle = document.body?.style;
|
|
129
128
|
if (this.getAttribute(`message`)) {
|
|
130
129
|
document.body.style.overflow = `hidden`;
|
|
131
130
|
this.shadowRoot.querySelector(`.overlay`).classList.add(`visible`);
|
|
@@ -133,14 +132,13 @@ export class Component extends HTMLElement {
|
|
|
133
132
|
this.getAttribute(`message`);
|
|
134
133
|
return;
|
|
135
134
|
}
|
|
136
|
-
if (
|
|
135
|
+
if (this.documentBodyStyle?.overflow && document?.body?.style) {
|
|
137
136
|
document.body.style.overflow = this.documentBodyStyle.overflow;
|
|
138
137
|
}
|
|
139
138
|
this.shadowRoot.querySelector(`.overlay`).classList.remove(`visible`);
|
|
140
139
|
}
|
|
141
140
|
connectedCallback() {
|
|
142
|
-
|
|
143
|
-
if ((_a = document.body) === null || _a === void 0 ? void 0 : _a.style)
|
|
141
|
+
if (document.body?.style)
|
|
144
142
|
this.documentBodyStyle = document.body.style;
|
|
145
143
|
}
|
|
146
144
|
}
|
|
@@ -2,7 +2,7 @@ const ansiPattern = [
|
|
|
2
2
|
`[\\u001B\\u009B][[\\]()#;?]*(?:(?:(?:(?:;[-a-zA-Z\\d\\/#&.:=?%@~_]+)*|[a-zA-Z\\d]+(?:;[-a-zA-Z\\d\\/#&.:=?%@~_]*)*)?\\u0007)`,
|
|
3
3
|
`(?:(?:\\d{1,4}(?:;\\d{0,4})*)?[\\dA-PR-TZcf-ntqry=><~]))`,
|
|
4
4
|
].join(`|`);
|
|
5
|
-
const stripAnsi = (body) =>
|
|
5
|
+
const stripAnsi = (body) => body?.replace?.(new RegExp(ansiPattern, `g`), ``) ?? body;
|
|
6
6
|
/**
|
|
7
7
|
* Overlay controller
|
|
8
8
|
*/
|
|
@@ -11,10 +11,8 @@ export class Controller {
|
|
|
11
11
|
* Formatted error message
|
|
12
12
|
*/
|
|
13
13
|
get message() {
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
var _a, _b;
|
|
17
|
-
const msg = (_b = (_a = c === null || c === void 0 ? void 0 : c.message) !== null && _a !== void 0 ? _a : c === null || c === void 0 ? void 0 : c.error) !== null && _b !== void 0 ? _b : c;
|
|
14
|
+
return this.payload.errors?.reduce((a, c) => {
|
|
15
|
+
const msg = c?.message ?? c?.error ?? c;
|
|
18
16
|
if (!msg)
|
|
19
17
|
return a;
|
|
20
18
|
return `${a}
|
|
@@ -34,25 +32,22 @@ export class Controller {
|
|
|
34
32
|
* Append `bud-error` element to the DOM
|
|
35
33
|
*/
|
|
36
34
|
createError() {
|
|
37
|
-
var _a;
|
|
38
35
|
!document.body.querySelector(`bud-error`) &&
|
|
39
|
-
|
|
36
|
+
document.body?.appendChild(this.element);
|
|
40
37
|
}
|
|
41
38
|
/**
|
|
42
39
|
* Remove `bud-error` element from the DOM (if present)
|
|
43
40
|
*/
|
|
44
41
|
removeError() {
|
|
45
|
-
|
|
46
|
-
(_a = document.body.querySelector(`bud-error`)) === null || _a === void 0 ? void 0 : _a.remove();
|
|
42
|
+
document.body.querySelector(`bud-error`)?.remove();
|
|
47
43
|
}
|
|
48
44
|
/**
|
|
49
45
|
* Update DOM
|
|
50
46
|
*/
|
|
51
47
|
update(payload) {
|
|
52
|
-
var _a, _b;
|
|
53
48
|
this.payload = payload;
|
|
54
|
-
this.element.setAttribute(`message`,
|
|
55
|
-
if (
|
|
49
|
+
this.element.setAttribute(`message`, this.message ?? ``);
|
|
50
|
+
if (this.payload.errors?.length > 0) {
|
|
56
51
|
return this.createError();
|
|
57
52
|
}
|
|
58
53
|
this.removeError();
|
package/lib/hot/events.d.ts
CHANGED
|
@@ -33,9 +33,9 @@ export declare const injectEvents: (eventSource: new (path: string) => EventSour
|
|
|
33
33
|
readonly url: string;
|
|
34
34
|
readonly withCredentials: boolean;
|
|
35
35
|
close(): void;
|
|
36
|
-
readonly
|
|
37
|
-
readonly
|
|
38
|
-
readonly
|
|
36
|
+
readonly CONNECTING: 0;
|
|
37
|
+
readonly OPEN: 1;
|
|
38
|
+
readonly CLOSED: 2;
|
|
39
39
|
addEventListener<K extends keyof EventSourceEventMap>(type: K, listener: (this: EventSource, ev: EventSourceEventMap[K]) => any, options?: boolean | AddEventListenerOptions): void;
|
|
40
40
|
addEventListener(type: string, listener: (this: EventSource, event: MessageEvent<any>) => any, options?: boolean | AddEventListenerOptions): void;
|
|
41
41
|
addEventListener(type: string, listener: EventListenerOrEventListenerObject, options?: boolean | AddEventListenerOptions): void;
|
|
@@ -83,9 +83,9 @@ export declare const injectEvents: (eventSource: new (path: string) => EventSour
|
|
|
83
83
|
readonly url: string;
|
|
84
84
|
readonly withCredentials: boolean;
|
|
85
85
|
close(): void;
|
|
86
|
-
readonly
|
|
87
|
-
readonly
|
|
88
|
-
readonly
|
|
86
|
+
readonly CONNECTING: 0;
|
|
87
|
+
readonly OPEN: 1;
|
|
88
|
+
readonly CLOSED: 2;
|
|
89
89
|
addEventListener<K extends keyof EventSourceEventMap>(type: K, listener: (this: EventSource, ev: EventSourceEventMap[K]) => any, options?: boolean | AddEventListenerOptions): void;
|
|
90
90
|
addEventListener(type: string, listener: (this: EventSource, event: MessageEvent<any>) => any, options?: boolean | AddEventListenerOptions): void;
|
|
91
91
|
addEventListener(type: string, listener: EventListenerOrEventListenerObject, options?: boolean | AddEventListenerOptions): void;
|
package/lib/hot/events.js
CHANGED
|
@@ -1,13 +1,4 @@
|
|
|
1
1
|
/* eslint-disable no-console */
|
|
2
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
-
});
|
|
10
|
-
};
|
|
11
2
|
export const injectEvents = (eventSource) => {
|
|
12
3
|
/**
|
|
13
4
|
* EventSource wrapper
|
|
@@ -43,21 +34,19 @@ export const injectEvents = (eventSource) => {
|
|
|
43
34
|
* EventSource `onmessage` handler
|
|
44
35
|
* @public
|
|
45
36
|
*/
|
|
46
|
-
this.onmessage = function (payload) {
|
|
47
|
-
|
|
48
|
-
|
|
37
|
+
this.onmessage = async function (payload) {
|
|
38
|
+
if (!payload?.data || payload.data == `\uD83D\uDC93`) {
|
|
39
|
+
return;
|
|
40
|
+
}
|
|
41
|
+
try {
|
|
42
|
+
const data = JSON.parse(payload.data);
|
|
43
|
+
if (!data)
|
|
49
44
|
return;
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
yield Promise.all([...this.listeners].map((listener) => __awaiter(this, void 0, void 0, function* () {
|
|
56
|
-
return yield listener(data);
|
|
57
|
-
})));
|
|
58
|
-
}
|
|
59
|
-
catch (ex) { }
|
|
60
|
-
});
|
|
45
|
+
await Promise.all([...this.listeners].map(async (listener) => {
|
|
46
|
+
return await listener(data);
|
|
47
|
+
}));
|
|
48
|
+
}
|
|
49
|
+
catch (ex) { }
|
|
61
50
|
};
|
|
62
51
|
this.onopen = this.onopen.bind(this);
|
|
63
52
|
this.onmessage = this.onmessage.bind(this);
|
package/lib/hot/index.js
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/* eslint-disable no-console */
|
|
2
|
+
/* global __resourceQuery */
|
|
3
|
+
/* global module */
|
|
4
|
+
import { client } from './client.js';
|
|
5
|
+
try {
|
|
6
|
+
client(__resourceQuery, import.meta.webpackHot);
|
|
7
|
+
}
|
|
8
|
+
catch (err) {
|
|
9
|
+
console.error(err);
|
|
10
|
+
try {
|
|
11
|
+
client(__resourceQuery, module.hot);
|
|
12
|
+
}
|
|
13
|
+
catch (error) {
|
|
14
|
+
console.error(error);
|
|
15
|
+
}
|
|
16
|
+
}
|
package/lib/hot/options.js
CHANGED
|
@@ -24,7 +24,7 @@ const setFromParameters = (query) => {
|
|
|
24
24
|
parsedParams[key] =
|
|
25
25
|
value === `true` ? true : value === `false` ? false : value;
|
|
26
26
|
});
|
|
27
|
-
data[parsedParams.name] =
|
|
27
|
+
data[parsedParams.name] = { ...data, ...parsedParams };
|
|
28
28
|
return data[parsedParams.name];
|
|
29
29
|
};
|
|
30
30
|
export { data, get, setFromParameters };
|
|
@@ -1,26 +1,15 @@
|
|
|
1
1
|
/* eslint-disable no-console */
|
|
2
2
|
/* global __resourceQuery */
|
|
3
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
4
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
5
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
6
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
7
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
8
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
9
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
10
|
-
});
|
|
11
|
-
};
|
|
12
3
|
import intercept from './index.js';
|
|
13
|
-
window.requestAnimationFrame(function ready() {
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
: window.requestAnimationFrame(ready);
|
|
25
|
-
});
|
|
4
|
+
window.requestAnimationFrame(async function ready() {
|
|
5
|
+
if (!__resourceQuery)
|
|
6
|
+
return;
|
|
7
|
+
const params = new URLSearchParams(__resourceQuery);
|
|
8
|
+
if (!params || !params.has(`search`) || !params.has(`replace`))
|
|
9
|
+
return;
|
|
10
|
+
const search = decodeURI(params.get(`search`));
|
|
11
|
+
const replace = decodeURI(params.get(`replace`));
|
|
12
|
+
return document.body
|
|
13
|
+
? intercept(search, replace)
|
|
14
|
+
: window.requestAnimationFrame(ready);
|
|
26
15
|
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@roots/bud-client",
|
|
3
|
-
"version": "6.
|
|
3
|
+
"version": "6.13.0",
|
|
4
4
|
"description": "Client scripts for @roots/bud",
|
|
5
5
|
"engines": {
|
|
6
6
|
"node": ">=16"
|
|
@@ -43,13 +43,14 @@
|
|
|
43
43
|
"lib",
|
|
44
44
|
"src"
|
|
45
45
|
],
|
|
46
|
+
"type": "module",
|
|
46
47
|
"exports": {
|
|
47
48
|
".": {
|
|
48
|
-
"
|
|
49
|
-
"default": "./lib/index.
|
|
49
|
+
"import": "./lib/index.js",
|
|
50
|
+
"default": "./lib/index.js"
|
|
50
51
|
},
|
|
51
52
|
"./lib/*": {
|
|
52
|
-
"
|
|
53
|
+
"import": "./lib/*",
|
|
53
54
|
"default": "./lib/*"
|
|
54
55
|
}
|
|
55
56
|
},
|
|
@@ -64,12 +65,11 @@
|
|
|
64
65
|
}
|
|
65
66
|
},
|
|
66
67
|
"types": "./lib/index.d.ts",
|
|
67
|
-
"main": "./lib/index.cjs",
|
|
68
68
|
"module": "./lib/index.mjs",
|
|
69
69
|
"devDependencies": {
|
|
70
|
-
"@roots/bud": "6.
|
|
70
|
+
"@roots/bud": "6.13.0",
|
|
71
71
|
"@skypack/package-check": "0.2.2",
|
|
72
|
-
"@types/node": "18.16.
|
|
72
|
+
"@types/node": "18.16.12",
|
|
73
73
|
"@types/webpack-env": "1.18.0"
|
|
74
74
|
},
|
|
75
75
|
"dependencies": {
|
package/src/hot/client.ts
CHANGED
|
@@ -111,12 +111,14 @@ export const client = async (
|
|
|
111
111
|
}
|
|
112
112
|
|
|
113
113
|
/* Instantiate indicator, overlay */
|
|
114
|
-
|
|
114
|
+
try {
|
|
115
|
+
await components.make(options)
|
|
116
|
+
} catch (error) {}
|
|
115
117
|
|
|
116
118
|
/* Instantiate eventSource */
|
|
117
119
|
const events = injectEvents(EventSource).make(options)
|
|
118
120
|
|
|
119
|
-
if (!window.bud.listeners[options.name]) {
|
|
121
|
+
if (!window.bud.listeners?.[options.name]) {
|
|
120
122
|
window.bud.listeners[options.name] = async payload => {
|
|
121
123
|
if (!payload) return
|
|
122
124
|
|
package/src/hot/index.ts
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/* eslint-disable no-console */
|
|
2
|
+
/* global __resourceQuery */
|
|
3
|
+
/* global module */
|
|
4
|
+
|
|
5
|
+
import {client} from './client.js'
|
|
6
|
+
|
|
7
|
+
try {
|
|
8
|
+
client(__resourceQuery, import.meta.webpackHot)
|
|
9
|
+
} catch (err) {
|
|
10
|
+
console.error(err)
|
|
11
|
+
|
|
12
|
+
try {
|
|
13
|
+
client(__resourceQuery, module.hot)
|
|
14
|
+
} catch (error) {
|
|
15
|
+
console.error(error)
|
|
16
|
+
}
|
|
17
|
+
}
|
package/lib/hot/index.cjs
DELETED
package/lib/hot/index.d.mts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
package/lib/hot/index.mjs
DELETED
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
/* eslint-disable no-console */
|
|
2
|
-
/* global __resourceQuery */
|
|
3
|
-
/* global module */
|
|
4
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
5
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
6
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
7
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
8
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
9
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
10
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
11
|
-
});
|
|
12
|
-
};
|
|
13
|
-
;
|
|
14
|
-
(() => __awaiter(void 0, void 0, void 0, function* () {
|
|
15
|
-
return yield import(`./client.js`).then((module) => __awaiter(void 0, void 0, void 0, function* () { return yield module.client(__resourceQuery, import.meta.webpackHot); }));
|
|
16
|
-
}))();
|
|
17
|
-
export {};
|
package/lib/index.cjs
DELETED
package/lib/index.d.mts
DELETED
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* `@roots/bud` client scripts
|
|
3
|
-
*
|
|
4
|
-
* You should not import this root module.
|
|
5
|
-
* Import the components from the submodules instead.
|
|
6
|
-
*
|
|
7
|
-
* @see https://bud.js.org
|
|
8
|
-
* @see https://github.com/roots/bud
|
|
9
|
-
*
|
|
10
|
-
* @packageDocumentation
|
|
11
|
-
*/
|
|
12
|
-
export {};
|
package/lib/index.mjs
DELETED
package/src/hot/client.test.ts
DELETED
|
@@ -1,78 +0,0 @@
|
|
|
1
|
-
/* eslint-disable no-console */
|
|
2
|
-
/**
|
|
3
|
-
* @vitest-environment jsdom
|
|
4
|
-
*/
|
|
5
|
-
import {describe, expect, it, vi} from 'vitest'
|
|
6
|
-
|
|
7
|
-
import {client} from './client.js'
|
|
8
|
-
import {injectEvents} from './events.js'
|
|
9
|
-
import * as options from './options.js'
|
|
10
|
-
|
|
11
|
-
// @ts-ignore
|
|
12
|
-
global.EventSource = class Events {
|
|
13
|
-
public constructor() {}
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
window.EventSource = global.EventSource
|
|
17
|
-
|
|
18
|
-
const Events = injectEvents(global.EventSource)
|
|
19
|
-
|
|
20
|
-
// @ts-ignore
|
|
21
|
-
const webpackHotMock = {
|
|
22
|
-
hot: vi.fn(),
|
|
23
|
-
status: vi.fn(),
|
|
24
|
-
} as __WebpackModuleApi.Hot
|
|
25
|
-
|
|
26
|
-
describe(`@roots/bud-client`, () => {
|
|
27
|
-
it(`should be a fn module`, () => {
|
|
28
|
-
expect(client).toBeInstanceOf(Function)
|
|
29
|
-
})
|
|
30
|
-
|
|
31
|
-
it(`should add window.bud`, async () => {
|
|
32
|
-
await client(`?name=test`, webpackHotMock)
|
|
33
|
-
expect(window.bud).toBeDefined()
|
|
34
|
-
})
|
|
35
|
-
|
|
36
|
-
it(`should add window.bud.hmr as an instance of EventSource`, async () => {
|
|
37
|
-
await client(`?name=test`, webpackHotMock)
|
|
38
|
-
expect(window.bud?.hmr?.test).toBeInstanceOf(EventSource)
|
|
39
|
-
})
|
|
40
|
-
|
|
41
|
-
it(`should set clientOptions`, async () => {
|
|
42
|
-
await client(`?name=test`, webpackHotMock)
|
|
43
|
-
expect(options.data).toEqual(
|
|
44
|
-
expect.objectContaining({
|
|
45
|
-
debug: true,
|
|
46
|
-
indicator: true,
|
|
47
|
-
log: true,
|
|
48
|
-
name: `@roots/bud-client`,
|
|
49
|
-
overlay: true,
|
|
50
|
-
path: `/bud/hot`,
|
|
51
|
-
reload: true,
|
|
52
|
-
timeout: 2000,
|
|
53
|
-
}),
|
|
54
|
-
)
|
|
55
|
-
})
|
|
56
|
-
|
|
57
|
-
it(`should call listener from onmessage`, async () => {
|
|
58
|
-
await client(`?name=test`, webpackHotMock)
|
|
59
|
-
const events = Events.make(options.data)
|
|
60
|
-
|
|
61
|
-
const listenerMock = vi.fn(async () => {})
|
|
62
|
-
events.addListener(listenerMock)
|
|
63
|
-
|
|
64
|
-
await events.onmessage(
|
|
65
|
-
// @ts-ignore
|
|
66
|
-
{
|
|
67
|
-
data: `{
|
|
68
|
-
"data": {
|
|
69
|
-
"hash": "test",
|
|
70
|
-
"action": "update"
|
|
71
|
-
}
|
|
72
|
-
}`,
|
|
73
|
-
},
|
|
74
|
-
)
|
|
75
|
-
|
|
76
|
-
expect(listenerMock).toHaveBeenCalled()
|
|
77
|
-
})
|
|
78
|
-
})
|
package/src/hot/index.cts
DELETED
package/src/hot/index.mts
DELETED
|
File without changes
|
|
File without changes
|
|
File without changes
|