File tree Expand file tree Collapse file tree 1 file changed +15
-10
lines changed
Expand file tree Collapse file tree 1 file changed +15
-10
lines changed Original file line number Diff line number Diff line change 11import { Environment , napi } from 'napi-wasm' ;
22import { await_promise_sync , createBundleAsync } from './async.mjs' ;
33
4- let wasm , bundleAsyncInternal ;
4+ let wasm , initPromise , bundleAsyncInternal ;
55
66export default async function init ( input ) {
7+ if ( wasm ) return ;
8+ if ( initPromise ) {
9+ await initPromise ;
10+ return ;
11+ }
12+
713 input = input ?? new URL ( 'lightningcss_node.wasm' , import . meta. url ) ;
814 if ( typeof input === 'string' || ( typeof Request === 'function' && input instanceof Request ) || ( typeof URL === 'function' && input instanceof URL ) ) {
915 input = fetchOrReadFromFs ( input ) ;
1016 }
1117
12- const { instance } = await load ( await input , {
13- env : {
14- ...napi ,
15- await_promise_sync
16- }
17- } ) ;
18+ initPromise = input
19+ . then ( input => load ( input , { env : { ...napi , await_promise_sync} } ) )
20+ . then ( ( { instance} ) => {
21+ let env = new Environment ( instance ) ;
22+ bundleAsyncInternal = createBundleAsync ( env ) ;
23+ wasm = env . exports ;
24+ } ) ;
1825
19- let env = new Environment ( instance ) ;
20- wasm = env . exports ;
21- bundleAsyncInternal = createBundleAsync ( env ) ;
26+ await initPromise ;
2227}
2328
2429export function transform ( options ) {
You can’t perform that action at this time.
0 commit comments