Skip to content

Commit

Permalink
feat: package is now ESM (#248)
Browse files Browse the repository at this point in the history
BREAKING CHANGE: This package is now ESM only
  • Loading branch information
wolfy1339 authored Jun 11, 2024
1 parent a805ca6 commit a52c8e8
Show file tree
Hide file tree
Showing 7 changed files with 79 additions and 99 deletions.
105 changes: 43 additions & 62 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 12 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
{
"name": "@octokit/auth-callback",
"version": "0.0.0-development",
"type": "module",
"description": "GitHub API authentication using a callback method",
"scripts": {
"build": "node scripts/build.mjs && tsc -p tsconfig.json",
"lint": "prettier --check '{src,test,scripts}/**/*' README.md package.json",
"lint:fix": "prettier --write '{src,test,scripts}/**/*' README.md package.json",
"pretest": "npm run -s lint",
"test": "jest --coverage"
"test": "NODE_OPTIONS=\"$NODE_OPTIONS --experimental-vm-modules\" npx jest --coverage"
},
"repository": "github:octokit/auth-callback.js",
"keywords": [
Expand All @@ -19,8 +20,8 @@
"author": "Gregor Martynus (https://dev.to/gr2m)",
"license": "MIT",
"devDependencies": {
"@octokit/core": "^5.0.0",
"@octokit/request": "^8.0.0",
"@octokit/core": "^6.0.0",
"@octokit/request": "^9.0.0",
"@octokit/tsconfig": "^3.0.0",
"@types/jest": "^29.0.0",
"@types/node": "^20.0.0",
Expand All @@ -33,11 +34,15 @@
"typescript": "^5.0.0"
},
"jest": {
"extensionsToTreatAsEsm": [
".ts"
],
"transform": {
"^.+\\.(ts|tsx)$": [
"ts-jest",
{
"tsconfig": "test/tsconfig.test.json"
"tsconfig": "test/tsconfig.test.json",
"useESM": true
}
]
},
Expand All @@ -48,6 +53,9 @@
"functions": 100,
"lines": 100
}
},
"moduleNameMapper": {
"^(.+)\\.jsx?$": "$1"
}
},
"release": {
Expand Down
43 changes: 17 additions & 26 deletions scripts/build.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ const sharedOptions = {
minify: false,
allowOverwrite: true,
packages: "external",
platform: "neutral",
format: "esm",
target: "es2022",
};

async function main() {
Expand All @@ -18,8 +21,6 @@ async function main() {
entryPoints: await glob(["./src/*.ts", "./src/**/*.ts"]),
outdir: "pkg/dist-src",
bundle: false,
platform: "neutral",
format: "esm",
...sharedOptions,
sourcemap: false,
});
Expand All @@ -35,27 +36,12 @@ async function main() {

const entryPoints = ["./pkg/dist-src/index.js"];

await Promise.all([
// Build the a CJS Node.js bundle
esbuild.build({
entryPoints,
outdir: "pkg/dist-node",
bundle: true,
platform: "node",
target: "node14",
format: "cjs",
...sharedOptions,
}),
// Build an ESM browser bundle
esbuild.build({
entryPoints,
outdir: "pkg/dist-web",
bundle: true,
platform: "browser",
format: "esm",
...sharedOptions,
}),
]);
await esbuild.build({
entryPoints,
outdir: "pkg/dist-bundle",
bundle: true,
...sharedOptions,
});

// Copy the README, LICENSE to the pkg folder
await copyFile("LICENSE", "pkg/LICENSE");
Expand All @@ -74,10 +60,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-bundle/index.js",
// Tooling currently are having issues with the "exports" field when there is no "default", ex: TypeScript, eslint, ncc
default: "./dist-bundle/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,4 +1,4 @@
import type { Callback, Authentication } from "./types";
import type { Callback, Authentication } from "./types.js";

export async function auth(callback: Callback): Promise<Authentication> {
const result = await callback();
Expand Down
4 changes: 2 additions & 2 deletions src/hook.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ import type {
RequestParameters,
Route,
Callback,
} from "./types";
} from "./types.js";

import { withAuthorizationPrefix } from "./with-authorization-prefix";
import { withAuthorizationPrefix } from "./with-authorization-prefix.js";

export async function hook(
callback: Callback,
Expand Down
6 changes: 3 additions & 3 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { auth } from "./auth";
import { hook } from "./hook";
import { auth } from "./auth.js";
import { hook } from "./hook.js";
import type {
StrategyInterface,
StrategyOption,
Authentication,
} from "./types";
} from "./types.js";

export type Types = {
StrategyOptions: StrategyOption;
Expand Down
2 changes: 1 addition & 1 deletion test/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { request } from "@octokit/request";
import fetchMock, { MockMatcherFunction } from "fetch-mock";
import { Octokit } from "@octokit/core";

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

test("README example", async () => {
let token: string | undefined;
Expand Down

0 comments on commit a52c8e8

Please sign in to comment.