@atlaspack/runtime-browser-hmr 2.14.5-canary.27 → 2.14.5-canary.270

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.
@@ -1,4 +1,3 @@
1
- // @flow
2
1
  /* global HMR_HOST, HMR_PORT, HMR_ENV_HASH, HMR_SECURE, HMR_USE_SSE, chrome, browser, __parcel__import__, __parcel__importScripts__, ServiceWorkerGlobalScope */
3
2
 
4
3
  /*::
@@ -49,49 +48,75 @@ declare var globalThis: typeof self;
49
48
  declare var ServiceWorkerGlobalScope: Object;
50
49
  */
51
50
 
51
+ // flow-to-ts helpers
52
+ export type SetComplement<A, B extends A> = A extends B ? never : A;
53
+ export type Diff<T extends U, U extends object> = Pick<
54
+ T,
55
+ SetComplement<keyof T, keyof U>
56
+ >;
57
+ // /flow-to-ts helpers
58
+
52
59
  var OVERLAY_ID = '__parcel__error__overlay__';
53
60
 
61
+ // @ts-expect-error TS2339
54
62
  var OldModule = module.bundle.Module;
55
63
 
56
- function Module(moduleName) {
64
+ function Module(moduleName: any) {
65
+ // @ts-expect-error TS2683
57
66
  OldModule.call(this, moduleName);
67
+ // @ts-expect-error TS2683
58
68
  this.hot = {
69
+ // @ts-expect-error TS2339
59
70
  data: module.bundle.hotData[moduleName],
60
71
  _acceptCallbacks: [],
61
72
  _disposeCallbacks: [],
73
+ // @ts-expect-error TS7006
62
74
  accept: function (fn) {
63
75
  this._acceptCallbacks.push(fn || function () {});
64
76
  },
77
+ // @ts-expect-error TS7006
65
78
  dispose: function (fn) {
66
79
  this._disposeCallbacks.push(fn);
67
80
  },
68
81
  };
82
+ // @ts-expect-error TS2339
69
83
  module.bundle.hotData[moduleName] = undefined;
70
84
  }
85
+ // @ts-expect-error TS2339
71
86
  module.bundle.Module = Module;
87
+ // @ts-expect-error TS2339
72
88
  module.bundle.hotData = {};
73
89
 
90
+ // @ts-expect-error TS7034
74
91
  var checkedAssets /*: {|[string]: boolean|} */,
92
+ // @ts-expect-error TS7034
93
+ disposedAssets /*: {|[string]: boolean|} */,
94
+ // @ts-expect-error TS7034
75
95
  assetsToDispose /*: Array<[ParcelRequire, string]> */,
96
+ // @ts-expect-error TS7034
76
97
  assetsToAccept /*: Array<[ParcelRequire, string]> */;
77
98
 
78
99
  function getHostname() {
79
100
  return (
101
+ // @ts-expect-error TS2304
80
102
  HMR_HOST ||
81
103
  (location.protocol.indexOf('http') === 0 ? location.hostname : 'localhost')
82
104
  );
83
105
  }
84
106
 
85
107
  function getPort() {
108
+ // @ts-expect-error TS2304
86
109
  return HMR_PORT || location.port;
87
110
  }
88
111
 
89
112
  // eslint-disable-next-line no-redeclare
113
+ // @ts-expect-error TS2339
90
114
  var parent = module.bundle.parent;
91
115
  if ((!parent || !parent.isParcelRequire) && typeof WebSocket !== 'undefined') {
92
116
  var hostname = getHostname();
93
117
  var port = getPort();
94
118
  var protocol =
119
+ // @ts-expect-error TS2304
95
120
  HMR_SECURE ||
96
121
  (location.protocol == 'https:' &&
97
122
  !['localhost', '127.0.0.1', '0.0.0.0'].includes(hostname))
@@ -99,6 +124,7 @@ if ((!parent || !parent.isParcelRequire) && typeof WebSocket !== 'undefined') {
99
124
  : 'ws';
100
125
 
101
126
  var ws;
127
+ // @ts-expect-error TS2304
102
128
  if (HMR_USE_SSE) {
103
129
  ws = new EventSource('/__parcel_hmr');
104
130
  } else {
@@ -106,7 +132,7 @@ if ((!parent || !parent.isParcelRequire) && typeof WebSocket !== 'undefined') {
106
132
  ws = new WebSocket(
107
133
  protocol + '://' + hostname + (port ? ':' + port : '') + '/',
108
134
  );
109
- } catch (err) {
135
+ } catch (err: any) {
110
136
  if (err.message) {
111
137
  console.error(err.message);
112
138
  }
@@ -116,24 +142,33 @@ if ((!parent || !parent.isParcelRequire) && typeof WebSocket !== 'undefined') {
116
142
 
117
143
  // Web extension context
118
144
  var extCtx =
145
+ // @ts-expect-error TS2304
119
146
  typeof browser === 'undefined'
120
- ? typeof chrome === 'undefined'
147
+ ? // @ts-expect-error TS2304
148
+ typeof chrome === 'undefined'
121
149
  ? null
122
- : chrome
123
- : browser;
150
+ : // @ts-expect-error TS2304
151
+ chrome
152
+ : // @ts-expect-error TS2304
153
+ browser;
124
154
 
125
155
  // Safari doesn't support sourceURL in error stacks.
126
156
  // eval may also be disabled via CSP, so do a quick check.
127
157
  var supportsSourceURL = false;
128
158
  try {
129
159
  (0, eval)('throw new Error("test"); //# sourceURL=test.js');
130
- } catch (err) {
160
+ } catch (err: any) {
131
161
  supportsSourceURL = err.stack.includes('test.js');
132
162
  }
133
163
 
134
- // $FlowFixMe
135
- ws.onmessage = async function (event /*: {data: string, ...} */) {
136
- checkedAssets = ({} /*: {|[string]: boolean|} */);
164
+ // @ts-expect-error TS2339
165
+ ws.onmessage = async function (
166
+ event: {
167
+ data: string;
168
+ } /*: {data: string, ...} */,
169
+ ) {
170
+ checkedAssets = {} /*: {|[string]: boolean|} */;
171
+ disposedAssets = {} /*: {|[string]: boolean|} */;
137
172
  assetsToAccept = [];
138
173
  assetsToDispose = [];
139
174
 
@@ -148,14 +183,17 @@ if ((!parent || !parent.isParcelRequire) && typeof WebSocket !== 'undefined') {
148
183
  }
149
184
 
150
185
  let assets = data.assets.filter(
186
+ // @ts-expect-error TS7006
151
187
  (asset) => asset.envHash === HMR_ENV_HASH,
152
188
  );
153
189
 
154
190
  // Handle HMR Update
191
+ // @ts-expect-error TS7006
155
192
  let handled = assets.every((asset) => {
156
193
  return (
157
194
  asset.type === 'css' ||
158
195
  (asset.type === 'js' &&
196
+ // @ts-expect-error TS2339
159
197
  hmrAcceptCheck(module.bundle.root, asset.id, asset.depsByBundle))
160
198
  );
161
199
  });
@@ -173,23 +211,16 @@ if ((!parent || !parent.isParcelRequire) && typeof WebSocket !== 'undefined') {
173
211
 
174
212
  await hmrApplyUpdates(assets);
175
213
 
176
- // Dispose all old assets.
177
- let processedAssets = ({} /*: {|[string]: boolean|} */);
178
- for (let i = 0; i < assetsToDispose.length; i++) {
179
- let id = assetsToDispose[i][1];
180
-
181
- if (!processedAssets[id]) {
182
- hmrDispose(assetsToDispose[i][0], id);
183
- processedAssets[id] = true;
184
- }
185
- }
214
+ hmrDisposeQueue();
186
215
 
187
216
  // Run accept callbacks. This will also re-execute other disposed assets in topological order.
188
- processedAssets = {};
217
+ let processedAssets: Record<string, any> = {};
189
218
  for (let i = 0; i < assetsToAccept.length; i++) {
219
+ // @ts-expect-error TS7005
190
220
  let id = assetsToAccept[i][1];
191
221
 
192
222
  if (!processedAssets[id]) {
223
+ // @ts-expect-error TS7005
193
224
  hmrAccept(assetsToAccept[i][0], id);
194
225
  processedAssets[id] = true;
195
226
  }
@@ -218,18 +249,17 @@ if ((!parent || !parent.isParcelRequire) && typeof WebSocket !== 'undefined') {
218
249
  // Render the fancy html overlay
219
250
  removeErrorOverlay();
220
251
  var overlay = createErrorOverlay(data.diagnostics.html);
221
- // $FlowFixMe
222
252
  document.body.appendChild(overlay);
223
253
  }
224
254
  }
225
255
  };
226
256
  if (ws instanceof WebSocket) {
227
- ws.onerror = function (e) {
257
+ ws.onerror = function (e: any) {
228
258
  if (e.message) {
229
259
  console.error(e.message);
230
260
  }
231
261
  };
232
- ws.onclose = function (e) {
262
+ ws.onclose = function (e: CloseEvent) {
233
263
  if (process.env.ATLASPACK_BUILD_ENV !== 'test') {
234
264
  console.warn('[parcel] 🚨 Connection to the HMR server was lost');
235
265
  }
@@ -245,7 +275,19 @@ function removeErrorOverlay() {
245
275
  }
246
276
  }
247
277
 
248
- function createErrorOverlay(diagnostics) {
278
+ function createErrorOverlay(
279
+ diagnostics: Array<
280
+ Partial<
281
+ Diff<
282
+ // @ts-expect-error TS2304
283
+ AnsiDiagnosticResult,
284
+ {
285
+ codeframe: string;
286
+ }
287
+ >
288
+ >
289
+ >,
290
+ ) {
249
291
  var overlay = document.createElement('div');
250
292
  overlay.id = OVERLAY_ID;
251
293
 
@@ -254,7 +296,8 @@ function createErrorOverlay(diagnostics) {
254
296
 
255
297
  for (let diagnostic of diagnostics) {
256
298
  let stack = diagnostic.frames.length
257
- ? diagnostic.frames.reduce((p, frame) => {
299
+ ? // @ts-expect-error TS7006
300
+ diagnostic.frames.reduce((p, frame) => {
258
301
  return `${p}
259
302
  <a href="/__parcel_launch_editor?file=${encodeURIComponent(
260
303
  frame.location,
@@ -273,6 +316,7 @@ ${frame.code}`;
273
316
  <pre>${stack}</pre>
274
317
  <div>
275
318
  ${diagnostic.hints
319
+ // @ts-expect-error TS7006
276
320
  .map((hint) => '<div>💡 ' + hint + '</div>')
277
321
  .join('')}
278
322
  </div>
@@ -300,13 +344,18 @@ function fullReload() {
300
344
  }
301
345
  }
302
346
 
303
- function getParents(bundle, id) /*: Array<[ParcelRequire, string]> */ {
347
+ function getParents(
348
+ // @ts-expect-error TS2304
349
+ bundle: ParcelRequire,
350
+ id: string,
351
+ ) /*: Array<[ParcelRequire, string]> */ {
304
352
  var modules = bundle.modules;
305
353
  if (!modules) {
306
354
  return [];
307
355
  }
308
356
 
309
- var parents = [];
357
+ // @ts-expect-error TS2304
358
+ var parents: Array<[ParcelRequire, string]> = [];
310
359
  var k, d, dep;
311
360
 
312
361
  for (k in modules) {
@@ -326,51 +375,55 @@ function getParents(bundle, id) /*: Array<[ParcelRequire, string]> */ {
326
375
  return parents;
327
376
  }
328
377
 
329
- function updateLink(link) {
378
+ function updateLink(link: HTMLElement) {
330
379
  var href = link.getAttribute('href');
331
380
 
332
381
  if (!href) {
333
382
  return;
334
383
  }
335
384
  var newLink = link.cloneNode();
385
+ // @ts-expect-error TS2345
336
386
  newLink.onload = function () {
337
387
  if (link.parentNode !== null) {
338
- // $FlowFixMe
339
388
  link.parentNode.removeChild(link);
340
389
  }
341
390
  };
342
- newLink.setAttribute(
343
- 'href',
344
- // $FlowFixMe
345
- href.split('?')[0] + '?' + Date.now(),
346
- );
347
- // $FlowFixMe
391
+ // @ts-expect-error TS2339
392
+ newLink.setAttribute('href', href.split('?')[0] + '?' + Date.now());
393
+ // @ts-expect-error TS18047
348
394
  link.parentNode.insertBefore(newLink, link.nextSibling);
349
395
  }
350
396
 
397
+ // @ts-expect-error TS7034
351
398
  var cssTimeout = null;
352
399
  function reloadCSS() {
400
+ // @ts-expect-error TS7005
353
401
  if (cssTimeout) {
354
402
  return;
355
403
  }
356
404
 
357
405
  cssTimeout = setTimeout(function () {
406
+ var document = window.document;
358
407
  var links = document.querySelectorAll('link[rel="stylesheet"]');
359
408
  for (var i = 0; i < links.length; i++) {
360
- // $FlowFixMe[incompatible-type]
361
409
  var href /*: string */ = links[i].getAttribute('href');
362
410
  var hostname = getHostname();
363
411
  var servedFromHMRServer =
364
412
  hostname === 'localhost'
365
413
  ? new RegExp(
366
414
  '^(https?:\\/\\/(0.0.0.0|127.0.0.1)|localhost):' + getPort(),
415
+ // @ts-expect-error TS2345
367
416
  ).test(href)
368
- : href.indexOf(hostname + ':' + getPort());
417
+ : // @ts-expect-error TS2345
418
+ href.indexOf(hostname + ':' + getPort());
369
419
  var absolute =
420
+ // @ts-expect-error TS2345
370
421
  /^https?:\/\//i.test(href) &&
422
+ // @ts-expect-error TS18047
371
423
  href.indexOf(location.origin) !== 0 &&
372
424
  !servedFromHMRServer;
373
425
  if (!absolute) {
426
+ // @ts-expect-error TS2345
374
427
  updateLink(links[i]);
375
428
  }
376
429
  }
@@ -379,7 +432,8 @@ function reloadCSS() {
379
432
  }, 50);
380
433
  }
381
434
 
382
- function hmrDownload(asset) {
435
+ // @ts-expect-error TS2304
436
+ function hmrDownload(asset: HMRAsset) {
383
437
  if (asset.type === 'js') {
384
438
  if (typeof document !== 'undefined') {
385
439
  let script = document.createElement('script');
@@ -387,30 +441,48 @@ function hmrDownload(asset) {
387
441
  if (asset.outputFormat === 'esmodule') {
388
442
  script.type = 'module';
389
443
  }
390
- return new Promise((resolve, reject) => {
391
- script.onload = () => resolve(script);
392
- script.onerror = reject;
393
- document.head?.appendChild(script);
394
- });
444
+ return new Promise(
445
+ (
446
+ resolve: (
447
+ result: Promise<HTMLScriptElement> | HTMLScriptElement,
448
+ ) => void,
449
+ reject: (error?: any) => void,
450
+ ) => {
451
+ script.onload = () => resolve(script);
452
+ script.onerror = reject;
453
+ document.head?.appendChild(script);
454
+ },
455
+ );
456
+ // @ts-expect-error TS2304
395
457
  } else if (typeof importScripts === 'function') {
396
458
  // Worker scripts
397
459
  if (asset.outputFormat === 'esmodule') {
460
+ // @ts-expect-error TS2304
398
461
  return __parcel__import__(asset.url + '?t=' + Date.now());
399
462
  } else {
400
- return new Promise((resolve, reject) => {
401
- try {
402
- __parcel__importScripts__(asset.url + '?t=' + Date.now());
403
- resolve();
404
- } catch (err) {
405
- reject(err);
406
- }
407
- });
463
+ return new Promise(
464
+ (
465
+ resolve: (result: Promise<undefined> | undefined) => void,
466
+ reject: (error?: any) => void,
467
+ ) => {
468
+ try {
469
+ // @ts-expect-error TS2304
470
+ __parcel__importScripts__(asset.url + '?t=' + Date.now());
471
+ // @ts-expect-error TS2794
472
+ resolve();
473
+ } catch (err: any) {
474
+ reject(err);
475
+ }
476
+ },
477
+ );
408
478
  }
409
479
  }
410
480
  }
411
481
  }
412
482
 
413
- async function hmrApplyUpdates(assets) {
483
+ // @ts-expect-error TS2304
484
+ async function hmrApplyUpdates(assets: Array<HMRAsset>) {
485
+ // @ts-expect-error TS7017
414
486
  global.parcelHotUpdate = Object.create(null);
415
487
 
416
488
  let scriptsToRemove;
@@ -423,13 +495,15 @@ async function hmrApplyUpdates(assets) {
423
495
  // This path is also taken if a CSP disallows eval.
424
496
  if (!supportsSourceURL) {
425
497
  let promises = assets.map((asset) =>
426
- hmrDownload(asset)?.catch((err) => {
498
+ hmrDownload(asset)?.catch((err: any) => {
427
499
  // Web extension fix
428
500
  if (
429
501
  extCtx &&
430
502
  extCtx.runtime &&
431
503
  extCtx.runtime.getManifest().manifest_version == 3 &&
504
+ // @ts-expect-error TS2304
432
505
  typeof ServiceWorkerGlobalScope != 'undefined' &&
506
+ // @ts-expect-error TS2304
433
507
  global instanceof ServiceWorkerGlobalScope
434
508
  ) {
435
509
  extCtx.runtime.reload();
@@ -443,12 +517,15 @@ async function hmrApplyUpdates(assets) {
443
517
  }
444
518
 
445
519
  assets.forEach(function (asset) {
520
+ // @ts-expect-error TS2339
446
521
  hmrApply(module.bundle.root, asset);
447
522
  });
448
523
  } finally {
524
+ // @ts-expect-error TS7017
449
525
  delete global.parcelHotUpdate;
450
526
 
451
527
  if (scriptsToRemove) {
528
+ // @ts-expect-error TS7006
452
529
  scriptsToRemove.forEach((script) => {
453
530
  if (script) {
454
531
  document.head?.removeChild(script);
@@ -458,7 +535,12 @@ async function hmrApplyUpdates(assets) {
458
535
  }
459
536
  }
460
537
 
461
- function hmrApply(bundle /*: ParcelRequire */, asset /*: HMRAsset */) {
538
+ function hmrApply(
539
+ // @ts-expect-error TS2304
540
+ bundle: ParcelRequire /*: ParcelRequire */,
541
+ // @ts-expect-error TS2304
542
+ asset: HMRAsset /*: HMRAsset */,
543
+ ) {
462
544
  var modules = bundle.modules;
463
545
  if (!modules) {
464
546
  return;
@@ -476,8 +558,10 @@ function hmrApply(bundle /*: ParcelRequire */, asset /*: HMRAsset */) {
476
558
  for (let dep in oldDeps) {
477
559
  if (!deps[dep] || deps[dep] !== oldDeps[dep]) {
478
560
  let id = oldDeps[dep];
561
+ // @ts-expect-error TS2339
479
562
  let parents = getParents(module.bundle.root, id);
480
563
  if (parents.length === 1) {
564
+ // @ts-expect-error TS2339
481
565
  hmrDelete(module.bundle.root, id);
482
566
  }
483
567
  }
@@ -490,16 +574,21 @@ function hmrApply(bundle /*: ParcelRequire */, asset /*: HMRAsset */) {
490
574
  (0, eval)(asset.output);
491
575
  }
492
576
 
493
- // $FlowFixMe
577
+ // @ts-expect-error TS7017
494
578
  let fn = global.parcelHotUpdate[asset.id];
495
579
  modules[asset.id] = [fn, deps];
496
- } else if (bundle.parent) {
580
+ }
581
+
582
+ // Always traverse to the parent bundle, even if we already replaced the asset in this bundle.
583
+ // This is required in case modules are duplicated. We need to ensure all instances have the updated code.
584
+ if (bundle.parent) {
497
585
  hmrApply(bundle.parent, asset);
498
586
  }
499
587
  }
500
588
  }
501
589
 
502
- function hmrDelete(bundle, id) {
590
+ // @ts-expect-error TS2304
591
+ function hmrDelete(bundle: ParcelRequire, id: string) {
503
592
  let modules = bundle.modules;
504
593
  if (!modules) {
505
594
  return;
@@ -508,8 +597,9 @@ function hmrDelete(bundle, id) {
508
597
  if (modules[id]) {
509
598
  // Collect dependencies that will become orphaned when this module is deleted.
510
599
  let deps = modules[id][1];
511
- let orphans = [];
600
+ let orphans: Array<string> = [];
512
601
  for (let dep in deps) {
602
+ // @ts-expect-error TS2339
513
603
  let parents = getParents(module.bundle.root, deps[dep]);
514
604
  if (parents.length === 1) {
515
605
  orphans.push(deps[dep]);
@@ -522,6 +612,7 @@ function hmrDelete(bundle, id) {
522
612
 
523
613
  // Now delete the orphans.
524
614
  orphans.forEach((id) => {
615
+ // @ts-expect-error TS2339
525
616
  hmrDelete(module.bundle.root, id);
526
617
  });
527
618
  } else if (bundle.parent) {
@@ -530,25 +621,36 @@ function hmrDelete(bundle, id) {
530
621
  }
531
622
 
532
623
  function hmrAcceptCheck(
533
- bundle /*: ParcelRequire */,
534
- id /*: string */,
535
- depsByBundle /*: ?{ [string]: { [string]: string } }*/,
624
+ // @ts-expect-error TS2304
625
+ bundle: ParcelRequire /*: ParcelRequire */,
626
+ id: string /*: string */,
627
+ depsByBundle:
628
+ | {
629
+ [key: string]: {
630
+ [key: string]: string;
631
+ };
632
+ }
633
+ | null
634
+ | undefined /*: ?{ [string]: { [string]: string } }*/,
536
635
  ) {
537
636
  if (hmrAcceptCheckOne(bundle, id, depsByBundle)) {
538
637
  return true;
539
638
  }
540
639
 
541
640
  // Traverse parents breadth first. All possible ancestries must accept the HMR update, or we'll reload.
641
+ // @ts-expect-error TS2339
542
642
  let parents = getParents(module.bundle.root, id);
543
643
  let accepted = false;
544
644
  while (parents.length > 0) {
545
645
  let v = parents.shift();
646
+ // @ts-expect-error TS18048
546
647
  let a = hmrAcceptCheckOne(v[0], v[1], null);
547
648
  if (a) {
548
649
  // If this parent accepts, stop traversing upward, but still consider siblings.
549
650
  accepted = true;
550
651
  } else {
551
652
  // Otherwise, queue the parents in the next level upward.
653
+ // @ts-expect-error TS2339
552
654
  let p = getParents(module.bundle.root, v[1]);
553
655
  if (p.length === 0) {
554
656
  // If there are no parents, then we've reached an entry without accepting. Reload.
@@ -563,9 +665,17 @@ function hmrAcceptCheck(
563
665
  }
564
666
 
565
667
  function hmrAcceptCheckOne(
566
- bundle /*: ParcelRequire */,
567
- id /*: string */,
568
- depsByBundle /*: ?{ [string]: { [string]: string } }*/,
668
+ // @ts-expect-error TS2304
669
+ bundle: ParcelRequire /*: ParcelRequire */,
670
+ id: string /*: string */,
671
+ depsByBundle:
672
+ | {
673
+ [key: string]: {
674
+ [key: string]: string;
675
+ };
676
+ }
677
+ | null
678
+ | undefined /*: ?{ [string]: { [string]: string } }*/,
569
679
  ) {
570
680
  var modules = bundle.modules;
571
681
  if (!modules) {
@@ -582,10 +692,12 @@ function hmrAcceptCheckOne(
582
692
  return hmrAcceptCheck(bundle.parent, id, depsByBundle);
583
693
  }
584
694
 
695
+ // @ts-expect-error TS7005
585
696
  if (checkedAssets[id]) {
586
697
  return true;
587
698
  }
588
699
 
700
+ // @ts-expect-error TS7005
589
701
  checkedAssets[id] = true;
590
702
 
591
703
  var cached = bundle.cache[id];
@@ -597,7 +709,28 @@ function hmrAcceptCheckOne(
597
709
  }
598
710
  }
599
711
 
600
- function hmrDispose(bundle /*: ParcelRequire */, id /*: string */) {
712
+ function hmrDisposeQueue() {
713
+ // Dispose all old assets.
714
+ for (let i = 0; i < assetsToDispose.length; i++) {
715
+ // @ts-expect-error TS7005
716
+ let id = assetsToDispose[i][1];
717
+
718
+ // @ts-expect-error TS7005
719
+ if (!disposedAssets[id]) {
720
+ // @ts-expect-error TS7005
721
+ hmrDispose(assetsToDispose[i][0], id);
722
+ disposedAssets[id] = true;
723
+ }
724
+ }
725
+
726
+ assetsToDispose = [];
727
+ }
728
+
729
+ function hmrDispose(
730
+ // @ts-expect-error TS2304
731
+ bundle: ParcelRequire /*: ParcelRequire */,
732
+ id: string /*: string */,
733
+ ) {
601
734
  var cached = bundle.cache[id];
602
735
  bundle.hotData[id] = {};
603
736
  if (cached && cached.hot) {
@@ -605,6 +738,7 @@ function hmrDispose(bundle /*: ParcelRequire */, id /*: string */) {
605
738
  }
606
739
 
607
740
  if (cached && cached.hot && cached.hot._disposeCallbacks.length) {
741
+ // @ts-expect-error TS7006
608
742
  cached.hot._disposeCallbacks.forEach(function (cb) {
609
743
  cb(bundle.hotData[id]);
610
744
  });
@@ -613,25 +747,41 @@ function hmrDispose(bundle /*: ParcelRequire */, id /*: string */) {
613
747
  delete bundle.cache[id];
614
748
  }
615
749
 
616
- function hmrAccept(bundle /*: ParcelRequire */, id /*: string */) {
750
+ function hmrAccept(
751
+ // @ts-expect-error TS2304
752
+ bundle: ParcelRequire /*: ParcelRequire */,
753
+ id: string /*: string */,
754
+ ) {
617
755
  // Execute the module.
618
756
  bundle(id);
619
757
 
620
758
  // Run the accept callbacks in the new version of the module.
621
759
  var cached = bundle.cache[id];
622
760
  if (cached && cached.hot && cached.hot._acceptCallbacks.length) {
761
+ let assetsToAlsoAccept: Array<never> = [];
762
+ // @ts-expect-error TS7006
623
763
  cached.hot._acceptCallbacks.forEach(function (cb) {
624
- var assetsToAlsoAccept = cb(function () {
764
+ let additionalAssets = cb(function () {
765
+ // @ts-expect-error TS2339
625
766
  return getParents(module.bundle.root, id);
626
767
  });
627
- if (assetsToAlsoAccept && assetsToAccept.length) {
628
- assetsToAlsoAccept.forEach(function (a) {
629
- hmrDispose(a[0], a[1]);
630
- });
631
-
632
- // $FlowFixMe[method-unbinding]
633
- assetsToAccept.push.apply(assetsToAccept, assetsToAlsoAccept);
768
+ if (Array.isArray(additionalAssets) && additionalAssets.length) {
769
+ // @ts-expect-error TS2345
770
+ assetsToAlsoAccept.push(...additionalAssets);
634
771
  }
635
772
  });
773
+
774
+ if (assetsToAlsoAccept.length > 0) {
775
+ let handled = assetsToAlsoAccept.every(function (a) {
776
+ // @ts-expect-error TS2554
777
+ return hmrAcceptCheck(a[0], a[1]);
778
+ });
779
+
780
+ if (!handled) {
781
+ return fullReload();
782
+ }
783
+
784
+ hmrDisposeQueue();
785
+ }
636
786
  }
637
787
  }
package/tsconfig.json ADDED
@@ -0,0 +1,16 @@
1
+ {
2
+ "extends": "../../../tsconfig.base.json",
3
+ "include": ["src"],
4
+ "compilerOptions": {
5
+ "lib": ["ESNext", "DOM"],
6
+ "composite": true
7
+ },
8
+ "references": [
9
+ {
10
+ "path": "../../core/plugin/tsconfig.json"
11
+ },
12
+ {
13
+ "path": "../../core/utils/tsconfig.json"
14
+ }
15
+ ]
16
+ }