Switch to .mjs for ES module output for Node.js compat
This also reverts commit 60cf26c2f3
.
This commit is contained in:
parent
6868e4aa59
commit
1d4ab5a0de
|
@ -2,11 +2,12 @@
|
|||
"name": "node-fetch",
|
||||
"version": "2.1.2",
|
||||
"description": "A light-weight module that brings window.fetch to node.js",
|
||||
"main": "lib/index.js",
|
||||
"main": "lib/index",
|
||||
"browser": "./browser.js",
|
||||
"module": "lib/index.es.js",
|
||||
"module": "lib/index.mjs",
|
||||
"files": [
|
||||
"lib/index.js",
|
||||
"lib/index.mjs",
|
||||
"lib/index.es.js",
|
||||
"browser.js"
|
||||
],
|
||||
|
@ -47,6 +48,7 @@
|
|||
"codecov": "^3.0.0",
|
||||
"cross-env": "^5.1.3",
|
||||
"form-data": "^2.3.1",
|
||||
"is-builtin-module": "^1.0.0",
|
||||
"mocha": "^5.0.0",
|
||||
"nyc": "11.9.0",
|
||||
"parted": "^0.1.1",
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
import isBuiltin from 'is-builtin-module';
|
||||
import babel from 'rollup-plugin-babel';
|
||||
import tweakDefault from './build/rollup-plugin';
|
||||
|
||||
|
@ -7,7 +8,8 @@ export default {
|
|||
input: 'src/index.js',
|
||||
output: [
|
||||
{ file: 'lib/index.js', format: 'cjs', exports: 'named' },
|
||||
{ file: 'lib/index.es.js', format: 'es', exports: 'named' }
|
||||
{ file: 'lib/index.es.js', format: 'es', exports: 'named', intro: 'process.emitWarning("The .es.js file is deprecated. Use .mjs instead.");' },
|
||||
{ file: 'lib/index.mjs', format: 'es', exports: 'named' },
|
||||
],
|
||||
plugins: [
|
||||
babel({
|
||||
|
@ -16,6 +18,9 @@ export default {
|
|||
tweakDefault()
|
||||
],
|
||||
external: function (id) {
|
||||
if (isBuiltin(id)) {
|
||||
return true;
|
||||
}
|
||||
id = id.split('/').slice(0, id[0] === '@' ? 2 : 1).join('/');
|
||||
return !!require('./package.json').dependencies[id];
|
||||
}
|
||||
|
|
|
@ -5,12 +5,10 @@
|
|||
* Body interface provides common methods for Request and Response
|
||||
*/
|
||||
|
||||
import Stream, { PassThrough } from 'stream';
|
||||
import Blob, { BUFFER } from './blob.js';
|
||||
import FetchError from './fetch-error.js';
|
||||
|
||||
const Stream = require('stream');
|
||||
const { PassThrough } = require('stream');
|
||||
|
||||
let convert;
|
||||
try { convert = require('encoding').convert; } catch(e) {}
|
||||
|
||||
|
|
12
src/index.js
12
src/index.js
|
@ -7,18 +7,18 @@
|
|||
* All spec algorithm step numbers are based on https://fetch.spec.whatwg.org/commit-snapshots/ae716822cb3a61843226cd090eefc6589446c1d2/.
|
||||
*/
|
||||
|
||||
import { resolve as resolve_url } from 'url';
|
||||
import http from 'http';
|
||||
import https from 'https';
|
||||
import zlib from 'zlib';
|
||||
import { PassThrough } from 'stream';
|
||||
|
||||
import Body, { writeToStream, getTotalBytes } from './body';
|
||||
import Response from './response';
|
||||
import Headers, { createHeadersLenient } from './headers';
|
||||
import Request, { getNodeRequestOptions } from './request';
|
||||
import FetchError from './fetch-error';
|
||||
|
||||
const http = require('http');
|
||||
const https = require('https');
|
||||
const { PassThrough } = require('stream');
|
||||
const { resolve: resolve_url } = require('url');
|
||||
const zlib = require('zlib');
|
||||
|
||||
/**
|
||||
* Fetch function
|
||||
*
|
||||
|
|
|
@ -7,11 +7,10 @@
|
|||
* 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 Headers, { exportNodeCompatibleHeaders } from './headers.js';
|
||||
import Body, { clone, extractContentType, getTotalBytes } from './body';
|
||||
|
||||
const { format: format_url, parse: parse_url } = require('url');
|
||||
|
||||
const INTERNALS = Symbol('Request internals');
|
||||
|
||||
/**
|
||||
|
|
|
@ -5,11 +5,10 @@
|
|||
* Response class provides content decoding
|
||||
*/
|
||||
|
||||
import { STATUS_CODES } from 'http';
|
||||
import Headers from './headers.js';
|
||||
import Body, { clone } from './body';
|
||||
|
||||
const { STATUS_CODES } = require('http');
|
||||
|
||||
const INTERNALS = Symbol('Response internals');
|
||||
|
||||
/**
|
||||
|
|
Loading…
Reference in New Issue