From 3657492c528a54fc2d16d1596818d7eb75f18fc0 Mon Sep 17 00:00:00 2001 From: Andrea Giammarchi Date: Fri, 12 Sep 2025 09:40:23 +0200 Subject: [PATCH] Simplify even further the bridge with a fallback (#2379) --- bridge/index.js | 18 ++++++++++++++++++ bridge/package.json | 2 +- bridge/test/index.html | 2 -- 3 files changed, 19 insertions(+), 3 deletions(-) diff --git a/bridge/index.js b/bridge/index.js index 2c4776e4..a65afb60 100644 --- a/bridge/index.js +++ b/bridge/index.js @@ -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; }); } diff --git a/bridge/package.json b/bridge/package.json index 1bf49234..f3bbaf1b 100644 --- a/bridge/package.json +++ b/bridge/package.json @@ -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", diff --git a/bridge/test/index.html b/bridge/test/index.html index 7ee05f2d..382d5362 100644 --- a/bridge/test/index.html +++ b/bridge/test/index.html @@ -5,8 +5,6 @@ PyScript Bridge - -