@atlaspack/reporter-dev-server 2.14.5-canary.46 → 2.14.5-canary.460

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (39) hide show
  1. package/CHANGELOG.md +478 -0
  2. package/dist/HMRServer.js +220 -0
  3. package/dist/Server.js +408 -0
  4. package/dist/ServerDataProvider.js +2 -0
  5. package/dist/ServerReporter.js +135 -0
  6. package/dist/StaticServerDataProvider.js +51 -0
  7. package/dist/serverErrors.js +16 -0
  8. package/dist/types.js +2 -0
  9. package/lib/HMRServer.js +270 -0
  10. package/lib/Server.js +466 -0
  11. package/lib/ServerDataProvider.js +1 -0
  12. package/lib/ServerReporter.js +137 -17455
  13. package/lib/StaticServerDataProvider.js +58 -0
  14. package/lib/launch-editor.d.js +1 -0
  15. package/lib/serverErrors.js +20 -0
  16. package/lib/types/HMRServer.d.ts +54 -0
  17. package/lib/types/Server.d.ts +45 -0
  18. package/lib/types/ServerDataProvider.d.ts +33 -0
  19. package/lib/types/ServerReporter.d.ts +3 -0
  20. package/lib/types/StaticServerDataProvider.d.ts +23 -0
  21. package/lib/types/serverErrors.d.ts +4 -0
  22. package/lib/types/types.d.ts +34 -0
  23. package/lib/types.js +1 -0
  24. package/package.json +19 -11
  25. package/src/{HMRServer.js → HMRServer.ts} +61 -35
  26. package/src/{Server.js → Server.ts} +52 -38
  27. package/src/ServerDataProvider.ts +34 -0
  28. package/src/{ServerReporter.js → ServerReporter.ts} +3 -5
  29. package/src/StaticServerDataProvider.ts +72 -0
  30. package/src/launch-editor.d.ts +4 -0
  31. package/src/{serverErrors.js → serverErrors.ts} +6 -5
  32. package/src/types.ts +46 -0
  33. package/{src/templates → templates}/404.html +1 -1
  34. package/{src/templates → templates}/500.html +1 -1
  35. package/test/StaticServerDataProvider.test.ts +131 -0
  36. package/tsconfig.json +18 -0
  37. package/tsconfig.tsbuildinfo +1 -0
  38. package/lib/ServerReporter.js.map +0 -1
  39. package/src/types.js.flow +0 -56
package/CHANGELOG.md CHANGED
@@ -1,5 +1,483 @@
1
1
  # @atlaspack/reporter-dev-server
2
2
 
