@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.
- package/LICENSE +201 -0
- package/lib/HMRRuntime.d.ts +3 -0
- package/lib/HMRRuntime.js +3 -3
- package/lib/loaders/hmr-runtime.d.ts +2 -0
- package/lib/loaders/hmr-runtime.js +157 -27
- package/package.json +12 -7
- package/src/{HMRRuntime.js → HMRRuntime.ts} +8 -10
- package/src/loaders/{hmr-runtime.js → hmr-runtime.ts} +202 -57
- package/tsconfig.json +4 -0
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
// @flow
|
|
2
1
|
/* global HMR_HOST, HMR_PORT, HMR_ENV_HASH, HMR_SECURE, HMR_USE_SSE, chrome, browser, __parcel__import__, __parcel__importScripts__, ServiceWorkerGlobalScope */
|
|
3
2
|
|
|
4
3
|
/*::
|
|
@@ -49,57 +48,85 @@ declare var globalThis: typeof self;
|
|
|
49
48
|
declare var ServiceWorkerGlobalScope: Object;
|
|
50
49
|
*/
|
|
51
50
|
|
|
51
|
+
// flow-to-ts helpers
|
|
52
|
+
export type SetComplement<A, B extends A> = A extends B ? never : A;
|
|
53
|
+
export type Diff<T extends U, U extends object> = Pick<
|
|
54
|
+
T,
|
|
55
|
+
SetComplement<keyof T, keyof U>
|
|
56
|
+
>;
|
|
57
|
+
// /flow-to-ts helpers
|
|
58
|
+
|
|
52
59
|
var OVERLAY_ID = '__parcel__error__overlay__';
|
|
53
60
|
|
|
61
|
+
// @ts-expect-error TS2339
|
|
54
62
|
var OldModule = module.bundle.Module;
|
|
55
63
|
|
|
56
|
-
function Module(moduleName) {
|
|
64
|
+
function Module(moduleName: any) {
|
|
65
|
+
// @ts-expect-error TS2683
|
|
57
66
|
OldModule.call(this, moduleName);
|
|
67
|
+
// @ts-expect-error TS2683
|
|
58
68
|
this.hot = {
|
|
69
|
+
// @ts-expect-error TS2339
|
|
59
70
|
data: module.bundle.hotData[moduleName],
|
|
60
71
|
_acceptCallbacks: [],
|
|
61
72
|
_disposeCallbacks: [],
|
|
73
|
+
// @ts-expect-error TS7006
|
|
62
74
|
accept: function (fn) {
|
|
63
75
|
this._acceptCallbacks.push(fn || function () {});
|
|
64
76
|
},
|
|
77
|
+
// @ts-expect-error TS7006
|
|
65
78
|
dispose: function (fn) {
|
|
66
79
|
this._disposeCallbacks.push(fn);
|
|
67
80
|
},
|
|
68
81
|
};
|
|
82
|
+
// @ts-expect-error TS2339
|
|
69
83
|
module.bundle.hotData[moduleName] = undefined;
|
|
70
84
|
}
|
|
85
|
+
// @ts-expect-error TS2339
|
|
71
86
|
module.bundle.Module = Module;
|
|
87
|
+
// @ts-expect-error TS2339
|
|
72
88
|
module.bundle.hotData = {};
|
|
73
89
|
|
|
90
|
+
// @ts-expect-error TS7034
|
|
74
91
|
var checkedAssets /*: {|[string]: boolean|} */,
|
|
92
|
+
// @ts-expect-error TS7034
|
|
75
93
|
disposedAssets /*: {|[string]: boolean|} */,
|
|
94
|
+
// @ts-expect-error TS7034
|
|
76
95
|
assetsToDispose /*: Array<[ParcelRequire, string]> */,
|
|
96
|
+
// @ts-expect-error TS7034
|
|
77
97
|
assetsToAccept /*: Array<[ParcelRequire, string]> */;
|
|
78
98
|
|
|
79
99
|
function getHostname() {
|
|
80
100
|
return (
|
|
101
|
+
// @ts-expect-error TS2304
|
|
81
102
|
HMR_HOST ||
|
|
103
|
+
// @ts-expect-error TS2304
|
|
82
104
|
(location.protocol.indexOf('http') === 0 ? location.hostname : 'localhost')
|
|
83
105
|
);
|
|
84
106
|
}
|
|
85
107
|
|
|
86
108
|
function getPort() {
|
|
109
|
+
// @ts-expect-error TS2304
|
|
87
110
|
return HMR_PORT || location.port;
|
|
88
111
|
}
|
|
89
112
|
|
|
90
113
|
// eslint-disable-next-line no-redeclare
|
|
114
|
+
// @ts-expect-error TS2339
|
|
91
115
|
var parent = module.bundle.parent;
|
|
92
116
|
if ((!parent || !parent.isParcelRequire) && typeof WebSocket !== 'undefined') {
|
|
93
117
|
var hostname = getHostname();
|
|
94
118
|
var port = getPort();
|
|
95
119
|
var protocol =
|
|
120
|
+
// @ts-expect-error TS2304
|
|
96
121
|
HMR_SECURE ||
|
|
122
|
+
// @ts-expect-error TS2304
|
|
97
123
|
(location.protocol == 'https:' &&
|
|
98
124
|
!['localhost', '127.0.0.1', '0.0.0.0'].includes(hostname))
|
|
99
125
|
? 'wss'
|
|
100
126
|
: 'ws';
|
|
101
127
|
|
|
102
128
|
var ws;
|
|
129
|
+
// @ts-expect-error TS2304
|
|
103
130
|
if (HMR_USE_SSE) {
|
|
104
131
|
ws = new EventSource('/__parcel_hmr');
|
|
105
132
|
} else {
|
|
@@ -107,7 +134,7 @@ if ((!parent || !parent.isParcelRequire) && typeof WebSocket !== 'undefined') {
|
|
|
107
134
|
ws = new WebSocket(
|
|
108
135
|
protocol + '://' + hostname + (port ? ':' + port : '') + '/',
|
|
109
136
|
);
|
|
110
|
-
} catch (err) {
|
|
137
|
+
} catch (err: any) {
|
|
111
138
|
if (err.message) {
|
|
112
139
|
console.error(err.message);
|
|
113
140
|
}
|
|
@@ -117,25 +144,33 @@ if ((!parent || !parent.isParcelRequire) && typeof WebSocket !== 'undefined') {
|
|
|
117
144
|
|
|
118
145
|
// Web extension context
|
|
119
146
|
var extCtx =
|
|
147
|
+
// @ts-expect-error TS2304
|
|
120
148
|
typeof browser === 'undefined'
|
|
121
|
-
?
|
|
149
|
+
? // @ts-expect-error TS2304
|
|
150
|
+
typeof chrome === 'undefined'
|
|
122
151
|
? null
|
|
123
|
-
:
|
|
124
|
-
|
|
152
|
+
: // @ts-expect-error TS2304
|
|
153
|
+
chrome
|
|
154
|
+
: // @ts-expect-error TS2304
|
|
155
|
+
browser;
|
|
125
156
|
|
|
126
157
|
// Safari doesn't support sourceURL in error stacks.
|
|
127
158
|
// eval may also be disabled via CSP, so do a quick check.
|
|
128
159
|
var supportsSourceURL = false;
|
|
129
160
|
try {
|
|
130
161
|
(0, eval)('throw new Error("test"); //# sourceURL=test.js');
|
|
131
|
-
} catch (err) {
|
|
162
|
+
} catch (err: any) {
|
|
132
163
|
supportsSourceURL = err.stack.includes('test.js');
|
|
133
164
|
}
|
|
134
165
|
|
|
135
|
-
//
|
|
136
|
-
ws.onmessage = async function (
|
|
137
|
-
|
|
138
|
-
|
|
166
|
+
// @ts-expect-error TS2339
|
|
167
|
+
ws.onmessage = async function (
|
|
168
|
+
event: {
|
|
169
|
+
data: string;
|
|
170
|
+
} /*: {data: string, ...} */,
|
|
171
|
+
) {
|
|
172
|
+
checkedAssets = {} /*: {|[string]: boolean|} */;
|
|
173
|
+
disposedAssets = {} /*: {|[string]: boolean|} */;
|
|
139
174
|
assetsToAccept = [];
|
|
140
175
|
assetsToDispose = [];
|
|
141
176
|
|
|
@@ -145,19 +180,23 @@ if ((!parent || !parent.isParcelRequire) && typeof WebSocket !== 'undefined') {
|
|
|
145
180
|
fullReload();
|
|
146
181
|
} else if (data.type === 'update') {
|
|
147
182
|
// Remove error overlay if there is one
|
|
183
|
+
// @ts-expect-error TS2304
|
|
148
184
|
if (typeof document !== 'undefined') {
|
|
149
185
|
removeErrorOverlay();
|
|
150
186
|
}
|
|
151
187
|
|
|
152
188
|
let assets = data.assets.filter(
|
|
189
|
+
// @ts-expect-error TS7006
|
|
153
190
|
(asset) => asset.envHash === HMR_ENV_HASH,
|
|
154
191
|
);
|
|
155
192
|
|
|
156
193
|
// Handle HMR Update
|
|
194
|
+
// @ts-expect-error TS7006
|
|
157
195
|
let handled = assets.every((asset) => {
|
|
158
196
|
return (
|
|
159
197
|
asset.type === 'css' ||
|
|
160
198
|
(asset.type === 'js' &&
|
|
199
|
+
// @ts-expect-error TS2339
|
|
161
200
|
hmrAcceptCheck(module.bundle.root, asset.id, asset.depsByBundle))
|
|
162
201
|
);
|
|
163
202
|
});
|
|
@@ -167,9 +206,11 @@ if ((!parent || !parent.isParcelRequire) && typeof WebSocket !== 'undefined') {
|
|
|
167
206
|
|
|
168
207
|
// Dispatch custom event so other runtimes (e.g React Refresh) are aware.
|
|
169
208
|
if (
|
|
209
|
+
// @ts-expect-error TS2304
|
|
170
210
|
typeof window !== 'undefined' &&
|
|
171
211
|
typeof CustomEvent !== 'undefined'
|
|
172
212
|
) {
|
|
213
|
+
// @ts-expect-error TS2304
|
|
173
214
|
window.dispatchEvent(new CustomEvent('parcelhmraccept'));
|
|
174
215
|
}
|
|
175
216
|
|
|
@@ -178,11 +219,13 @@ if ((!parent || !parent.isParcelRequire) && typeof WebSocket !== 'undefined') {
|
|
|
178
219
|
hmrDisposeQueue();
|
|
179
220
|
|
|
180
221
|
// Run accept callbacks. This will also re-execute other disposed assets in topological order.
|
|
181
|
-
let processedAssets = {};
|
|
222
|
+
let processedAssets: Record<string, any> = {};
|
|
182
223
|
for (let i = 0; i < assetsToAccept.length; i++) {
|
|
224
|
+
// @ts-expect-error TS7005
|
|
183
225
|
let id = assetsToAccept[i][1];
|
|
184
226
|
|
|
185
227
|
if (!processedAssets[id]) {
|
|
228
|
+
// @ts-expect-error TS7005
|
|
186
229
|
hmrAccept(assetsToAccept[i][0], id);
|
|
187
230
|
processedAssets[id] = true;
|
|
188
231
|
}
|
|
@@ -207,22 +250,23 @@ if ((!parent || !parent.isParcelRequire) && typeof WebSocket !== 'undefined') {
|
|
|
207
250
|
);
|
|
208
251
|
}
|
|
209
252
|
|
|
253
|
+
// @ts-expect-error TS2304
|
|
210
254
|
if (typeof document !== 'undefined') {
|
|
211
255
|
// Render the fancy html overlay
|
|
212
256
|
removeErrorOverlay();
|
|
213
257
|
var overlay = createErrorOverlay(data.diagnostics.html);
|
|
214
|
-
//
|
|
258
|
+
// @ts-expect-error TS2304
|
|
215
259
|
document.body.appendChild(overlay);
|
|
216
260
|
}
|
|
217
261
|
}
|
|
218
262
|
};
|
|
219
263
|
if (ws instanceof WebSocket) {
|
|
220
|
-
ws.onerror = function (e) {
|
|
264
|
+
ws.onerror = function (e: any) {
|
|
221
265
|
if (e.message) {
|
|
222
266
|
console.error(e.message);
|
|
223
267
|
}
|
|
224
268
|
};
|
|
225
|
-
ws.onclose = function (e) {
|
|
269
|
+
ws.onclose = function (e: CloseEvent) {
|
|
226
270
|
if (process.env.ATLASPACK_BUILD_ENV !== 'test') {
|
|
227
271
|
console.warn('[parcel] 🚨 Connection to the HMR server was lost');
|
|
228
272
|
}
|
|
@@ -231,6 +275,7 @@ if ((!parent || !parent.isParcelRequire) && typeof WebSocket !== 'undefined') {
|
|
|
231
275
|
}
|
|
232
276
|
|
|
233
277
|
function removeErrorOverlay() {
|
|
278
|
+
// @ts-expect-error TS2304
|
|
234
279
|
var overlay = document.getElementById(OVERLAY_ID);
|
|
235
280
|
if (overlay) {
|
|
236
281
|
overlay.remove();
|
|
@@ -238,7 +283,20 @@ function removeErrorOverlay() {
|
|
|
238
283
|
}
|
|
239
284
|
}
|
|
240
285
|
|
|
241
|
-
function createErrorOverlay(
|
|
286
|
+
function createErrorOverlay(
|
|
287
|
+
diagnostics: Array<
|
|
288
|
+
Partial<
|
|
289
|
+
Diff<
|
|
290
|
+
// @ts-expect-error TS2304
|
|
291
|
+
AnsiDiagnosticResult,
|
|
292
|
+
{
|
|
293
|
+
codeframe: string;
|
|
294
|
+
}
|
|
295
|
+
>
|
|
296
|
+
>
|
|
297
|
+
>,
|
|
298
|
+
) {
|
|
299
|
+
// @ts-expect-error TS2304
|
|
242
300
|
var overlay = document.createElement('div');
|
|
243
301
|
overlay.id = OVERLAY_ID;
|
|
244
302
|
|
|
@@ -247,7 +305,8 @@ function createErrorOverlay(diagnostics) {
|
|
|
247
305
|
|
|
248
306
|
for (let diagnostic of diagnostics) {
|
|
249
307
|
let stack = diagnostic.frames.length
|
|
250
|
-
?
|
|
308
|
+
? // @ts-expect-error TS7006
|
|
309
|
+
diagnostic.frames.reduce((p, frame) => {
|
|
251
310
|
return `${p}
|
|
252
311
|
<a href="/__parcel_launch_editor?file=${encodeURIComponent(
|
|
253
312
|
frame.location,
|
|
@@ -266,6 +325,7 @@ ${frame.code}`;
|
|
|
266
325
|
<pre>${stack}</pre>
|
|
267
326
|
<div>
|
|
268
327
|
${diagnostic.hints
|
|
328
|
+
// @ts-expect-error TS7006
|
|
269
329
|
.map((hint) => '<div>💡 ' + hint + '</div>')
|
|
270
330
|
.join('')}
|
|
271
331
|
</div>
|
|
@@ -286,20 +346,27 @@ ${frame.code}`;
|
|
|
286
346
|
}
|
|
287
347
|
|
|
288
348
|
function fullReload() {
|
|
349
|
+
// @ts-expect-error TS2304
|
|
289
350
|
if ('reload' in location) {
|
|
351
|
+
// @ts-expect-error TS2304
|
|
290
352
|
location.reload();
|
|
291
353
|
} else if (extCtx && extCtx.runtime && extCtx.runtime.reload) {
|
|
292
354
|
extCtx.runtime.reload();
|
|
293
355
|
}
|
|
294
356
|
}
|
|
295
357
|
|
|
296
|
-
function getParents(
|
|
358
|
+
function getParents(
|
|
359
|
+
// @ts-expect-error TS2304
|
|
360
|
+
bundle: ParcelRequire,
|
|
361
|
+
id: string,
|
|
362
|
+
) /*: Array<[ParcelRequire, string]> */ {
|
|
297
363
|
var modules = bundle.modules;
|
|
298
364
|
if (!modules) {
|
|
299
365
|
return [];
|
|
300
366
|
}
|
|
301
367
|
|
|
302
|
-
|
|
368
|
+
// @ts-expect-error TS2304
|
|
369
|
+
var parents: Array<[ParcelRequire, string]> = [];
|
|
303
370
|
var k, d, dep;
|
|
304
371
|
|
|
305
372
|
for (k in modules) {
|
|
@@ -319,38 +386,40 @@ function getParents(bundle, id) /*: Array<[ParcelRequire, string]> */ {
|
|
|
319
386
|
return parents;
|
|
320
387
|
}
|
|
321
388
|
|
|
322
|
-
function updateLink(link) {
|
|
389
|
+
function updateLink(link: HTMLElement) {
|
|
390
|
+
// @ts-expect-error TS2339
|
|
323
391
|
var href = link.getAttribute('href');
|
|
324
392
|
|
|
325
393
|
if (!href) {
|
|
326
394
|
return;
|
|
327
395
|
}
|
|
396
|
+
// @ts-expect-error TS2339
|
|
328
397
|
var newLink = link.cloneNode();
|
|
329
398
|
newLink.onload = function () {
|
|
399
|
+
// @ts-expect-error TS2339
|
|
330
400
|
if (link.parentNode !== null) {
|
|
331
|
-
//
|
|
401
|
+
// @ts-expect-error TS2339
|
|
332
402
|
link.parentNode.removeChild(link);
|
|
333
403
|
}
|
|
334
404
|
};
|
|
335
|
-
newLink.setAttribute(
|
|
336
|
-
|
|
337
|
-
// $FlowFixMe
|
|
338
|
-
href.split('?')[0] + '?' + Date.now(),
|
|
339
|
-
);
|
|
340
|
-
// $FlowFixMe
|
|
405
|
+
newLink.setAttribute('href', href.split('?')[0] + '?' + Date.now());
|
|
406
|
+
// @ts-expect-error TS18047
|
|
341
407
|
link.parentNode.insertBefore(newLink, link.nextSibling);
|
|
342
408
|
}
|
|
343
409
|
|
|
410
|
+
// @ts-expect-error TS7034
|
|
344
411
|
var cssTimeout = null;
|
|
345
412
|
function reloadCSS() {
|
|
413
|
+
// @ts-expect-error TS7005
|
|
346
414
|
if (cssTimeout) {
|
|
347
415
|
return;
|
|
348
416
|
}
|
|
349
417
|
|
|
350
418
|
cssTimeout = setTimeout(function () {
|
|
419
|
+
// @ts-expect-error TS18047
|
|
420
|
+
var document = window.document;
|
|
351
421
|
var links = document.querySelectorAll('link[rel="stylesheet"]');
|
|
352
422
|
for (var i = 0; i < links.length; i++) {
|
|
353
|
-
// $FlowFixMe[incompatible-type]
|
|
354
423
|
var href /*: string */ = links[i].getAttribute('href');
|
|
355
424
|
var hostname = getHostname();
|
|
356
425
|
var servedFromHMRServer =
|
|
@@ -361,6 +430,7 @@ function reloadCSS() {
|
|
|
361
430
|
: href.indexOf(hostname + ':' + getPort());
|
|
362
431
|
var absolute =
|
|
363
432
|
/^https?:\/\//i.test(href) &&
|
|
433
|
+
// @ts-expect-error TS18047
|
|
364
434
|
href.indexOf(location.origin) !== 0 &&
|
|
365
435
|
!servedFromHMRServer;
|
|
366
436
|
if (!absolute) {
|
|
@@ -372,38 +442,60 @@ function reloadCSS() {
|
|
|
372
442
|
}, 50);
|
|
373
443
|
}
|
|
374
444
|
|
|
375
|
-
|
|
445
|
+
// @ts-expect-error TS2304
|
|
446
|
+
function hmrDownload(asset: HMRAsset) {
|
|
376
447
|
if (asset.type === 'js') {
|
|
448
|
+
// @ts-expect-error TS18047
|
|
377
449
|
if (typeof document !== 'undefined') {
|
|
450
|
+
// @ts-expect-error TS18047
|
|
378
451
|
let script = document.createElement('script');
|
|
379
452
|
script.src = asset.url + '?t=' + Date.now();
|
|
380
453
|
if (asset.outputFormat === 'esmodule') {
|
|
381
454
|
script.type = 'module';
|
|
382
455
|
}
|
|
383
|
-
return new Promise(
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
456
|
+
return new Promise(
|
|
457
|
+
(
|
|
458
|
+
resolve: (
|
|
459
|
+
result: Promise<HTMLScriptElement> | HTMLScriptElement,
|
|
460
|
+
) => void,
|
|
461
|
+
reject: (error?: any) => void,
|
|
462
|
+
) => {
|
|
463
|
+
script.onload = () => resolve(script);
|
|
464
|
+
script.onerror = reject;
|
|
465
|
+
// @ts-expect-error TS18047
|
|
466
|
+
document.head?.appendChild(script);
|
|
467
|
+
},
|
|
468
|
+
);
|
|
469
|
+
// @ts-expect-error TS2304
|
|
388
470
|
} else if (typeof importScripts === 'function') {
|
|
389
471
|
// Worker scripts
|
|
390
472
|
if (asset.outputFormat === 'esmodule') {
|
|
473
|
+
// @ts-expect-error TS2304
|
|
391
474
|
return __parcel__import__(asset.url + '?t=' + Date.now());
|
|
392
475
|
} else {
|
|
393
|
-
return new Promise(
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
476
|
+
return new Promise(
|
|
477
|
+
(
|
|
478
|
+
resolve: (result: Promise<undefined> | undefined) => void,
|
|
479
|
+
reject: (error?: any) => void,
|
|
480
|
+
) => {
|
|
481
|
+
try {
|
|
482
|
+
// @ts-expect-error TS2304
|
|
483
|
+
__parcel__importScripts__(asset.url + '?t=' + Date.now());
|
|
484
|
+
// @ts-expect-error TS2794
|
|
485
|
+
resolve();
|
|
486
|
+
} catch (err: any) {
|
|
487
|
+
reject(err);
|
|
488
|
+
}
|
|
489
|
+
},
|
|
490
|
+
);
|
|
401
491
|
}
|
|
402
492
|
}
|
|
403
493
|
}
|
|
404
494
|
}
|
|
405
495
|
|
|
406
|
-
|
|
496
|
+
// @ts-expect-error TS2304
|
|
497
|
+
async function hmrApplyUpdates(assets: Array<HMRAsset>) {
|
|
498
|
+
// @ts-expect-error TS7017
|
|
407
499
|
global.parcelHotUpdate = Object.create(null);
|
|
408
500
|
|
|
409
501
|
let scriptsToRemove;
|
|
@@ -416,13 +508,15 @@ async function hmrApplyUpdates(assets) {
|
|
|
416
508
|
// This path is also taken if a CSP disallows eval.
|
|
417
509
|
if (!supportsSourceURL) {
|
|
418
510
|
let promises = assets.map((asset) =>
|
|
419
|
-
hmrDownload(asset)?.catch((err) => {
|
|
511
|
+
hmrDownload(asset)?.catch((err: any) => {
|
|
420
512
|
// Web extension fix
|
|
421
513
|
if (
|
|
422
514
|
extCtx &&
|
|
423
515
|
extCtx.runtime &&
|
|
424
516
|
extCtx.runtime.getManifest().manifest_version == 3 &&
|
|
517
|
+
// @ts-expect-error TS2304
|
|
425
518
|
typeof ServiceWorkerGlobalScope != 'undefined' &&
|
|
519
|
+
// @ts-expect-error TS2304
|
|
426
520
|
global instanceof ServiceWorkerGlobalScope
|
|
427
521
|
) {
|
|
428
522
|
extCtx.runtime.reload();
|
|
@@ -436,14 +530,18 @@ async function hmrApplyUpdates(assets) {
|
|
|
436
530
|
}
|
|
437
531
|
|
|
438
532
|
assets.forEach(function (asset) {
|
|
533
|
+
// @ts-expect-error TS2339
|
|
439
534
|
hmrApply(module.bundle.root, asset);
|
|
440
535
|
});
|
|
441
536
|
} finally {
|
|
537
|
+
// @ts-expect-error TS7017
|
|
442
538
|
delete global.parcelHotUpdate;
|
|
443
539
|
|
|
444
540
|
if (scriptsToRemove) {
|
|
541
|
+
// @ts-expect-error TS7006
|
|
445
542
|
scriptsToRemove.forEach((script) => {
|
|
446
543
|
if (script) {
|
|
544
|
+
// @ts-expect-error TS18047
|
|
447
545
|
document.head?.removeChild(script);
|
|
448
546
|
}
|
|
449
547
|
});
|
|
@@ -451,7 +549,12 @@ async function hmrApplyUpdates(assets) {
|
|
|
451
549
|
}
|
|
452
550
|
}
|
|
453
551
|
|
|
454
|
-
function hmrApply(
|
|
552
|
+
function hmrApply(
|
|
553
|
+
// @ts-expect-error TS2304
|
|
554
|
+
bundle: ParcelRequire /*: ParcelRequire */,
|
|
555
|
+
// @ts-expect-error TS2304
|
|
556
|
+
asset: HMRAsset /*: HMRAsset */,
|
|
557
|
+
) {
|
|
455
558
|
var modules = bundle.modules;
|
|
456
559
|
if (!modules) {
|
|
457
560
|
return;
|
|
@@ -469,8 +572,10 @@ function hmrApply(bundle /*: ParcelRequire */, asset /*: HMRAsset */) {
|
|
|
469
572
|
for (let dep in oldDeps) {
|
|
470
573
|
if (!deps[dep] || deps[dep] !== oldDeps[dep]) {
|
|
471
574
|
let id = oldDeps[dep];
|
|
575
|
+
// @ts-expect-error TS2339
|
|
472
576
|
let parents = getParents(module.bundle.root, id);
|
|
473
577
|
if (parents.length === 1) {
|
|
578
|
+
// @ts-expect-error TS2339
|
|
474
579
|
hmrDelete(module.bundle.root, id);
|
|
475
580
|
}
|
|
476
581
|
}
|
|
@@ -483,7 +588,7 @@ function hmrApply(bundle /*: ParcelRequire */, asset /*: HMRAsset */) {
|
|
|
483
588
|
(0, eval)(asset.output);
|
|
484
589
|
}
|
|
485
590
|
|
|
486
|
-
//
|
|
591
|
+
// @ts-expect-error TS7017
|
|
487
592
|
let fn = global.parcelHotUpdate[asset.id];
|
|
488
593
|
modules[asset.id] = [fn, deps];
|
|
489
594
|
}
|
|
@@ -496,7 +601,8 @@ function hmrApply(bundle /*: ParcelRequire */, asset /*: HMRAsset */) {
|
|
|
496
601
|
}
|
|
497
602
|
}
|
|
498
603
|
|
|
499
|
-
|
|
604
|
+
// @ts-expect-error TS2304
|
|
605
|
+
function hmrDelete(bundle: ParcelRequire, id: string) {
|
|
500
606
|
let modules = bundle.modules;
|
|
501
607
|
if (!modules) {
|
|
502
608
|
return;
|
|
@@ -505,8 +611,9 @@ function hmrDelete(bundle, id) {
|
|
|
505
611
|
if (modules[id]) {
|
|
506
612
|
// Collect dependencies that will become orphaned when this module is deleted.
|
|
507
613
|
let deps = modules[id][1];
|
|
508
|
-
let orphans = [];
|
|
614
|
+
let orphans: Array<string> = [];
|
|
509
615
|
for (let dep in deps) {
|
|
616
|
+
// @ts-expect-error TS2339
|
|
510
617
|
let parents = getParents(module.bundle.root, deps[dep]);
|
|
511
618
|
if (parents.length === 1) {
|
|
512
619
|
orphans.push(deps[dep]);
|
|
@@ -519,6 +626,7 @@ function hmrDelete(bundle, id) {
|
|
|
519
626
|
|
|
520
627
|
// Now delete the orphans.
|
|
521
628
|
orphans.forEach((id) => {
|
|
629
|
+
// @ts-expect-error TS2339
|
|
522
630
|
hmrDelete(module.bundle.root, id);
|
|
523
631
|
});
|
|
524
632
|
} else if (bundle.parent) {
|
|
@@ -527,25 +635,36 @@ function hmrDelete(bundle, id) {
|
|
|
527
635
|
}
|
|
528
636
|
|
|
529
637
|
function hmrAcceptCheck(
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
638
|
+
// @ts-expect-error TS2304
|
|
639
|
+
bundle: ParcelRequire /*: ParcelRequire */,
|
|
640
|
+
id: string /*: string */,
|
|
641
|
+
depsByBundle:
|
|
642
|
+
| {
|
|
643
|
+
[key: string]: {
|
|
644
|
+
[key: string]: string;
|
|
645
|
+
};
|
|
646
|
+
}
|
|
647
|
+
| null
|
|
648
|
+
| undefined /*: ?{ [string]: { [string]: string } }*/,
|
|
533
649
|
) {
|
|
534
650
|
if (hmrAcceptCheckOne(bundle, id, depsByBundle)) {
|
|
535
651
|
return true;
|
|
536
652
|
}
|
|
537
653
|
|
|
538
654
|
// Traverse parents breadth first. All possible ancestries must accept the HMR update, or we'll reload.
|
|
655
|
+
// @ts-expect-error TS2339
|
|
539
656
|
let parents = getParents(module.bundle.root, id);
|
|
540
657
|
let accepted = false;
|
|
541
658
|
while (parents.length > 0) {
|
|
542
659
|
let v = parents.shift();
|
|
660
|
+
// @ts-expect-error TS18048
|
|
543
661
|
let a = hmrAcceptCheckOne(v[0], v[1], null);
|
|
544
662
|
if (a) {
|
|
545
663
|
// If this parent accepts, stop traversing upward, but still consider siblings.
|
|
546
664
|
accepted = true;
|
|
547
665
|
} else {
|
|
548
666
|
// Otherwise, queue the parents in the next level upward.
|
|
667
|
+
// @ts-expect-error TS2339
|
|
549
668
|
let p = getParents(module.bundle.root, v[1]);
|
|
550
669
|
if (p.length === 0) {
|
|
551
670
|
// If there are no parents, then we've reached an entry without accepting. Reload.
|
|
@@ -560,9 +679,17 @@ function hmrAcceptCheck(
|
|
|
560
679
|
}
|
|
561
680
|
|
|
562
681
|
function hmrAcceptCheckOne(
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
682
|
+
// @ts-expect-error TS2304
|
|
683
|
+
bundle: ParcelRequire /*: ParcelRequire */,
|
|
684
|
+
id: string /*: string */,
|
|
685
|
+
depsByBundle:
|
|
686
|
+
| {
|
|
687
|
+
[key: string]: {
|
|
688
|
+
[key: string]: string;
|
|
689
|
+
};
|
|
690
|
+
}
|
|
691
|
+
| null
|
|
692
|
+
| undefined /*: ?{ [string]: { [string]: string } }*/,
|
|
566
693
|
) {
|
|
567
694
|
var modules = bundle.modules;
|
|
568
695
|
if (!modules) {
|
|
@@ -579,10 +706,12 @@ function hmrAcceptCheckOne(
|
|
|
579
706
|
return hmrAcceptCheck(bundle.parent, id, depsByBundle);
|
|
580
707
|
}
|
|
581
708
|
|
|
709
|
+
// @ts-expect-error TS7005
|
|
582
710
|
if (checkedAssets[id]) {
|
|
583
711
|
return true;
|
|
584
712
|
}
|
|
585
713
|
|
|
714
|
+
// @ts-expect-error TS7005
|
|
586
715
|
checkedAssets[id] = true;
|
|
587
716
|
|
|
588
717
|
var cached = bundle.cache[id];
|
|
@@ -597,9 +726,12 @@ function hmrAcceptCheckOne(
|
|
|
597
726
|
function hmrDisposeQueue() {
|
|
598
727
|
// Dispose all old assets.
|
|
599
728
|
for (let i = 0; i < assetsToDispose.length; i++) {
|
|
729
|
+
// @ts-expect-error TS7005
|
|
600
730
|
let id = assetsToDispose[i][1];
|
|
601
731
|
|
|
732
|
+
// @ts-expect-error TS7005
|
|
602
733
|
if (!disposedAssets[id]) {
|
|
734
|
+
// @ts-expect-error TS7005
|
|
603
735
|
hmrDispose(assetsToDispose[i][0], id);
|
|
604
736
|
disposedAssets[id] = true;
|
|
605
737
|
}
|
|
@@ -608,7 +740,11 @@ function hmrDisposeQueue() {
|
|
|
608
740
|
assetsToDispose = [];
|
|
609
741
|
}
|
|
610
742
|
|
|
611
|
-
function hmrDispose(
|
|
743
|
+
function hmrDispose(
|
|
744
|
+
// @ts-expect-error TS2304
|
|
745
|
+
bundle: ParcelRequire /*: ParcelRequire */,
|
|
746
|
+
id: string /*: string */,
|
|
747
|
+
) {
|
|
612
748
|
var cached = bundle.cache[id];
|
|
613
749
|
bundle.hotData[id] = {};
|
|
614
750
|
if (cached && cached.hot) {
|
|
@@ -616,6 +752,7 @@ function hmrDispose(bundle /*: ParcelRequire */, id /*: string */) {
|
|
|
616
752
|
}
|
|
617
753
|
|
|
618
754
|
if (cached && cached.hot && cached.hot._disposeCallbacks.length) {
|
|
755
|
+
// @ts-expect-error TS7006
|
|
619
756
|
cached.hot._disposeCallbacks.forEach(function (cb) {
|
|
620
757
|
cb(bundle.hotData[id]);
|
|
621
758
|
});
|
|
@@ -624,25 +761,33 @@ function hmrDispose(bundle /*: ParcelRequire */, id /*: string */) {
|
|
|
624
761
|
delete bundle.cache[id];
|
|
625
762
|
}
|
|
626
763
|
|
|
627
|
-
function hmrAccept(
|
|
764
|
+
function hmrAccept(
|
|
765
|
+
// @ts-expect-error TS2304
|
|
766
|
+
bundle: ParcelRequire /*: ParcelRequire */,
|
|
767
|
+
id: string /*: string */,
|
|
768
|
+
) {
|
|
628
769
|
// Execute the module.
|
|
629
770
|
bundle(id);
|
|
630
771
|
|
|
631
772
|
// Run the accept callbacks in the new version of the module.
|
|
632
773
|
var cached = bundle.cache[id];
|
|
633
774
|
if (cached && cached.hot && cached.hot._acceptCallbacks.length) {
|
|
634
|
-
let assetsToAlsoAccept = [];
|
|
775
|
+
let assetsToAlsoAccept: Array<never> = [];
|
|
776
|
+
// @ts-expect-error TS7006
|
|
635
777
|
cached.hot._acceptCallbacks.forEach(function (cb) {
|
|
636
778
|
let additionalAssets = cb(function () {
|
|
779
|
+
// @ts-expect-error TS2339
|
|
637
780
|
return getParents(module.bundle.root, id);
|
|
638
781
|
});
|
|
639
782
|
if (Array.isArray(additionalAssets) && additionalAssets.length) {
|
|
783
|
+
// @ts-expect-error TS2345
|
|
640
784
|
assetsToAlsoAccept.push(...additionalAssets);
|
|
641
785
|
}
|
|
642
786
|
});
|
|
643
787
|
|
|
644
788
|
if (assetsToAlsoAccept.length > 0) {
|
|
645
789
|
let handled = assetsToAlsoAccept.every(function (a) {
|
|
790
|
+
// @ts-expect-error TS2554
|
|
646
791
|
return hmrAcceptCheck(a[0], a[1]);
|
|
647
792
|
});
|
|
648
793
|
|
package/tsconfig.json
ADDED