webpack-dev-service 0.5.2 → 0.5.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.
- package/client/cjs/client.cjs +111 -109
- package/client/cjs/events.cjs +33 -32
- package/client/cjs/hot.cjs +61 -60
- package/client/cjs/index.cjs +10 -8
- package/client/cjs/main.cjs +63 -60
- package/client/cjs/ui/overlay.cjs +64 -63
- package/client/cjs/ui/progress.cjs +35 -35
- package/client/cjs/ui/utils/ansi/index.cjs +439 -413
- package/client/cjs/ui/utils/ansi/regx.cjs +8 -8
- package/client/cjs/ui/utils/ansi/utils.cjs +14 -14
- package/client/cjs/ui/utils/index.cjs +99 -99
- package/client/esm/client.js +111 -109
- package/client/esm/events.js +33 -32
- package/client/esm/hot.js +61 -60
- package/client/esm/index.js +8 -8
- package/client/esm/main.js +63 -60
- package/client/esm/ui/overlay.js +64 -63
- package/client/esm/ui/progress.js +35 -35
- package/client/esm/ui/utils/ansi/index.js +439 -413
- package/client/esm/ui/utils/ansi/regx.js +8 -8
- package/client/esm/ui/utils/ansi/utils.js +14 -14
- package/client/esm/ui/utils/index.js +99 -99
- package/package.json +11 -11
- package/server/cjs/dev.cjs +30 -36
- package/server/cjs/hot.cjs +174 -177
- package/server/cjs/index.cjs +16 -17
- package/server/esm/dev.js +28 -32
- package/server/esm/hot.js +171 -172
- package/server/esm/index.js +14 -13
- package/types/client/client.d.ts +7 -7
- package/types/client/events.d.ts +10 -10
- package/types/client/message.d.ts +25 -25
- package/types/client/ui/overlay.d.ts +12 -12
- package/types/client/ui/progress.d.ts +8 -8
- package/types/client/ui/utils/ansi/enum.d.ts +7 -7
- package/types/client/ui/utils/ansi/index.d.ts +11 -11
- package/types/client/ui/utils/ansi/interface.d.ts +46 -42
- package/types/server/dev.d.ts +4 -4
- package/types/server/hot.d.ts +5 -5
- package/types/server/index.d.ts +2 -2
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
/**
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
2
|
+
* @package webpack-dev-service
|
|
3
|
+
* @license MIT
|
|
4
|
+
* @version 0.5.3
|
|
5
|
+
* @author nuintun <nuintun@qq.com>
|
|
6
|
+
* @description A koa 2 middleware for webpack development and hot reloading.
|
|
7
|
+
* @see https://github.com/nuintun/webpack-dev-service#readme
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
10
|
/**
|
|
11
11
|
* @module regx
|
|
12
12
|
*/
|
|
@@ -1,24 +1,24 @@
|
|
|
1
1
|
/**
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
2
|
+
* @package webpack-dev-service
|
|
3
|
+
* @license MIT
|
|
4
|
+
* @version 0.5.3
|
|
5
|
+
* @author nuintun <nuintun@qq.com>
|
|
6
|
+
* @description A koa 2 middleware for webpack development and hot reloading.
|
|
7
|
+
* @see https://github.com/nuintun/webpack-dev-service#readme
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
10
|
/**
|
|
11
11
|
* @module utils
|
|
12
12
|
*/
|
|
13
13
|
function toUint8(uint8) {
|
|
14
|
-
|
|
14
|
+
return uint8 & 0xff;
|
|
15
15
|
}
|
|
16
16
|
function getThemeColor(defaultColor, color) {
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
17
|
+
if (color) {
|
|
18
|
+
const [r, g, b] = color;
|
|
19
|
+
return [toUint8(r), toUint8(g), toUint8(b)];
|
|
20
|
+
}
|
|
21
|
+
return defaultColor;
|
|
22
22
|
}
|
|
23
23
|
|
|
24
24
|
export { getThemeColor, toUint8 };
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
/**
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
2
|
+
* @package webpack-dev-service
|
|
3
|
+
* @license MIT
|
|
4
|
+
* @version 0.5.3
|
|
5
|
+
* @author nuintun <nuintun@qq.com>
|
|
6
|
+
* @description A koa 2 middleware for webpack development and hot reloading.
|
|
7
|
+
* @see https://github.com/nuintun/webpack-dev-service#readme
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
10
|
import Ansi from './ansi/index.js';
|
|
11
11
|
|
|
12
12
|
/**
|
|
@@ -15,106 +15,106 @@ import Ansi from './ansi/index.js';
|
|
|
15
15
|
const ansi = new Ansi();
|
|
16
16
|
const defaultStyleElement = document.createElement('style');
|
|
17
17
|
function injectCSS(css, styleElement = defaultStyleElement) {
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
18
|
+
const { head } = document;
|
|
19
|
+
styleElement.appendChild(document.createTextNode(css.trim()));
|
|
20
|
+
if (!head.contains(styleElement)) {
|
|
21
|
+
head.appendChild(styleElement);
|
|
22
|
+
}
|
|
23
|
+
return styleElement;
|
|
24
24
|
}
|
|
25
25
|
function appendHTML(html, parent) {
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
26
|
+
const nodes = [];
|
|
27
|
+
const parser = new DOMParser();
|
|
28
|
+
const stage = parent || document.body;
|
|
29
|
+
const fragment = document.createDocumentFragment();
|
|
30
|
+
const { body } = parser.parseFromString(html.trim(), 'text/html');
|
|
31
|
+
while (body.firstChild) {
|
|
32
|
+
nodes.push(fragment.appendChild(body.firstChild));
|
|
33
|
+
}
|
|
34
|
+
stage.appendChild(fragment);
|
|
35
|
+
return nodes;
|
|
36
36
|
}
|
|
37
37
|
function escapeHTML(text) {
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
38
|
+
return text.replace(/[&<>"']/gm, match => {
|
|
39
|
+
switch (match) {
|
|
40
|
+
case '&':
|
|
41
|
+
return '&';
|
|
42
|
+
case '<':
|
|
43
|
+
return '<';
|
|
44
|
+
case '>':
|
|
45
|
+
return '>';
|
|
46
|
+
case '"':
|
|
47
|
+
return '"';
|
|
48
|
+
case "'":
|
|
49
|
+
return ''';
|
|
50
|
+
default:
|
|
51
|
+
return match;
|
|
52
|
+
}
|
|
53
|
+
});
|
|
54
54
|
}
|
|
55
55
|
function blockToHTML({ style, value, url }) {
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
56
|
+
const styles = [];
|
|
57
|
+
const textDecorations = [];
|
|
58
|
+
if (style.dim) {
|
|
59
|
+
styles.push(`opacity:0.5`);
|
|
60
|
+
}
|
|
61
|
+
if (style.bold) {
|
|
62
|
+
styles.push(`font-weight:bold`);
|
|
63
|
+
}
|
|
64
|
+
if (style.italic) {
|
|
65
|
+
styles.push(`font-style:italic`);
|
|
66
|
+
}
|
|
67
|
+
if (style.inverse) {
|
|
68
|
+
styles.push(`filter:invert(1)`);
|
|
69
|
+
}
|
|
70
|
+
if (style.hidden) {
|
|
71
|
+
styles.push(`visibility:hidden`);
|
|
72
|
+
}
|
|
73
|
+
if (style.blink) {
|
|
74
|
+
textDecorations.push('blink');
|
|
75
|
+
}
|
|
76
|
+
if (style.overline) {
|
|
77
|
+
textDecorations.push('overline');
|
|
78
|
+
}
|
|
79
|
+
if (style.underline) {
|
|
80
|
+
textDecorations.push('underline');
|
|
81
|
+
}
|
|
82
|
+
if (style.strikethrough) {
|
|
83
|
+
textDecorations.push('line-through');
|
|
84
|
+
}
|
|
85
|
+
const { color, background } = style;
|
|
86
|
+
if (color) {
|
|
87
|
+
styles.push(`color:rgb(${color})`);
|
|
88
|
+
}
|
|
89
|
+
if (background) {
|
|
90
|
+
styles.push(`background-color:rgb(${background})`);
|
|
91
|
+
}
|
|
92
|
+
if (textDecorations.length > 0) {
|
|
93
|
+
styles.push(`text-decoration:${textDecorations.join(' ')}`);
|
|
94
|
+
}
|
|
95
|
+
const escapedValue = escapeHTML(value);
|
|
96
|
+
const href = url ? JSON.stringify(escapeHTML(url)) : null;
|
|
97
|
+
if (styles.length <= 0) {
|
|
98
|
+
if (!href) {
|
|
99
|
+
return escapedValue;
|
|
100
|
+
}
|
|
101
|
+
return `<a href=${href} target="_blank">${escapedValue}</a>`;
|
|
102
|
+
}
|
|
103
|
+
const inlineStyle = JSON.stringify(`${styles.join(';')};`);
|
|
98
104
|
if (!href) {
|
|
99
|
-
|
|
100
|
-
}
|
|
101
|
-
return `<a href=${href} target="_blank">${escapedValue}</a>`;
|
|
102
|
-
}
|
|
103
|
-
const inlineStyle = JSON.stringify(`${styles.join(';')};`);
|
|
104
|
-
if (!href) {
|
|
105
|
-
return `<span style=${inlineStyle}>${escapedValue}</span>`;
|
|
106
|
-
}
|
|
107
|
-
return `<a style=${inlineStyle} href=${href} target="_blank">${escapedValue}</a>`;
|
|
105
|
+
return `<span style=${inlineStyle}>${escapedValue}</span>`;
|
|
106
|
+
}
|
|
107
|
+
return `<a style=${inlineStyle} href=${href} target="_blank">${escapedValue}</a>`;
|
|
108
108
|
}
|
|
109
109
|
function ansiToHTML(text) {
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
110
|
+
let html = '';
|
|
111
|
+
ansi.write(text, block => {
|
|
112
|
+
html += blockToHTML(block);
|
|
113
|
+
});
|
|
114
|
+
ansi.flush(block => {
|
|
115
|
+
html += blockToHTML(block);
|
|
116
|
+
});
|
|
117
|
+
return html;
|
|
118
118
|
}
|
|
119
119
|
|
|
120
120
|
export { ansiToHTML, appendHTML, blockToHTML, escapeHTML, injectCSS };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "webpack-dev-service",
|
|
3
|
-
"version": "0.5.
|
|
3
|
+
"version": "0.5.3",
|
|
4
4
|
"description": "A koa 2 middleware for webpack development and hot reloading.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"sideEffects": [
|
|
@@ -89,30 +89,30 @@
|
|
|
89
89
|
"@types/koa": "^2.13.6",
|
|
90
90
|
"@types/ws": "^8.5.5",
|
|
91
91
|
"koa-compose": "^4.1.0",
|
|
92
|
-
"tslib": "^2.
|
|
92
|
+
"tslib": "^2.6.0",
|
|
93
93
|
"webpack-dev-middleware": "^6.1.1",
|
|
94
94
|
"ws": "^8.13.0"
|
|
95
95
|
},
|
|
96
96
|
"devDependencies": {
|
|
97
|
-
"@rollup/plugin-typescript": "^11.1.
|
|
98
|
-
"@swc/core": "^1.3.
|
|
97
|
+
"@rollup/plugin-typescript": "^11.1.2",
|
|
98
|
+
"@swc/core": "^1.3.70",
|
|
99
99
|
"@swc/helpers": "^0.5.1",
|
|
100
100
|
"@types/koa-compose": "^3.2.5",
|
|
101
|
-
"@types/node": "^20.
|
|
101
|
+
"@types/node": "^20.4.2",
|
|
102
102
|
"css-loader": "^6.8.1",
|
|
103
103
|
"html-webpack-plugin": "^5.5.3",
|
|
104
104
|
"koa": "^2.14.2",
|
|
105
|
-
"magic-string": "^0.30.
|
|
106
|
-
"memfs": "^
|
|
105
|
+
"magic-string": "^0.30.1",
|
|
106
|
+
"memfs": "^4.2.0",
|
|
107
107
|
"mini-css-extract-plugin": "^2.7.6",
|
|
108
|
-
"prettier": "^
|
|
108
|
+
"prettier": "^3.0.0",
|
|
109
109
|
"react": "^18.2.0",
|
|
110
110
|
"react-dom": "^18.2.0",
|
|
111
111
|
"rimraf": "^5.0.1",
|
|
112
|
-
"rollup": "^3.
|
|
112
|
+
"rollup": "^3.26.3",
|
|
113
113
|
"swc-loader": "^0.2.3",
|
|
114
|
-
"typescript": "^5.1.
|
|
115
|
-
"webpack": "^5.
|
|
114
|
+
"typescript": "^5.1.6",
|
|
115
|
+
"webpack": "^5.88.2"
|
|
116
116
|
},
|
|
117
117
|
"peerDependencies": {
|
|
118
118
|
"webpack": "^5.0.0"
|
package/server/cjs/dev.cjs
CHANGED
|
@@ -1,50 +1,44 @@
|
|
|
1
1
|
/**
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
2
|
+
* @package webpack-dev-service
|
|
3
|
+
* @license MIT
|
|
4
|
+
* @version 0.5.3
|
|
5
|
+
* @author nuintun <nuintun@qq.com>
|
|
6
|
+
* @description A koa 2 middleware for webpack development and hot reloading.
|
|
7
|
+
* @see https://github.com/nuintun/webpack-dev-service#readme
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
10
|
'use strict';
|
|
11
11
|
|
|
12
12
|
const webpackDevMiddleware = require('webpack-dev-middleware');
|
|
13
13
|
|
|
14
|
-
function _interopDefault(e) {
|
|
15
|
-
return e && e.__esModule ? e : { default: e };
|
|
16
|
-
}
|
|
14
|
+
function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
|
|
17
15
|
|
|
18
|
-
const webpackDevMiddleware__default = /*#__PURE__*/
|
|
16
|
+
const webpackDevMiddleware__default = /*#__PURE__*/_interopDefault(webpackDevMiddleware);
|
|
19
17
|
|
|
20
18
|
/**
|
|
21
19
|
* @module dev
|
|
22
20
|
*/
|
|
23
21
|
function dev(compiler, options) {
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
next
|
|
45
|
-
);
|
|
46
|
-
};
|
|
47
|
-
return Object.assign(devMiddleware, middleware);
|
|
22
|
+
const middleware = webpackDevMiddleware__default.default(compiler, options);
|
|
23
|
+
const devMiddleware = async (context, next) => {
|
|
24
|
+
context.remove('Content-Type');
|
|
25
|
+
await middleware(context.req, {
|
|
26
|
+
locals: context.state,
|
|
27
|
+
send(body) {
|
|
28
|
+
context.body = body;
|
|
29
|
+
},
|
|
30
|
+
status(statusCode) {
|
|
31
|
+
context.status = statusCode;
|
|
32
|
+
},
|
|
33
|
+
set(field, value) {
|
|
34
|
+
context.response.set(field, value);
|
|
35
|
+
},
|
|
36
|
+
get(field) {
|
|
37
|
+
return context.response.get(field);
|
|
38
|
+
}
|
|
39
|
+
}, next);
|
|
40
|
+
};
|
|
41
|
+
return Object.assign(devMiddleware, middleware);
|
|
48
42
|
}
|
|
49
43
|
|
|
50
44
|
module.exports = dev;
|