From 29ffeca731b2731588d09dc488e29b516ca26dfd Mon Sep 17 00:00:00 2001 From: wolfy1339 Date: Mon, 8 Apr 2024 12:48:25 -0400 Subject: [PATCH 1/4] fix(pkg): add a default fallback See #665 #667 --- scripts/build.mjs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/build.mjs b/scripts/build.mjs index 5e76ea9ee..ff1743e07 100644 --- a/scripts/build.mjs +++ b/scripts/build.mjs @@ -55,12 +55,12 @@ async function main() { { ...pkg, files: ["dist-*/**", "bin/**"], - main: "./dist-src/index.js", types: "./dist-types/index.d.ts", exports: { ".": { types: "./dist-types/index.d.ts", import: "./dist-src/index.js", + default: "./dist-src/index.js" }, }, sideEffects: false, From 232770a847e32c83c7e29398a60a52c2ee595015 Mon Sep 17 00:00:00 2001 From: wolfy1339 Date: Mon, 8 Apr 2024 12:50:24 -0400 Subject: [PATCH 2/4] fix(pkg): add an export for `dist-types/types.d.ts` Many people are importing from `dist-types/types.d.ts`, and the switch to ESM prevents them from using any of the types defined in that file. --- scripts/build.mjs | 3 +++ 1 file changed, 3 insertions(+) diff --git a/scripts/build.mjs b/scripts/build.mjs index ff1743e07..8a25107a2 100644 --- a/scripts/build.mjs +++ b/scripts/build.mjs @@ -62,6 +62,9 @@ async function main() { import: "./dist-src/index.js", default: "./dist-src/index.js" }, + "./types": { + types: "./dist-types/types.d.ts" + } }, sideEffects: false, }, From e83812f5495cac94c46d294a8c7fcdc7fc901190 Mon Sep 17 00:00:00 2001 From: wolfy1339 Date: Mon, 8 Apr 2024 12:50:51 -0400 Subject: [PATCH 3/4] fix: mark `graphql` import as a type import --- src/index.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/index.ts b/src/index.ts index 0dd0950ac..5be0a3662 100644 --- a/src/index.ts +++ b/src/index.ts @@ -2,7 +2,7 @@ import { getUserAgent } from "universal-user-agent"; import type { HookCollection } from "before-after-hook"; import Hook from "before-after-hook"; import { request } from "@octokit/request"; -import { graphql, withCustomRequest } from "@octokit/graphql"; +import { type graphql, withCustomRequest } from "@octokit/graphql"; import { createTokenAuth } from "@octokit/auth-token"; import type { From 89d822cead3131ef154381ca9c5e248b6d9639a6 Mon Sep 17 00:00:00 2001 From: wolfy1339 Date: Mon, 8 Apr 2024 13:29:53 -0400 Subject: [PATCH 4/4] docs: add note on needed config changes for TypeScript --- README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/README.md b/README.md index 622429c03..ed4c07002 100644 --- a/README.md +++ b/README.md @@ -55,6 +55,8 @@ import { Octokit } from "@octokit/core"; +As we use [conditional exports](https://nodejs.org/api/packages.html#conditional-exports), you will need to adapt your `tsconfig.json`. See the TypeScript docs on [package.json "exports"](https://www.typescriptlang.org/docs/handbook/modules/reference.html#packagejson-exports). + ### REST API example ```js