@atlaspack/reporter-dev-server 2.14.21-typescript-5b4d3ad41.0 → 2.14.21
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/CHANGELOG.md +9 -0
- package/lib/HMRServer.js +3 -10
- package/lib/Server.js +3 -24
- package/lib/ServerReporter.js +1 -2
- package/lib/serverErrors.js +0 -3
- package/package.json +9 -14
- package/src/{HMRServer.ts → HMRServer.js} +33 -59
- package/src/{Server.ts → Server.js} +36 -57
- package/src/{ServerReporter.ts → ServerReporter.js} +5 -4
- package/src/{serverErrors.ts → serverErrors.js} +5 -6
- package/src/types.js.flow +56 -0
- package/templates/404.html +1 -1
- package/templates/500.html +1 -1
- package/LICENSE +0 -201
- package/lib/HMRServer.d.ts +0 -54
- package/lib/Server.d.ts +0 -45
- package/lib/ServerReporter.d.ts +0 -3
- package/lib/serverErrors.d.ts +0 -4
- package/tsconfig.json +0 -4
package/CHANGELOG.md
CHANGED
package/lib/HMRServer.js
CHANGED
|
@@ -48,18 +48,10 @@ function _utils() {
|
|
|
48
48
|
return data;
|
|
49
49
|
}
|
|
50
50
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
51
|
-
// @ts-expect-error TS7016
|
|
52
|
-
|
|
53
|
-
// flow-to-ts helpers
|
|
54
|
-
|
|
55
|
-
// /flow-to-ts helpers
|
|
56
|
-
|
|
57
51
|
const FS_CONCURRENCY = 64;
|
|
58
52
|
const HMR_ENDPOINT = '/__parcel_hmr';
|
|
59
53
|
const BROADCAST_MAX_ASSETS = 10000;
|
|
60
54
|
class HMRServer {
|
|
61
|
-
// @ts-expect-error TS2564
|
|
62
|
-
|
|
63
55
|
unresolvedError = null;
|
|
64
56
|
bundleGraph = null;
|
|
65
57
|
constructor(options) {
|
|
@@ -96,6 +88,8 @@ class HMRServer {
|
|
|
96
88
|
ws.send(JSON.stringify(this.unresolvedError));
|
|
97
89
|
}
|
|
98
90
|
});
|
|
91
|
+
|
|
92
|
+
// $FlowFixMe[incompatible-exact]
|
|
99
93
|
this.wss.on('error', err => this.handleSocketError(err));
|
|
100
94
|
}
|
|
101
95
|
handle(req, res) {
|
|
@@ -171,7 +165,6 @@ class HMRServer {
|
|
|
171
165
|
});
|
|
172
166
|
if (isOnlyReferencedByRuntimes) {
|
|
173
167
|
for (let runtime of runtimes) {
|
|
174
|
-
// @ts-expect-error TS2345
|
|
175
168
|
changedAssets.add(runtime);
|
|
176
169
|
}
|
|
177
170
|
continue;
|
|
@@ -211,7 +204,6 @@ class HMRServer {
|
|
|
211
204
|
} else {
|
|
212
205
|
this.broadcast({
|
|
213
206
|
type: 'update',
|
|
214
|
-
// @ts-expect-error TS2322
|
|
215
207
|
assets
|
|
216
208
|
});
|
|
217
209
|
}
|
|
@@ -228,6 +220,7 @@ class HMRServer {
|
|
|
228
220
|
let sourcemapStringified = await sourcemap.stringify({
|
|
229
221
|
format: 'inline',
|
|
230
222
|
sourceRoot: _Server.SOURCES_ENDPOINT + '/',
|
|
223
|
+
// $FlowFixMe
|
|
231
224
|
fs: asset.fs
|
|
232
225
|
});
|
|
233
226
|
(0, _assert().default)(typeof sourcemapStringified === 'string');
|
package/lib/Server.js
CHANGED
|
@@ -86,18 +86,6 @@ function _fresh() {
|
|
|
86
86
|
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
|
|
87
87
|
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && Object.prototype.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
|
|
88
88
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
89
|
-
// @ts-expect-error TS2307
|
|
90
|
-
|
|
91
|
-
// @ts-expect-error TS7016
|
|
92
|
-
|
|
93
|
-
// @ts-expect-error TS7016
|
|
94
|
-
|
|
95
|
-
// @ts-expect-error TS7016
|
|
96
|
-
|
|
97
|
-
// @ts-expect-error TS7016
|
|
98
|
-
|
|
99
|
-
// @ts-expect-error TS7016
|
|
100
|
-
|
|
101
89
|
function setHeaders(res) {
|
|
102
90
|
res.setHeader('Access-Control-Allow-Origin', '*');
|
|
103
91
|
res.setHeader('Access-Control-Allow-Methods', 'GET, HEAD, PUT, PATCH, POST, DELETE');
|
|
@@ -336,13 +324,9 @@ class Server {
|
|
|
336
324
|
public: root,
|
|
337
325
|
cleanUrls: false
|
|
338
326
|
}, {
|
|
339
|
-
// @ts-expect-error TS7006
|
|
340
327
|
lstat: path => fs.stat(path),
|
|
341
|
-
// @ts-expect-error TS7006
|
|
342
328
|
realpath: path => fs.realpath(path),
|
|
343
|
-
// @ts-expect-error TS7006
|
|
344
329
|
createReadStream: (path, options) => fs.createReadStream(path, options),
|
|
345
|
-
// @ts-expect-error TS7006
|
|
346
330
|
readdir: path => fs.readdir(path)
|
|
347
331
|
});
|
|
348
332
|
}
|
|
@@ -395,12 +379,13 @@ class Server {
|
|
|
395
379
|
}
|
|
396
380
|
for (const [context, options] of Object.entries(cfg)) {
|
|
397
381
|
// each key is interpreted as context, and value as middleware options
|
|
398
|
-
// @ts-expect-error TS2345
|
|
399
382
|
app.use((0, _httpProxyMiddleware().createProxyMiddleware)(context, options));
|
|
400
383
|
}
|
|
401
384
|
} else {
|
|
402
385
|
let cfg = await this.options.packageManager.require(configFilePath, fileInRoot);
|
|
403
|
-
if (
|
|
386
|
+
if (
|
|
387
|
+
// $FlowFixMe
|
|
388
|
+
Object.prototype.toString.call(cfg) === '[object Module]') {
|
|
404
389
|
cfg = cfg.default;
|
|
405
390
|
}
|
|
406
391
|
if (typeof cfg !== 'function') {
|
|
@@ -425,13 +410,10 @@ class Server {
|
|
|
425
410
|
}
|
|
426
411
|
};
|
|
427
412
|
const app = (0, _connect().default)();
|
|
428
|
-
// @ts-expect-error TS7006
|
|
429
413
|
app.use((req, res, next) => {
|
|
430
414
|
setHeaders(res);
|
|
431
415
|
next();
|
|
432
416
|
});
|
|
433
|
-
|
|
434
|
-
// @ts-expect-error TS7006
|
|
435
417
|
app.use((req, res, next) => {
|
|
436
418
|
if (req.url === '/__parcel_healthcheck') {
|
|
437
419
|
res.statusCode = 200;
|
|
@@ -456,17 +438,14 @@ class Server {
|
|
|
456
438
|
});
|
|
457
439
|
this.stopServer = stop;
|
|
458
440
|
server.listen(this.options.port, this.options.host);
|
|
459
|
-
// @ts-expect-error TS2322
|
|
460
441
|
return new Promise((resolve, reject) => {
|
|
461
442
|
server.once('error', err => {
|
|
462
443
|
this.options.logger.error({
|
|
463
|
-
// @ts-expect-error TS2345
|
|
464
444
|
message: (0, _serverErrors.default)(err, this.options.port)
|
|
465
445
|
});
|
|
466
446
|
reject(err);
|
|
467
447
|
});
|
|
468
448
|
server.once('listening', () => {
|
|
469
|
-
// @ts-expect-error TS2345
|
|
470
449
|
resolve(server);
|
|
471
450
|
});
|
|
472
451
|
});
|
package/lib/ServerReporter.js
CHANGED
|
@@ -61,7 +61,6 @@ var _default = exports.default = new (_plugin().Reporter)({
|
|
|
61
61
|
port: serveOptions.port,
|
|
62
62
|
host: hmrOptions.host,
|
|
63
63
|
devServer,
|
|
64
|
-
// @ts-expect-error TS7006
|
|
65
64
|
addMiddleware: handler => {
|
|
66
65
|
var _server;
|
|
67
66
|
(_server = server) === null || _server === void 0 || _server.middleware.push(handler);
|
|
@@ -107,7 +106,7 @@ var _default = exports.default = new (_plugin().Reporter)({
|
|
|
107
106
|
}
|
|
108
107
|
if (hmrOptions && hmrServer) {
|
|
109
108
|
await hmrServer.stop();
|
|
110
|
-
//
|
|
109
|
+
// $FlowFixMe[prop-missing]
|
|
111
110
|
hmrServers.delete(hmrServer.wss.options.port);
|
|
112
111
|
}
|
|
113
112
|
break;
|
package/lib/serverErrors.js
CHANGED
|
@@ -10,10 +10,7 @@ const serverErrorList = {
|
|
|
10
10
|
};
|
|
11
11
|
function serverErrors(err, port) {
|
|
12
12
|
let desc = `Error: ${err.code} occurred while setting up server on port ${port.toString()}.`;
|
|
13
|
-
|
|
14
|
-
// @ts-expect-error TS7053
|
|
15
13
|
if (serverErrorList[err.code]) {
|
|
16
|
-
// @ts-expect-error TS7053
|
|
17
14
|
desc = serverErrorList[err.code].replace(/{port}/g, port);
|
|
18
15
|
}
|
|
19
16
|
return desc;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@atlaspack/reporter-dev-server",
|
|
3
|
-
"version": "2.14.21
|
|
3
|
+
"version": "2.14.21",
|
|
4
4
|
"description": "Blazing fast, zero configuration web application bundler",
|
|
5
5
|
"license": "(MIT OR Apache-2.0)",
|
|
6
6
|
"type": "commonjs",
|
|
@@ -11,9 +11,8 @@
|
|
|
11
11
|
"type": "git",
|
|
12
12
|
"url": "https://github.com/atlassian-labs/atlaspack.git"
|
|
13
13
|
},
|
|
14
|
-
"main": "
|
|
15
|
-
"source": "
|
|
16
|
-
"types": "./lib/ServerReporter.d.ts",
|
|
14
|
+
"main": "lib/ServerReporter.js",
|
|
15
|
+
"source": "src/ServerReporter.js",
|
|
17
16
|
"engines": {
|
|
18
17
|
"node": ">= 16.0.0"
|
|
19
18
|
},
|
|
@@ -26,9 +25,9 @@
|
|
|
26
25
|
}
|
|
27
26
|
},
|
|
28
27
|
"dependencies": {
|
|
29
|
-
"@atlaspack/plugin": "2.14.21
|
|
30
|
-
"@atlaspack/
|
|
31
|
-
"@atlaspack/
|
|
28
|
+
"@atlaspack/plugin": "2.14.21",
|
|
29
|
+
"@atlaspack/utils": "2.17.3",
|
|
30
|
+
"@atlaspack/types": "2.15.11",
|
|
32
31
|
"connect": "^3.7.0",
|
|
33
32
|
"ejs": "^3.1.6",
|
|
34
33
|
"fresh": "^0.5.2",
|
|
@@ -40,10 +39,6 @@
|
|
|
40
39
|
"ws": "^7.0.0"
|
|
41
40
|
},
|
|
42
41
|
"devDependencies": {
|
|
43
|
-
"@atlaspack/babel-preset": "2.14.
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
"check-ts": "tsc --emitDeclarationOnly --rootDir src"
|
|
47
|
-
},
|
|
48
|
-
"gitHead": "5b4d3ad41ffa002b989ba77271bb3010a1f05b2a"
|
|
49
|
-
}
|
|
42
|
+
"@atlaspack/babel-preset": "2.14.1"
|
|
43
|
+
}
|
|
44
|
+
}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
// @flow
|
|
1
2
|
import type {
|
|
2
3
|
Asset,
|
|
3
4
|
BundleGraph,
|
|
@@ -13,13 +14,11 @@ import type {
|
|
|
13
14
|
HMRServerOptions,
|
|
14
15
|
Request,
|
|
15
16
|
Response,
|
|
16
|
-
// @ts-expect-error TS2307
|
|
17
17
|
} from './types.js.flow';
|
|
18
18
|
import {setHeaders, SOURCES_ENDPOINT} from './Server';
|
|
19
19
|
|
|
20
20
|
import nullthrows from 'nullthrows';
|
|
21
21
|
import url from 'url';
|
|
22
|
-
// @ts-expect-error TS7016
|
|
23
22
|
import mime from 'mime-types';
|
|
24
23
|
import WebSocket from 'ws';
|
|
25
24
|
import invariant from 'assert';
|
|
@@ -30,65 +29,43 @@ import {
|
|
|
30
29
|
PromiseQueue,
|
|
31
30
|
} from '@atlaspack/utils';
|
|
32
31
|
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
id: string;
|
|
43
|
-
url: string;
|
|
44
|
-
type: string;
|
|
45
|
-
output: string;
|
|
46
|
-
envHash: string;
|
|
47
|
-
outputFormat: string;
|
|
48
|
-
depsByBundle: {
|
|
49
|
-
[key: string]: {
|
|
50
|
-
[key: string]: string;
|
|
51
|
-
};
|
|
52
|
-
};
|
|
53
|
-
};
|
|
32
|
+
export type HMRAsset = {|
|
|
33
|
+
id: string,
|
|
34
|
+
url: string,
|
|
35
|
+
type: string,
|
|
36
|
+
output: string,
|
|
37
|
+
envHash: string,
|
|
38
|
+
outputFormat: string,
|
|
39
|
+
depsByBundle: {[string]: {[string]: string, ...}, ...},
|
|
40
|
+
|};
|
|
54
41
|
|
|
55
42
|
export type HMRMessage =
|
|
56
|
-
| {
|
|
57
|
-
type: 'update'
|
|
58
|
-
assets: Array<HMRAsset
|
|
59
|
-
}
|
|
60
|
-
| {
|
|
61
|
-
type: 'reload'
|
|
62
|
-
}
|
|
63
|
-
| {
|
|
64
|
-
type: 'error'
|
|
65
|
-
diagnostics: {
|
|
66
|
-
ansi: Array<AnsiDiagnosticResult
|
|
67
|
-
html: Array<
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
AnsiDiagnosticResult,
|
|
71
|
-
{
|
|
72
|
-
codeframe: string;
|
|
73
|
-
}
|
|
74
|
-
>
|
|
75
|
-
>
|
|
76
|
-
>;
|
|
77
|
-
};
|
|
78
|
-
};
|
|
43
|
+
| {|
|
|
44
|
+
type: 'update',
|
|
45
|
+
assets: Array<HMRAsset>,
|
|
46
|
+
|}
|
|
47
|
+
| {|
|
|
48
|
+
type: 'reload',
|
|
49
|
+
|}
|
|
50
|
+
| {|
|
|
51
|
+
type: 'error',
|
|
52
|
+
diagnostics: {|
|
|
53
|
+
ansi: Array<AnsiDiagnosticResult>,
|
|
54
|
+
html: Array<$Rest<AnsiDiagnosticResult, {|codeframe: string|}>>,
|
|
55
|
+
|},
|
|
56
|
+
|};
|
|
79
57
|
|
|
80
58
|
const FS_CONCURRENCY = 64;
|
|
81
59
|
const HMR_ENDPOINT = '/__parcel_hmr';
|
|
82
60
|
const BROADCAST_MAX_ASSETS = 10000;
|
|
83
61
|
|
|
84
62
|
export default class HMRServer {
|
|
85
|
-
// @ts-expect-error TS2564
|
|
86
63
|
wss: WebSocket.Server;
|
|
87
64
|
unresolvedError: HMRMessage | null = null;
|
|
88
65
|
options: HMRServerOptions;
|
|
89
66
|
bundleGraph: BundleGraph<PackagedBundle> | BundleGraph<NamedBundle> | null =
|
|
90
67
|
null;
|
|
91
|
-
stopServer: (
|
|
68
|
+
stopServer: ?() => Promise<void>;
|
|
92
69
|
|
|
93
70
|
constructor(options: HMRServerOptions) {
|
|
94
71
|
this.options = options;
|
|
@@ -114,9 +91,7 @@ export default class HMRServer {
|
|
|
114
91
|
server.listen(this.options.port, this.options.host);
|
|
115
92
|
this.stopServer = result.stop;
|
|
116
93
|
} else {
|
|
117
|
-
this.options.addMiddleware?.((req
|
|
118
|
-
this.handle(req, res),
|
|
119
|
-
);
|
|
94
|
+
this.options.addMiddleware?.((req, res) => this.handle(req, res));
|
|
120
95
|
}
|
|
121
96
|
this.wss = new WebSocket.Server({server});
|
|
122
97
|
|
|
@@ -126,6 +101,7 @@ export default class HMRServer {
|
|
|
126
101
|
}
|
|
127
102
|
});
|
|
128
103
|
|
|
104
|
+
// $FlowFixMe[incompatible-exact]
|
|
129
105
|
this.wss.on('error', (err) => this.handleSocketError(err));
|
|
130
106
|
}
|
|
131
107
|
|
|
@@ -182,10 +158,9 @@ export default class HMRServer {
|
|
|
182
158
|
}
|
|
183
159
|
|
|
184
160
|
async emitUpdate(event: {
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
readonly changedAssets: Map<string, Asset>;
|
|
161
|
+
+bundleGraph: BundleGraph<PackagedBundle> | BundleGraph<NamedBundle>,
|
|
162
|
+
+changedAssets: Map<string, Asset>,
|
|
163
|
+
...
|
|
189
164
|
}) {
|
|
190
165
|
this.unresolvedError = null;
|
|
191
166
|
this.bundleGraph = event.bundleGraph;
|
|
@@ -212,7 +187,6 @@ export default class HMRServer {
|
|
|
212
187
|
|
|
213
188
|
if (isOnlyReferencedByRuntimes) {
|
|
214
189
|
for (let runtime of runtimes) {
|
|
215
|
-
// @ts-expect-error TS2345
|
|
216
190
|
changedAssets.add(runtime);
|
|
217
191
|
}
|
|
218
192
|
|
|
@@ -222,9 +196,9 @@ export default class HMRServer {
|
|
|
222
196
|
|
|
223
197
|
queue.add(async () => {
|
|
224
198
|
let dependencies = event.bundleGraph.getDependencies(asset);
|
|
225
|
-
let depsByBundle
|
|
199
|
+
let depsByBundle = {};
|
|
226
200
|
for (let bundle of event.bundleGraph.getBundlesWithAsset(asset)) {
|
|
227
|
-
let deps
|
|
201
|
+
let deps = {};
|
|
228
202
|
for (let dep of dependencies) {
|
|
229
203
|
let resolved = event.bundleGraph.getResolvedAsset(dep, bundle);
|
|
230
204
|
if (resolved) {
|
|
@@ -257,7 +231,6 @@ export default class HMRServer {
|
|
|
257
231
|
} else {
|
|
258
232
|
this.broadcast({
|
|
259
233
|
type: 'update',
|
|
260
|
-
// @ts-expect-error TS2322
|
|
261
234
|
assets,
|
|
262
235
|
});
|
|
263
236
|
}
|
|
@@ -276,6 +249,7 @@ export default class HMRServer {
|
|
|
276
249
|
let sourcemapStringified = await sourcemap.stringify({
|
|
277
250
|
format: 'inline',
|
|
278
251
|
sourceRoot: SOURCES_ENDPOINT + '/',
|
|
252
|
+
// $FlowFixMe
|
|
279
253
|
fs: asset.fs,
|
|
280
254
|
});
|
|
281
255
|
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
// @
|
|
1
|
+
// @flow
|
|
2
|
+
|
|
2
3
|
import type {DevServerOptions, Request, Response} from './types.js.flow';
|
|
3
4
|
import type {
|
|
4
5
|
BuildSuccessEvent,
|
|
@@ -24,17 +25,12 @@ import {
|
|
|
24
25
|
} from '@atlaspack/utils';
|
|
25
26
|
import serverErrors from './serverErrors';
|
|
26
27
|
import fs from 'fs';
|
|
27
|
-
// @ts-expect-error TS7016
|
|
28
28
|
import ejs from 'ejs';
|
|
29
|
-
// @ts-expect-error TS7016
|
|
30
29
|
import connect from 'connect';
|
|
31
|
-
// @ts-expect-error TS7016
|
|
32
30
|
import serveHandler from 'serve-handler';
|
|
33
31
|
import {createProxyMiddleware} from 'http-proxy-middleware';
|
|
34
32
|
import {URL, URLSearchParams} from 'url';
|
|
35
|
-
// @ts-expect-error TS7016
|
|
36
33
|
import launchEditor from 'launch-editor';
|
|
37
|
-
// @ts-expect-error TS7016
|
|
38
34
|
import fresh from 'fresh';
|
|
39
35
|
|
|
40
36
|
export function setHeaders(res: Response) {
|
|
@@ -63,11 +59,7 @@ const TEMPLATE_500 = fs.readFileSync(
|
|
|
63
59
|
path.join(__dirname, '..', 'templates/500.html'),
|
|
64
60
|
'utf8',
|
|
65
61
|
);
|
|
66
|
-
type NextFunction = (
|
|
67
|
-
req: Request,
|
|
68
|
-
res: Response,
|
|
69
|
-
next?: (arg1?: any) => any,
|
|
70
|
-
) => any;
|
|
62
|
+
type NextFunction = (req: Request, res: Response, next?: (any) => any) => any;
|
|
71
63
|
|
|
72
64
|
export default class Server {
|
|
73
65
|
pending: boolean;
|
|
@@ -76,24 +68,21 @@ export default class Server {
|
|
|
76
68
|
options: DevServerOptions;
|
|
77
69
|
rootPath: string;
|
|
78
70
|
bundleGraph: BundleGraph<PackagedBundle> | null;
|
|
79
|
-
requestBundle:
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
documentation: string;
|
|
89
|
-
}> | null;
|
|
90
|
-
stopServer: (() => Promise<void>) | null | undefined;
|
|
71
|
+
requestBundle: ?(bundle: PackagedBundle) => Promise<BuildSuccessEvent>;
|
|
72
|
+
errors: Array<{|
|
|
73
|
+
message: string,
|
|
74
|
+
stack: ?string,
|
|
75
|
+
frames: Array<FormattedCodeFrame>,
|
|
76
|
+
hints: Array<string>,
|
|
77
|
+
documentation: string,
|
|
78
|
+
|}> | null;
|
|
79
|
+
stopServer: ?() => Promise<void>;
|
|
91
80
|
|
|
92
81
|
constructor(options: DevServerOptions) {
|
|
93
82
|
this.options = options;
|
|
94
83
|
try {
|
|
95
84
|
this.rootPath = new URL(options.publicUrl).pathname;
|
|
96
|
-
} catch (e
|
|
85
|
+
} catch (e) {
|
|
97
86
|
this.rootPath = options.publicUrl;
|
|
98
87
|
}
|
|
99
88
|
this.pending = true;
|
|
@@ -146,7 +135,7 @@ export default class Server {
|
|
|
146
135
|
);
|
|
147
136
|
}
|
|
148
137
|
|
|
149
|
-
respond(req: Request, res: Response):
|
|
138
|
+
respond(req: Request, res: Response): mixed {
|
|
150
139
|
if (this.middleware.some((handler) => handler(req, res))) return;
|
|
151
140
|
let {pathname, search} = url.parse(req.originalUrl || req.url);
|
|
152
141
|
if (pathname == null) {
|
|
@@ -292,7 +281,7 @@ export default class Server {
|
|
|
292
281
|
invariant(this.requestBundle != null);
|
|
293
282
|
try {
|
|
294
283
|
await this.requestBundle(bundle);
|
|
295
|
-
} catch (err
|
|
284
|
+
} catch (err) {
|
|
296
285
|
this.send500(req, res);
|
|
297
286
|
return;
|
|
298
287
|
}
|
|
@@ -307,7 +296,7 @@ export default class Server {
|
|
|
307
296
|
req: Request,
|
|
308
297
|
res: Response,
|
|
309
298
|
next: NextFunction,
|
|
310
|
-
): Promise<
|
|
299
|
+
): Promise<void> | Promise<mixed> {
|
|
311
300
|
return this.serve(
|
|
312
301
|
this.options.outputFS,
|
|
313
302
|
this.options.distDir,
|
|
@@ -323,7 +312,7 @@ export default class Server {
|
|
|
323
312
|
req: Request,
|
|
324
313
|
res: Response,
|
|
325
314
|
next: NextFunction,
|
|
326
|
-
): Promise<
|
|
315
|
+
): Promise<mixed> {
|
|
327
316
|
if (req.method !== 'GET' && req.method !== 'HEAD') {
|
|
328
317
|
// method not allowed
|
|
329
318
|
res.statusCode = 405;
|
|
@@ -336,7 +325,7 @@ export default class Server {
|
|
|
336
325
|
try {
|
|
337
326
|
var filePath = url.parse(req.url).pathname || '';
|
|
338
327
|
filePath = decodeURIComponent(filePath);
|
|
339
|
-
} catch (err
|
|
328
|
+
} catch (err) {
|
|
340
329
|
return this.sendError(res, 400);
|
|
341
330
|
}
|
|
342
331
|
|
|
@@ -354,7 +343,7 @@ export default class Server {
|
|
|
354
343
|
|
|
355
344
|
try {
|
|
356
345
|
var stat = await fs.stat(filePath);
|
|
357
|
-
} catch (err
|
|
346
|
+
} catch (err) {
|
|
358
347
|
if (err.code === 'ENOENT') {
|
|
359
348
|
return next(req, res);
|
|
360
349
|
}
|
|
@@ -381,13 +370,9 @@ export default class Server {
|
|
|
381
370
|
cleanUrls: false,
|
|
382
371
|
},
|
|
383
372
|
{
|
|
384
|
-
// @ts-expect-error TS7006
|
|
385
373
|
lstat: (path) => fs.stat(path),
|
|
386
|
-
// @ts-expect-error TS7006
|
|
387
374
|
realpath: (path) => fs.realpath(path),
|
|
388
|
-
// @ts-expect-error TS7006
|
|
389
375
|
createReadStream: (path, options) => fs.createReadStream(path, options),
|
|
390
|
-
// @ts-expect-error TS7006
|
|
391
376
|
readdir: (path) => fs.readdir(path),
|
|
392
377
|
},
|
|
393
378
|
);
|
|
@@ -403,7 +388,7 @@ export default class Server {
|
|
|
403
388
|
res.end(TEMPLATE_404);
|
|
404
389
|
}
|
|
405
390
|
|
|
406
|
-
send500(req: Request, res: Response):
|
|
391
|
+
send500(req: Request, res: Response): void | Response {
|
|
407
392
|
res.setHeader('Content-Type', 'text/html; charset=utf-8');
|
|
408
393
|
res.writeHead(500);
|
|
409
394
|
|
|
@@ -467,7 +452,6 @@ export default class Server {
|
|
|
467
452
|
}
|
|
468
453
|
for (const [context, options] of Object.entries(cfg)) {
|
|
469
454
|
// each key is interpreted as context, and value as middleware options
|
|
470
|
-
// @ts-expect-error TS2345
|
|
471
455
|
app.use(createProxyMiddleware(context, options));
|
|
472
456
|
}
|
|
473
457
|
} else {
|
|
@@ -475,7 +459,10 @@ export default class Server {
|
|
|
475
459
|
configFilePath,
|
|
476
460
|
fileInRoot,
|
|
477
461
|
);
|
|
478
|
-
if (
|
|
462
|
+
if (
|
|
463
|
+
// $FlowFixMe
|
|
464
|
+
Object.prototype.toString.call(cfg) === '[object Module]'
|
|
465
|
+
) {
|
|
479
466
|
cfg = cfg.default;
|
|
480
467
|
}
|
|
481
468
|
|
|
@@ -504,13 +491,11 @@ export default class Server {
|
|
|
504
491
|
};
|
|
505
492
|
|
|
506
493
|
const app = connect();
|
|
507
|
-
// @ts-expect-error TS7006
|
|
508
494
|
app.use((req, res, next) => {
|
|
509
495
|
setHeaders(res);
|
|
510
496
|
next();
|
|
511
497
|
});
|
|
512
498
|
|
|
513
|
-
// @ts-expect-error TS7006
|
|
514
499
|
app.use((req, res, next) => {
|
|
515
500
|
if (req.url === '/__parcel_healthcheck') {
|
|
516
501
|
res.statusCode = 200;
|
|
@@ -535,26 +520,20 @@ export default class Server {
|
|
|
535
520
|
this.stopServer = stop;
|
|
536
521
|
|
|
537
522
|
server.listen(this.options.port, this.options.host);
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
reject: (error?: any) => void,
|
|
543
|
-
) => {
|
|
544
|
-
server.once('error', (err) => {
|
|
545
|
-
this.options.logger.error({
|
|
546
|
-
// @ts-expect-error TS2345
|
|
523
|
+
return new Promise((resolve, reject) => {
|
|
524
|
+
server.once('error', (err) => {
|
|
525
|
+
this.options.logger.error(
|
|
526
|
+
({
|
|
547
527
|
message: serverErrors(err, this.options.port),
|
|
548
|
-
}
|
|
549
|
-
|
|
550
|
-
|
|
528
|
+
}: Diagnostic),
|
|
529
|
+
);
|
|
530
|
+
reject(err);
|
|
531
|
+
});
|
|
551
532
|
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
},
|
|
557
|
-
);
|
|
533
|
+
server.once('listening', () => {
|
|
534
|
+
resolve(server);
|
|
535
|
+
});
|
|
536
|
+
});
|
|
558
537
|
}
|
|
559
538
|
|
|
560
539
|
async stop(): Promise<void> {
|
|
@@ -1,10 +1,12 @@
|
|
|
1
|
+
// @flow
|
|
2
|
+
|
|
1
3
|
import {Reporter} from '@atlaspack/plugin';
|
|
2
4
|
import HMRServer from './HMRServer';
|
|
3
5
|
import Server from './Server';
|
|
4
6
|
|
|
5
7
|
let servers: Map<number, Server> = new Map();
|
|
6
8
|
let hmrServers: Map<number, HMRServer> = new Map();
|
|
7
|
-
export default new Reporter({
|
|
9
|
+
export default (new Reporter({
|
|
8
10
|
async report({event, options, logger}) {
|
|
9
11
|
let {serveOptions, hmrOptions} = options;
|
|
10
12
|
let server = serveOptions ? servers.get(serveOptions.port) : undefined;
|
|
@@ -45,7 +47,6 @@ export default new Reporter({
|
|
|
45
47
|
port: serveOptions.port,
|
|
46
48
|
host: hmrOptions.host,
|
|
47
49
|
devServer,
|
|
48
|
-
// @ts-expect-error TS7006
|
|
49
50
|
addMiddleware: (handler) => {
|
|
50
51
|
server?.middleware.push(handler);
|
|
51
52
|
},
|
|
@@ -92,7 +93,7 @@ export default new Reporter({
|
|
|
92
93
|
}
|
|
93
94
|
if (hmrOptions && hmrServer) {
|
|
94
95
|
await hmrServer.stop();
|
|
95
|
-
//
|
|
96
|
+
// $FlowFixMe[prop-missing]
|
|
96
97
|
hmrServers.delete(hmrServer.wss.options.port);
|
|
97
98
|
}
|
|
98
99
|
break;
|
|
@@ -139,4 +140,4 @@ export default new Reporter({
|
|
|
139
140
|
break;
|
|
140
141
|
}
|
|
141
142
|
},
|
|
142
|
-
})
|
|
143
|
+
}): Reporter);
|
|
@@ -1,20 +1,19 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
// @flow
|
|
2
|
+
export type ServerError = Error & {|
|
|
3
|
+
code: string,
|
|
4
|
+
|};
|
|
4
5
|
|
|
5
6
|
const serverErrorList = {
|
|
6
7
|
EACCES: "You don't have access to bind the server to port {port}.",
|
|
7
8
|
EADDRINUSE: 'There is already a process listening on port {port}.',
|
|
8
|
-
}
|
|
9
|
+
};
|
|
9
10
|
|
|
10
11
|
export default function serverErrors(err: ServerError, port: number): string {
|
|
11
12
|
let desc = `Error: ${
|
|
12
13
|
err.code
|
|
13
14
|
} occurred while setting up server on port ${port.toString()}.`;
|
|
14
15
|
|
|
15
|
-
// @ts-expect-error TS7053
|
|
16
16
|
if (serverErrorList[err.code]) {
|
|
17
|
-
// @ts-expect-error TS7053
|
|
18
17
|
desc = serverErrorList[err.code].replace(/{port}/g, port);
|
|
19
18
|
}
|
|
20
19
|
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
// @flow
|
|
2
|
+
import type {
|
|
3
|
+
ServerOptions,
|
|
4
|
+
PluginLogger,
|
|
5
|
+
HMROptions,
|
|
6
|
+
HTTPSOptions,
|
|
7
|
+
FilePath,
|
|
8
|
+
} from '@atlaspack/types';
|
|
9
|
+
import type {FileSystem} from '@atlaspack/fs';
|
|
10
|
+
import type {HTTPServer} from '@atlaspack/utils';
|
|
11
|
+
import type {PackageManager} from '@atlaspack/package-manager';
|
|
12
|
+
import {
|
|
13
|
+
IncomingMessage as HTTPIncomingMessage,
|
|
14
|
+
ServerResponse as HTTPServerResponse,
|
|
15
|
+
} from 'http';
|
|
16
|
+
import {
|
|
17
|
+
IncomingMessage as HTTPSIncomingMessage,
|
|
18
|
+
ServerResponse as HTTPSServerResponse,
|
|
19
|
+
} from 'https';
|
|
20
|
+
|
|
21
|
+
interface HTTPRequest extends HTTPIncomingMessage {
|
|
22
|
+
originalUrl?: string;
|
|
23
|
+
}
|
|
24
|
+
interface HTTPSRequest extends HTTPSIncomingMessage {
|
|
25
|
+
originalUrl?: string;
|
|
26
|
+
}
|
|
27
|
+
export type Request = HTTPRequest | HTTPSRequest;
|
|
28
|
+
export type Response = HTTPServerResponse | HTTPSServerResponse;
|
|
29
|
+
export type DevServerOptions = {|
|
|
30
|
+
...ServerOptions,
|
|
31
|
+
projectRoot: string,
|
|
32
|
+
publicUrl: string,
|
|
33
|
+
cacheDir: string,
|
|
34
|
+
inputFS: FileSystem,
|
|
35
|
+
outputFS: FileSystem,
|
|
36
|
+
logger: PluginLogger,
|
|
37
|
+
hmrOptions: ?HMROptions,
|
|
38
|
+
packageManager: PackageManager,
|
|
39
|
+
|};
|
|
40
|
+
|
|
41
|
+
// TODO: Figure out if there is a node.js type that could be imported with a complete ServerError
|
|
42
|
+
export type ServerError = Error & {|
|
|
43
|
+
code: string,
|
|
44
|
+
|};
|
|
45
|
+
|
|
46
|
+
export type HMRServerOptions = {|
|
|
47
|
+
devServer?: HTTPServer,
|
|
48
|
+
addMiddleware?: (handler: (req: Request, res: Response) => boolean) => void,
|
|
49
|
+
port: number,
|
|
50
|
+
host: ?string,
|
|
51
|
+
logger: PluginLogger,
|
|
52
|
+
https?: HTTPSOptions | boolean,
|
|
53
|
+
cacheDir: FilePath,
|
|
54
|
+
inputFS: FileSystem,
|
|
55
|
+
outputFS: FileSystem,
|
|
56
|
+
|};
|
package/templates/404.html
CHANGED
package/templates/500.html
CHANGED
package/LICENSE
DELETED
|
@@ -1,201 +0,0 @@
|
|
|
1
|
-
Apache License
|
|
2
|
-
Version 2.0, January 2004
|
|
3
|
-
http://www.apache.org/licenses/
|
|
4
|
-
|
|
5
|
-
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
-
|
|
7
|
-
1. Definitions.
|
|
8
|
-
|
|
9
|
-
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
-
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
-
|
|
12
|
-
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
-
the copyright owner that is granting the License.
|
|
14
|
-
|
|
15
|
-
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
-
other entities that control, are controlled by, or are under common
|
|
17
|
-
control with that entity. For the purposes of this definition,
|
|
18
|
-
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
-
direction or management of such entity, whether by contract or
|
|
20
|
-
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
-
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
-
|
|
23
|
-
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
-
exercising permissions granted by this License.
|
|
25
|
-
|
|
26
|
-
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
-
including but not limited to software source code, documentation
|
|
28
|
-
source, and configuration files.
|
|
29
|
-
|
|
30
|
-
"Object" form shall mean any form resulting from mechanical
|
|
31
|
-
transformation or translation of a Source form, including but
|
|
32
|
-
not limited to compiled object code, generated documentation,
|
|
33
|
-
and conversions to other media types.
|
|
34
|
-
|
|
35
|
-
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
-
Object form, made available under the License, as indicated by a
|
|
37
|
-
copyright notice that is included in or attached to the work
|
|
38
|
-
(an example is provided in the Appendix below).
|
|
39
|
-
|
|
40
|
-
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
-
form, that is based on (or derived from) the Work and for which the
|
|
42
|
-
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
-
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
-
of this License, Derivative Works shall not include works that remain
|
|
45
|
-
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
-
the Work and Derivative Works thereof.
|
|
47
|
-
|
|
48
|
-
"Contribution" shall mean any work of authorship, including
|
|
49
|
-
the original version of the Work and any modifications or additions
|
|
50
|
-
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
-
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
-
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
-
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
-
means any form of electronic, verbal, or written communication sent
|
|
55
|
-
to the Licensor or its representatives, including but not limited to
|
|
56
|
-
communication on electronic mailing lists, source code control systems,
|
|
57
|
-
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
-
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
-
excluding communication that is conspicuously marked or otherwise
|
|
60
|
-
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
-
|
|
62
|
-
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
-
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
-
subsequently incorporated within the Work.
|
|
65
|
-
|
|
66
|
-
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
-
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
-
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
-
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
-
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
-
Work and such Derivative Works in Source or Object form.
|
|
72
|
-
|
|
73
|
-
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
-
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
-
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
-
(except as stated in this section) patent license to make, have made,
|
|
77
|
-
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
-
where such license applies only to those patent claims licensable
|
|
79
|
-
by such Contributor that are necessarily infringed by their
|
|
80
|
-
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
-
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
-
institute patent litigation against any entity (including a
|
|
83
|
-
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
-
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
-
or contributory patent infringement, then any patent licenses
|
|
86
|
-
granted to You under this License for that Work shall terminate
|
|
87
|
-
as of the date such litigation is filed.
|
|
88
|
-
|
|
89
|
-
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
-
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
-
modifications, and in Source or Object form, provided that You
|
|
92
|
-
meet the following conditions:
|
|
93
|
-
|
|
94
|
-
(a) You must give any other recipients of the Work or
|
|
95
|
-
Derivative Works a copy of this License; and
|
|
96
|
-
|
|
97
|
-
(b) You must cause any modified files to carry prominent notices
|
|
98
|
-
stating that You changed the files; and
|
|
99
|
-
|
|
100
|
-
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
-
that You distribute, all copyright, patent, trademark, and
|
|
102
|
-
attribution notices from the Source form of the Work,
|
|
103
|
-
excluding those notices that do not pertain to any part of
|
|
104
|
-
the Derivative Works; and
|
|
105
|
-
|
|
106
|
-
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
-
distribution, then any Derivative Works that You distribute must
|
|
108
|
-
include a readable copy of the attribution notices contained
|
|
109
|
-
within such NOTICE file, excluding those notices that do not
|
|
110
|
-
pertain to any part of the Derivative Works, in at least one
|
|
111
|
-
of the following places: within a NOTICE text file distributed
|
|
112
|
-
as part of the Derivative Works; within the Source form or
|
|
113
|
-
documentation, if provided along with the Derivative Works; or,
|
|
114
|
-
within a display generated by the Derivative Works, if and
|
|
115
|
-
wherever such third-party notices normally appear. The contents
|
|
116
|
-
of the NOTICE file are for informational purposes only and
|
|
117
|
-
do not modify the License. You may add Your own attribution
|
|
118
|
-
notices within Derivative Works that You distribute, alongside
|
|
119
|
-
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
-
that such additional attribution notices cannot be construed
|
|
121
|
-
as modifying the License.
|
|
122
|
-
|
|
123
|
-
You may add Your own copyright statement to Your modifications and
|
|
124
|
-
may provide additional or different license terms and conditions
|
|
125
|
-
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
-
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
-
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
-
the conditions stated in this License.
|
|
129
|
-
|
|
130
|
-
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
-
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
-
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
-
this License, without any additional terms or conditions.
|
|
134
|
-
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
-
the terms of any separate license agreement you may have executed
|
|
136
|
-
with Licensor regarding such Contributions.
|
|
137
|
-
|
|
138
|
-
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
-
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
-
except as required for reasonable and customary use in describing the
|
|
141
|
-
origin of the Work and reproducing the content of the NOTICE file.
|
|
142
|
-
|
|
143
|
-
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
-
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
-
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
-
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
-
implied, including, without limitation, any warranties or conditions
|
|
148
|
-
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
-
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
-
appropriateness of using or redistributing the Work and assume any
|
|
151
|
-
risks associated with Your exercise of permissions under this License.
|
|
152
|
-
|
|
153
|
-
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
-
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
-
unless required by applicable law (such as deliberate and grossly
|
|
156
|
-
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
-
liable to You for damages, including any direct, indirect, special,
|
|
158
|
-
incidental, or consequential damages of any character arising as a
|
|
159
|
-
result of this License or out of the use or inability to use the
|
|
160
|
-
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
-
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
-
other commercial damages or losses), even if such Contributor
|
|
163
|
-
has been advised of the possibility of such damages.
|
|
164
|
-
|
|
165
|
-
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
-
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
-
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
-
or other liability obligations and/or rights consistent with this
|
|
169
|
-
License. However, in accepting such obligations, You may act only
|
|
170
|
-
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
-
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
-
defend, and hold each Contributor harmless for any liability
|
|
173
|
-
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
-
of your accepting any such warranty or additional liability.
|
|
175
|
-
|
|
176
|
-
END OF TERMS AND CONDITIONS
|
|
177
|
-
|
|
178
|
-
APPENDIX: How to apply the Apache License to your work.
|
|
179
|
-
|
|
180
|
-
To apply the Apache License to your work, attach the following
|
|
181
|
-
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
182
|
-
replaced with your own identifying information. (Don't include
|
|
183
|
-
the brackets!) The text should be enclosed in the appropriate
|
|
184
|
-
comment syntax for the file format. We also recommend that a
|
|
185
|
-
file or class name and description of purpose be included on the
|
|
186
|
-
same "printed page" as the copyright notice for easier
|
|
187
|
-
identification within third-party archives.
|
|
188
|
-
|
|
189
|
-
Copyright (c) 2024 Atlassian US., Inc.
|
|
190
|
-
|
|
191
|
-
Licensed under the Apache License, Version 2.0 (the "License");
|
|
192
|
-
you may not use this file except in compliance with the License.
|
|
193
|
-
You may obtain a copy of the License at
|
|
194
|
-
|
|
195
|
-
http://www.apache.org/licenses/LICENSE-2.0
|
|
196
|
-
|
|
197
|
-
Unless required by applicable law or agreed to in writing, software
|
|
198
|
-
distributed under the License is distributed on an "AS IS" BASIS,
|
|
199
|
-
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
200
|
-
See the License for the specific language governing permissions and
|
|
201
|
-
limitations under the License.
|
package/lib/HMRServer.d.ts
DELETED
|
@@ -1,54 +0,0 @@
|
|
|
1
|
-
import type { Asset, BundleGraph, NamedBundle, PackagedBundle, PluginOptions } from '@atlaspack/types';
|
|
2
|
-
import type { Diagnostic } from '@atlaspack/diagnostic';
|
|
3
|
-
import type { AnsiDiagnosticResult } from '@atlaspack/utils';
|
|
4
|
-
import type { ServerError, HMRServerOptions, Request, Response } from './types.js.flow';
|
|
5
|
-
import WebSocket from 'ws';
|
|
6
|
-
export type SetComplement<A, B extends A> = A extends B ? never : A;
|
|
7
|
-
export type Diff<T extends U, U extends object> = Pick<T, SetComplement<keyof T, keyof U>>;
|
|
8
|
-
export type HMRAsset = {
|
|
9
|
-
id: string;
|
|
10
|
-
url: string;
|
|
11
|
-
type: string;
|
|
12
|
-
output: string;
|
|
13
|
-
envHash: string;
|
|
14
|
-
outputFormat: string;
|
|
15
|
-
depsByBundle: {
|
|
16
|
-
[key: string]: {
|
|
17
|
-
[key: string]: string;
|
|
18
|
-
};
|
|
19
|
-
};
|
|
20
|
-
};
|
|
21
|
-
export type HMRMessage = {
|
|
22
|
-
type: 'update';
|
|
23
|
-
assets: Array<HMRAsset>;
|
|
24
|
-
} | {
|
|
25
|
-
type: 'reload';
|
|
26
|
-
} | {
|
|
27
|
-
type: 'error';
|
|
28
|
-
diagnostics: {
|
|
29
|
-
ansi: Array<AnsiDiagnosticResult>;
|
|
30
|
-
html: Array<Partial<Diff<AnsiDiagnosticResult, {
|
|
31
|
-
codeframe: string;
|
|
32
|
-
}>>>;
|
|
33
|
-
};
|
|
34
|
-
};
|
|
35
|
-
export default class HMRServer {
|
|
36
|
-
wss: WebSocket.Server;
|
|
37
|
-
unresolvedError: HMRMessage | null;
|
|
38
|
-
options: HMRServerOptions;
|
|
39
|
-
bundleGraph: BundleGraph<PackagedBundle> | BundleGraph<NamedBundle> | null;
|
|
40
|
-
stopServer: (() => Promise<void>) | null | undefined;
|
|
41
|
-
constructor(options: HMRServerOptions);
|
|
42
|
-
start(): Promise<void>;
|
|
43
|
-
handle(req: Request, res: Response): boolean;
|
|
44
|
-
stop(): Promise<void>;
|
|
45
|
-
emitError(options: PluginOptions, diagnostics: Array<Diagnostic>): Promise<void>;
|
|
46
|
-
emitUpdate(event: {
|
|
47
|
-
readonly bundleGraph: BundleGraph<PackagedBundle> | BundleGraph<NamedBundle>;
|
|
48
|
-
readonly changedAssets: Map<string, Asset>;
|
|
49
|
-
}): Promise<void>;
|
|
50
|
-
getHotAssetContents(asset: Asset): Promise<string>;
|
|
51
|
-
getSourceURL(asset: Asset): string;
|
|
52
|
-
handleSocketError(err: ServerError): void;
|
|
53
|
-
broadcast(msg: HMRMessage): void;
|
|
54
|
-
}
|
package/lib/Server.d.ts
DELETED
|
@@ -1,45 +0,0 @@
|
|
|
1
|
-
import type { DevServerOptions, Request, Response } from './types.js.flow';
|
|
2
|
-
import type { BuildSuccessEvent, BundleGraph, FilePath, PluginOptions, PackagedBundle } from '@atlaspack/types';
|
|
3
|
-
import type { Diagnostic } from '@atlaspack/diagnostic';
|
|
4
|
-
import type { FileSystem } from '@atlaspack/fs';
|
|
5
|
-
import type { HTTPServer, FormattedCodeFrame } from '@atlaspack/utils';
|
|
6
|
-
export declare function setHeaders(res: Response): void;
|
|
7
|
-
export declare const SOURCES_ENDPOINT = "/__parcel_source_root";
|
|
8
|
-
type NextFunction = (req: Request, res: Response, next?: (arg1?: any) => any) => any;
|
|
9
|
-
export default class Server {
|
|
10
|
-
pending: boolean;
|
|
11
|
-
pendingRequests: Array<[Request, Response]>;
|
|
12
|
-
middleware: Array<(req: Request, res: Response) => boolean>;
|
|
13
|
-
options: DevServerOptions;
|
|
14
|
-
rootPath: string;
|
|
15
|
-
bundleGraph: BundleGraph<PackagedBundle> | null;
|
|
16
|
-
requestBundle: ((bundle: PackagedBundle) => Promise<BuildSuccessEvent>) | null | undefined;
|
|
17
|
-
errors: Array<{
|
|
18
|
-
message: string;
|
|
19
|
-
stack: string | null | undefined;
|
|
20
|
-
frames: Array<FormattedCodeFrame>;
|
|
21
|
-
hints: Array<string>;
|
|
22
|
-
documentation: string;
|
|
23
|
-
}> | null;
|
|
24
|
-
stopServer: (() => Promise<void>) | null | undefined;
|
|
25
|
-
constructor(options: DevServerOptions);
|
|
26
|
-
buildStart(): void;
|
|
27
|
-
buildSuccess(bundleGraph: BundleGraph<PackagedBundle>, requestBundle: (bundle: PackagedBundle) => Promise<BuildSuccessEvent>): void;
|
|
28
|
-
buildError(options: PluginOptions, diagnostics: Array<Diagnostic>): Promise<void>;
|
|
29
|
-
respond(req: Request, res: Response): unknown;
|
|
30
|
-
sendIndex(req: Request, res: Response): void;
|
|
31
|
-
serveBundle(req: Request, res: Response, next: NextFunction): Promise<void>;
|
|
32
|
-
serveDist(req: Request, res: Response, next: NextFunction): Promise<undefined> | Promise<unknown>;
|
|
33
|
-
serve(fs: FileSystem, root: FilePath, req: Request, res: Response, next: NextFunction): Promise<unknown>;
|
|
34
|
-
sendError(res: Response, statusCode: number): void;
|
|
35
|
-
send404(req: Request, res: Response): void;
|
|
36
|
-
send500(req: Request, res: Response): undefined | Response;
|
|
37
|
-
logAccessIfVerbose(req: Request): void;
|
|
38
|
-
/**
|
|
39
|
-
* Load proxy table from package.json and apply them.
|
|
40
|
-
*/
|
|
41
|
-
applyProxyTable(app: any): Promise<Server>;
|
|
42
|
-
start(): Promise<HTTPServer>;
|
|
43
|
-
stop(): Promise<void>;
|
|
44
|
-
}
|
|
45
|
-
export {};
|
package/lib/ServerReporter.d.ts
DELETED
package/lib/serverErrors.d.ts
DELETED
package/tsconfig.json
DELETED