Skip to content

Commit af3d390

Browse files
authored
fix(pkg): add default fallback and types export (#673)
* 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
1 parent 82a36c9 commit af3d390

File tree

3 files changed

+7
-2
lines changed

3 files changed

+7
-2
lines changed

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,8 @@ import { Octokit } from "@octokit/core";
5555
</tbody>
5656
</table>
5757

58+
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).
59+
5860
### REST API example
5961

6062
```js

scripts/build.mjs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,13 +55,16 @@ async function main() {
5555
{
5656
...pkg,
5757
files: ["dist-*/**", "bin/**"],
58-
main: "./dist-src/index.js",
5958
types: "./dist-types/index.d.ts",
6059
exports: {
6160
".": {
6261
types: "./dist-types/index.d.ts",
6362
import: "./dist-src/index.js",
63+
default: "./dist-src/index.js"
6464
},
65+
"./types": {
66+
types: "./dist-types/types.d.ts"
67+
}
6568
},
6669
sideEffects: false,
6770
},

src/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { getUserAgent } from "universal-user-agent";
22
import type { HookCollection } from "before-after-hook";
33
import Hook from "before-after-hook";
44
import { request } from "@octokit/request";
5-
import { graphql, withCustomRequest } from "@octokit/graphql";
5+
import { type graphql, withCustomRequest } from "@octokit/graphql";
66
import { createTokenAuth } from "@octokit/auth-token";
77

88
import type {

0 commit comments

Comments
 (0)