@atlaspack/runtime-browser-hmr 2.14.21 → 2.14.22-typescript-5ad950d33.0

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,76 @@ 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|} */, disposedAssets /*: {|[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 || (
100
+ // @ts-expect-error TS2304
101
+ location.protocol.indexOf('http') === 0 ? location.hostname : 'localhost')
102
+ );
74
103
  }
75
104
  function getPort() {
105
+ // @ts-expect-error TS2304
76
106
  return HMR_PORT || location.port;
77
107
  }
78
108
 
79
109
  // eslint-disable-next-line no-redeclare
110
+ // @ts-expect-error TS2339
80
111
  var parent = module.bundle.parent;
81
112
  if ((!parent || !parent.isParcelRequire) && typeof WebSocket !== 'undefined') {
82
113
  var hostname = getHostname();
83
114
  var port = getPort();
84
- var protocol = HMR_SECURE || location.protocol == 'https:' && !['localhost', '127.0.0.1', '0.0.0.0'].includes(hostname) ? 'wss' : 'ws';
115
+ var protocol =
116
+ // @ts-expect-error TS2304
117
+ HMR_SECURE ||
118
+ // @ts-expect-error TS2304
119
+ location.protocol == 'https:' && !['localhost', '127.0.0.1', '0.0.0.0'].includes(hostname) ? 'wss' : 'ws';
85
120
  var ws;
121
+ // @ts-expect-error TS2304
86
122
  if (HMR_USE_SSE) {
87
123
  ws = new EventSource('/__parcel_hmr');
88
124
  } else {
@@ -97,7 +133,15 @@ if ((!parent || !parent.isParcelRequire) && typeof WebSocket !== 'undefined') {
97
133
  }
98
134
 
99
135
  // Web extension context
100
- var extCtx = typeof browser === 'undefined' ? typeof chrome === 'undefined' ? null : chrome : browser;
136
+ var extCtx =
137
+ // @ts-expect-error TS2304
138
+ typeof browser === 'undefined' ?
139
+ // @ts-expect-error TS2304
140
+ typeof chrome === 'undefined' ? null :
141
+ // @ts-expect-error TS2304
142
+ chrome :
143
+ // @ts-expect-error TS2304
144
+ browser;
101
145
 
102
146
  // Safari doesn't support sourceURL in error stacks.
103
147
  // eval may also be disabled via CSP, so do a quick check.
@@ -108,8 +152,8 @@ if ((!parent || !parent.isParcelRequire) && typeof WebSocket !== 'undefined') {
108
152
  supportsSourceURL = err.stack.includes('test.js');
109
153
  }
110
154
 
111
- // $FlowFixMe
112
- ws.onmessage = async function (event /*: {data: string, ...} */) {
155
+ // @ts-expect-error TS2339
156
+ ws.onmessage = async function (event) {
113
157
  checkedAssets = {} /*: {|[string]: boolean|} */;
114
158
  disposedAssets = {} /*: {|[string]: boolean|} */;
115
159
  assetsToAccept = [];
@@ -119,20 +163,29 @@ if ((!parent || !parent.isParcelRequire) && typeof WebSocket !== 'undefined') {
119
163
  fullReload();
120
164
  } else if (data.type === 'update') {
121
165
  // Remove error overlay if there is one
166
+ // @ts-expect-error TS2304
122
167
  if (typeof document !== 'undefined') {
123
168
  removeErrorOverlay();
124
169
  }
125
- let assets = data.assets.filter(asset => asset.envHash === HMR_ENV_HASH);
170
+ let assets = data.assets.filter(
171
+ // @ts-expect-error TS7006
172
+ asset => asset.envHash === HMR_ENV_HASH);
126
173
 
127
174
  // Handle HMR Update
175
+ // @ts-expect-error TS7006
128
176
  let handled = assets.every(asset => {
129
- return asset.type === 'css' || asset.type === 'js' && hmrAcceptCheck(module.bundle.root, asset.id, asset.depsByBundle);
177
+ return asset.type === 'css' || asset.type === 'js' &&
178
+ // @ts-expect-error TS2339
179
+ hmrAcceptCheck(module.bundle.root, asset.id, asset.depsByBundle);
130
180
  });
131
181
  if (handled) {
132
182
  console.clear();
133
183
 
134
184
  // Dispatch custom event so other runtimes (e.g React Refresh) are aware.
135
- if (typeof window !== 'undefined' && typeof CustomEvent !== 'undefined') {
185
+ if (
186
+ // @ts-expect-error TS2304
187
+ typeof window !== 'undefined' && typeof CustomEvent !== 'undefined') {
188
+ // @ts-expect-error TS2304
136
189
  window.dispatchEvent(new CustomEvent('parcelhmraccept'));
137
190
  }
138
191
  await hmrApplyUpdates(assets);
@@ -141,8 +194,10 @@ if ((!parent || !parent.isParcelRequire) && typeof WebSocket !== 'undefined') {
141
194
  // Run accept callbacks. This will also re-execute other disposed assets in topological order.
142
195
  let processedAssets = {};
143
196
  for (let i = 0; i < assetsToAccept.length; i++) {
197
+ // @ts-expect-error TS7005
144
198
  let id = assetsToAccept[i][1];
145
199
  if (!processedAssets[id]) {
200
+ // @ts-expect-error TS7005
146
201
  hmrAccept(assetsToAccept[i][0], id);
147
202
  processedAssets[id] = true;
148
203
  }
@@ -155,11 +210,13 @@ if ((!parent || !parent.isParcelRequire) && typeof WebSocket !== 'undefined') {
155
210
  let stack = ansiDiagnostic.codeframe ? ansiDiagnostic.codeframe : ansiDiagnostic.stack;
156
211
  console.error('🚨 [parcel]: ' + ansiDiagnostic.message + '\n' + stack + '\n\n' + ansiDiagnostic.hints.join('\n'));
157
212
  }
213
+
214
+ // @ts-expect-error TS2304
158
215
  if (typeof document !== 'undefined') {
159
216
  // Render the fancy html overlay
160
217
  removeErrorOverlay();
161
218
  var overlay = createErrorOverlay(data.diagnostics.html);
162
- // $FlowFixMe
219
+ // @ts-expect-error TS2304
163
220
  document.body.appendChild(overlay);
164
221
  }
165
222
  }
@@ -178,6 +235,7 @@ if ((!parent || !parent.isParcelRequire) && typeof WebSocket !== 'undefined') {
178
235
  }
179
236
  }
180
237
  function removeErrorOverlay() {
238
+ // @ts-expect-error TS2304
181
239
  var overlay = document.getElementById(OVERLAY_ID);
182
240
  if (overlay) {
183
241
  overlay.remove();
@@ -185,11 +243,14 @@ function removeErrorOverlay() {
185
243
  }
186
244
  }
187
245
  function createErrorOverlay(diagnostics) {
246
+ // @ts-expect-error TS2304
188
247
  var overlay = document.createElement('div');
189
248
  overlay.id = OVERLAY_ID;
190
249
  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;">';
191
250
  for (let diagnostic of diagnostics) {
192
- let stack = diagnostic.frames.length ? diagnostic.frames.reduce((p, frame) => {
251
+ let stack = diagnostic.frames.length ?
252
+ // @ts-expect-error TS7006
253
+ diagnostic.frames.reduce((p, frame) => {
193
254
  return `${p}
194
255
  <a href="/__parcel_launch_editor?file=${encodeURIComponent(frame.location)}" style="text-decoration: underline; color: #888" onclick="fetch(this.href); return false">${frame.location}</a>
195
256
  ${frame.code}`;
@@ -201,7 +262,9 @@ ${frame.code}`;
201
262
  </div>
202
263
  <pre>${stack}</pre>
203
264
  <div>
204
- ${diagnostic.hints.map(hint => '<div>💡 ' + hint + '</div>').join('')}
265
+ ${diagnostic.hints
266
+ // @ts-expect-error TS7006
267
+ .map(hint => '<div>💡 ' + hint + '</div>').join('')}
205
268
  </div>
206
269
  ${diagnostic.documentation ? `<div>📝 <a style="color: violet" href="${diagnostic.documentation}" target="_blank">Learn more</a></div>` : ''}
207
270
  </div>
@@ -212,17 +275,23 @@ ${frame.code}`;
212
275
  return overlay;
213
276
  }
214
277
  function fullReload() {
278
+ // @ts-expect-error TS2304
215
279
  if ('reload' in location) {
280
+ // @ts-expect-error TS2304
216
281
  location.reload();
217
282
  } else if (extCtx && extCtx.runtime && extCtx.runtime.reload) {
218
283
  extCtx.runtime.reload();
219
284
  }
220
285
  }
221
- function getParents(bundle, id) /*: Array<[ParcelRequire, string]> */{
286
+ function getParents(
287
+ // @ts-expect-error TS2304
288
+ bundle, id) /*: Array<[ParcelRequire, string]> */{
222
289
  var modules = bundle.modules;
223
290
  if (!modules) {
224
291
  return [];
225
292
  }
293
+
294
+ // @ts-expect-error TS2304
226
295
  var parents = [];
227
296
  var k, d, dep;
228
297
  for (k in modules) {
@@ -239,36 +308,43 @@ function getParents(bundle, id) /*: Array<[ParcelRequire, string]> */{
239
308
  return parents;
240
309
  }
241
310
  function updateLink(link) {
311
+ // @ts-expect-error TS2339
242
312
  var href = link.getAttribute('href');
243
313
  if (!href) {
244
314
  return;
245
315
  }
316
+ // @ts-expect-error TS2339
246
317
  var newLink = link.cloneNode();
247
318
  newLink.onload = function () {
319
+ // @ts-expect-error TS2339
248
320
  if (link.parentNode !== null) {
249
- // $FlowFixMe
321
+ // @ts-expect-error TS2339
250
322
  link.parentNode.removeChild(link);
251
323
  }
252
324
  };
253
- newLink.setAttribute('href',
254
- // $FlowFixMe
255
- href.split('?')[0] + '?' + Date.now());
256
- // $FlowFixMe
325
+ newLink.setAttribute('href', href.split('?')[0] + '?' + Date.now());
326
+ // @ts-expect-error TS18047
257
327
  link.parentNode.insertBefore(newLink, link.nextSibling);
258
328
  }
329
+
330
+ // @ts-expect-error TS7034
259
331
  var cssTimeout = null;
260
332
  function reloadCSS() {
333
+ // @ts-expect-error TS7005
261
334
  if (cssTimeout) {
262
335
  return;
263
336
  }
264
337
  cssTimeout = setTimeout(function () {
338
+ // @ts-expect-error TS18047
339
+ var document = window.document;
265
340
  var links = document.querySelectorAll('link[rel="stylesheet"]');
266
341
  for (var i = 0; i < links.length; i++) {
267
- // $FlowFixMe[incompatible-type]
268
342
  var href /*: string */ = links[i].getAttribute('href');
269
343
  var hostname = getHostname();
270
344
  var servedFromHMRServer = hostname === 'localhost' ? new RegExp('^(https?:\\/\\/(0.0.0.0|127.0.0.1)|localhost):' + getPort()).test(href) : href.indexOf(hostname + ':' + getPort());
271
- var absolute = /^https?:\/\//i.test(href) && href.indexOf(location.origin) !== 0 && !servedFromHMRServer;
345
+ var absolute = /^https?:\/\//i.test(href) &&
346
+ // @ts-expect-error TS18047
347
+ href.indexOf(location.origin) !== 0 && !servedFromHMRServer;
272
348
  if (!absolute) {
273
349
  updateLink(links[i]);
274
350
  }
@@ -276,9 +352,13 @@ function reloadCSS() {
276
352
  cssTimeout = null;
277
353
  }, 50);
278
354
  }
355
+
356
+ // @ts-expect-error TS2304
279
357
  function hmrDownload(asset) {
280
358
  if (asset.type === 'js') {
359
+ // @ts-expect-error TS18047
281
360
  if (typeof document !== 'undefined') {
361
+ // @ts-expect-error TS18047
282
362
  let script = document.createElement('script');
283
363
  script.src = asset.url + '?t=' + Date.now();
284
364
  if (asset.outputFormat === 'esmodule') {
@@ -288,16 +368,21 @@ function hmrDownload(asset) {
288
368
  var _document$head;
289
369
  script.onload = () => resolve(script);
290
370
  script.onerror = reject;
371
+ // @ts-expect-error TS18047
291
372
  (_document$head = document.head) === null || _document$head === void 0 || _document$head.appendChild(script);
292
373
  });
374
+ // @ts-expect-error TS2304
293
375
  } else if (typeof importScripts === 'function') {
294
376
  // Worker scripts
295
377
  if (asset.outputFormat === 'esmodule') {
378
+ // @ts-expect-error TS2304
296
379
  return __parcel__import__(asset.url + '?t=' + Date.now());
297
380
  } else {
298
381
  return new Promise((resolve, reject) => {
299
382
  try {
383
+ // @ts-expect-error TS2304
300
384
  __parcel__importScripts__(asset.url + '?t=' + Date.now());
385
+ // @ts-expect-error TS2794
301
386
  resolve();
302
387
  } catch (err) {
303
388
  reject(err);
@@ -307,7 +392,10 @@ function hmrDownload(asset) {
307
392
  }
308
393
  }
309
394
  }
395
+
396
+ // @ts-expect-error TS2304
310
397
  async function hmrApplyUpdates(assets) {
398
+ // @ts-expect-error TS7017
311
399
  global.parcelHotUpdate = Object.create(null);
312
400
  let scriptsToRemove;
313
401
  try {
@@ -322,7 +410,11 @@ async function hmrApplyUpdates(assets) {
322
410
  var _hmrDownload;
323
411
  return (_hmrDownload = hmrDownload(asset)) === null || _hmrDownload === void 0 ? void 0 : _hmrDownload.catch(err => {
324
412
  // Web extension fix
325
- if (extCtx && extCtx.runtime && extCtx.runtime.getManifest().manifest_version == 3 && typeof ServiceWorkerGlobalScope != 'undefined' && global instanceof ServiceWorkerGlobalScope) {
413
+ if (extCtx && extCtx.runtime && extCtx.runtime.getManifest().manifest_version == 3 &&
414
+ // @ts-expect-error TS2304
415
+ typeof ServiceWorkerGlobalScope != 'undefined' &&
416
+ // @ts-expect-error TS2304
417
+ global instanceof ServiceWorkerGlobalScope) {
326
418
  extCtx.runtime.reload();
327
419
  return;
328
420
  }
@@ -332,21 +424,29 @@ async function hmrApplyUpdates(assets) {
332
424
  scriptsToRemove = await Promise.all(promises);
333
425
  }
334
426
  assets.forEach(function (asset) {
427
+ // @ts-expect-error TS2339
335
428
  hmrApply(module.bundle.root, asset);
336
429
  });
337
430
  } finally {
431
+ // @ts-expect-error TS7017
338
432
  delete global.parcelHotUpdate;
339
433
  if (scriptsToRemove) {
434
+ // @ts-expect-error TS7006
340
435
  scriptsToRemove.forEach(script => {
341
436
  if (script) {
342
437
  var _document$head2;
438
+ // @ts-expect-error TS18047
343
439
  (_document$head2 = document.head) === null || _document$head2 === void 0 || _document$head2.removeChild(script);
344
440
  }
345
441
  });
346
442
  }
347
443
  }
348
444
  }
349
- function hmrApply(bundle /*: ParcelRequire */, asset /*: HMRAsset */) {
445
+ function hmrApply(
446
+ // @ts-expect-error TS2304
447
+ bundle,
448
+ // @ts-expect-error TS2304
449
+ asset) {
350
450
  var modules = bundle.modules;
351
451
  if (!modules) {
352
452
  return;
@@ -363,8 +463,10 @@ function hmrApply(bundle /*: ParcelRequire */, asset /*: HMRAsset */) {
363
463
  for (let dep in oldDeps) {
364
464
  if (!deps[dep] || deps[dep] !== oldDeps[dep]) {
365
465
  let id = oldDeps[dep];
466
+ // @ts-expect-error TS2339
366
467
  let parents = getParents(module.bundle.root, id);
367
468
  if (parents.length === 1) {
469
+ // @ts-expect-error TS2339
368
470
  hmrDelete(module.bundle.root, id);
369
471
  }
370
472
  }
@@ -376,7 +478,7 @@ function hmrApply(bundle /*: ParcelRequire */, asset /*: HMRAsset */) {
376
478
  (0, eval)(asset.output);
377
479
  }
378
480
 
379
- // $FlowFixMe
481
+ // @ts-expect-error TS7017
380
482
  let fn = global.parcelHotUpdate[asset.id];
381
483
  modules[asset.id] = [fn, deps];
382
484
  }
@@ -388,6 +490,8 @@ function hmrApply(bundle /*: ParcelRequire */, asset /*: HMRAsset */) {
388
490
  }
389
491
  }
390
492
  }
493
+
494
+ // @ts-expect-error TS2304
391
495
  function hmrDelete(bundle, id) {
392
496
  let modules = bundle.modules;
393
497
  if (!modules) {
@@ -398,6 +502,7 @@ function hmrDelete(bundle, id) {
398
502
  let deps = modules[id][1];
399
503
  let orphans = [];
400
504
  for (let dep in deps) {
505
+ // @ts-expect-error TS2339
401
506
  let parents = getParents(module.bundle.root, deps[dep]);
402
507
  if (parents.length === 1) {
403
508
  orphans.push(deps[dep]);
@@ -410,28 +515,34 @@ function hmrDelete(bundle, id) {
410
515
 
411
516
  // Now delete the orphans.
412
517
  orphans.forEach(id => {
518
+ // @ts-expect-error TS2339
413
519
  hmrDelete(module.bundle.root, id);
414
520
  });
415
521
  } else if (bundle.parent) {
416
522
  hmrDelete(bundle.parent, id);
417
523
  }
418
524
  }
419
- function hmrAcceptCheck(bundle /*: ParcelRequire */, id /*: string */, depsByBundle /*: ?{ [string]: { [string]: string } }*/) {
525
+ function hmrAcceptCheck(
526
+ // @ts-expect-error TS2304
527
+ bundle, id, depsByBundle) {
420
528
  if (hmrAcceptCheckOne(bundle, id, depsByBundle)) {
421
529
  return true;
422
530
  }
423
531
 
424
532
  // Traverse parents breadth first. All possible ancestries must accept the HMR update, or we'll reload.
533
+ // @ts-expect-error TS2339
425
534
  let parents = getParents(module.bundle.root, id);
426
535
  let accepted = false;
427
536
  while (parents.length > 0) {
428
537
  let v = parents.shift();
538
+ // @ts-expect-error TS18048
429
539
  let a = hmrAcceptCheckOne(v[0], v[1], null);
430
540
  if (a) {
431
541
  // If this parent accepts, stop traversing upward, but still consider siblings.
432
542
  accepted = true;
433
543
  } else {
434
544
  // Otherwise, queue the parents in the next level upward.
545
+ // @ts-expect-error TS2339
435
546
  let p = getParents(module.bundle.root, v[1]);
436
547
  if (p.length === 0) {
437
548
  // If there are no parents, then we've reached an entry without accepting. Reload.
@@ -443,7 +554,9 @@ function hmrAcceptCheck(bundle /*: ParcelRequire */, id /*: string */, depsByBun
443
554
  }
444
555
  return accepted;
445
556
  }
446
- function hmrAcceptCheckOne(bundle /*: ParcelRequire */, id /*: string */, depsByBundle /*: ?{ [string]: { [string]: string } }*/) {
557
+ function hmrAcceptCheckOne(
558
+ // @ts-expect-error TS2304
559
+ bundle, id, depsByBundle) {
447
560
  var modules = bundle.modules;
448
561
  if (!modules) {
449
562
  return;
@@ -456,9 +569,13 @@ function hmrAcceptCheckOne(bundle /*: ParcelRequire */, id /*: string */, depsBy
456
569
  }
457
570
  return hmrAcceptCheck(bundle.parent, id, depsByBundle);
458
571
  }
572
+
573
+ // @ts-expect-error TS7005
459
574
  if (checkedAssets[id]) {
460
575
  return true;
461
576
  }
577
+
578
+ // @ts-expect-error TS7005
462
579
  checkedAssets[id] = true;
463
580
  var cached = bundle.cache[id];
464
581
  assetsToDispose.push([bundle, id]);
@@ -470,28 +587,37 @@ function hmrAcceptCheckOne(bundle /*: ParcelRequire */, id /*: string */, depsBy
470
587
  function hmrDisposeQueue() {
471
588
  // Dispose all old assets.
472
589
  for (let i = 0; i < assetsToDispose.length; i++) {
590
+ // @ts-expect-error TS7005
473
591
  let id = assetsToDispose[i][1];
592
+
593
+ // @ts-expect-error TS7005
474
594
  if (!disposedAssets[id]) {
595
+ // @ts-expect-error TS7005
475
596
  hmrDispose(assetsToDispose[i][0], id);
476
597
  disposedAssets[id] = true;
477
598
  }
478
599
  }
479
600
  assetsToDispose = [];
480
601
  }
481
- function hmrDispose(bundle /*: ParcelRequire */, id /*: string */) {
602
+ function hmrDispose(
603
+ // @ts-expect-error TS2304
604
+ bundle, id) {
482
605
  var cached = bundle.cache[id];
483
606
  bundle.hotData[id] = {};
484
607
  if (cached && cached.hot) {
485
608
  cached.hot.data = bundle.hotData[id];
486
609
  }
487
610
  if (cached && cached.hot && cached.hot._disposeCallbacks.length) {
611
+ // @ts-expect-error TS7006
488
612
  cached.hot._disposeCallbacks.forEach(function (cb) {
489
613
  cb(bundle.hotData[id]);
490
614
  });
491
615
  }
492
616
  delete bundle.cache[id];
493
617
  }
494
- function hmrAccept(bundle /*: ParcelRequire */, id /*: string */) {
618
+ function hmrAccept(
619
+ // @ts-expect-error TS2304
620
+ bundle, id) {
495
621
  // Execute the module.
496
622
  bundle(id);
497
623
 
@@ -499,16 +625,20 @@ function hmrAccept(bundle /*: ParcelRequire */, id /*: string */) {
499
625
  var cached = bundle.cache[id];
500
626
  if (cached && cached.hot && cached.hot._acceptCallbacks.length) {
501
627
  let assetsToAlsoAccept = [];
628
+ // @ts-expect-error TS7006
502
629
  cached.hot._acceptCallbacks.forEach(function (cb) {
503
630
  let additionalAssets = cb(function () {
631
+ // @ts-expect-error TS2339
504
632
  return getParents(module.bundle.root, id);
505
633
  });
506
634
  if (Array.isArray(additionalAssets) && additionalAssets.length) {
635
+ // @ts-expect-error TS2345
507
636
  assetsToAlsoAccept.push(...additionalAssets);
508
637
  }
509
638
  });
510
639
  if (assetsToAlsoAccept.length > 0) {
511
640
  let handled = assetsToAlsoAccept.every(function (a) {
641
+ // @ts-expect-error TS2554
512
642
  return hmrAcceptCheck(a[0], a[1]);
513
643
  });
514
644
  if (!handled) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atlaspack/runtime-browser-hmr",
3
- "version": "2.14.21",
3
+ "version": "2.14.22-typescript-5ad950d33.0",
4
4
  "license": "(MIT OR Apache-2.0)",
5
5
  "publishConfig": {
6
6
  "access": "public"
@@ -9,14 +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/HMRRuntime.d.ts",
14
15
  "engines": {
15
16
  "node": ">= 16.0.0"
16
17
  },
17
18
  "dependencies": {
18
- "@atlaspack/plugin": "2.14.21",
19
- "@atlaspack/utils": "2.17.3"
19
+ "@atlaspack/plugin": "2.14.22-typescript-5ad950d33.0",
20
+ "@atlaspack/utils": "2.17.4-typescript-5ad950d33.0"
20
21
  },
21
- "type": "commonjs"
22
- }
22
+ "type": "commonjs",
23
+ "scripts": {
24
+ "check-ts": "tsc --emitDeclarationOnly --rootDir src"
25
+ },
26
+ "gitHead": "5ad950d33a5f2255ebeb10c04a2e84c346e2de85"
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<mixed>);
62
+ }) as Runtime<unknown>;