@atlaspack/runtime-js 2.13.2-dev.3682 → 2.14.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.
@@ -1,72 +0,0 @@
1
- "use strict";
2
-
3
- async function load(id) {
4
- // Global state maps the initial url to the completed task.
5
- // This ensures the same URL is used in subsequent imports
6
- if (!parcelRequire._retryState) parcelRequire._retryState = {};
7
- /** @type {Record<string, Promise<void>>} */
8
- const retryState = parcelRequire._retryState;
9
-
10
- // The number of retries before rethrowing the error
11
- const maxRetries = 6;
12
-
13
- // Resolve the request URL from the bundle ID
14
- const url = require('../bundle-manifest').resolve(id);
15
-
16
- // Wait for the user to go online before making a request
17
- if (!globalThis.navigator.onLine) {
18
- await new Promise(resolve => globalThis.addEventListener('online', resolve, {
19
- once: true
20
- }));
21
- }
22
-
23
- // If the import has not run or is not currently running
24
- // then start the import retry task. Otherwise reuse the
25
- // existing result or wait for the current task to complete
26
- if (!retryState[url]) {
27
- retryState[url] = (async () => {
28
- // Try first request with normal import circuit
29
- try {
30
- // eslint-disable-next-line no-undef
31
- return await __parcel__import__(url);
32
- } catch {
33
- /**/
34
- }
35
-
36
- // Attempt to retry request
37
- for (let i = 1; i <= maxRetries; i++) {
38
- try {
39
- // Wait for an increasing delay time
40
- const jitter = Math.round(Math.random() * 100);
41
- const delay = Math.min(Math.pow(2, i), 8) * 1000;
42
- await new Promise(resolve => setTimeout(resolve, delay + jitter));
43
-
44
- // Append the current time to the request URL
45
- // to ensure it has not been cached by the browser
46
- // eslint-disable-next-line no-undef
47
- const result = await __parcel__import__(`${url}?t=${Date.now()}`);
48
- sendAnalyticsEvent('recovered', url, i);
49
- return result;
50
- } catch (error) {
51
- if (i === maxRetries) {
52
- sendAnalyticsEvent('failure', url, i);
53
- throw error;
54
- }
55
- sendAnalyticsEvent('progress', url, i);
56
- }
57
- }
58
- })();
59
- }
60
- return retryState[url];
61
- }
62
- function sendAnalyticsEvent(status, targetUrl, attempt) {
63
- require('./analytics/analytics.js').sendAnalyticsEvent({
64
- action: 'importRetry',
65
- attributes: {
66
- status,
67
- targetUrl,
68
- attempt
69
- }
70
- });
71
- }
72
- module.exports = load;
@@ -1,7 +0,0 @@
1
- "use strict";
2
-
3
- let load = maxShards => id => {
4
- // eslint-disable-next-line no-undef
5
- return __parcel__import__(require('@atlaspack/domain-sharding').shardUrl(require('../bundle-manifest').resolve(id), maxShards));
6
- };
7
- module.exports = load;
@@ -1,7 +0,0 @@
1
- "use strict";
2
-
3
- function load(id) {
4
- // eslint-disable-next-line no-undef
5
- return __parcel__import__(require('../bundle-manifest').resolve(id));
6
- }
7
- module.exports = load;
@@ -1,8 +0,0 @@
1
- "use strict";
2
-
3
- const cacheLoader = require('../cacheLoader');
4
- module.exports = cacheLoader(function (bundle) {
5
- return fetch(bundle).then(function (res) {
6
- return res.text();
7
- });
8
- });
@@ -1,32 +0,0 @@
1
- "use strict";
2
-
3
- const cacheLoader = require('../cacheLoader');
4
- module.exports = cacheLoader(function (bundle) {
5
- return new Promise((resolve, reject) => {
6
- // Add a global function to handle when the script loads.
7
- let globalName = `i${('' + Math.random()).slice(2)}`;
8
- global[globalName] = m => {
9
- resolve(m);
10
- cleanup();
11
- };
12
-
13
- // Remove script on load or error
14
- let cleanup = () => {
15
- delete global[globalName];
16
- script.onerror = null;
17
- script.remove();
18
- };
19
-
20
- // Append an inline script tag into the document head
21
- let script = document.createElement('script');
22
- script.async = true;
23
- script.type = 'module';
24
- script.charset = 'utf-8';
25
- script.textContent = `import * as m from '${bundle}'; ${globalName}(m);`;
26
- script.onerror = function (e) {
27
- reject(e);
28
- cleanup();
29
- };
30
- document.head.appendChild(script);
31
- });
32
- });
@@ -1,35 +0,0 @@
1
- "use strict";
2
-
3
- const cacheLoader = require('../cacheLoader');
4
- module.exports = cacheLoader(function (bundle) {
5
- return new Promise(function (resolve, reject) {
6
- // Don't insert the same script twice (e.g. if it was already in the HTML)
7
- let existingScripts = document.getElementsByTagName('script');
8
- if ([].concat(existingScripts).some(function (script) {
9
- return script.src === bundle;
10
- })) {
11
- resolve();
12
- return;
13
- }
14
- var preloadLink = document.createElement('link');
15
- preloadLink.href = bundle;
16
- preloadLink.rel = 'preload';
17
- preloadLink.as = 'script';
18
- document.head.appendChild(preloadLink);
19
- var script = document.createElement('script');
20
- script.async = true;
21
- script.type = 'text/javascript';
22
- script.src = bundle;
23
- script.onerror = function (e) {
24
- var error = new TypeError(`Failed to fetch dynamically imported module: ${bundle}. Error: ${e.message}`);
25
- script.onerror = script.onload = null;
26
- script.remove();
27
- reject(error);
28
- };
29
- script.onload = function () {
30
- script.onerror = script.onload = null;
31
- resolve();
32
- };
33
- document.getElementsByTagName('head')[0].appendChild(script);
34
- });
35
- });
@@ -1,13 +0,0 @@
1
- "use strict";
2
-
3
- const cacheLoader = require('../cacheLoader');
4
- module.exports = cacheLoader(function (bundle, priority) {
5
- var link = document.createElement('link');
6
- link.rel = 'prefetch';
7
- link.href = bundle;
8
- if (priority) {
9
- link.as = priority;
10
- }
11
- document.getElementsByTagName('head')[0].appendChild(link);
12
- return Promise.resolve();
13
- }, 'prefetch');
@@ -1,14 +0,0 @@
1
- "use strict";
2
-
3
- const cacheLoader = require('../cacheLoader');
4
- module.exports = cacheLoader(function (bundle, priority, isModule) {
5
- var link = document.createElement('link');
6
- link.charset = 'utf-8';
7
- link.rel = isModule ? 'modulepreload' : 'preload';
8
- link.href = bundle;
9
- if (priority) {
10
- link.as = priority;
11
- }
12
- document.getElementsByTagName('head')[0].appendChild(link);
13
- return Promise.resolve();
14
- }, 'preload');
@@ -1,16 +0,0 @@
1
- "use strict";
2
-
3
- const cacheLoader = require('../cacheLoader');
4
- module.exports = cacheLoader(function (bundle) {
5
- return fetch(bundle).then(function (res) {
6
- if (WebAssembly.instantiateStreaming) {
7
- return WebAssembly.instantiateStreaming(res);
8
- } else {
9
- return res.arrayBuffer().then(function (data) {
10
- return WebAssembly.instantiate(data);
11
- });
12
- }
13
- }).then(function (wasmModule) {
14
- return wasmModule.instance.exports;
15
- });
16
- });
@@ -1,21 +0,0 @@
1
- "use strict";
2
-
3
- var mapping = new Map();
4
- function register( /** @type {string} */baseUrl, /** @type {Array<string>} */manifest // ['id', 'path', 'id2', 'path2']
5
- ) {
6
- for (var i = 0; i < manifest.length - 1; i += 2) {
7
- mapping.set(manifest[i], {
8
- baseUrl: baseUrl,
9
- path: manifest[i + 1]
10
- });
11
- }
12
- }
13
- function resolve(id) {
14
- var resolved = mapping.get(id);
15
- if (resolved == null) {
16
- throw new Error('Could not resolve bundle with id ' + id);
17
- }
18
- return new URL(resolved.path, resolved.baseUrl).toString();
19
- }
20
- module.exports.register = register;
21
- module.exports.resolve = resolve;
@@ -1,57 +0,0 @@
1
- "use strict";
2
-
3
- const stackTraceUrlRegexp = /(https?|file|ftp|(chrome|moz|safari-web)-extension):\/\/[^)\n]+/g;
4
- const bundleURL = {};
5
-
6
- /**
7
- * Retrieves the cached bundle URL for a given identifier.
8
- * If the URL is not cached, it computes and stores it in the cache.
9
- *
10
- * @param {string} id - The identifier for the bundle.
11
- * @param {Error?} inputError - An error object to extract the stack trace from
12
- * (for testing purposes).
13
- * @returns {string} The URL of the bundle, without file name.
14
- */
15
- function getBundleURLCached(id, inputError) {
16
- let value = bundleURL[id];
17
- if (!value) {
18
- value = getBundleURL(inputError);
19
- bundleURL[id] = value;
20
- }
21
- return value;
22
- }
23
-
24
- /** Get the URL without the filename (last / segment)
25
- *
26
- * @param {string} url
27
- * @returns {string} The URL with the file name removed
28
- */
29
- function getBaseURL(url) {
30
- return url.slice(0, url.lastIndexOf('/')) + '/';
31
- }
32
- function getBundleURL(inputError) {
33
- try {
34
- throw inputError ?? new Error();
35
- } catch (err) {
36
- var matches = ('' + err.stack).match(stackTraceUrlRegexp);
37
- if (matches) {
38
- // The first two stack frames will be this function and getBundleURLCached.
39
- // Use the 3rd one, which will be a runtime in the original bundle.
40
- return getBaseURL(matches[2]);
41
- }
42
- }
43
- return '/';
44
- }
45
-
46
- /**
47
- * @param {string} url
48
- * @returns {string}
49
- */
50
- function getOrigin(url) {
51
- return new URL(url).origin;
52
- }
53
-
54
- // TODO: convert this file to ESM once HMR issues are resolved
55
- exports.getOrigin = getOrigin;
56
- exports.getBundleURL = getBundleURLCached;
57
- exports.getBaseURL = getBaseURL;
@@ -1,27 +0,0 @@
1
- "use strict";
2
-
3
- let cachedBundles = {};
4
- let cachedPreloads = {};
5
- let cachedPrefetches = {};
6
- function getCache(type) {
7
- switch (type) {
8
- case 'preload':
9
- return cachedPreloads;
10
- case 'prefetch':
11
- return cachedPrefetches;
12
- default:
13
- return cachedBundles;
14
- }
15
- }
16
- module.exports = function (loader, type) {
17
- return function (bundle) {
18
- let cache = getCache(type);
19
- if (cache[bundle]) {
20
- return cache[bundle];
21
- }
22
- return cache[bundle] = loader.apply(null, arguments).catch(function (e) {
23
- delete cache[bundle];
24
- throw e;
25
- });
26
- };
27
- };
@@ -1,16 +0,0 @@
1
- "use strict";
2
-
3
- module.exports = function (cond, ifTrue, ifFalse) {
4
- if (typeof globalThis.__MCOND !== 'function') {
5
- throw new TypeError('"globalThis.__MCOND" was not set to an object. Ensure the function is set to return the key condition for conditional bundles to load with.');
6
- }
7
- if (typeof globalThis.__MCOND(cond) === 'undefined') {
8
- console.error(`"${cond}" did not match on globalThis.__MCOND. The conditional dependency will be loaded with the false variant.`);
9
- }
10
- try {
11
- return globalThis.__MCOND(cond) ? ifTrue() : ifFalse();
12
- } catch (err) {
13
- console.error('Conditional dependency was missing. Ensure the server sends the correct scripts to the client ("conditional-manifest.json").');
14
- throw err;
15
- }
16
- };
@@ -1,5 +0,0 @@
1
- "use strict";
2
-
3
- module.exports = function (cond, ifTrue, ifFalse) {
4
- return globalThis.__MCOND && globalThis.__MCOND(cond) ? ifTrue() : ifFalse();
5
- };
@@ -1,15 +0,0 @@
1
- "use strict";
2
-
3
- module.exports = function (workerUrl, origin, isESM) {
4
- if (origin === self.location.origin) {
5
- // If the worker bundle's url is on the same origin as the document,
6
- // use the worker bundle's own url.
7
- return workerUrl;
8
- } else {
9
- // Otherwise, create a blob URL which loads the worker bundle with `importScripts`.
10
- let source = isESM ? 'import ' + JSON.stringify(workerUrl) + ';' : 'importScripts(' + JSON.stringify(workerUrl) + ');';
11
- return URL.createObjectURL(new Blob([source], {
12
- type: 'application/javascript'
13
- }));
14
- }
15
- };
@@ -1,6 +0,0 @@
1
- "use strict";
2
-
3
- // loading a CSS style is a no-op in Node.js
4
- module.exports = function () {
5
- return Promise.resolve();
6
- };
@@ -1,19 +0,0 @@
1
- "use strict";
2
-
3
- const fs = require('fs');
4
- const cacheLoader = require('../cacheLoader');
5
- module.exports = cacheLoader(function (bundle) {
6
- return new Promise(function (resolve, reject) {
7
- fs.readFile(__dirname + bundle, 'utf8', function (err, data) {
8
- if (err) {
9
- reject(err);
10
- } else {
11
- // wait for the next event loop iteration, so we are sure
12
- // the current module is fully loaded
13
- setImmediate(function () {
14
- resolve(data);
15
- });
16
- }
17
- });
18
- });
19
- });
@@ -1,21 +0,0 @@
1
- "use strict";
2
-
3
- const fs = require('fs');
4
- const cacheLoader = require('../cacheLoader');
5
- module.exports = cacheLoader(function (bundle) {
6
- return new Promise(function (resolve, reject) {
7
- fs.readFile(__dirname + bundle, 'utf8', function (err, data) {
8
- if (err) {
9
- reject(err);
10
- } else {
11
- // wait for the next event loop iteration, so we are sure
12
- // the current module is fully loaded
13
- setImmediate(function () {
14
- resolve(data);
15
- });
16
- }
17
- });
18
- }).then(function (code) {
19
- new Function('', code)();
20
- });
21
- });
@@ -1,19 +0,0 @@
1
- "use strict";
2
-
3
- const fs = require('fs');
4
- const cacheLoader = require('../cacheLoader');
5
- module.exports = cacheLoader(function (bundle) {
6
- return new Promise(function (resolve, reject) {
7
- fs.readFile(__dirname + bundle, function (err, data) {
8
- if (err) {
9
- reject(err);
10
- } else {
11
- resolve(data.buffer);
12
- }
13
- });
14
- }).then(function (data) {
15
- return WebAssembly.instantiate(data);
16
- }).then(function (wasmModule) {
17
- return wasmModule.instance.exports;
18
- });
19
- });
@@ -1,14 +0,0 @@
1
- "use strict";
2
-
3
- /* global __parcel__importScripts__:readonly*/
4
- const cacheLoader = require('../cacheLoader');
5
- module.exports = cacheLoader(function (bundle) {
6
- return new Promise(function (resolve, reject) {
7
- try {
8
- __parcel__importScripts__(bundle);
9
- resolve();
10
- } catch (e) {
11
- reject(e);
12
- }
13
- });
14
- });
@@ -1,16 +0,0 @@
1
- "use strict";
2
-
3
- const cacheLoader = require('../cacheLoader');
4
- module.exports = cacheLoader(function (bundle) {
5
- return fetch(bundle).then(function (res) {
6
- if (WebAssembly.instantiateStreaming) {
7
- return WebAssembly.instantiateStreaming(res);
8
- } else {
9
- return res.arrayBuffer().then(function (data) {
10
- return WebAssembly.instantiate(data);
11
- });
12
- }
13
- }).then(function (wasmModule) {
14
- return wasmModule.instance.exports;
15
- });
16
- });