Skip to content

Commit f970e0d

Browse files
committed
feat: package is now ESM
BREAKING CHANGE: package is now ESM
1 parent 990930e commit f970e0d

File tree

7 files changed

+208
-318
lines changed

7 files changed

+208
-318
lines changed

package-lock.json

Lines changed: 172 additions & 301 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
"publishConfig": {
44
"access": "public"
55
},
6+
"type": "module",
67
"version": "0.0.0-development",
78
"description": "GitHub Apps toolset for Node.js",
89
"main": "index.js",
@@ -11,23 +12,23 @@
1112
"lint": "prettier --check {src,test}/* *.md package.json",
1213
"lint:fix": "prettier --write {src,test}/* *.md package.json",
1314
"pretest": "npm run -s lint",
14-
"test": "jest --coverage",
15+
"test": "NODE_OPTIONS=\"$NODE_OPTIONS --experimental-vm-modules\" npx jest --coverage",
1516
"test:typescript": "npx tsc --allowImportingTsExtensions --noEmit --declaration --noUnusedLocals --esModuleInterop --strict --target es2020 --moduleResolution node16 --module node16 test/typescript-validate.ts"
1617
},
1718
"repository": "github:octokit/app.js",
1819
"author": "Gregor Martynus (https://github.com/gr2m)",
1920
"license": "MIT",
2021
"dependencies": {
21-
"@octokit/auth-app": "^6.0.0",
22-
"@octokit/auth-unauthenticated": "^5.0.0",
23-
"@octokit/core": "^5.0.0",
24-
"@octokit/oauth-app": "^6.0.0",
22+
"@octokit/auth-app": "^7.0.0-beta.3",
23+
"@octokit/auth-unauthenticated": "^6.0.0",
24+
"@octokit/core": "^6.0.0",
25+
"@octokit/oauth-app": "^7.0.0",
2526
"@octokit/plugin-paginate-rest": "^9.0.0",
26-
"@octokit/types": "^12.0.0",
27-
"@octokit/webhooks": "^12.0.4"
27+
"@octokit/types": "^12.6.0",
28+
"@octokit/webhooks": "^13.0.0"
2829
},
2930
"devDependencies": {
30-
"@octokit/tsconfig": "^2.0.0",
31+
"@octokit/tsconfig": "^3.0.0",
3132
"@types/jest": "^29.0.0",
3233
"@types/node": "^20.0.0",
3334
"esbuild": "^0.20.0",
@@ -45,11 +46,15 @@
4546
"node": ">= 18"
4647
},
4748
"jest": {
49+
"extensionsToTreatAsEsm": [
50+
".ts"
51+
],
4852
"transform": {
4953
"^.+\\.(ts|tsx)$": [
5054
"ts-jest",
5155
{
52-
"tsconfig": "test/tsconfig.test.json"
56+
"tsconfig": "test/tsconfig.test.json",
57+
"useESM": true
5358
}
5459
]
5560
},

scripts/build.mjs

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,8 @@ async function main() {
4646
outdir: "pkg/dist-node",
4747
bundle: true,
4848
platform: "node",
49-
target: "node14",
50-
format: "cjs",
49+
target: "node18",
50+
format: "esm",
5151
...sharedOptions,
5252
}),
5353
// Build an ESM browser bundle
@@ -78,10 +78,22 @@ async function main() {
7878
{
7979
...pkg,
8080
files: ["dist-*/**", "bin/**"],
81-
main: "dist-node/index.js",
82-
module: "dist-web/index.js",
83-
types: "dist-types/index.d.ts",
84-
source: "dist-src/index.js",
81+
exports: {
82+
".": {
83+
node: {
84+
types: "./dist-types/index.d.ts",
85+
import: "./dist-node/index.js",
86+
},
87+
browser: {
88+
types: "./dist-types/web.d.ts",
89+
import: "./dist-web/index.js",
90+
},
91+
default: {
92+
types: "./dist-types/index.d.ts",
93+
import: "./dist-node/index.js",
94+
},
95+
},
96+
},
8597
sideEffects: false,
8698
},
8799
null,

test/log.test.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ const CLIENT_ID = "0123";
3030
const CLIENT_SECRET = "0123secret";
3131
const WEBHOOK_SECRET = "secret";
3232

33+
import { jest } from "@jest/globals";
3334
import { App } from "../src/index.ts";
3435

3536
describe("app.log", () => {

test/node-middleware.test.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
import { createServer } from "node:http";
22

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

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

test/octokit.test.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ const BEARER =
3838
"eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCJ9.eyJpYXQiOi0zMCwiZXhwIjo1NzAsImlzcyI6MX0.q3foRa78U3WegM5PrWLEh5N0bH1SD62OqW66ZYzArp95JBNiCbo8KAlGtiRENCIfBZT9ibDUWy82cI4g3F09mdTq3bD1xLavIfmTksIQCz5EymTWR5v6gL14LSmQdWY9lSqkgUG0XCFljWUglEP39H4yeHbFgdjvAYg3ifDS12z9oQz2ACdSpvxPiTuCC804HkPVw8Qoy0OSXvCkFU70l7VXCVUxnuhHnk8-oCGcKUspmeP6UdDnXk-Aus-eGwDfJbU2WritxxaXw6B4a3flTPojkYLSkPBr6Pi0H2-mBsW_Nvs0aLPVLKobQd4gqTkosX3967DoAG8luUMhrnxe8Q";
3939

4040
import { App } from "../src/index.ts";
41+
import { jest } from "@jest/globals";
4142

4243
describe("app.octokit", () => {
4344
let app: InstanceType<typeof App>;

test/tsconfig.test.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
"compilerOptions": {
44
"emitDeclarationOnly": false,
55
"noEmit": true,
6-
"verbatimModuleSyntax": false,
76
"allowImportingTsExtensions": true
87
},
98
"include": ["src/**/*"]

0 commit comments

Comments
 (0)