webpack-dev-service 0.5.5 → 0.5.7
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 +109 -111
- package/client/cjs/events.cjs +32 -33
- package/client/cjs/hot.cjs +60 -61
- package/client/cjs/index.cjs +8 -10
- package/client/cjs/main.cjs +60 -63
- package/client/cjs/ui/overlay.cjs +63 -64
- package/client/cjs/ui/progress.cjs +35 -35
- package/client/cjs/ui/utils/ansi/index.cjs +414 -440
- package/client/cjs/ui/utils/ansi/{regx.cjs → regexp.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 +109 -111
- package/client/esm/events.js +32 -33
- package/client/esm/hot.js +60 -61
- package/client/esm/index.js +8 -8
- package/client/esm/main.js +60 -63
- package/client/esm/ui/overlay.js +63 -64
- package/client/esm/ui/progress.js +35 -35
- package/client/esm/ui/utils/ansi/index.js +414 -440
- package/client/esm/ui/utils/ansi/{regx.js → regexp.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 +6 -6
- package/server/cjs/dev.cjs +36 -30
- package/server/cjs/hot.cjs +177 -174
- package/server/cjs/index.cjs +17 -16
- package/server/esm/dev.js +32 -28
- package/server/esm/hot.js +172 -171
- package/server/esm/index.js +13 -14
- 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 +42 -46
- package/types/server/dev.d.ts +4 -4
- package/types/server/hot.d.ts +5 -5
- package/types/server/index.d.ts +2 -2
- /package/types/client/ui/utils/ansi/{regx.d.ts → regexp.d.ts} +0 -0
|
@@ -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.7
|
|
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.7
|
|
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.7
|
|
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
|
-
|
|
98
|
-
if (!href) {
|
|
99
|
-
return escapedValue;
|
|
100
|
-
}
|
|
101
|
-
return `<a href=${href} target="_blank">${escapedValue}</a>`;
|
|
102
|
-
}
|
|
103
|
-
const inlineStyle = JSON.stringify(`${styles.join(';')};`);
|
|
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) {
|
|
104
98
|
if (!href) {
|
|
105
|
-
|
|
106
|
-
}
|
|
107
|
-
return `<a
|
|
99
|
+
return escapedValue;
|
|
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>`;
|
|
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.7",
|
|
4
4
|
"description": "A koa 2 middleware for webpack development and hot reloading.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"sideEffects": [
|
|
@@ -76,11 +76,11 @@
|
|
|
76
76
|
"scripts": {
|
|
77
77
|
"lint": "tsc --noEmit",
|
|
78
78
|
"clean": "node tools/clean.js",
|
|
79
|
-
"format": "prettier --write .",
|
|
80
79
|
"prepublishOnly": "npm run build",
|
|
81
80
|
"test": "cd tests && node webpack.js",
|
|
82
81
|
"build:cjs": "rollup -c tools/rollup.cjs.js",
|
|
83
82
|
"build:esm": "rollup -c tools/rollup.esm.js",
|
|
83
|
+
"format": "prettier --write . --ignore-path .prettierignore",
|
|
84
84
|
"build": "npm run clean && npm run build:main && npm run format",
|
|
85
85
|
"build:main": "npm run build:cjs && npm run build:esm && npm run build:types",
|
|
86
86
|
"build:types": "tsc --declaration --emitDeclarationOnly --declarationDir types && node tools/fix-types.js"
|
|
@@ -95,21 +95,21 @@
|
|
|
95
95
|
},
|
|
96
96
|
"devDependencies": {
|
|
97
97
|
"@rollup/plugin-typescript": "^11.1.2",
|
|
98
|
-
"@swc/core": "^1.3.
|
|
98
|
+
"@swc/core": "^1.3.76",
|
|
99
99
|
"@swc/helpers": "^0.5.1",
|
|
100
100
|
"@types/koa-compose": "^3.2.5",
|
|
101
|
-
"@types/node": "^20.4.
|
|
101
|
+
"@types/node": "^20.4.9",
|
|
102
102
|
"css-loader": "^6.8.1",
|
|
103
103
|
"html-webpack-plugin": "^5.5.3",
|
|
104
104
|
"koa": "^2.14.2",
|
|
105
105
|
"magic-string": "^0.30.2",
|
|
106
|
-
"memfs": "^4.2.
|
|
106
|
+
"memfs": "^4.2.1",
|
|
107
107
|
"mini-css-extract-plugin": "^2.7.6",
|
|
108
108
|
"prettier": "^3.0.1",
|
|
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.28.0",
|
|
113
113
|
"swc-loader": "^0.2.3",
|
|
114
114
|
"tsc-alias": "^1.8.7",
|
|
115
115
|
"typescript": "^5.1.6",
|
package/server/cjs/dev.cjs
CHANGED
|
@@ -1,44 +1,50 @@
|
|
|
1
1
|
/**
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
2
|
+
* @package webpack-dev-service
|
|
3
|
+
* @license MIT
|
|
4
|
+
* @version 0.5.7
|
|
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
|
|
14
|
+
function _interopDefault(e) {
|
|
15
|
+
return e && e.__esModule ? e : { default: e };
|
|
16
|
+
}
|
|
15
17
|
|
|
16
|
-
const webpackDevMiddleware__default = /*#__PURE__*/_interopDefault(webpackDevMiddleware);
|
|
18
|
+
const webpackDevMiddleware__default = /*#__PURE__*/ _interopDefault(webpackDevMiddleware);
|
|
17
19
|
|
|
18
20
|
/**
|
|
19
21
|
* @module dev
|
|
20
22
|
*/
|
|
21
23
|
function dev(compiler, options) {
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
24
|
+
const middleware = webpackDevMiddleware__default.default(compiler, options);
|
|
25
|
+
const devMiddleware = async (context, next) => {
|
|
26
|
+
context.remove('Content-Type');
|
|
27
|
+
await middleware(
|
|
28
|
+
context.req,
|
|
29
|
+
{
|
|
30
|
+
locals: context.state,
|
|
31
|
+
send(body) {
|
|
32
|
+
context.body = body;
|
|
33
|
+
},
|
|
34
|
+
status(statusCode) {
|
|
35
|
+
context.status = statusCode;
|
|
36
|
+
},
|
|
37
|
+
set(field, value) {
|
|
38
|
+
context.response.set(field, value);
|
|
39
|
+
},
|
|
40
|
+
get(field) {
|
|
41
|
+
return context.response.get(field);
|
|
42
|
+
}
|
|
43
|
+
},
|
|
44
|
+
next
|
|
45
|
+
);
|
|
46
|
+
};
|
|
47
|
+
return Object.assign(devMiddleware, middleware);
|
|
42
48
|
}
|
|
43
49
|
|
|
44
50
|
module.exports = dev;
|