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 24, 2024
1 parent 0cf80ff commit 0e272e6
Show file tree
Hide file tree
Showing 9 changed files with 575 additions and 97 deletions.
631 changes: 550 additions & 81 deletions package-lock.json

Large diffs are not rendered by default.

25 changes: 15 additions & 10 deletions package.json
Expand Up @@ -4,13 +4,14 @@
"publishConfig": {
"access": "public"
},
"type": "module",
"description": "Extendable client for GitHub's REST & GraphQL APIs",
"scripts": {
"build": "node scripts/build.mjs && tsc -p tsconfig.json",
"lint": "prettier --check '{src,test}/**/*.{ts,md}' README.md package.json",
"lint:fix": "prettier --write '{src,test}/**/*.{ts,md}' 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 test/typescript-validate.ts"
},
"repository": "github:octokit/core.js",
Expand All @@ -24,21 +25,21 @@
"author": "Gregor Martynus (https://github.com/gr2m)",
"license": "MIT",
"dependencies": {
"@octokit/auth-token": "^4.0.0",
"@octokit/graphql": "^7.0.0",
"@octokit/request": "^8.0.2",
"@octokit/request-error": "^5.0.0",
"@octokit/auth-token": "^5.0.0-beta.1",
"@octokit/graphql": "^8.0.0-beta.1",
"@octokit/request": "^9.0.0",
"@octokit/request-error": "^6.0.1",
"@octokit/types": "^12.0.0",
"before-after-hook": "^2.2.0",
"universal-user-agent": "^6.0.0"
"before-after-hook": "^3.0.2",
"universal-user-agent": "^7.0.0"
},
"devDependencies": {
"@octokit/auth-action": "^4.0.0",
"@octokit/auth-app": "^6.0.0",
"@octokit/auth-oauth-app": "^7.0.0",
"@octokit/tsconfig": "^2.0.0",
"@octokit/tsconfig": "^3.0.0",
"@sinonjs/fake-timers": "^11.2.2",
"@types/fetch-mock": "^7.3.1",
"@types/fetch-mock": "^7.3.8",
"@types/jest": "^29.0.0",
"@types/lolex": "^5.1.0",
"@types/node": "^20.0.0",
Expand All @@ -57,11 +58,15 @@
"undici": "^6.0.0"
},
"jest": {
"extensionsToTreatAsEsm": [
".ts"
],
"transform": {
"^.+\\.(ts|tsx)$": [
"ts-jest",
{
"tsconfig": "test/tsconfig.test.json"
"tsconfig": "test/tsconfig.test.json",
"useESM": true
}
]
},
Expand Down
4 changes: 2 additions & 2 deletions src/index.ts
@@ -1,6 +1,6 @@
import { getUserAgent } from "universal-user-agent";
import type { HookCollection } from "before-after-hook";
import { Collection } from "before-after-hook";
import Hook from "before-after-hook";
import { request } from "@octokit/request";
import { graphql, withCustomRequest } from "@octokit/graphql";
import { createTokenAuth } from "@octokit/auth-token";
Expand Down Expand Up @@ -80,7 +80,7 @@ export class Octokit {
}

constructor(options: OctokitOptions = {}) {
const hook = new Collection<Hooks>();
const hook = new Hook.Collection<Hooks>();
const requestDefaults: Required<RequestParameters> = {
baseUrl: request.endpoint.DEFAULTS.baseUrl,
headers: {},
Expand Down
1 change: 1 addition & 0 deletions test/agent-ca/agent-ca-test.test.ts
Expand Up @@ -5,6 +5,7 @@ import { fetch as undiciFetch, Agent } from "undici";
import { request } from "@octokit/request";
import { type AddressInfo } from "node:net";

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

describe("custom client certificate", () => {
Expand Down
2 changes: 1 addition & 1 deletion test/agent-proxy/agent-proxy-test.test.ts
Expand Up @@ -11,7 +11,7 @@
*/
import { Server, createServer } from "node:http";
import { type AddressInfo } from "node:net";
import { ProxyServer, createProxy } from "proxy";
import { type ProxyServer, createProxy } from "proxy";
import { ProxyAgent, fetch as undiciFetch } from "undici";
import { Octokit } from "../../src/index.ts";

Expand Down
5 changes: 4 additions & 1 deletion test/auth.test.ts
Expand Up @@ -4,6 +4,7 @@ import { createAppAuth } from "@octokit/auth-app";
import { createActionAuth } from "@octokit/auth-action";
import { createOAuthAppAuth } from "@octokit/auth-oauth-app";
import { install as installFakeTimers, type Clock } from "@sinonjs/fake-timers";
import { jest } from "@jest/globals";

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

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

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

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

// @ts-expect-error The types here don't work
expect(Object.keys(strategyOptions).sort()).toStrictEqual([
"log",
"octokit",
"octokitOptions",
"request",
"secret",
]);
// @ts-expect-error The types here don't work
expect(strategyOptions.octokitOptions).toStrictEqual({
auth: {
secret: "123",
Expand Down
2 changes: 2 additions & 0 deletions test/log.test.ts
@@ -1,3 +1,5 @@
import { jest } from "@jest/globals";

describe("octokit.log", () => {
it(".debug() and .info() are no-ops by default", async () => {
const calls: String[] = [];
Expand Down
1 change: 0 additions & 1 deletion test/request.test.ts
Expand Up @@ -179,7 +179,6 @@ describe("octokit.request()", () => {
{
owner: "epmatsw",
repo: "example-repo",
// @ts-expect-error There is currently an issue with the types, null is an allowed value
milestone: null,
issue_number: 1,
},
Expand Down
1 change: 0 additions & 1 deletion test/tsconfig.test.json
Expand Up @@ -3,7 +3,6 @@
"compilerOptions": {
"emitDeclarationOnly": false,
"noEmit": true,
"verbatimModuleSyntax": false,
"allowImportingTsExtensions": true
},
"include": ["src/**/*"]
Expand Down

0 comments on commit 0e272e6

Please sign in to comment.