@atlaspack/runtime-js 2.12.1-canary.3605 → 2.12.1-canary.3607
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.
|
@@ -8,93 +8,122 @@ function load() {
|
|
|
8
8
|
return _load.apply(this, arguments);
|
|
9
9
|
}
|
|
10
10
|
function _load() {
|
|
11
|
-
_load = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function
|
|
12
|
-
var
|
|
13
|
-
return _regeneratorRuntime().wrap(function
|
|
14
|
-
while (1) switch (
|
|
11
|
+
_load = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2(id) {
|
|
12
|
+
var retryState, maxRetries, url;
|
|
13
|
+
return _regeneratorRuntime().wrap(function _callee2$(_context3) {
|
|
14
|
+
while (1) switch (_context3.prev = _context3.next) {
|
|
15
15
|
case 0:
|
|
16
|
-
url
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
break;
|
|
26
|
-
}
|
|
27
|
-
_context.next = 3;
|
|
28
|
-
return new Promise(function (resolve) {
|
|
29
|
-
return globalThis.addEventListener('online', resolve, {
|
|
30
|
-
once: true
|
|
31
|
-
});
|
|
32
|
-
});
|
|
33
|
-
case 3:
|
|
34
|
-
requestUrl = url;
|
|
35
|
-
if (i !== 0) {
|
|
36
|
-
// Date ensures the client hasn't previously cached a failed request
|
|
37
|
-
requestUrl = "".concat(requestUrl, "?retry=").concat(i, ":").concat(Date.now());
|
|
38
|
-
}
|
|
39
|
-
_context.prev = 5;
|
|
40
|
-
_context.next = 8;
|
|
41
|
-
return __parcel__import__(requestUrl);
|
|
42
|
-
case 8:
|
|
43
|
-
_context.t0 = _context.sent;
|
|
44
|
-
return _context.abrupt("return", {
|
|
45
|
-
v: _context.t0
|
|
46
|
-
});
|
|
47
|
-
case 12:
|
|
48
|
-
_context.prev = 12;
|
|
49
|
-
_context.t1 = _context["catch"](5);
|
|
50
|
-
if (!(i === maxRetries)) {
|
|
51
|
-
_context.next = 16;
|
|
52
|
-
break;
|
|
53
|
-
}
|
|
54
|
-
throw _context.t1;
|
|
55
|
-
case 16:
|
|
56
|
-
// Dispatch event for reporting
|
|
57
|
-
window.dispatchEvent(new CustomEvent('atlaspack:import_retry', {
|
|
58
|
-
detail: {
|
|
59
|
-
target: url,
|
|
60
|
-
attempt: i
|
|
61
|
-
}
|
|
62
|
-
}));
|
|
63
|
-
jitter = Math.round(Math.random() * 100);
|
|
64
|
-
delay = Math.min(Math.pow(2, i), 8) * 1000;
|
|
65
|
-
_context.next = 21;
|
|
66
|
-
return new Promise(function (resolve) {
|
|
67
|
-
return setTimeout(resolve, delay + jitter);
|
|
68
|
-
});
|
|
69
|
-
case 21:
|
|
70
|
-
case "end":
|
|
71
|
-
return _context.stop();
|
|
72
|
-
}
|
|
73
|
-
}, _loop, null, [[5, 12]]);
|
|
74
|
-
});
|
|
75
|
-
i = 1;
|
|
76
|
-
case 4:
|
|
77
|
-
if (!(i <= maxRetries)) {
|
|
78
|
-
_context2.next = 12;
|
|
16
|
+
// Global state maps the initial url to the completed task.
|
|
17
|
+
// This ensures the same URL is used in subsequent imports
|
|
18
|
+
if (!parcelRequire._retryState) parcelRequire._retryState = {};
|
|
19
|
+
/** @type {Record<string, Promise<void>>} */
|
|
20
|
+
retryState = parcelRequire._retryState; // The number of retries before rethrowing the error
|
|
21
|
+
maxRetries = 6; // Resolve the request URL from the bundle ID
|
|
22
|
+
url = require('../bundle-manifest').resolve(id); // Wait for the user to go online before making a request
|
|
23
|
+
if (globalThis.navigator.onLine) {
|
|
24
|
+
_context3.next = 7;
|
|
79
25
|
break;
|
|
80
26
|
}
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
27
|
+
_context3.next = 7;
|
|
28
|
+
return new Promise(function (resolve) {
|
|
29
|
+
return globalThis.addEventListener('online', resolve, {
|
|
30
|
+
once: true
|
|
31
|
+
});
|
|
32
|
+
});
|
|
33
|
+
case 7:
|
|
34
|
+
// If the import has not run or is not currently running
|
|
35
|
+
// then start the import retry task. Otherwise reuse the
|
|
36
|
+
// existing result or wait for the current task to complete
|
|
37
|
+
if (!retryState[url]) {
|
|
38
|
+
retryState[url] = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee() {
|
|
39
|
+
var _loop, _ret, i;
|
|
40
|
+
return _regeneratorRuntime().wrap(function _callee$(_context2) {
|
|
41
|
+
while (1) switch (_context2.prev = _context2.next) {
|
|
42
|
+
case 0:
|
|
43
|
+
_context2.prev = 0;
|
|
44
|
+
_context2.next = 3;
|
|
45
|
+
return __parcel__import__(url);
|
|
46
|
+
case 3:
|
|
47
|
+
return _context2.abrupt("return", _context2.sent);
|
|
48
|
+
case 6:
|
|
49
|
+
_context2.prev = 6;
|
|
50
|
+
_context2.t0 = _context2["catch"](0);
|
|
51
|
+
case 8:
|
|
52
|
+
_loop = /*#__PURE__*/_regeneratorRuntime().mark(function _loop() {
|
|
53
|
+
var jitter, delay, event;
|
|
54
|
+
return _regeneratorRuntime().wrap(function _loop$(_context) {
|
|
55
|
+
while (1) switch (_context.prev = _context.next) {
|
|
56
|
+
case 0:
|
|
57
|
+
_context.prev = 0;
|
|
58
|
+
// Wait for an increasing delay time
|
|
59
|
+
jitter = Math.round(Math.random() * 100);
|
|
60
|
+
delay = Math.min(Math.pow(2, i), 8) * 1000;
|
|
61
|
+
_context.next = 5;
|
|
62
|
+
return new Promise(function (resolve) {
|
|
63
|
+
return setTimeout(resolve, delay + jitter);
|
|
64
|
+
});
|
|
65
|
+
case 5:
|
|
66
|
+
_context.next = 7;
|
|
67
|
+
return __parcel__import__("".concat(url, "?t=").concat(Date.now()));
|
|
68
|
+
case 7:
|
|
69
|
+
_context.t0 = _context.sent;
|
|
70
|
+
return _context.abrupt("return", {
|
|
71
|
+
v: _context.t0
|
|
72
|
+
});
|
|
73
|
+
case 11:
|
|
74
|
+
_context.prev = 11;
|
|
75
|
+
_context.t1 = _context["catch"](0);
|
|
76
|
+
if (!(i === maxRetries)) {
|
|
77
|
+
_context.next = 15;
|
|
78
|
+
break;
|
|
79
|
+
}
|
|
80
|
+
throw _context.t1;
|
|
81
|
+
case 15:
|
|
82
|
+
// Dispatch event for reporting
|
|
83
|
+
event = {
|
|
84
|
+
detail: {
|
|
85
|
+
target: url,
|
|
86
|
+
attempt: i
|
|
87
|
+
}
|
|
88
|
+
};
|
|
89
|
+
window.dispatchEvent(new CustomEvent('atlaspack:import_retry', event));
|
|
90
|
+
case 17:
|
|
91
|
+
case "end":
|
|
92
|
+
return _context.stop();
|
|
93
|
+
}
|
|
94
|
+
}, _loop, null, [[0, 11]]);
|
|
95
|
+
});
|
|
96
|
+
i = 1;
|
|
97
|
+
case 10:
|
|
98
|
+
if (!(i <= maxRetries)) {
|
|
99
|
+
_context2.next = 18;
|
|
100
|
+
break;
|
|
101
|
+
}
|
|
102
|
+
return _context2.delegateYield(_loop(), "t1", 12);
|
|
103
|
+
case 12:
|
|
104
|
+
_ret = _context2.t1;
|
|
105
|
+
if (!_ret) {
|
|
106
|
+
_context2.next = 15;
|
|
107
|
+
break;
|
|
108
|
+
}
|
|
109
|
+
return _context2.abrupt("return", _ret.v);
|
|
110
|
+
case 15:
|
|
111
|
+
i++;
|
|
112
|
+
_context2.next = 10;
|
|
113
|
+
break;
|
|
114
|
+
case 18:
|
|
115
|
+
case "end":
|
|
116
|
+
return _context2.stop();
|
|
117
|
+
}
|
|
118
|
+
}, _callee, null, [[0, 6]]);
|
|
119
|
+
}))();
|
|
87
120
|
}
|
|
88
|
-
return
|
|
121
|
+
return _context3.abrupt("return", retryState[url]);
|
|
89
122
|
case 9:
|
|
90
|
-
i++;
|
|
91
|
-
_context2.next = 4;
|
|
92
|
-
break;
|
|
93
|
-
case 12:
|
|
94
123
|
case "end":
|
|
95
|
-
return
|
|
124
|
+
return _context3.stop();
|
|
96
125
|
}
|
|
97
|
-
},
|
|
126
|
+
}, _callee2);
|
|
98
127
|
}));
|
|
99
128
|
return _load.apply(this, arguments);
|
|
100
129
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@atlaspack/runtime-js",
|
|
3
|
-
"version": "2.12.1-canary.
|
|
3
|
+
"version": "2.12.1-canary.3607+fc7589858",
|
|
4
4
|
"license": "(MIT OR Apache-2.0)",
|
|
5
5
|
"publishConfig": {
|
|
6
6
|
"access": "public"
|
|
@@ -12,16 +12,16 @@
|
|
|
12
12
|
"main": "lib/JSRuntime.js",
|
|
13
13
|
"source": "src/JSRuntime.js",
|
|
14
14
|
"engines": {
|
|
15
|
-
"atlaspack": "2.12.1-canary.
|
|
15
|
+
"atlaspack": "2.12.1-canary.3607+fc7589858",
|
|
16
16
|
"node": ">= 16.0.0"
|
|
17
17
|
},
|
|
18
18
|
"dependencies": {
|
|
19
|
-
"@atlaspack/diagnostic": "2.12.1-canary.
|
|
20
|
-
"@atlaspack/domain-sharding": "2.12.1-canary.
|
|
21
|
-
"@atlaspack/feature-flags": "2.12.1-canary.
|
|
22
|
-
"@atlaspack/plugin": "2.12.1-canary.
|
|
23
|
-
"@atlaspack/utils": "2.12.1-canary.
|
|
19
|
+
"@atlaspack/diagnostic": "2.12.1-canary.3607+fc7589858",
|
|
20
|
+
"@atlaspack/domain-sharding": "2.12.1-canary.3607+fc7589858",
|
|
21
|
+
"@atlaspack/feature-flags": "2.12.1-canary.3607+fc7589858",
|
|
22
|
+
"@atlaspack/plugin": "2.12.1-canary.3607+fc7589858",
|
|
23
|
+
"@atlaspack/utils": "2.12.1-canary.3607+fc7589858",
|
|
24
24
|
"nullthrows": "^1.1.1"
|
|
25
25
|
},
|
|
26
|
-
"gitHead": "
|
|
26
|
+
"gitHead": "fc7589858cb8a7330b6ce2c389eb89917a143237"
|
|
27
27
|
}
|
|
@@ -1,42 +1,61 @@
|
|
|
1
1
|
async function load(id) {
|
|
2
|
-
|
|
2
|
+
// Global state maps the initial url to the completed task.
|
|
3
|
+
// This ensures the same URL is used in subsequent imports
|
|
4
|
+
if (!parcelRequire._retryState) parcelRequire._retryState = {};
|
|
5
|
+
/** @type {Record<string, Promise<void>>} */
|
|
6
|
+
const retryState = parcelRequire._retryState;
|
|
3
7
|
|
|
8
|
+
// The number of retries before rethrowing the error
|
|
4
9
|
const maxRetries = 6;
|
|
5
10
|
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
//
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
11
|
+
// Resolve the request URL from the bundle ID
|
|
12
|
+
const url = require('../bundle-manifest').resolve(id);
|
|
13
|
+
|
|
14
|
+
// Wait for the user to go online before making a request
|
|
15
|
+
if (!globalThis.navigator.onLine) {
|
|
16
|
+
await new Promise((resolve) =>
|
|
17
|
+
globalThis.addEventListener('online', resolve, {once: true}),
|
|
18
|
+
);
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
// If the import has not run or is not currently running
|
|
22
|
+
// then start the import retry task. Otherwise reuse the
|
|
23
|
+
// existing result or wait for the current task to complete
|
|
24
|
+
if (!retryState[url]) {
|
|
25
|
+
retryState[url] = (async () => {
|
|
26
|
+
// Try first request with normal import circuit
|
|
27
|
+
try {
|
|
28
|
+
// eslint-disable-next-line no-undef
|
|
29
|
+
return await __parcel__import__(url);
|
|
30
|
+
} catch {
|
|
31
|
+
/**/
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
// Attempt to retry request
|
|
35
|
+
for (let i = 1; i <= maxRetries; i++) {
|
|
36
|
+
try {
|
|
37
|
+
// Wait for an increasing delay time
|
|
38
|
+
const jitter = Math.round(Math.random() * 100);
|
|
39
|
+
const delay = Math.min(Math.pow(2, i), 8) * 1000;
|
|
40
|
+
await new Promise((resolve) => setTimeout(resolve, delay + jitter));
|
|
41
|
+
|
|
42
|
+
// Append the current time to the request URL
|
|
43
|
+
// to ensure it has not been cached by the browser
|
|
44
|
+
// eslint-disable-next-line no-undef
|
|
45
|
+
return await __parcel__import__(`${url}?t=${Date.now()}`);
|
|
46
|
+
} catch (error) {
|
|
47
|
+
if (i === maxRetries) throw error;
|
|
48
|
+
// Dispatch event for reporting
|
|
49
|
+
const event = {detail: {target: url, attempt: i}};
|
|
50
|
+
window.dispatchEvent(
|
|
51
|
+
new CustomEvent('atlaspack:import_retry', event),
|
|
52
|
+
);
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
})();
|
|
39
56
|
}
|
|
57
|
+
|
|
58
|
+
return retryState[url];
|
|
40
59
|
}
|
|
41
60
|
|
|
42
61
|
module.exports = load;
|