webpack-dev-service 0.12.1 → 0.12.2
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/cjs/client/client.cjs +1 -1
- package/cjs/client/events.cjs +1 -1
- package/cjs/client/hot.cjs +1 -1
- package/cjs/client/index.cjs +1 -1
- package/cjs/client/main.cjs +1 -1
- package/cjs/client/ui/Overlay.cjs +1 -1
- package/cjs/client/ui/Progress.cjs +1 -1
- package/cjs/client/ui/utils.cjs +1 -1
- package/cjs/server/compose.cjs +1 -1
- package/cjs/server/dev/Service.cjs +14 -95
- package/cjs/server/dev/index.cjs +1 -1
- package/cjs/server/dev/middleware.cjs +1 -1
- package/cjs/server/dev/utils/fs.cjs +1 -1
- package/cjs/server/dev/utils/hash.cjs +3 -3
- package/cjs/server/dev/utils/http.cjs +22 -19
- package/cjs/server/dev/utils/path.cjs +5 -5
- package/cjs/server/dev/utils/paths.cjs +3 -3
- package/cjs/server/dev/utils/ready.cjs +1 -1
- package/cjs/server/dev/utils/setupHooks.cjs +1 -1
- package/cjs/server/dev/utils/setupOutputFileSystem.cjs +1 -1
- package/cjs/server/dev/utils/setupWatching.cjs +1 -1
- package/cjs/server/dev/utils/setupWriteToDisk.cjs +6 -6
- package/cjs/server/dev/utils/stream.cjs +189 -0
- package/cjs/server/hot/Socket.cjs +8 -7
- package/cjs/server/hot/index.cjs +1 -1
- package/cjs/server/hot/utils.cjs +1 -1
- package/cjs/server/index.cjs +1 -1
- package/cjs/server/schema.cjs +1 -1
- package/cjs/server/utils.cjs +1 -1
- package/esm/client/client.js +1 -1
- package/esm/client/events.js +1 -1
- package/esm/client/hot.js +1 -1
- package/esm/client/index.js +1 -1
- package/esm/client/main.js +1 -1
- package/esm/client/ui/Overlay.js +1 -1
- package/esm/client/ui/Progress.js +1 -1
- package/esm/client/ui/utils.js +1 -1
- package/esm/server/compose.js +1 -1
- package/esm/server/dev/Service.js +6 -86
- package/esm/server/dev/index.js +1 -1
- package/esm/server/dev/middleware.js +1 -1
- package/esm/server/dev/utils/fs.js +1 -1
- package/esm/server/dev/utils/hash.js +2 -2
- package/esm/server/dev/utils/http.js +22 -19
- package/esm/server/dev/utils/path.js +2 -2
- package/esm/server/dev/utils/paths.js +2 -2
- package/esm/server/dev/utils/ready.js +1 -1
- package/esm/server/dev/utils/setupHooks.js +1 -1
- package/esm/server/dev/utils/setupOutputFileSystem.js +1 -1
- package/esm/server/dev/utils/setupWatching.js +1 -1
- package/esm/server/dev/utils/setupWriteToDisk.js +3 -3
- package/esm/server/dev/utils/stream.js +187 -0
- package/esm/server/hot/Socket.js +4 -3
- package/esm/server/hot/index.js +1 -1
- package/esm/server/hot/utils.js +1 -1
- package/esm/server/index.js +1 -1
- package/esm/server/schema.js +1 -1
- package/esm/server/utils.js +1 -1
- package/package.json +3 -4
- package/types/server/dev/Service.d.ts +2 -20
- package/types/server/dev/utils/fs.d.ts +7 -12
- package/types/server/dev/utils/http.d.ts +6 -11
- package/types/server/dev/utils/stream.d.ts +83 -0
package/cjs/client/client.cjs
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* @package webpack-dev-service
|
|
3
3
|
* @license MIT
|
|
4
|
-
* @version 0.12.
|
|
4
|
+
* @version 0.12.2
|
|
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/cjs/client/events.cjs
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* @package webpack-dev-service
|
|
3
3
|
* @license MIT
|
|
4
|
-
* @version 0.12.
|
|
4
|
+
* @version 0.12.2
|
|
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/cjs/client/hot.cjs
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* @package webpack-dev-service
|
|
3
3
|
* @license MIT
|
|
4
|
-
* @version 0.12.
|
|
4
|
+
* @version 0.12.2
|
|
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/cjs/client/index.cjs
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* @package webpack-dev-service
|
|
3
3
|
* @license MIT
|
|
4
|
-
* @version 0.12.
|
|
4
|
+
* @version 0.12.2
|
|
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/cjs/client/main.cjs
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* @package webpack-dev-service
|
|
3
3
|
* @license MIT
|
|
4
|
-
* @version 0.12.
|
|
4
|
+
* @version 0.12.2
|
|
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.12.
|
|
4
|
+
* @version 0.12.2
|
|
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.12.
|
|
4
|
+
* @version 0.12.2
|
|
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/cjs/client/ui/utils.cjs
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* @package webpack-dev-service
|
|
3
3
|
* @license MIT
|
|
4
|
-
* @version 0.12.
|
|
4
|
+
* @version 0.12.2
|
|
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/cjs/server/compose.cjs
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* @package webpack-dev-service
|
|
3
3
|
* @license MIT
|
|
4
|
-
* @version 0.12.
|
|
4
|
+
* @version 0.12.2
|
|
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.12.
|
|
4
|
+
* @version 0.12.2
|
|
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
|
|
@@ -10,11 +10,10 @@
|
|
|
10
10
|
'use strict';
|
|
11
11
|
|
|
12
12
|
const createETag = require('etag');
|
|
13
|
-
const destroy = require('destroy');
|
|
14
|
-
const stream = require('stream');
|
|
15
13
|
const utils = require('../utils.cjs');
|
|
16
14
|
const fs = require('./utils/fs.cjs');
|
|
17
|
-
const
|
|
15
|
+
const stream = require('./utils/stream.cjs');
|
|
16
|
+
const node_path = require('node:path');
|
|
18
17
|
const path = require('./utils/path.cjs');
|
|
19
18
|
const http = require('./utils/http.cjs');
|
|
20
19
|
|
|
@@ -23,7 +22,6 @@ function _interopDefault(e) {
|
|
|
23
22
|
}
|
|
24
23
|
|
|
25
24
|
const createETag__default = /*#__PURE__*/ _interopDefault(createETag);
|
|
26
|
-
const destroy__default = /*#__PURE__*/ _interopDefault(destroy);
|
|
27
25
|
|
|
28
26
|
/**
|
|
29
27
|
* @module Service
|
|
@@ -42,7 +40,7 @@ class Service {
|
|
|
42
40
|
*/
|
|
43
41
|
constructor(root, options) {
|
|
44
42
|
this.options = options;
|
|
45
|
-
this.root = path.unixify(
|
|
43
|
+
this.root = path.unixify(node_path.resolve(root));
|
|
46
44
|
}
|
|
47
45
|
/**
|
|
48
46
|
* @private
|
|
@@ -68,7 +66,7 @@ class Service {
|
|
|
68
66
|
// Set status.
|
|
69
67
|
context.status = 200;
|
|
70
68
|
// Set Content-Type.
|
|
71
|
-
context.type =
|
|
69
|
+
context.type = node_path.extname(path);
|
|
72
70
|
// Accept-Ranges.
|
|
73
71
|
if (options.acceptRanges === false) {
|
|
74
72
|
// Set Accept-Ranges to none tell client not support.
|
|
@@ -105,81 +103,6 @@ class Service {
|
|
|
105
103
|
}
|
|
106
104
|
}
|
|
107
105
|
}
|
|
108
|
-
/**
|
|
109
|
-
* @private
|
|
110
|
-
* @method read
|
|
111
|
-
* @description Read file with range.
|
|
112
|
-
* @param path The file path to read.
|
|
113
|
-
* @param range The range to read.
|
|
114
|
-
* @param stream The destination stream.
|
|
115
|
-
* @param end The end flag after pipe to stream.
|
|
116
|
-
*/
|
|
117
|
-
read(path, range, stream, end) {
|
|
118
|
-
const { fs } = this.options;
|
|
119
|
-
return new Promise(resolve => {
|
|
120
|
-
// Range prefix and suffix.
|
|
121
|
-
const { prefix, suffix } = range;
|
|
122
|
-
// Create file stream reader.
|
|
123
|
-
const reader = fs.createReadStream(path, range);
|
|
124
|
-
// File read stream open.
|
|
125
|
-
if (prefix) {
|
|
126
|
-
reader.once('open', () => {
|
|
127
|
-
// Write prefix boundary.
|
|
128
|
-
stream.write(prefix);
|
|
129
|
-
});
|
|
130
|
-
}
|
|
131
|
-
// File read stream end.
|
|
132
|
-
if (suffix) {
|
|
133
|
-
reader.once('end', () => {
|
|
134
|
-
// Push suffix boundary.
|
|
135
|
-
stream.write(suffix);
|
|
136
|
-
});
|
|
137
|
-
}
|
|
138
|
-
// File read stream error.
|
|
139
|
-
reader.once('error', () => {
|
|
140
|
-
// End stream.
|
|
141
|
-
stream.end();
|
|
142
|
-
// Unpipe.
|
|
143
|
-
reader.unpipe();
|
|
144
|
-
// Destroy.
|
|
145
|
-
destroy__default.default(reader);
|
|
146
|
-
// Resolve.
|
|
147
|
-
resolve(false);
|
|
148
|
-
});
|
|
149
|
-
// File read stream close.
|
|
150
|
-
reader.once('close', () => {
|
|
151
|
-
// Unpipe.
|
|
152
|
-
reader.unpipe();
|
|
153
|
-
// Destroy.
|
|
154
|
-
destroy__default.default(reader);
|
|
155
|
-
// Resolve.
|
|
156
|
-
resolve(true);
|
|
157
|
-
});
|
|
158
|
-
// Write data to buffer.
|
|
159
|
-
reader.pipe(stream, { end });
|
|
160
|
-
});
|
|
161
|
-
}
|
|
162
|
-
/**
|
|
163
|
-
* @private
|
|
164
|
-
* @method send
|
|
165
|
-
* @description Send file with ranges.
|
|
166
|
-
* @param path The file path to send.
|
|
167
|
-
* @param ranges The ranges to send.
|
|
168
|
-
* @param stream The destination stream.
|
|
169
|
-
*/
|
|
170
|
-
async send(path, ranges, stream) {
|
|
171
|
-
// Ranges length.
|
|
172
|
-
let { length } = ranges;
|
|
173
|
-
// Write ranges to stream.
|
|
174
|
-
for (const range of ranges) {
|
|
175
|
-
// Write range.
|
|
176
|
-
const passed = await this.read(path, range, stream, --length === 0);
|
|
177
|
-
// If not passed, break.
|
|
178
|
-
if (!passed) {
|
|
179
|
-
break;
|
|
180
|
-
}
|
|
181
|
-
}
|
|
182
|
-
}
|
|
183
106
|
/**
|
|
184
107
|
* @public
|
|
185
108
|
* @method respond
|
|
@@ -200,17 +123,17 @@ class Service {
|
|
|
200
123
|
// Real pathname.
|
|
201
124
|
const realpath = pathname.slice(length);
|
|
202
125
|
// Get path of file.
|
|
203
|
-
const path$
|
|
126
|
+
const path$1 = path.unixify(node_path.join(root, realpath));
|
|
204
127
|
// Malicious path (403).
|
|
205
|
-
if (path.isOutRoot(path$
|
|
128
|
+
if (path.isOutRoot(path$1, root)) {
|
|
206
129
|
return false;
|
|
207
130
|
}
|
|
208
131
|
// Is ignore path or file (403).
|
|
209
|
-
if (this.isIgnore(path$
|
|
132
|
+
if (this.isIgnore(path$1)) {
|
|
210
133
|
return false;
|
|
211
134
|
}
|
|
212
135
|
// File stats.
|
|
213
|
-
const stats = await fs.stat(this.options.fs, path$
|
|
136
|
+
const stats = await fs.stat(this.options.fs, path$1);
|
|
214
137
|
// Check file stats.
|
|
215
138
|
if (
|
|
216
139
|
// File not exist (404 | 500).
|
|
@@ -218,12 +141,12 @@ class Service {
|
|
|
218
141
|
// Is directory (403).
|
|
219
142
|
stats.isDirectory() ||
|
|
220
143
|
// Not a directory but has trailing slash (404).
|
|
221
|
-
path.hasTrailingSlash(path$
|
|
144
|
+
path.hasTrailingSlash(path$1)
|
|
222
145
|
) {
|
|
223
146
|
return false;
|
|
224
147
|
}
|
|
225
148
|
// Setup headers.
|
|
226
|
-
this.setupHeaders(context, path$
|
|
149
|
+
this.setupHeaders(context, path$1, stats);
|
|
227
150
|
// Conditional get support.
|
|
228
151
|
if (http.isConditionalGET(context)) {
|
|
229
152
|
// Request precondition failure.
|
|
@@ -262,14 +185,10 @@ class Service {
|
|
|
262
185
|
if (ranges === -2) {
|
|
263
186
|
return context.throw(400);
|
|
264
187
|
}
|
|
265
|
-
//
|
|
266
|
-
const
|
|
267
|
-
highWaterMark: 65536
|
|
268
|
-
});
|
|
269
|
-
// Send file with ranges.
|
|
270
|
-
this.send(path$2, ranges, stream$1);
|
|
188
|
+
// Ranges length.
|
|
189
|
+
const { fs: fs$1, highWaterMark } = this.options;
|
|
271
190
|
// Set response body.
|
|
272
|
-
context.body = stream$1;
|
|
191
|
+
context.body = new stream.FileReadStream(path$1, ranges, { fs: fs$1, highWaterMark });
|
|
273
192
|
// File found.
|
|
274
193
|
return true;
|
|
275
194
|
}
|
package/cjs/server/dev/index.cjs
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* @package webpack-dev-service
|
|
3
3
|
* @license MIT
|
|
4
|
-
* @version 0.12.
|
|
4
|
+
* @version 0.12.2
|
|
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.12.
|
|
4
|
+
* @version 0.12.2
|
|
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.12.
|
|
4
|
+
* @version 0.12.2
|
|
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.12.
|
|
4
|
+
* @version 0.12.2
|
|
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
|
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
|
|
10
10
|
'use strict';
|
|
11
11
|
|
|
12
|
-
const
|
|
12
|
+
const node_crypto = require('node:crypto');
|
|
13
13
|
|
|
14
14
|
/**
|
|
15
15
|
* @module hash
|
|
@@ -34,7 +34,7 @@ const CHARS = [
|
|
|
34
34
|
*/
|
|
35
35
|
function generate(length = 32) {
|
|
36
36
|
let hash = '';
|
|
37
|
-
const randomValues =
|
|
37
|
+
const randomValues = node_crypto.getRandomValues(new Uint8Array(length));
|
|
38
38
|
// Create hash.
|
|
39
39
|
for (const value of randomValues) {
|
|
40
40
|
hash += CHARS[value % 62];
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* @package webpack-dev-service
|
|
3
3
|
* @license MIT
|
|
4
|
-
* @version 0.12.
|
|
4
|
+
* @version 0.12.2
|
|
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
|
|
@@ -10,6 +10,7 @@
|
|
|
10
10
|
'use strict';
|
|
11
11
|
|
|
12
12
|
const hash = require('./hash.cjs');
|
|
13
|
+
const node_buffer = require('node:buffer');
|
|
13
14
|
const parseRange = require('range-parser');
|
|
14
15
|
|
|
15
16
|
function _interopDefault(e) {
|
|
@@ -108,7 +109,7 @@ function decodeURI(URI) {
|
|
|
108
109
|
/**
|
|
109
110
|
* @function isConditionalGET
|
|
110
111
|
* @description Check if request is conditional GET.
|
|
111
|
-
* @param context
|
|
112
|
+
* @param context The koa context.
|
|
112
113
|
*/
|
|
113
114
|
function isConditionalGET(context) {
|
|
114
115
|
const { request } = context;
|
|
@@ -122,7 +123,7 @@ function isConditionalGET(context) {
|
|
|
122
123
|
/**
|
|
123
124
|
* @function isPreconditionFailure
|
|
124
125
|
* @description Check if request precondition failure.
|
|
125
|
-
* @param context
|
|
126
|
+
* @param context The koa context.
|
|
126
127
|
*/
|
|
127
128
|
function isPreconditionFailure({ request, response }) {
|
|
128
129
|
// If-Match.
|
|
@@ -147,8 +148,8 @@ function isPreconditionFailure({ request, response }) {
|
|
|
147
148
|
/**
|
|
148
149
|
* @function parseRanges
|
|
149
150
|
* @description Parse ranges.
|
|
150
|
-
* @param context
|
|
151
|
-
* @param stats
|
|
151
|
+
* @param context The koa context.
|
|
152
|
+
* @param stats The file stats.
|
|
152
153
|
*/
|
|
153
154
|
function parseRanges(context, stats) {
|
|
154
155
|
const { size } = stats;
|
|
@@ -175,42 +176,44 @@ function parseRanges(context, stats) {
|
|
|
175
176
|
let contentLength = 0;
|
|
176
177
|
// Ranges.
|
|
177
178
|
const ranges = [];
|
|
179
|
+
// Parsed entries.
|
|
180
|
+
const entries = parsed.entries();
|
|
178
181
|
// Range boundary.
|
|
179
182
|
const boundary = `<${hash.generate()}>`;
|
|
180
|
-
// Range suffix.
|
|
181
|
-
const suffix = `\r\n--${boundary}--\r\n`;
|
|
182
183
|
// Multipart Content-Type.
|
|
183
184
|
const contentType = `Content-Type: ${context.type}`;
|
|
185
|
+
// Range suffix.
|
|
186
|
+
const suffix = node_buffer.Buffer.from(`\r\n--${boundary}--\r\n`);
|
|
184
187
|
// Override Content-Type.
|
|
185
188
|
context.type = `multipart/byteranges; boundary=${boundary}`;
|
|
186
189
|
// Map ranges.
|
|
187
|
-
for (
|
|
188
|
-
const
|
|
189
|
-
// The first prefix boundary no \r\n.
|
|
190
|
+
for (const [index, { start, end }] of entries) {
|
|
191
|
+
const length = end - start + 1;
|
|
190
192
|
const head = index > 0 ? '\r\n' : '';
|
|
191
193
|
const contentRange = `Content-Range: bytes ${start}-${end}/${size}`;
|
|
192
|
-
const prefix = `${head}--${boundary}\r\n${contentType}\r\n${contentRange}\r\n\r\n
|
|
194
|
+
const prefix = node_buffer.Buffer.from(`${head}--${boundary}\r\n${contentType}\r\n${contentRange}\r\n\r\n`);
|
|
193
195
|
// Compute Content-Length
|
|
194
|
-
contentLength +=
|
|
196
|
+
contentLength += length + prefix.length;
|
|
195
197
|
// Cache range.
|
|
196
|
-
ranges.push({ start,
|
|
198
|
+
ranges.push({ offset: start, length, prefix });
|
|
197
199
|
}
|
|
198
|
-
// The last add suffix boundary.
|
|
199
|
-
ranges[length - 1].suffix = suffix;
|
|
200
200
|
// Compute Content-Length.
|
|
201
|
-
contentLength +=
|
|
201
|
+
contentLength += suffix.length;
|
|
202
202
|
// Set Content-Length.
|
|
203
203
|
context.length = contentLength;
|
|
204
|
+
// The last add suffix boundary.
|
|
205
|
+
ranges[length - 1].suffix = suffix;
|
|
204
206
|
// Return ranges.
|
|
205
207
|
return ranges;
|
|
206
208
|
} else {
|
|
207
209
|
const [{ start, end }] = parsed;
|
|
210
|
+
const length = end - start + 1;
|
|
208
211
|
// Set Content-Length.
|
|
209
|
-
context.length =
|
|
212
|
+
context.length = length;
|
|
210
213
|
// Set Content-Range.
|
|
211
214
|
context.set('Content-Range', `bytes ${start}-${end}/${size}`);
|
|
212
215
|
// Return ranges.
|
|
213
|
-
return
|
|
216
|
+
return [{ offset: start, length }];
|
|
214
217
|
}
|
|
215
218
|
}
|
|
216
219
|
}
|
|
@@ -218,7 +221,7 @@ function parseRanges(context, stats) {
|
|
|
218
221
|
// Set Content-Length.
|
|
219
222
|
context.length = size;
|
|
220
223
|
// Return ranges.
|
|
221
|
-
return [{
|
|
224
|
+
return [{ offset: 0, length: size }];
|
|
222
225
|
}
|
|
223
226
|
|
|
224
227
|
exports.decodeURI = decodeURI;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* @package webpack-dev-service
|
|
3
3
|
* @license MIT
|
|
4
|
-
* @version 0.12.
|
|
4
|
+
* @version 0.12.2
|
|
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
|
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
|
|
10
10
|
'use strict';
|
|
11
11
|
|
|
12
|
-
const
|
|
12
|
+
const node_path = require('node:path');
|
|
13
13
|
|
|
14
14
|
/**
|
|
15
15
|
* @module path
|
|
@@ -36,9 +36,9 @@ function hasTrailingSlash(path) {
|
|
|
36
36
|
* @param path The path to check.
|
|
37
37
|
* @param root The root path.
|
|
38
38
|
*/
|
|
39
|
-
function isOutRoot(path
|
|
40
|
-
path
|
|
41
|
-
return /\.\.(?:[\\/]|$)/.test(path
|
|
39
|
+
function isOutRoot(path, root) {
|
|
40
|
+
path = node_path.relative(root, path);
|
|
41
|
+
return /\.\.(?:[\\/]|$)/.test(path) || node_path.isAbsolute(path);
|
|
42
42
|
}
|
|
43
43
|
|
|
44
44
|
exports.hasTrailingSlash = hasTrailingSlash;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* @package webpack-dev-service
|
|
3
3
|
* @license MIT
|
|
4
|
-
* @version 0.12.
|
|
4
|
+
* @version 0.12.2
|
|
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
|
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
|
|
10
10
|
'use strict';
|
|
11
11
|
|
|
12
|
-
const
|
|
12
|
+
const node_url = require('node:url');
|
|
13
13
|
const path = require('./path.cjs');
|
|
14
14
|
|
|
15
15
|
/**
|
|
@@ -39,7 +39,7 @@ function getPublicPath(compilation) {
|
|
|
39
39
|
const path = compilation.getPath(publicPath ?? '');
|
|
40
40
|
// Get public path without protocol.
|
|
41
41
|
try {
|
|
42
|
-
return new
|
|
42
|
+
return new node_url.URL(path).pathname;
|
|
43
43
|
} catch {
|
|
44
44
|
return normalize(path);
|
|
45
45
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* @package webpack-dev-service
|
|
3
3
|
* @license MIT
|
|
4
|
-
* @version 0.12.
|
|
4
|
+
* @version 0.12.2
|
|
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.12.
|
|
4
|
+
* @version 0.12.2
|
|
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.12.
|
|
4
|
+
* @version 0.12.2
|
|
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.12.
|
|
4
|
+
* @version 0.12.2
|
|
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.12.
|
|
4
|
+
* @version 0.12.2
|
|
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
|
|
@@ -9,8 +9,8 @@
|
|
|
9
9
|
|
|
10
10
|
'use strict';
|
|
11
11
|
|
|
12
|
-
const
|
|
13
|
-
const
|
|
12
|
+
const node_path = require('node:path');
|
|
13
|
+
const node_fs = require('node:fs');
|
|
14
14
|
const utils = require('../../utils.cjs');
|
|
15
15
|
|
|
16
16
|
/**
|
|
@@ -31,14 +31,14 @@ function setupWriteToDisk(context) {
|
|
|
31
31
|
if (!isAllowWrite(targetPath, filter)) {
|
|
32
32
|
return callback();
|
|
33
33
|
}
|
|
34
|
-
const dir =
|
|
34
|
+
const dir = node_path.dirname(targetPath);
|
|
35
35
|
const name = getCompilerName(compiler);
|
|
36
|
-
return
|
|
36
|
+
return node_fs.mkdir(dir, { recursive: true }, error => {
|
|
37
37
|
if (error) {
|
|
38
38
|
logger.error(`${name}unable to write "${dir}" directory to disk:\n${error}`);
|
|
39
39
|
return callback(error);
|
|
40
40
|
}
|
|
41
|
-
|
|
41
|
+
node_fs.writeFile(targetPath, content, error => {
|
|
42
42
|
if (error) {
|
|
43
43
|
logger.error(`${name}unable to write "${targetPath}" asset to disk:\n${error}`);
|
|
44
44
|
return callback(error);
|