@atlaspack/runtime-browser-hmr 2.14.5-canary.137 → 2.14.5-canary.139

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