|
| 1 | +import { |
| 2 | + createOnMessage as __wasmCreateOnMessageForFsProxy, |
| 3 | + getDefaultContext as __emnapiGetDefaultContext, |
| 4 | + instantiateNapiModuleSync as __emnapiInstantiateNapiModuleSync, |
| 5 | + WASI as __WASI, |
| 6 | +} from '@napi-rs/wasm-runtime' |
| 7 | + |
| 8 | + |
| 9 | + |
| 10 | +const __wasi = new __WASI({ |
| 11 | + version: 'preview1', |
| 12 | +}) |
| 13 | + |
| 14 | +const __wasmUrl = new URL('./compiler.wasm32-wasi.wasm', import.meta.url).href |
| 15 | +const __emnapiContext = __emnapiGetDefaultContext() |
| 16 | + |
| 17 | + |
| 18 | +const __sharedMemory = new WebAssembly.Memory({ |
| 19 | + initial: 4000, |
| 20 | + maximum: 65536, |
| 21 | + shared: true, |
| 22 | +}) |
| 23 | + |
| 24 | +const __wasmFile = await fetch(__wasmUrl).then((res) => res.arrayBuffer()) |
| 25 | + |
| 26 | +const { |
| 27 | + instance: __napiInstance, |
| 28 | + module: __wasiModule, |
| 29 | + napiModule: __napiModule, |
| 30 | +} = __emnapiInstantiateNapiModuleSync(__wasmFile, { |
| 31 | + context: __emnapiContext, |
| 32 | + asyncWorkPoolSize: 4, |
| 33 | + wasi: __wasi, |
| 34 | + onCreateWorker() { |
| 35 | + const worker = new Worker(new URL('./wasi-worker-browser.mjs', import.meta.url), { |
| 36 | + type: 'module', |
| 37 | + }) |
| 38 | + |
| 39 | + |
| 40 | + return worker |
| 41 | + }, |
| 42 | + overwriteImports(importObject) { |
| 43 | + importObject.env = { |
| 44 | + ...importObject.env, |
| 45 | + ...importObject.napi, |
| 46 | + ...importObject.emnapi, |
| 47 | + memory: __sharedMemory, |
| 48 | + } |
| 49 | + return importObject |
| 50 | + }, |
| 51 | + beforeInit({ instance }) { |
| 52 | + for (const name of Object.keys(instance.exports)) { |
| 53 | + if (name.startsWith('__napi_register__')) { |
| 54 | + instance.exports[name]() |
| 55 | + } |
| 56 | + } |
| 57 | + }, |
| 58 | +}) |
| 59 | +export default __napiModule.exports |
| 60 | +export const Compiler = __napiModule.exports.Compiler |
| 61 | +export const Extractor = __napiModule.exports.Extractor |
| 62 | +export const compile = __napiModule.exports.compile |
| 63 | +export const DiagnosticSeverity = __napiModule.exports.DiagnosticSeverity |
| 64 | +export const extract = __napiModule.exports.extract |
| 65 | +export const extractCalls = __napiModule.exports.extractCalls |
| 66 | +export const extractDebug = __napiModule.exports.extractDebug |
| 67 | +export const ExtractedArgKind = __napiModule.exports.ExtractedArgKind |
| 68 | +export const extractJsx = __napiModule.exports.extractJsx |
| 69 | +export const flushTracing = __napiModule.exports.flushTracing |
| 70 | +export const ImportKind = __napiModule.exports.ImportKind |
| 71 | +export const ImportSpecifierKind = __napiModule.exports.ImportSpecifierKind |
| 72 | +export const JsxKind = __napiModule.exports.JsxKind |
| 73 | +export const MatchCategory = __napiModule.exports.MatchCategory |
| 74 | +export const matchImports = __napiModule.exports.matchImports |
| 75 | +export const scanImports = __napiModule.exports.scanImports |
| 76 | +export const shutdownTracing = __napiModule.exports.shutdownTracing |
| 77 | +export const startTracing = __napiModule.exports.startTracing |
0 commit comments