(spec: string, options: LoadAnalyzerOptions)
| 263 | } |
| 264 | |
| 265 | async function constructWasm(spec: string, options: LoadAnalyzerOptions): Promise<IAnalyzer> { |
| 266 | const mod = requireFromHere(spec); |
| 267 | const Inner = mod?.WasmAnalyzer as WasmInnerConstructor | undefined; |
| 268 | if (typeof Inner !== 'function') { |
| 269 | // Guards against pointing this at napi's WASI build, which exposes the napi |
| 270 | // surface (Analyzer/TestAnalyzer) rather than the wasm-bindgen WasmAnalyzer. |
| 271 | throw new Error( |
| 272 | `'${spec}' does not export a 'WasmAnalyzer' constructor (${describeExports(mod)})`, |
| 273 | ); |
| 274 | } |
| 275 | const {WasmAnalyzer} = await import('./analyzer_wasm.js'); |
| 276 | |
| 277 | // The engine has no OS beneath it, so without this bridge it can only see |
| 278 | // `virtualFiles` and cannot analyze a project on disk. Callers can substitute their |
| 279 | // own host (a bundler's module graph, say) or pass null to keep it in-memory only. |
| 280 | let hostFs = options.hostFs; |
| 281 | if (hostFs === undefined) { |
| 282 | const {createNodeHostFs} = await import('./wasm_host_fs.js'); |
| 283 | hostFs = createNodeHostFs(); |
| 284 | } |
| 285 | |
| 286 | const inner = new Inner(JSON.stringify(engineOptions(options)), hostFs); |
| 287 | return new WasmAnalyzer(inner); |
| 288 | } |
| 289 | |
| 290 | function hostDescription(): string { |
| 291 | const parts = [`${process.platform}/${process.arch}`, `node ${process.version}`]; |
no test coverage detected