drop Babel (while keeping ESM) (#805)
* drop Babel * fix lint * just to trigger CI * Update package.json Co-authored-by: Linus Unnebäck <linus@folkdatorn.se> * fix all imports * coverage only from Node 14.x * remove esm * restore travis * fix lint Co-authored-by: Linus Unnebäck <linus@folkdatorn.se>
This commit is contained in:
parent
6e12fe22ad
commit
0f97d62844
|
@ -11,3 +11,6 @@ indent_style = tab
|
|||
|
||||
[*.md]
|
||||
trim_trailing_whitespace = false
|
||||
|
||||
[*.yml]
|
||||
indent_style = space
|
||||
|
|
52
package.json
52
package.json
|
@ -2,12 +2,13 @@
|
|||
"name": "node-fetch",
|
||||
"version": "3.0.0-beta.5",
|
||||
"description": "A light-weight module that brings window.fetch to node.js",
|
||||
"main": "./dist/index.js",
|
||||
"main": "./dist/index.cjs",
|
||||
"module": "./src/index.js",
|
||||
"sideEffects": false,
|
||||
"type": "module",
|
||||
"exports": {
|
||||
"import": "./src/index.js",
|
||||
"require": "./dist/index.js"
|
||||
"require": "./dist/index.cjs"
|
||||
},
|
||||
"files": [
|
||||
"src",
|
||||
|
@ -18,9 +19,9 @@
|
|||
"node": ">=10"
|
||||
},
|
||||
"scripts": {
|
||||
"build": "babel src --out-dir dist",
|
||||
"test": "nyc --reporter=html --reporter=text mocha --require @babel/register --throw-deprecation",
|
||||
"coverage": "nyc report --reporter=text-lcov | coveralls",
|
||||
"build": "rollup -c",
|
||||
"test": "node --experimental-modules node_modules/.bin/c8 --reporter=html --reporter=text --check-coverage node --experimental-modules node_modules/.bin/mocha",
|
||||
"coverage": "c8 report --reporter=text-lcov | coveralls",
|
||||
"lint": "xo"
|
||||
},
|
||||
"repository": {
|
||||
|
@ -43,26 +44,20 @@
|
|||
"url": "https://opencollective.com/node-fetch"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@babel/cli": "^7.8.4",
|
||||
"@babel/core": "^7.9.0",
|
||||
"@babel/preset-env": "^7.9.5",
|
||||
"@babel/register": "^7.9.0",
|
||||
"@istanbuljs/nyc-config-babel": "^3.0.0",
|
||||
"abort-controller": "^3.0.0",
|
||||
"abortcontroller-polyfill": "^1.4.0",
|
||||
"babel-plugin-add-module-exports": "^1.0.2",
|
||||
"babel-plugin-istanbul": "^6.0.0",
|
||||
"c8": "^7.1.2",
|
||||
"chai": "^4.2.0",
|
||||
"chai-as-promised": "^7.1.1",
|
||||
"chai-iterator": "^3.0.2",
|
||||
"chai-string": "^1.5.0",
|
||||
"coveralls": "^3.0.13",
|
||||
"coveralls": "^3.1.0",
|
||||
"form-data": "^3.0.0",
|
||||
"mocha": "^7.1.1",
|
||||
"nyc": "^15.0.1",
|
||||
"mocha": "^7.1.2",
|
||||
"parted": "^0.1.1",
|
||||
"promise": "^8.1.0",
|
||||
"resumer": "0.0.0",
|
||||
"rollup": "^2.10.4",
|
||||
"string-to-arraybuffer": "^1.0.2",
|
||||
"xo": "^0.30.0"
|
||||
},
|
||||
|
@ -70,6 +65,9 @@
|
|||
"data-uri-to-buffer": "^3.0.0",
|
||||
"fetch-blob": "^1.0.5"
|
||||
},
|
||||
"esm": {
|
||||
"sourceMap": true
|
||||
},
|
||||
"xo": {
|
||||
"envs": [
|
||||
"node",
|
||||
|
@ -81,7 +79,10 @@
|
|||
"no-mixed-operators": 0,
|
||||
"no-negated-condition": 0,
|
||||
"unicorn/prevent-abbreviations": 0,
|
||||
"@typescript-eslint/prefer-readonly-parameter-types": 0
|
||||
"@typescript-eslint/prefer-readonly-parameter-types": 0,
|
||||
"import/extensions": 0,
|
||||
"import/no-useless-path-segments": 0,
|
||||
"unicorn/import-index": 0
|
||||
},
|
||||
"ignores": [
|
||||
"dist",
|
||||
|
@ -109,24 +110,5 @@
|
|||
}
|
||||
]
|
||||
},
|
||||
"babel": {
|
||||
"presets": [
|
||||
[
|
||||
"@babel/preset-env",
|
||||
{
|
||||
"targets": {
|
||||
"node": true
|
||||
}
|
||||
}
|
||||
]
|
||||
],
|
||||
"plugins": [
|
||||
"add-module-exports",
|
||||
"istanbul"
|
||||
]
|
||||
},
|
||||
"nyc": {
|
||||
"extends": "@istanbuljs/nyc-config-babel"
|
||||
},
|
||||
"runkitExampleFilename": "example.js"
|
||||
}
|
||||
|
|
|
@ -0,0 +1,18 @@
|
|||
import {builtinModules} from 'module';
|
||||
import {dependencies} from './package.json';
|
||||
|
||||
export default {
|
||||
input: 'src/index.js',
|
||||
output: {
|
||||
file: 'dist/index.cjs',
|
||||
format: 'cjs',
|
||||
esModule: false,
|
||||
interop: false,
|
||||
sourcemap: true,
|
||||
preferConst: true,
|
||||
exports: 'named',
|
||||
// https://github.com/rollup/rollup/issues/1961#issuecomment-534977678
|
||||
intro: 'exports = module.exports = fetch;'
|
||||
},
|
||||
external: [...builtinModules, ...Object.keys(dependencies)]
|
||||
};
|
|
@ -8,8 +8,8 @@
|
|||
import Stream, {PassThrough} from 'stream';
|
||||
|
||||
import Blob from 'fetch-blob';
|
||||
import FetchError from './errors/fetch-error';
|
||||
import {isBlob, isURLSearchParams, isArrayBuffer, isAbortError} from './utils/is';
|
||||
import FetchError from './errors/fetch-error.js';
|
||||
import {isBlob, isURLSearchParams, isArrayBuffer, isAbortError} from './utils/is.js';
|
||||
|
||||
const INTERNALS = Symbol('Body internals');
|
||||
|
||||
|
|
23
src/index.js
23
src/index.js
|
@ -12,12 +12,18 @@ import zlib from 'zlib';
|
|||
import Stream, {PassThrough, pipeline as pump} from 'stream';
|
||||
import dataURIToBuffer from 'data-uri-to-buffer';
|
||||
|
||||
import Body, {writeToStream, getTotalBytes} from './body';
|
||||
import Response from './response';
|
||||
import Headers, {createHeadersLenient} from './headers';
|
||||
import Request, {getNodeRequestOptions} from './request';
|
||||
import FetchError from './errors/fetch-error';
|
||||
import AbortError from './errors/abort-error';
|
||||
import Body, {writeToStream, getTotalBytes} from './body.js';
|
||||
import Response from './response.js';
|
||||
import Headers, {createHeadersLenient} from './headers.js';
|
||||
import Request, {getNodeRequestOptions} from './request.js';
|
||||
import FetchError from './errors/fetch-error.js';
|
||||
import AbortError from './errors/abort-error.js';
|
||||
|
||||
export {default as Headers} from './headers.js';
|
||||
export {default as Request} from './request.js';
|
||||
export {default as Response} from './response.js';
|
||||
export {default as FetchError} from './errors/fetch-error.js';
|
||||
export {default as AbortError} from './errors/abort-error.js';
|
||||
|
||||
/**
|
||||
* Fetch function
|
||||
|
@ -305,8 +311,3 @@ fetch.isRedirect = code => [301, 302, 303, 307, 308].includes(code);
|
|||
|
||||
// Expose Promise
|
||||
fetch.Promise = global.Promise;
|
||||
fetch.Headers = Headers;
|
||||
fetch.Request = Request;
|
||||
fetch.Response = Response;
|
||||
fetch.FetchError = FetchError;
|
||||
fetch.AbortError = AbortError;
|
||||
|
|
|
@ -9,10 +9,10 @@
|
|||
|
||||
import {format as formatUrl} from 'url';
|
||||
import Stream from 'stream';
|
||||
import Headers, {exportNodeCompatibleHeaders} from './headers';
|
||||
import Body, {clone, extractContentType, getTotalBytes} from './body';
|
||||
import {isAbortSignal} from './utils/is';
|
||||
import {getSearch} from './utils/get-search';
|
||||
import Headers, {exportNodeCompatibleHeaders} from './headers.js';
|
||||
import Body, {clone, extractContentType, getTotalBytes} from './body.js';
|
||||
import {isAbortSignal} from './utils/is.js';
|
||||
import {getSearch} from './utils/get-search.js';
|
||||
|
||||
const INTERNALS = Symbol('Request internals');
|
||||
|
||||
|
|
|
@ -4,8 +4,8 @@
|
|||
* Response class provides content decoding
|
||||
*/
|
||||
|
||||
import Headers from './headers';
|
||||
import Body, {clone, extractContentType} from './body';
|
||||
import Headers from './headers.js';
|
||||
import Body, {clone, extractContentType} from './body.js';
|
||||
|
||||
const INTERNALS = Symbol('Response internals');
|
||||
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
import fetch from '../src';
|
||||
import fetch from '../src/index.js';
|
||||
import chai from 'chai';
|
||||
|
||||
const {expect} = chai;
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
import {Headers} from '../src';
|
||||
import {Headers} from '../src/index.js';
|
||||
import chai from 'chai';
|
||||
|
||||
const {expect} = chai;
|
||||
|
|
30
test/main.js
30
test/main.js
|
@ -2,10 +2,9 @@
|
|||
import zlib from 'zlib';
|
||||
import crypto from 'crypto';
|
||||
import {spawn} from 'child_process';
|
||||
import * as http from 'http';
|
||||
import * as fs from 'fs';
|
||||
import * as path from 'path';
|
||||
import * as stream from 'stream';
|
||||
import http from 'http';
|
||||
import fs from 'fs';
|
||||
import stream from 'stream';
|
||||
import {lookup} from 'dns';
|
||||
import vm from 'vm';
|
||||
import chai from 'chai';
|
||||
|
@ -17,29 +16,32 @@ import resumer from 'resumer';
|
|||
import FormData from 'form-data';
|
||||
import stringToArrayBuffer from 'string-to-arraybuffer';
|
||||
|
||||
import {AbortController} from 'abortcontroller-polyfill/dist/abortcontroller';
|
||||
import polyfill from 'abortcontroller-polyfill/dist/abortcontroller.js';
|
||||
import AbortController2 from 'abort-controller';
|
||||
|
||||
const {AbortController} = polyfill;
|
||||
|
||||
// Test subjects
|
||||
import Blob from 'fetch-blob';
|
||||
|
||||
import fetch, {
|
||||
FetchError,
|
||||
Headers,
|
||||
Request,
|
||||
Response
|
||||
} from '../src';
|
||||
import FetchErrorOrig from '../src/errors/fetch-error';
|
||||
import HeadersOrig, {createHeadersLenient} from '../src/headers';
|
||||
import RequestOrig from '../src/request';
|
||||
import ResponseOrig from '../src/response';
|
||||
import Body, {getTotalBytes, extractContentType} from '../src/body';
|
||||
import TestServer from './utils/server';
|
||||
} from '../src/index.js';
|
||||
import FetchErrorOrig from '../src/errors/fetch-error.js';
|
||||
import HeadersOrig, {createHeadersLenient} from '../src/headers.js';
|
||||
import RequestOrig from '../src/request.js';
|
||||
import ResponseOrig from '../src/response.js';
|
||||
import Body, {getTotalBytes, extractContentType} from '../src/body.js';
|
||||
import TestServer from './utils/server.js';
|
||||
|
||||
const {
|
||||
Uint8Array: VMUint8Array
|
||||
} = vm.runInNewContext('this');
|
||||
|
||||
import chaiTimeout from './utils/chai-timeout';
|
||||
import chaiTimeout from './utils/chai-timeout.js';
|
||||
|
||||
chai.use(chaiPromised);
|
||||
chai.use(chaiIterator);
|
||||
|
@ -1378,7 +1380,7 @@ describe('node-fetch', () => {
|
|||
|
||||
itIf(process.platform !== 'win32')('should allow POST request with form-data using stream as body', () => {
|
||||
const form = new FormData();
|
||||
form.append('my_field', fs.createReadStream(path.join(__dirname, './utils/dummy.txt')));
|
||||
form.append('my_field', fs.createReadStream('test/utils/dummy.txt'));
|
||||
|
||||
const url = `${base}multipart`;
|
||||
const options = {
|
||||
|
|
|
@ -1,14 +1,16 @@
|
|||
import * as stream from 'stream';
|
||||
import * as http from 'http';
|
||||
import {Request} from '../src';
|
||||
import TestServer from './utils/server';
|
||||
import {AbortController} from 'abortcontroller-polyfill/dist/abortcontroller';
|
||||
import stream from 'stream';
|
||||
import http from 'http';
|
||||
import polyfill from 'abortcontroller-polyfill/dist/abortcontroller.js';
|
||||
import chai from 'chai';
|
||||
import FormData from 'form-data';
|
||||
import Blob from 'fetch-blob';
|
||||
import resumer from 'resumer';
|
||||
import stringToArrayBuffer from 'string-to-arraybuffer';
|
||||
|
||||
import TestServer from './utils/server.js';
|
||||
import {Request} from '../src/index.js';
|
||||
|
||||
const {AbortController} = polyfill;
|
||||
const {expect} = chai;
|
||||
|
||||
const local = new TestServer();
|
||||
|
|
|
@ -1,10 +1,10 @@
|
|||
import * as stream from 'stream';
|
||||
import {Response} from '../src';
|
||||
import TestServer from './utils/server';
|
||||
import chai from 'chai';
|
||||
import resumer from 'resumer';
|
||||
import stringToArrayBuffer from 'string-to-arraybuffer';
|
||||
import Blob from 'fetch-blob';
|
||||
import {Response} from '../src/index.js';
|
||||
import TestServer from './utils/server.js';
|
||||
|
||||
const {expect} = chai;
|
||||
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
import * as http from 'http';
|
||||
import * as zlib from 'zlib';
|
||||
import {multipart as Multipart} from 'parted';
|
||||
import http from 'http';
|
||||
import zlib from 'zlib';
|
||||
import parted from 'parted';
|
||||
const {multipart: Multipart} = parted;
|
||||
|
||||
export default class TestServer {
|
||||
constructor() {
|
||||
|
@ -379,9 +380,3 @@ export default class TestServer {
|
|||
}
|
||||
}
|
||||
|
||||
if (require.main === module) {
|
||||
const server = new TestServer();
|
||||
server.start(() => {
|
||||
console.log(`Server started listening at port ${server.port}`);
|
||||
});
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue