Simplify even further the bridge with a fallback (#2379)

This commit is contained in:
Andrea Giammarchi
2025-09-12 09:40:23 +02:00
committed by GitHub
parent a8b8e1de36
commit 3657492c52
3 changed files with 19 additions and 3 deletions

View File

@@ -131,6 +131,24 @@ export default (url, {
// return a promise that will resolve only once the event
// has been emitted and the interpreter evaluated the code
const { promise, resolve } = Promise.withResolvers();
// ⚠️ This is just a *fallback* !!!
// Please always use an explicit PyScript release !!!
if (!(Symbol.for('@pyscript/core') in globalThis)) {
// bring in PyScript via the `npm` developers' channel
const cdn = 'https://cdn.jsdelivr.net/npm/@pyscript/core/dist';
document.head.appendChild(
Object.assign(
document.createElement('link'),
{
rel: 'stylesheet',
href: `${cdn}/core.css`,
}
)
);
try { await import(`${cdn}/core.js`) }
catch {}
}
return promise;
});
}

View File

@@ -1,6 +1,6 @@
{
"name": "@pyscript/bridge",
"version": "0.1.0",
"version": "0.2.0",
"description": "A JS based way to use PyScript modules",
"type": "module",
"module": "./index.js",

View File

@@ -5,8 +5,6 @@
<meta name="viewport" content="width=device-width,initial-scale=1">
<title>PyScript Bridge</title>
<style>body { font-family: system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, 'Open Sans', 'Helvetica Neue', sans-serif; }</style>
<link rel="stylesheet" href="https://pyscript.net/releases/2025.5.1/core.css" />
<script type="module" src="https://pyscript.net/releases/2025.5.1/core.js"></script>
<!-- for local testing purpose only-->
<script type="importmap">{"imports":{"https://esm.run/@pyscript/bridge":"../index.js"}}</script>
<script type="module">