Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: package is now ESM #512

Merged
merged 10 commits into from
Apr 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,12 @@ const { App, createNodeMiddleware } = require("@octokit/app");
</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)

```js
const app = new App({
appId: 123,
Expand Down
1,345 changes: 366 additions & 979 deletions package-lock.json

Large diffs are not rendered by default.

25 changes: 15 additions & 10 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"access": "public",
"provenance": true
},
"type": "module",
"version": "0.0.0-development",
"description": "GitHub Apps toolset for Node.js",
"main": "index.js",
Expand All @@ -12,23 +13,23 @@
"lint": "prettier --check {src,test}/* *.md package.json",
"lint:fix": "prettier --write {src,test}/* *.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 --allowImportingTsExtensions --noEmit --declaration --noUnusedLocals --esModuleInterop --strict --target es2020 --moduleResolution node16 --module node16 test/typescript-validate.ts"
},
"repository": "github:octokit/app.js",
"author": "Gregor Martynus (https://github.com/gr2m)",
"license": "MIT",
"dependencies": {
"@octokit/auth-app": "^6.0.0",
"@octokit/auth-unauthenticated": "^5.0.0",
"@octokit/core": "^5.0.0",
"@octokit/oauth-app": "^6.0.0",
"@octokit/plugin-paginate-rest": "^9.0.0",
"@octokit/types": "^12.0.0",
"@octokit/webhooks": "^12.0.4"
"@octokit/auth-app": "^7.0.0",
"@octokit/auth-unauthenticated": "^6.0.0",
"@octokit/core": "^6.1.2",
"@octokit/oauth-app": "^7.0.0",
"@octokit/plugin-paginate-rest": "^11.0.0",
"@octokit/types": "^13.0.0",
"@octokit/webhooks": "^13.0.0"
},
"devDependencies": {
"@octokit/tsconfig": "^2.0.0",
"@octokit/tsconfig": "^3.0.0",
"@types/jest": "^29.0.0",
"@types/node": "^20.0.0",
"esbuild": "^0.20.0",
Expand All @@ -46,11 +47,15 @@
"node": ">= 18"
},
"jest": {
"extensionsToTreatAsEsm": [
".ts"
],
"transform": {
"^.+\\.(ts|tsx)$": [
"ts-jest",
{
"tsconfig": "test/tsconfig.test.json"
"tsconfig": "test/tsconfig.test.json",
"useESM": true
}
]
},
Expand Down
26 changes: 20 additions & 6 deletions scripts/build.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@ async function main() {
outdir: "pkg/dist-node",
bundle: true,
platform: "node",
target: "node14",
format: "cjs",
target: "node18",
format: "esm",
...sharedOptions,
}),
// Build an ESM browser bundle
Expand Down Expand Up @@ -78,10 +78,24 @@ async function main() {
{
...pkg,
files: ["dist-*/**", "bin/**"],
main: "dist-node/index.js",
module: "dist-web/index.js",
types: "dist-types/index.d.ts",
source: "dist-src/index.js",
main: "./dist-node/index.js",
types: "./dist-types/index.d.ts",
exports: {
".": {
node: {
types: "./dist-types/index.d.ts",
import: "./dist-node/index.js",
},
browser: {
types: "./dist-types/web.d.ts",
import: "./dist-web/index.js",
},
default: {
types: "./dist-types/index.d.ts",
import: "./dist-node/index.js",
},
},
},
sideEffects: false,
},
null,
Expand Down
1 change: 1 addition & 0 deletions test/log.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ const CLIENT_ID = "0123";
const CLIENT_SECRET = "0123secret";
const WEBHOOK_SECRET = "secret";

import { jest } from "@jest/globals";
import { App } from "../src/index.ts";

describe("app.log", () => {
Expand Down
3 changes: 2 additions & 1 deletion test/node-middleware.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import { createServer } from "node:http";

// import without types
const express = require("express");
// @ts-ignore
const express = (await import("express")).default as any;

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

Expand Down
1 change: 1 addition & 0 deletions test/octokit.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ const BEARER =
"eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCJ9.eyJpYXQiOi0zMCwiZXhwIjo1NzAsImlzcyI6MX0.q3foRa78U3WegM5PrWLEh5N0bH1SD62OqW66ZYzArp95JBNiCbo8KAlGtiRENCIfBZT9ibDUWy82cI4g3F09mdTq3bD1xLavIfmTksIQCz5EymTWR5v6gL14LSmQdWY9lSqkgUG0XCFljWUglEP39H4yeHbFgdjvAYg3ifDS12z9oQz2ACdSpvxPiTuCC804HkPVw8Qoy0OSXvCkFU70l7VXCVUxnuhHnk8-oCGcKUspmeP6UdDnXk-Aus-eGwDfJbU2WritxxaXw6B4a3flTPojkYLSkPBr6Pi0H2-mBsW_Nvs0aLPVLKobQd4gqTkosX3967DoAG8luUMhrnxe8Q";

import { App } from "../src/index.ts";
import { jest } from "@jest/globals";

describe("app.octokit", () => {
let app: InstanceType<typeof App>;
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