@atlaspack/runtime-browser-hmr 2.14.5-canary.26 → 2.14.5-canary.261

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,6 +1,7 @@
1
1
  "use strict";
2
2
 
3
3
  /* global HMR_HOST, HMR_PORT, HMR_ENV_HASH, HMR_SECURE, HMR_USE_SSE, chrome, browser, __parcel__import__, __parcel__importScripts__, ServiceWorkerGlobalScope */
4
+
4
5
  /*::
5
6
  import type {
6
7
  HMRAsset,
@@ -48,41 +49,72 @@ declare var __parcel__importScripts__: (string) => Promise<void>;
48
49
  declare var globalThis: typeof self;
49
50
  declare var ServiceWorkerGlobalScope: Object;
50
51
  */
52
+
53
+ // flow-to-ts helpers
54
+
55
+ // /flow-to-ts helpers
56
+
51
57
  var OVERLAY_ID = '__parcel__error__overlay__';
58
+
59
+ // @ts-expect-error TS2339
52
60
  var OldModule = module.bundle.Module;
53
61
  function Module(moduleName) {
62
+ // @ts-expect-error TS2683
54
63
  OldModule.call(this, moduleName);
64
+ // @ts-expect-error TS2683
55
65
  this.hot = {
66
+ // @ts-expect-error TS2339
56
67
  data: module.bundle.hotData[moduleName],
57
68
  _acceptCallbacks: [],
58
69
  _disposeCallbacks: [],
70
+ // @ts-expect-error TS7006
59
71
  accept: function (fn) {
60
72
  this._acceptCallbacks.push(fn || function () {});
61
73
  },
74
+ // @ts-expect-error TS7006
62
75
  dispose: function (fn) {
63
76
  this._disposeCallbacks.push(fn);
64
77
  }
65
78
  };
79
+ // @ts-expect-error TS2339
66
80
  module.bundle.hotData[moduleName] = undefined;
67
81
  }
82
+ // @ts-expect-error TS2339
68
83
  module.bundle.Module = Module;
84
+ // @ts-expect-error TS2339
69
85
  module.bundle.hotData = {};
70
- var checkedAssets /*: {|[string]: boolean|} */, assetsToDispose /*: Array<[ParcelRequire, string]> */, assetsToAccept /*: Array<[ParcelRequire, string]> */;
86
+
87
+ // @ts-expect-error TS7034
88
+ var checkedAssets /*: {|[string]: boolean|} */,
89
+ // @ts-expect-error TS7034
90
+ disposedAssets /*: {|[string]: boolean|} */,
91
+ // @ts-expect-error TS7034
92
+ assetsToDispose /*: Array<[ParcelRequire, string]> */,
93
+ // @ts-expect-error TS7034
94
+ assetsToAccept /*: Array<[ParcelRequire, string]> */;
71
95
 
72
96
  function getHostname() {
73
- return HMR_HOST || (location.protocol.indexOf('http') === 0 ? location.hostname : 'localhost');
97
+ return (
98
+ // @ts-expect-error TS2304
99
+ HMR_HOST || (location.protocol.indexOf('http') === 0 ? location.hostname : 'localhost')
100
+ );
74
101
  }
75
102
  function getPort() {
103
+ // @ts-expect-error TS2304
76
104
  return HMR_PORT || location.port;
77
105
  }
78
106
 
79
107
  // eslint-disable-next-line no-redeclare
108
+ // @ts-expect-error TS2339
80
109
  var parent = module.bundle.parent;