3
+ ## 2.14.61
4
+
5
+ ### Patch Changes
6
+
7
+ - Updated dependencies [[`e898fda`](https://github.com/atlassian-labs/atlaspack/commit/e898fda7511d98e5597d847c4a32c028a8a24d6c)]:
8
+ - @atlaspack/utils@3.4.3
9
+ - @atlaspack/types@2.15.51
10
+ - @atlaspack/plugin@2.14.61
11
+
12
+ ## 2.14.60
13
+
14
+ ### Patch Changes
15
+
16
+ - Updated dependencies []:
17
+ - @atlaspack/utils@3.4.2
18
+ - @atlaspack/types@2.15.50
19
+ - @atlaspack/plugin@2.14.60
20
+
21
+ ## 2.14.59
22
+
23
+ ### Patch Changes
24
+
25
+ - Updated dependencies []:
26
+ - @atlaspack/utils@3.4.1
27
+ - @atlaspack/types@2.15.49
28
+ - @atlaspack/plugin@2.14.59
29
+
30
+ ## 2.14.58
31
+
32
+ ### Patch Changes
33
+
34
+ - Updated dependencies [[`71981ea`](https://github.com/atlassian-labs/atlaspack/commit/71981eac258f7e6dfb40ec4b202d194f71c64ff1)]:
35
+ - @atlaspack/utils@3.4.0
36
+ - @atlaspack/plugin@2.14.58
37
+ - @atlaspack/types@2.15.48
38
+
39
+ ## 2.14.57
40
+
41
+ ### Patch Changes
42
+
43
+ - Updated dependencies []:
44
+ - @atlaspack/utils@3.3.9
45
+ - @atlaspack/plugin@2.14.57
46
+ - @atlaspack/types@2.15.47
47
+
48
+ ## 2.14.56
49
+
50
+ ### Patch Changes
51
+
52
+ - Updated dependencies []:
53
+ - @atlaspack/utils@3.3.8
54
+ - @atlaspack/plugin@2.14.56
55
+ - @atlaspack/types@2.15.46
56
+
57
+ ## 2.14.55
58
+
59
+ ### Patch Changes
60
+
61
+ - Updated dependencies []:
62
+ - @atlaspack/utils@3.3.7
63
+ - @atlaspack/plugin@2.14.55
64
+ - @atlaspack/types@2.15.45
65
+
66
+ ## 2.14.54
67
+
68
+ ### Patch Changes
69
+
70
+ - Updated dependencies [[`d8e984b`](https://github.com/atlassian-labs/atlaspack/commit/d8e984b7f6d04fa03707fa299bfd8b8bf9f58280)]:
71
+ - @atlaspack/utils@3.3.6
72
+ - @atlaspack/plugin@2.14.54
73
+ - @atlaspack/types@2.15.44
74
+
75
+ ## 2.14.53
76
+
77
+ ### Patch Changes
78
+
79
+ - Updated dependencies []:
80
+ - @atlaspack/utils@3.3.5
81
+ - @atlaspack/plugin@2.14.53
82
+ - @atlaspack/types@2.15.43
83
+
84
+ ## 2.14.52
85
+
86
+ ### Patch Changes
87
+
88
+ - Updated dependencies []:
89
+ - @atlaspack/plugin@2.14.52
90
+ - @atlaspack/types@2.15.42
91
+ - @atlaspack/utils@3.3.4
92
+
93
+ ## 2.14.51
94
+
95
+ ### Patch Changes
96
+
97
+ - Updated dependencies []:
98
+ - @atlaspack/utils@3.3.3
99
+ - @atlaspack/types@2.15.41
100
+ - @atlaspack/plugin@2.14.51
101
+
102
+ ## 2.14.50
103
+
104
+ ### Patch Changes
105
+
106
+ - Updated dependencies []:
107
+ - @atlaspack/utils@3.3.2
108
+ - @atlaspack/plugin@2.14.50
109
+ - @atlaspack/types@2.15.40
110
+
111
+ ## 2.14.49
112
+
113
+ ### Patch Changes
114
+
115
+ - Updated dependencies []:
116
+ - @atlaspack/utils@3.3.1
117
+ - @atlaspack/plugin@2.14.49
118
+ - @atlaspack/types@2.15.39
119
+
120
+ ## 2.14.48
121
+
122
+ ### Patch Changes
123
+
124
+ - Updated dependencies [[`47aa84e`](https://github.com/atlassian-labs/atlaspack/commit/47aa84e44c61066072a5bf3d57678565b9d2c5a3)]:
125
+ - @atlaspack/utils@3.3.0
126
+ - @atlaspack/types@2.15.38
127
+ - @atlaspack/plugin@2.14.48
128
+
129
+ ## 2.14.47
130
+
131
+ ### Patch Changes
132
+
133
+ - Updated dependencies []:
134
+ - @atlaspack/utils@3.2.8
135
+ - @atlaspack/types@2.15.37
136
+ - @atlaspack/plugin@2.14.47
137
+
138
+ ## 2.14.46
139
+
140
+ ### Patch Changes
141
+
142
+ - Updated dependencies []:
143
+ - @atlaspack/utils@3.2.7
144
+ - @atlaspack/plugin@2.14.46
145
+ - @atlaspack/types@2.15.36
146
+
147
+ ## 2.14.45
148
+
149
+ ### Patch Changes
150
+
151
+ - Updated dependencies []:
152
+ - @atlaspack/utils@3.2.6
153
+ - @atlaspack/plugin@2.14.45
154
+ - @atlaspack/types@2.15.35
155
+
156
+ ## 2.14.44
157
+
158
+ ### Patch Changes
159
+
160
+ - Updated dependencies []:
161
+ - @atlaspack/utils@3.2.5
162
+ - @atlaspack/plugin@2.14.44
163
+ - @atlaspack/types@2.15.34
164
+
165
+ ## 2.14.43
166
+
167
+ ### Patch Changes
168
+
169
+ - Updated dependencies []:
170
+ - @atlaspack/plugin@2.14.43
171
+ - @atlaspack/types@2.15.33
172
+ - @atlaspack/utils@3.2.4
173
+
174
+ ## 2.14.42
175
+
176
+ ### Patch Changes
177
+
178
+ - Updated dependencies []:
179
+ - @atlaspack/utils@3.2.3
180
+ - @atlaspack/plugin@2.14.42
181
+ - @atlaspack/types@2.15.32
182
+
183
+ ## 2.14.41
184
+
185
+ ### Patch Changes
186
+
187
+ - Updated dependencies []:
188
+ - @atlaspack/utils@3.2.2
189
+ - @atlaspack/plugin@2.14.41
190
+ - @atlaspack/types@2.15.31
191
+
192
+ ## 2.14.40
193
+
194
+ ### Patch Changes
195
+
196
+ - Updated dependencies []:
197
+ - @atlaspack/utils@3.2.1
198
+ - @atlaspack/plugin@2.14.40
199
+ - @atlaspack/types@2.15.30
200
+
201
+ ## 2.14.39
202
+
203
+ ### Patch Changes
204
+
205
+ - Updated dependencies [[`73168c2`](https://github.com/atlassian-labs/atlaspack/commit/73168c275a5d9abff9907bcf536b340bca1ed5f0), [`617a318`](https://github.com/atlassian-labs/atlaspack/commit/617a318ddc9419b38360257353fec50b9051ee13)]:
206
+ - @atlaspack/utils@3.2.0
207
+ - @atlaspack/plugin@2.14.39
208
+ - @atlaspack/types@2.15.29
209
+
210
+ ## 2.14.38
211
+
212
+ ### Patch Changes
213
+
214
+ - Updated dependencies [[`7d7a55d`](https://github.com/atlassian-labs/atlaspack/commit/7d7a55dd6395ec391a2e4c33b3dec0d1ea477d4c)]:
215
+ - @atlaspack/utils@3.1.2
216
+ - @atlaspack/plugin@2.14.38
217
+ - @atlaspack/types@2.15.28
218
+
219
+ ## 2.14.37
220
+
221
+ ### Patch Changes
222
+
223
+ - Updated dependencies []:
224
+ - @atlaspack/utils@3.1.1
225
+ - @atlaspack/plugin@2.14.37
226
+ - @atlaspack/types@2.15.27
227
+
228
+ ## 2.14.36
229
+
230
+ ### Patch Changes
231
+
232
+ - Updated dependencies [[`5776be2`](https://github.com/atlassian-labs/atlaspack/commit/5776be21f70a3f2b9471ba33da3ba1a883f21f1a)]:
233
+ - @atlaspack/utils@3.1.0
234
+ - @atlaspack/plugin@2.14.36
235
+ - @atlaspack/types@2.15.26
236
+
237
+ ## 2.14.35
238
+
239
+ ### Patch Changes
240
+
241
+ - Updated dependencies [[`c372f3f`](https://github.com/atlassian-labs/atlaspack/commit/c372f3fd6fce8200d5cf47f41bc7895c6cbb5558), [`17dfea9`](https://github.com/atlassian-labs/atlaspack/commit/17dfea9e9f3169807808520df9c09ebf70dc8b10)]:
242
+ - @atlaspack/utils@3.0.3
243
+ - @atlaspack/plugin@2.14.35
244
+ - @atlaspack/types@2.15.25
245
+
246
+ ## 2.14.34
247
+
248
+ ### Patch Changes
249
+
250
+ - Updated dependencies []:
251
+ - @atlaspack/types@2.15.24
252
+ - @atlaspack/utils@3.0.2
253
+ - @atlaspack/plugin@2.14.34
254
+
255
+ ## 2.14.33
256
+
257
+ ### Patch Changes
258
+
259
+ - Updated dependencies [[`236e546`](https://github.com/atlassian-labs/atlaspack/commit/236e5465863dca6044a7191e05260a5b924c342e)]:
260
+ - @atlaspack/utils@3.0.1
261
+ - @atlaspack/types@2.15.23
262
+ - @atlaspack/plugin@2.14.33
263
+
264
+ ## 2.14.32
265
+
266
+ ### Patch Changes
267
+
268
+ - Updated dependencies [[`1180103`](https://github.com/atlassian-labs/atlaspack/commit/118010351ed444f8178988afb3f77807154dd933)]:
269
+ - @atlaspack/utils@3.0.0
270
+ - @atlaspack/plugin@2.14.32
271
+ - @atlaspack/types@2.15.22
272
+
273
+ ## 2.14.31
274
+
275
+ ### Patch Changes
276
+
277
+ - [#785](https://github.com/atlassian-labs/atlaspack/pull/785) [`0e7dd5e`](https://github.com/atlassian-labs/atlaspack/commit/0e7dd5ec6fbe05aa9e0bb5775a9d0975f206a922) Thanks [@matt-koko](https://github.com/matt-koko)! - We need to re-publish every package in Atlaspack with the corrected types field.
278
+
279
+ - Updated dependencies [[`0e7dd5e`](https://github.com/atlassian-labs/atlaspack/commit/0e7dd5ec6fbe05aa9e0bb5775a9d0975f206a922)]:
280
+ - @atlaspack/plugin@2.14.31
281
+ - @atlaspack/types@2.15.21
282
+ - @atlaspack/utils@2.19.3
283
+
284
+ ## 2.14.30
285
+
286
+ ### Patch Changes
287
+
288
+ - Updated dependencies []:
289
+ - @atlaspack/utils@2.19.2
290
+ - @atlaspack/plugin@2.14.30
291
+ - @atlaspack/types@2.15.20
292
+
293
+ ## 2.14.29
294
+
295
+ ### Patch Changes
296
+
297
+ - Updated dependencies []:
298
+ - @atlaspack/utils@2.19.1
299
+ - @atlaspack/plugin@2.14.29
300
+ - @atlaspack/types@2.15.19
301
+
302
+ ## 2.14.28
303
+
304
+ ### Patch Changes
305
+
306
+ - Updated dependencies [[`f0349a6`](https://github.com/atlassian-labs/atlaspack/commit/f0349a6b9b04755088f121095ca6301a2ada3767)]:
307
+ - @atlaspack/utils@2.19.0
308
+ - @atlaspack/plugin@2.14.28
309
+ - @atlaspack/types@2.15.18
310
+
311
+ ## 2.14.27
312
+
313
+ ### Patch Changes
314
+
315
+ - Updated dependencies []:
316
+ - @atlaspack/utils@2.18.4
317
+ - @atlaspack/plugin@2.14.27
318
+ - @atlaspack/types@2.15.17
319
+
320
+ ## 2.14.26
321
+
322
+ ### Patch Changes
323
+
324
+ - [#742](https://github.com/atlassian-labs/atlaspack/pull/742) [`ee040bb`](https://github.com/atlassian-labs/atlaspack/commit/ee040bb6428f29b57d892ddd8107e29077d08ffd) Thanks [@yamadapc](https://github.com/yamadapc)! - Internal changes and bug fixes to environmentDeduplication flag
325
+
326
+ - Updated dependencies [[`ee040bb`](https://github.com/atlassian-labs/atlaspack/commit/ee040bb6428f29b57d892ddd8107e29077d08ffd), [`889c65c`](https://github.com/atlassian-labs/atlaspack/commit/889c65cd25b811045e26a117e7404f694dde77a2)]:
327
+ - @atlaspack/plugin@2.14.26
328
+ - @atlaspack/types@2.15.16
329
+ - @atlaspack/utils@2.18.3
330
+
331
+ ## 2.14.25
332
+
333
+ ### Patch Changes
334
+
335
+ - Updated dependencies []:
336
+ - @atlaspack/utils@2.18.2
337
+ - @atlaspack/plugin@2.14.25
338
+ - @atlaspack/types@2.15.15
339
+
340
+ ## 2.14.24
341
+
342
+ ### Patch Changes
343
+
344
+ - Updated dependencies []:
345
+ - @atlaspack/utils@2.18.1
346
+ - @atlaspack/plugin@2.14.24
347
+ - @atlaspack/types@2.15.14
348
+
349
+ ## 2.14.23
350
+
351
+ ### Patch Changes
352
+
353
+ - Updated dependencies [[`23d561e`](https://github.com/atlassian-labs/atlaspack/commit/23d561e51e68b0c38fd1ff4e4fb173e5e7b01cf2)]:
354
+ - @atlaspack/utils@2.18.0
355
+ - @atlaspack/types@2.15.13
356
+ - @atlaspack/plugin@2.14.23
357
+
358
+ ## 2.14.22
359
+
360
+ ### Patch Changes
361
+
362
+ - [#720](https://github.com/atlassian-labs/atlaspack/pull/720) [`d2fd849`](https://github.com/atlassian-labs/atlaspack/commit/d2fd849770fe6305e9c694bd97b1bd905abd9d94) Thanks [@alshdavid](https://github.com/alshdavid)! - Migrate to TypeScript
363
+
364
+ - Updated dependencies [[`d2fd849`](https://github.com/atlassian-labs/atlaspack/commit/d2fd849770fe6305e9c694bd97b1bd905abd9d94)]:
365
+ - @atlaspack/plugin@2.14.22
366
+ - @atlaspack/types@2.15.12
367
+ - @atlaspack/utils@2.17.4
368
+
369
+ ## 2.14.21
370
+
371
+ ### Patch Changes
372
+
373
+ - Updated dependencies []:
374
+ - @atlaspack/types@2.15.11
375
+ - @atlaspack/utils@2.17.3
376
+ - @atlaspack/plugin@2.14.21
377
+
378
+ ## 2.14.20
379
+
380
+ ### Patch Changes
381
+
382
+ - Updated dependencies [[`daaa768`](https://github.com/atlassian-labs/atlaspack/commit/daaa7688786772d7e3713b71c5bba6b89ec704aa)]:
383
+ - @atlaspack/plugin@2.14.20
384
+ - @atlaspack/utils@2.17.2
385
+ - @atlaspack/types@2.15.10
386
+
387
+ ## 2.14.19
388
+
389
+ ### Patch Changes
390
+
391
+ - Updated dependencies []:
392
+ - @atlaspack/utils@2.17.1
393
+ - @atlaspack/types@2.15.9
394
+ - @atlaspack/plugin@2.14.19
395
+
396
+ ## 2.14.18
397
+
398
+ ### Patch Changes
399
+
400
+ - [#645](https://github.com/atlassian-labs/atlaspack/pull/645) [`de23e0c`](https://github.com/atlassian-labs/atlaspack/commit/de23e0ce49d5504fe3947ac26640a3d951087da3) Thanks [@alshdavid](https://github.com/alshdavid)! - Updated build system and added some extra test-specific code
401
+
402
+ - [#682](https://github.com/atlassian-labs/atlaspack/pull/682) [`a5ed1b4`](https://github.com/atlassian-labs/atlaspack/commit/a5ed1b414498560f393ff491af4da25b6e8dde56) Thanks [@alshdavid](https://github.com/alshdavid)! - Updating build system
403
+
404
+ - Updated dependencies [[`dbb4072`](https://github.com/atlassian-labs/atlaspack/commit/dbb40721ebeb45990a14ba04e6b44e7f836fb32d), [`de23e0c`](https://github.com/atlassian-labs/atlaspack/commit/de23e0ce49d5504fe3947ac26640a3d951087da3), [`18a57cf`](https://github.com/atlassian-labs/atlaspack/commit/18a57cf8a4789b2de5ad8e2676f317a26cc91417), [`a5ed1b4`](https://github.com/atlassian-labs/atlaspack/commit/a5ed1b414498560f393ff491af4da25b6e8dde56)]:
405
+ - @atlaspack/utils@2.17.0
406
+ - @atlaspack/types@2.15.8
407
+ - @atlaspack/plugin@2.14.18
408
+
409
+ ## 2.14.17
410
+
411
+ ### Patch Changes
412
+
413
+ - Updated dependencies []:
414
+ - @atlaspack/utils@2.16.1
415
+ - @atlaspack/plugin@2.14.17
416
+
417
+ ## 2.14.16
418
+
419
+ ### Patch Changes
420
+
421
+ - Updated dependencies [[`30ee2cf`](https://github.com/atlassian-labs/atlaspack/commit/30ee2cfcd34cf2646ded0eda13fdb80a2a5de529)]:
422
+ - @atlaspack/utils@2.16.0
423
+ - @atlaspack/plugin@2.14.16
424
+
425
+ ## 2.14.15
426
+
427
+ ### Patch Changes
428
+
429
+ - Updated dependencies []:
430
+ - @atlaspack/utils@2.15.3
431
+ - @atlaspack/plugin@2.14.15
432
+
433
+ ## 2.14.14
434
+
435
+ ### Patch Changes
436
+
437
+ - Updated dependencies []:
438
+ - @atlaspack/utils@2.15.2
439
+ - @atlaspack/plugin@2.14.14
440
+
441
+ ## 2.14.13
442
+
443
+ ### Patch Changes
444
+
445
+ - Updated dependencies []:
446
+ - @atlaspack/utils@2.15.1
447
+ - @atlaspack/plugin@2.14.13
448
+
449
+ ## 2.14.12
450
+
451
+ ### Patch Changes
452
+
453
+ - Updated dependencies [[`e39c6cf`](https://github.com/atlassian-labs/atlaspack/commit/e39c6cf05f7e95ce5420dbcea66f401b1cbd397c)]:
454
+ - @atlaspack/utils@2.15.0
455
+ - @atlaspack/plugin@2.14.12
456
+
457
+ ## 2.14.11
458
+
459
+ ### Patch Changes
460
+
461
+ - Updated dependencies []:
462
+ - @atlaspack/utils@2.14.11
463
+ - @atlaspack/plugin@2.14.11
464
+
465
+ ## 2.14.10
466
+
467
+ ### Patch Changes
468
+
469
+ - Updated dependencies []:
470
+ - @atlaspack/plugin@2.14.10
471
+ - @atlaspack/utils@2.14.10
472
+
473
+ ## 2.14.9
474
+
475
+ ### Patch Changes
476
+
477
+ - Updated dependencies []:
478
+ - @atlaspack/utils@2.14.9
479
+ - @atlaspack/plugin@2.14.9
480
+
3
481
  ## 2.14.8
4
482
 
5
483
  ### Patch Changes
@@ -0,0 +1,220 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ const Server_1 = require("./Server");
7
+ const nullthrows_1 = __importDefault(require("nullthrows"));
8
+ const url_1 = __importDefault(require("url"));
9
+ // @ts-expect-error TS7016
10
+ const mime_types_1 = __importDefault(require("mime-types"));
11
+ // @ts-expect-error TS7016
12
+ const ws_1 = __importDefault(require("ws"));
13
+ const assert_1 = __importDefault(require("assert"));
14
+ const utils_1 = require("@atlaspack/utils");
15
+ const FS_CONCURRENCY = 64;
16
+ const HMR_ENDPOINT = '/__parcel_hmr';
17
+ const BROADCAST_MAX_ASSETS = 10000;
18
+ class HMRServer {
19
+ constructor(options) {
20
+ this.unresolvedError = null;
21
+ this.bundleGraph = null;
22
+ this.options = options;
23
+ }
24
+ async start() {
25
+ let server = this.options.devServer;
26
+ if (!server) {
27
+ let result = await (0, utils_1.createHTTPServer)({
28
+ https: this.options.https,
29
+ inputFS: this.options.inputFS,
30
+ outputFS: this.options.outputFS,
31
+ cacheDir: this.options.cacheDir,
32
+ listener: (req, res) => {
33
+ (0, Server_1.setHeaders)(res);
34
+ if (!this.handle(req, res)) {
35
+ res.statusCode = 404;
36
+ res.end();
37
+ }
38
+ },
39
+ });
40
+ server = result.server;
41
+ server.listen(this.options.port, this.options.host);
42
+ this.stopServer = result.stop;
43
+ }
44
+ else {
45
+ this.options.addMiddleware?.((req, res) => this.handle(req, res));
46
+ }
47
+ this.wss = new ws_1.default.Server({ server });
48
+ this.wss.on('connection', (ws) => {
49
+ if (this.unresolvedError) {
50
+ ws.send(JSON.stringify(this.unresolvedError));
51
+ }
52
+ });
53
+ this.wss.on('error', (err) => this.handleSocketError(err));
54
+ }
55
+ handle(req, res) {
56
+ let { pathname } = url_1.default.parse(req.originalUrl || req.url);
57
+ if (pathname != null && pathname.startsWith(HMR_ENDPOINT)) {
58
+ let id = pathname.slice(HMR_ENDPOINT.length + 1);
59
+ let bundleGraph = (0, nullthrows_1.default)(this.bundleGraph);
60
+ let asset = bundleGraph.getAssetById(id);
61
+ this.getHotAssetContents(asset).then((output) => {
62
+ res.setHeader('Content-Type', mime_types_1.default.contentType(asset.type));
63
+ res.end(output);
64
+ });
65
+ return true;
66
+ }
67
+ return false;
68
+ }
69
+ async stop() {
70
+ if (this.stopServer != null) {
71
+ await this.stopServer();
72
+ this.stopServer = null;
73
+ }
74
+ this.wss.close();
75
+ }
76
+ async emitError(options, diagnostics) {
77
+ let renderedDiagnostics = await Promise.all(diagnostics.map((d) => (0, utils_1.prettyDiagnostic)(d, options)));
78
+ // store the most recent error so we can notify new connections
79
+ // and so we can broadcast when the error is resolved
80
+ this.unresolvedError = {
81
+ type: 'error',
82
+ diagnostics: {
83
+ ansi: renderedDiagnostics,
84
+ html: renderedDiagnostics.map((d, i) => {
85
+ return {
86
+ message: (0, utils_1.ansiHtml)(d.message),
87
+ stack: (0, utils_1.ansiHtml)(d.stack),
88
+ frames: d.frames.map((f) => ({
89
+ location: f.location,
90
+ code: (0, utils_1.ansiHtml)(f.code),
91
+ })),
92
+ hints: d.hints.map((hint) => (0, utils_1.ansiHtml)(hint)),
93
+ documentation: diagnostics[i].documentationURL ?? '',
94
+ };
95
+ }),
96
+ },
97
+ };
98
+ this.broadcast(this.unresolvedError);
99
+ }
100
+ async emitUpdate(event) {
101
+ this.unresolvedError = null;
102
+ this.bundleGraph = event.bundleGraph;
103
+ let changedAssets = new Set(event.changedAssets.values());
104
+ if (changedAssets.size === 0)
105
+ return;
106
+ let queue = new utils_1.PromiseQueue({ maxConcurrent: FS_CONCURRENCY });
107
+ for (let asset of changedAssets) {
108
+ if (asset.type !== 'js' && asset.type !== 'css') {
109
+ // If all of the incoming dependencies of the asset actually resolve to a JS asset
110
+ // rather than the original, we can mark the runtimes as changed instead. URL runtimes
111
+ // have a cache busting query param added with HMR enabled which will trigger a reload.
112
+ let runtimes = new Set();
113
+ let incomingDeps = event.bundleGraph.getIncomingDependencies(asset);
114
+ let isOnlyReferencedByRuntimes = incomingDeps.every((dep) => {
115
+ let resolved = event.bundleGraph.getResolvedAsset(dep);
116
+ let isRuntime = resolved?.type === 'js' && resolved !== asset;
117
+ if (resolved && isRuntime) {
118
+ runtimes.add(resolved);
119
+ }
120
+ return isRuntime;
121
+ });
122
+ if (isOnlyReferencedByRuntimes) {
123
+ for (let runtime of runtimes) {
124
+ // @ts-expect-error TS2345
125
+ changedAssets.add(runtime);
126
+ }
127
+ continue;
128
+ }
129
+ }
130
+ queue.add(async () => {
131
+ let dependencies = event.bundleGraph.getDependencies(asset);
132
+ let depsByBundle = {};
133
+ for (let bundle of event.bundleGraph.getBundlesWithAsset(asset)) {
134
+ let deps = {};
135
+ for (let dep of dependencies) {
136
+ let resolved = event.bundleGraph.getResolvedAsset(dep, bundle);
137
+ if (resolved) {
138
+ deps[getSpecifier(dep)] =
139
+ event.bundleGraph.getAssetPublicId(resolved);
140
+ }
141
+ }
142
+ depsByBundle[bundle.id] = deps;
143
+ }
144
+ return {
145
+ id: event.bundleGraph.getAssetPublicId(asset),
146
+ url: this.getSourceURL(asset),
147
+ type: asset.type,
148
+ // No need to send the contents of non-JS assets to the client.
149
+ output: asset.type === 'js' ? await this.getHotAssetContents(asset) : '',
150
+ envHash: asset.env.id,
151
+ outputFormat: asset.env.outputFormat,
152
+ depsByBundle,
153
+ };
154
+ });
155
+ }
156
+ let assets = await queue.run();
157
+ if (assets.length >= BROADCAST_MAX_ASSETS) {
158
+ // Too many assets to send via an update without errors, just reload instead
159
+ this.broadcast({ type: 'reload' });
160
+ }
161
+ else {
162
+ this.broadcast({
163
+ type: 'update',
164
+ // @ts-expect-error TS2322
165
+ assets,
166
+ });
167
+ }
168
+ }
169
+ async getHotAssetContents(asset) {
170
+ let output = await asset.getCode();
171
+ let bundleGraph = (0, nullthrows_1.default)(this.bundleGraph);
172
+ if (asset.type === 'js') {
173
+ let publicId = bundleGraph.getAssetPublicId(asset);
174
+ output = `parcelHotUpdate['${publicId}'] = function (require, module, exports) {${output}}`;
175
+ }
176
+ let sourcemap = await asset.getMap();
177
+ if (sourcemap) {
178
+ let sourcemapStringified = await sourcemap.stringify({
179
+ format: 'inline',
180
+ sourceRoot: Server_1.SOURCES_ENDPOINT + '/',
181
+ fs: asset.fs,
182
+ });
183
+ (0, assert_1.default)(typeof sourcemapStringified === 'string');
184
+ output += `\n//# sourceMappingURL=${sourcemapStringified}`;
185
+ output += `\n//# sourceURL=${encodeURI(this.getSourceURL(asset))}\n`;
186
+ }
187
+ return output;
188
+ }
189
+ getSourceURL(asset) {
190
+ let origin = '';
191
+ if (!this.options.devServer) {
192
+ origin = `http://${this.options.host || 'localhost'}:${this.options.port}`;
193
+ }
194
+ return origin + HMR_ENDPOINT + '/' + asset.id;
195
+ }
196
+ handleSocketError(err) {
197
+ if (err.code === 'ECONNRESET') {
198
+ // This gets triggered on page refresh, ignore this
199
+ return;
200
+ }
201
+ this.options.logger.warn({
202
+ origin: '@atlaspack/reporter-dev-server',
203
+ message: `[${err.code}]: ${err.message}`,
204
+ stack: err.stack,
205
+ });
206
+ }
207
+ broadcast(msg) {
208
+ const json = JSON.stringify(msg);
209
+ for (let ws of this.wss.clients) {
210
+ ws.send(json);
211
+ }
212
+ }
213
+ }
214
+ exports.default = HMRServer;
215
+ function getSpecifier(dep) {
216
+ if (typeof dep.meta.placeholder === 'string') {
217
+ return dep.meta.placeholder;
218
+ }
219
+ return dep.specifier;
220
+ }