diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 3b6f33d..568f17a 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -31,7 +31,7 @@ jobs: strategy: fail-fast: false matrix: - node-version: [10.x, 12.x, 14.x, 15.x] + node-version: [10.x, 12.x, 14.x, 16.x] # See supported Node.js release schedule at https://nodejs.org/en/about/releases/ steps: - uses: actions/checkout@v2 diff --git a/.gitignore b/.gitignore index bd2263a..88b3696 100644 --- a/.gitignore +++ b/.gitignore @@ -27,11 +27,12 @@ DerivedData *.xcuserstate project.xcworkspace -# Android/IntelliJ +# IDEs # build/ .idea .gradle +.vscode local.properties *.iml diff --git a/Makefile b/Makefile index cca59be..7e15049 100644 --- a/Makefile +++ b/Makefile @@ -8,9 +8,12 @@ build: build-dist build-test build-dist: npx rollup -c -build-test: test/fetch/api.spec.js +build-test: test/fetch-api/api.spec.js npx tsc +browser: + ./bin/server --exec "npx open-cli http://localhost:8000/test/fetch-api/browser/" + commitlint: node_modules npx commitlint --from origin/main --to HEAD --verbose @@ -34,32 +37,32 @@ test: test-fetch test-module test-fetch: test-fetch-browser test-fetch-whatwg test-fetch-node test-fetch-browser: build - ./test/fetch/browser/run.sh + ./test/fetch-api/browser/run.sh test-fetch-whatwg: build - ./test/fetch/whatwg/run.sh + ./test/fetch-api/whatwg/run.sh test-fetch-node: build - ./test/fetch/node/run.sh + ./test/fetch-api/node/run.sh test-module: test-module-web-cjs test-module-web-esm test-module-node-cjs test-module-node-esm test-module-react-native test-module-web-cjs: build - ./test/module/web.cjs/run.sh + ./test/module-system/web.cjs/run.sh test-module-web-esm: build - ./test/module/web.esm/run.sh + ./test/module-system/web.esm/run.sh test-module-node-cjs: build - ./test/module/node.cjs/run.sh + ./test/module-system/node.cjs/run.sh test-module-node-esm: build - ./test/module/node.esm/run.sh + ./test/module-system/node.esm/run.sh test-module-react-native: build - ./test/module/react-native/run.sh + ./test/module-system/react-native/run.sh typecheck: - npx tsc --lib ES6 --noEmit index.d.ts ./test/fetch/api.spec.ts + npx tsc --lib ES6 --noEmit index.d.ts ./test/fetch-api/api.spec.ts .PHONY: all build deploy lint test test-fetch test-fetch-browser test-fetch-whatwg test-fetch-node test-module test-module-web-cjs test-module-web-esm test-module-node-cjs test-module-node-esm test-module-react-native typecheck diff --git a/bin/server b/bin/server index c3173d5..37dccb9 100755 --- a/bin/server +++ b/bin/server @@ -1,8 +1,9 @@ #!/usr/bin/env node +const yargs = require('yargs/yargs') const { spawn } = require('child_process') const express = require('express') const bodyParser = require('body-parser') -const serveIndex = require('serve-index'); +const serveIndex = require('serve-index') const path = require('path') const app = express() const dir = path.join(__dirname, '..') @@ -19,9 +20,9 @@ app.patch('/request', processRequest) app.delete('/request', processRequest) // This line needs to be at the end, otherwise it will block any method different than GET -app.use(express.static(dir), serveIndex(dir, {'icons': true, view: 'details'})) +app.use(express.static(dir), serveIndex(dir, { icons: true, view: 'details' })) -function processRequest(req, res) { +function processRequest (req, res) { const headers = {} const isDelete = req.method === 'DELETE' @@ -39,39 +40,43 @@ function processRequest(req, res) { }) } -function processFileUrl(argv) { - const args = argv.slice(2) +function processFileUrl (args) { const fileParamIndex = args.indexOf('-f') + if (fileParamIndex > 0) { const fileIndex = fileParamIndex + 1 args[fileIndex] = args[fileIndex].replace(/^\.\//, `http://localhost:${port}/`) } + return args } const hostname = '127.0.0.1' const port = 8000 -const args = processFileUrl(process.argv) +const { argv } = yargs(process.argv.slice(2)) const server = app.listen(port, hostname, () => { - if (args.length === 0) { - console.log(`Test server listening at http://localhost:${port}`) - return - } + console.log(`Test server listening at http://localhost:${port}`) - const command = args[0] - const params = args.slice(1) - const child = spawn(command, params, { - env: { - ...process.env, - FORCE_COLOR: true // ensure mocha outputs colors on node test - } - }) + if (argv.exec) { + const args = processFileUrl(argv.exec.split(' ')) + const command = args[0] + const params = args.slice(1) + const child = spawn(command, params, { + env: { + ...process.env, + FORCE_COLOR: true // ensure mocha outputs colors on node test + } + }) - child.stdout.pipe(process.stdout) - child.stderr.pipe(process.stdout) - child.on('exit', code => { - server.close() - process.exit(code) - }) + child.stdout.pipe(process.stdout) + child.stderr.pipe(process.stdout) + + if (argv.closeOnExec) { + child.on('exit', code => { + server.close() + process.exit(code) + }) + } + } }) diff --git a/dist/browser-polyfill.js b/dist/browser-polyfill.js index da6342e..11ccad1 100644 --- a/dist/browser-polyfill.js +++ b/dist/browser-polyfill.js @@ -528,5 +528,5 @@ var irrelevant = (function (exports) { return exports; -}({})); +})({}); })(typeof self !== 'undefined' ? self : this); diff --git a/dist/browser-ponyfill.js b/dist/browser-ponyfill.js index f26eb09..f216aa3 100644 --- a/dist/browser-ponyfill.js +++ b/dist/browser-ponyfill.js @@ -537,7 +537,7 @@ var irrelevant = (function (exports) { return exports; -}({})); +})({}); })(__self__); __self__.fetch.ponyfill = true; // Remove "polyfill" property added by whatwg-fetch diff --git a/package.json b/package.json index c3dba2c..4db780a 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "cross-fetch", - "version": "3.1.4", + "version": "3.1.5", "description": "Universal WHATWG Fetch API for Node, Browsers and React Native", "homepage": "https://github.com/lquixada/cross-fetch", "main": "dist/node-ponyfill.js", @@ -24,8 +24,7 @@ "globals": [ "expect", "assert", - "chai", - "sinon" + "chai" ], "ignore": [ "/dist/", @@ -71,38 +70,38 @@ "url": "https://github.com/lquixada/cross-fetch/issues" }, "dependencies": { - "node-fetch": "2.6.1" + "node-fetch": "2.6.7" }, "devDependencies": { "@commitlint/cli": "12.0.1", "@commitlint/config-conventional": "12.0.1", - "@types/chai": "4.2.15", + "@types/chai": "4.2.22", "@types/mocha": "8.2.2", "@types/node": "14.14.37", "body-parser": "1.19.0", "chai": "4.3.4", - "codecov": "3.8.1", + "codecov": "3.8.3", "cz-conventional-changelog": "3.3.0", "express": "4.17.1", "husky": "6.0.0", "lint-staged": "10.5.4", "mocha": "8.3.2", "mocha-headless-chrome": "3.1.0", - "nock": "13.0.11", + "nock": "13.1.3", "nyc": "15.1.0", - "ora": "5.4.0", - "rollup": "2.44.0", + "open-cli": "6.0.1", + "rollup": "2.58.0", "rollup-plugin-copy": "3.4.0", "rollup-plugin-terser": "7.0.2", "semver": "7.3.5", "serve-index": "1.9.1", - "sinon": "10.0.0", - "standard": "16.0.3", - "standard-version": "9.1.1", - "typescript": "4.2.3", - "webpack": "5.28.0", - "webpack-cli": "4.6.0", - "whatwg-fetch": "3.0.0" + "standard": "16.0.4", + "standard-version": "9.3.1", + "typescript": "4.4.4", + "webpack": "5.58.2", + "webpack-cli": "4.9.0", + "whatwg-fetch": "3.0.0", + "yargs": "16.2.0" }, "files": [ "dist", diff --git a/test/fetch/api.spec.js b/test/fetch-api/api.spec.js similarity index 100% rename from test/fetch/api.spec.js rename to test/fetch-api/api.spec.js diff --git a/test/fetch/api.spec.ts b/test/fetch-api/api.spec.ts similarity index 100% rename from test/fetch/api.spec.ts rename to test/fetch-api/api.spec.ts diff --git a/test/fetch/browser/index.html b/test/fetch-api/browser/index.html similarity index 86% rename from test/fetch/browser/index.html rename to test/fetch-api/browser/index.html index 1d738b9..0c68368 100644 --- a/test/fetch/browser/index.html +++ b/test/fetch-api/browser/index.html @@ -1,5 +1,6 @@ +