@roots/bud-client 2023.6.4 → 2023.6.6
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 +25 -38
- 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.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 +6 -6
- 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,10 +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) =>
|
|
21
|
-
var _a;
|
|
11
|
+
export const client = async (queryString, webpackHot) => {
|
|
22
12
|
/* Guard: EventSource browser support */
|
|
23
|
-
if (typeof
|
|
13
|
+
if (typeof window?.EventSource === `undefined`) {
|
|
24
14
|
console.error(`[bud] hot module reload requires EventSource to work. https://developer.mozilla.org/en-US/docs/Web/API/Server-sent_events#Tools`);
|
|
25
15
|
return false;
|
|
26
16
|
}
|
|
@@ -52,21 +42,19 @@ export const client = (queryString, webpackHot) => __awaiter(void 0, void 0, voi
|
|
|
52
42
|
/**
|
|
53
43
|
* Webpack HMR check handler
|
|
54
44
|
*/
|
|
55
|
-
const check = () =>
|
|
45
|
+
const check = async () => {
|
|
56
46
|
if (webpackHot.status() === `idle`) {
|
|
57
|
-
|
|
58
|
-
requestAnimationFrame(function whenReady() {
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
}
|
|
66
|
-
});
|
|
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
|
+
}
|
|
67
55
|
});
|
|
68
56
|
}
|
|
69
|
-
}
|
|
57
|
+
};
|
|
70
58
|
/**
|
|
71
59
|
* Webpack HMR unaccepted module handler
|
|
72
60
|
*/
|
|
@@ -78,16 +66,16 @@ export const client = (queryString, webpackHot) => __awaiter(void 0, void 0, voi
|
|
|
78
66
|
* Webpack HMR error handler
|
|
79
67
|
*/
|
|
80
68
|
const onErrored = (error) => {
|
|
81
|
-
window.bud.controllers.map(controller => controller
|
|
69
|
+
window.bud.controllers.map(controller => controller?.update({
|
|
82
70
|
errors: [error],
|
|
83
71
|
}));
|
|
84
72
|
};
|
|
85
73
|
/**
|
|
86
74
|
* Webpack HMR update handler
|
|
87
75
|
*/
|
|
88
|
-
const update = () =>
|
|
76
|
+
const update = async () => {
|
|
89
77
|
try {
|
|
90
|
-
|
|
78
|
+
await webpackHot.apply({
|
|
91
79
|
ignoreUnaccepted: true,
|
|
92
80
|
ignoreDeclined: true,
|
|
93
81
|
ignoreErrored: true,
|
|
@@ -96,30 +84,29 @@ export const client = (queryString, webpackHot) => __awaiter(void 0, void 0, voi
|
|
|
96
84
|
onDeclined: onUnacceptedOrDeclined,
|
|
97
85
|
});
|
|
98
86
|
if (!isStale())
|
|
99
|
-
|
|
87
|
+
await check();
|
|
100
88
|
}
|
|
101
89
|
catch (error) {
|
|
102
90
|
logger.error(error);
|
|
103
91
|
}
|
|
104
|
-
}
|
|
92
|
+
};
|
|
105
93
|
/* Instantiate indicator, overlay */
|
|
106
94
|
try {
|
|
107
|
-
|
|
95
|
+
await components.make(options);
|
|
108
96
|
}
|
|
109
97
|
catch (error) { }
|
|
110
98
|
/* Instantiate eventSource */
|
|
111
99
|
const events = injectEvents(EventSource).make(options);
|
|
112
|
-
if (!
|
|
113
|
-
window.bud.listeners[options.name] = (payload) =>
|
|
114
|
-
var _b;
|
|
100
|
+
if (!window.bud.listeners?.[options.name]) {
|
|
101
|
+
window.bud.listeners[options.name] = async (payload) => {
|
|
115
102
|
if (!payload)
|
|
116
103
|
return;
|
|
117
104
|
if (options.reload && payload.action === `reload`)
|
|
118
105
|
return window.location.reload();
|
|
119
106
|
if (payload.name !== options.name)
|
|
120
107
|
return;
|
|
121
|
-
window.bud.controllers.map(controller => controller
|
|
122
|
-
if (
|
|
108
|
+
window.bud.controllers.map(controller => controller?.update(payload));
|
|
109
|
+
if (payload.errors?.length > 0)
|
|
123
110
|
return;
|
|
124
111
|
if (payload.action === `built` || payload.action === `sync`) {
|
|
125
112
|
if (isStale(payload.hash))
|
|
@@ -127,13 +114,13 @@ export const client = (queryString, webpackHot) => __awaiter(void 0, void 0, voi
|
|
|
127
114
|
if (payload.action === `built`) {
|
|
128
115
|
logger.log(`built in ${payload.time}ms`);
|
|
129
116
|
}
|
|
130
|
-
|
|
117
|
+
await check();
|
|
131
118
|
}
|
|
132
|
-
}
|
|
119
|
+
};
|
|
133
120
|
/*
|
|
134
121
|
* Instantiate HMR event source
|
|
135
122
|
* and register client listeners
|
|
136
123
|
*/
|
|
137
124
|
events.addListener(window.bud.listeners[options.name]);
|
|
138
125
|
}
|
|
139
|
-
}
|
|
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.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": "2023.6.
|
|
3
|
+
"version": "2023.6.6",
|
|
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,10 +65,9 @@
|
|
|
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": "2023.6.
|
|
70
|
+
"@roots/bud": "2023.6.6",
|
|
71
71
|
"@skypack/package-check": "0.2.2",
|
|
72
72
|
"@types/node": "18.16.12",
|
|
73
73
|
"@types/webpack-env": "1.18.0"
|
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
|