Skip to content

Commit 90e12d0

Browse files
authored
feat: package is now ESM (#235)
BREAKING CHANGE: package is now ESM
1 parent 5d1330a commit 90e12d0

File tree

11 files changed

+163
-81
lines changed

11 files changed

+163
-81
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ Node
5454
Install with `npm install @octokit/core @octokit/auth-oauth-device`
5555

5656
```js
57-
const { createOAuthDeviceAuth } = require("@octokit/auth-oauth-device");
57+
import { createOAuthDeviceAuth } from "@octokit/auth-oauth-device";
5858
```
5959

6060
</td></tr>
@@ -224,7 +224,7 @@ Must be either `oauth-app` or `github-app`. Defaults to `oauth-app`.
224224
You can pass in your own <a href="https://github.com/octokit/request.js"><code>@octokit/request</code></a> instance. For usage with enterprise, set <code>baseUrl</code> to the API root endpoint. Example:
225225

226226
```js
227-
const { request } = require("@octokit/request");
227+
import { request } from "@octokit/request";
228228
createOAuthDeviceAuth({
229229
clientId: "1234567890abcdef1234",
230230
clientSecret: "secret",

package-lock.json

Lines changed: 119 additions & 31 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,13 @@
22
"name": "@octokit/auth-oauth-device",
33
"version": "0.0.0-development",
44
"description": "GitHub OAuth Device authentication strategy for JavaScript",
5+
"type": "module",
56
"scripts": {
67
"build": "node scripts/build.mjs && tsc -p tsconfig.json",
78
"lint": "prettier --check '{src,test,scripts}/**/*' README.md package.json",
89
"lint:fix": "prettier --write '{src,test,scripts}/**/*' README.md package.json",
910
"pretest": "npm run -s lint",
10-
"test": "jest --coverage"
11+
"test": "NODE_OPTIONS=\"$NODE_OPTIONS --experimental-vm-modules\" npx jest --coverage"
1112
},
1213
"repository": "github:octokit/auth-oauth-device.js",
1314
"keywords": [
@@ -19,10 +20,10 @@
1920
"author": "Gregor Martynus (https://dev.to/gr2m)",
2021
"license": "MIT",
2122
"dependencies": {
22-
"@octokit/oauth-methods": "^4.0.0",
23-
"@octokit/request": "^8.0.0",
23+
"@octokit/oauth-methods": "^5.0.0",
24+
"@octokit/request": "^9.0.0",
2425
"@octokit/types": "^12.0.0",
25-
"universal-user-agent": "^6.0.0"
26+
"universal-user-agent": "^7.0.0"
2627
},
2728
"devDependencies": {
2829
"@octokit/tsconfig": "^3.0.0",
@@ -39,11 +40,15 @@
3940
"typescript": "^5.0.0"
4041
},
4142
"jest": {
43+
"extensionsToTreatAsEsm": [
44+
".ts"
45+
],
4246
"transform": {
4347
"^.+\\.(ts|tsx)$": [
4448
"ts-jest",
4549
{
46-
"tsconfig": "test/tsconfig.test.json"
50+
"tsconfig": "test/tsconfig.test.json",
51+
"useESM": true
4752
}
4853
]
4954
},
@@ -54,6 +59,9 @@
5459
"functions": 100,
5560
"lines": 100
5661
}
62+
},
63+
"moduleNameMapper": {
64+
"^(.+)\\.jsx?$": "$1"
5765
}
5866
},
5967
"release": {

scripts/build.mjs

Lines changed: 15 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@ const sharedOptions = {
88
minify: false,
99
allowOverwrite: true,
1010
packages: "external",
11+
target: "es2022",
12+
format: "esm",
13+
platform: "neutral",
1114
};
1215

1316
async function main() {
@@ -18,8 +21,6 @@ async function main() {
1821
entryPoints: await glob(["./src/*.ts", "./src/**/*.ts"]),
1922
outdir: "pkg/dist-src",
2023
bundle: false,
21-
platform: "neutral",
22-
format: "esm",
2324
...sharedOptions,
2425
sourcemap: false,
2526
});
@@ -33,29 +34,12 @@ async function main() {
3334
await rm(typeFile);
3435
}
3536

36-
const entryPoints = ["./pkg/dist-src/index.js"];
37-
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: "node14",
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-
]);
37+
await esbuild.build({
38+
entryPoints: ["./pkg/dist-src/index.js"],
39+
outdir: "pkg/dist-bundle",
40+
bundle: true,
41+
...sharedOptions,
42+
});
5943

6044
// Copy the README, LICENSE to the pkg folder
6145
await copyFile("LICENSE", "pkg/LICENSE");
@@ -74,10 +58,12 @@ async function main() {
7458
{
7559
...pkg,
7660
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",
61+
exports: {
62+
".": {
63+
types: "./dist-types/index.d.ts",
64+
import: "./dist-bundle/index.js",
65+
},
66+
},
8167
sideEffects: false,
8268
},
8369
null,

0 commit comments

Comments
 (0)