mirror of
https://github.com/pyscript/pyscript.git
synced 2025-12-21 03:05:38 -05:00
* kill unwrapped_remote (#1490) * kill unwrapped_remote * linting * don't use callKwargs for python plugins * fix tests and improve types * Bringing PyScript.next PoC to the main project * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --------- Co-authored-by: Madhur Tandon <20173739+madhur-tandon@users.noreply.github.com> Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
40 lines
1.3 KiB
JavaScript
40 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(/@$/, "");
|