Fix #1943 - Updated Polyscript with configURL (#1944)

This commit is contained in:
Andrea Giammarchi
2024-01-17 16:15:51 +01:00
committed by GitHub
parent 1efd73af8f
commit 7ad7f0abfb
8 changed files with 232 additions and 181 deletions

View File

@@ -63,6 +63,9 @@ for (const [TYPE] of TYPES) {
/** @type {Error | undefined} The error thrown when parsing the PyScript config, if any.*/
let error;
/** @type {string | undefined} The `configURL` field to normalize all config operations as opposite of guessing it once resolved */
let configURL;
let config,
type,
pyElement,
@@ -105,6 +108,7 @@ for (const [TYPE] of TYPES) {
if (!error && config) {
try {
const { json, toml, text, url } = await configDetails(config, type);
if (url) configURL = new URL(url, location.href).href;
config = text;
if (json || type === "json") {
try {
@@ -146,7 +150,7 @@ for (const [TYPE] of TYPES) {
// assign plugins as Promise.all only if needed
plugins = Promise.all(toBeAwaited);
configs.set(TYPE, { config: parsed, plugins, error });
configs.set(TYPE, { config: parsed, configURL, plugins, error });
}
export default configs;

View File

@@ -64,7 +64,7 @@ for (const [TYPE, interpreter] of TYPES) {
else dispatch(element, TYPE, "done");
};
const { config, plugins, error } = configs.get(TYPE);
const { config, configURL, plugins, error } = configs.get(TYPE);
// create a unique identifier when/if needed
let id = 0;
@@ -259,6 +259,7 @@ for (const [TYPE, interpreter] of TYPES) {
define(TYPE, {
config,
configURL,
interpreter,
hooks,
env: `${TYPE}-script`,