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