From 8f8a93f74b9dfd29775badf53e9dbd67406e2213 Mon Sep 17 00:00:00 2001 From: Ian Thomas Date: Tue, 29 Oct 2024 15:53:44 +0000 Subject: [PATCH] Support use of em-forge wasm files in standalone JupyterLite deployment (#31) --- .gitignore | 1 + jupyterlite_terminal/add_on.py | 12 ++++++++++-- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/.gitignore b/.gitignore index 461d437..2ba6146 100644 --- a/.gitignore +++ b/.gitignore @@ -128,3 +128,4 @@ dmypy.json _output/ cockle_wasm_env/ cockle-config.json +.cockle_temp/ diff --git a/jupyterlite_terminal/add_on.py b/jupyterlite_terminal/add_on.py index a623ea3..04ece09 100644 --- a/jupyterlite_terminal/add_on.py +++ b/jupyterlite_terminal/add_on.py @@ -20,14 +20,22 @@ def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) def post_build(self, manager): - cockleTool = Path("node_modules") / "@jupyterlite" / "cockle" / "lib" / "tools" / "prepare_wasm.js" + cockleTool = Path("node_modules", "@jupyterlite", "cockle", "lib", "tools", "prepare_wasm.js") + if not cockleTool.is_file(): + cockleTool = ".cockle_temp" / cockleTool + cmd = ["npm", "install", "--no-save", "--prefix", cockleTool.parts[0], "@jupyterlite/cockle"] + print("TerminalAddon:", " ".join(cmd)) + subprocess.run(cmd, check=True) + assetDir = Path(self.manager.output_dir) / "extensions" / "@jupyterlite" / "terminal" / "static" / "wasm" # Although cockle's prepare_wasm is perfectly capable of copying the wasm and associated # files to the asset directory, here we just get the list of required files and let the # add-on do the copying for consistency with other extensions. tempFilename = 'cockle-files.txt' - subprocess.run(["node", str(cockleTool), "--list", tempFilename], check=True) + cmd = ["node", str(cockleTool), "--list", tempFilename] + print("TerminalAddon:", " ".join(cmd)) + subprocess.run(cmd, check=True) with open(tempFilename, 'r') as f: for source in f: