From efdf1995795921488106ef978c140876ff81ff19 Mon Sep 17 00:00:00 2001 From: Jon Koops Date: Sun, 29 Oct 2023 17:24:56 +0100 Subject: [PATCH] feat!: remove support for CommonJS --- README.md | 6 ++--- examples/other-package-commonjs.ts | 23 ------------------ examples/request-cookie-support-for-node.ts | 27 --------------------- package.json | 14 +++-------- tsconfig.esm.json => tsconfig.build.json | 2 +- tsconfig.cjs.json | 11 --------- 6 files changed, 6 insertions(+), 77 deletions(-) delete mode 100644 examples/other-package-commonjs.ts delete mode 100644 examples/request-cookie-support-for-node.ts rename tsconfig.esm.json => tsconfig.build.json (83%) delete mode 100644 tsconfig.cjs.json diff --git a/README.md b/README.md index 38c62bfcf..73b1e3088 100644 --- a/README.md +++ b/README.md @@ -30,7 +30,7 @@ Minimal GraphQL client supporting Node and browsers for scripts or simple apps - Most **simple & lightweight** GraphQL client - Promise-based API (works with `async` / `await`) -- ESM native package (CJS build is included for now as well, but will eventually be removed) +- [Pure ESM package](https://gist.github.com/sindresorhus/a39789f98801d908bbc7ff3ecc99d99c) - First class TypeScript support - Including `TypedDocumentNode` - Isomorphic (works in both Nodejs and Browsers) @@ -94,7 +94,6 @@ await client.request(document) - [Cancellation](./examples/request-cancellation.ts) - [Headers Per Request (static)](./examples/request-headers-static-per-request.ts) - [Headers Per Request (dynamic)](./examples/request-headers-dynamic-per-request.ts) - - [Cookie support for Nodejs](./examples/request-cookie-support-for-node.ts) - [Handle Raw Response](./examples/request-handle-raw-response.ts) - GraphQL: - [Document Variables](./examples/graphql-document-variables.ts) @@ -102,7 +101,7 @@ await client.request(document) - [Batching Requests](./examples/graphql-batching-requests.ts) - Configuration: - [Fetch: Passing Options](./examples/configuration-fetch-options.ts) - - [Fetch: Use custom function](./examples/configuration-fetch-custom-function.ts) + - [Fetch: Use custom function (e.g. cookie support)](./examples/configuration-fetch-custom-function.ts) - [Custom JSON Serializer](./examples/configuration-request-json-serializer.ts) - [Incremental: Set Endpoint](./examples/configuration-incremental-endpoint.ts) - [Incremental: Set Request Headers](./examples/configuration-incremental-request-headers.ts) @@ -113,7 +112,6 @@ await client.request(document) - Other: - [Middleware](./examples/other-middleware.ts) - [Error Handling](./examples/other-error-handling.ts) - - [OCommonJS Support](./examples/other-package-commonjs.ts) ## Node Version Support diff --git a/examples/other-package-commonjs.ts b/examples/other-package-commonjs.ts deleted file mode 100644 index ceaea508d..000000000 --- a/examples/other-package-commonjs.ts +++ /dev/null @@ -1,23 +0,0 @@ -/* eslint-disable */ - -const { request, gql } = require(`graphql-request`) - -main() - -async function main() { - const endpoint = `https://api.graph.cool/simple/v1/cixos23120m0n0173veiiwrjr` - - const query = gql` - { - Movie(title: "Inception") { - releaseDate - actors { - name - } - } - } - ` - - const data = await request(endpoint, query) - console.log(data) -} diff --git a/examples/request-cookie-support-for-node.ts b/examples/request-cookie-support-for-node.ts deleted file mode 100644 index ffea693bf..000000000 --- a/examples/request-cookie-support-for-node.ts +++ /dev/null @@ -1,27 +0,0 @@ -;(global as any).fetch = require(`fetch-cookie/node-fetch`)(require(`node-fetch`)) //eslint-disable-line - -import { gql, GraphQLClient } from '../src/index.js' - -const client = new GraphQLClient(`https://api.graph.cool/simple/v1/cixos23120m0n0173veiiwrjr`, { - headers: { - authorization: `Bearer MY_TOKEN`, - }, -}) - -const query = gql` - { - Movie(title: "Inception") { - releaseDate - actors { - name - } - } - } -` - -interface Data { - Movie: { releaseDate: string; actors: Array<{ name: string }> } -} - -const data = await client.rawRequest(query) -console.log(data) diff --git a/package.json b/package.json index 9ac0bbb7f..61e8b4dd7 100644 --- a/package.json +++ b/package.json @@ -2,20 +2,14 @@ "name": "graphql-request", "version": "0.0.0-dripip", "type": "module", - "main": "./build/cjs/index.js", "exports": { ".": { - "require": { - "types": "./build/cjs/index.d.ts", - "default": "./build/cjs/index.js" - }, "import": { - "types": "./build/esm/index.d.ts", - "default": "./build/esm/index.js" + "types": "./build/index.d.ts", + "default": "./build/index.js" } } }, - "types": "./build/esm/index.d.ts", "packageManager": "pnpm@8.10.0", "files": [ "build", @@ -51,9 +45,7 @@ "check:lint": "eslint . --ext .ts,.tsx --max-warnings 0", "prepublishOnly": "pnpm build", "build:docs": "doctoc README.md --notitle && prettier --write README.md", - "build": "pnpm clean && pnpm build:cjs && pnpm build:esm", - "build:cjs": "pnpm tsc --project tsconfig.cjs.json && echo '{\"type\":\"commonjs\"}' > build/cjs/package.json", - "build:esm": "pnpm tsc --project tsconfig.esm.json", + "build": "pnpm clean && pnpm tsc --project tsconfig.build.json", "clean": "tsc --build --clean && rm -rf build", "test": "vitest", "test:coverage": "pnpm test -- --coverage", diff --git a/tsconfig.esm.json b/tsconfig.build.json similarity index 83% rename from tsconfig.esm.json rename to tsconfig.build.json index 071db7a3e..c51514c70 100644 --- a/tsconfig.esm.json +++ b/tsconfig.build.json @@ -1,7 +1,7 @@ { "extends": "./tsconfig.json", "compilerOptions": { - "outDir": "build/esm", + "outDir": "build", "rootDir": "src" }, "include": ["src"], diff --git a/tsconfig.cjs.json b/tsconfig.cjs.json deleted file mode 100644 index 595bb0c7c..000000000 --- a/tsconfig.cjs.json +++ /dev/null @@ -1,11 +0,0 @@ -{ - "extends": "./tsconfig.json", - "compilerOptions": { - "outDir": "build/cjs", - "module": "commonjs", - "moduleResolution": "node", - "rootDir": "src" - }, - "include": ["src"], - "exclude": ["**/*.spec.*"] -}