Skip to content

Use standard-conforming URL #360

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

Closed
wants to merge 4 commits into from

Conversation

redeyes2015
Copy link
Contributor

Initial work is done by @tromey.

A commit is added so that when URL is presented in global object, it is used as
the consturctor; otherwise fallback to use require('url').URL in order to support
the environments of node v8 and v9. Since node v10, URL is also presented in
global object.

@redeyes2015
Copy link
Contributor Author

redeyes2015 commented Sep 28, 2018

The issues metioned in #275 (comment) are not checked yet. I.e. whether these two cases are intentional:

  assert.equal(libUtil.join('http://foo.org/a//', '//b'), 'http://b');
  assert.equal(libUtil.join('http://www.example.com', '//foo.org/bar'), 'http://foo.org/bar');

By the way, I made another branch based on 0.6.1 to test in debugger.html, which make one test case fail: devtools-source-map/src/tests/source-map.js line 29: expect "webpack:///webpack/bootstrap 4ef8c7ec7c1df790781e" , but get "webpack:///webpack/bootstrap%204ef8c7ec7c1df790781e". Test cases in source-map is updated to expect %20, but is that the expected behavior for devtools?

@redeyes2015
Copy link
Contributor Author

About the CI failure... it is caused by an inconsistency between webpack and webpack-cli.

I filed #361 to fix it.

tromey and others added 4 commits October 4, 2018 14:03
If the global "URL" is a function, use it. This should be the case in
browser environments.

In [node] environment, `require('url').URL`, which follows WHATWG URL
Standard, was added in v7, and `URL` became available in global object
since v10.0. To support the version before v10, we need to check the
global object, and then fallback to `require('url').URL`.

However, note one thing: the version packed in by webpack-v3 ([npm-url])
only supports the "legacy version of Url API", which is not compatible
with "WHATWG URL Standard", must not be used as a replacement for `URL`.

[node]: https://nodejs.org/dist/latest-v10.x/docs/api/url.html
[npm-url]: https://www.npmjs.com/package/url
@coveralls
Copy link

Pull Request Test Coverage Report for Build 512

  • 17 of 20 (85.0%) changed or added relevant lines in 2 files are covered.
  • 3 unchanged lines in 1 file lost coverage.
  • Overall coverage decreased (-1.0%) to 82.928%

Changes Missing Coverage Covered Lines Changed/Added Lines %
lib/util.js 15 18 83.33%
Files with Coverage Reduction New Missed Lines %
lib/util.js 3 75.36%
Totals Coverage Status
Change from base Build 505: -1.0%
Covered Lines: 884
Relevant Lines: 1032

💛 - Coveralls

@loganfsmyth
Copy link
Contributor

@redeyes2015 FYI, I posted #367 with a more elaborate approach to using new URL if you're interested.

@redeyes2015
Copy link
Contributor Author

@loganfsmyth : Before closing this PR, I still feel like to ask, if I may, you to consider this test case:

exports["test sourceURL resolution with null sourceRoot and blob sourceMapURL"] = async function(assert) {
  const map = {
    version: 3,
    sources:  ["something.js"],
    names: [],
    mappings: "CAAS",
    file: "static/js/manifest.b7cf97680f7a50fa150f.js",
    sourceRoot: null,
  };
  const consumer = await new SourceMapConsumer(map, "blob:http://exmaple.com/12345-12345-12345");
  assert.equal(consumer.sources.length, 1);
  assert.equal(consumer.sources[0], "something.js");
  consumer.destroy();
};

AFAIK, this still fails in #367. One way to fix this is adding try-catch guards, like the last part of #275 (comment) . The aternative would be avoiding passing "blob url" as SourceMapUrl in devtools-source-map/src/utils/createConsumer.js , like:

 async function createConsumer(map: any, sourceMapUrl: any): SourceMapConsumer {
+  if (typeof sourceMapUrl == 'string' && sourceMapUrl.startsWith('blob:')) {
+    sourceMapUrl = undefined;
+  }
   return new SourceMapConsumer(map, sourceMapUrl);
 }

Either way would solve the issue for style-loader, but both feel hacky. I just hope this would be handled eventually.

Thanks for all the response and support :-)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants