Skip to content

Commit

Permalink
fix: import whatwg-url in a way compatible with ESM Node
Browse files Browse the repository at this point in the history
  • Loading branch information
LinusU committed Sep 21, 2021
1 parent ace7536 commit 14e1f39
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
4 changes: 2 additions & 2 deletions src/request.js
Expand Up @@ -9,7 +9,7 @@

import Url from 'url';
import Stream from 'stream';
import {URL} from 'whatwg-url';
import whatwgUrl from 'whatwg-url';
import Headers, { exportNodeCompatibleHeaders } from './headers.js';
import Body, { clone, extractContentType, getTotalBytes } from './body';

Expand All @@ -33,7 +33,7 @@ function parseURL(urlStr) {
Absolute URL: https://tools.ietf.org/html/rfc3986#section-4.3
*/
if (/^[a-zA-Z][a-zA-Z\d+\-.]*:/.exec(urlStr)) {
const url = new URL(urlStr);
const url = new whatwgUrl.URL(urlStr);

return {
path: url.pathname,
Expand Down
4 changes: 2 additions & 2 deletions test/test.js
Expand Up @@ -9,7 +9,7 @@ import resumer from 'resumer';
import FormData from 'form-data';
import stringToArrayBuffer from 'string-to-arraybuffer';
import URLSearchParams_Polyfill from '@ungap/url-search-params';
import { URL } from 'whatwg-url';
import whatwgUrl from 'whatwg-url';
import { AbortController } from 'abortcontroller-polyfill/dist/abortcontroller';
import AbortController2 from 'abort-controller';

Expand Down Expand Up @@ -1812,7 +1812,7 @@ describe('node-fetch', () => {

it('should support fetch with WHATWG URL object', function() {
const url = `${base}hello`;
const urlObj = new URL(url);
const urlObj = new whatwgUrl.URL(url);
const req = new Request(urlObj);
return fetch(req).then(res => {
expect(res.url).to.equal(url);
Expand Down

0 comments on commit 14e1f39

Please sign in to comment.