mirror of
https://github.com/pyscript/pyscript.git
synced 2025-12-19 18:27:29 -05:00
* patched an issue with wasmoon randomly asking to resolve proxy references * simplified pyodide and micropython dance by grouping their common utilities together * created an integration test around a worker to main thread input between MicroPython and Lua * commented some weird bugs / funny behaviors around both MicroPython and Pyodide * other minor clean ups
41 lines
1.3 KiB
JavaScript
41 lines
1.3 KiB
JavaScript
import { runtime } from "./runtimes.js";
|
|
import { absoluteURL, resolve } from "./utils.js";
|
|
import { parse } from "./toml.js";
|
|
import { getJSON, getText } from "./fetch-utils.js";
|
|
|
|
/**
|
|
* @param {string} id the runtime name @ version identifier
|
|
* @param {string} [config] optional config file to parse
|
|
* @returns
|
|
*/
|
|
export const getRuntime = (id, config) => {
|
|
let options = {};
|
|
if (config) {
|
|
// REQUIRES INTEGRATION TEST
|
|
/* c8 ignore start */
|
|
if (config.endsWith(".json")) {
|
|
options = fetch(config).then(getJSON);
|
|
} else if (config.endsWith(".toml")) {
|
|
options = fetch(config).then(getText).then(parse);
|
|
} else {
|
|
try {
|
|
options = JSON.parse(config);
|
|
} catch (_) {
|
|
options = parse(config);
|
|
}
|
|
// make the config a URL to be able to retrieve relative paths from it
|
|
config = absoluteURL("./config.txt");
|
|
}
|
|
/* c8 ignore stop */
|
|
}
|
|
return resolve(options).then((options) => runtime[id](options, config));
|
|
};
|
|
|
|
/**
|
|
* @param {string} type the runtime type
|
|
* @param {string} [version] the optional runtime version
|
|
* @returns
|
|
*/
|
|
export const getRuntimeID = (type, version = "") =>
|
|
`${type}@${version}`.replace(/@$/, "");
|