native-url icon indicating copy to clipboard operation
native-url copied to clipboard

Ensure that URL constructor is globally available

Open vladimyr opened this issue 4 years ago • 5 comments

WHATWG URL API has been implemented since v7 but global URL constructor was added later as part of v10 release.

  • [x] Tests pass
  • [ ] Appropriate changes to README are included in PR

vladimyr avatar Jan 29 '20 21:01 vladimyr

Hi @vladimyr . Thanks for the PR!

Just wondering if there is a need to export URL and URLSearchParams, since we are proving methods around it? Also URL and URLSearchParams will be available globally in all cases (with the new changes).

janicklas-ralph avatar Jan 30 '20 18:01 janicklas-ralph

Strictly speaking, there is no need to export it but it is neat in case you have existing node codebase and you are trying to update it by swapping usages of node's builtin url module with native-url. Due to URL and URLSearchParams being first implemented as module exports of url module and later introduced as globals it is pretty common to find snippets like this one:

const { URL } = require('url');

I understand that the primary intention of this package is to implement legacy URL API on top of WHATWG's work and not producing a replacement for the node's builtin url module. That being said node's url is literally made of WHATWG API plus legacy one. First is now globally available, the latter is being phased out. So from a practical point of view, there is a strong incentive of supporting the seamless and backward compatible transition from url to native-url.

vladimyr avatar Jan 30 '20 23:01 vladimyr

@janicklas-ralph What do you think?

vladimyr avatar Feb 10 '20 18:02 vladimyr

Sorry about the late response! Thats a very valid point. Let me check out and test the changes before merging this

janicklas-ralph avatar Apr 09 '20 19:04 janicklas-ralph

Hi, want to check if there is some update for the changes :) We tried to globally replace node url with native-url, but found out it's common for other libraries to import constructor from the module. Thanks!

roderickhsiao avatar Apr 25 '22 20:04 roderickhsiao