Skip to content

Commit 0e272e6

Browse files
committed
feat: package is now ESM
BREAKING CHANGE: package is now ESM
1 parent 0cf80ff commit 0e272e6

File tree

9 files changed

+575
-97
lines changed

9 files changed

+575
-97
lines changed

package-lock.json

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

package.json

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,14 @@
44
"publishConfig": {
55
"access": "public"
66
},
7+
"type": "module",
78
"description": "Extendable client for GitHub's REST & GraphQL APIs",
89
"scripts": {
910
"build": "node scripts/build.mjs && tsc -p tsconfig.json",
1011
"lint": "prettier --check '{src,test}/**/*.{ts,md}' README.md package.json",
1112
"lint:fix": "prettier --write '{src,test}/**/*.{ts,md}' README.md package.json",
1213
"pretest": "npm run -s lint",
13-
"test": "jest --coverage",
14+
"test": "NODE_OPTIONS=\"$NODE_OPTIONS --experimental-vm-modules\" npx jest --coverage",
1415
"test:typescript": "npx tsc --noEmit --declaration --noUnusedLocals --allowImportingTsExtensions test/typescript-validate.ts"
1516
},
1617
"repository": "github:octokit/core.js",
@@ -24,21 +25,21 @@
2425
"author": "Gregor Martynus (https://github.com/gr2m)",
2526
"license": "MIT",
2627
"dependencies": {
27-
"@octokit/auth-token": "^4.0.0",
28-
"@octokit/graphql": "^7.0.0",
29-
"@octokit/request": "^8.0.2",
30-
"@octokit/request-error": "^5.0.0",
28+
"@octokit/auth-token": "^5.0.0-beta.1",
29+
"@octokit/graphql": "^8.0.0-beta.1",
30+
"@octokit/request": "^9.0.0",
31+
"@octokit/request-error": "^6.0.1",
3132
"@octokit/types": "^12.0.0",
32-
"before-after-hook": "^2.2.0",
33-
"universal-user-agent": "^6.0.0"
33+
"before-after-hook": "^3.0.2",
34+
"universal-user-agent": "^7.0.0"
3435
},
3536
"devDependencies": {
3637
"@octokit/auth-action": "^4.0.0",
3738
"@octokit/auth-app": "^6.0.0",
3839
"@octokit/auth-oauth-app": "^7.0.0",
39-
"@octokit/tsconfig": "^2.0.0",
40+
"@octokit/tsconfig": "^3.0.0",
4041
"@sinonjs/fake-timers": "^11.2.2",
41-
"@types/fetch-mock": "^7.3.1",
42+
"@types/fetch-mock": "^7.3.8",
4243
"@types/jest": "^29.0.0",
4344
"@types/lolex": "^5.1.0",
4445
"@types/node": "^20.0.0",
@@ -57,11 +58,15 @@
5758
"undici": "^6.0.0"
5859
},
5960
"jest": {
61+
"extensionsToTreatAsEsm": [
62+
".ts"
63+
],
6064
"transform": {
6165
"^.+\\.(ts|tsx)$": [
6266
"ts-jest",
6367
{
64-
"tsconfig": "test/tsconfig.test.json"
68+
"tsconfig": "test/tsconfig.test.json",
69+
"useESM": true
6570
}
6671
]
6772
},

src/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { getUserAgent } from "universal-user-agent";
22
import type { HookCollection } from "before-after-hook";
3-
import { Collection } from "before-after-hook";
3+
import Hook from "before-after-hook";
44
import { request } from "@octokit/request";
55
import { graphql, withCustomRequest } from "@octokit/graphql";
66
import { createTokenAuth } from "@octokit/auth-token";
@@ -80,7 +80,7 @@ export class Octokit {
8080
}
8181

8282
constructor(options: OctokitOptions = {}) {
83-
const hook = new Collection<Hooks>();
83+
const hook = new Hook.Collection<Hooks>();
8484
const requestDefaults: Required<RequestParameters> = {
8585
baseUrl: request.endpoint.DEFAULTS.baseUrl,
8686
headers: {},

test/agent-ca/agent-ca-test.test.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import { fetch as undiciFetch, Agent } from "undici";
55
import { request } from "@octokit/request";
66
import { type AddressInfo } from "node:net";
77

8+
const __dirname = new URL(".", import.meta.url).pathname;
89
const ca = readFileSync(resolve(__dirname, "./ca.crt"));
910

1011
describe("custom client certificate", () => {

test/agent-proxy/agent-proxy-test.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
*/
1212
import { Server, createServer } from "node:http";
1313
import { type AddressInfo } from "node:net";
14-
import { ProxyServer, createProxy } from "proxy";
14+
import { type ProxyServer, createProxy } from "proxy";
1515
import { ProxyAgent, fetch as undiciFetch } from "undici";
1616
import { Octokit } from "../../src/index.ts";
1717

test/auth.test.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { createAppAuth } from "@octokit/auth-app";
44
import { createActionAuth } from "@octokit/auth-action";
55
import { createOAuthAppAuth } from "@octokit/auth-oauth-app";
66
import { install as installFakeTimers, type Clock } from "@sinonjs/fake-timers";
7+
import { jest } from "@jest/globals";
78

89
import { Octokit } from "../src/index.ts";
910

@@ -47,7 +48,7 @@ beforeAll(() => {
4748
// unless `token.fingerprint` option was passed. The fingerprint is
4849
// calculated using `Math.random().toString(36).substr(2)`, so the
4950
// default fingerprint is always `"4feornbt361"`.
50-
Math.random = jest.fn().mockReturnValue(0.123);
51+
Math.random = jest.fn<Math["random"]>().mockReturnValue(0.123);
5152

5253
// A timestamp is added to the default token note, e.g.
5354
// "octokit 2019-07-04 4feornbt361". sinon-fake-timers mocks the Date class so
@@ -402,13 +403,15 @@ describe("Authentication", () => {
402403

403404
const strategyOptions = authStrategy.mock.calls[0][0];
404405

406+
// @ts-expect-error The types here don't work
405407
expect(Object.keys(strategyOptions).sort()).toStrictEqual([
406408
"log",
407409
"octokit",
408410
"octokitOptions",
409411
"request",
410412
"secret",
411413
]);
414+
// @ts-expect-error The types here don't work
412415
expect(strategyOptions.octokitOptions).toStrictEqual({
413416
auth: {
414417
secret: "123",

test/log.test.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import { jest } from "@jest/globals";
2+
13
describe("octokit.log", () => {
24
it(".debug() and .info() are no-ops by default", async () => {
35
const calls: String[] = [];

test/request.test.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,6 @@ describe("octokit.request()", () => {
179179
{
180180
owner: "epmatsw",
181181
repo: "example-repo",
182-
// @ts-expect-error There is currently an issue with the types, null is an allowed value
183182
milestone: null,
184183
issue_number: 1,
185184
},

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)