Add --default-platform option to package js#457
Merged
kateinoigakukun merged 11 commits intoswiftwasm:mainfrom Oct 24, 2025
Merged
Add --default-platform option to package js#457kateinoigakukun merged 11 commits intoswiftwasm:mainfrom
--default-platform option to package js#457kateinoigakukun merged 11 commits intoswiftwasm:mainfrom
Conversation
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
MaxDesiatov
reviewed
Oct 20, 2025
| /// Name of the package (default: lowercased Package.swift name) | ||
| var packageName: String? | ||
| /// Target platform for the generated JavaScript (default: browser) | ||
| var platform: String? |
Member
There was a problem hiding this comment.
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?
Member
|
Please run |
--platform option to package js
--platform option to package js--platform option to package js
Member
|
Thanks for the updates! Cleaned up the title:
|
Member
kateinoigakukun
left a comment
There was a problem hiding this comment.
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 :)
Contributor
Author
|
Cool, yeah that seems reasonable, feel free to to change the patch accordingly! Thank you. |
ab3c404 to
617110e
Compare
--platform option to package js--default-platform option to package js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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.