Skip to content

Commit

Permalink
fix(pkg): add default fallback and types export (#673)
Browse files Browse the repository at this point in the history
* fix(pkg): add a default fallback

See #665 #667

* 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.

* fix: mark `graphql` import as a type import

* docs: add note on needed config changes for TypeScript
  • Loading branch information
wolfy1339 committed Apr 9, 2024
1 parent 82a36c9 commit af3d390
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 2 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@ import { Octokit } from "@octokit/core";
</tbody>
</table>

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
Expand Down
5 changes: 4 additions & 1 deletion scripts/build.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -55,13 +55,16 @@ 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"
},
"./types": {
types: "./dist-types/types.d.ts"
}
},
sideEffects: false,
},
Expand Down
2 changes: 1 addition & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit af3d390

Please sign in to comment.