@atlaspack/reporter-dev-server 2.14.5-canary.48 → 2.14.5-canary.481

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 +496 -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,501 @@
1
1
  # @atlaspack/reporter-dev-server
2
2
 
3
+ ## 2.14.63
4
+
5
+ ### Patch Changes
6
+
7
+ - Updated dependencies []:
8
+ - @atlaspack/utils@3.4.5
9
+ - @atlaspack/plugin@2.14.63
10
+ - @atlaspack/types@2.15.53
11
+
12
+ ## 2.14.62
13
+
14
+ ### Patch Changes
15
+
16
+ - Updated dependencies []:
17
+ - @atlaspack/utils@3.4.4
18
+ - @atlaspack/plugin@2.14.62
19
+ - @atlaspack/types@2.15.52
20
+
21
+ ## 2.14.61
22
+
23
+ ### Patch Changes
24
+
25
+ - Updated dependencies [[`e898fda`](https://github.com/atlassian-labs/atlaspack/commit/e898fda7511d98e5597d847c4a32c028a8a24d6c)]:
26
+ - @atlaspack/utils@3.4.3
27
+ - @atlaspack/types@2.15.51
28
+ - @atlaspack/plugin@2.14.61
29
+
30
+ ## 2.14.60
31
+
32
+ ### Patch Changes
33
+
34
+ - Updated dependencies []:
35
+ - @atlaspack/utils@3.4.2
36
+ - @atlaspack/types@2.15.50
37
+ - @atlaspack/plugin@2.14.60
38
+
39
+ ## 2.14.59
40
+
41
+ ### Patch Changes
42
+
43
+ - Updated dependencies []:
44
+ - @atlaspack/utils@3.4.1
45
+ - @atlaspack/types@2.15.49
46
+ - @atlaspack/plugin@2.14.59
47
+
48
+ ## 2.14.58
49
+
50
+ ### Patch Changes
51
+
52
+ - Updated dependencies [[`71981ea`](https://github.com/atlassian-labs/atlaspack/commit/71981eac258f7e6dfb40ec4b202d194f71c64ff1)]:
53
+ - @atlaspack/utils@3.4.0
54
+ - @atlaspack/plugin@2.14.58
55
+ - @atlaspack/types@2.15.48
56
+
57
+ ## 2.14.57
58
+
59
+ ### Patch Changes
60
+
61
+ - Updated dependencies []:
62
+ - @atlaspack/utils@3.3.9
63
+ - @atlaspack/plugin@2.14.57
64
+ - @atlaspack/types@2.15.47
65
+
66
+ ## 2.14.56
67
+
68
+ ### Patch Changes
69
+
70
+ - Updated dependencies []:
71
+ - @atlaspack/utils@3.3.8
72
+ - @atlaspack/plugin@2.14.56
73
+ - @atlaspack/types@2.15.46
74
+
75
+ ## 2.14.55
76
+
77
+ ### Patch Changes
78
+
79
+ - Updated dependencies []:
80
+ - @atlaspack/utils@3.3.7
81
+ - @atlaspack/plugin@2.14.55
82
+ - @atlaspack/types@2.15.45
83
+
84
+ ## 2.14.54
85
+
86
+ ### Patch Changes
87
+
88
+ - Updated dependencies [[`d8e984b`](https://github.com/atlassian-labs/atlaspack/commit/d8e984b7f6d04fa03707fa299bfd8b8bf9f58280)]:
89
+ - @atlaspack/utils@3.3.6
90
+ - @atlaspack/plugin@2.14.54
91
+ - @atlaspack/types@2.15.44
92
+
93
+ ## 2.14.53
94
+
95
+ ### Patch Changes
96
+
97
+ - Updated dependencies []:
98
+ - @atlaspack/utils@3.3.5
99
+ - @atlaspack/plugin@2.14.53
100
+ - @atlaspack/types@2.15.43
101
+
102
+ ## 2.14.52
103
+
104
+ ### Patch Changes
105
+
106
+ - Updated dependencies []:
107
+ - @atlaspack/plugin@2.14.52
108
+ - @atlaspack/types@2.15.42
109
+ - @atlaspack/utils@3.3.4
110
+
111
+ ## 2.14.51
112
+
113
+ ### Patch Changes
114
+
115
+ - Updated dependencies []:
116
+ - @atlaspack/utils@3.3.3
117
+ - @atlaspack/types@2.15.41
118
+ - @atlaspack/plugin@2.14.51
119
+
120
+ ## 2.14.50
121
+
122
+ ### Patch Changes
123
+
124
+ - Updated dependencies []:
125
+ - @atlaspack/utils@3.3.2
126
+ - @atlaspack/plugin@2.14.50
127
+ - @atlaspack/types@2.15.40
128
+
129
+ ## 2.14.49
130
+
131
+ ### Patch Changes
132
+
133
+ - Updated dependencies []:
134
+ - @atlaspack/utils@3.3.1
135
+ - @atlaspack/plugin@2.14.49
136
+ - @atlaspack/types@2.15.39
137
+
138
+ ## 2.14.48
139
+
140
+ ### Patch Changes
141
+
142
+ - Updated dependencies [[`47aa84e`](https://github.com/atlassian-labs/atlaspack/commit/47aa84e44c61066072a5bf3d57678565b9d2c5a3)]:
143
+ - @atlaspack/utils@3.3.0
144
+ - @atlaspack/types@2.15.38
145
+ - @atlaspack/plugin@2.14.48
146
+
147
+ ## 2.14.47
148
+
149
+ ### Patch Changes
150
+
151
+ - Updated dependencies []:
152
+ - @atlaspack/utils@3.2.8
153
+ - @atlaspack/types@2.15.37
154
+ - @atlaspack/plugin@2.14.47
155
+
156
+ ## 2.14.46
157
+
158
+ ### Patch Changes
159
+
160
+ - Updated dependencies []:
161
+ - @atlaspack/utils@3.2.7
162
+ - @atlaspack/plugin@2.14.46
163
+ - @atlaspack/types@2.15.36
164
+
165
+ ## 2.14.45
166
+
167
+ ### Patch Changes
168
+
169
+ - Updated dependencies []:
170
+ - @atlaspack/utils@3.2.6
171
+ - @atlaspack/plugin@2.14.45
172
+ - @atlaspack/types@2.15.35
173
+
174
+ ## 2.14.44
175
+
176
+ ### Patch Changes
177
+
178
+ - Updated dependencies []:
179
+ - @atlaspack/utils@3.2.5
180
+ - @atlaspack/plugin@2.14.44
181
+ - @atlaspack/types@2.15.34
182
+
183
+ ## 2.14.43
184
+
185
+ ### Patch Changes
186
+
187
+ - Updated dependencies []:
188
+ - @atlaspack/plugin@2.14.43
189
+ - @atlaspack/types@2.15.33
190
+ - @atlaspack/utils@3.2.4
191
+
192
+ ## 2.14.42
193
+
194
+ ### Patch Changes
195
+
196
+ - Updated dependencies []:
197
+ - @atlaspack/utils@3.2.3
198
+ - @atlaspack/plugin@2.14.42
199
+ - @atlaspack/types@2.15.32
200
+
201
+ ## 2.14.41
202
+
203
+ ### Patch Changes
204
+
205
+ - Updated dependencies []:
206
+ - @atlaspack/utils@3.2.2
207
+ - @atlaspack/plugin@2.14.41
208
+ - @atlaspack/types@2.15.31
209
+
210
+ ## 2.14.40
211
+
212
+ ### Patch Changes
213
+
214
+ - Updated dependencies []:
215
+ - @atlaspack/utils@3.2.1
216
+ - @atlaspack/plugin@2.14.40
217
+ - @atlaspack/types@2.15.30
218
+
219
+ ## 2.14.39
220
+
221
+ ### Patch Changes
222
+
223
+ - Updated dependencies [[`73168c2`](https://github.com/atlassian-labs/atlaspack/commit/73168c275a5d9abff9907bcf536b340bca1ed5f0), [`617a318`](https://github.com/atlassian-labs/atlaspack/commit/617a318ddc9419b38360257353fec50b9051ee13)]:
224
+ - @atlaspack/utils@3.2.0
225
+ - @atlaspack/plugin@2.14.39
226
+ - @atlaspack/types@2.15.29
227
+
228
+ ## 2.14.38
229
+
230
+ ### Patch Changes
231
+
232
+ - Updated dependencies [[`7d7a55d`](https://github.com/atlassian-labs/atlaspack/commit/7d7a55dd6395ec391a2e4c33b3dec0d1ea477d4c)]:
233
+ - @atlaspack/utils@3.1.2
234
+ - @atlaspack/plugin@2.14.38
235
+ - @atlaspack/types@2.15.28
236
+
237
+ ## 2.14.37
238
+
239
+ ### Patch Changes
240
+
241
+ - Updated dependencies []:
242
+ - @atlaspack/utils@3.1.1
243
+ - @atlaspack/plugin@2.14.37
244
+ - @atlaspack/types@2.15.27
245
+
246
+ ## 2.14.36
247
+
248
+ ### Patch Changes
249
+
250
+ - Updated dependencies [[`5776be2`](https://github.com/atlassian-labs/atlaspack/commit/5776be21f70a3f2b9471ba33da3ba1a883f21f1a)]:
251
+ - @atlaspack/utils@3.1.0
252
+ - @atlaspack/plugin@2.14.36
253
+ - @atlaspack/types@2.15.26
254
+
255
+ ## 2.14.35
256
+
257
+ ### Patch Changes
258
+
259
+ - Updated dependencies [[`c372f3f`](https://github.com/atlassian-labs/atlaspack/commit/c372f3fd6fce8200d5cf47f41bc7895c6cbb5558), [`17dfea9`](https://github.com/atlassian-labs/atlaspack/commit/17dfea9e9f3169807808520df9c09ebf70dc8b10)]:
260
+ - @atlaspack/utils@3.0.3
261
+ - @atlaspack/plugin@2.14.35
262
+ - @atlaspack/types@2.15.25
263
+
264
+ ## 2.14.34
265
+
266
+ ### Patch Changes
267
+
268
+ - Updated dependencies []:
269
+ - @atlaspack/types@2.15.24
270
+ - @atlaspack/utils@3.0.2
271
+ - @atlaspack/plugin@2.14.34
272
+
273
+ ## 2.14.33
274
+
275
+ ### Patch Changes
276
+
277
+ - Updated dependencies [[`236e546`](https://github.com/atlassian-labs/atlaspack/commit/236e5465863dca6044a7191e05260a5b924c342e)]:
278
+ - @atlaspack/utils@3.0.1
279
+ - @atlaspack/types@2.15.23
280
+ - @atlaspack/plugin@2.14.33
281
+
282
+ ## 2.14.32
283
+
284
+ ### Patch Changes
285
+
286
+ - Updated dependencies [[`1180103`](https://github.com/atlassian-labs/atlaspack/commit/118010351ed444f8178988afb3f77807154dd933)]:
287
+ - @atlaspack/utils@3.0.0
288
+ - @atlaspack/plugin@2.14.32
289
+ - @atlaspack/types@2.15.22
290
+
291
+ ## 2.14.31
292
+
293
+ ### Patch Changes
294
+
295
+ - [#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.
296
+
297
+ - Updated dependencies [[`0e7dd5e`](https://github.com/atlassian-labs/atlaspack/commit/0e7dd5ec6fbe05aa9e0bb5775a9d0975f206a922)]:
298
+ - @atlaspack/plugin@2.14.31
299
+ - @atlaspack/types@2.15.21
300
+ - @atlaspack/utils@2.19.3
301
+
302
+ ## 2.14.30
303
+
304
+ ### Patch Changes
305
+
306
+ - Updated dependencies []:
307
+ - @atlaspack/utils@2.19.2
308
+ - @atlaspack/plugin@2.14.30
309
+ - @atlaspack/types@2.15.20
310
+
311
+ ## 2.14.29
312
+
313
+ ### Patch Changes
314
+
315
+ - Updated dependencies []:
316
+ - @atlaspack/utils@2.19.1
317
+ - @atlaspack/plugin@2.14.29
318
+ - @atlaspack/types@2.15.19
319
+
320
+ ## 2.14.28
321
+
322
+ ### Patch Changes
323
+
324
+ - Updated dependencies [[`f0349a6`](https://github.com/atlassian-labs/atlaspack/commit/f0349a6b9b04755088f121095ca6301a2ada3767)]:
325
+ - @atlaspack/utils@2.19.0
326
+ - @atlaspack/plugin@2.14.28
327
+ - @atlaspack/types@2.15.18
328
+
329
+ ## 2.14.27
330
+
331
+ ### Patch Changes
332
+
333
+ - Updated dependencies []:
334
+ - @atlaspack/utils@2.18.4
335
+ - @atlaspack/plugin@2.14.27
336
+ - @atlaspack/types@2.15.17
337
+
338
+ ## 2.14.26
339
+
340
+ ### Patch Changes
341
+
342
+ - [#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
343
+
344
+ - Updated dependencies [[`ee040bb`](https://github.com/atlassian-labs/atlaspack/commit/ee040bb6428f29b57d892ddd8107e29077d08ffd), [`889c65c`](https://github.com/atlassian-labs/atlaspack/commit/889c65cd25b811045e26a117e7404f694dde77a2)]:
345
+ - @atlaspack/plugin@2.14.26
346
+ - @atlaspack/types@2.15.16
347
+ - @atlaspack/utils@2.18.3
348
+
349
+ ## 2.14.25
350
+
351
+ ### Patch Changes
352
+
353
+ - Updated dependencies []:
354
+ - @atlaspack/utils@2.18.2
355
+ - @atlaspack/plugin@2.14.25
356
+ - @atlaspack/types@2.15.15
357
+
358
+ ## 2.14.24
359
+
360
+ ### Patch Changes
361
+
362
+ - Updated dependencies []:
363
+ - @atlaspack/utils@2.18.1
364
+ - @atlaspack/plugin@2.14.24
365
+ - @atlaspack/types@2.15.14
366
+
367
+ ## 2.14.23
368
+
369
+ ### Patch Changes
370
+
371
+ - Updated dependencies [[`23d561e`](https://github.com/atlassian-labs/atlaspack/commit/23d561e51e68b0c38fd1ff4e4fb173e5e7b01cf2)]:
372
+ - @atlaspack/utils@2.18.0
373
+ - @atlaspack/types@2.15.13
374
+ - @atlaspack/plugin@2.14.23
375
+
376
+ ## 2.14.22
377
+
378
+ ### Patch Changes
379
+
380
+ - [#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
381
+
382
+ - Updated dependencies [[`d2fd849`](https://github.com/atlassian-labs/atlaspack/commit/d2fd849770fe6305e9c694bd97b1bd905abd9d94)]:
383
+ - @atlaspack/plugin@2.14.22
384
+ - @atlaspack/types@2.15.12
385
+ - @atlaspack/utils@2.17.4
386
+
387
+ ## 2.14.21
388
+
389
+ ### Patch Changes
390
+
391
+ - Updated dependencies []:
392
+ - @atlaspack/types@2.15.11
393
+ - @atlaspack/utils@2.17.3
394
+ - @atlaspack/plugin@2.14.21
395
+
396
+ ## 2.14.20
397
+
398
+ ### Patch Changes
399
+
400
+ - Updated dependencies [[`daaa768`](https://github.com/atlassian-labs/atlaspack/commit/daaa7688786772d7e3713b71c5bba6b89ec704aa)]:
401
+ - @atlaspack/plugin@2.14.20
402
+ - @atlaspack/utils@2.17.2
403
+ - @atlaspack/types@2.15.10
404
+
405
+ ## 2.14.19
406
+
407
+ ### Patch Changes
408
+
409
+ - Updated dependencies []:
410
+ - @atlaspack/utils@2.17.1
411
+ - @atlaspack/types@2.15.9
412
+ - @atlaspack/plugin@2.14.19
413
+
414
+ ## 2.14.18
415
+
416
+ ### Patch Changes
417
+
418
+ - [#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
419
+
420
+ - [#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
421
+
422
+ - 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)]:
423
+ - @atlaspack/utils@2.17.0
424
+ - @atlaspack/types@2.15.8
425
+ - @atlaspack/plugin@2.14.18
426
+
427
+ ## 2.14.17
428
+
429
+ ### Patch Changes
430
+
431
+ - Updated dependencies []:
432
+ - @atlaspack/utils@2.16.1
433
+ - @atlaspack/plugin@2.14.17
434
+
435
+ ## 2.14.16
436
+
437
+ ### Patch Changes
438
+
439
+ - Updated dependencies [[`30ee2cf`](https://github.com/atlassian-labs/atlaspack/commit/30ee2cfcd34cf2646ded0eda13fdb80a2a5de529)]:
440
+ - @atlaspack/utils@2.16.0
441
+ - @atlaspack/plugin@2.14.16
442
+
443
+ ## 2.14.15
444
+
445
+ ### Patch Changes
446
+
447
+ - Updated dependencies []:
448
+ - @atlaspack/utils@2.15.3
449
+ - @atlaspack/plugin@2.14.15
450
+
451
+ ## 2.14.14
452
+
453
+ ### Patch Changes
454
+
455
+ - Updated dependencies []:
456
+ - @atlaspack/utils@2.15.2
457
+ - @atlaspack/plugin@2.14.14
458
+
459
+ ## 2.14.13
460
+
461
+ ### Patch Changes
462
+
463
+ - Updated dependencies []:
464
+ - @atlaspack/utils@2.15.1
465
+ - @atlaspack/plugin@2.14.13
466
+
467
+ ## 2.14.12
468
+
469
+ ### Patch Changes
470
+
471
+ - Updated dependencies [[`e39c6cf`](https://github.com/atlassian-labs/atlaspack/commit/e39c6cf05f7e95ce5420dbcea66f401b1cbd397c)]:
472
+ - @atlaspack/utils@2.15.0
473
+ - @atlaspack/plugin@2.14.12
474
+
475
+ ## 2.14.11
476
+
477
+ ### Patch Changes
478
+
479
+ - Updated dependencies []:
480
+ - @atlaspack/utils@2.14.11
481
+ - @atlaspack/plugin@2.14.11
482
+
483
+ ## 2.14.10
484
+
485
+ ### Patch Changes
486
+
487
+ - Updated dependencies []:
488
+ - @atlaspack/plugin@2.14.10
489
+ - @atlaspack/utils@2.14.10
490
+
491
+ ## 2.14.9
492
+
493
+ ### Patch Changes
494
+
495
+ - Updated dependencies []:
496
+ - @atlaspack/utils@2.14.9
497
+ - @atlaspack/plugin@2.14.9
498
+
3
499
  ## 2.14.8
4
500
 
5
501
  ### 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
+ }