From 9e1d600ca391db1af469b0d2776f5d54ae7152cc Mon Sep 17 00:00:00 2001 From: Ben Jeffery Date: Fri, 5 Jun 2026 00:49:56 +0100 Subject: [PATCH] Fix module type --- build.sh | 6 ++++++ content-hash.txt | 2 +- tests/test_notebooks_pyodide.py | 9 +++++++++ 3 files changed, 16 insertions(+), 1 deletion(-) diff --git a/build.sh b/build.sh index 198f028..add8a83 100755 --- a/build.sh +++ b/build.sh @@ -38,15 +38,21 @@ load_pyodide_pattern = re.compile( r"\(await ([A-Za-z_$][\w$]*|__webpack_require__)\(476\)\(([A-Za-z_$][\w$]*)\)\)\.loadPyodide" ) patched_files = [] +worker_type_patched_files = [] for path in kernel_extension_dir.glob("*.js"): source = path.read_text() patched = load_pyodide_pattern.sub(r"(await import(\2)).loadPyodide", source) + patched = patched.replace("{type:void 0}", '{type:"module"}') if patched != source: path.write_text(patched) patched_files.append(path.name) + if "{type:void 0}" in source and '{type:"module"}' in patched: + worker_type_patched_files.append(path.name) if not patched_files: raise SystemExit("No Pyodide dynamic import bundle entry was patched") +if not worker_type_patched_files: + raise SystemExit("No Pyodide worker type entry was patched") PY python3 - <<'PY' import hashlib diff --git a/content-hash.txt b/content-hash.txt index 53eee71..6eeffa0 100644 --- a/content-hash.txt +++ b/content-hash.txt @@ -1 +1 @@ -5401e341378a031ff0d1bc35f51696710a091d23df4fa6592bb2ed4805641c21 +757a3beb0900ec3b676d915aaed054bbca25bcd7d7cb6146435ed617adf3d765 diff --git a/tests/test_notebooks_pyodide.py b/tests/test_notebooks_pyodide.py index d7c5478..2c4a1c0 100644 --- a/tests/test_notebooks_pyodide.py +++ b/tests/test_notebooks_pyodide.py @@ -62,6 +62,15 @@ def test_pyodide_kernel_uses_native_dynamic_import(): assert "(476)(s)).loadPyodide" not in bundle_source +def test_pyodide_kernel_uses_module_workers(): + extension_dir = DIST / "extensions" / "@jupyterlite" / "pyodide-kernel-extension" / "static" + js_files = list(extension_dir.glob("*.js")) + assert js_files + bundle_source = "\n".join(path.read_text(encoding="utf8") for path in js_files) + assert '{type:"module"}' in bundle_source + assert "{type:void 0}" not in bundle_source + + def _execute_notebook(notebook_path: Path, *, cells: int | None = None, timeout: int = 600) -> None: """Execute a notebook using the local CPython kernel.