Skip to content

Commit 2a41b55

Browse files
authored
feat: package is now ESM (#353)
BREAKING CHANGE: package is now ESM
1 parent 6ccd791 commit 2a41b55

File tree

6 files changed

+28
-40
lines changed

6 files changed

+28
-40
lines changed

package-lock.json

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

package.json

+11-3
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,15 @@
33
"publishConfig": {
44
"access": "public"
55
},
6+
"type": "module",
67
"version": "0.0.0-development",
78
"description": "Universal library to retrieve GitHub’s identity URL for the OAuth web flow",
89
"scripts": {
910
"build": "node scripts/build.mjs && tsc -p tsconfig.json",
1011
"lint": "prettier --check '{src,test}/**/*' README.md package.json",
1112
"lint:fix": "prettier --write '{src,test}/**/*' 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
},
1516
"repository": "github:octokit/oauth-authorization-url.js",
1617
"files": [
@@ -24,7 +25,7 @@
2425
"author": "Gregor Martynus (https://github.com/gr2m)",
2526
"license": "MIT",
2627
"devDependencies": {
27-
"@octokit/tsconfig": "^2.0.0",
28+
"@octokit/tsconfig": "^3.0.0",
2829
"@types/jest": "^29.0.0",
2930
"esbuild": "^0.20.0",
3031
"glob": "^10.2.6",
@@ -34,11 +35,15 @@
3435
"typescript": "^5.0.0"
3536
},
3637
"jest": {
38+
"extensionsToTreatAsEsm": [
39+
".ts"
40+
],
3741
"transform": {
3842
"^.+\\.(ts|tsx)$": [
3943
"ts-jest",
4044
{
41-
"tsconfig": "test/tsconfig.test.json"
45+
"tsconfig": "test/tsconfig.test.json",
46+
"useESM": true
4247
}
4348
]
4449
},
@@ -49,6 +54,9 @@
4954
"functions": 100,
5055
"lines": 100
5156
}
57+
},
58+
"moduleNameMapper": {
59+
"^(.+)\\.jsx?$": "$1"
5260
}
5361
},
5462
"release": {

scripts/build.mjs

+8-28
Original file line numberDiff line numberDiff line change
@@ -35,28 +35,6 @@ async function main() {
3535

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

38-
await Promise.all([
39-
// Build the a CJS Node.js bundle
40-
esbuild.build({
41-
entryPoints,
42-
outdir: "pkg/dist-node",
43-
bundle: true,
44-
platform: "node",
45-
target: "node18",
46-
format: "cjs",
47-
...sharedOptions,
48-
}),
49-
// Build an ESM browser bundle
50-
esbuild.build({
51-
entryPoints,
52-
outdir: "pkg/dist-web",
53-
bundle: true,
54-
platform: "browser",
55-
format: "esm",
56-
...sharedOptions,
57-
}),
58-
]);
59-
6038
// Copy the README, LICENSE to the pkg folder
6139
await copyFile("LICENSE", "pkg/LICENSE");
6240
await copyFile("README.md", "pkg/README.md");
@@ -73,13 +51,15 @@ async function main() {
7351
JSON.stringify(
7452
{
7553
...pkg,
76-
files: ["dist-*/**", "bin/**"],
77-
main: "dist-node/index.js",
78-
browser: "dist-web/index.js",
79-
types: "dist-types/index.d.ts",
80-
module: "dist-src/index.js",
54+
files: ["dist-*/**"],
55+
exports: {
56+
".": {
57+
types: "./dist-types/index.d.ts",
58+
import: "./dist-src/index.js",
59+
},
60+
},
8161
sideEffects: false,
82-
unpkg: "dist-web/index.js"
62+
unpkg: "dist-src/index.js"
8363
},
8464
null,
8565
2

src/index.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,14 @@ import type {
33
GitHubAppOptions,
44
OAuthAppResult,
55
GitHubAppResult,
6-
} from "./types";
6+
} from "./types.js";
77
export type {
88
ClientType,
99
OAuthAppOptions,
1010
GitHubAppOptions,
1111
OAuthAppResult,
1212
GitHubAppResult,
13-
} from "./types";
13+
} from "./types.js";
1414

1515
export function oauthAuthorizationUrl(options: OAuthAppOptions): OAuthAppResult;
1616
export function oauthAuthorizationUrl(

test/index.test.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
import { oauthAuthorizationUrl } from "../src/index";
1+
import { oauthAuthorizationUrl } from "../src/index.js";
2+
import { jest } from "@jest/globals";
23

34
beforeAll(() => {
45
Math.random = jest.fn(() => 0.123);

test/tsconfig.test.json

+1-2
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,7 @@
22
"extends": "../tsconfig.json",
33
"compilerOptions": {
44
"emitDeclarationOnly": false,
5-
"noEmit": true,
6-
"verbatimModuleSyntax": false
5+
"noEmit": true
76
},
87
"include": ["src/**/*"]
98
}

0 commit comments

Comments
 (0)