webpack-dev-service 0.12.0 → 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 +31 -113
- package/cjs/server/dev/index.cjs +1 -1
- package/cjs/server/dev/middleware.cjs +8 -8
- 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 +22 -103
- package/esm/server/dev/index.js +1 -1
- package/esm/server/dev/middleware.js +8 -8
- 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 +10 -11
- package/types/server/dev/Service.d.ts +15 -32
- 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
|
|
@@ -9,12 +9,11 @@
|
|
|
9
9
|
|
|
10
10
|
'use strict';
|
|
11
11
|
|
|
12
|
-
const
|
|
13
|
-
const destroy = require('destroy');
|
|
14
|
-
const stream = require('stream');
|
|
12
|
+
const createETag = require('etag');
|
|
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
|
|
|
@@ -22,8 +21,7 @@ function _interopDefault(e) {
|
|
|
22
21
|
return e && e.__esModule ? e : { default: e };
|
|
23
22
|
}
|
|
24
23
|
|
|
25
|
-
const
|
|
26
|
-
const destroy__default = /*#__PURE__*/ _interopDefault(destroy);
|
|
24
|
+
const createETag__default = /*#__PURE__*/ _interopDefault(createETag);
|
|
27
25
|
|
|
28
26
|
/**
|
|
29
27
|
* @module Service
|
|
@@ -37,18 +35,18 @@ class Service {
|
|
|
37
35
|
/**
|
|
38
36
|
* @constructor
|
|
39
37
|
* @description Create file service.
|
|
40
|
-
* @param root
|
|
41
|
-
* @param options
|
|
38
|
+
* @param root The file service root.
|
|
39
|
+
* @param options The file service options.
|
|
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
|
|
49
47
|
* @method isIgnore
|
|
50
48
|
* @description Check if path is ignore.
|
|
51
|
-
* @param path
|
|
49
|
+
* @param path The path to check.
|
|
52
50
|
*/
|
|
53
51
|
isIgnore(path) {
|
|
54
52
|
const { ignore } = this.options;
|
|
@@ -57,10 +55,10 @@ class Service {
|
|
|
57
55
|
/**
|
|
58
56
|
* @private
|
|
59
57
|
* @method setupHeaders
|
|
60
|
-
* @description Setup headers
|
|
61
|
-
* @param context
|
|
62
|
-
* @param path
|
|
63
|
-
* @param stats
|
|
58
|
+
* @description Setup headers.
|
|
59
|
+
* @param context The koa context.
|
|
60
|
+
* @param path The file path.
|
|
61
|
+
* @param stats The file stats.
|
|
64
62
|
*/
|
|
65
63
|
setupHeaders(context, path, stats) {
|
|
66
64
|
const { options } = this;
|
|
@@ -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.
|
|
@@ -83,7 +81,7 @@ class Service {
|
|
|
83
81
|
context.remove('ETag');
|
|
84
82
|
} else {
|
|
85
83
|
// Set ETag.
|
|
86
|
-
context.set('ETag',
|
|
84
|
+
context.set('ETag', createETag__default.default(stats));
|
|
87
85
|
}
|
|
88
86
|
// Last-Modified.
|
|
89
87
|
if (options.lastModified === false) {
|
|
@@ -105,97 +103,15 @@ class Service {
|
|
|
105
103
|
}
|
|
106
104
|
}
|
|
107
105
|
}
|
|
108
|
-
/**
|
|
109
|
-
* @private
|
|
110
|
-
* @method write
|
|
111
|
-
* @description Write file to stream.
|
|
112
|
-
* @param stream Destination stream.
|
|
113
|
-
* @param path The file path to read.
|
|
114
|
-
* @param range The range to read.
|
|
115
|
-
* @param end Is destory destination stream after read complete.
|
|
116
|
-
*/
|
|
117
|
-
write(stream, path, range, 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.
|
|
166
|
-
* @param context Koa context.
|
|
167
|
-
* @param path File path.
|
|
168
|
-
* @param ranges Read ranges.
|
|
169
|
-
*/
|
|
170
|
-
async send(context, path, ranges) {
|
|
171
|
-
// Set stream body, highWaterMark 64kb.
|
|
172
|
-
const stream$1 = new stream.PassThrough({
|
|
173
|
-
highWaterMark: 65536
|
|
174
|
-
});
|
|
175
|
-
// Set response body.
|
|
176
|
-
context.body = stream$1;
|
|
177
|
-
// Ranges length.
|
|
178
|
-
let { length } = ranges;
|
|
179
|
-
// Write ranges to stream.
|
|
180
|
-
for (const range of ranges) {
|
|
181
|
-
// Write range.
|
|
182
|
-
const passed = await this.write(stream$1, path, range, --length === 0);
|
|
183
|
-
// If not passed, break.
|
|
184
|
-
if (!passed) {
|
|
185
|
-
break;
|
|
186
|
-
}
|
|
187
|
-
}
|
|
188
|
-
}
|
|
189
106
|
/**
|
|
190
107
|
* @public
|
|
191
|
-
* @method
|
|
192
|
-
* @description
|
|
193
|
-
* @param
|
|
194
|
-
* @param
|
|
108
|
+
* @method respond
|
|
109
|
+
* @description Respond file.
|
|
110
|
+
* @param pathname The pathname.
|
|
111
|
+
* @param context The koa context.
|
|
112
|
+
* @param publicPath The public path.
|
|
195
113
|
*/
|
|
196
|
-
async
|
|
197
|
-
// Get request pathname.
|
|
198
|
-
const pathname = context.path || '/';
|
|
114
|
+
async respond(pathname, context, publicPath) {
|
|
199
115
|
// Check public path.
|
|
200
116
|
if (!pathname.startsWith(publicPath)) {
|
|
201
117
|
return false;
|
|
@@ -207,17 +123,17 @@ class Service {
|
|
|
207
123
|
// Real pathname.
|
|
208
124
|
const realpath = pathname.slice(length);
|
|
209
125
|
// Get path of file.
|
|
210
|
-
const path$
|
|
126
|
+
const path$1 = path.unixify(node_path.join(root, realpath));
|
|
211
127
|
// Malicious path (403).
|
|
212
|
-
if (path.isOutRoot(path$
|
|
128
|
+
if (path.isOutRoot(path$1, root)) {
|
|
213
129
|
return false;
|
|
214
130
|
}
|
|
215
131
|
// Is ignore path or file (403).
|
|
216
|
-
if (this.isIgnore(path$
|
|
132
|
+
if (this.isIgnore(path$1)) {
|
|
217
133
|
return false;
|
|
218
134
|
}
|
|
219
135
|
// File stats.
|
|
220
|
-
const stats = await fs.stat(this.options.fs, path$
|
|
136
|
+
const stats = await fs.stat(this.options.fs, path$1);
|
|
221
137
|
// Check file stats.
|
|
222
138
|
if (
|
|
223
139
|
// File not exist (404 | 500).
|
|
@@ -225,12 +141,12 @@ class Service {
|
|
|
225
141
|
// Is directory (403).
|
|
226
142
|
stats.isDirectory() ||
|
|
227
143
|
// Not a directory but has trailing slash (404).
|
|
228
|
-
path.hasTrailingSlash(path$
|
|
144
|
+
path.hasTrailingSlash(path$1)
|
|
229
145
|
) {
|
|
230
146
|
return false;
|
|
231
147
|
}
|
|
232
148
|
// Setup headers.
|
|
233
|
-
this.setupHeaders(context, path$
|
|
149
|
+
this.setupHeaders(context, path$1, stats);
|
|
234
150
|
// Conditional get support.
|
|
235
151
|
if (http.isConditionalGET(context)) {
|
|
236
152
|
// Request precondition failure.
|
|
@@ -269,8 +185,10 @@ class Service {
|
|
|
269
185
|
if (ranges === -2) {
|
|
270
186
|
return context.throw(400);
|
|
271
187
|
}
|
|
272
|
-
//
|
|
273
|
-
|
|
188
|
+
// Ranges length.
|
|
189
|
+
const { fs: fs$1, highWaterMark } = this.options;
|
|
190
|
+
// Set response body.
|
|
191
|
+
context.body = new stream.FileReadStream(path$1, ranges, { fs: fs$1, highWaterMark });
|
|
274
192
|
// File found.
|
|
275
193
|
return true;
|
|
276
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
|
|
@@ -46,7 +46,7 @@ function getFileServices(context, stats) {
|
|
|
46
46
|
// Return services.
|
|
47
47
|
return services;
|
|
48
48
|
}
|
|
49
|
-
function getFileServicesAsync(context,
|
|
49
|
+
function getFileServicesAsync(context, pathname) {
|
|
50
50
|
return new Promise(resolve => {
|
|
51
51
|
const { stats } = context;
|
|
52
52
|
// If stats exists, resolve immediately.
|
|
@@ -54,7 +54,7 @@ function getFileServicesAsync(context, path) {
|
|
|
54
54
|
resolve(getFileServices(context, stats));
|
|
55
55
|
} else {
|
|
56
56
|
// Log waiting info.
|
|
57
|
-
context.logger.info(`wait until bundle finished: ${
|
|
57
|
+
context.logger.info(`wait until bundle finished: ${pathname}`);
|
|
58
58
|
// Otherwise, wait until bundle finished.
|
|
59
59
|
ready.ready(context, stats => {
|
|
60
60
|
resolve(getFileServices(context, stats));
|
|
@@ -65,18 +65,18 @@ function getFileServicesAsync(context, path) {
|
|
|
65
65
|
function middleware(context) {
|
|
66
66
|
// Middleware.
|
|
67
67
|
return async (ctx, next) => {
|
|
68
|
-
const
|
|
69
|
-
//
|
|
70
|
-
if (
|
|
68
|
+
const pathname = http.decodeURI(ctx.path);
|
|
69
|
+
// Pathname decode failed or includes null byte(s).
|
|
70
|
+
if (pathname === -1 || pathname.includes('\0')) {
|
|
71
71
|
return ctx.throw(400);
|
|
72
72
|
}
|
|
73
73
|
// Only support GET and HEAD (405).
|
|
74
74
|
if (ctx.method === 'GET' || ctx.method === 'HEAD') {
|
|
75
75
|
// Get the file services.
|
|
76
|
-
const services = await getFileServicesAsync(context,
|
|
76
|
+
const services = await getFileServicesAsync(context, pathname);
|
|
77
77
|
// Try to respond.
|
|
78
78
|
for (const [publicPath, service] of services) {
|
|
79
|
-
if (await service.
|
|
79
|
+
if (await service.respond(pathname, ctx, publicPath)) {
|
|
80
80
|
return;
|
|
81
81
|
}
|
|
82
82
|
}
|
|
@@ -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
|