doc: add WHATWG file URLs in fs module#12670
Conversation
jasnell
left a comment
There was a problem hiding this comment.
Minor rewording suggestion. Thank you very much for doing this! :-)
doc/api/fs.md
Outdated
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
Absolutely right, on my way to correct that.
addaleax
left a comment
There was a problem hiding this comment.
LGTM with @TimothyGu’s comment addressed
doc/api/fs.md
Outdated
There was a problem hiding this comment.
I think the ; here is a typo, you can remove it while you’re already here if you want
|
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. |
doc/api/fs.md
Outdated
There was a problem hiding this comment.
This should maintain the alphabetical order.
There was a problem hiding this comment.
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.
the links are un-ordered ATM, sadly, this seems as good a place as any for now
There was a problem hiding this comment.
Thank you @sam-github. I will wait that your PR is merged to rebase it in mine.
doc/api/fs.md
Outdated
There was a problem hiding this comment.
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.
I second that. Examples may be helpful. Will work on that tomorrow. Thanks a lot !
There was a problem hiding this comment.
link experimental to the stability index, pls
There was a problem hiding this comment.
@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. |
doc/api/fs.md
Outdated
There was a problem hiding this comment.
stability statement are usually linked to stability definitions
There was a problem hiding this comment.
@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.
-
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
doc/api/fs.md
Outdated
doc/api/fs.md
Outdated
There was a problem hiding this comment.
It seems more common to have the drive letter capitalized.
doc/api/fs.md
Outdated
There was a problem hiding this comment.
Template string literal is unnecessary here. A ' should suffice.
doc/api/fs.md
Outdated
doc/api/fs.md
Outdated
There was a problem hiding this comment.
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.
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
There was a problem hiding this comment.
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
doc/api/fs.md
Outdated
There was a problem hiding this comment.
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. |
TimothyGu
left a comment
There was a problem hiding this comment.
One last comment. Otherwise LGTM.
doc/api/fs.md
Outdated
There was a problem hiding this comment.
This entry shouldn't be necessary anymore.
There was a problem hiding this comment.
Fixed !
Thank you a lot.
Your feedback & suggestions greatly helped me.
TimothyGu
left a comment
There was a problem hiding this comment.
Other than the tiniest of nits, LGTM.
doc/api/fs.md
Outdated
There was a problem hiding this comment.
Extra space before :
(This is English, not French :)
There was a problem hiding this comment.
Oh so right, forgot about that difference. Sorry :) All fixed in latest commit
doc/api/fs.md
Outdated
doc/api/fs.md
Outdated
doc/api/fs.md
Outdated
|
@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 <[email protected]> Reviewed-By: Anna Henningsen <[email protected]> Reviewed-By: Benjamin Gruenbaum <[email protected]> Reviewed-By: Timothy Gu <[email protected]> Reviewed-By: Joyee Cheung <[email protected]>
|
Landed in c1b3b95 |
Update
fsmodule 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
fsroot level.Where relevant :
YAMLflags in order to update revision history.fsfunctions / classes arguments types.