[next] Cumulative pre-release patches (#1682)

This commit is contained in:
Andrea Giammarchi
2023-09-07 15:17:09 +02:00
committed by GitHub
parent d56eeb59ed
commit 0696e4682d
6 changed files with 86 additions and 32 deletions

View File

@@ -1,7 +1,6 @@
import "@ungap/with-resolvers";
import { $ } from "basic-devtools";
import { define, XWorker } from "polyscript";
import { htmlDecode } from "./utils.js";
import sync from "./sync.js";
import stdlib from "./stdlib.js";
@@ -10,6 +9,7 @@ import plugins from "./plugins.js";
// TODO: this is not strictly polyscript related but handy ... not sure
// we should factor this utility out a part but this works anyway.
import { queryTarget } from "../node_modules/polyscript/esm/script-handler.js";
import { dedent } from "../node_modules/polyscript/esm/utils.js";
import { Hook } from "../node_modules/polyscript/esm/worker/hooks.js";
import { robustFetch as fetch } from "./fetch.js";
@@ -65,14 +65,14 @@ const fetchSource = async (tag, io, asText) => {
}
}
if (asText) return tag.textContent;
if (asText) return dedent(tag.textContent);
console.warn(
'Deprecated: use <script type="py"> for an always safe content parsing:\n',
tag.innerHTML,
);
return htmlDecode(tag.innerHTML);
return dedent(tag.innerHTML);
};
// common life-cycle handlers for any node
@@ -128,14 +128,19 @@ export const hooks = {
const workerHooks = {
codeBeforeRunWorker: () =>
[stdlib, ...hooks.codeBeforeRunWorker].join("\n"),
[stdlib, ...hooks.codeBeforeRunWorker].map(dedent).join("\n"),
codeBeforeRunWorkerAsync: () =>
[stdlib, ...hooks.codeBeforeRunWorkerAsync].join("\n"),
codeAfterRunWorker: () => [...hooks.codeAfterRunWorker].join("\n"),
[stdlib, ...hooks.codeBeforeRunWorkerAsync].map(dedent).join("\n"),
codeAfterRunWorker: () =>
[...hooks.codeAfterRunWorker].map(dedent).join("\n"),
codeAfterRunWorkerAsync: () =>
[...hooks.codeAfterRunWorkerAsync].join("\n"),
[...hooks.codeAfterRunWorkerAsync].map(dedent).join("\n"),
};
// avoid running further script if the previous one had
// some import that would inevitably delay its execution
let queuePlugins;
// define the module as both `<script type="py">` and `<py-script>`
define("py", {
config,
@@ -172,7 +177,14 @@ define("py", {
toBeAwaited.push(value());
}
if (toBeAwaited.length) await Promise.all(toBeAwaited);
// this grants queued results when first script/tag has plugins
// and the second one *might* rely on first tag execution
if (toBeAwaited.length) {
const all = Promise.all(toBeAwaited);
queuePlugins = queuePlugins ? queuePlugins.then(() => all) : all;
}
if (queuePlugins) await queuePlugins;
// allows plugins to do whatever they want with the element
// before regular stuff happens in here