mirror of
https://github.com/pyscript/pyscript.git
synced 2025-12-22 19:53:00 -05:00
Improve offline dist content (#1836)
This commit is contained in:
committed by
GitHub
parent
e81830a2ea
commit
c8ec29a3d8
7
pyscript.core/src/3rd-party/README.md
vendored
Normal file
7
pyscript.core/src/3rd-party/README.md
vendored
Normal file
@@ -0,0 +1,7 @@
|
||||
# PyScript 3rd Party
|
||||
|
||||
This folder contains artifacts created via [3rd-party.cjs](../../rollup/3rd-party.cjs).
|
||||
|
||||
As we would like to offer a way to run PyScript offline, and we already offer a `dist` folder with all the necessary scripts, we have created a foreign dependencies resolver that allow to lazy-load CDN dependencies out of the box.
|
||||
|
||||
Please **note** these dependencies are **not interpreters**, because interpreters have their own mechanism, folders structure, WASM files, and whatnot, to work locally, but at least XTerm or the TOML parser, among other lazy dependencies, should be available within the dist folder.
|
||||
@@ -89,7 +89,7 @@ for (const [TYPE] of TYPES) {
|
||||
} else if (toml || type === "toml") {
|
||||
try {
|
||||
const { parse } = await import(
|
||||
/* webpackIgnore: true */ "./toml.js"
|
||||
/* webpackIgnore: true */ "./3rd-party/toml.js"
|
||||
);
|
||||
parsed = parse(text);
|
||||
} catch (e) {
|
||||
|
||||
@@ -1,9 +1,6 @@
|
||||
// PyScript py-terminal plugin
|
||||
import { TYPES, hooks } from "../core.js";
|
||||
|
||||
const CDN = "https://cdn.jsdelivr.net/npm/xterm";
|
||||
const XTERM = "5.3.0";
|
||||
const XTERM_READLINE = "1.1.1";
|
||||
const SELECTOR = [...TYPES.keys()]
|
||||
.map((type) => `script[type="${type}"][terminal],${type}-script[terminal]`)
|
||||
.join(",");
|
||||
@@ -26,22 +23,18 @@ const pyTerminal = async () => {
|
||||
if (element.matches('script[type="mpy"],mpy-script'))
|
||||
throw new Error("Unsupported terminal");
|
||||
|
||||
// import styles once and lazily (only on valid terminal)
|
||||
if (!document.querySelector(`link[href^="${CDN}"]`)) {
|
||||
document.head.append(
|
||||
Object.assign(document.createElement("link"), {
|
||||
rel: "stylesheet",
|
||||
href: `${CDN}@${XTERM}/css/xterm.min.css`,
|
||||
}),
|
||||
);
|
||||
}
|
||||
// import styles lazily
|
||||
document.head.append(
|
||||
Object.assign(document.createElement("link"), {
|
||||
rel: "stylesheet",
|
||||
href: new URL("./xterm.css", import.meta.url),
|
||||
}),
|
||||
);
|
||||
|
||||
// lazy load these only when a valid terminal is found
|
||||
const [{ Terminal }, { Readline }] = await Promise.all([
|
||||
import(/* webpackIgnore: true */ `${CDN}@${XTERM}/+esm`),
|
||||
import(
|
||||
/* webpackIgnore: true */ `${CDN}-readline@${XTERM_READLINE}/+esm`
|
||||
),
|
||||
import(/* webpackIgnore: true */ "../3rd-party/xterm.js"),
|
||||
import(/* webpackIgnore: true */ "../3rd-party/xterm-readline.js"),
|
||||
]);
|
||||
|
||||
const readline = new Readline();
|
||||
|
||||
File diff suppressed because one or more lines are too long
Reference in New Issue
Block a user