Skip to content

Conversation

t089
Copy link

@t089 t089 commented Oct 18, 2025

Currently swift package js only generates code for the "browser" platform.

This PR adds a --platform node|browser [default: browser] argument that lets you control this behaviour. In case of node it will generate a init function that calls defaultNodeSetup instead of defaultBrowserSetup.

t089 added 7 commits October 18, 2025 09:34
1. Fixed missing type export (platforms/node.d.ts)
   - Exported DefaultNodeSetupOptions type that is referenced in index.js

2. Updated index.d.ts to support both platforms
   - Made init() function accept DefaultNodeSetupOptions for node platform
   - Made init() function accept Options for browser platform

3. Fixed conditional compilation in node.js
   - Wrapped getImports() in HAS_IMPORTS conditional (platforms/node.js)
test both browser and node platform variants
/// Name of the package (default: lowercased Package.swift name)
var packageName: String?
/// Target platform for the generated JavaScript (default: browser)
var platform: String?
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could this become an enum Platform: CaseIterable, so then you would rely on .allCases to dynamically compute help string for all available platforms in the help output you've added below for this new option?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sounds good! Will do

@MaxDesiatov
Copy link
Member

Please run ./Utilities/format.py for the formatting check to pass.

@MaxDesiatov MaxDesiatov added enhancement New feature or request dependencies Pull requests that update a dependency file labels Oct 20, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

dependencies Pull requests that update a dependency file enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants