Skip to content

Commit

Permalink
feat: package is now ESM
Browse files Browse the repository at this point in the history
BREAKING CHANGE: package is now ESM
  • Loading branch information
wolfy1339 committed Feb 25, 2024
1 parent 8426abb commit 80ed2fe
Show file tree
Hide file tree
Showing 8 changed files with 44 additions and 68 deletions.
18 changes: 11 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,8 @@ Install with `npm install @octokit/oauth-app`
### For OAuth Apps

```js
const { OAuthApp, createNodeMiddleware } = require("@octokit/oauth-app");
import { OAuthApp, createNodeMiddleware } from "@octokit/oauth-app";
import { createServer } from "node:http";

const app = new OAuthApp({
clientType: "oauth-app",
Expand All @@ -82,7 +83,7 @@ app.on("token", async ({ token, octokit }) => {
console.log(`Token retrieved for ${data.login}`);
});

require("http").createServer(createNodeMiddleware(app)).listen(3000);
createServer(createNodeMiddleware(app)).listen(3000);
// can now receive user authorization callbacks at /api/github/oauth/callback
// See all endpoints at https://github.com/octokit/oauth-app.js#middlewares
```
Expand All @@ -92,7 +93,8 @@ require("http").createServer(createNodeMiddleware(app)).listen(3000);
GitHub Apps do not support `scopes`. If the GitHub App has expiring user tokens enabled, the token used for the `octokit` instance will be refreshed automatically, and the additional refresh-related properties will be passed to the `"token"` event handler.

```js
const { OAuthApp, createNodeMiddleware } = require("@octokit/oauth-app");
import { OAuthApp, createNodeMiddleware } from "@octokit/oauth-app";
import { createServer } from "node:http";

const app = new OAuthApp({
clientType: "github-app",
Expand All @@ -105,7 +107,7 @@ app.on("token", async ({ token, octokit, expiresAt }) => {
console.log(`Token retrieved for ${data.login}`);
});

require("http").createServer(createNodeMiddleware(app)).listen(3000);
createServer(createNodeMiddleware(app)).listen(3000);
// can now receive user authorization callbacks at /api/github/oauth/callback
// See all endpoints at https://github.com/octokit/oauth-app.js#middlewares
```
Expand Down Expand Up @@ -239,7 +241,7 @@ You can pass in your own Octokit constructor with custom defaults and plugins. T
For usage with enterprise, set `baseUrl` to the hostname + `/api/v3`. Example:

```js
const { Octokit } = require("@octokit/core");
import { Octokit } from "@octokit/core";
new OAuthApp({
clientId: "1234567890abcdef1234",
clientSecret: "1234567890abcdef1234567890abcdef12345678",
Expand Down Expand Up @@ -895,7 +897,9 @@ By default, all middlewares expose the following routes
Native http server middleware for Node.js

```js
const { OAuthApp, createNodeMiddleware } = require("@octokit/oauth-app");
import { OAuthApp, createNodeMiddleware } from "@octokit/oauth-app";
import { createServer } from "node:http";

const app = new OAuthApp({
clientType: "oauth-app",
clientId: "1234567890abcdef1234",
Expand All @@ -906,7 +910,7 @@ const middleware = createNodeMiddleware(app, {
pathPrefix: "/api/github/oauth",
});

require("http").createServer(middleware).listen(3000);
createServer(middleware).listen(3000);
// can now receive user authorization callbacks at /api/github/oauth/callback
```

Expand Down
64 changes: 13 additions & 51 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 10 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,13 @@
"name": "@octokit/oauth-app",
"version": "0.0.0-development",
"description": "GitHub OAuth toolset for Node.js",
"type": "module",
"scripts": {
"build": "node scripts/build.mjs && tsc -p tsconfig.json",
"lint": "prettier --check '{src,test}/**/*' README.md package.json",
"lint:fix": "prettier --write '{src,test}/**/*' README.md package.json",
"pretest": "npm run -s lint",
"test": "jest --coverage",
"test": "NODE_OPTIONS=\"$NODE_OPTIONS --experimental-vm-modules\" npx jest --coverage",
"test:typescript": "npx tsc --noEmit --declaration --noUnusedLocals --allowImportingTsExtensions --moduleResolution node16 --module node16 test/typescript-validate.ts"
},
"repository": "github:octokit/oauth-app.js",
Expand All @@ -20,9 +21,9 @@
"author": "Gregor Martynus (https://twitter.com/gr2m)",
"license": "MIT",
"dependencies": {
"@octokit/auth-oauth-app": "^8.0.0-beta.2",
"@octokit/auth-oauth-user": "^5.0.0",
"@octokit/auth-unauthenticated": "^5.0.0",
"@octokit/auth-oauth-app": "^8.0.0",
"@octokit/auth-oauth-user": "^5.0.1",
"@octokit/auth-unauthenticated": "^6.0.0-beta.1",
"@octokit/core": "^6.0.0",
"@octokit/oauth-authorization-url": "^7.0.0",
"@octokit/oauth-methods": "^5.0.0",
Expand All @@ -45,11 +46,15 @@
"typescript": "^5.0.0"
},
"jest": {
"extensionsToTreatAsEsm": [
".ts"
],
"transform": {
"^.+\\.(ts|tsx)$": [
"ts-jest",
{
"tsconfig": "test/tsconfig.test.json"
"tsconfig": "test/tsconfig.test.json",
"useESM": true
}
]
},
Expand Down
11 changes: 7 additions & 4 deletions scripts/build.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ async function main() {
bundle: true,
platform: "node",
target: "node18",
format: "cjs",
format: "esm",
...sharedOptions,
});

Expand All @@ -67,9 +67,12 @@ async function main() {
{
...pkg,
files: ["dist-*/**", "bin/**"],
main: "dist-node/index.js",
types: "dist-types/index.d.ts",
source: "dist-src/index.js",
exports: {
".": {
types: "./dist-types/index.d.ts",
import: "./dist-node/index.js",
},
},
sideEffects: false,
},
null,
Expand Down
1 change: 1 addition & 0 deletions test/app.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import fetchMock from "fetch-mock";
import { Octokit } from "@octokit/core";
import { jest } from "@jest/globals";

import { OAuthApp } from "../src/index.ts";
import { OAuthAppOctokit } from "../src/oauth-app-octokit.ts";
Expand Down
1 change: 1 addition & 0 deletions test/node-middleware.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { createServer, IncomingMessage } from "node:http";
import { URL } from "node:url";
import { jest } from "@jest/globals";

import { createNodeMiddleware, OAuthApp } from "../src/index.ts";

Expand Down
1 change: 0 additions & 1 deletion test/tsconfig.test.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
"compilerOptions": {
"emitDeclarationOnly": false,
"noEmit": true,
"verbatimModuleSyntax": false,
"allowImportingTsExtensions": true
},
"include": ["src/**/*"]
Expand Down
1 change: 1 addition & 0 deletions test/web-worker-handler.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { URL } from "node:url";
import { jest } from "@jest/globals";
import { createWebWorkerHandler, OAuthApp } from "../src/index.ts";

describe("createWebWorkerHandler(app)", () => {
Expand Down

0 comments on commit 80ed2fe

Please sign in to comment.