11// @ts -check
22import { instantiate } from './instantiate.js' ;
3- /* #if TARGET_PLATFORM_NODE */
4- import { defaultNodeSetup /* #if USE_SHARED_MEMORY */ , createDefaultWorkerFactory /* #endif */ } from './platforms/node.js' ;
3+ /* #if TARGET_DEFAULT_PLATFORM_NODE */
4+ import { defaultNodeSetup /* #if USE_SHARED_MEMORY */ , createDefaultWorkerFactory as createDefaultWorkerFactoryForNode /* #endif */ } from './platforms/node.js' ;
55/* #else */
6- import { defaultBrowserSetup /* #if USE_SHARED_MEMORY */ , createDefaultWorkerFactory /* #endif */ } from './platforms/browser.js' ;
6+ import { defaultBrowserSetup /* #if USE_SHARED_MEMORY */ , createDefaultWorkerFactory as createDefaultWorkerFactoryForBrowser /* #endif */ } from './platforms/browser.js' ;
77/* #endif */
88
9+ /* #if TARGET_DEFAULT_PLATFORM_NODE */
910/** @type {import('./index.d').init } */
10- export async function init ( _options ) {
11- /* #if TARGET_PLATFORM_NODE */
11+ async function initNode ( _options ) {
1212 /** @type {import('./platforms/node.d.ts').DefaultNodeSetupOptions } */
13- const options = _options || { } ;
14- const instantiateOptions = await defaultNodeSetup ( {
15- args : options . args ,
16- onExit : options . onExit ,
13+ const options = {
14+ ...( _options || { } ) ,
1715/* #if USE_SHARED_MEMORY */
18- spawnWorker : options . spawnWorker || createDefaultWorkerFactory ( )
16+ spawnWorker : createDefaultWorkerFactoryForNode ( ) ,
1917/* #endif */
20- } ) ;
18+ } ;
19+ const instantiateOptions = await defaultNodeSetup ( options ) ;
20+ return await instantiate ( instantiateOptions ) ;
21+ }
22+
2123/* #else */
24+
25+ /** @type {import('./index.d').init } */
26+ async function initBrowser ( _options ) {
2227 /** @type {import('./index.d').Options } */
2328 const options = _options || {
2429/* #if HAS_IMPORTS */
@@ -36,9 +41,19 @@ export async function init(_options) {
3641 getImports : ( ) => options . getImports ( ) ,
3742/* #endif */
3843/* #if USE_SHARED_MEMORY */
39- spawnWorker : createDefaultWorkerFactory ( )
44+ spawnWorker : createDefaultWorkerFactoryForBrowser ( )
4045/* #endif */
4146 } )
42- /* #endif */
4347 return await instantiate ( instantiateOptions ) ;
4448}
49+
50+ /* #endif */
51+
52+ /** @type {import('./index.d').init } */
53+ export async function init ( options ) {
54+ /* #if TARGET_DEFAULT_PLATFORM_NODE */
55+ return initNode ( options ) ;
56+ /* #else */
57+ return initBrowser ( options ) ;
58+ /* #endif */
59+ }
0 commit comments