Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitf60bfd6

Browse files
committed
adds a --platform flag to js to control the target platform of the generated code
1 parent2c183f3 commitf60bfd6

File tree

3 files changed

+22
-0
lines changed

3 files changed

+22
-0
lines changed

‎Plugins/PackageToJS/Sources/PackageToJS.swift‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ struct PackageToJS {
88
varconfiguration:String?
99
/// Name of the package (default: lowercased Package.swift name)
1010
varpackageName:String?
11+
/// Target platform for the generated JavaScript (default: browser)
12+
varplatform:String?
1113
/// Whether to explain the build plan (default: false)
1214
varexplain: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
letconstantSubstitutions:[String:String]=[
722725
"PACKAGE_TO_JS_MODULE_PATH": wasmFilename,

‎Plugins/PackageToJS/Sources/PackageToJSPlugin.swift‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -446,6 +446,7 @@ extension PackageToJS.PackageOptions {
446446
letconfiguration:String?=
447447
(extractor.extractOption(named:"configuration")+ extractor.extractSingleDashOption(named:"c")).last
448448
letpackageName= extractor.extractOption(named:"package-name").last
449+
letplatform= extractor.extractOption(named:"platform").last
449450
letexplain= extractor.extractFlag(named:"explain")
450451
letuseCDN= extractor.extractFlag(named:"use-cdn")
451452
letverbose= 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

‎Plugins/PackageToJS/Templates/index.js‎

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,24 @@
11
//@ts-check
22
import{instantiate}from'./instantiate.js';
3+
/* #if TARGET_PLATFORM_NODE */
4+
import{defaultNodeSetup/* #if USE_SHARED_MEMORY */,createDefaultWorkerFactory/* #endif */}from'./platforms/node.js';
5+
/* #else */
36
import{defaultBrowserSetup/* #if USE_SHARED_MEMORY */,createDefaultWorkerFactory/* #endif */}from'./platforms/browser.js';
7+
/* #endif */
48

59
/**@type {import('./index.d').init} */
610
exportasyncfunctioninit(_options){
11+
/* #if TARGET_PLATFORM_NODE */
12+
/**@type {import('./platforms/node.d.ts').DefaultNodeSetupOptions} */
13+
constoptions=_options||{};
14+
constinstantiateOptions=awaitdefaultNodeSetup({
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
constoptions=_options||{
924
/* #if HAS_IMPORTS */
@@ -24,5 +39,6 @@ export async function init(_options) {
2439
spawnWorker:createDefaultWorkerFactory()
2540
/* #endif */
2641
})
42+
/* #endif */
2743
returnawaitinstantiate(instantiateOptions);
2844
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp