Skip to content

Commit 6c0d0c3

Browse files
feat: migrate to ESM (#272)
BREAKING CHANGE: package is now ESM --------- Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
1 parent ee9835f commit 6c0d0c3

11 files changed

+1565
-4752
lines changed

Diff for: package-lock.json

+1,517-4,708
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: package.json

+13-34
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
11
{
22
"name": "octokit-auth-probot",
33
"version": "0.0.0-development",
4+
"type": "module",
45
"description": "Octokit authentication strategy that supports token, app (JWT), and event-based installation authentication",
56
"main": "index.js",
67
"scripts": {
78
"build": "node scripts/build.mjs && tsc -p tsconfig.json",
89
"lint": "prettier --check '{src,test}/**/*.{ts,md}' *.md *.json",
910
"lint:fix": "prettier --write '{src,test}/**/*.{ts,md}' *.md *.json",
1011
"pretest": "npm run -s lint",
11-
"test": "jest --coverage"
12+
"test": "vitest --ui --coverage"
1213
},
1314
"repository": "github:probot/octokit-auth-probot",
1415
"keywords": [
@@ -17,50 +18,28 @@
1718
"author": "Gregor Martynus (https://twitter.com/gr2m)",
1819
"license": "ISC",
1920
"dependencies": {
20-
"@octokit/auth-app": "^6.0.1",
21-
"@octokit/auth-token": "^4.0.0",
22-
"@octokit/auth-unauthenticated": "^5.0.1",
23-
"@octokit/types": "^12.0.0"
21+
"@octokit/auth-app": "^7.0.0",
22+
"@octokit/auth-token": "^5.0.0",
23+
"@octokit/auth-unauthenticated": "^6.0.0",
24+
"@octokit/types": "^13.0.0"
2425
},
2526
"peerDependencies": {
26-
"@octokit/core": ">=5"
27+
"@octokit/core": ">=6"
2728
},
2829
"devDependencies": {
29-
"@octokit/core": "^5.0.0",
30-
"@octokit/tsconfig": "^2.0.0",
30+
"@octokit/core": "^6.0.0",
31+
"@octokit/tsconfig": "^3.0.0",
3132
"@types/fetch-mock": "^7.3.7",
32-
"@types/jest": "^29.0.0",
3333
"@types/node": "^18.18.6",
34+
"@vitest/coverage-v8": "^1.5.3",
35+
"@vitest/ui": "^1.5.3",
3436
"esbuild": "^0.20.0",
3537
"fetch-mock": "npm:@gr2m/[email protected]",
3638
"glob": "^10.3.10",
37-
"jest": "^29.0.0",
3839
"mockdate": "^3.0.2",
3940
"prettier": "^3.0.3",
40-
"ts-jest": "^29.1.1",
41-
"typescript": "^5.2.2"
42-
},
43-
"jest": {
44-
"testEnvironment": "node",
45-
"coverageThreshold": {
46-
"global": {
47-
"statements": 100,
48-
"branches": 100,
49-
"functions": 100,
50-
"lines": 100
51-
}
52-
},
53-
"transform": {
54-
"^.+\\.tsx?$": [
55-
"ts-jest",
56-
{
57-
"tsconfig": "test/tsconfig.json"
58-
}
59-
]
60-
},
61-
"moduleNameMapper": {
62-
"^(.+)\\.jsx?$": "$1"
63-
}
41+
"typescript": "^5.2.2",
42+
"vitest": "^1.5.3"
6443
},
6544
"release": {
6645
"branches": [

Diff for: scripts/build.mjs

+9-4
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ async function main() {
4343
bundle: true,
4444
platform: "node",
4545
target: "node18",
46-
format: "cjs",
46+
format: "esm",
4747
...sharedOptions,
4848
}),
4949
// Build an ESM browser bundle
@@ -73,10 +73,15 @@ async function main() {
7373
{
7474
...pkg,
7575
files: ["dist-*/**", "bin/**"],
76-
main: "dist-node/index.js",
77-
browser: "dist-web/index.js",
7876
types: "dist-types/index.d.ts",
79-
module: "dist-src/index.js",
77+
exports: {
78+
".": {
79+
types: "./dist-types/index.d.ts",
80+
import: "./dist-node/index.js",
81+
browser: "./dist-web/index.js",
82+
default: "./dist-node/index.js",
83+
},
84+
},
8085
sideEffects: false,
8186
},
8287
null,

Diff for: src/auth.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { createUnauthenticatedAuth } from "@octokit/auth-unauthenticated";
22
import type { Octokit } from "@octokit/core";
33

4-
import type { AuthOptions, State } from "./types";
4+
import type { AuthOptions, State } from "./types.js";
55

66
export async function auth(state: State, options: AuthOptions) {
77
// return authentication from internal auth instance unless the event is "event-octokit"

Diff for: src/get-state.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { createTokenAuth } from "@octokit/auth-token";
22
import { createAppAuth } from "@octokit/auth-app";
33
import { createUnauthenticatedAuth } from "@octokit/auth-unauthenticated";
44

5-
import type { State, StrategyOptions } from "./types";
5+
import type { State, StrategyOptions } from "./types.js";
66

77
export function getState(options: StrategyOptions): State {
88
const common = {

Diff for: src/index.ts

+7-2
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,14 @@
11
import { auth } from "./auth.js";
22
import { getState } from "./get-state.js";
3-
import type { StrategyOptions, State } from "./types";
3+
import type { StrategyOptions, State } from "./types.js";
44
import { VERSION } from "./version.js";
55

6-
export function createProbotAuth(options: StrategyOptions): any {
6+
export interface ProbotAuth {
7+
(options: Parameters<typeof auth>[1]): Promise<any>;
8+
hook: State["auth"]["hook"];
9+
}
10+
11+
export function createProbotAuth(options: StrategyOptions): ProbotAuth {
712
const state: State = getState(options);
813

914
return Object.assign(auth.bind(null, state), {

Diff for: test/auth.test.ts

+3-1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ import fetchMock from "fetch-mock";
33

44
import { createProbotAuth } from "../src/index.js";
55

6+
import { describe, expect, test, vi } from "vitest";
7+
68
const ProbotOctokit = Octokit.defaults({
79
authStrategy: createProbotAuth,
810
});
@@ -61,7 +63,7 @@ describe("octokit.auth()", () => {
6163
};
6264
const octokit = new ProbotOctokit(octokitOptions);
6365

64-
const factory = jest.fn().mockReturnValue("test");
66+
const factory = vi.fn().mockReturnValue("test");
6567

6668
const authentication = await octokit.auth({
6769
type: "installation",

Diff for: test/readme-examples.test.ts

+2
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ import MockDate from "mockdate";
44

55
import { createProbotAuth } from "../src/index.js";
66

7+
import { afterEach, beforeEach, describe, expect, it, test } from "vitest";
8+
79
const ProbotOctokit = Octokit.defaults({
810
authStrategy: createProbotAuth,
911
});

Diff for: test/smoke.test.ts

+1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { createProbotAuth } from "../src/index.js";
2+
import { describe, expect, it } from "vitest";
23

34
describe("Smoke test", () => {
45
it("is a function", () => {

Diff for: test/tsconfig.json

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

Diff for: vitest.config.ts

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import { defineConfig } from 'vitest/config'
2+
3+
export default defineConfig({
4+
test: {
5+
include: ['test/**/*.test.ts'],
6+
coverage: {
7+
include: ['src/**/*.ts'],
8+
provider: "v8",
9+
},
10+
},
11+
})

0 commit comments

Comments
 (0)