@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.
@@ -0,0 +1,616 @@
1
+ "use strict";
2
+ /* global HMR_HOST, HMR_PORT, HMR_ENV_HASH, HMR_SECURE, HMR_USE_SSE, chrome, browser, __parcel__import__, __parcel__importScripts__, ServiceWorkerGlobalScope, HMR_ENABLE_BUNDLE_VERSION */
3
+ Object.defineProperty(exports, "__esModule", { value: true });
4
+ // /flow-to-ts helpers
5
+ var OVERLAY_ID = '__parcel__error__overlay__';
6
+ var HMR_BUNDLE_VERSION = '__parcel__hmrBundleVersion';
7
+ // @ts-expect-error TS2339
8
+ var OldModule = module.bundle.Module;
9
+ function Module(moduleName) {
10
+ // @ts-expect-error TS2683
11
+ OldModule.call(this, moduleName);
12
+ // @ts-expect-error TS2683
13
+ this.hot = {
14
+ // @ts-expect-error TS2339
15
+ data: module.bundle.hotData[moduleName],
16
+ _acceptCallbacks: [],
17
+ _disposeCallbacks: [],
18
+ // @ts-expect-error TS7006
19
+ accept: function (fn) {
20
+ this._acceptCallbacks.push(fn || function () { });
21
+ },
22
+ // @ts-expect-error TS7006
23
+ dispose: function (fn) {
24
+ this._disposeCallbacks.push(fn);
25
+ },
26
+ };
27
+ // @ts-expect-error TS2339
28
+ module.bundle.hotData[moduleName] = undefined;
29
+ }
30
+ // @ts-expect-error TS2339
31
+ module.bundle.Module = Module;
32
+ // @ts-expect-error TS2339
33
+ module.bundle.hotData = {};
34
+ // @ts-expect-error TS7034
35
+ var checkedAssets /*: {|[string]: boolean|} */,
36
+ // @ts-expect-error TS7034
37
+ disposedAssets /*: {|[string]: boolean|} */,
38
+ // @ts-expect-error TS7034
39
+ assetsToDispose /*: Array<[ParcelRequire, string]> */,
40
+ // @ts-expect-error TS7034
41
+ assetsToAccept /*: Array<[ParcelRequire, string]> */;
42
+ function getBundleVersion() {
43
+ // @ts-expect-error TS7017
44
+ return globalThis[HMR_BUNDLE_VERSION];
45
+ }
46
+ function bumpBundleVersion() {
47
+ // @ts-expect-error TS2304
48
+ if (!HMR_ENABLE_BUNDLE_VERSION) {
49
+ return;
50
+ }
51
+ let version = getBundleVersion();
52
+ let nextVersion = typeof version === 'number' && Number.isFinite(version) ? version + 1 : 1;
53
+ // @ts-expect-error TS7017
54
+ globalThis[HMR_BUNDLE_VERSION] = nextVersion;
55
+ return nextVersion;
56
+ }
57
+ function appendBundleVersion(url) {
58
+ // @ts-expect-error TS2304
59
+ if (!HMR_ENABLE_BUNDLE_VERSION) {
60
+ return url + (url.includes('?') ? '&' : '?') + 't=' + Date.now();
61
+ }
62
+ let version = getBundleVersion();
63
+ if (version == null) {
64
+ return url;
65
+ }
66
+ return url + (url.includes('?') ? '&' : '?') + 't=' + version;
67
+ }
68
+ function getHostname() {
69
+ return (
70
+ // @ts-expect-error TS2304
71
+ HMR_HOST ||
72
+ (location.protocol.indexOf('http') === 0 ? location.hostname : 'localhost'));
73
+ }
74
+ function getPort() {
75
+ // @ts-expect-error TS2304
76
+ return HMR_PORT || location.port;
77
+ }
78
+ // eslint-disable-next-line no-redeclare
79
+ // @ts-expect-error TS2339
80
+ var parent = module.bundle.parent;
81
+ if ((!parent || !parent.isParcelRequire) && typeof WebSocket !== 'undefined') {
82
+ var hostname = getHostname();
83
+ var port = getPort();
84
+ var protocol =
85
+ // @ts-expect-error TS2304
86
+ HMR_SECURE ||
87
+ (location.protocol == 'https:' &&
88
+ !['localhost', '127.0.0.1', '0.0.0.0'].includes(hostname))
89
+ ? 'wss'
90
+ : 'ws';
91
+ var ws;
92
+ // @ts-expect-error TS2304
93
+ if (HMR_USE_SSE) {
94
+ ws = new EventSource('/__parcel_hmr');
95
+ }
96
+ else {
97
+ try {
98
+ ws = new WebSocket(protocol + '://' + hostname + (port ? ':' + port : '') + '/');
99
+ }
100
+ catch (err) {
101
+ if (err.message) {
102
+ console.error(err.message);
103
+ }
104
+ ws = {};
105
+ }
106
+ }
107
+ // Web extension context
108
+ var extCtx =
109
+ // @ts-expect-error TS2304
110
+ typeof browser === 'undefined'
111
+ ? // @ts-expect-error TS2304
112
+ typeof chrome === 'undefined'
113
+ ? null
114
+ : // @ts-expect-error TS2304
115
+ chrome
116
+ : // @ts-expect-error TS2304
117
+ browser;
118
+ // Safari doesn't support sourceURL in error stacks.
119
+ // eval may also be disabled via CSP, so do a quick check.
120
+ var supportsSourceURL = false;
121
+ try {
122
+ (0, eval)('throw new Error("test"); //# sourceURL=test.js');
123
+ }
124
+ catch (err) {
125
+ supportsSourceURL = err.stack.includes('test.js');
126
+ }
127
+ // @ts-expect-error TS2339
128
+ ws.onmessage = async function (event /*: {data: string, ...} */) {
129
+ checkedAssets = {} /*: {|[string]: boolean|} */;
130
+ disposedAssets = {} /*: {|[string]: boolean|} */;
131
+ assetsToAccept = [];
132
+ assetsToDispose = [];
133
+ var data /*: HMRMessage */ = JSON.parse(event.data);
134
+ if (data.type === 'reload') {
135
+ fullReload();
136
+ }
137
+ else if (data.type === 'update') {
138
+ // Remove error overlay if there is one
139
+ if (typeof document !== 'undefined') {
140
+ removeErrorOverlay();
141
+ }
142
+ let assets = data.assets.filter(
143
+ // @ts-expect-error TS7006
144
+ (asset) => asset.envHash === HMR_ENV_HASH);
145
+ // Handle HMR Update
146
+ // @ts-expect-error TS7006
147
+ let handled = assets.every((asset) => {
148
+ return (asset.type === 'css' ||
149
+ (asset.type === 'js' &&
150
+ // @ts-expect-error TS2339
151
+ hmrAcceptCheck(module.bundle.root, asset.id, asset.depsByBundle)));
152
+ });
153
+ if (handled) {
154
+ bumpBundleVersion();
155
+ console.clear();
156
+ // Dispatch custom event so other runtimes (e.g React Refresh) are aware.
157
+ if (typeof window !== 'undefined' &&
158
+ typeof CustomEvent !== 'undefined') {
159
+ window.dispatchEvent(new CustomEvent('parcelhmraccept'));
160
+ }
161
+ await hmrApplyUpdates(assets);
162
+ hmrDisposeQueue();
163
+ // Run accept callbacks. This will also re-execute other disposed assets in topological order.
164
+ let processedAssets = {};
165
+ for (let i = 0; i < assetsToAccept.length; i++) {
166
+ // @ts-expect-error TS7005
167
+ let id = assetsToAccept[i][1];
168
+ if (!processedAssets[id]) {
169
+ // @ts-expect-error TS7005
170
+ hmrAccept(assetsToAccept[i][0], id);
171
+ processedAssets[id] = true;
172
+ }
173
+ }
174
+ }
175
+ else
176
+ fullReload();
177
+ }
178
+ if (data.type === 'error') {
179
+ // Log parcel errors to console
180
+ for (let ansiDiagnostic of data.diagnostics.ansi) {
181
+ let stack = ansiDiagnostic.codeframe
182
+ ? ansiDiagnostic.codeframe
183
+ : ansiDiagnostic.stack;
184
+ console.error('🚨 [parcel]: ' +
185
+ ansiDiagnostic.message +
186
+ '\n' +
187
+ stack +
188
+ '\n\n' +
189
+ ansiDiagnostic.hints.join('\n'));
190
+ }
191
+ if (typeof document !== 'undefined') {
192
+ // Render the fancy html overlay
193
+ removeErrorOverlay();
194
+ var overlay = createErrorOverlay(data.diagnostics.html);
195
+ document.body.appendChild(overlay);
196
+ }
197
+ }
198
+ };
199
+ if (ws instanceof WebSocket) {
200
+ ws.onerror = function (e) {
201
+ if (e.message) {
202
+ console.error(e.message);
203
+ }
204
+ };
205
+ ws.onclose = function (e) {
206
+ if (process.env.ATLASPACK_BUILD_ENV !== 'test') {
207
+ console.warn('[parcel] 🚨 Connection to the HMR server was lost');
208
+ }
209
+ };
210
+ }
211
+ }
212
+ function removeErrorOverlay() {
213
+ var overlay = document.getElementById(OVERLAY_ID);
214
+ if (overlay) {
215
+ overlay.remove();
216
+ console.log('[parcel] ✨ Error resolved');
217
+ }
218
+ }
219
+ function createErrorOverlay(diagnostics) {
220
+ var overlay = document.createElement('div');
221
+ overlay.id = OVERLAY_ID;
222
+ 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;">';
223
+ for (let diagnostic of diagnostics) {
224
+ let stack = diagnostic.frames.length
225
+ ? // @ts-expect-error TS7006
226
+ diagnostic.frames.reduce((p, frame) => {
227
+ return `${p}
228
+ <a href="/__parcel_launch_editor?file=${encodeURIComponent(frame.location)}" style="text-decoration: underline; color: #888" onclick="fetch(this.href); return false">${frame.location}</a>
229
+ ${frame.code}`;
230
+ }, '')
231
+ : diagnostic.stack;
232
+ errorHTML += `
233
+ <div>
234
+ <div style="font-size: 18px; font-weight: bold; margin-top: 20px;">
235
+ 🚨 ${diagnostic.message}
236
+ </div>
237
+ <pre>${stack}</pre>
238
+ <div>
239
+ ${diagnostic.hints
240
+ // @ts-expect-error TS7006
241
+ .map((hint) => '<div>💡 ' + hint + '</div>')
242
+ .join('')}
243
+ </div>
244
+ ${diagnostic.documentation
245
+ ? `<div>📝 <a style="color: violet" href="${diagnostic.documentation}" target="_blank">Learn more</a></div>`
246
+ : ''}
247
+ </div>
248
+ `;
249
+ }
250
+ errorHTML += '</div>';
251
+ overlay.innerHTML = errorHTML;
252
+ return overlay;
253
+ }
254
+ function fullReload() {
255
+ if ('reload' in location) {
256
+ location.reload();
257
+ }
258
+ else if (extCtx && extCtx.runtime && extCtx.runtime.reload) {
259
+ extCtx.runtime.reload();
260
+ }
261
+ }
262
+ function getParents(
263
+ // @ts-expect-error TS2304
264
+ bundle, id) {
265
+ var modules = bundle.modules;
266
+ if (!modules) {
267
+ return [];
268
+ }
269
+ // @ts-expect-error TS2304
270
+ var parents = [];
271
+ var k, d, dep;
272
+ for (k in modules) {
273
+ for (d in modules[k][1]) {
274
+ dep = modules[k][1][d];
275
+ if (dep === id || (Array.isArray(dep) && dep[dep.length - 1] === id)) {
276
+ parents.push([bundle, k]);
277
+ }
278
+ }
279
+ }
280
+ if (bundle.parent) {
281
+ parents = parents.concat(getParents(bundle.parent, id));
282
+ }
283
+ return parents;
284
+ }
285
+ function updateLink(link) {
286
+ var href = link.getAttribute('href');
287
+ if (!href) {
288
+ return;
289
+ }
290
+ var newLink = link.cloneNode();
291
+ // @ts-expect-error TS2345
292
+ newLink.onload = function () {
293
+ if (link.parentNode !== null) {
294
+ link.parentNode.removeChild(link);
295
+ }
296
+ };
297
+ // @ts-expect-error TS2339
298
+ newLink.setAttribute('href', appendBundleVersion(href));
299
+ // @ts-expect-error TS18047
300
+ link.parentNode.insertBefore(newLink, link.nextSibling);
301
+ }
302
+ // @ts-expect-error TS7034
303
+ var cssTimeout = null;
304
+ function reloadCSS() {
305
+ // @ts-expect-error TS7005
306
+ if (cssTimeout) {
307
+ return;
308
+ }
309
+ cssTimeout = setTimeout(function () {
310
+ var document = window.document;
311
+ var links = document.querySelectorAll('link[rel="stylesheet"]');
312
+ for (var i = 0; i < links.length; i++) {
313
+ var href /*: string */ = links[i].getAttribute('href');
314
+ var hostname = getHostname();
315
+ var servedFromHMRServer = hostname === 'localhost'
316
+ ? new RegExp('^(https?:\\/\\/(0.0.0.0|127.0.0.1)|localhost):' + getPort()).test(href)
317
+ : // @ts-expect-error TS2345
318
+ href.indexOf(hostname + ':' + getPort());
319
+ var absolute =
320
+ // @ts-expect-error TS2345
321
+ /^https?:\/\//i.test(href) &&
322
+ // @ts-expect-error TS18047
323
+ href.indexOf(location.origin) !== 0 &&
324
+ !servedFromHMRServer;
325
+ if (!absolute) {
326
+ // @ts-expect-error TS2345
327
+ updateLink(links[i]);
328
+ }
329
+ }
330
+ cssTimeout = null;
331
+ }, 50);
332
+ }
333
+ // @ts-expect-error TS2304
334
+ function hmrDownload(asset) {
335
+ if (asset.type === 'js') {
336
+ if (typeof document !== 'undefined') {
337
+ let script = document.createElement('script');
338
+ script.src = appendBundleVersion(asset.url);
339
+ if (asset.outputFormat === 'esmodule') {
340
+ script.type = 'module';
341
+ }
342
+ return new Promise((resolve, reject) => {
343
+ script.onload = () => resolve(script);
344
+ script.onerror = reject;
345
+ document.head?.appendChild(script);
346
+ });
347
+ // @ts-expect-error TS2304
348
+ }
349
+ else if (typeof importScripts === 'function') {
350
+ // Worker scripts
351
+ if (asset.outputFormat === 'esmodule') {
352
+ // @ts-expect-error TS2304
353
+ return __parcel__import__(appendBundleVersion(asset.url));
354
+ }
355
+ else {
356
+ return new Promise((resolve, reject) => {
357
+ try {
358
+ // @ts-expect-error TS2304
359
+ __parcel__importScripts__(appendBundleVersion(asset.url));
360
+ // @ts-expect-error TS2794
361
+ resolve();
362
+ }
363
+ catch (err) {
364
+ reject(err);
365
+ }
366
+ });
367
+ }
368
+ }
369
+ }
370
+ }
371
+ // @ts-expect-error TS2304
372
+ async function hmrApplyUpdates(assets) {
373
+ // @ts-expect-error TS7017
374
+ global.parcelHotUpdate = Object.create(null);
375
+ let scriptsToRemove;
376
+ try {
377
+ // If sourceURL comments aren't supported in eval, we need to load
378
+ // the update from the dev server over HTTP so that stack traces
379
+ // are correct in errors/logs. This is much slower than eval, so
380
+ // we only do it if needed (currently just Safari).
381
+ // https://bugs.webkit.org/show_bug.cgi?id=137297
382
+ // This path is also taken if a CSP disallows eval.
383
+ if (!supportsSourceURL) {
384
+ let promises = assets.map((asset) => hmrDownload(asset)?.catch((err) => {
385
+ // Web extension fix
386
+ if (extCtx &&
387
+ extCtx.runtime &&
388
+ extCtx.runtime.getManifest().manifest_version == 3 &&
389
+ // @ts-expect-error TS2304
390
+ typeof ServiceWorkerGlobalScope != 'undefined' &&
391
+ // @ts-expect-error TS2304
392
+ global instanceof ServiceWorkerGlobalScope) {
393
+ extCtx.runtime.reload();
394
+ return;
395
+ }
396
+ throw err;
397
+ }));
398
+ scriptsToRemove = await Promise.all(promises);
399
+ }
400
+ assets.forEach(function (asset) {
401
+ // @ts-expect-error TS2339
402
+ hmrApply(module.bundle.root, asset);
403
+ });
404
+ }
405
+ finally {
406
+ // @ts-expect-error TS7017
407
+ delete global.parcelHotUpdate;
408
+ if (scriptsToRemove) {
409
+ // @ts-expect-error TS7006
410
+ scriptsToRemove.forEach((script) => {
411
+ if (script) {
412
+ document.head?.removeChild(script);
413
+ }
414
+ });
415
+ }
416
+ }
417
+ }
418
+ function hmrApply(
419
+ // @ts-expect-error TS2304
420
+ bundle /*: ParcelRequire */,
421
+ // @ts-expect-error TS2304
422
+ asset /*: HMRAsset */) {
423
+ var modules = bundle.modules;
424
+ if (!modules) {
425
+ return;
426
+ }
427
+ if (asset.type === 'css') {
428
+ reloadCSS();
429
+ }
430
+ else if (asset.type === 'js') {
431
+ let deps = asset.depsByBundle[bundle.HMR_BUNDLE_ID];
432
+ if (deps) {
433
+ if (modules[asset.id]) {
434
+ // Remove dependencies that are removed and will become orphaned.
435
+ // This is necessary so that if the asset is added back again, the cache is gone, and we prevent a full page reload.
436
+ let oldDeps = modules[asset.id][1];
437
+ for (let dep in oldDeps) {
438
+ if (!deps[dep] || deps[dep] !== oldDeps[dep]) {
439
+ let id = oldDeps[dep];
440
+ // @ts-expect-error TS2339
441
+ let parents = getParents(module.bundle.root, id);
442
+ if (parents.length === 1) {
443
+ // @ts-expect-error TS2339
444
+ hmrDelete(module.bundle.root, id);
445
+ }
446
+ }
447
+ }
448
+ }
449
+ if (supportsSourceURL) {
450
+ // Global eval. We would use `new Function` here but browser
451
+ // support for source maps is better with eval.
452
+ (0, eval)(asset.output);
453
+ }
454
+ // @ts-expect-error TS7017
455
+ let fn = global.parcelHotUpdate[asset.id];
456
+ modules[asset.id] = [fn, deps];
457
+ }
458
+ // Always traverse to the parent bundle, even if we already replaced the asset in this bundle.
459
+ // This is required in case modules are duplicated. We need to ensure all instances have the updated code.
460
+ if (bundle.parent) {
461
+ hmrApply(bundle.parent, asset);
462
+ }
463
+ }
464
+ }
465
+ // @ts-expect-error TS2304
466
+ function hmrDelete(bundle, id) {
467
+ let modules = bundle.modules;
468
+ if (!modules) {
469
+ return;
470
+ }
471
+ if (modules[id]) {
472
+ // Collect dependencies that will become orphaned when this module is deleted.
473
+ let deps = modules[id][1];
474
+ let orphans = [];
475
+ for (let dep in deps) {
476
+ // @ts-expect-error TS2339
477
+ let parents = getParents(module.bundle.root, deps[dep]);
478
+ if (parents.length === 1) {
479
+ orphans.push(deps[dep]);
480
+ }
481
+ }
482
+ // Delete the module. This must be done before deleting dependencies in case of circular dependencies.
483
+ delete modules[id];
484
+ delete bundle.cache[id];
485
+ // Now delete the orphans.
486
+ orphans.forEach((id) => {
487
+ // @ts-expect-error TS2339
488
+ hmrDelete(module.bundle.root, id);
489
+ });
490
+ }
491
+ else if (bundle.parent) {
492
+ hmrDelete(bundle.parent, id);
493
+ }
494
+ }
495
+ function hmrAcceptCheck(
496
+ // @ts-expect-error TS2304
497
+ bundle /*: ParcelRequire */, id /*: string */, depsByBundle /*: ?{ [string]: { [string]: string } }*/) {
498
+ if (hmrAcceptCheckOne(bundle, id, depsByBundle)) {
499
+ return true;
500
+ }
501
+ // Traverse parents breadth first. All possible ancestries must accept the HMR update, or we'll reload.
502
+ // @ts-expect-error TS2339
503
+ let parents = getParents(module.bundle.root, id);
504
+ let accepted = false;
505
+ while (parents.length > 0) {
506
+ let v = parents.shift();
507
+ // @ts-expect-error TS18048
508
+ let a = hmrAcceptCheckOne(v[0], v[1], null);
509
+ if (a) {
510
+ // If this parent accepts, stop traversing upward, but still consider siblings.
511
+ accepted = true;
512
+ }
513
+ else {
514
+ // Otherwise, queue the parents in the next level upward.
515
+ // @ts-expect-error TS2339
516
+ let p = getParents(module.bundle.root, v[1]);
517
+ if (p.length === 0) {
518
+ // If there are no parents, then we've reached an entry without accepting. Reload.
519
+ accepted = false;
520
+ break;
521
+ }
522
+ parents.push(...p);
523
+ }
524
+ }
525
+ return accepted;
526
+ }
527
+ function hmrAcceptCheckOne(
528
+ // @ts-expect-error TS2304
529
+ bundle /*: ParcelRequire */, id /*: string */, depsByBundle /*: ?{ [string]: { [string]: string } }*/) {
530
+ var modules = bundle.modules;
531
+ if (!modules) {
532
+ return;
533
+ }
534
+ if (depsByBundle && !depsByBundle[bundle.HMR_BUNDLE_ID]) {
535
+ // If we reached the root bundle without finding where the asset should go,
536
+ // there's nothing to do. Mark as "accepted" so we don't reload the page.
537
+ if (!bundle.parent) {
538
+ return true;
539
+ }
540
+ return hmrAcceptCheck(bundle.parent, id, depsByBundle);
541
+ }
542
+ // @ts-expect-error TS7005
543
+ if (checkedAssets[id]) {
544
+ return true;
545
+ }
546
+ // @ts-expect-error TS7005
547
+ checkedAssets[id] = true;
548
+ var cached = bundle.cache[id];
549
+ assetsToDispose.push([bundle, id]);
550
+ if (!cached || (cached.hot && cached.hot._acceptCallbacks.length)) {
551
+ assetsToAccept.push([bundle, id]);
552
+ return true;
553
+ }
554
+ }
555
+ function hmrDisposeQueue() {
556
+ // Dispose all old assets.
557
+ for (let i = 0; i < assetsToDispose.length; i++) {
558
+ // @ts-expect-error TS7005
559
+ let id = assetsToDispose[i][1];
560
+ // @ts-expect-error TS7005
561
+ if (!disposedAssets[id]) {
562
+ // @ts-expect-error TS7005
563
+ hmrDispose(assetsToDispose[i][0], id);
564
+ disposedAssets[id] = true;
565
+ }
566
+ }
567
+ assetsToDispose = [];
568
+ }
569
+ function hmrDispose(
570
+ // @ts-expect-error TS2304
571
+ bundle /*: ParcelRequire */, id /*: string */) {
572
+ var cached = bundle.cache[id];
573
+ bundle.hotData[id] = {};
574
+ if (cached && cached.hot) {
575
+ cached.hot.data = bundle.hotData[id];
576
+ }
577
+ if (cached && cached.hot && cached.hot._disposeCallbacks.length) {
578
+ // @ts-expect-error TS7006
579
+ cached.hot._disposeCallbacks.forEach(function (cb) {
580
+ cb(bundle.hotData[id]);
581
+ });
582
+ }
583
+ delete bundle.cache[id];
584
+ }
585
+ function hmrAccept(
586
+ // @ts-expect-error TS2304
587
+ bundle /*: ParcelRequire */, id /*: string */) {
588
+ // Execute the module.
589
+ bundle(id);
590
+ // Run the accept callbacks in the new version of the module.
591
+ var cached = bundle.cache[id];
592
+ if (cached && cached.hot && cached.hot._acceptCallbacks.length) {
593
+ let assetsToAlsoAccept = [];
594
+ // @ts-expect-error TS7006
595
+ cached.hot._acceptCallbacks.forEach(function (cb) {
596
+ let additionalAssets = cb(function () {
597
+ // @ts-expect-error TS2339
598
+ return getParents(module.bundle.root, id);
599
+ });
600
+ if (Array.isArray(additionalAssets) && additionalAssets.length) {
601
+ // @ts-expect-error TS2345
602
+ assetsToAlsoAccept.push(...additionalAssets);
603
+ }
604
+ });
605
+ if (assetsToAlsoAccept.length > 0) {
606
+ let handled = assetsToAlsoAccept.every(function (a) {
607
+ // @ts-expect-error TS2554
608
+ return hmrAcceptCheck(a[0], a[1]);
609
+ });
610
+ if (!handled) {
611
+ return fullReload();
612
+ }
613
+ hmrDisposeQueue();
614
+ }
615
+ }
616
+ }
package/lib/HMRRuntime.js CHANGED
@@ -11,6 +11,13 @@ function _plugin() {
11
11
  };
12
12
  return data;
13
13
  }
14
+ function _featureFlags() {
15
+ const data = require("@atlaspack/feature-flags");
16
+ _featureFlags = function () {
17
+ return data;
18
+ };
19
+ return data;
20
+ }
14
21
  function _fs() {
15
22
  const data = _interopRequireDefault(require("fs"));
16
23
  _fs = function () {
@@ -25,14 +32,16 @@ function _path() {
25
32
  };
26
33
  return data;
27
34
  }
28
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
35
+ function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
29
36
  // Without this, the hmr-runtime.js is transpiled with the React Refresh swc transform because it
30
37
  // lives in `/app/packages/runtimes/...` and thus the `config` in the JSTransformer is actually the
31
38
  // user's package.json, and hmr-runtime.js is transpiled as a JSX asset.
32
39
  const FILENAME =
33
- // $FlowFixMe
40
+ // @ts-expect-error TS2339
34
41
  process.env.ATLASPACK_BUILD_REPL && process.browser ? '/' + __filename : __filename;
35
- const HMR_RUNTIME = _fs().default.readFileSync(_path().default.join(__dirname, './loaders/hmr-runtime.js'), 'utf8');
42
+ const HMR_RUNTIME = process.env.ATLASPACK_REGISTER_USE_SRC === 'true' ?
43
+ // This is templated code so it has to be compiled before inlining
44
+ _fs().default.readFileSync(_path().default.join(__dirname, '../lib/loaders/hmr-runtime.js'), 'utf8') : _fs().default.readFileSync(_path().default.join(__dirname, './loaders/hmr-runtime.js'), 'utf8');
36
45
  var _default = exports.default = new (_plugin().Runtime)({
37
46
  apply({
38
47
  bundle,
@@ -51,11 +60,17 @@ var _default = exports.default = new (_plugin().Runtime)({
51
60
  // Default to the HTTP port in the browser, only override
52
61
  // in watch mode or if hmr port != serve port
53
62
  !options.serveOptions || options.serveOptions.port !== port) ? port : null)};` + `var HMR_SECURE = ${JSON.stringify(!!(options.serveOptions && options.serveOptions.https))};` + `var HMR_ENV_HASH = "${bundle.env.id}";` + `var HMR_USE_SSE = ${JSON.stringify(
54
- // $FlowFixMe
55
- !!(process.env.ATLASPACK_BUILD_REPL && process.browser))};` + `module.bundle.HMR_BUNDLE_ID = ${JSON.stringify(bundle.id)};` + HMR_RUNTIME,
63
+ // @ts-expect-error TS2339
64
+ !!(process.env.ATLASPACK_BUILD_REPL && process.browser))};` + `var HMR_ENABLE_BUNDLE_VERSION = ${JSON.stringify((0, _featureFlags().getFeatureFlag)('hmrBundleVersioning'))};` + `module.bundle.HMR_BUNDLE_ID = ${JSON.stringify(bundle.id)};` + HMR_RUNTIME,
56
65
  isEntry: true,
57
66
  env: {
58
67
  sourceType: 'module'
68
+ },
69
+ // Pre-computed symbols: HMR runtime sets globals and executes, no explicit exports/imports
70
+ symbolData: {
71
+ symbols: new Map(),
72
+ // No exports, just side effects
73
+ dependencies: [] // No explicit dependencies, uses runtime globals
59
74
  }
60
75
  };
61
76
  }