1
0
mirror of https://github.com/pyscript/pyscript.git synced 2022-05-01 19:47:48 +03:00

Merge pull request #25 from anaconda/mattpap/esm_import_module

Allow `import d3` instead of `from esm import d3`
This commit is contained in:
Fabio Pliger
2022-04-18 10:16:32 -05:00
committed by GitHub
2 changed files with 7 additions and 7 deletions

View File

@@ -109,7 +109,7 @@ for (const d of data) {
<py-script>
from pyodide import create_proxy, to_js
from esm import d3
import d3
fruits = [
dict(name="🍊", count=21),

View File

@@ -247,8 +247,6 @@ export class PyScript extends HTMLElement {
}
protected async _register_esm(pyodide: PyodideInterface): Promise<void> {
const imports: {[key: string]: unknown} = {}
for (const node of document.querySelectorAll("script[type='importmap']")) {
const importmap = (() => {
try {
@@ -265,17 +263,19 @@ export class PyScript extends HTMLElement {
if (typeof name != "string" || typeof url != "string")
continue
let exports: object
try {
// XXX: pyodide doesn't like Module(), failing with
// "can't read 'name' of undefined" at import time
imports[name] = {...await import(url)}
exports = {...await import(url)}
} catch {
console.error(`failed to fetch '${url}' for '${name}'`)
console.warn(`failed to fetch '${url}' for '${name}'`)
continue
}
pyodide.registerJsModule(name, exports)
}
}
pyodide.registerJsModule("esm", imports)
}
async evaluate(): Promise<void> {