@atlaspack/runtime-js 2.14.5-canary.47 → 2.14.5-canary.470
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 +580 -0
- package/dist/JSRuntime.js +963 -0
- package/lib/JSRuntime.js +425 -42
- package/lib/helpers/browser/analytics/analytics.d.js +1 -0
- package/lib/helpers/browser/css-loader.js +4 -3
- package/lib/helpers/browser/html-loader.js +1 -1
- package/lib/helpers/browser/import-polyfill.js +1 -1
- package/lib/helpers/browser/js-loader.js +4 -3
- package/lib/helpers/browser/prefetch-loader.js +1 -1
- package/lib/helpers/browser/preload-loader.js +1 -1
- package/lib/helpers/browser/sync-js-loader.js +32 -0
- package/lib/helpers/browser/wasm-loader.js +1 -1
- package/lib/helpers/bundle-manifest.js +1 -1
- package/lib/helpers/cacheLoader.js +1 -1
- package/lib/helpers/conditional-loader-dev.js +12 -3
- package/lib/helpers/conditional-loader.js +22 -2
- package/lib/helpers/get-worker-url.js +1 -1
- package/lib/helpers/node/css-loader.js +1 -1
- package/lib/helpers/node/html-loader.js +1 -1
- package/lib/helpers/node/js-loader.js +1 -1
- package/lib/helpers/node/wasm-loader.js +1 -1
- package/lib/helpers/worker/js-loader.js +1 -1
- package/lib/helpers/worker/wasm-loader.js +1 -1
- package/lib/types/JSRuntime.d.ts +9 -0
- package/package.json +15 -10
- package/src/{JSRuntime.js → JSRuntime.ts} +520 -113
- package/src/helpers/browser/preload-loader.js +1 -2
- package/src/helpers/browser/sync-js-loader.js +37 -0
- package/src/helpers/conditional-loader-dev.js +17 -3
- package/src/helpers/conditional-loader.js +24 -2
- package/test/analytics.test.ts +4 -1
- package/test/{bundle-url.test.js → bundle-url.test.ts} +1 -2
- package/test/esm-js-loader-retry.test.ts +4 -7
- package/tsconfig.json +27 -0
- package/tsconfig.tsbuildinfo +1 -0
- package/src/helpers/browser/analytics/analytics.js.flow +0 -10
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";
|
|
@@ -1,13 +1,14 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
3
|
const cacheLoader = require('../cacheLoader');
|
|
4
|
-
module.exports = cacheLoader(function (bundle) {
|
|
4
|
+
module.exports = cacheLoader(function loadCSSBundle(bundle) {
|
|
5
5
|
return new Promise(function (resolve, reject) {
|
|
6
6
|
// Don't insert the same link element twice (e.g. if it was already in the HTML)
|
|
7
7
|
let existingLinks = document.getElementsByTagName('link');
|
|
8
|
-
|
|
8
|
+
let isCurrentBundle = function (link) {
|
|
9
9
|
return link.href === bundle && link.rel.indexOf('stylesheet') > -1;
|
|
10
|
-
}
|
|
10
|
+
};
|
|
11
|
+
if ([].concat(existingLinks).some(isCurrentBundle)) {
|
|
11
12
|
resolve();
|
|
12
13
|
return;
|
|
13
14
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
3
|
const cacheLoader = require('../cacheLoader');
|
|
4
|
-
module.exports = cacheLoader(function (bundle) {
|
|
4
|
+
module.exports = cacheLoader(function importModule(bundle) {
|
|
5
5
|
return new Promise((resolve, reject) => {
|
|
6
6
|
// Add a global function to handle when the script loads.
|
|
7
7
|
let globalName = `i${('' + Math.random()).slice(2)}`;
|
|
@@ -1,13 +1,14 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
3
|
const cacheLoader = require('../cacheLoader');
|
|
4
|
-
module.exports = cacheLoader(function (bundle) {
|
|
4
|
+
module.exports = cacheLoader(function loadJSBundle(bundle) {
|
|
5
5
|
return new Promise(function (resolve, reject) {
|
|
6
6
|
// Don't insert the same script twice (e.g. if it was already in the HTML)
|
|
7
7
|
let existingScripts = document.getElementsByTagName('script');
|
|
8
|
-
|
|
8
|
+
let isCurrentBundle = function (script) {
|
|
9
9
|
return script.src === bundle;
|
|
10
|
-
}
|
|
10
|
+
};
|
|
11
|
+
if ([].concat(existingScripts).some(isCurrentBundle)) {
|
|
11
12
|
resolve();
|
|
12
13
|
return;
|
|
13
14
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
3
|
const cacheLoader = require('../cacheLoader');
|
|
4
|
-
module.exports = cacheLoader(function (bundle, priority) {
|
|
4
|
+
module.exports = cacheLoader(function prefetchJSBundle(bundle, priority) {
|
|
5
5
|
var link = document.createElement('link');
|
|
6
6
|
link.rel = 'prefetch';
|
|
7
7
|
link.href = bundle;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
3
|
const cacheLoader = require('../cacheLoader');
|
|
4
|
-
module.exports = cacheLoader(function (bundle, priority, isModule) {
|
|
4
|
+
module.exports = cacheLoader(function preloadJSBundle(bundle, priority, isModule) {
|
|
5
5
|
var link = document.createElement('link');
|
|
6
6
|
link.charset = 'utf-8';
|
|
7
7
|
link.rel = isModule ? 'modulepreload' : 'preload';
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
module.exports = function loadJSBundle(bundle) {
|
|
4
|
+
// Don't insert the same script twice (e.g. if it was already in the HTML)
|
|
5
|
+
let existingScripts = document.getElementsByTagName('script');
|
|
6
|
+
let isCurrentBundle = function (script) {
|
|
7
|
+
return script.src === bundle;
|
|
8
|
+
};
|
|
9
|
+
if ([].concat(existingScripts).some(isCurrentBundle)) {
|
|
10
|
+
return;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
// Request using XHR because it's synchronous and we can't use promises here
|
|
14
|
+
// This has extremely poor performance because we're idle during this fetch, so we only use this so that the app won't crash
|
|
15
|
+
const xhr = new XMLHttpRequest();
|
|
16
|
+
xhr.open('GET', bundle, false);
|
|
17
|
+
try {
|
|
18
|
+
xhr.send();
|
|
19
|
+
if (xhr.status === 200) {
|
|
20
|
+
const script = document.createElement('script');
|
|
21
|
+
script.type = 'text/javascript';
|
|
22
|
+
script.text = xhr.responseText;
|
|
23
|
+
|
|
24
|
+
// Execute the script synchronously
|
|
25
|
+
document.head.appendChild(script);
|
|
26
|
+
} else {
|
|
27
|
+
throw new TypeError(`Failed to fetch dynamically imported module: ${bundle}. Status: ${xhr.status}`);
|
|
28
|
+
}
|
|
29
|
+
} catch (e) {
|
|
30
|
+
throw new TypeError(`Failed to fetch dynamically imported module: ${bundle}. Error: ${e.message}`);
|
|
31
|
+
}
|
|
32
|
+
};
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
3
|
const cacheLoader = require('../cacheLoader');
|
|
4
|
-
module.exports = cacheLoader(function (bundle) {
|
|
4
|
+
module.exports = cacheLoader(function loadWASMBundle(bundle) {
|
|
5
5
|
return fetch(bundle).then(function (res) {
|
|
6
6
|
if (WebAssembly.instantiateStreaming) {
|
|
7
7
|
return WebAssembly.instantiateStreaming(res);
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
3
|
var mapping = new Map();
|
|
4
|
-
function register(
|
|
4
|
+
function register(/** @type {string} */baseUrl, /** @type {Array<string>} */manifest // ['id', 'path', 'id2', 'path2']
|
|
5
5
|
) {
|
|
6
6
|
for (var i = 0; i < manifest.length - 1; i += 2) {
|
|
7
7
|
mapping.set(manifest[i], {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
-
module.exports = function (cond, ifTrue, ifFalse) {
|
|
3
|
+
module.exports = function loadCond(cond, ifTrue, ifFalse, fallback) {
|
|
4
4
|
if (typeof globalThis.__MCOND !== 'function') {
|
|
5
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
6
|
}
|
|
@@ -10,7 +10,16 @@ module.exports = function (cond, ifTrue, ifFalse) {
|
|
|
10
10
|
try {
|
|
11
11
|
return globalThis.__MCOND(cond) ? ifTrue() : ifFalse();
|
|
12
12
|
} catch (err) {
|
|
13
|
-
console.error('Conditional dependency was
|
|
14
|
-
|
|
13
|
+
console.error('Conditional dependency was not registered when executing. Ensure the server sends the correct scripts to the client. Falling back to synchronous bundle loading.');
|
|
14
|
+
if (fallback) {
|
|
15
|
+
globalThis.__ATLASPACK_ERRORS = globalThis.__ATLASPACK_ERRORS || [];
|
|
16
|
+
globalThis.__ATLASPACK_ERRORS.push(new Error(`Sync dependency fallback triggered for condition "${cond}": ${err.message}`));
|
|
17
|
+
for (const url of fallback.urls) {
|
|
18
|
+
fallback.l(url);
|
|
19
|
+
}
|
|
20
|
+
return globalThis.__MCOND(cond) ? ifTrue() : ifFalse();
|
|
21
|
+
} else {
|
|
22
|
+
throw new Error('No fallback urls specified, cannot fallback safely');
|
|
23
|
+
}
|
|
15
24
|
}
|
|
16
25
|
};
|
|
@@ -1,5 +1,25 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
3
|
+
const {
|
|
4
|
+
getBundleURL
|
|
5
|
+
} = require('./bundle-url');
|
|
6
|
+
const {
|
|
7
|
+
resolve
|
|
8
|
+
} = require('./bundle-manifest');
|
|
9
|
+
module.exports = function loadCond(cond, ifTrue, ifFalse, fallback) {
|
|
10
|
+
let result = globalThis.__MCOND(cond);
|
|
11
|
+
try {
|
|
12
|
+
return result ? ifTrue() : ifFalse();
|
|
13
|
+
} catch (err) {
|
|
14
|
+
if (fallback) {
|
|
15
|
+
globalThis.__ATLASPACK_ERRORS = globalThis.__ATLASPACK_ERRORS || [];
|
|
16
|
+
globalThis.__ATLASPACK_ERRORS.push(new Error(`Sync dependency fallback triggered for condition "${cond}": ${err.message}`));
|
|
17
|
+
for (const id of fallback.i) {
|
|
18
|
+
fallback.l(new URL(resolve(id), getBundleURL(id)).toString());
|
|
19
|
+
}
|
|
20
|
+
return result ? ifTrue() : ifFalse();
|
|
21
|
+
} else {
|
|
22
|
+
throw err;
|
|
23
|
+
}
|
|
24
|
+
}
|
|
5
25
|
};
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
-
module.exports = function (workerUrl, origin, isESM) {
|
|
3
|
+
module.exports = function loadWorker(workerUrl, origin, isESM) {
|
|
4
4
|
if (origin === self.location.origin) {
|
|
5
5
|
// If the worker bundle's url is on the same origin as the document,
|
|
6
6
|
// use the worker bundle's own url.
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
const fs = require('fs');
|
|
4
4
|
const cacheLoader = require('../cacheLoader');
|
|
5
|
-
module.exports = cacheLoader(function (bundle) {
|
|
5
|
+
module.exports = cacheLoader(function loadHTMLBundle(bundle) {
|
|
6
6
|
return new Promise(function (resolve, reject) {
|
|
7
7
|
fs.readFile(__dirname + bundle, 'utf8', function (err, data) {
|
|
8
8
|
if (err) {
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
const fs = require('fs');
|
|
4
4
|
const cacheLoader = require('../cacheLoader');
|
|
5
|
-
module.exports = cacheLoader(function (bundle) {
|
|
5
|
+
module.exports = cacheLoader(function loadJSBundle(bundle) {
|
|
6
6
|
return new Promise(function (resolve, reject) {
|
|
7
7
|
fs.readFile(__dirname + bundle, 'utf8', function (err, data) {
|
|
8
8
|
if (err) {
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
const fs = require('fs');
|
|
4
4
|
const cacheLoader = require('../cacheLoader');
|
|
5
|
-
module.exports = cacheLoader(function (bundle) {
|
|
5
|
+
module.exports = cacheLoader(function loadWASMBundle(bundle) {
|
|
6
6
|
return new Promise(function (resolve, reject) {
|
|
7
7
|
fs.readFile(__dirname + bundle, function (err, data) {
|
|
8
8
|
if (err) {
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
/* global __parcel__importScripts__:readonly*/
|
|
4
4
|
const cacheLoader = require('../cacheLoader');
|
|
5
|
-
module.exports = cacheLoader(function (bundle) {
|
|
5
|
+
module.exports = cacheLoader(function loadJSBundle(bundle) {
|
|
6
6
|
return new Promise(function (resolve, reject) {
|
|
7
7
|
try {
|
|
8
8
|
__parcel__importScripts__(bundle);
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
3
|
const cacheLoader = require('../cacheLoader');
|
|
4
|
-
module.exports = cacheLoader(function (bundle) {
|
|
4
|
+
module.exports = cacheLoader(function loadWASMBundle(bundle) {
|
|
5
5
|
return fetch(bundle).then(function (res) {
|
|
6
6
|
if (WebAssembly.instantiateStreaming) {
|
|
7
7
|
return WebAssembly.instantiateStreaming(res);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@atlaspack/runtime-js",
|
|
3
|
-
"version": "2.14.5-canary.
|
|
3
|
+
"version": "2.14.5-canary.470+7e1b48866",
|
|
4
4
|
"license": "(MIT OR Apache-2.0)",
|
|
5
5
|
"publishConfig": {
|
|
6
6
|
"access": "public"
|
|
@@ -9,19 +9,24 @@
|
|
|
9
9
|
"type": "git",
|
|
10
10
|
"url": "https://github.com/atlassian-labs/atlaspack.git"
|
|
11
11
|
},
|
|
12
|
-
"main": "lib/JSRuntime.js",
|
|
13
|
-
"source": "src/JSRuntime.
|
|
12
|
+
"main": "./lib/JSRuntime.js",
|
|
13
|
+
"source": "./src/JSRuntime.ts",
|
|
14
|
+
"types": "./lib/types/JSRuntime.d.ts",
|
|
14
15
|
"engines": {
|
|
15
16
|
"node": ">= 16.0.0"
|
|
16
17
|
},
|
|
17
18
|
"dependencies": {
|
|
18
|
-
"@atlaspack/diagnostic": "2.14.1-canary.
|
|
19
|
-
"@atlaspack/domain-sharding": "2.14.1-canary.
|
|
20
|
-
"@atlaspack/feature-flags": "2.14.1-canary.
|
|
21
|
-
"@atlaspack/plugin": "2.14.5-canary.
|
|
22
|
-
"@atlaspack/
|
|
19
|
+
"@atlaspack/diagnostic": "2.14.1-canary.538+7e1b48866",
|
|
20
|
+
"@atlaspack/domain-sharding": "2.14.1-canary.538+7e1b48866",
|
|
21
|
+
"@atlaspack/feature-flags": "2.14.1-canary.538+7e1b48866",
|
|
22
|
+
"@atlaspack/plugin": "2.14.5-canary.470+7e1b48866",
|
|
23
|
+
"@atlaspack/types-internal": "2.14.1-canary.538+7e1b48866",
|
|
24
|
+
"@atlaspack/utils": "2.14.5-canary.470+7e1b48866",
|
|
23
25
|
"nullthrows": "^1.1.1"
|
|
24
26
|
},
|
|
25
27
|
"type": "commonjs",
|
|
26
|
-
"
|
|
27
|
-
|
|
28
|
+
"scripts": {
|
|
29
|
+
"build:lib": "gulp build --gulpfile ../../../gulpfile.js --cwd ."
|
|
30
|
+
},
|
|
31
|
+
"gitHead": "7e1b48866a6bce2f7e9f3f8705ac3fe99c550707"
|
|
32
|
+
}
|