-
Notifications
You must be signed in to change notification settings - Fork 1.7k
[dart2js] Bundles targeting browser pay cost of Uri
Windows handling for Node
#54474
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 our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Thanks @parlough! To make sure I understand, sounds like your goal is to not pay for the cost of the I'm wondering if there is still a way to achieve that through code tree-shaking. One idea here is that we could add an extra, but constant condition to Today, you have to run dart2js with static final bool _isWindowsCached =
!const bool.fromEnvironment('dart.library.html') && JS(
'bool',
'typeof process != "undefined" && '
'Object.prototype.toString.call(process) == "[object process]" && '
'process.platform == "win32"'); Then dart2js will recognize that In the future, I'd prefer to not expose this via |
Thanks for the ideas and clarifying questions! :D
Yes, that's correct. We now recommend
If that solution is acceptable to the web compilers team, I'm all for that :). I didn't consider it here as I wasn't sure how that will work after I will note that I think the current custom handling is potentially confusing though, as it isn't documented, and only accounts for Node, so behavior could be different on other runtimes (Deno, Bun, etc.) that don't have similar process/platform APIs. ...I think this leads in to a separate/larger discussion of how the web compilers (especially |
Using any of
Uri.directory
,Uri.file
, anduri.toFilePath
without explicitly specifyingwindows: false
every time results in all of theUri
code for handling Windows file paths being included due to special handling added for Node in 5a74d8a. This technically also results in an extra check that will always evaluate to false.Usages of these constructors and functions are often indirect, such as through other packages, making this quite hard to avoid.
I feel this cost is likely not worth it for handling the node case, and my initial feeling is that it would actually be quite surprising for my Dart compiled to JS to behave differently on Node than in the browser. When I compile to JS (or Wasm) I
personally expect I'm opting in to consistent behavior in respect to my code no matter the platform.
Anyone requiring platform specific Uri file behavior on Node (or any other non-browser JS runtime) should probably explicitly give a value to the
windows
parameter or use Node's https://nodejs.org/api/url.html#urlpathtofileurlpath and https://nodejs.org/api/url.html#urlfileurltopathurl functions.The text was updated successfully, but these errors were encountered: