File tree Expand file tree Collapse file tree 3 files changed +22
-0
lines changed Expand file tree Collapse file tree 3 files changed +22
-0
lines changed Original file line number Diff line number Diff line change @@ -8,6 +8,8 @@ struct PackageToJS {
88 var configuration : String ?
99 /// Name of the package (default: lowercased Package.swift name)
1010 var packageName : String ?
11+ /// Target platform for the generated JavaScript (default: browser)
12+ var platform : String ?
1113 /// Whether to explain the build plan (default: false)
1214 var explain : Bool = false
1315 /// Whether to print verbose output
@@ -717,6 +719,7 @@ struct PackagingPlanner {
717719 " USE_WASI_CDN " : options. useCDN,
718720 " HAS_BRIDGE " : exportedSkeletons. count > 0 || importedSkeletons. count > 0 ,
719721 " HAS_IMPORTS " : importedSkeletons. count > 0 ,
722+ " TARGET_PLATFORM_NODE " : options. platform == " node " ,
720723 ]
721724 let constantSubstitutions : [ String : String ] = [
722725 " PACKAGE_TO_JS_MODULE_PATH " : wasmFilename,
Original file line number Diff line number Diff line change @@ -446,6 +446,7 @@ extension PackageToJS.PackageOptions {
446446 let configuration : String ? =
447447 ( extractor. extractOption ( named: " configuration " ) + extractor. extractSingleDashOption ( named: " c " ) ) . last
448448 let packageName = extractor. extractOption ( named: " package-name " ) . last
449+ let platform = extractor. extractOption ( named: " platform " ) . last
449450 let explain = extractor. extractFlag ( named: " explain " )
450451 let useCDN = extractor. extractFlag ( named: " use-cdn " )
451452 let verbose = extractor. extractFlag ( named: " verbose " )
@@ -454,6 +455,7 @@ extension PackageToJS.PackageOptions {
454455 outputPath: outputPath,
455456 configuration: configuration,
456457 packageName: packageName,
458+ platform: platform,
457459 explain: explain != 0 ,
458460 verbose: verbose != 0 ,
459461 useCDN: useCDN != 0 ,
@@ -466,6 +468,7 @@ extension PackageToJS.PackageOptions {
466468 --output <path> Path to the output directory (default: .build/plugins/PackageToJS/outputs/Package)
467469 -c, --configuration <name> The build configuration to use (values: debug, release; default: debug)
468470 --package-name <name> Name of the package (default: lowercased Package.swift name)
471+ --platform <name> Target platform for generated JavaScript (values: browser, node; default: browser)
469472 --use-cdn Whether to use CDN for dependency packages
470473 --enable-code-coverage Whether to enable code coverage collection
471474 --explain Whether to explain the build plan
Original file line number Diff line number Diff line change 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' ;
5+ /* #else */
36import { defaultBrowserSetup /* #if USE_SHARED_MEMORY */ , createDefaultWorkerFactory /* #endif */ } from './platforms/browser.js' ;
7+ /* #endif */
48
59/** @type {import('./index.d').init } */
610export async function init ( _options ) {
11+ /* #if TARGET_PLATFORM_NODE */
12+ /** @type {import('./platforms/node.d.ts').DefaultNodeSetupOptions } */
13+ const options = _options || { } ;
14+ const instantiateOptions = await defaultNodeSetup ( {
15+ args : options . args ,
16+ onExit : options . onExit ,
17+ /* #if USE_SHARED_MEMORY */
18+ spawnWorker : options . spawnWorker || createDefaultWorkerFactory ( )
19+ /* #endif */
20+ } ) ;
21+ /* #else */
722 /** @type {import('./index.d').Options } */
823 const options = _options || {
924/* #if HAS_IMPORTS */
@@ -24,5 +39,6 @@ export async function init(_options) {
2439 spawnWorker : createDefaultWorkerFactory ( )
2540/* #endif */
2641 } )
42+ /* #endif */
2743 return await instantiate ( instantiateOptions ) ;
2844}
You can’t perform that action at this time.
0 commit comments