@atlaspack/runtime-browser-hmr 2.14.19 → 2.14.21-typescript-08dcc1c9b.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/CHANGELOG.md +10 -0
- package/LICENSE +201 -0
- package/lib/HMRRuntime.js +3 -3
- package/lib/loaders/hmr-runtime.js +151 -27
- package/package.json +10 -5
- package/src/{HMRRuntime.js → HMRRuntime.ts} +8 -10
- package/src/loaders/{hmr-runtime.js → hmr-runtime.ts} +195 -57
- package/tsconfig.json +4 -0
|
@@ -49,40 +49,70 @@ declare var globalThis: typeof self;
|
|
|
49
49
|
declare var ServiceWorkerGlobalScope: Object;
|
|
50
50
|
*/
|
|
51
51
|
var OVERLAY_ID = '__parcel__error__overlay__';
|
|
52
|
+
|
|
53
|
+
// @ts-expect-error TS2339
|
|
52
54
|
var OldModule = module.bundle.Module;
|
|
53
55
|
function Module(moduleName) {
|
|
56
|
+
// @ts-expect-error TS2683
|
|
54
57
|
OldModule.call(this, moduleName);
|
|
58
|
+
// @ts-expect-error TS2683
|
|
55
59
|
this.hot = {
|
|
60
|
+
// @ts-expect-error TS2339
|
|
56
61
|
data: module.bundle.hotData[moduleName],
|
|
57
62
|
_acceptCallbacks: [],
|
|
58
63
|
_disposeCallbacks: [],
|
|
64
|
+
// @ts-expect-error TS7006
|
|
59
65
|
accept: function (fn) {
|
|
60
66
|
this._acceptCallbacks.push(fn || function () {});
|
|
61
67
|
},
|
|
68
|
+
// @ts-expect-error TS7006
|
|
62
69
|
dispose: function (fn) {
|
|
63
70
|
this._disposeCallbacks.push(fn);
|
|
64
71
|
}
|
|
65
72
|
};
|
|
73
|
+
// @ts-expect-error TS2339
|
|
66
74
|
module.bundle.hotData[moduleName] = undefined;
|
|
67
75
|
}
|
|
76
|
+
// @ts-expect-error TS2339
|
|
68
77
|
module.bundle.Module = Module;
|
|
78
|
+
// @ts-expect-error TS2339
|
|
69
79
|
module.bundle.hotData = {};
|
|
70
|
-
|
|
80
|
+
|
|
81
|
+
// @ts-expect-error TS7034
|
|
82
|
+
var checkedAssets /*: {|[string]: boolean|} */,
|
|
83
|
+
// @ts-expect-error TS7034
|
|
84
|
+
disposedAssets /*: {|[string]: boolean|} */,
|
|
85
|
+
// @ts-expect-error TS7034
|
|
86
|
+
assetsToDispose /*: Array<[ParcelRequire, string]> */,
|
|
87
|
+
// @ts-expect-error TS7034
|
|
88
|
+
assetsToAccept /*: Array<[ParcelRequire, string]> */;
|
|
71
89
|
|
|
72
90
|
function getHostname() {
|
|
73
|
-
return
|
|
91
|
+
return (
|
|
92
|
+
// @ts-expect-error TS2304
|
|
93
|
+
HMR_HOST || (
|
|
94
|
+
// @ts-expect-error TS2304
|
|
95
|
+
location.protocol.indexOf('http') === 0 ? location.hostname : 'localhost')
|
|
96
|
+
);
|
|
74
97
|
}
|
|
75
98
|
function getPort() {
|
|
99
|
+
// @ts-expect-error TS2304
|
|
76
100
|
return HMR_PORT || location.port;
|
|
77
101
|
}
|
|
78
102
|
|
|
79
103
|
// eslint-disable-next-line no-redeclare
|
|
104
|
+
// @ts-expect-error TS2339
|
|
80
105
|
var parent = module.bundle.parent;
|
|
81
106
|
if ((!parent || !parent.isParcelRequire) && typeof WebSocket !== 'undefined') {
|
|
82
107
|
var hostname = getHostname();
|
|
83
108
|
var port = getPort();
|
|
84
|
-
var protocol =
|
|
109
|
+
var protocol =
|
|
110
|
+
// @ts-expect-error TS2304
|
|
111
|
+
HMR_SECURE ||
|
|
112
|
+
// @ts-expect-error TS2304
|
|
113
|
+
location.protocol == 'https:' && !['localhost', '127.0.0.1', '0.0.0.0'].includes(hostname) ? 'wss' : 'ws';
|
|
85
114
|
var ws;
|
|
115
|
+
// @ts-expect-error TS2304
|
|
86
116
|
if (HMR_USE_SSE) {
|
|
87
117
|
ws = new EventSource('/__parcel_hmr');
|
|
88
118
|
} else {
|
|
@@ -97,7 +127,15 @@ if ((!parent || !parent.isParcelRequire) && typeof WebSocket !== 'undefined') {
|
|
|
97
127
|
}
|
|
98
128
|
|
|
99
129
|
// Web extension context
|
|
100
|
-
var extCtx =
|
|
130
|
+
var extCtx =
|
|
131
|
+
// @ts-expect-error TS2304
|
|
132
|
+
typeof browser === 'undefined' ?
|
|
133
|
+
// @ts-expect-error TS2304
|
|
134
|
+
typeof chrome === 'undefined' ? null :
|
|
135
|
+
// @ts-expect-error TS2304
|
|
136
|
+
chrome :
|
|
137
|
+
// @ts-expect-error TS2304
|
|
138
|
+
browser;
|
|
101
139
|
|
|
102
140
|
// Safari doesn't support sourceURL in error stacks.
|
|
103
141
|
// eval may also be disabled via CSP, so do a quick check.
|
|
@@ -108,8 +146,8 @@ if ((!parent || !parent.isParcelRequire) && typeof WebSocket !== 'undefined') {
|
|
|
108
146
|
supportsSourceURL = err.stack.includes('test.js');
|
|
109
147
|
}
|
|
110
148
|
|
|
111
|
-
//
|
|
112
|
-
ws.onmessage = async function (event
|
|
149
|
+
// @ts-expect-error TS2339
|
|
150
|
+
ws.onmessage = async function (event) {
|
|
113
151
|
checkedAssets = {} /*: {|[string]: boolean|} */;
|
|
114
152
|
disposedAssets = {} /*: {|[string]: boolean|} */;
|
|
115
153
|
assetsToAccept = [];
|
|
@@ -119,20 +157,29 @@ if ((!parent || !parent.isParcelRequire) && typeof WebSocket !== 'undefined') {
|
|
|
119
157
|
fullReload();
|
|
120
158
|
} else if (data.type === 'update') {
|
|
121
159
|
// Remove error overlay if there is one
|
|
160
|
+
// @ts-expect-error TS2304
|
|
122
161
|
if (typeof document !== 'undefined') {
|
|
123
162
|
removeErrorOverlay();
|
|
124
163
|
}
|
|
125
|
-
let assets = data.assets.filter(
|
|
164
|
+
let assets = data.assets.filter(
|
|
165
|
+
// @ts-expect-error TS7006
|
|
166
|
+
asset => asset.envHash === HMR_ENV_HASH);
|
|
126
167
|
|
|
127
168
|
// Handle HMR Update
|
|
169
|
+
// @ts-expect-error TS7006
|
|
128
170
|
let handled = assets.every(asset => {
|
|
129
|
-
return asset.type === 'css' || asset.type === 'js' &&
|
|
171
|
+
return asset.type === 'css' || asset.type === 'js' &&
|
|
172
|
+
// @ts-expect-error TS2339
|
|
173
|
+
hmrAcceptCheck(module.bundle.root, asset.id, asset.depsByBundle);
|
|
130
174
|
});
|
|
131
175
|
if (handled) {
|
|
132
176
|
console.clear();
|
|
133
177
|
|
|
134
178
|
// Dispatch custom event so other runtimes (e.g React Refresh) are aware.
|
|
135
|
-
if (
|
|
179
|
+
if (
|
|
180
|
+
// @ts-expect-error TS2304
|
|
181
|
+
typeof window !== 'undefined' && typeof CustomEvent !== 'undefined') {
|
|
182
|
+
// @ts-expect-error TS2304
|
|
136
183
|
window.dispatchEvent(new CustomEvent('parcelhmraccept'));
|
|
137
184
|
}
|
|
138
185
|
await hmrApplyUpdates(assets);
|
|
@@ -141,8 +188,10 @@ if ((!parent || !parent.isParcelRequire) && typeof WebSocket !== 'undefined') {
|
|
|
141
188
|
// Run accept callbacks. This will also re-execute other disposed assets in topological order.
|
|
142
189
|
let processedAssets = {};
|
|
143
190
|
for (let i = 0; i < assetsToAccept.length; i++) {
|
|
191
|
+
// @ts-expect-error TS7005
|
|
144
192
|
let id = assetsToAccept[i][1];
|
|
145
193
|
if (!processedAssets[id]) {
|
|
194
|
+
// @ts-expect-error TS7005
|
|
146
195
|
hmrAccept(assetsToAccept[i][0], id);
|
|
147
196
|
processedAssets[id] = true;
|
|
148
197
|
}
|
|
@@ -155,11 +204,13 @@ if ((!parent || !parent.isParcelRequire) && typeof WebSocket !== 'undefined') {
|
|
|
155
204
|
let stack = ansiDiagnostic.codeframe ? ansiDiagnostic.codeframe : ansiDiagnostic.stack;
|
|
156
205
|
console.error('🚨 [parcel]: ' + ansiDiagnostic.message + '\n' + stack + '\n\n' + ansiDiagnostic.hints.join('\n'));
|
|
157
206
|
}
|
|
207
|
+
|
|
208
|
+
// @ts-expect-error TS2304
|
|
158
209
|
if (typeof document !== 'undefined') {
|
|
159
210
|
// Render the fancy html overlay
|
|
160
211
|
removeErrorOverlay();
|
|
161
212
|
var overlay = createErrorOverlay(data.diagnostics.html);
|
|
162
|
-
//
|
|
213
|
+
// @ts-expect-error TS2304
|
|
163
214
|
document.body.appendChild(overlay);
|
|
164
215
|
}
|
|
165
216
|
}
|
|
@@ -178,6 +229,7 @@ if ((!parent || !parent.isParcelRequire) && typeof WebSocket !== 'undefined') {
|
|
|
178
229
|
}
|
|
179
230
|
}
|
|
180
231
|
function removeErrorOverlay() {
|
|
232
|
+
// @ts-expect-error TS2304
|
|
181
233
|
var overlay = document.getElementById(OVERLAY_ID);
|
|
182
234
|
if (overlay) {
|
|
183
235
|
overlay.remove();
|
|
@@ -185,11 +237,14 @@ function removeErrorOverlay() {
|
|
|
185
237
|
}
|
|
186
238
|
}
|
|
187
239
|
function createErrorOverlay(diagnostics) {
|
|
240
|
+
// @ts-expect-error TS2304
|
|
188
241
|
var overlay = document.createElement('div');
|
|
189
242
|
overlay.id = OVERLAY_ID;
|
|
190
243
|
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;">';
|
|
191
244
|
for (let diagnostic of diagnostics) {
|
|
192
|
-
let stack = diagnostic.frames.length ?
|
|
245
|
+
let stack = diagnostic.frames.length ?
|
|
246
|
+
// @ts-expect-error TS7006
|
|
247
|
+
diagnostic.frames.reduce((p, frame) => {
|
|
193
248
|
return `${p}
|
|
194
249
|
<a href="/__parcel_launch_editor?file=${encodeURIComponent(frame.location)}" style="text-decoration: underline; color: #888" onclick="fetch(this.href); return false">${frame.location}</a>
|
|
195
250
|
${frame.code}`;
|
|
@@ -201,7 +256,9 @@ ${frame.code}`;
|
|
|
201
256
|
</div>
|
|
202
257
|
<pre>${stack}</pre>
|
|
203
258
|
<div>
|
|
204
|
-
${diagnostic.hints
|
|
259
|
+
${diagnostic.hints
|
|
260
|
+
// @ts-expect-error TS7006
|
|
261
|
+
.map(hint => '<div>💡 ' + hint + '</div>').join('')}
|
|
205
262
|
</div>
|
|
206
263
|
${diagnostic.documentation ? `<div>📝 <a style="color: violet" href="${diagnostic.documentation}" target="_blank">Learn more</a></div>` : ''}
|
|
207
264
|
</div>
|
|
@@ -212,17 +269,23 @@ ${frame.code}`;
|
|
|
212
269
|
return overlay;
|
|
213
270
|
}
|
|
214
271
|
function fullReload() {
|
|
272
|
+
// @ts-expect-error TS2304
|
|
215
273
|
if ('reload' in location) {
|
|
274
|
+
// @ts-expect-error TS2304
|
|
216
275
|
location.reload();
|
|
217
276
|
} else if (extCtx && extCtx.runtime && extCtx.runtime.reload) {
|
|
218
277
|
extCtx.runtime.reload();
|
|
219
278
|
}
|
|
220
279
|
}
|
|
221
|
-
function getParents(
|
|
280
|
+
function getParents(
|
|
281
|
+
// @ts-expect-error TS2304
|
|
282
|
+
bundle, id) /*: Array<[ParcelRequire, string]> */{
|
|
222
283
|
var modules = bundle.modules;
|
|
223
284
|
if (!modules) {
|
|
224
285
|
return [];
|
|
225
286
|
}
|
|
287
|
+
|
|
288
|
+
// @ts-expect-error TS2304
|
|
226
289
|
var parents = [];
|
|
227
290
|
var k, d, dep;
|
|
228
291
|
for (k in modules) {
|
|
@@ -239,36 +302,43 @@ function getParents(bundle, id) /*: Array<[ParcelRequire, string]> */{
|
|
|
239
302
|
return parents;
|
|
240
303
|
}
|
|
241
304
|
function updateLink(link) {
|
|
305
|
+
// @ts-expect-error TS2339
|
|
242
306
|
var href = link.getAttribute('href');
|
|
243
307
|
if (!href) {
|
|
244
308
|
return;
|
|
245
309
|
}
|
|
310
|
+
// @ts-expect-error TS2339
|
|
246
311
|
var newLink = link.cloneNode();
|
|
247
312
|
newLink.onload = function () {
|
|
313
|
+
// @ts-expect-error TS2339
|
|
248
314
|
if (link.parentNode !== null) {
|
|
249
|
-
//
|
|
315
|
+
// @ts-expect-error TS2339
|
|
250
316
|
link.parentNode.removeChild(link);
|
|
251
317
|
}
|
|
252
318
|
};
|
|
253
|
-
newLink.setAttribute('href',
|
|
254
|
-
//
|
|
255
|
-
href.split('?')[0] + '?' + Date.now());
|
|
256
|
-
// $FlowFixMe
|
|
319
|
+
newLink.setAttribute('href', href.split('?')[0] + '?' + Date.now());
|
|
320
|
+
// @ts-expect-error TS18047
|
|
257
321
|
link.parentNode.insertBefore(newLink, link.nextSibling);
|
|
258
322
|
}
|
|
323
|
+
|
|
324
|
+
// @ts-expect-error TS7034
|
|
259
325
|
var cssTimeout = null;
|
|
260
326
|
function reloadCSS() {
|
|
327
|
+
// @ts-expect-error TS7005
|
|
261
328
|
if (cssTimeout) {
|
|
262
329
|
return;
|
|
263
330
|
}
|
|
264
331
|
cssTimeout = setTimeout(function () {
|
|
332
|
+
// @ts-expect-error TS18047
|
|
333
|
+
var document = window.document;
|
|
265
334
|
var links = document.querySelectorAll('link[rel="stylesheet"]');
|
|
266
335
|
for (var i = 0; i < links.length; i++) {
|
|
267
|
-
// $FlowFixMe[incompatible-type]
|
|
268
336
|
var href /*: string */ = links[i].getAttribute('href');
|
|
269
337
|
var hostname = getHostname();
|
|
270
338
|
var servedFromHMRServer = hostname === 'localhost' ? new RegExp('^(https?:\\/\\/(0.0.0.0|127.0.0.1)|localhost):' + getPort()).test(href) : href.indexOf(hostname + ':' + getPort());
|
|
271
|
-
var absolute = /^https?:\/\//i.test(href) &&
|
|
339
|
+
var absolute = /^https?:\/\//i.test(href) &&
|
|
340
|
+
// @ts-expect-error TS18047
|
|
341
|
+
href.indexOf(location.origin) !== 0 && !servedFromHMRServer;
|
|
272
342
|
if (!absolute) {
|
|
273
343
|
updateLink(links[i]);
|
|
274
344
|
}
|
|
@@ -276,9 +346,13 @@ function reloadCSS() {
|
|
|
276
346
|
cssTimeout = null;
|
|
277
347
|
}, 50);
|
|
278
348
|
}
|
|
349
|
+
|
|
350
|
+
// @ts-expect-error TS2304
|
|
279
351
|
function hmrDownload(asset) {
|
|
280
352
|
if (asset.type === 'js') {
|
|
353
|
+
// @ts-expect-error TS18047
|
|
281
354
|
if (typeof document !== 'undefined') {
|
|
355
|
+
// @ts-expect-error TS18047
|
|
282
356
|
let script = document.createElement('script');
|
|
283
357
|
script.src = asset.url + '?t=' + Date.now();
|
|
284
358
|
if (asset.outputFormat === 'esmodule') {
|
|
@@ -288,16 +362,21 @@ function hmrDownload(asset) {
|
|
|
288
362
|
var _document$head;
|
|
289
363
|
script.onload = () => resolve(script);
|
|
290
364
|
script.onerror = reject;
|
|
365
|
+
// @ts-expect-error TS18047
|
|
291
366
|
(_document$head = document.head) === null || _document$head === void 0 || _document$head.appendChild(script);
|
|
292
367
|
});
|
|
368
|
+
// @ts-expect-error TS2304
|
|
293
369
|
} else if (typeof importScripts === 'function') {
|
|
294
370
|
// Worker scripts
|
|
295
371
|
if (asset.outputFormat === 'esmodule') {
|
|
372
|
+
// @ts-expect-error TS2304
|
|
296
373
|
return __parcel__import__(asset.url + '?t=' + Date.now());
|
|
297
374
|
} else {
|
|
298
375
|
return new Promise((resolve, reject) => {
|
|
299
376
|
try {
|
|
377
|
+
// @ts-expect-error TS2304
|
|
300
378
|
__parcel__importScripts__(asset.url + '?t=' + Date.now());
|
|
379
|
+
// @ts-expect-error TS2794
|
|
301
380
|
resolve();
|
|
302
381
|
} catch (err) {
|
|
303
382
|
reject(err);
|
|
@@ -307,7 +386,10 @@ function hmrDownload(asset) {
|
|
|
307
386
|
}
|
|
308
387
|
}
|
|
309
388
|
}
|
|
389
|
+
|
|
390
|
+
// @ts-expect-error TS2304
|
|
310
391
|
async function hmrApplyUpdates(assets) {
|
|
392
|
+
// @ts-expect-error TS7017
|
|
311
393
|
global.parcelHotUpdate = Object.create(null);
|
|
312
394
|
let scriptsToRemove;
|
|
313
395
|
try {
|
|
@@ -322,7 +404,11 @@ async function hmrApplyUpdates(assets) {
|
|
|
322
404
|
var _hmrDownload;
|
|
323
405
|
return (_hmrDownload = hmrDownload(asset)) === null || _hmrDownload === void 0 ? void 0 : _hmrDownload.catch(err => {
|
|
324
406
|
// Web extension fix
|
|
325
|
-
if (extCtx && extCtx.runtime && extCtx.runtime.getManifest().manifest_version == 3 &&
|
|
407
|
+
if (extCtx && extCtx.runtime && extCtx.runtime.getManifest().manifest_version == 3 &&
|
|
408
|
+
// @ts-expect-error TS2304
|
|
409
|
+
typeof ServiceWorkerGlobalScope != 'undefined' &&
|
|
410
|
+
// @ts-expect-error TS2304
|
|
411
|
+
global instanceof ServiceWorkerGlobalScope) {
|
|
326
412
|
extCtx.runtime.reload();
|
|
327
413
|
return;
|
|
328
414
|
}
|
|
@@ -332,21 +418,29 @@ async function hmrApplyUpdates(assets) {
|
|
|
332
418
|
scriptsToRemove = await Promise.all(promises);
|
|
333
419
|
}
|
|
334
420
|
assets.forEach(function (asset) {
|
|
421
|
+
// @ts-expect-error TS2339
|
|
335
422
|
hmrApply(module.bundle.root, asset);
|
|
336
423
|
});
|
|
337
424
|
} finally {
|
|
425
|
+
// @ts-expect-error TS7017
|
|
338
426
|
delete global.parcelHotUpdate;
|
|
339
427
|
if (scriptsToRemove) {
|
|
428
|
+
// @ts-expect-error TS7006
|
|
340
429
|
scriptsToRemove.forEach(script => {
|
|
341
430
|
if (script) {
|
|
342
431
|
var _document$head2;
|
|
432
|
+
// @ts-expect-error TS18047
|
|
343
433
|
(_document$head2 = document.head) === null || _document$head2 === void 0 || _document$head2.removeChild(script);
|
|
344
434
|
}
|
|
345
435
|
});
|
|
346
436
|
}
|
|
347
437
|
}
|
|
348
438
|
}
|
|
349
|
-
function hmrApply(
|
|
439
|
+
function hmrApply(
|
|
440
|
+
// @ts-expect-error TS2304
|
|
441
|
+
bundle,
|
|
442
|
+
// @ts-expect-error TS2304
|
|
443
|
+
asset) {
|
|
350
444
|
var modules = bundle.modules;
|
|
351
445
|
if (!modules) {
|
|
352
446
|
return;
|
|
@@ -363,8 +457,10 @@ function hmrApply(bundle /*: ParcelRequire */, asset /*: HMRAsset */) {
|
|
|
363
457
|
for (let dep in oldDeps) {
|
|
364
458
|
if (!deps[dep] || deps[dep] !== oldDeps[dep]) {
|
|
365
459
|
let id = oldDeps[dep];
|
|
460
|
+
// @ts-expect-error TS2339
|
|
366
461
|
let parents = getParents(module.bundle.root, id);
|
|
367
462
|
if (parents.length === 1) {
|
|
463
|
+
// @ts-expect-error TS2339
|
|
368
464
|
hmrDelete(module.bundle.root, id);
|
|
369
465
|
}
|
|
370
466
|
}
|
|
@@ -376,7 +472,7 @@ function hmrApply(bundle /*: ParcelRequire */, asset /*: HMRAsset */) {
|
|
|
376
472
|
(0, eval)(asset.output);
|
|
377
473
|
}
|
|
378
474
|
|
|
379
|
-
//
|
|
475
|
+
// @ts-expect-error TS7017
|
|
380
476
|
let fn = global.parcelHotUpdate[asset.id];
|
|
381
477
|
modules[asset.id] = [fn, deps];
|
|
382
478
|
}
|
|
@@ -388,6 +484,8 @@ function hmrApply(bundle /*: ParcelRequire */, asset /*: HMRAsset */) {
|
|
|
388
484
|
}
|
|
389
485
|
}
|
|
390
486
|
}
|
|
487
|
+
|
|
488
|
+
// @ts-expect-error TS2304
|
|
391
489
|
function hmrDelete(bundle, id) {
|
|
392
490
|
let modules = bundle.modules;
|
|
393
491
|
if (!modules) {
|
|
@@ -398,6 +496,7 @@ function hmrDelete(bundle, id) {
|
|
|
398
496
|
let deps = modules[id][1];
|
|
399
497
|
let orphans = [];
|
|
400
498
|
for (let dep in deps) {
|
|
499
|
+
// @ts-expect-error TS2339
|
|
401
500
|
let parents = getParents(module.bundle.root, deps[dep]);
|
|
402
501
|
if (parents.length === 1) {
|
|
403
502
|
orphans.push(deps[dep]);
|
|
@@ -410,28 +509,34 @@ function hmrDelete(bundle, id) {
|
|
|
410
509
|
|
|
411
510
|
// Now delete the orphans.
|
|
412
511
|
orphans.forEach(id => {
|
|
512
|
+
// @ts-expect-error TS2339
|
|
413
513
|
hmrDelete(module.bundle.root, id);
|
|
414
514
|
});
|
|
415
515
|
} else if (bundle.parent) {
|
|
416
516
|
hmrDelete(bundle.parent, id);
|
|
417
517
|
}
|
|
418
518
|
}
|
|
419
|
-
function hmrAcceptCheck(
|
|
519
|
+
function hmrAcceptCheck(
|
|
520
|
+
// @ts-expect-error TS2304
|
|
521
|
+
bundle, id, depsByBundle) {
|
|
420
522
|
if (hmrAcceptCheckOne(bundle, id, depsByBundle)) {
|
|
421
523
|
return true;
|
|
422
524
|
}
|
|
423
525
|
|
|
424
526
|
// Traverse parents breadth first. All possible ancestries must accept the HMR update, or we'll reload.
|
|
527
|
+
// @ts-expect-error TS2339
|
|
425
528
|
let parents = getParents(module.bundle.root, id);
|
|
426
529
|
let accepted = false;
|
|
427
530
|
while (parents.length > 0) {
|
|
428
531
|
let v = parents.shift();
|
|
532
|
+
// @ts-expect-error TS18048
|
|
429
533
|
let a = hmrAcceptCheckOne(v[0], v[1], null);
|
|
430
534
|
if (a) {
|
|
431
535
|
// If this parent accepts, stop traversing upward, but still consider siblings.
|
|
432
536
|
accepted = true;
|
|
433
537
|
} else {
|
|
434
538
|
// Otherwise, queue the parents in the next level upward.
|
|
539
|
+
// @ts-expect-error TS2339
|
|
435
540
|
let p = getParents(module.bundle.root, v[1]);
|
|
436
541
|
if (p.length === 0) {
|
|
437
542
|
// If there are no parents, then we've reached an entry without accepting. Reload.
|
|
@@ -443,7 +548,9 @@ function hmrAcceptCheck(bundle /*: ParcelRequire */, id /*: string */, depsByBun
|
|
|
443
548
|
}
|
|
444
549
|
return accepted;
|
|
445
550
|
}
|
|
446
|
-
function hmrAcceptCheckOne(
|
|
551
|
+
function hmrAcceptCheckOne(
|
|
552
|
+
// @ts-expect-error TS2304
|
|
553
|
+
bundle, id, depsByBundle) {
|
|
447
554
|
var modules = bundle.modules;
|
|
448
555
|
if (!modules) {
|
|
449
556
|
return;
|
|
@@ -456,9 +563,13 @@ function hmrAcceptCheckOne(bundle /*: ParcelRequire */, id /*: string */, depsBy
|
|
|
456
563
|
}
|
|
457
564
|
return hmrAcceptCheck(bundle.parent, id, depsByBundle);
|
|
458
565
|
}
|
|
566
|
+
|
|
567
|
+
// @ts-expect-error TS7005
|
|
459
568
|
if (checkedAssets[id]) {
|
|
460
569
|
return true;
|
|
461
570
|
}
|
|
571
|
+
|
|
572
|
+
// @ts-expect-error TS7005
|
|
462
573
|
checkedAssets[id] = true;
|
|
463
574
|
var cached = bundle.cache[id];
|
|
464
575
|
assetsToDispose.push([bundle, id]);
|
|
@@ -470,28 +581,37 @@ function hmrAcceptCheckOne(bundle /*: ParcelRequire */, id /*: string */, depsBy
|
|
|
470
581
|
function hmrDisposeQueue() {
|
|
471
582
|
// Dispose all old assets.
|
|
472
583
|
for (let i = 0; i < assetsToDispose.length; i++) {
|
|
584
|
+
// @ts-expect-error TS7005
|
|
473
585
|
let id = assetsToDispose[i][1];
|
|
586
|
+
|
|
587
|
+
// @ts-expect-error TS7005
|
|
474
588
|
if (!disposedAssets[id]) {
|
|
589
|
+
// @ts-expect-error TS7005
|
|
475
590
|
hmrDispose(assetsToDispose[i][0], id);
|
|
476
591
|
disposedAssets[id] = true;
|
|
477
592
|
}
|
|
478
593
|
}
|
|
479
594
|
assetsToDispose = [];
|
|
480
595
|
}
|
|
481
|
-
function hmrDispose(
|
|
596
|
+
function hmrDispose(
|
|
597
|
+
// @ts-expect-error TS2304
|
|
598
|
+
bundle, id) {
|
|
482
599
|
var cached = bundle.cache[id];
|
|
483
600
|
bundle.hotData[id] = {};
|
|
484
601
|
if (cached && cached.hot) {
|
|
485
602
|
cached.hot.data = bundle.hotData[id];
|
|
486
603
|
}
|
|
487
604
|
if (cached && cached.hot && cached.hot._disposeCallbacks.length) {
|
|
605
|
+
// @ts-expect-error TS7006
|
|
488
606
|
cached.hot._disposeCallbacks.forEach(function (cb) {
|
|
489
607
|
cb(bundle.hotData[id]);
|
|
490
608
|
});
|
|
491
609
|
}
|
|
492
610
|
delete bundle.cache[id];
|
|
493
611
|
}
|
|
494
|
-
function hmrAccept(
|
|
612
|
+
function hmrAccept(
|
|
613
|
+
// @ts-expect-error TS2304
|
|
614
|
+
bundle, id) {
|
|
495
615
|
// Execute the module.
|
|
496
616
|
bundle(id);
|
|
497
617
|
|
|
@@ -499,16 +619,20 @@ function hmrAccept(bundle /*: ParcelRequire */, id /*: string */) {
|
|
|
499
619
|
var cached = bundle.cache[id];
|
|
500
620
|
if (cached && cached.hot && cached.hot._acceptCallbacks.length) {
|
|
501
621
|
let assetsToAlsoAccept = [];
|
|
622
|
+
// @ts-expect-error TS7006
|
|
502
623
|
cached.hot._acceptCallbacks.forEach(function (cb) {
|
|
503
624
|
let additionalAssets = cb(function () {
|
|
625
|
+
// @ts-expect-error TS2339
|
|
504
626
|
return getParents(module.bundle.root, id);
|
|
505
627
|
});
|
|
506
628
|
if (Array.isArray(additionalAssets) && additionalAssets.length) {
|
|
629
|
+
// @ts-expect-error TS2345
|
|
507
630
|
assetsToAlsoAccept.push(...additionalAssets);
|
|
508
631
|
}
|
|
509
632
|
});
|
|
510
633
|
if (assetsToAlsoAccept.length > 0) {
|
|
511
634
|
let handled = assetsToAlsoAccept.every(function (a) {
|
|
635
|
+
// @ts-expect-error TS2554
|
|
512
636
|
return hmrAcceptCheck(a[0], a[1]);
|
|
513
637
|
});
|
|
514
638
|
if (!handled) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@atlaspack/runtime-browser-hmr",
|
|
3
|
-
"version": "2.14.
|
|
3
|
+
"version": "2.14.21-typescript-08dcc1c9b.0",
|
|
4
4
|
"license": "(MIT OR Apache-2.0)",
|
|
5
5
|
"publishConfig": {
|
|
6
6
|
"access": "public"
|
|
@@ -10,13 +10,18 @@
|
|
|
10
10
|
"url": "https://github.com/atlassian-labs/atlaspack.git"
|
|
11
11
|
},
|
|
12
12
|
"main": "lib/HMRRuntime.js",
|
|
13
|
-
"source": "src/HMRRuntime.
|
|
13
|
+
"source": "src/HMRRuntime.ts",
|
|
14
14
|
"engines": {
|
|
15
15
|
"node": ">= 16.0.0"
|
|
16
16
|
},
|
|
17
17
|
"dependencies": {
|
|
18
|
-
"@atlaspack/plugin": "2.14.
|
|
19
|
-
"@atlaspack/utils": "2.17.
|
|
18
|
+
"@atlaspack/plugin": "2.14.21-typescript-08dcc1c9b.0",
|
|
19
|
+
"@atlaspack/utils": "2.17.3-typescript-08dcc1c9b.0"
|
|
20
20
|
},
|
|
21
|
-
"type": "commonjs"
|
|
21
|
+
"type": "commonjs",
|
|
22
|
+
"scripts": {
|
|
23
|
+
"check-ts": "tsc --noEmit"
|
|
24
|
+
},
|
|
25
|
+
"types": "src/HMRRuntime.ts",
|
|
26
|
+
"gitHead": "08dcc1c9bcdc6ab931d55e05ccc0f45669de2f22"
|
|
22
27
|
}
|
|
@@ -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>;
|