-
Notifications
You must be signed in to change notification settings - Fork 30k
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
doc: add WHATWG file URLs in fs module #12670
Conversation
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.
Minor rewording suggestion. Thank you very much for doing this! :-)
doc/api/fs.md
Outdated
Most fs functions' path or filename arguments can be WHATWG URLs. Only | ||
WHATWG URLs using `file:///` protocol are supported. | ||
|
||
*Note* that file WHATWG file URLs are always absolute paths. WHATWG file URLs |
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.
Suggestion:
For most `fs` module functions, the `path` or `filename` argument may be passed
as a WHATWG [URL][] object. Only [URL][] objects using the `file:` protocol are
supported. Use of [URL][] objects is currently still experimental.
*Note*: `file:` URLs are always absolute paths.
Then add a link at the end of the page:
[URL]: url.html#url_the_whatwg_url_api
@jasnell Updated the PR in order to include your rewording suggestion ! Thanks a lot for helping me out 👍 |
doc/api/fs.md
Outdated
--> | ||
|
||
* `eventType` {string} The type of fs change | ||
* `filename` {string|Buffer} The filename that changed (if relevant/available) | ||
* `filename` {string|Buffer|URL} The filename that changed (if relevant/available) |
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.
This is not documentation for a method, but description of the payload of an event. Hence it cannot be a URL.
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.
Absolutely right, on my way to correct that.
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.
LGTM with @TimothyGu’s comment addressed
doc/api/fs.md
Outdated
@@ -1646,7 +1776,7 @@ changes: | |||
description: The `cache` parameter was removed. | |||
--> | |||
|
|||
* `path` {string|Buffer}; | |||
* `path` {string|Buffer|URL}; |
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.
I think the ;
here is a typo, you can remove it while you’re already here if you want
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.
Good catch @addaleax fixing it as well
Pushed a new commit including suggestions from @TimothyGu and @addaleax |
It’s a docs-only change, I think we’re good. :) We may have linting for the docs at some point in the future, but we haven’t integrated anything into CI or |
Looks good but would love to see some examples added. |
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.
Almost there!
doc/api/fs.md
Outdated
@@ -2495,6 +2687,7 @@ The following constants are meant for use with the [`fs.Stats`][] object's | |||
[`stat()`]: fs.html#fs_fs_stat_path_callback | |||
[`util.inspect(stats)`]: util.html#util_util_inspect_object_options | |||
[`WriteStream`]: #fs_class_fs_writestream | |||
[URL]: url.html#url_the_whatwg_url_api |
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.
This should maintain the alphabetical order.
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.
Hi @TimothyGu what alphabetical order ? I was trying to figure it out if there was something like that when I included that change. However i couldn't guess what the logic was as list items seems a bit melted.
Does internal vs external links matters in the order ?
Does functions / classes matters ?
If you can describe me the logical structure beneath the list I will be happy to sort that :)
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.
the links are un-ordered ATM, sadly, this seems as good a place as any for now
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.
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 @sam-github. I will wait that your PR is merged to rebase it in mine.
doc/api/fs.md
Outdated
@@ -70,6 +70,12 @@ the entire process until they complete--halting all connections. | |||
The relative path to a filename can be used. Remember, however, that this path | |||
will be relative to `process.cwd()`. | |||
|
|||
For most `fs` module functions, the `path` or `filename` argument may be passed | |||
as a WHATWG [URL][] object. Only [URL][] objects using the `file:` protocol are | |||
supported. Use of [URL][] objects is currently still experimental. |
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.
Aside from the scheme limitation, we also have some other platform-specific restrictions. Documenting them through examples can be helpful.
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.
I second that. Examples may be helpful. Will work on that tomorrow. Thanks a lot !
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.
link experimental
to the stability index, pls
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.
@sam-github You mean link experimental
to documentation.html#documentation_stability_index
?
Created this gist with proposal of examples. Feedback is welcome ! Also I plan to add James description in his PR #10739 below the short description i previously made at the root module level.
|
Please don't use Fwiw, I'm not sure why we need this feature. Unlike https://www.npmjs.com/package/open-uri you need to already have parsed a url into a |
The WHATWG URL API is experimental, the usage of the term in this PR is correct. In this case, it’s the description of “experimental” in the Stability index that’s wrong – we haven’t been consistent about putting experimental features behind flags (which I am okay with, it can be a case-by-case decision, but we should probably document that better). |
Review was for an older iteration of the PR
The WHATWG URL stuff is still technically experimental, although I'm likely to be opening a PR very soon (ahem, later today) that proposes upgrading it to a fully supported feature. |
I think the URL stuff is technically NOT experimental :-). But as @jasnell says, it will be irrelevant soon. @anchika That still means you should remove the experimental text. @addaleax I'm opening an issue seeking confirmation that the text is correct as-is. Until the definition is changed, it is what it is. Full disclosure, I think that we should hide all experimental features behind a flag. Maybe we should talk about at collab summit. #10739 is absent of any information on why the feature should be added, I still think its odd. Not sure what use-case its for. Does it help browser compatibility? But they don't have "experimental" status or not, I doubt we are going to delete this feature now that its here, perhaps the docs can at least say what its useful for. Also, does the arg actually have to be a |
@sam-github ... this PR should be ready to land before my PR removing the experimental status so the experimental text should actually remain in this PR.
In practice, yes. See https://github.com/nodejs/node/blob/master/lib/internal/url.js#L1348. The code checks for the presence of the |
Pushed a new commit with platform specific description and examples as requested by @TimothyGu. |
- version: v7.6.0 | ||
pr-url: https://github.com/nodejs/node/pull/10739 | ||
description: The `path` parameter can be a WHATWG `URL` object using `file:` | ||
protocol. Support is currently still *experimental*. |
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.
stability statement are usually linked to stability definitions
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.
@sam-github Same as above link the word experimental
to documentation.html#documentation_stability_index
@anchnk ... looks like this needs a quick rebase :-) |
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.
-
This PR still doesn't address restrictions like these:
// On POSIX fs.readFileSync(new URL('file:///path/%2F')); // TypeError [ERR_INVALID_FILE_URL_PATH]: File URL path must not include encoded / characters // On Windows fs.readFileSync(new URL('file:///C:/path/%2F')); fs.readFileSync(new URL('file:///C:/path/%5C')); // TypeError [ERR_INVALID_FILE_URL_PATH]: File URL path must not include encoded \ or / characters // On Windows fs.readFileSync(new URL('file:///notdriveletter/path/%5C')); // TypeError [ERR_INVALID_FILE_URL_PATH]: File URL path must be absolute
-
You might want to split this part of the documentation into a new chapter "WHATWG URL object support" (or something like that). The section has grown too big IMO.
doc/api/fs.md
Outdated
supported. Use of [URL][] objects is currently still experimental. | ||
|
||
```js | ||
const fs = require('fs'); |
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.
nit: extra space before =
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.
fixed with last commits
doc/api/fs.md
Outdated
```js | ||
const fs = require('fs'); | ||
const { URL } = require('url'); | ||
const file_url = new URL('file:///tmp/hello'); |
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.
camelCase please.
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.
fixed with last commits
doc/api/fs.md
Outdated
const file_url_with_hostname = new URL('file://hostname/p/a/t/h/file'); | ||
|
||
// path with drive letter converted to absolute path => c:\tmp\hello | ||
const file_url_with_drive_letter = new URL('file:///c:/tmp/hello'); |
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.
It seems more common to have the drive letter capitalized.
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.
fixed
doc/api/fs.md
Outdated
const { URL } = require('url'); | ||
|
||
// path with hostname => throw! | ||
const file_url_with_hostname = new URL(`file://hostname/p/a/t/h/file`); |
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.
Template string literal is unnecessary here. A '
should suffice.
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.
fixed
doc/api/fs.md
Outdated
// path with drive letter converted to absolute path => c:\tmp\hello | ||
const file_url_with_drive_letter = new URL('file:///c:/tmp/hello'); | ||
|
||
// On windows, WHATWG file URLs with hostname convert to UNC path |
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.
Windows
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.
fixed
doc/api/fs.md
Outdated
const { URL } = require('url'); | ||
const file_url = new URL('file:///tmp/hello'); | ||
|
||
fs.readFile(file_url, 'utf-8', (err,data) => { |
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.
IMO it would be easier to use the synchronous API (fs.readFileSync
) instead. You can even leave off the encoding
argument since it's not necessary to demonstrate URL support.
fs.readFileSync(fileURL);
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.
In the last commits I tried to remove everything that wasn't meaningful for the examples. So now they are quite minimalistic. That was based on your suggestion, again let me know.
doc/api/fs.md
Outdated
@@ -70,6 +70,76 @@ the entire process until they complete--halting all connections. | |||
The relative path to a filename can be used. Remember, however, that this path | |||
will be relative to `process.cwd()`. | |||
|
|||
For most `fs` module functions, the `path` or `filename` argument may be passed | |||
as a WHATWG [URL][] object. Only [URL][] objects using the `file:` protocol are |
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.
[`URL`][] object
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.
I created a new chapter on the last commit based on your suggestion @TimothyGu . Also the URL link formatting is fixed.
doc/api/fs.md
Outdated
fs.readFileSync(new URL('file:///p/a/t/h/%2F')); | ||
fs.readFileSync(new URL('file:///p/a/t/h/%2f')); | ||
/* TypeError [ERR_INVALID_FILE_URL_PATH]: File URL path must not include encoded | ||
/ characters *: |
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.
You are missing a */
here :)
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.
Oups ! thank you fixed !
doc/api/fs.md
Outdated
/* TypeError [ERR_INVALID_FILE_URL_PATH]: File URL path must not include encoded | ||
/ characters *: | ||
``` | ||
On Windows, `file:` URLs having encoded backslash will result in a throw : |
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.
Can you make sure to not have whitespace before :
? ;)
I did quite a bunch of changes in the last commits, so feel free to give any feedback. |
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.
One last comment. Otherwise LGTM.
doc/api/fs.md
Outdated
@@ -2499,6 +2774,7 @@ The following constants are meant for use with the [`fs.Stats`][] object's | |||
[`stat()`]: fs.html#fs_fs_stat_path_callback | |||
[`util.inspect(stats)`]: util.html#util_util_inspect_object_options | |||
[`WriteStream`]: #fs_class_fs_writestream | |||
[URL]: url.html#url_the_whatwg_url_api |
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.
This entry shouldn't be necessary anymore.
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.
Fixed !
Thank you a lot.
Your feedback & suggestions greatly helped me.
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.
Other than the tiniest of nits, LGTM.
doc/api/fs.md
Outdated
the drive letter. Using another separator will result in a throw. | ||
|
||
On all other platforms, `file:` URLs with a hostname are unsupported and will | ||
result in a throw : |
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.
Extra space before :
(This is English, not French :)
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.
Oh so right, forgot about that difference. Sorry :) All fixed in latest commit
doc/api/fs.md
Outdated
result in a throw : | ||
|
||
```js | ||
// On other platforms : |
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.
Ditto.
doc/api/fs.md
Outdated
``` | ||
|
||
A `file:` URL having encoded slash characters will result in a throw on all | ||
platforms : |
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.
Here too.
doc/api/fs.md
Outdated
/* TypeError [ERR_INVALID_FILE_URL_PATH]: File URL path must not include encoded | ||
/ characters */ | ||
``` | ||
On Windows, `file:` URLs having encoded backslash will result in a throw : |
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.
... and here.
@anchnk ... can you squash the commits down to prepare for landing? |
Update fs module documentation adding WHATWG file URLS support for relevant fs functions/classes. Fixes: nodejs#12341 Refs: nodejs#10739
@jasnell Squashing done. |
Update fs module documentation adding WHATWG file URLS support for relevant fs functions/classes. PR-URL: #12670 Fixes: #12341 Ref: #10739 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com> Reviewed-By: Timothy Gu <timothygu99@gmail.com> Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com>
Landed in c1b3b95 |
Update
fs
module documentation adding WHATWG file URLs support for relevant fs functions/classes.Fixes: #12341
Refs: #10739
Checklist
Affected core subsystem(s)
doc, fs
Description of change
fs
root level.Where relevant :
YAML
flags in order to update revision history.fs
functions / classes arguments types.