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.
Files changed (41) hide show
  1. package/client/cjs/client.cjs +109 -111
  2. package/client/cjs/events.cjs +32 -33
  3. package/client/cjs/hot.cjs +60 -61
  4. package/client/cjs/index.cjs +8 -10
  5. package/client/cjs/main.cjs +60 -63
  6. package/client/cjs/ui/overlay.cjs +63 -64
  7. package/client/cjs/ui/progress.cjs +35 -35
  8. package/client/cjs/ui/utils/ansi/index.cjs +414 -440
  9. package/client/cjs/ui/utils/ansi/{regx.cjs → regexp.cjs} +8 -8
  10. package/client/cjs/ui/utils/ansi/utils.cjs +14 -14
  11. package/client/cjs/ui/utils/index.cjs +99 -99
  12. package/client/esm/client.js +109 -111
  13. package/client/esm/events.js +32 -33
  14. package/client/esm/hot.js +60 -61
  15. package/client/esm/index.js +8 -8
  16. package/client/esm/main.js +60 -63
  17. package/client/esm/ui/overlay.js +63 -64
  18. package/client/esm/ui/progress.js +35 -35
  19. package/client/esm/ui/utils/ansi/index.js +414 -440
  20. package/client/esm/ui/utils/ansi/{regx.js → regexp.js} +8 -8
  21. package/client/esm/ui/utils/ansi/utils.js +14 -14
  22. package/client/esm/ui/utils/index.js +99 -99
  23. package/package.json +6 -6
  24. package/server/cjs/dev.cjs +36 -30
  25. package/server/cjs/hot.cjs +177 -174
  26. package/server/cjs/index.cjs +17 -16
  27. package/server/esm/dev.js +32 -28
  28. package/server/esm/hot.js +172 -171
  29. package/server/esm/index.js +13 -14
  30. package/types/client/client.d.ts +7 -7
  31. package/types/client/events.d.ts +10 -10
  32. package/types/client/message.d.ts +25 -25
  33. package/types/client/ui/overlay.d.ts +12 -12
  34. package/types/client/ui/progress.d.ts +8 -8
  35. package/types/client/ui/utils/ansi/enum.d.ts +7 -7
  36. package/types/client/ui/utils/ansi/index.d.ts +11 -11
  37. package/types/client/ui/utils/ansi/interface.d.ts +42 -46
  38. package/types/server/dev.d.ts +4 -4
  39. package/types/server/hot.d.ts +5 -5
  40. package/types/server/index.d.ts +2 -2
  41. /package/types/client/ui/utils/ansi/{regx.d.ts → regexp.d.ts} +0 -0
@@ -1,12 +1,12 @@
1
1
  /**
2
- * @package webpack-dev-service
3
- * @license MIT
4
- * @version 0.5.5
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
-
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
- * @package webpack-dev-service
3
- * @license MIT
4
- * @version 0.5.5
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
-
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
- return uint8 & 0xff;
14
+ return uint8 & 0xff;
15
15
  }
16
16
  function getThemeColor(defaultColor, color) {
17
- if (color) {
18
- const [r, g, b] = color;
19
- return [toUint8(r), toUint8(g), toUint8(b)];
20
- }
21
- return defaultColor;
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
- * @package webpack-dev-service
3
- * @license MIT
4
- * @version 0.5.5
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
-
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
- const { head } = document;
19
- styleElement.appendChild(document.createTextNode(css.trim()));
20
- if (!head.contains(styleElement)) {
21
- head.appendChild(styleElement);
22
- }
23
- return styleElement;
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
- 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;
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
- return text.replace(/[&<>"']/gm, match => {
39
- switch (match) {
40
- case '&':
41
- return '&amp;';
42
- case '<':
43
- return '&lt;';
44
- case '>':
45
- return '&gt;';
46
- case '"':
47
- return '&quot;';
48
- case "'":
49
- return '&#x27;';
50
- default:
51
- return match;
52
- }
53
- });
38
+ return text.replace(/[&<>"']/gm, match => {
39
+ switch (match) {
40
+ case '&':
41
+ return '&amp;';
42
+ case '<':
43
+ return '&lt;';
44
+ case '>':
45
+ return '&gt;';
46
+ case '"':
47
+ return '&quot;';
48
+ case "'":
49
+ return '&#x27;';
50
+ default:
51
+ return match;
52
+ }
53
+ });
54
54
  }
55
55
  function blockToHTML({ style, value, url }) {
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(';')};`);
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
- return `<span style=${inlineStyle}>${escapedValue}</span>`;
106
- }
107
- return `<a style=${inlineStyle} href=${href} target="_blank">${escapedValue}</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
- let html = '';
111
- ansi.write(text, block => {
112
- html += blockToHTML(block);
113
- });
114
- ansi.flush(block => {
115
- html += blockToHTML(block);
116
- });
117
- return html;
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.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.74",
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.7",
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.0",
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.27.1",
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",
@@ -1,44 +1,50 @@
1
1
  /**
2
- * @package webpack-dev-service
3
- * @license MIT
4
- * @version 0.5.5
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
-
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 (e) { return e && e.__esModule ? e : { default: e }; }
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
- 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);
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;