Skip to content

Commit

Permalink
docs: update for ESM
Browse files Browse the repository at this point in the history
  • Loading branch information
wolfy1339 committed May 8, 2024
1 parent 2de6a3b commit 9bde849
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,19 @@ Node
Install with `npm install @octokit/action`

```js
const { Octokit } = require("@octokit/action");
// or: import { Octokit } from "@octokit/action";
import { Octokit } from "@octokit/action";
```

</td></tr>
</tbody>
</table>

> [!IMPORTANT]
> As we use [conditional exports](https://nodejs.org/api/packages.html#conditional-exports), you will need to adapt your `tsconfig.json` by setting `"moduleResolution": "node16", "module": "node16"`.
>
> See the TypeScript docs on [package.json "exports"](https://www.typescriptlang.org/docs/handbook/modules/reference.html#packagejson-exports).<br>
> See this [helpful guide on transitioning to ESM](https://gist.github.com/sindresorhus/a39789f98801d908bbc7ff3ecc99d99c) from [@sindresorhus](https://github.com/sindresorhus)
You can pass `secret.GITHUB_TOKEN` or any of your own secrets to a Node.js script. For example

```yml
Expand Down Expand Up @@ -59,7 +64,7 @@ Setting `GITHUB_TOKEN` on either [`with:`](https://help.github.com/en/actions/re

```js
// .github/actions/my-script.js
const { Octokit } = require("@octokit/action");
import { Octokit } from "@octokit/action";
const octokit = new Octokit();
Expand All @@ -69,7 +74,7 @@ const octokit = new Octokit();
### Create an issue using REST API

```js
const { Octokit } = require("@octokit/action");
import { Octokit } from "@octokit/action";

const octokit = new Octokit();
const [owner, repo] = process.env.GITHUB_REPOSITORY.split("/");
Expand All @@ -88,7 +93,7 @@ You can also use `octokit.issues.create({ owner, repo, title })`. See the [REST
### Create an issue using GraphQL

```js
const { Octokit } = require("@octokit/action");
import { Octokit } from "@octokit/action";

const octokit = new Octokit();
const eventPayload = require(process.env.GITHUB_EVENT_PATH);
Expand Down

0 comments on commit 9bde849

Please sign in to comment.