sandboxedjs 0.1.21 → 0.1.22

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -633,8 +633,15 @@ Those use dynamic imports, so they only fail if you call them.
633
633
 
634
634
  ### Python in a browser
635
635
 
636
- Node resolves Pyodide from the installed package. A browser cannot resolve it by name, so tell it
637
- where the module and the assets are a CDN is fine:
636
+ Python works lazily in a browser without extra configuration. On first use,
637
+ SandboxedJS loads the matching Pyodide runtime and assets from jsDelivr:
638
+
639
+ ```ts
640
+ const box = await createContainer();
641
+ await box.exec("python3 -c 'import sqlite3; print(sqlite3.sqlite_version)'");
642
+ ```
643
+
644
+ To self-host Pyodide or use another trusted CDN, override both URLs:
638
645
 
639
646
  ```ts
640
647
  import { configurePython, createContainer } from "sandboxedjs";
@@ -648,8 +655,8 @@ const box = await createContainer();
648
655
  await box.exec("python3 -c 'import sqlite3; print(sqlite3.sqlite_version)'");
649
656
  ```
650
657
 
651
- Without that configuration, a browser with no package resolver cannot locate
652
- Pyodide. Python never falls back to a host interpreter or another runtime.
658
+ Python never falls back to a host interpreter or another runtime. A custom
659
+ Pyodide module and its asset directory must use the same Pyodide version.
653
660
 
654
661
  ## Uploading files
655
662
 
package/dist/index.cjs CHANGED
@@ -22163,6 +22163,8 @@ var RESERVED_FOR_INTERPRETER = /* @__PURE__ */ new Set(["lib", "dev", "proc"]);
22163
22163
  var pyodideModule = null;
22164
22164
  var indexUrl;
22165
22165
  var moduleUrl;
22166
+ var DEFAULT_BROWSER_INDEX_URL = "https://cdn.jsdelivr.net/pyodide/v0.28.3/full/";
22167
+ var isNode2 = typeof process !== "undefined" && process.versions != null && process.versions.node != null;
22166
22168
  function configureCPython(options = {}) {
22167
22169
  if (options.indexURL !== void 0) indexUrl = options.indexURL;
22168
22170
  if (options.moduleURL !== void 0) {
@@ -22172,19 +22174,27 @@ function configureCPython(options = {}) {
22172
22174
  }
22173
22175
  function importPyodide() {
22174
22176
  if (!pyodideModule) {
22175
- const specifier = moduleUrl ?? ["py", "odide"].join("");
22176
- pyodideModule = import(
22177
- /* @vite-ignore */
22178
- /* webpackIgnore: true */
22179
- specifier
22180
- );
22177
+ if (moduleUrl) {
22178
+ pyodideModule = import(
22179
+ /* @vite-ignore */
22180
+ /* webpackIgnore: true */
22181
+ moduleUrl
22182
+ );
22183
+ } else if (isNode2) {
22184
+ pyodideModule = nodeOnlyModule("pyodide");
22185
+ } else {
22186
+ pyodideModule = import(
22187
+ /* @vite-ignore */
22188
+ /* webpackIgnore: true */
22189
+ `${DEFAULT_BROWSER_INDEX_URL}pyodide.mjs`
22190
+ );
22191
+ }
22181
22192
  }
22182
22193
  return pyodideModule;
22183
22194
  }
22184
- var isNode2 = typeof process !== "undefined" && process.versions != null && process.versions.node != null;
22185
22195
  async function resolveIndexUrl() {
22186
22196
  if (indexUrl) return indexUrl;
22187
- if (!isNode2) return void 0;
22197
+ if (!isNode2) return DEFAULT_BROWSER_INDEX_URL;
22188
22198
  try {
22189
22199
  const { createRequire } = await nodeBuiltin("module");
22190
22200
  const path = await nodeBuiltin("path");