diff --git a/.github/workflows/branch.yml b/.github/workflows/branch.yml index 67b2d0ae..d1ff7881 100644 --- a/.github/workflows/branch.yml +++ b/.github/workflows/branch.yml @@ -10,10 +10,10 @@ jobs: name: Install runs-on: ubuntu-latest steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 - name: Cache node_modules id: cacheModules - uses: actions/cache@v3 + uses: actions/cache@v4 with: path: ~/.npm # this is cache where npm installs from before going out to the network key: ${{ runner.os }}-node-${{ hashFiles('**/package.json') }} @@ -25,12 +25,14 @@ jobs: name: Debug runs-on: ubuntu-latest steps: - - uses: hmarr/debug-action@v2 + - uses: hmarr/debug-action@v3 checks: name: Check needs: [install] uses: ./.github/workflows/checks.yml + with: + ref: ${{ github.sha }} # The security job can't run on pull requests opened from forks because # Github doesn't pass down the SNYK_TOKEN environment variable. @@ -39,8 +41,8 @@ jobs: needs: [install] runs-on: ubuntu-latest steps: - - uses: actions/checkout@v3 - - uses: actions/cache@v3 + - uses: actions/checkout@v4 + - uses: actions/cache@v4 with: path: ~/.npm # this is cache where npm installs from before going out to the network key: ${{ runner.os }}-node-${{ hashFiles('**/package.json') }} diff --git a/.github/workflows/checks.yml b/.github/workflows/checks.yml index 6dc5a19f..932d476a 100644 --- a/.github/workflows/checks.yml +++ b/.github/workflows/checks.yml @@ -1,6 +1,13 @@ name: v4.x checks -on: [workflow_call] +on: + workflow_call: + inputs: + ref: + description: 'The commit the workflow should check out' + required: true + default: ${{ github.sha }} + type: string jobs: test-node: @@ -12,13 +19,15 @@ jobs: node-version: [14.x, 16.x, 18.x, 20.x] # See supported Node.js release schedule at https://nodejs.org/en/about/releases/ steps: - - uses: actions/checkout@v3 - - uses: actions/cache@v3 + - uses: actions/checkout@v4 + with: + ref: ${{ inputs.ref }} + - uses: actions/cache@v4 with: path: ~/.npm # this is cache where npm installs from before going out to the network key: ${{ runner.os }}-node-${{ hashFiles('**/package.json') }} - name: Use Node.js ${{ matrix.node-version }} - uses: actions/setup-node@v3 + uses: actions/setup-node@v4 with: node-version: ${{ matrix.node-version }} - run: npm install --prefer-offline @@ -28,13 +37,15 @@ jobs: name: Browser Test Specs runs-on: ubuntu-latest steps: - - uses: actions/checkout@v3 - - uses: actions/cache@v3 + - uses: actions/checkout@v4 + with: + ref: ${{ inputs.ref }} + - uses: actions/cache@v4 with: path: ~/.npm # this is cache where npm installs from before going out to the network key: ${{ runner.os }}-node-${{ hashFiles('**/package.json') }} - name: Use Node.js ${{ matrix.node-version }} - uses: actions/setup-node@v3 + uses: actions/setup-node@v4 with: node-version: ${{ matrix.node-version }} - run: npm install --prefer-offline @@ -44,8 +55,10 @@ jobs: name: Code Lint runs-on: ubuntu-latest steps: - - uses: actions/checkout@v3 - - uses: actions/cache@v3 + - uses: actions/checkout@v4 + with: + ref: ${{ inputs.ref }} + - uses: actions/cache@v4 with: path: ~/.npm # this is cache where npm installs from before going out to the network key: ${{ runner.os }}-node-${{ hashFiles('**/package.json') }} @@ -56,8 +69,10 @@ jobs: name: Types runs-on: ubuntu-latest steps: - - uses: actions/checkout@v3 - - uses: actions/cache@v3 + - uses: actions/checkout@v4 + with: + ref: ${{ inputs.ref }} + - uses: actions/cache@v4 with: path: ~/.npm # this is cache where npm installs from before going out to the network key: ${{ runner.os }}-node-${{ hashFiles('**/package.json') }} diff --git a/.github/workflows/pr.yml b/.github/workflows/pr.yml index 464d1729..d0a72612 100644 --- a/.github/workflows/pr.yml +++ b/.github/workflows/pr.yml @@ -22,16 +22,18 @@ jobs: name: Debug runs-on: ubuntu-latest steps: - - uses: hmarr/debug-action@v2 + - uses: hmarr/debug-action@v3 install: name: Install runs-on: ubuntu-latest steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 + with: + ref: ${{ github.event.pull_request.head.sha }} - name: Cache node_modules id: cacheModules - uses: actions/cache@v3 + uses: actions/cache@v4 with: path: ~/.npm # this is cache where npm installs from before going out to the network key: ${{ runner.os }}-node-${{ hashFiles('**/package.json') }} @@ -43,3 +45,5 @@ jobs: name: Checks needs: [install] uses: ./.github/workflows/checks.yml + with: + ref: ${{ github.event.pull_request.head.sha }} diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index c064dba8..5333a3a6 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -16,10 +16,10 @@ jobs: name: Install runs-on: ubuntu-latest steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 - name: Cache node_modules id: cacheModules - uses: actions/cache@v3 + uses: actions/cache@v4 with: path: ~/.npm # cache where "npm install" uses before going out to the network key: ${{ runner.os }}-node-${{ hashFiles('**/package.json') }} @@ -31,7 +31,7 @@ jobs: name: Debug runs-on: ubuntu-latest steps: - - uses: hmarr/debug-action@v2 + - uses: hmarr/debug-action@v3 checks: name: Check @@ -45,8 +45,8 @@ jobs: needs: [install] runs-on: ubuntu-latest steps: - - uses: actions/checkout@v3 - - uses: actions/cache@v3 + - uses: actions/checkout@v4 + - uses: actions/cache@v4 with: path: ~/.npm # cache where "npm install" uses before going out to the network key: ${{ runner.os }}-node-${{ hashFiles('**/package.json') }} @@ -60,13 +60,13 @@ jobs: runs-on: ubuntu-latest needs: [checks, security] steps: - - uses: actions/checkout@v3 - - uses: actions/setup-node@v3 + - uses: actions/checkout@v4 + - uses: actions/setup-node@v4 with: node-version-file: '.nvmrc' # Setup .npmrc file to publish to npm registry-url: 'https://registry.npmjs.org' - - uses: actions/cache@v3 + - uses: actions/cache@v4 with: path: ~/.npm # this is cache where npm installs from before going out to the network key: ${{ runner.os }}-node-${{ hashFiles('**/package.json') }} diff --git a/.nvmrc b/.nvmrc index 8351c193..209e3ef4 100644 --- a/.nvmrc +++ b/.nvmrc @@ -1 +1 @@ -14 +20 diff --git a/Makefile b/Makefile index c0ca39e5..425e9230 100644 --- a/Makefile +++ b/Makefile @@ -1,3 +1,5 @@ +include makefiles/*.mk + .PHONY: all all: test lint typecheck @@ -40,120 +42,3 @@ test/fetch-api/api.spec.js: test/fetch-api/api.spec.ts @echo "" @echo "=> make $@" @npx tsc - - -## -# Checks - -.PHONY: commitlint -commitlint: node_modules - npx commitlint --from origin/main --to HEAD --verbose - -.PHONY: cov -cov: - npx nyc report --reporter=text-lcov > .reports/coverage.lcov && npx codecov - -.PHONY: lint -lint: - @echo "" - @echo "=> make $@" - @npx standard - -.PHONY: secure -secure: - @echo "" - @echo "=> make $@" - @npx snyk test - -.PHONY: typecheck -typecheck: - @echo "" - @echo "=> make $@" - @npx tsc --lib ES6 --noEmit index.d.ts ./test/fetch-api/api.spec.ts - - -## -# Test groups - -.PHONY: test -test: | test-browser test-node - -.PHONY: test-browser -test-browser: |\ - test-fetch-browser-native \ - test-fetch-browser-whatwg \ - test-fetch-browser-service-worker \ - test-module-web-cjs \ - test-module-web-esm \ - test-module-react-native - -.PHONY: test-node -test-node: |\ - test-fetch-node-native \ - test-fetch-node-fetch \ - test-module-node-cjs \ - test-module-node-esm - - -## -# Test units - -.PHONY: test-fetch-browser-native -test-fetch-browser-native: | dist test/fetch-api/api.spec.js - @echo "" - @echo "=> make $@" - @./test/fetch-api/browser/run.sh - -.PHONY: test-fetch-browser-whatwg -test-fetch-browser-whatwg: | dist test/fetch-api/api.spec.js - @echo "" - @echo "=> make $@" - @./test/fetch-api/whatwg/run.sh - -.PHONY: test-fetch-browser-service-worker -test-fetch-browser-service-worker: dist test/fetch-api/api.spec.js - @echo "" - @echo "=> make $@" - @./test/fetch-api/service-worker/run.sh - -.PHONY: test-fetch-node-native -test-fetch-node-native: | dist test/fetch-api/api.spec.js - @echo "" - @echo "=> make $@" - @./test/fetch-api/node/run.sh - -.PHONY: test-fetch-node-fetch -test-fetch-node-fetch: | dist test/fetch-api/api.spec.js - @echo "" - @echo "=> make $@" - @./test/fetch-api/node-fetch/run.sh - -.PHONY: test-module-web-cjs -test-module-web-cjs: | dist - @echo "" - @echo "=> make $@" - @./test/module-system/web.cjs/run.sh - -.PHONY: test-module-web-esm -test-module-web-esm: | dist - @echo "" - @echo "=> make $@" - @./test/module-system/web.esm/run.sh - -.PHONY: test-module-node-cjs -test-module-node-cjs: | dist - @echo "" - @echo "=> make $@" - @./test/module-system/node.cjs/run.sh - -.PHONY: test-module-node-esm -test-module-node-esm: | dist - @echo "" - @echo "=> make $@" - @./test/module-system/node.esm/run.sh - -.PHONY: test-module-react-native -test-module-react-native: | dist - @echo "" - @echo "=> make $@" - @./test/module-system/react-native/run.sh diff --git a/bin/is-port-in-use b/bin/is-port-in-use new file mode 100755 index 00000000..5efbd743 --- /dev/null +++ b/bin/is-port-in-use @@ -0,0 +1,17 @@ +#!/usr/bin/env node + +const net = require('net') +const args = process.argv.slice(2) +const port = args[0] || 8000 +const server = net.createServer().listen(port) + +server.on('listening', () => { + server.close() + console.log('Port ' + port + ' is available.') + process.exit(0) +}) + +server.on('error', () => { + console.log('Port ' + port + ' is in use.') + process.exit(1) +}) diff --git a/makefiles/checks.mk b/makefiles/checks.mk new file mode 100644 index 00000000..312b9dcc --- /dev/null +++ b/makefiles/checks.mk @@ -0,0 +1,30 @@ + +## +# Checks + +.PHONY: commitlint +commitlint: node_modules + npx commitlint --from origin/main --to HEAD --verbose + +.PHONY: cov +cov: + npx nyc report --reporter=text-lcov > .reports/coverage.lcov && npx codecov + +.PHONY: lint +lint: + @echo "" + @echo "=> make $@" + @npx standard + +.PHONY: secure +secure: + @echo "" + @echo "=> make $@" + @npx snyk test + +.PHONY: typecheck +typecheck: + @echo "" + @echo "=> make $@" + @npx tsc --lib ES6 --noEmit index.d.ts ./test/fetch-api/api.spec.ts + diff --git a/makefiles/test.mk b/makefiles/test.mk new file mode 100644 index 00000000..736ffc79 --- /dev/null +++ b/makefiles/test.mk @@ -0,0 +1,86 @@ + +## +# Test groups + +.PHONY: test +test: | test-browser test-node + +.PHONY: test-browser +test-browser: |\ + test-fetch-browser-native \ + test-fetch-browser-whatwg \ + test-fetch-browser-service-worker \ + test-module-web-cjs \ + test-module-web-esm \ + test-module-react-native + +.PHONY: test-node +test-node: |\ + test-fetch-node-native \ + test-fetch-node-fetch \ + test-module-node-cjs \ + test-module-node-esm + + +## +# Test units + +.PHONY: test-fetch-browser-native +test-fetch-browser-native: | dist test/fetch-api/api.spec.js + @echo "" + @echo "=> make $@" + @./test/fetch-api/browser/run.sh + +.PHONY: test-fetch-browser-whatwg +test-fetch-browser-whatwg: | dist test/fetch-api/api.spec.js + @echo "" + @echo "=> make $@" + @./test/fetch-api/whatwg/run.sh + +.PHONY: test-fetch-browser-service-worker +test-fetch-browser-service-worker: dist test/fetch-api/api.spec.js + @echo "" + @echo "=> make $@" + @./test/fetch-api/service-worker/run.sh + +.PHONY: test-fetch-node-native +test-fetch-node-native: | dist test/fetch-api/api.spec.js + @echo "" + @echo "=> make $@" + @./test/fetch-api/node/run.sh + +.PHONY: test-fetch-node-fetch +test-fetch-node-fetch: | dist test/fetch-api/api.spec.js + @echo "" + @echo "=> make $@" + @./test/fetch-api/node-fetch/run.sh + +.PHONY: test-module-web-cjs +test-module-web-cjs: | dist + @echo "" + @echo "=> make $@" + @./test/module-system/web.cjs/run.sh + +.PHONY: test-module-web-esm +test-module-web-esm: | dist + @echo "" + @echo "=> make $@" + @./test/module-system/web.esm/run.sh + +.PHONY: test-module-node-cjs +test-module-node-cjs: | dist + @echo "" + @echo "=> make $@" + @./test/module-system/node.cjs/run.sh + +.PHONY: test-module-node-esm +test-module-node-esm: | dist + @echo "" + @echo "=> make $@" + @./test/module-system/node.esm/run.sh + +.PHONY: test-module-react-native +test-module-react-native: | dist + @echo "" + @echo "=> make $@" + @./test/module-system/react-native/run.sh diff --git a/package.json b/package.json index 30f06907..c88009b7 100644 --- a/package.json +++ b/package.json @@ -73,7 +73,6 @@ "devDependencies": { "@commitlint/cli": "17.6.6", "@commitlint/config-conventional": "17.6.6", - "@rollup/plugin-terser": "0.4.3", "@types/chai": "4.3.5", "@types/mocha": "10.0.1", "@types/node": "18.15.13", @@ -92,6 +91,8 @@ "rimraf": "5.0.1", "rollup": "3.26.0", "rollup-plugin-copy": "3.4.0", + "rollup-plugin-esbuild": "6.1.1", + "rollup-plugin-esbuild-minify": "1.1.2", "semver": "7.5.3", "serve-index": "1.9.1", "standard": "17.1.0", diff --git a/rollup.config.js b/rollup.config.js index dfd00e5d..0958bd28 100644 --- a/rollup.config.js +++ b/rollup.config.js @@ -1,7 +1,7 @@ /* Rollup creates the browser version of the polyfill and ponyfill. */ import path from 'path' import copy from 'rollup-plugin-copy' -import terser from '@rollup/plugin-terser' +import { minify } from 'rollup-plugin-esbuild' const input = path.join(__dirname, 'node_modules', 'whatwg-fetch', 'fetch.js') @@ -128,7 +128,7 @@ export default [ `) }, plugins: [ - terser() + minify() ] } ] diff --git a/test/setup/server.sh b/test/setup/server.sh index f9ecb62d..337cc5cb 100644 --- a/test/setup/server.sh +++ b/test/setup/server.sh @@ -11,7 +11,7 @@ kill_server() { } is_server_ready() { - lsof -i :8000 > /dev/null + ./bin/is-port-in-use > /dev/null } wait_server() {