webpack-dev-service 0.6.0 → 0.7.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.
@@ -1,7 +1,7 @@
1
1
  /**
2
2
  * @package webpack-dev-service
3
3
  * @license MIT
4
- * @version 0.6.0
4
+ * @version 0.7.0
5
5
  * @author nuintun <nuintun@qq.com>
6
6
  * @description A koa 2 middleware for webpack development and hot reloading.
7
7
  * @see https://github.com/nuintun/webpack-dev-service#readme
@@ -63,7 +63,7 @@ function createClient(options) {
63
63
  const debug = console[method];
64
64
  for (const { moduleName, chunkName, message } of problems) {
65
65
  const filename = moduleName || chunkName || 'unknown';
66
- debug(`\x1b[0m${name} in ${filename}\r\n${message}`);
66
+ debug(`${name} in ${filename}\n${message}`);
67
67
  }
68
68
  };
69
69
  const onProblems = ({ errors, warnings }) => {
@@ -1,7 +1,7 @@
1
1
  /**
2
2
  * @package webpack-dev-service
3
3
  * @license MIT
4
- * @version 0.6.0
4
+ * @version 0.7.0
5
5
  * @author nuintun <nuintun@qq.com>
6
6
  * @description A koa 2 middleware for webpack development and hot reloading.
7
7
  * @see https://github.com/nuintun/webpack-dev-service#readme
@@ -1,7 +1,7 @@
1
1
  /**
2
2
  * @package webpack-dev-service
3
3
  * @license MIT
4
- * @version 0.6.0
4
+ * @version 0.7.0
5
5
  * @author nuintun <nuintun@qq.com>
6
6
  * @description A koa 2 middleware for webpack development and hot reloading.
7
7
  * @see https://github.com/nuintun/webpack-dev-service#readme
@@ -1,7 +1,7 @@
1
1
  /**
2
2
  * @package webpack-dev-service
3
3
  * @license MIT
4
- * @version 0.6.0
4
+ * @version 0.7.0
5
5
  * @author nuintun <nuintun@qq.com>
6
6
  * @description A koa 2 middleware for webpack development and hot reloading.
7
7
  * @see https://github.com/nuintun/webpack-dev-service#readme
@@ -1,7 +1,7 @@
1
1
  /**
2
2
  * @package webpack-dev-service
3
3
  * @license MIT
4
- * @version 0.6.0
4
+ * @version 0.7.0
5
5
  * @author nuintun <nuintun@qq.com>
6
6
  * @description A koa 2 middleware for webpack development and hot reloading.
7
7
  * @see https://github.com/nuintun/webpack-dev-service#readme
@@ -1,7 +1,7 @@
1
1
  /**
2
2
  * @package webpack-dev-service
3
3
  * @license MIT
4
- * @version 0.6.0
4
+ * @version 0.7.0
5
5
  * @author nuintun <nuintun@qq.com>
6
6
  * @description A koa 2 middleware for webpack development and hot reloading.
7
7
  * @see https://github.com/nuintun/webpack-dev-service#readme
@@ -149,6 +149,8 @@ const CSS = `
149
149
  white-space: pre-wrap;
150
150
  overflow-wrap: anywhere;
151
151
  }
152
+ .${OVERLAY}-errors > section > pre a,
153
+ .${OVERLAY}-warnings > section > pre a,
152
154
  .${OVERLAY}-errors > section > pre span,
153
155
  .${OVERLAY}-warnings > section > pre span {
154
156
  display: inline-flex;
@@ -175,8 +177,9 @@ const HTML = `
175
177
  class Overlay {
176
178
  constructor(name) {
177
179
  this.hidden = true;
178
- utils.injectCSS(CSS);
179
- const [dialog] = utils.appendHTML(HTML);
180
+ const root = utils.getRootElement(OVERLAY);
181
+ utils.injectCSS(CSS, root);
182
+ const [dialog] = utils.appendHTML(HTML, root);
180
183
  this.dialog = dialog;
181
184
  this.name = dialog.querySelector(`.${OVERLAY}-name`);
182
185
  this.close = dialog.querySelector(`.${OVERLAY}-close`);
@@ -1,7 +1,7 @@
1
1
  /**
2
2
  * @package webpack-dev-service
3
3
  * @license MIT
4
- * @version 0.6.0
4
+ * @version 0.7.0
5
5
  * @author nuintun <nuintun@qq.com>
6
6
  * @description A koa 2 middleware for webpack development and hot reloading.
7
7
  * @see https://github.com/nuintun/webpack-dev-service#readme
@@ -62,8 +62,9 @@ const HTML = `
62
62
  class Progress {
63
63
  constructor() {
64
64
  this.hidden = true;
65
- utils.injectCSS(CSS);
66
- [this.svg] = utils.appendHTML(HTML);
65
+ const root = utils.getRootElement(PROGRESS);
66
+ utils.injectCSS(CSS, root);
67
+ [this.svg] = utils.appendHTML(HTML, root);
67
68
  this.track = this.svg.querySelector(`.${PROGRESS}-track`);
68
69
  }
69
70
  update(value) {
@@ -1,7 +1,7 @@
1
1
  /**
2
2
  * @package webpack-dev-service
3
3
  * @license MIT
4
- * @version 0.6.0
4
+ * @version 0.7.0
5
5
  * @author nuintun <nuintun@qq.com>
6
6
  * @description A koa 2 middleware for webpack development and hot reloading.
7
7
  * @see https://github.com/nuintun/webpack-dev-service#readme
@@ -21,27 +21,6 @@ const Ansi__default = /*#__PURE__*/ _interopDefault(Ansi);
21
21
  * @module utils
