Skip to content

Commit

Permalink
feat: migrate to ESM (#272)
Browse files Browse the repository at this point in the history
BREAKING CHANGE: package is now ESM

---------

Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
  • Loading branch information
wolfy1339 and renovate[bot] committed Jun 14, 2024
1 parent ee9835f commit 6c0d0c3
Show file tree
Hide file tree
Showing 11 changed files with 1,565 additions and 4,752 deletions.
6,225 changes: 1,517 additions & 4,708 deletions package-lock.json

Large diffs are not rendered by default.

47 changes: 13 additions & 34 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
{
"name": "octokit-auth-probot",
"version": "0.0.0-development",
"type": "module",
"description": "Octokit authentication strategy that supports token, app (JWT), and event-based installation authentication",
"main": "index.js",
"scripts": {
"build": "node scripts/build.mjs && tsc -p tsconfig.json",
"lint": "prettier --check '{src,test}/**/*.{ts,md}' *.md *.json",
"lint:fix": "prettier --write '{src,test}/**/*.{ts,md}' *.md *.json",
"pretest": "npm run -s lint",
"test": "jest --coverage"
"test": "vitest --ui --coverage"
},
"repository": "github:probot/octokit-auth-probot",
"keywords": [
Expand All @@ -17,50 +18,28 @@
"author": "Gregor Martynus (https://twitter.com/gr2m)",
"license": "ISC",
"dependencies": {
"@octokit/auth-app": "^6.0.1",
"@octokit/auth-token": "^4.0.0",
"@octokit/auth-unauthenticated": "^5.0.1",
"@octokit/types": "^12.0.0"
"@octokit/auth-app": "^7.0.0",
"@octokit/auth-token": "^5.0.0",
"@octokit/auth-unauthenticated": "^6.0.0",
"@octokit/types": "^13.0.0"
},
"peerDependencies": {
"@octokit/core": ">=5"
"@octokit/core": ">=6"
},
"devDependencies": {
"@octokit/core": "^5.0.0",
"@octokit/tsconfig": "^2.0.0",
"@octokit/core": "^6.0.0",
"@octokit/tsconfig": "^3.0.0",
"@types/fetch-mock": "^7.3.7",
"@types/jest": "^29.0.0",
"@types/node": "^18.18.6",
"@vitest/coverage-v8": "^1.5.3",
"@vitest/ui": "^1.5.3",
"esbuild": "^0.20.0",
"fetch-mock": "npm:@gr2m/[email protected]",
"glob": "^10.3.10",
"jest": "^29.0.0",
"mockdate": "^3.0.2",
"prettier": "^3.0.3",
"ts-jest": "^29.1.1",
"typescript": "^5.2.2"
},
"jest": {
"testEnvironment": "node",
"coverageThreshold": {
"global": {
"statements": 100,
"branches": 100,
"functions": 100,
"lines": 100
}
},
"transform": {
"^.+\\.tsx?$": [
"ts-jest",
{
"tsconfig": "test/tsconfig.json"
}
]
},
"moduleNameMapper": {
"^(.+)\\.jsx?$": "$1"
}
"typescript": "^5.2.2",
"vitest": "^1.5.3"
},
"release": {
"branches": [
Expand Down
13 changes: 9 additions & 4 deletions scripts/build.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ async function main() {
bundle: true,
platform: "node",
target: "node18",
format: "cjs",
format: "esm",
...sharedOptions,
}),
// Build an ESM browser bundle
Expand Down Expand Up @@ -73,10 +73,15 @@ async function main() {
{
...pkg,
files: ["dist-*/**", "bin/**"],
main: "dist-node/index.js",
browser: "dist-web/index.js",
types: "dist-types/index.d.ts",
module: "dist-src/index.js",
exports: {
".": {
types: "./dist-types/index.d.ts",
import: "./dist-node/index.js",
browser: "./dist-web/index.js",
default: "./dist-node/index.js",
},
},
sideEffects: false,
},
null,
Expand Down
2 changes: 1 addition & 1 deletion src/auth.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { createUnauthenticatedAuth } from "@octokit/auth-unauthenticated";
import type { Octokit } from "@octokit/core";

import type { AuthOptions, State } from "./types";
import type { AuthOptions, State } from "./types.js";

export async function auth(state: State, options: AuthOptions) {
// return authentication from internal auth instance unless the event is "event-octokit"
Expand Down
2 changes: 1 addition & 1 deletion src/get-state.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { createTokenAuth } from "@octokit/auth-token";
import { createAppAuth } from "@octokit/auth-app";
import { createUnauthenticatedAuth } from "@octokit/auth-unauthenticated";

import type { State, StrategyOptions } from "./types";
import type { State, StrategyOptions } from "./types.js";

export function getState(options: StrategyOptions): State {
const common = {
Expand Down
9 changes: 7 additions & 2 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
import { auth } from "./auth.js";
import { getState } from "./get-state.js";
import type { StrategyOptions, State } from "./types";
import type { StrategyOptions, State } from "./types.js";
import { VERSION } from "./version.js";

export function createProbotAuth(options: StrategyOptions): any {
export interface ProbotAuth {
(options: Parameters<typeof auth>[1]): Promise<any>;
hook: State["auth"]["hook"];
}

export function createProbotAuth(options: StrategyOptions): ProbotAuth {
const state: State = getState(options);

return Object.assign(auth.bind(null, state), {
Expand Down
4 changes: 3 additions & 1 deletion test/auth.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ import fetchMock from "fetch-mock";

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

import { describe, expect, test, vi } from "vitest";

const ProbotOctokit = Octokit.defaults({
authStrategy: createProbotAuth,
});
Expand Down Expand Up @@ -61,7 +63,7 @@ describe("octokit.auth()", () => {
};
const octokit = new ProbotOctokit(octokitOptions);

const factory = jest.fn().mockReturnValue("test");
const factory = vi.fn().mockReturnValue("test");

const authentication = await octokit.auth({
type: "installation",
Expand Down
2 changes: 2 additions & 0 deletions test/readme-examples.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import MockDate from "mockdate";

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

import { afterEach, beforeEach, describe, expect, it, test } from "vitest";

const ProbotOctokit = Octokit.defaults({
authStrategy: createProbotAuth,
});
Expand Down
1 change: 1 addition & 0 deletions test/smoke.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { createProbotAuth } from "../src/index.js";
import { describe, expect, it } from "vitest";

describe("Smoke test", () => {
it("is a function", () => {
Expand Down
1 change: 0 additions & 1 deletion test/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
"compilerOptions": {
"emitDeclarationOnly": false,
"noEmit": true,
"verbatimModuleSyntax": false
},
"include": ["src/**/*", "./**/*"]
}
11 changes: 11 additions & 0 deletions vitest.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { defineConfig } from 'vitest/config'

export default defineConfig({
test: {
include: ['test/**/*.test.ts'],
coverage: {
include: ['src/**/*.ts'],
provider: "v8",
},
},
})

0 comments on commit 6c0d0c3

Please sign in to comment.