-
Notifications
You must be signed in to change notification settings - Fork 29.6k
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
url: expose the WHATWG URL API globally #18281
Conversation
I'm -0 on this, but I think that it's a leat preferable to schedule this for a major release. |
I agree. I forgot to put the semver-major label. |
I'd rather not add more globals, but I won't block this if people think it's the right thing to do. |
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.
Makes complete sense to me. Very much in favour. 👍
(Even though with this being semver-major, my vote doesn't make much of a difference.)
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 we might want a lint rule like the one we have for Buffer
which verifies that internal modules don’t rely on the global and instead do explicitly require url
?
@addaleax we don't need a special rule. ESLint already considers uses of global URL an error. |
I'm +0 on this. The implementation is ok, but I would not add more globals, but I'm not objecting either as it's very common on web platform. If we are doing this, I would prefer if we started using it everywhere, even internally (https://github.com/nodejs/node/blob/master/lib/_http_client.js#L26), and gently phase away the old url parser. If we think this is the way to go, there is very little incentive for the community to adopt it if we do not use it internally. |
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.
I personally don't have a problem with exposing them as globals. Next up: TextEncoder?
I'll get my coat.
doc/api/url.md
Outdated
@@ -447,20 +431,23 @@ console.log(JSON.stringify(myURLs)); | |||
### Class: URLSearchParams | |||
<!-- YAML | |||
added: v7.5.0 | |||
changes: | |||
- version: REPLACEME | |||
pr-url: REPLACEME |
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.
we should be able to also set this, shouldn't we?
doc/api/url.md
Outdated
<!-- YAML | ||
added: v7.0.0 | ||
changes: | ||
- version: REPLACEME | ||
pr-url: REPLACEME |
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.
we should be able to go ahead and set this, no?
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.
thanks. updated
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.
Very happy to see this come back around. It wasn't quite as popular an idea the first time I suggested it :-)
-0 for reasons described in nodejs/node-eps#28 (comment) (my and others comments). I don't think that things changed much since that discussion. I won't block this though if this is what others want. |
@@ -327,6 +328,24 @@ | |||
setupInspector(originalConsole, wrappedConsole, Module); | |||
} | |||
|
|||
function setupGlobalURL() { | |||
const { URL, URLSearchParams } = NativeModule.require('internal/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.
Does this impact startup performance, and if so, could it be required on use possibly?
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.
No, as this module is already being imported on startup:
node/lib/internal/bootstrap_node.js
Lines 80 to 82 in a3555d0
// Ensure setURLConstructor() is called before the native | |
// URL::ToObject() method is used. | |
NativeModule.require('internal/url'); |
Install URL and URLSearchParams on the global object, like they can be found in browser environments. PR-URL: nodejs#18281 Reviewed-By: Anatoli Papirovski <apapirovski@mac.com> Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Daijiro Wachi <daijiro.wachi@gmail.com> Reviewed-By: Tiancheng "Timothy" Gu <timothygu99@gmail.com> Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de> Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com> Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl> Reviewed-By: Evan Lucas <evanlucas@me.com> Reviewed-By: James M Snell <jasnell@gmail.com>
New CI: https://ci.nodejs.org/job/node-test-pull-request/12797/ |
I'm not sure what's going on with AIX but it does not seem related. |
Trying again on AIX. Given all the problems that have erupted on CI in the last month or two, I'm kinda -1 on landing something if we can't get CI to build/run on a platform. But I'm optimistic this is fixed now, so hopefully no problems... CI for AIX: https://ci.nodejs.org/job/node-test-commit-aix/12189/ |
@Trott thanks for restarting AIX. I fixed up one of the machines yesterday. There were a bunch of stale processes. I see the run you launched is green :) |
Landed in 3124146 |
Install URL and URLSearchParams on the global object, like they can be found in browser environments. PR-URL: #18281 Reviewed-By: Anatoli Papirovski <apapirovski@mac.com> Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Daijiro Wachi <daijiro.wachi@gmail.com> Reviewed-By: Tiancheng "Timothy" Gu <timothygu99@gmail.com> Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de> Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com> Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl> Reviewed-By: Evan Lucas <evanlucas@me.com> Reviewed-By: James M Snell <jasnell@gmail.com>
I'm a nobody here, but I hope to see APIs shared across platform in the global scope so I don't have to mess with the |
I'm just wondering, would it be worth backporting this to 8.x? Would help a lot to be able to treat this as a baseline support. I can put together the port if it sounds like it could be possible. |
@guybedford I'd rather not since there might be code out there checking |
@TimothyGu I've never ever seen a pattern like that for environment detection - usually it is based on Window or Document. Every case I've seen doing Users wanting to use the URL global in Node won't be able to until Node 8 EOL, which is over a year away, so it's a shame not to be able to really use this awesome feature in published packages that want to support Node 8 +. |
I'm generically -1 in adding new globals in semver-minors. Code running without |
If you feel strongly about it, can you please open a new issue for that discussion? |
Install URL and URLSearchParams on the global object, like they can be found in browser environments. PR-URL: nodejs#18281 Reviewed-By: Anatoli Papirovski <apapirovski@mac.com> Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Daijiro Wachi <daijiro.wachi@gmail.com> Reviewed-By: Tiancheng "Timothy" Gu <timothygu99@gmail.com> Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de> Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com> Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl> Reviewed-By: Evan Lucas <evanlucas@me.com> Reviewed-By: James M Snell <jasnell@gmail.com>
try {
new URL("http://google.com")
} catch (e) {
// we are on Node 10!
// so we can use XYZ.
} also if (!global.URL) {
// assume something that's not true anymore
} |
Install URL and URLSearchParams on the global object, like they can be found in browser environments. PR-URL: nodejs#18281 Reviewed-By: Anatoli Papirovski <apapirovski@mac.com> Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Daijiro Wachi <daijiro.wachi@gmail.com> Reviewed-By: Tiancheng "Timothy" Gu <timothygu99@gmail.com> Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de> Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com> Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl> Reviewed-By: Evan Lucas <evanlucas@me.com> Reviewed-By: James M Snell <jasnell@gmail.com>
Install
URL
andURLSearchParams
on the global object, like they can befound in browser environments.
Checklist
make -j4 test
(UNIX), orvcbuild test
(Windows) passesAffected core subsystem(s)
url
/cc @nodejs/tsc @nodejs/url @jasnell
Quick CI: https://ci.nodejs.org/job/node-test-pull-request-lite/106/Quick CI: https://ci.nodejs.org/job/node-test-pull-request-lite/107/