Skip to content

Commit

Permalink
Require Node.js 12.20.0 and move to ESM (#1141)
Browse files Browse the repository at this point in the history
* Use ESM import in runkit example file

* Update dependencies, version and transition to ESM

* Use ESM imports, add ESM-related info

* Remove rollup

* Lint TypeScript-related files

* Update dependency

* Lint & update dependency

* Lint

* Remove commonjs tests

* chore: update changelog

* Remove commonjs GitHub action

* Update funding.yml

* Update linter rules

* Lint

* Fix tsd

* Remove unnecessary types

* Simplify

* Use top-level await

* Update GitHub Actions

* Use Mocha with ESM

* Revamp

* specify what node version

* update formdata-node dep

* remove lint from example using top await

* updated name and link to formdata-polyfill

* Stop recommend form-data

* filter example - it has many duplicate variables

* Update type definitions to ESM

* Remove unused lint rule disable comment

* Remove leftover rollup and dist folder

* updated depn

* updated d.ts

* lint

* Fix breaking changes with blob v3 stream()

* revert eslint comment

* revert back to xo 0.39

Don't want to deal with all those new rules right now. will fix it later
fixed some of them...

* none TS fan trying to fix type definition

* Give me a break

* Test on all minimum supported Node.js versions (#1170)

* Test on all minimum supported Node.js versions

* Tweak Node.js workaround version range

* Handle Node.js 16 aborted error message

* fix node version string compare

Co-authored-by: Jimmy Wärting <jimmy@warting.se>

* bumped fetch-blob version

* import from dom lib

* rm unused comment

* updated required version in docs

* fixed named import

* set lowest support to 12.20.0

* comment explaining both

* rm log

Co-authored-by: Jimmy Wärting <jimmy@warting.se>
Co-authored-by: Linus Unnebäck <linus@folkdatorn.se>
  • Loading branch information
3 people committed Jul 18, 2021
1 parent ffef5e3 commit b50fbc1
Show file tree
Hide file tree
Showing 30 changed files with 251 additions and 452 deletions.
2 changes: 1 addition & 1 deletion .github/FUNDING.yml
@@ -1,6 +1,6 @@
# These are supported funding model platforms

github: # Replace with up to 4 GitHub Sponsors-enabled usernames e.g., [user1, user2]
github: node-fetch # Replace with up to 4 GitHub Sponsors-enabled usernames e.g., [user1, user2]
patreon: # Replace with a single Patreon username
open_collective: node-fetch # Replace with a single Open Collective username
ko_fi: # Replace with a single Ko-fi username
Expand Down
37 changes: 6 additions & 31 deletions .github/workflows/ci.yml
Expand Up @@ -14,52 +14,27 @@ jobs:
strategy:
matrix:
os: [ubuntu-latest, windows-latest, macOS-latest]
node: ["14", "12", engines]
node: ["12.20.0", "14.13.1", "16.0.0"]
exclude:
# On Windows, run tests with only the LTS environments.
- os: windows-latest
node: engines
node: "12.22.3"
- os: windows-latest
node: "14"
node: "16.0.0"
# On macOS, run tests with only the LTS environments.
- os: macOS-latest
node: engines
node: "12.22.3"
- os: macOS-latest
node: "14"
node: "16.0.0"

runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v2

- name: Get Node.JS version from package.json
if: matrix.node == 'engines'
id: get-version
run: echo ::set-output name=node::$(npx --q minimum-node-version)

- uses: actions/setup-node@v2-beta
if: matrix.node != 'engines'
- uses: actions/setup-node@v2
with:
node-version: ${{ matrix.node }}

- uses: actions/setup-node@v2-beta
if: matrix.node == 'engines'
with:
node-version: ${{steps.get-version.outputs.node}}

- run: npm install

- run: npm test -- --colors
if: matrix.node != 'engines'

- name: Test without coverage
if: matrix.node == 'engines'
run: |
npm i esm
npx mocha -r esm --colors
# upload coverage only once
- name: Coveralls
uses: coverallsapp/github-action@master
if: matrix.node == '12' && matrix.os == 'ubuntu-latest'
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
30 changes: 0 additions & 30 deletions .github/workflows/commonjs.yml

This file was deleted.

2 changes: 1 addition & 1 deletion .github/workflows/lint.yml
Expand Up @@ -13,7 +13,7 @@ jobs:
steps:
- uses: actions/checkout@v2
- name: Use Node.js
uses: actions/setup-node@v2-beta
uses: actions/setup-node@v2
with:
node-version: 14
- run: npm install
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/types.yml
Expand Up @@ -12,7 +12,7 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/setup-node@v2-beta
- uses: actions/setup-node@v2

- run: npm install

Expand Down
3 changes: 0 additions & 3 deletions .gitignore
@@ -1,9 +1,6 @@
# Sketch temporary file
~*.sketch

# Generated files
dist/

# Logs
logs
*.log
Expand Down
77 changes: 24 additions & 53 deletions @types/index.d.ts
@@ -1,19 +1,16 @@
/// <reference types="node" />
/// <reference lib="dom" />

/* eslint-disable no-var, import/no-mutable-exports */

import { Agent } from 'http';
import { URL, URLSearchParams } from 'url'
import Blob = require('fetch-blob');
import {Agent} from 'http';

type AbortSignal = {
readonly aborted: boolean;

addEventListener(type: "abort", listener: (this: AbortSignal) => void): void;
removeEventListener(type: "abort", listener: (this: AbortSignal) => void): void;
addEventListener: (type: 'abort', listener: (this: AbortSignal) => void) => void;
removeEventListener: (type: 'abort', listener: (this: AbortSignal) => void) => void;
};

type HeadersInit = Headers | Record<string, string> | Iterable<readonly [string, string]> | Iterable<Iterable<string>>;
export type HeadersInit = Headers | Record<string, string> | Iterable<readonly [string, string]> | Iterable<Iterable<string>>;

/**
* This Fetch API interface allows you to perform various actions on HTTP request and response headers.
Expand All @@ -22,7 +19,7 @@ type HeadersInit = Headers | Record<string, string> | Iterable<readonly [string,
* You can add to this using methods like append() (see Examples.)
* In all methods of this interface, header names are matched by case-insensitive byte sequence.
* */
declare class Headers {
export class Headers {
constructor(init?: HeadersInit);

append(name: string, value: string): void;
Expand Down Expand Up @@ -53,7 +50,7 @@ declare class Headers {
raw(): Record<string, string[]>;
}

interface RequestInit {
export interface RequestInit {
/**
* A BodyInit object or null to set request's body.
*/
Expand Down Expand Up @@ -88,21 +85,20 @@ interface RequestInit {
insecureHTTPParser?: boolean;
}

interface ResponseInit {
export interface ResponseInit {
headers?: HeadersInit;
status?: number;
statusText?: string;
}

type BodyInit =
export type BodyInit =
| Blob
| Buffer
| URLSearchParams
| NodeJS.ReadableStream
| string;
type BodyType = { [K in keyof Body]: Body[K] };
declare class Body {
constructor(body?: BodyInit, opts?: { size?: number });
declare class BodyMixin {
constructor(body?: BodyInit, options?: {size?: number});

readonly body: NodeJS.ReadableStream | null;
readonly bodyUsed: boolean;
Expand All @@ -115,9 +111,12 @@ declare class Body {
text(): Promise<string>;
}

type RequestRedirect = 'error' | 'follow' | 'manual';
type RequestInfo = string | Body;
declare class Request extends Body {
// `Body` must not be exported as a class since it's not exported from the JavaScript code.
export interface Body extends Pick<BodyMixin, keyof BodyMixin> {}

export type RequestRedirect = 'error' | 'follow' | 'manual';
export type RequestInfo = string | Request;
export class Request extends BodyMixin {
constructor(input: RequestInfo, init?: RequestInit);

/**
Expand All @@ -143,9 +142,9 @@ declare class Request extends Body {
clone(): Request;
}

type ResponseType = "basic" | "cors" | "default" | "error" | "opaque" | "opaqueredirect"
type ResponseType = 'basic' | 'cors' | 'default' | 'error' | 'opaque' | 'opaqueredirect';

declare class Response extends Body {
export class Response extends BodyMixin {
constructor(body?: BodyInit | null, init?: ResponseInit);

readonly headers: Headers;
Expand All @@ -160,8 +159,8 @@ declare class Response extends Body {
static error(): Response;
}

declare class FetchError extends Error {
constructor(message: string, type: string, systemError?: object);
export class FetchError extends Error {
constructor(message: string, type: string, systemError?: Record<string, unknown>);

name: 'FetchError';
[Symbol.toStringTag]: 'FetchError';
Expand All @@ -170,39 +169,11 @@ declare class FetchError extends Error {
errno?: string;
}

declare class AbortError extends Error {
export class AbortError extends Error {
type: string;
name: 'AbortError';
[Symbol.toStringTag]: 'AbortError';
}


declare function fetch(url: RequestInfo, init?: RequestInit): Promise<Response>;
declare class fetch {
static default: typeof fetch;
}
declare namespace fetch {
export function isRedirect(code: number): boolean;

export {
HeadersInit,
Headers,

RequestInit,
RequestRedirect,
RequestInfo,
Request,

BodyInit,

ResponseInit,
Response,

FetchError,
AbortError
};

export interface Body extends BodyType { }
}

export = fetch;
export function isRedirect(code: number): boolean;
export default function fetch(url: RequestInfo, init?: RequestInit): Promise<Response>;

0 comments on commit b50fbc1

Please sign in to comment.