Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork57
Add--default-platform option topackage js#457
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Uh oh!
There was an error while loading.Please reload this page.
Conversation
1. Fixed missing type export (platforms/node.d.ts) - Exported DefaultNodeSetupOptions type that is referenced in index.js2. Updated index.d.ts to support both platforms - Made init() function accept DefaultNodeSetupOptions for node platform - Made init() function accept Options for browser platform3. 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) | ||
| varpackageName:String? | ||
| /// Target platform for the generated JavaScript (default: browser) | ||
| varplatform:String? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
Could this become anenum 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?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
Sounds good! Will do
Please run |
--platform option topackage js--platform option topackage js--platform option topackage jsMaxDesiatov commentedOct 20, 2025 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
Thanks for the updates! Cleaned up the title:
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
Thank you for putting your effort here! Overall it makes sense to me!
Let me leave a few feedbacks before mering:
- I'd like to keep the generated JS package to be runtime independent as much as possible, so it might be better to name the option as
--default-platform, indicating that only the default entrypointindex.jsis platform dependent, and rest of the modules are still platform independent. The clarification would be partuculary helpful for library author publishing a platform-agnostic JS package containing the JSKit genrated code. - I'm not a big fan of adding
@types/nodedependency here because we use only small surface of Node.js API, and most of the usage is not visible from users (except forWorkertype). I think we can loosen type checks in the Node.js for the sake of the simplicity.
If that sounds reasonable, I can make changes on the top of your branch and merge this PR :)
Cool, yeah that seems reasonable, feel free to to change the patch accordingly! Thank you. |
ab3c404 to617110eCompareThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
Thanks!
84243a4 intoswiftwasm:mainUh oh!
There was an error while loading.Please reload this page.
--platform option topackage js--default-platform option topackage js
Currently
swift package jsonly generates code for the "browser" platform.This PR adds a
--platform node|browser [default: browser]argument that lets you control this behaviour. In case ofnodeit will generate ainitfunction that callsdefaultNodeSetupinstead ofdefaultBrowserSetup.