-
-
Notifications
You must be signed in to change notification settings - Fork 35.6k
Discussion: File URLs in Node.jsΒ #22502
Copy link
Copy link
Closed
Labels
feature requestIssues that request new features to be added to Node.js.Issues that request new features to be added to Node.js.fsIssues and PRs related to the fs subsystem / file system.Issues and PRs related to the fs subsystem / file system.whatwg-urlIssues and PRs related to the WHATWG URL implementation.Issues and PRs related to the WHATWG URL implementation.
Metadata
Metadata
Assignees
Labels
feature requestIssues that request new features to be added to Node.js.Issues that request new features to be added to Node.js.fsIssues and PRs related to the fs subsystem / file system.Issues and PRs related to the fs subsystem / file system.whatwg-urlIssues and PRs related to the WHATWG URL implementation.Issues and PRs related to the WHATWG URL implementation.
Type
Fields
Give feedbackNo fields configured for issues without a type.
I wanted to open up a discussion on this topic, as previous work around this has perhaps lacked wider context (#20950)
Basically when we provide file:/// URLs to users (through
import.meta.url, the Loader API for modules which relies heavily on file URLs, or any other means), we are expecting users to understand a lot of intricacies of how file URLs work in Node, which it already seems 90% of people will miss.For example, see - wasm-tool/node-loader@e4f6b7d.
There are two major problems most people will walk into blindly when converting from file URLs to paths in Node.js:
fs.readFile(url.pathname)works in unix systems, but will break on Windows. This means Windows support will naturally hit a wide and reliably propagating point of friction as these workflows integrate into the npm ecosystem. This issue will keep coming up across many projects as they work with file URLs.Non-latin characters need to be percent decoded.
import './δ½ ε₯½.mjs'will be resolved intofile:///.../%E4%BD%A0%E5%A5%BD.mjs, so that in order to support loading the native characters from the file system, a percent decode operation needs to be performed on the path, with some special cases (eg not percent decoding path separators).(1) is the immediate issue that will show as one of the standard Windows compatibility issues (alongside
path.replace(/\\/g, '/')), and (2) seems like a deeper less seen Anglocentric preference that will continue to propagate here as well.Since I've personally not been able to make any progress on this problem through #20950 I'd be interested to hear what we might be able to do about this.
What I would like to suggest here is two new native functions:
Let me know if that sounds like a good idea here, and I can see if we can get something into
pathorurl... (suggestions on which is best are welcome too).