Skip to content

Commit 3657492

Browse files
Simplify even further the bridge with a fallback (#2379)
1 parent a8b8e1d commit 3657492

File tree

3 files changed

+19
-3
lines changed

3 files changed

+19
-3
lines changed

bridge/index.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,24 @@ export default (url, {
131131
// return a promise that will resolve only once the event
132132
// has been emitted and the interpreter evaluated the code
133133
const { promise, resolve } = Promise.withResolvers();
134+
135+
// ⚠️ This is just a *fallback* !!!
136+
// Please always use an explicit PyScript release !!!
137+
if (!(Symbol.for('@pyscript/core') in globalThis)) {
138+
// bring in PyScript via the `npm` developers' channel
139+
const cdn = 'https://cdn.jsdelivr.net/npm/@pyscript/core/dist';
140+
document.head.appendChild(
141+
Object.assign(
142+
document.createElement('link'),
143+
{
144+
rel: 'stylesheet',
145+
href: `${cdn}/core.css`,
146+
}
147+
)
148+
);
149+
try { await import(`${cdn}/core.js`) }
150+
catch {}
151+
}
134152
return promise;
135153
});
136154
}

bridge/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@pyscript/bridge",
3-
"version": "0.1.0",
3+
"version": "0.2.0",
44
"description": "A JS based way to use PyScript modules",
55
"type": "module",
66
"module": "./index.js",

bridge/test/index.html

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

0 commit comments

Comments
 (0)