For each imported name, resolve via the shared registry, fetch, and stash under dist/vendor/.
(
manifest: &Manifest,
imports: &BTreeSet<String>,
out_dir: &Path,
)
| 149 | |
| 150 | /// For each imported name, resolve via the shared registry, fetch, and stash under dist/vendor/. |
| 151 | fn vendor_packages( |
| 152 | manifest: &Manifest, |
| 153 | imports: &BTreeSet<String>, |
| 154 | out_dir: &Path, |
| 155 | ) -> Result<(BTreeMap<String, String>, BTreeMap<String, String>)> { |
| 156 | let mut std_local = BTreeMap::new(); |
| 157 | let mut host_local = BTreeMap::new(); |
| 158 | |
| 159 | for name in imports { |
| 160 | // Unknown names are project-local .py modules; let the runtime resolve them at run time. |
| 161 | let Some((kind, url)) = pkg::resolve(name, manifest) else { continue }; |
| 162 | let bytes = fetch(&url).with_context(|| format!("fetching {url}"))?; |
| 163 | let local = match kind { |
| 164 | // std packages are .wasm, except pure-Python ones (test) served as .py; preserve the real extension. |
| 165 | Kind::Std => format!("vendor/{name}.{}", if url.ends_with(".py") { "py" } else { "wasm" }), |
| 166 | Kind::Host => format!("vendor/{name}/index.js"), |
| 167 | }; |
| 168 | write_under(out_dir, &local, &bytes)?; |
| 169 | match kind { |
| 170 | Kind::Std => { std_local.insert(name.clone(), local); } |
| 171 | Kind::Host => { host_local.insert(name.clone(), local); } |
| 172 | } |
| 173 | } |
| 174 | Ok((std_local, host_local)) |
| 175 | } |
| 176 | |
| 177 | fn write_under(root: &Path, rel: &str, bytes: &[u8]) -> Result<()> { |
| 178 | let path = root.join(rel); |
no test coverage detected