@atlaspack/runtime-browser-hmr 2.14.5-dev.73 → 2.14.5-dev.93
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.
- package/CHANGELOG.md +26 -0
- package/lib/loaders/hmr-runtime.js +37 -23
- package/package.json +4 -4
- package/src/loaders/hmr-runtime.js +39 -20
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,31 @@
|
|
|
1
1
|
# @atlaspack/runtime-browser-hmr
|
|
2
2
|
|
|
3
|
+
## 2.14.14
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- Updated dependencies []:
|
|
8
|
+
- @atlaspack/utils@2.15.2
|
|
9
|
+
- @atlaspack/plugin@2.14.14
|
|
10
|
+
|
|
11
|
+
## 2.14.13
|
|
12
|
+
|
|
13
|
+
### Patch Changes
|
|
14
|
+
|
|
15
|
+
- [#633](https://github.com/atlassian-labs/atlaspack/pull/633) [`26aa9c5`](https://github.com/atlassian-labs/atlaspack/commit/26aa9c599d2be45ce1438a74c5fa22f39b9b554b) Thanks [@sbhuiyan-atlassian](https://github.com/sbhuiyan-atlassian)! - Ported various HMR changes from Parcel
|
|
16
|
+
|
|
17
|
+
- Updated dependencies []:
|
|
18
|
+
- @atlaspack/utils@2.15.1
|
|
19
|
+
- @atlaspack/plugin@2.14.13
|
|
20
|
+
|
|
21
|
+
## 2.14.12
|
|
22
|
+
|
|
23
|
+
### Patch Changes
|
|
24
|
+
|
|
25
|
+
- Updated dependencies [[`e39c6cf`](https://github.com/atlassian-labs/atlaspack/commit/e39c6cf05f7e95ce5420dbcea66f401b1cbd397c)]:
|
|
26
|
+
- @atlaspack/utils@2.15.0
|
|
27
|
+
- @atlaspack/plugin@2.14.12
|
|
28
|
+
|
|
3
29
|
## 2.14.11
|
|
4
30
|
|
|
5
31
|
### Patch Changes
|
|
@@ -67,7 +67,7 @@ function Module(moduleName) {
|
|
|
67
67
|
}
|
|
68
68
|
module.bundle.Module = Module;
|
|
69
69
|
module.bundle.hotData = {};
|
|
70
|
-
var checkedAssets /*: {|[string]: boolean|} */, assetsToDispose /*: Array<[ParcelRequire, string]> */, assetsToAccept /*: Array<[ParcelRequire, string]> */;
|
|
70
|
+
var checkedAssets /*: {|[string]: boolean|} */, disposedAssets /*: {|[string]: boolean|} */, assetsToDispose /*: Array<[ParcelRequire, string]> */, assetsToAccept /*: Array<[ParcelRequire, string]> */;
|
|
71
71
|
|
|
72
72
|
function getHostname() {
|
|
73
73
|
return HMR_HOST || (location.protocol.indexOf('http') === 0 ? location.hostname : 'localhost');
|
|
@@ -111,6 +111,7 @@ if ((!parent || !parent.isParcelRequire) && typeof WebSocket !== 'undefined') {
|
|
|
111
111
|
// $FlowFixMe
|
|
112
112
|
ws.onmessage = async function (event /*: {data: string, ...} */) {
|
|
113
113
|
checkedAssets = {} /*: {|[string]: boolean|} */;
|
|
114
|
+
disposedAssets = {} /*: {|[string]: boolean|} */;
|
|
114
115
|
assetsToAccept = [];
|
|
115
116
|
assetsToDispose = [];
|
|
116
117
|
var data /*: HMRMessage */ = JSON.parse(event.data);
|
|
@@ -135,19 +136,10 @@ if ((!parent || !parent.isParcelRequire) && typeof WebSocket !== 'undefined') {
|
|
|
135
136
|
window.dispatchEvent(new CustomEvent('parcelhmraccept'));
|
|
136
137
|
}
|
|
137
138
|
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
|
-
}
|
|
139
|
+
hmrDisposeQueue();
|
|
148
140
|
|
|
149
141
|
// Run accept callbacks. This will also re-execute other disposed assets in topological order.
|
|
150
|
-
processedAssets = {};
|
|
142
|
+
let processedAssets = {};
|
|
151
143
|
for (let i = 0; i < assetsToAccept.length; i++) {
|
|
152
144
|
let id = assetsToAccept[i][1];
|
|
153
145
|
if (!processedAssets[id]) {
|
|
@@ -178,8 +170,10 @@ if ((!parent || !parent.isParcelRequire) && typeof WebSocket !== 'undefined') {
|
|
|
178
170
|
console.error(e.message);
|
|
179
171
|
}
|
|
180
172
|
};
|
|
181
|
-
ws.onclose = function () {
|
|
182
|
-
|
|
173
|
+
ws.onclose = function (e) {
|
|
174
|
+
if (process.env.ATLASPACK_BUILD_ENV !== 'test') {
|
|
175
|
+
console.warn('[parcel] 🚨 Connection to the HMR server was lost');
|
|
176
|
+
}
|
|
183
177
|
};
|
|
184
178
|
}
|
|
185
179
|
}
|
|
@@ -385,7 +379,11 @@ function hmrApply(bundle /*: ParcelRequire */, asset /*: HMRAsset */) {
|
|
|
385
379
|
// $FlowFixMe
|
|
386
380
|
let fn = global.parcelHotUpdate[asset.id];
|
|
387
381
|
modules[asset.id] = [fn, deps];
|
|
388
|
-
}
|
|
382
|
+
}
|
|
383
|
+
|
|
384
|
+
// Always traverse to the parent bundle, even if we already replaced the asset in this bundle.
|
|
385
|
+
// This is required in case modules are duplicated. We need to ensure all instances have the updated code.
|
|
386
|
+
if (bundle.parent) {
|
|
389
387
|
hmrApply(bundle.parent, asset);
|
|
390
388
|
}
|
|
391
389
|
}
|
|
@@ -469,6 +467,17 @@ function hmrAcceptCheckOne(bundle /*: ParcelRequire */, id /*: string */, depsBy
|
|
|
469
467
|
return true;
|
|
470
468
|
}
|
|
471
469
|
}
|
|
470
|
+
function hmrDisposeQueue() {
|
|
471
|
+
// Dispose all old assets.
|
|
472
|
+
for (let i = 0; i < assetsToDispose.length; i++) {
|
|
473
|
+
let id = assetsToDispose[i][1];
|
|
474
|
+
if (!disposedAssets[id]) {
|
|
475
|
+
hmrDispose(assetsToDispose[i][0], id);
|
|
476
|
+
disposedAssets[id] = true;
|
|
477
|
+
}
|
|
478
|
+
}
|
|
479
|
+
assetsToDispose = [];
|
|
480
|
+
}
|
|
472
481
|
function hmrDispose(bundle /*: ParcelRequire */, id /*: string */) {
|
|
473
482
|
var cached = bundle.cache[id];
|
|
474
483
|
bundle.hotData[id] = {};
|
|
@@ -489,18 +498,23 @@ function hmrAccept(bundle /*: ParcelRequire */, id /*: string */) {
|
|
|
489
498
|
// Run the accept callbacks in the new version of the module.
|
|
490
499
|
var cached = bundle.cache[id];
|
|
491
500
|
if (cached && cached.hot && cached.hot._acceptCallbacks.length) {
|
|
501
|
+
let assetsToAlsoAccept = [];
|
|
492
502
|
cached.hot._acceptCallbacks.forEach(function (cb) {
|
|
493
|
-
|
|
503
|
+
let additionalAssets = cb(function () {
|
|
494
504
|
return getParents(module.bundle.root, id);
|
|
495
505
|
});
|
|
496
|
-
if (
|
|
497
|
-
assetsToAlsoAccept.
|
|
498
|
-
hmrDispose(a[0], a[1]);
|
|
499
|
-
});
|
|
500
|
-
|
|
501
|
-
// $FlowFixMe[method-unbinding]
|
|
502
|
-
assetsToAccept.push.apply(assetsToAccept, assetsToAlsoAccept);
|
|
506
|
+
if (Array.isArray(additionalAssets) && additionalAssets.length) {
|
|
507
|
+
assetsToAlsoAccept.push(...additionalAssets);
|
|
503
508
|
}
|
|
504
509
|
});
|
|
510
|
+
if (assetsToAlsoAccept.length > 0) {
|
|
511
|
+
let handled = assetsToAlsoAccept.every(function (a) {
|
|
512
|
+
return hmrAcceptCheck(a[0], a[1]);
|
|
513
|
+
});
|
|
514
|
+
if (!handled) {
|
|
515
|
+
return fullReload();
|
|
516
|
+
}
|
|
517
|
+
hmrDisposeQueue();
|
|
518
|
+
}
|
|
505
519
|
}
|
|
506
520
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@atlaspack/runtime-browser-hmr",
|
|
3
|
-
"version": "2.14.5-dev.
|
|
3
|
+
"version": "2.14.5-dev.93+207d003c0",
|
|
4
4
|
"license": "(MIT OR Apache-2.0)",
|
|
5
5
|
"publishConfig": {
|
|
6
6
|
"access": "public"
|
|
@@ -15,9 +15,9 @@
|
|
|
15
15
|
"node": ">= 16.0.0"
|
|
16
16
|
},
|
|
17
17
|
"dependencies": {
|
|
18
|
-
"@atlaspack/plugin": "2.14.5-dev.
|
|
19
|
-
"@atlaspack/utils": "2.14.5-dev.
|
|
18
|
+
"@atlaspack/plugin": "2.14.5-dev.93+207d003c0",
|
|
19
|
+
"@atlaspack/utils": "2.14.5-dev.93+207d003c0"
|
|
20
20
|
},
|
|
21
21
|
"type": "commonjs",
|
|
22
|
-
"gitHead": "
|
|
22
|
+
"gitHead": "207d003c0f1d4ffa6a1c52d2f8841d998616c523"
|
|
23
23
|
}
|
|
@@ -72,6 +72,7 @@ module.bundle.Module = Module;
|
|
|
72
72
|
module.bundle.hotData = {};
|
|
73
73
|
|
|
74
74
|
var checkedAssets /*: {|[string]: boolean|} */,
|
|
75
|
+
disposedAssets /*: {|[string]: boolean|} */,
|
|
75
76
|
assetsToDispose /*: Array<[ParcelRequire, string]> */,
|
|
76
77
|
assetsToAccept /*: Array<[ParcelRequire, string]> */;
|
|
77
78
|
|
|
@@ -134,6 +135,7 @@ if ((!parent || !parent.isParcelRequire) && typeof WebSocket !== 'undefined') {
|
|
|
134
135
|
// $FlowFixMe
|
|
135
136
|
ws.onmessage = async function (event /*: {data: string, ...} */) {
|
|
136
137
|
checkedAssets = ({} /*: {|[string]: boolean|} */);
|
|
138
|
+
disposedAssets = ({} /*: {|[string]: boolean|} */);
|
|
137
139
|
assetsToAccept = [];
|
|
138
140
|
assetsToDispose = [];
|
|
139
141
|
|
|
@@ -173,19 +175,10 @@ if ((!parent || !parent.isParcelRequire) && typeof WebSocket !== 'undefined') {
|
|
|
173
175
|
|
|
174
176
|
await hmrApplyUpdates(assets);
|
|
175
177
|
|
|
176
|
-
|
|
177
|
-
let processedAssets = ({} /*: {|[string]: boolean|} */);
|
|
178
|
-
for (let i = 0; i < assetsToDispose.length; i++) {
|
|
179
|
-
let id = assetsToDispose[i][1];
|
|
180
|
-
|
|
181
|
-
if (!processedAssets[id]) {
|
|
182
|
-
hmrDispose(assetsToDispose[i][0], id);
|
|
183
|
-
processedAssets[id] = true;
|
|
184
|
-
}
|
|
185
|
-
}
|
|
178
|
+
hmrDisposeQueue();
|
|
186
179
|
|
|
187
180
|
// Run accept callbacks. This will also re-execute other disposed assets in topological order.
|
|
188
|
-
processedAssets = {};
|
|
181
|
+
let processedAssets = {};
|
|
189
182
|
for (let i = 0; i < assetsToAccept.length; i++) {
|
|
190
183
|
let id = assetsToAccept[i][1];
|
|
191
184
|
|
|
@@ -493,7 +486,11 @@ function hmrApply(bundle /*: ParcelRequire */, asset /*: HMRAsset */) {
|
|
|
493
486
|
// $FlowFixMe
|
|
494
487
|
let fn = global.parcelHotUpdate[asset.id];
|
|
495
488
|
modules[asset.id] = [fn, deps];
|
|
496
|
-
}
|
|
489
|
+
}
|
|
490
|
+
|
|
491
|
+
// Always traverse to the parent bundle, even if we already replaced the asset in this bundle.
|
|
492
|
+
// This is required in case modules are duplicated. We need to ensure all instances have the updated code.
|
|
493
|
+
if (bundle.parent) {
|
|
497
494
|
hmrApply(bundle.parent, asset);
|
|
498
495
|
}
|
|
499
496
|
}
|
|
@@ -597,6 +594,20 @@ function hmrAcceptCheckOne(
|
|
|
597
594
|
}
|
|
598
595
|
}
|
|
599
596
|
|
|
597
|
+
function hmrDisposeQueue() {
|
|
598
|
+
// Dispose all old assets.
|
|
599
|
+
for (let i = 0; i < assetsToDispose.length; i++) {
|
|
600
|
+
let id = assetsToDispose[i][1];
|
|
601
|
+
|
|
602
|
+
if (!disposedAssets[id]) {
|
|
603
|
+
hmrDispose(assetsToDispose[i][0], id);
|
|
604
|
+
disposedAssets[id] = true;
|
|
605
|
+
}
|
|
606
|
+
}
|
|
607
|
+
|
|
608
|
+
assetsToDispose = [];
|
|
609
|
+
}
|
|
610
|
+
|
|
600
611
|
function hmrDispose(bundle /*: ParcelRequire */, id /*: string */) {
|
|
601
612
|
var cached = bundle.cache[id];
|
|
602
613
|
bundle.hotData[id] = {};
|
|
@@ -620,18 +631,26 @@ function hmrAccept(bundle /*: ParcelRequire */, id /*: string */) {
|
|
|
620
631
|
// Run the accept callbacks in the new version of the module.
|
|
621
632
|
var cached = bundle.cache[id];
|
|
622
633
|
if (cached && cached.hot && cached.hot._acceptCallbacks.length) {
|
|
634
|
+
let assetsToAlsoAccept = [];
|
|
623
635
|
cached.hot._acceptCallbacks.forEach(function (cb) {
|
|
624
|
-
|
|
636
|
+
let additionalAssets = cb(function () {
|
|
625
637
|
return getParents(module.bundle.root, id);
|
|
626
638
|
});
|
|
627
|
-
if (
|
|
628
|
-
assetsToAlsoAccept.
|
|
629
|
-
hmrDispose(a[0], a[1]);
|
|
630
|
-
});
|
|
631
|
-
|
|
632
|
-
// $FlowFixMe[method-unbinding]
|
|
633
|
-
assetsToAccept.push.apply(assetsToAccept, assetsToAlsoAccept);
|
|
639
|
+
if (Array.isArray(additionalAssets) && additionalAssets.length) {
|
|
640
|
+
assetsToAlsoAccept.push(...additionalAssets);
|
|
634
641
|
}
|
|
635
642
|
});
|
|
643
|
+
|
|
644
|
+
if (assetsToAlsoAccept.length > 0) {
|
|
645
|
+
let handled = assetsToAlsoAccept.every(function (a) {
|
|
646
|
+
return hmrAcceptCheck(a[0], a[1]);
|
|
647
|
+
});
|
|
648
|
+
|
|
649
|
+
if (!handled) {
|
|
650
|
+
return fullReload();
|
|
651
|
+
}
|
|
652
|
+
|
|
653
|
+
hmrDisposeQueue();
|
|
654
|
+
}
|
|
636
655
|
}
|
|
637
656
|
}
|