Skip to content

Commit

Permalink
avoid named export for compatibility below node 10
Browse files Browse the repository at this point in the history
  • Loading branch information
David Frank committed Nov 5, 2018
1 parent d935121 commit 91e1c0b
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 6 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Expand Up @@ -7,7 +7,7 @@ Changelog

## master

- Fix: `import` on index.js, where `PassThrough` doesn't have a named export when using with node <10 and `--exerimental-modules` flag.
- Fix: multiple `import` rules, where `PassThrough` etc. doesn't have a named export when using node <10 and `--exerimental-modules` flag.

## v2.2.0

Expand Down
6 changes: 5 additions & 1 deletion src/body.js
Expand Up @@ -5,7 +5,8 @@
* Body interface provides common methods for Request and Response
*/

import Stream, { PassThrough } from 'stream';
import Stream from 'stream';

import Blob, { BUFFER } from './blob.js';
import FetchError from './fetch-error.js';

Expand All @@ -14,6 +15,9 @@ try { convert = require('encoding').convert; } catch(e) {}

const INTERNALS = Symbol('Body internals');

// fix an issue where "PassThrough" isn't a named export for node <10
const PassThrough = Stream.PassThrough;

/**
* Body mixin
*
Expand Down
5 changes: 3 additions & 2 deletions src/index.js
Expand Up @@ -7,7 +7,7 @@
* All spec algorithm step numbers are based on https://fetch.spec.whatwg.org/commit-snapshots/ae716822cb3a61843226cd090eefc6589446c1d2/.
*/

import { resolve as resolve_url } from 'url';
import Url from 'url';
import http from 'http';
import https from 'https';
import zlib from 'zlib';
Expand All @@ -19,8 +19,9 @@ import Headers, { createHeadersLenient } from './headers';
import Request, { getNodeRequestOptions } from './request';
import FetchError from './fetch-error';

// fix an issue where PassThrough isn't a named export for node <10
// fix an issue where "PassThrough", "resolve" aren't a named export for node <10
const PassThrough = Stream.PassThrough;
const resolve_url = Url.resolve;

/**
* Fetch function
Expand Down
7 changes: 6 additions & 1 deletion src/request.js
Expand Up @@ -7,12 +7,17 @@
* All spec algorithm step numbers are based on https://fetch.spec.whatwg.org/commit-snapshots/ae716822cb3a61843226cd090eefc6589446c1d2/.
*/

import { format as format_url, parse as parse_url } from 'url';
import Url from 'url';

import Headers, { exportNodeCompatibleHeaders } from './headers.js';
import Body, { clone, extractContentType, getTotalBytes } from './body';

const INTERNALS = Symbol('Request internals');

// fix an issue where "format", "parse" aren't a named export for node <10
const parse_url = Url.parse;
const format_url = Url.format;

/**
* Check if a value is an instance of Request.
*
Expand Down
6 changes: 5 additions & 1 deletion src/response.js
Expand Up @@ -5,12 +5,16 @@
* Response class provides content decoding
*/

import { STATUS_CODES } from 'http';
import http from 'http';

import Headers from './headers.js';
import Body, { clone } from './body';

const INTERNALS = Symbol('Response internals');

// fix an issue where "STATUS_CODES" aren't a named export for node <10
const STATUS_CODES = http.STATUS_CODES;

/**
* Response class
*
Expand Down

0 comments on commit 91e1c0b

Please sign in to comment.