22
22
  */
23
23
  const ansi = new Ansi__default.default();
24
- const defaultStyleElement = document.createElement('style');
25
- function injectCSS(css, styleElement = defaultStyleElement) {
26
- const { head } = document;
27
- styleElement.appendChild(document.createTextNode(css.trim()));
28
- if (!head.contains(styleElement)) {
29
- head.appendChild(styleElement);
30
- }
31
- return styleElement;
32
- }
33
- function appendHTML(html, parent) {
34
- const nodes = [];
35
- const parser = new DOMParser();
36
- const stage = parent || document.body;
37
- const fragment = document.createDocumentFragment();
38
- const { body } = parser.parseFromString(html.trim(), 'text/html');
39
- while (body.firstChild) {
40
- nodes.push(fragment.appendChild(body.firstChild));
41
- }
42
- stage.appendChild(fragment);
43
- return nodes;
44
- }
45
24
  function escapeHTML(text) {
46
25
  return text.replace(/[&<>"']/gm, match => {
47
26
  switch (match) {
@@ -124,9 +103,34 @@ function ansiToHTML(text) {
124
103
  });
125
104
  return html;
126
105
  }
106
+ function getRootElement(tagName) {
107
+ const stage = document.createElement(tagName);
108
+ const root = stage.attachShadow({ mode: 'closed' });
109
+ document.body.appendChild(stage);
110
+ return root;
111
+ }
112
+ function injectCSS(css, root = document.body, styleElement = document.createElement('style')) {
113
+ styleElement.appendChild(document.createTextNode(css.trim()));
114
+ if (!root.contains(styleElement)) {
115
+ root.appendChild(styleElement);
116
+ }
117
+ return styleElement;
118
+ }
119
+ function appendHTML(html, root = document.body) {
120
+ const nodes = [];
121
+ const parser = new DOMParser();
122
+ const fragment = document.createDocumentFragment();
123
+ const { body } = parser.parseFromString(html.trim(), 'text/html');
124
+ while (body.firstChild) {
125
+ nodes.push(fragment.appendChild(body.firstChild));
126
+ }
127
+ root.appendChild(fragment);
128
+ return nodes;
129
+ }
127
130
 
128
131
  exports.ansiToHTML = ansiToHTML;
129
132
  exports.appendHTML = appendHTML;
130
133
  exports.blockToHTML = blockToHTML;
131
134
  exports.escapeHTML = escapeHTML;
135
+ exports.getRootElement = getRootElement;
132
136
  exports.injectCSS = injectCSS;
@@ -1,7 +1,7 @@
1
1
  /**
2
2
  * @package webpack-dev-service
3
3
  * @license MIT
4
- * @version 0.6.0
4
+ * @version 0.7.0
5
5
  * @author nuintun <nuintun@qq.com>
6
6
  * @description A koa 2 middleware for webpack development and hot reloading.
7
7
  * @see https://github.com/nuintun/webpack-dev-service#readme
@@ -61,7 +61,7 @@ function createClient(options) {
61
61
  const debug = console[method];
62
62
  for (const { moduleName, chunkName, message } of problems) {
63
63
  const filename = moduleName || chunkName || 'unknown';
64
- debug(`\x1b[0m${name} in ${filename}\r\n${message}`);
64
+ debug(`${name} in ${filename}\n${message}`);
65
65
  }
66
66
  };
67
67
  const onProblems = ({ errors, warnings }) => {
@@ -1,7 +1,7 @@
1
1
  /**
2
2
  * @package webpack-dev-service
3
3
  * @license MIT
4
- * @version 0.6.0
4
+ * @version 0.7.0
5
5
  * @author nuintun <nuintun@qq.com>
6
6
  * @description A koa 2 middleware for webpack development and hot reloading.
7
7
  * @see https://github.com/nuintun/webpack-dev-service#readme
package/client/esm/hot.js CHANGED
@@ -1,7 +1,7 @@
1
1
  /**
2
2
  * @package webpack-dev-service
3
3
  * @license MIT
4
- * @version 0.6.0
4
+ * @version 0.7.0
5
5
  * @author nuintun <nuintun@qq.com>
6
6
  * @description A koa 2 middleware for webpack development and hot reloading.
7
7
  * @see https://github.com/nuintun/webpack-dev-service#readme
@@ -1,7 +1,7 @@
1
1
  /**
2
2
  * @package webpack-dev-service
3
3
  * @license MIT
4
- * @version 0.6.0
4
+ * @version 0.7.0
5
5
  * @author nuintun <nuintun@qq.com>
6
6
  * @description A koa 2 middleware for webpack development and hot reloading.
7
7
  * @see https://github.com/nuintun/webpack-dev-service#readme
@@ -1,7 +1,7 @@
1
1
  /**
2
2
  * @package webpack-dev-service
3
3
  * @license MIT
4
- * @version 0.6.0
4
+ * @version 0.7.0
5
5
  * @author nuintun <nuintun@qq.com>
6
6
  * @description A koa 2 middleware for webpack development and hot reloading.
7
7
  * @see https://github.com/nuintun/webpack-dev-service#readme
@@ -1,13 +1,13 @@
1
1
  /**
2
2
  * @package webpack-dev-service
3
3
  * @license MIT
4
- * @version 0.6.0
4
+ * @version 0.7.0
5
5
  * @author nuintun <nuintun@qq.com>
6
6
  * @description A koa 2 middleware for webpack development and hot reloading.
7
7
  * @see https://github.com/nuintun/webpack-dev-service#readme
8
8
  */
9
9
 
10
- import { injectCSS, appendHTML, ansiToHTML } from './utils.js';
10
+ import { getRootElement, injectCSS, appendHTML, ansiToHTML } from './utils.js';
11
11
 
12
12
  /**
13
13
  * @module overlay
@@ -147,6 +147,8 @@ const CSS = `
147
147
  white-space: pre-wrap;
148
148
  overflow-wrap: anywhere;
149
149
  }
150
+ .${OVERLAY}-errors > section > pre a,
151
+ .${OVERLAY}-warnings > section > pre a,
150
152
  .${OVERLAY}-errors > section > pre span,
151
153
  .${OVERLAY}-warnings > section > pre span {
152
154
  display: inline-flex;
@@ -173,8 +175,9 @@ const HTML = `
173
175
  class Overlay {
174
176
  constructor(name) {
175
177
  this.hidden = true;
176
- injectCSS(CSS);
177
- const [dialog] = appendHTML(HTML);
178
+ const root = getRootElement(OVERLAY);
179
+ injectCSS(CSS, root);
180
+ const [dialog] = appendHTML(HTML, root);
178
181
  this.dialog = dialog;
179
182
  this.name = dialog.querySelector(`.${OVERLAY}-name`);
180
183
  this.close = dialog.querySelector(`.${OVERLAY}-close`);
@@ -1,13 +1,13 @@
1
1
  /**
2
2
  * @package webpack-dev-service
3
3
  * @license MIT
4
- * @version 0.6.0
4
+ * @version 0.7.0
5
5
  * @author nuintun <nuintun@qq.com>
6
6
  * @description A koa 2 middleware for webpack development and hot reloading.
7
7
  * @see https://github.com/nuintun/webpack-dev-service#readme
8
8
  */
9
9
 
10
- import { injectCSS, appendHTML } from './utils.js';
10
+ import { getRootElement, injectCSS, appendHTML } from './utils.js';
11
11
 
12
12
  /**
13
13
  * @module progress
@@ -60,8 +60,9 @@ const HTML = `
60
60
  class Progress {
61
61
  constructor() {
62
62
  this.hidden = true;
63
- injectCSS(CSS);
64
- [this.svg] = appendHTML(HTML);
63
+ const root = getRootElement(PROGRESS);
64
+ injectCSS(CSS, root);
65
+ [this.svg] = appendHTML(HTML, root);
65
66
  this.track = this.svg.querySelector(`.${PROGRESS}-track`);
66
67
  }
67
68
  update(value) {
@@ -1,7 +1,7 @@
1
1
  /**
2
2
  * @package webpack-dev-service
3
3
  * @license MIT
4
- * @version 0.6.0
4
+ * @version 0.7.0
5
5
  * @author nuintun <nuintun@qq.com>
6
6
  * @description A koa 2 middleware for webpack development and hot reloading.
7
7
  * @see https://github.com/nuintun/webpack-dev-service#readme
@@ -13,27 +13,6 @@ import Ansi from '@nuintun/ansi';
13
13
  * @module utils
14
14
  */
15
15
  const ansi = new Ansi();
16
- const defaultStyleElement = document.createElement('style');
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;
24
- }
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;
36
- }
37
16
  function escapeHTML(text) {
38
17
  return text.replace(/[&<>"']/gm, match => {
39
18
  switch (match) {
@@ -116,5 +95,29 @@ function ansiToHTML(text) {
116
95
  });
117
96
  return html;
118
97
  }
98
+ function getRootElement(tagName) {
99
+ const stage = document.createElement(tagName);
100
+ const root = stage.attachShadow({ mode: 'closed' });
101
+ document.body.appendChild(stage);
102
+ return root;
103
+ }
104
+ function injectCSS(css, root = document.body, styleElement = document.createElement('style')) {
105
+ styleElement.appendChild(document.createTextNode(css.trim()));
106
+ if (!root.contains(styleElement)) {
107
+ root.appendChild(styleElement);
108
+ }
109
+ return styleElement;
110
+ }
111
+ function appendHTML(html, root = document.body) {
112
+ const nodes = [];
113
+ const parser = new DOMParser();
114
+ const fragment = document.createDocumentFragment();
115
+ const { body } = parser.parseFromString(html.trim(), 'text/html');
116
+ while (body.firstChild) {
117
+ nodes.push(fragment.appendChild(body.firstChild));
118
+ }
119
+ root.appendChild(fragment);
120
+ return nodes;
121
+ }
119
122
 
120
- export { ansiToHTML, appendHTML, blockToHTML, escapeHTML, injectCSS };
123
+ export { ansiToHTML, appendHTML, blockToHTML, escapeHTML, getRootElement, injectCSS };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "webpack-dev-service",
3
- "version": "0.6.0",
3
+ "version": "0.7.0",
4
4
  "description": "A koa 2 middleware for webpack development and hot reloading.",
5
5
  "type": "module",
6
6
  "sideEffects": [
@@ -87,7 +87,7 @@
87
87
  },
88
88
  "dependencies": {
89
89
  "@nuintun/ansi": "^0.0.3",
90
- "@types/koa": "^2.13.12",
90
+ "@types/koa": "^2.15.0",
91
91
  "@types/ws": "^8.5.10",
92
92
  "koa-compose": "^4.1.0",
93
93
  "tslib": "^2.6.2",
@@ -95,26 +95,26 @@
95
95
  "ws": "^8.16.0"
96
96
  },
97
97
  "devDependencies": {
98
- "@rollup/plugin-typescript": "^11.1.5",
99
- "@swc/core": "^1.3.101",
100
- "@swc/helpers": "^0.5.3",
98
+ "@rollup/plugin-typescript": "^11.1.6",
99
+ "@swc/core": "^1.4.8",
100
+ "@swc/helpers": "^0.5.6",
101
101
  "@types/koa-compose": "^3.2.8",
102
- "@types/node": "^20.10.5",
103
- "css-loader": "^6.8.1",
102
+ "@types/node": "^20.11.28",
103
+ "css-loader": "^6.10.0",
104
104
  "html-webpack-plugin": "^5.6.0",
105
- "koa": "^2.14.2",
106
- "magic-string": "^0.30.5",
107
- "memfs": "^4.6.0",
108
- "mini-css-extract-plugin": "^2.7.6",
109
- "prettier": "^3.1.1",
105
+ "koa": "^2.15.1",
106
+ "magic-string": "^0.30.8",
107
+ "memfs": "^4.7.7",
108
+ "mini-css-extract-plugin": "^2.8.1",
109
+ "prettier": "^3.2.5",
110
110
  "react": "^18.2.0",
111
111
  "react-dom": "^18.2.0",
112
112
  "rimraf": "^5.0.5",
113
- "rollup": "^4.9.1",
114
- "swc-loader": "^0.2.3",
113
+ "rollup": "^4.13.0",
114
+ "swc-loader": "^0.2.6",
115
115
  "tsc-alias": "^1.8.8",
116
- "typescript": "^5.3.3",
117
- "webpack": "^5.89.0"
116
+ "typescript": "^5.4.2",
117
+ "webpack": "^5.90.3"
118
118
  },
119
119
  "peerDependencies": {
120
120
  "webpack": "^5.0.0"
@@ -1,7 +1,7 @@
1
1
  /**
2
2
  * @package webpack-dev-service
3
3
  * @license MIT
4
- * @version 0.6.0
4
+ * @version 0.7.0
5
5
  * @author nuintun <nuintun@qq.com>
6
6
  * @description A koa 2 middleware for webpack development and hot reloading.
7
7
  * @see https://github.com/nuintun/webpack-dev-service#readme
@@ -1,7 +1,7 @@
1
1
  /**
2
2
  * @package webpack-dev-service
3
3
  * @license MIT
4
- * @version 0.6.0
4
+ * @version 0.7.0
5
5
  * @author nuintun <nuintun@qq.com>
6
6
  * @description A koa 2 middleware for webpack development and hot reloading.
7
7
  * @see https://github.com/nuintun/webpack-dev-service#readme
@@ -1,7 +1,7 @@
1
1
  /**
2
2
  * @package webpack-dev-service
3
3
  * @license MIT
4
- * @version 0.6.0
4
+ * @version 0.7.0
5
5
  * @author nuintun <nuintun@qq.com>
6
6
  * @description A koa 2 middleware for webpack development and hot reloading.
7
7
  * @see https://github.com/nuintun/webpack-dev-service#readme
package/server/esm/dev.js CHANGED
@@ -1,7 +1,7 @@
1
1
  /**
2
2
  * @package webpack-dev-service
3
3
  * @license MIT
4
- * @version 0.6.0
4
+ * @version 0.7.0
5
5
  * @author nuintun <nuintun@qq.com>
6
6
  * @description A koa 2 middleware for webpack development and hot reloading.
7
7
  * @see https://github.com/nuintun/webpack-dev-service#readme
package/server/esm/hot.js CHANGED
@@ -1,7 +1,7 @@
1
1
  /**
2
2
  * @package webpack-dev-service
3
3
  * @license MIT
4
- * @version 0.6.0
4
+ * @version 0.7.0
5
5
  * @author nuintun <nuintun@qq.com>
6
6
  * @description A koa 2 middleware for webpack development and hot reloading.
7
7
  * @see https://github.com/nuintun/webpack-dev-service#readme
@@ -1,7 +1,7 @@
1
1
  /**
2
2
  * @package webpack-dev-service
3
3
  * @license MIT
4
- * @version 0.6.0
4
+ * @version 0.7.0
5
5
  * @author nuintun <nuintun@qq.com>
6
6
  * @description A koa 2 middleware for webpack development and hot reloading.
7
7
  * @see https://github.com/nuintun/webpack-dev-service#readme
@@ -2,8 +2,14 @@
2
2
  * @module utils
3
3
  */
4
4
  import { AnsiBlock } from '@nuintun/ansi';
5
- export declare function injectCSS(css: string, styleElement?: HTMLStyleElement): HTMLStyleElement;
6
- export declare function appendHTML(html: string, parent?: HTMLElement): ChildNode[];
7
5
  export declare function escapeHTML(text: string): string;
8
6
  export declare function blockToHTML({ style, value, url }: AnsiBlock): string;
9
7
  export declare function ansiToHTML(text: string): string;
8
+ export type RootElement = HTMLElement | ShadowRoot;
9
+ export declare function getRootElement(tagName: string): ShadowRoot;
10
+ export declare function injectCSS(
11
+ css: string,
12
+ root?: HTMLElement | ShadowRoot,
13
+ styleElement?: HTMLStyleElement
14
+ ): HTMLStyleElement;
15
+ export declare function appendHTML(html: string, root?: RootElement): ChildNode[];