81
110
  if ((!parent || !parent.isParcelRequire) && typeof WebSocket !== 'undefined') {
82
111
  var hostname = getHostname();
83
112
  var port = getPort();
84
- var protocol = HMR_SECURE || location.protocol == 'https:' && !['localhost', '127.0.0.1', '0.0.0.0'].includes(hostname) ? 'wss' : 'ws';
113
+ var protocol =
114
+ // @ts-expect-error TS2304
115
+ HMR_SECURE || location.protocol == 'https:' && !['localhost', '127.0.0.1', '0.0.0.0'].includes(hostname) ? 'wss' : 'ws';
85
116
  var ws;
117
+ // @ts-expect-error TS2304
86
118
  if (HMR_USE_SSE) {
87
119
  ws = new EventSource('/__parcel_hmr');
88
120
  } else {
@@ -97,7 +129,15 @@ if ((!parent || !parent.isParcelRequire) && typeof WebSocket !== 'undefined') {
97
129
  }
98
130
 
99
131
  // Web extension context
100
- var extCtx = typeof browser === 'undefined' ? typeof chrome === 'undefined' ? null : chrome : browser;
132
+ var extCtx =
133
+ // @ts-expect-error TS2304
134
+ typeof browser === 'undefined' ?
135
+ // @ts-expect-error TS2304
136
+ typeof chrome === 'undefined' ? null :
137
+ // @ts-expect-error TS2304
138
+ chrome :
139
+ // @ts-expect-error TS2304
140
+ browser;
101
141
 
102
142
  // Safari doesn't support sourceURL in error stacks.
103
143
  // eval may also be disabled via CSP, so do a quick check.
@@ -108,9 +148,10 @@ if ((!parent || !parent.isParcelRequire) && typeof WebSocket !== 'undefined') {
108
148
  supportsSourceURL = err.stack.includes('test.js');
109
149
  }
110
150
 
111
- // $FlowFixMe
112
- ws.onmessage = async function (event /*: {data: string, ...} */) {
151
+ // @ts-expect-error TS2339
152
+ ws.onmessage = async function (event) {
113
153
  checkedAssets = {} /*: {|[string]: boolean|} */;
154
+ disposedAssets = {} /*: {|[string]: boolean|} */;
114
155
  assetsToAccept = [];
115
156
  assetsToDispose = [];
116
157
  var data /*: HMRMessage */ = JSON.parse(event.data);
@@ -121,11 +162,16 @@ if ((!parent || !parent.isParcelRequire) && typeof WebSocket !== 'undefined') {
121
162
  if (typeof document !== 'undefined') {
122
163
  removeErrorOverlay();
123
164
  }
124
- let assets = data.assets.filter(asset => asset.envHash === HMR_ENV_HASH);
165
+ let assets = data.assets.filter(
166
+ // @ts-expect-error TS7006
167
+ asset => asset.envHash === HMR_ENV_HASH);
125
168
 
126
169
  // Handle HMR Update
170
+ // @ts-expect-error TS7006
127
171
  let handled = assets.every(asset => {
128
- return asset.type === 'css' || asset.type === 'js' && hmrAcceptCheck(module.bundle.root, asset.id, asset.depsByBundle);
172
+ return asset.type === 'css' || asset.type === 'js' &&
173
+ // @ts-expect-error TS2339
174
+ hmrAcceptCheck(module.bundle.root, asset.id, asset.depsByBundle);
129
175
  });
130
176
  if (handled) {
131
177
  console.clear();
@@ -135,22 +181,15 @@ if ((!parent || !parent.isParcelRequire) && typeof WebSocket !== 'undefined') {
135
181
  window.dispatchEvent(new CustomEvent('parcelhmraccept'));
136
182
  }
137
183
  await hmrApplyUpdates(assets);
138
-
139
- // Dispose all old assets.
140
- let processedAssets = {} /*: {|[string]: boolean|} */;
141
- for (let i = 0; i < assetsToDispose.length; i++) {
142
- let id = assetsToDispose[i][1];
143
- if (!processedAssets[id]) {
144
- hmrDispose(assetsToDispose[i][0], id);
145
- processedAssets[id] = true;
146
- }
147
- }
184
+ hmrDisposeQueue();
148
185
 
149
186
  // Run accept callbacks. This will also re-execute other disposed assets in topological order.
150
- processedAssets = {};
187
+ let processedAssets = {};
151
188
  for (let i = 0; i < assetsToAccept.length; i++) {
189
+ // @ts-expect-error TS7005
152
190
  let id = assetsToAccept[i][1];
153
191
  if (!processedAssets[id]) {
192
+ // @ts-expect-error TS7005
154
193
  hmrAccept(assetsToAccept[i][0], id);
155
194
  processedAssets[id] = true;
156
195
  }
@@ -167,7 +206,6 @@ if ((!parent || !parent.isParcelRequire) && typeof WebSocket !== 'undefined') {
167
206
  // Render the fancy html overlay
168
207
  removeErrorOverlay();
169
208
  var overlay = createErrorOverlay(data.diagnostics.html);
170
- // $FlowFixMe
171
209
  document.body.appendChild(overlay);
172
210
  }
173
211
  }
@@ -178,8 +216,10 @@ if ((!parent || !parent.isParcelRequire) && typeof WebSocket !== 'undefined') {
178
216
  console.error(e.message);
179
217
  }
180
218
  };
181
- ws.onclose = function () {
182
- console.warn('[parcel] 🚨 Connection to the HMR server was lost');
219
+ ws.onclose = function (e) {
220
+ if (process.env.ATLASPACK_BUILD_ENV !== 'test') {
221
+ console.warn('[parcel] 🚨 Connection to the HMR server was lost');
222
+ }
183
223
  };
184
224
  }
185
225
  }
@@ -195,7 +235,9 @@ function createErrorOverlay(diagnostics) {
195
235
  overlay.id = OVERLAY_ID;
196
236
  let errorHTML = '<div style="background: black; opacity: 0.85; font-size: 16px; color: white; position: fixed; height: 100%; width: 100%; top: 0px; left: 0px; padding: 30px; font-family: Menlo, Consolas, monospace; z-index: 9999;">';
197
237
  for (let diagnostic of diagnostics) {
198
- let stack = diagnostic.frames.length ? diagnostic.frames.reduce((p, frame) => {
238
+ let stack = diagnostic.frames.length ?
239
+ // @ts-expect-error TS7006
240
+ diagnostic.frames.reduce((p, frame) => {
199
241
  return `${p}
200
242
  <a href="/__parcel_launch_editor?file=${encodeURIComponent(frame.location)}" style="text-decoration: underline; color: #888" onclick="fetch(this.href); return false">${frame.location}</a>
201
243
  ${frame.code}`;
@@ -207,7 +249,9 @@ ${frame.code}`;
207
249
  </div>
208
250
  <pre>${stack}</pre>
209
251
  <div>
210
- ${diagnostic.hints.map(hint => '<div>💡 ' + hint + '</div>').join('')}
252
+ ${diagnostic.hints
253
+ // @ts-expect-error TS7006
254
+ .map(hint => '<div>💡 ' + hint + '</div>').join('')}
211
255
  </div>
212
256
  ${diagnostic.documentation ? `<div>📝 <a style="color: violet" href="${diagnostic.documentation}" target="_blank">Learn more</a></div>` : ''}
213
257
  </div>
@@ -224,11 +268,15 @@ function fullReload() {
224
268
  extCtx.runtime.reload();
225
269
  }
226
270
  }
227
- function getParents(bundle, id) /*: Array<[ParcelRequire, string]> */{
271
+ function getParents(
272
+ // @ts-expect-error TS2304
273
+ bundle, id) /*: Array<[ParcelRequire, string]> */{
228
274
  var modules = bundle.modules;
229
275
  if (!modules) {
230
276
  return [];
231
277
  }
278
+
279
+ // @ts-expect-error TS2304
232
280
  var parents = [];
233
281
  var k, d, dep;
234
282
  for (k in modules) {
@@ -250,38 +298,50 @@ function updateLink(link) {
250
298
  return;
251
299
  }
252
300
  var newLink = link.cloneNode();
301
+ // @ts-expect-error TS2345
253
302
  newLink.onload = function () {
254
303
  if (link.parentNode !== null) {
255
- // $FlowFixMe
256
304
  link.parentNode.removeChild(link);
257
305
  }
258
306
  };
259
- newLink.setAttribute('href',
260
- // $FlowFixMe
261
- href.split('?')[0] + '?' + Date.now());
262
- // $FlowFixMe
307
+ // @ts-expect-error TS2339
308
+ newLink.setAttribute('href', href.split('?')[0] + '?' + Date.now());
309
+ // @ts-expect-error TS18047
263
310
  link.parentNode.insertBefore(newLink, link.nextSibling);
264
311
  }
312
+
313
+ // @ts-expect-error TS7034
265
314
  var cssTimeout = null;
266
315
  function reloadCSS() {
316
+ // @ts-expect-error TS7005
267
317
  if (cssTimeout) {
268
318
  return;
269
319
  }
270
320
  cssTimeout = setTimeout(function () {
321
+ var document = window.document;
271
322
  var links = document.querySelectorAll('link[rel="stylesheet"]');
272
323
  for (var i = 0; i < links.length; i++) {
273
- // $FlowFixMe[incompatible-type]
274
324
  var href /*: string */ = links[i].getAttribute('href');
275
325
  var hostname = getHostname();
276
- var servedFromHMRServer = hostname === 'localhost' ? new RegExp('^(https?:\\/\\/(0.0.0.0|127.0.0.1)|localhost):' + getPort()).test(href) : href.indexOf(hostname + ':' + getPort());
277
- var absolute = /^https?:\/\//i.test(href) && href.indexOf(location.origin) !== 0 && !servedFromHMRServer;
326
+ var servedFromHMRServer = hostname === 'localhost' ? new RegExp('^(https?:\\/\\/(0.0.0.0|127.0.0.1)|localhost):' + getPort()) // @ts-expect-error TS2345
327
+ .test(href) :
328
+ // @ts-expect-error TS2345
329
+ href.indexOf(hostname + ':' + getPort());
330
+ var absolute =
331
+ // @ts-expect-error TS2345
332
+ /^https?:\/\//i.test(href) &&
333
+ // @ts-expect-error TS18047
334
+ href.indexOf(location.origin) !== 0 && !servedFromHMRServer;
278
335
  if (!absolute) {
336
+ // @ts-expect-error TS2345
279
337
  updateLink(links[i]);
280
338
  }
281
339
  }
282
340
  cssTimeout = null;
283
341
  }, 50);
284
342
  }
343
+
344
+ // @ts-expect-error TS2304
285
345
  function hmrDownload(asset) {
286
346
  if (asset.type === 'js') {
287
347
  if (typeof document !== 'undefined') {
@@ -296,14 +356,18 @@ function hmrDownload(asset) {
296
356
  script.onerror = reject;
297
357
  (_document$head = document.head) === null || _document$head === void 0 || _document$head.appendChild(script);
298
358
  });
359
+ // @ts-expect-error TS2304
299
360
  } else if (typeof importScripts === 'function') {
300
361
  // Worker scripts
301
362
  if (asset.outputFormat === 'esmodule') {
363
+ // @ts-expect-error TS2304
302
364
  return __parcel__import__(asset.url + '?t=' + Date.now());
303
365
  } else {
304
366
  return new Promise((resolve, reject) => {
305
367
  try {
368
+ // @ts-expect-error TS2304
306
369
  __parcel__importScripts__(asset.url + '?t=' + Date.now());
370
+ // @ts-expect-error TS2794
307
371
  resolve();
308
372
  } catch (err) {
309
373
  reject(err);
@@ -313,7 +377,10 @@ function hmrDownload(asset) {
313
377
  }
314
378
  }
315
379
  }
380
+
381
+ // @ts-expect-error TS2304
316
382
  async function hmrApplyUpdates(assets) {
383
+ // @ts-expect-error TS7017
317
384
  global.parcelHotUpdate = Object.create(null);
318
385
  let scriptsToRemove;
319
386
  try {
@@ -328,7 +395,11 @@ async function hmrApplyUpdates(assets) {
328
395
  var _hmrDownload;
329
396
  return (_hmrDownload = hmrDownload(asset)) === null || _hmrDownload === void 0 ? void 0 : _hmrDownload.catch(err => {
330
397
  // Web extension fix
331
- if (extCtx && extCtx.runtime && extCtx.runtime.getManifest().manifest_version == 3 && typeof ServiceWorkerGlobalScope != 'undefined' && global instanceof ServiceWorkerGlobalScope) {
398
+ if (extCtx && extCtx.runtime && extCtx.runtime.getManifest().manifest_version == 3 &&
399
+ // @ts-expect-error TS2304
400
+ typeof ServiceWorkerGlobalScope != 'undefined' &&
401
+ // @ts-expect-error TS2304
402
+ global instanceof ServiceWorkerGlobalScope) {
332
403
  extCtx.runtime.reload();
333
404
  return;
334
405
  }
@@ -338,11 +409,14 @@ async function hmrApplyUpdates(assets) {
338
409
  scriptsToRemove = await Promise.all(promises);
339
410
  }
340
411
  assets.forEach(function (asset) {
412
+ // @ts-expect-error TS2339
341
413
  hmrApply(module.bundle.root, asset);
342
414
  });
343
415
  } finally {
416
+ // @ts-expect-error TS7017
344
417
  delete global.parcelHotUpdate;
345
418
  if (scriptsToRemove) {
419
+ // @ts-expect-error TS7006
346
420
  scriptsToRemove.forEach(script => {
347
421
  if (script) {
348
422
  var _document$head2;
@@ -352,7 +426,11 @@ async function hmrApplyUpdates(assets) {
352
426
  }
353
427
  }
354
428
  }
355
- function hmrApply(bundle /*: ParcelRequire */, asset /*: HMRAsset */) {
429
+ function hmrApply(
430
+ // @ts-expect-error TS2304
431
+ bundle,
432
+ // @ts-expect-error TS2304
433
+ asset) {
356
434
  var modules = bundle.modules;
357
435
  if (!modules) {
358
436
  return;
@@ -369,8 +447,10 @@ function hmrApply(bundle /*: ParcelRequire */, asset /*: HMRAsset */) {
369
447
  for (let dep in oldDeps) {
370
448
  if (!deps[dep] || deps[dep] !== oldDeps[dep]) {
371
449
  let id = oldDeps[dep];
450
+ // @ts-expect-error TS2339
372
451
  let parents = getParents(module.bundle.root, id);
373
452
  if (parents.length === 1) {
453
+ // @ts-expect-error TS2339
374
454
  hmrDelete(module.bundle.root, id);
375
455
  }
376
456
  }
@@ -382,14 +462,20 @@ function hmrApply(bundle /*: ParcelRequire */, asset /*: HMRAsset */) {
382
462
  (0, eval)(asset.output);
383
463
  }
384
464
 
385
- // $FlowFixMe
465
+ // @ts-expect-error TS7017
386
466
  let fn = global.parcelHotUpdate[asset.id];
387
467
  modules[asset.id] = [fn, deps];
388
- } else if (bundle.parent) {
468
+ }
469
+
470
+ // Always traverse to the parent bundle, even if we already replaced the asset in this bundle.
471
+ // This is required in case modules are duplicated. We need to ensure all instances have the updated code.
472
+ if (bundle.parent) {
389
473
  hmrApply(bundle.parent, asset);
390
474
  }
391
475
  }
392
476
  }
477
+
478
+ // @ts-expect-error TS2304
393
479
  function hmrDelete(bundle, id) {
394
480
  let modules = bundle.modules;
395
481
  if (!modules) {
@@ -400,6 +486,7 @@ function hmrDelete(bundle, id) {
400
486
  let deps = modules[id][1];
401
487
  let orphans = [];
402
488
  for (let dep in deps) {
489
+ // @ts-expect-error TS2339
403
490
  let parents = getParents(module.bundle.root, deps[dep]);
404
491
  if (parents.length === 1) {
405
492
  orphans.push(deps[dep]);
@@ -412,28 +499,34 @@ function hmrDelete(bundle, id) {
412
499
 
413
500
  // Now delete the orphans.
414
501
  orphans.forEach(id => {
502
+ // @ts-expect-error TS2339
415
503
  hmrDelete(module.bundle.root, id);
416
504
  });
417
505
  } else if (bundle.parent) {
418
506
  hmrDelete(bundle.parent, id);
419
507
  }
420
508
  }
421
- function hmrAcceptCheck(bundle /*: ParcelRequire */, id /*: string */, depsByBundle /*: ?{ [string]: { [string]: string } }*/) {
509
+ function hmrAcceptCheck(
510
+ // @ts-expect-error TS2304
511
+ bundle, id, depsByBundle) {
422
512
  if (hmrAcceptCheckOne(bundle, id, depsByBundle)) {
423
513
  return true;
424
514
  }
425
515
 
426
516
  // Traverse parents breadth first. All possible ancestries must accept the HMR update, or we'll reload.
517
+ // @ts-expect-error TS2339
427
518
  let parents = getParents(module.bundle.root, id);
428
519
  let accepted = false;
429
520
  while (parents.length > 0) {
430
521
  let v = parents.shift();
522
+ // @ts-expect-error TS18048
431
523
  let a = hmrAcceptCheckOne(v[0], v[1], null);
432
524
  if (a) {
433
525
  // If this parent accepts, stop traversing upward, but still consider siblings.
434
526
  accepted = true;
435
527
  } else {
436
528
  // Otherwise, queue the parents in the next level upward.
529
+ // @ts-expect-error TS2339
437
530
  let p = getParents(module.bundle.root, v[1]);
438
531
  if (p.length === 0) {
439
532
  // If there are no parents, then we've reached an entry without accepting. Reload.
@@ -445,7 +538,9 @@ function hmrAcceptCheck(bundle /*: ParcelRequire */, id /*: string */, depsByBun
445
538
  }
446
539
  return accepted;
447
540
  }
448
- function hmrAcceptCheckOne(bundle /*: ParcelRequire */, id /*: string */, depsByBundle /*: ?{ [string]: { [string]: string } }*/) {
541
+ function hmrAcceptCheckOne(
542
+ // @ts-expect-error TS2304
543
+ bundle, id, depsByBundle) {
449
544
  var modules = bundle.modules;
450
545
  if (!modules) {
451
546
  return;
@@ -458,9 +553,13 @@ function hmrAcceptCheckOne(bundle /*: ParcelRequire */, id /*: string */, depsBy
458
553
  }
459
554
  return hmrAcceptCheck(bundle.parent, id, depsByBundle);
460
555
  }
556
+
557
+ // @ts-expect-error TS7005
461
558
  if (checkedAssets[id]) {
462
559
  return true;
463
560
  }
561
+
562
+ // @ts-expect-error TS7005
464
563
  checkedAssets[id] = true;
465
564
  var cached = bundle.cache[id];
466
565
  assetsToDispose.push([bundle, id]);
@@ -469,38 +568,67 @@ function hmrAcceptCheckOne(bundle /*: ParcelRequire */, id /*: string */, depsBy
469
568
  return true;
470
569
  }
471
570
  }
472
- function hmrDispose(bundle /*: ParcelRequire */, id /*: string */) {
571
+ function hmrDisposeQueue() {
572
+ // Dispose all old assets.
573
+ for (let i = 0; i < assetsToDispose.length; i++) {
574
+ // @ts-expect-error TS7005
575
+ let id = assetsToDispose[i][1];
576
+
577
+ // @ts-expect-error TS7005
578
+ if (!disposedAssets[id]) {
579
+ // @ts-expect-error TS7005
580
+ hmrDispose(assetsToDispose[i][0], id);
581
+ disposedAssets[id] = true;
582
+ }
583
+ }
584
+ assetsToDispose = [];
585
+ }
586
+ function hmrDispose(
587
+ // @ts-expect-error TS2304
588
+ bundle, id) {
473
589
  var cached = bundle.cache[id];
474
590
  bundle.hotData[id] = {};
475
591
  if (cached && cached.hot) {
476
592
  cached.hot.data = bundle.hotData[id];
477
593
  }
478
594
  if (cached && cached.hot && cached.hot._disposeCallbacks.length) {
595
+ // @ts-expect-error TS7006
479
596
  cached.hot._disposeCallbacks.forEach(function (cb) {
480
597
  cb(bundle.hotData[id]);
481
598
  });
482
599
  }
483
600
  delete bundle.cache[id];
484
601
  }
485
- function hmrAccept(bundle /*: ParcelRequire */, id /*: string */) {
602
+ function hmrAccept(
603
+ // @ts-expect-error TS2304
604
+ bundle, id) {
486
605
  // Execute the module.
487
606
  bundle(id);
488
607
 
489
608
  // Run the accept callbacks in the new version of the module.
490
609
  var cached = bundle.cache[id];
491
610
  if (cached && cached.hot && cached.hot._acceptCallbacks.length) {
611
+ let assetsToAlsoAccept = [];
612
+ // @ts-expect-error TS7006
492
613
  cached.hot._acceptCallbacks.forEach(function (cb) {
493
- var assetsToAlsoAccept = cb(function () {
614
+ let additionalAssets = cb(function () {
615
+ // @ts-expect-error TS2339
494
616
  return getParents(module.bundle.root, id);
495
617
  });
496
- if (assetsToAlsoAccept && assetsToAccept.length) {
497
- assetsToAlsoAccept.forEach(function (a) {
498
- hmrDispose(a[0], a[1]);
499
- });
500
-
501
- // $FlowFixMe[method-unbinding]
502
- assetsToAccept.push.apply(assetsToAccept, assetsToAlsoAccept);
618
+ if (Array.isArray(additionalAssets) && additionalAssets.length) {
619
+ // @ts-expect-error TS2345
620
+ assetsToAlsoAccept.push(...additionalAssets);
503
621
  }
504
622
  });
623
+ if (assetsToAlsoAccept.length > 0) {
624
+ let handled = assetsToAlsoAccept.every(function (a) {
625
+ // @ts-expect-error TS2554
626
+ return hmrAcceptCheck(a[0], a[1]);
627
+ });
628
+ if (!handled) {
629
+ return fullReload();
630
+ }
631
+ hmrDisposeQueue();
632
+ }
505
633
  }
506
634
  }
@@ -0,0 +1,3 @@
1
+ import { Runtime } from '@atlaspack/plugin';
2
+ declare const _default: Runtime<unknown>;
3
+ export default _default;
@@ -0,0 +1,2 @@
1
+ export type SetComplement<A, B extends A> = A extends B ? never : A;
2
+ export type Diff<T extends U, U extends object> = Pick<T, SetComplement<keyof T, keyof U>>;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atlaspack/runtime-browser-hmr",
3
- "version": "2.14.5-canary.26+87211c647",
3
+ "version": "2.14.5-canary.261+3af2f4c20",
4
4
  "license": "(MIT OR Apache-2.0)",
5
5
  "publishConfig": {
6
6
  "access": "public"
@@ -9,15 +9,19 @@
9
9
  "type": "git",
10
10
  "url": "https://github.com/atlassian-labs/atlaspack.git"
11
11
  },
12
- "main": "lib/HMRRuntime.js",
13
- "source": "src/HMRRuntime.js",
12
+ "main": "./lib/HMRRuntime.js",
13
+ "source": "./src/HMRRuntime.ts",
14
+ "types": "./lib/types/HMRRuntime.d.ts",
14
15
  "engines": {
15
16
  "node": ">= 16.0.0"
16
17
  },
17
18
  "dependencies": {
18
- "@atlaspack/plugin": "2.14.5-canary.26+87211c647",
19
- "@atlaspack/utils": "2.14.5-canary.26+87211c647"
19
+ "@atlaspack/plugin": "2.14.5-canary.261+3af2f4c20",
20
+ "@atlaspack/utils": "2.14.5-canary.261+3af2f4c20"
20
21
  },
21
22
  "type": "commonjs",
22
- "gitHead": "87211c647df95663b4bca3af09e3b2d84500b8fa"
23
- }
23
+ "scripts": {
24
+ "build:lib": "gulp build --gulpfile ../../../gulpfile.js --cwd ."
25
+ },
26
+ "gitHead": "3af2f4c2059c2d69309e724e0ead99b4345208f4"
27
+ }
@@ -1,5 +1,3 @@
1
- // @flow strict-local
2
-
3
1
  import {Runtime} from '@atlaspack/plugin';
4
2
  import fs from 'fs';
5
3
  import path from 'path';
@@ -8,17 +6,17 @@ import path from 'path';
8
6
  // lives in `/app/packages/runtimes/...` and thus the `config` in the JSTransformer is actually the
9
7
  // user's package.json, and hmr-runtime.js is transpiled as a JSX asset.
10
8
  const FILENAME =
11
- // $FlowFixMe
9
+ // @ts-expect-error TS2339
12
10
  process.env.ATLASPACK_BUILD_REPL && process.browser
13
11
  ? '/' + __filename
14
12
  : __filename;
15
13
 
16
- const HMR_RUNTIME = fs.readFileSync(
17
- path.join(__dirname, './loaders/hmr-runtime.js'),
18
- 'utf8',
19
- );
14
+ const HMR_RUNTIME =
15
+ process.env.ATLASPACK_REGISTER_USE_SRC === 'true'
16
+ ? fs.readFileSync(path.join(__dirname, './loaders/hmr-runtime.ts'), 'utf8')
17
+ : fs.readFileSync(path.join(__dirname, './loaders/hmr-runtime.js'), 'utf8');
20
18
 
21
- export default (new Runtime({
19
+ export default new Runtime({
22
20
  apply({bundle, options}) {
23
21
  if (
24
22
  bundle.type !== 'js' ||
@@ -50,7 +48,7 @@ export default (new Runtime({
50
48
  )};` +
51
49
  `var HMR_ENV_HASH = "${bundle.env.id}";` +
52
50
  `var HMR_USE_SSE = ${JSON.stringify(
53
- // $FlowFixMe
51
+ // @ts-expect-error TS2339
54
52
  !!(process.env.ATLASPACK_BUILD_REPL && process.browser),
55
53
  )};` +
56
54
  `module.bundle.HMR_BUNDLE_ID = ${JSON.stringify(bundle.id)};` +
@@ -61,4 +59,4 @@ export default (new Runtime({
61
59
  },
62
60
  };
63
61
  },
64
- }): Runtime);
62
+ }) as Runtime<unknown>;