@atlaspack/runtime-js 2.12.1-canary.3354
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/LICENSE +201 -0
- package/lib/JSRuntime.js +562 -0
- package/lib/helpers/browser/css-loader.js +28 -0
- package/lib/helpers/browser/esm-js-loader-retry.js +51 -0
- package/lib/helpers/browser/esm-js-loader.js +7 -0
- package/lib/helpers/browser/html-loader.js +8 -0
- package/lib/helpers/browser/import-polyfill.js +32 -0
- package/lib/helpers/browser/js-loader.js +35 -0
- package/lib/helpers/browser/prefetch-loader.js +13 -0
- package/lib/helpers/browser/preload-loader.js +14 -0
- package/lib/helpers/browser/wasm-loader.js +16 -0
- package/lib/helpers/bundle-manifest.js +20 -0
- package/lib/helpers/bundle-url.js +39 -0
- package/lib/helpers/cacheLoader.js +27 -0
- package/lib/helpers/get-worker-url.js +15 -0
- package/lib/helpers/node/css-loader.js +6 -0
- package/lib/helpers/node/html-loader.js +19 -0
- package/lib/helpers/node/js-loader.js +21 -0
- package/lib/helpers/node/wasm-loader.js +19 -0
- package/lib/helpers/worker/js-loader.js +14 -0
- package/lib/helpers/worker/wasm-loader.js +16 -0
- package/package.json +25 -0
- package/src/JSRuntime.js +742 -0
- package/src/helpers/.babelrc +9 -0
- package/src/helpers/.eslintrc.json +3 -0
- package/src/helpers/browser/css-loader.js +32 -0
- package/src/helpers/browser/esm-js-loader-retry.js +26 -0
- package/src/helpers/browser/esm-js-loader.js +6 -0
- package/src/helpers/browser/html-loader.js +7 -0
- package/src/helpers/browser/import-polyfill.js +32 -0
- package/src/helpers/browser/js-loader.js +42 -0
- package/src/helpers/browser/prefetch-loader.js +13 -0
- package/src/helpers/browser/preload-loader.js +19 -0
- package/src/helpers/browser/wasm-loader.js +17 -0
- package/src/helpers/bundle-manifest.js +21 -0
- package/src/helpers/bundle-url.js +51 -0
- package/src/helpers/cacheLoader.js +29 -0
- package/src/helpers/get-worker-url.js +15 -0
- package/src/helpers/node/css-loader.js +4 -0
- package/src/helpers/node/html-loader.js +18 -0
- package/src/helpers/node/js-loader.js +20 -0
- package/src/helpers/node/wasm-loader.js +20 -0
- package/src/helpers/worker/js-loader.js +13 -0
- package/src/helpers/worker/wasm-loader.js +17 -0
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var cacheLoader = require('../cacheLoader');
|
|
4
|
+
module.exports = cacheLoader(function (bundle) {
|
|
5
|
+
return new Promise(function (resolve, reject) {
|
|
6
|
+
// Add a global function to handle when the script loads.
|
|
7
|
+
var globalName = "i".concat(('' + Math.random()).slice(2));
|
|
8
|
+
global[globalName] = function (m) {
|
|
9
|
+
resolve(m);
|
|
10
|
+
cleanup();
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
// Remove script on load or error
|
|
14
|
+
var cleanup = function () {
|
|
15
|
+
delete global[globalName];
|
|
16
|
+
script.onerror = null;
|
|
17
|
+
script.remove();
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
// Append an inline script tag into the document head
|
|
21
|
+
var script = document.createElement('script');
|
|
22
|
+
script.async = true;
|
|
23
|
+
script.type = 'module';
|
|
24
|
+
script.charset = 'utf-8';
|
|
25
|
+
script.textContent = "import * as m from '".concat(bundle, "'; ").concat(globalName, "(m);");
|
|
26
|
+
script.onerror = function (e) {
|
|
27
|
+
reject(e);
|
|
28
|
+
cleanup();
|
|
29
|
+
};
|
|
30
|
+
document.head.appendChild(script);
|
|
31
|
+
});
|
|
32
|
+
});
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var 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
|
+
var existingScripts = document.getElementsByTagName('script');
|
|
8
|
+
if ([].concat(existingScripts).some(function isCurrentBundle(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: ".concat(bundle, ". Error: ").concat(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
|
+
});
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var 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');
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var 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');
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var 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
|
+
});
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var mapping = new Map();
|
|
4
|
+
function register(baseUrl, manifest) {
|
|
5
|
+
for (var i = 0; i < manifest.length - 1; i += 2) {
|
|
6
|
+
mapping.set(manifest[i], {
|
|
7
|
+
baseUrl: baseUrl,
|
|
8
|
+
path: manifest[i + 1]
|
|
9
|
+
});
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
function resolve(id) {
|
|
13
|
+
var resolved = mapping.get(id);
|
|
14
|
+
if (resolved == null) {
|
|
15
|
+
throw new Error('Could not resolve bundle with id ' + id);
|
|
16
|
+
}
|
|
17
|
+
return new URL(resolved.path, resolved.baseUrl).toString();
|
|
18
|
+
}
|
|
19
|
+
module.exports.register = register;
|
|
20
|
+
module.exports.resolve = resolve;
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var bundleURL = {};
|
|
4
|
+
function getBundleURLCached(id) {
|
|
5
|
+
var value = bundleURL[id];
|
|
6
|
+
if (!value) {
|
|
7
|
+
value = getBundleURL();
|
|
8
|
+
bundleURL[id] = value;
|
|
9
|
+
}
|
|
10
|
+
return value;
|
|
11
|
+
}
|
|
12
|
+
function getBundleURL() {
|
|
13
|
+
try {
|
|
14
|
+
throw new Error();
|
|
15
|
+
} catch (err) {
|
|
16
|
+
var matches = ('' + err.stack).match(/(https?|file|ftp|(chrome|moz|safari-web)-extension):\/\/[^)\n]+/g);
|
|
17
|
+
if (matches) {
|
|
18
|
+
// The first two stack frames will be this function and getBundleURLCached.
|
|
19
|
+
// Use the 3rd one, which will be a runtime in the original bundle.
|
|
20
|
+
return getBaseURL(matches[2]);
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
return '/';
|
|
24
|
+
}
|
|
25
|
+
function getBaseURL(url) {
|
|
26
|
+
return ('' + url).replace(/^((?:https?|file|ftp|(chrome|moz|safari-web)-extension):\/\/.+)\/[^/]+$/, '$1') + '/';
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
// TODO: Replace uses with `new URL(url).origin` when ie11 is no longer supported.
|
|
30
|
+
function getOrigin(url) {
|
|
31
|
+
var matches = ('' + url).match(/(https?|file|ftp|(chrome|moz|safari-web)-extension):\/\/[^/]+/);
|
|
32
|
+
if (!matches) {
|
|
33
|
+
throw new Error('Origin not found');
|
|
34
|
+
}
|
|
35
|
+
return matches[0];
|
|
36
|
+
}
|
|
37
|
+
exports.getBundleURL = getBundleURLCached;
|
|
38
|
+
exports.getBaseURL = getBaseURL;
|
|
39
|
+
exports.getOrigin = getOrigin;
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var cachedBundles = {};
|
|
4
|
+
var cachedPreloads = {};
|
|
5
|
+
var 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
|
+
var 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
|
+
};
|
|
@@ -0,0 +1,15 @@
|
|
|
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
|
+
var source = isESM ? 'import ' + JSON.stringify(workerUrl) + ';' : 'importScripts(' + JSON.stringify(workerUrl) + ');';
|
|
11
|
+
return URL.createObjectURL(new Blob([source], {
|
|
12
|
+
type: 'application/javascript'
|
|
13
|
+
}));
|
|
14
|
+
}
|
|
15
|
+
};
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var fs = require('fs');
|
|
4
|
+
var 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
|
+
});
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var fs = require('fs');
|
|
4
|
+
var 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
|
+
});
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var fs = require('fs');
|
|
4
|
+
var 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
|
+
});
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
/* global __atlaspack__importScripts__:readonly*/
|
|
4
|
+
var cacheLoader = require('../cacheLoader');
|
|
5
|
+
module.exports = cacheLoader(function (bundle) {
|
|
6
|
+
return new Promise(function (resolve, reject) {
|
|
7
|
+
try {
|
|
8
|
+
__atlaspack__importScripts__(bundle);
|
|
9
|
+
resolve();
|
|
10
|
+
} catch (e) {
|
|
11
|
+
reject(e);
|
|
12
|
+
}
|
|
13
|
+
});
|
|
14
|
+
});
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var 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
|
+
});
|
package/package.json
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@atlaspack/runtime-js",
|
|
3
|
+
"version": "2.12.1-canary.3354+7bb54d46a",
|
|
4
|
+
"license": "MIT",
|
|
5
|
+
"publishConfig": {
|
|
6
|
+
"access": "public"
|
|
7
|
+
},
|
|
8
|
+
"repository": {
|
|
9
|
+
"type": "git",
|
|
10
|
+
"url": "https://github.com/atlassian-labs/atlaspack.git"
|
|
11
|
+
},
|
|
12
|
+
"main": "lib/JSRuntime.js",
|
|
13
|
+
"source": "src/JSRuntime.js",
|
|
14
|
+
"engines": {
|
|
15
|
+
"node": ">= 16.0.0",
|
|
16
|
+
"atlaspack": "2.12.1-canary.3354+7bb54d46a"
|
|
17
|
+
},
|
|
18
|
+
"dependencies": {
|
|
19
|
+
"@atlaspack/diagnostic": "2.12.1-canary.3354+7bb54d46a",
|
|
20
|
+
"@atlaspack/plugin": "2.12.1-canary.3354+7bb54d46a",
|
|
21
|
+
"@atlaspack/utils": "2.12.1-canary.3354+7bb54d46a",
|
|
22
|
+
"nullthrows": "^1.1.1"
|
|
23
|
+
},
|
|
24
|
+
"gitHead": "7bb54d46a00c5ba9cdbc2ee426dcbe82c8d79a3e"
|
|
25
|
+
}
|