@atlaspack/runtime-browser-hmr 2.14.5-canary.49 → 2.14.5-canary.490

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