Skip to content

Commit

Permalink
feat: package is now ESM (#235)
Browse files Browse the repository at this point in the history
BREAKING CHANGE: package is now ESM
  • Loading branch information
wolfy1339 authored Feb 25, 2024
1 parent 5d1330a commit 90e12d0
Show file tree
Hide file tree
Showing 11 changed files with 163 additions and 81 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ Node
Install with `npm install @octokit/core @octokit/auth-oauth-device`

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

</td></tr>
Expand Down Expand Up @@ -224,7 +224,7 @@ Must be either `oauth-app` or `github-app`. Defaults to `oauth-app`.
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:

```js
const { request } = require("@octokit/request");
import { request } from "@octokit/request";
createOAuthDeviceAuth({
clientId: "1234567890abcdef1234",
clientSecret: "secret",
Expand Down
150 changes: 119 additions & 31 deletions package-lock.json

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

18 changes: 13 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,13 @@
"name": "@octokit/auth-oauth-device",
"version": "0.0.0-development",
"description": "GitHub OAuth Device authentication strategy for JavaScript",
"type": "module",
"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-oauth-device.js",
"keywords": [
Expand All @@ -19,10 +20,10 @@
"author": "Gregor Martynus (https://dev.to/gr2m)",
"license": "MIT",
"dependencies": {
"@octokit/oauth-methods": "^4.0.0",
"@octokit/request": "^8.0.0",
"@octokit/oauth-methods": "^5.0.0",
"@octokit/request": "^9.0.0",
"@octokit/types": "^12.0.0",
"universal-user-agent": "^6.0.0"
"universal-user-agent": "^7.0.0"
},
"devDependencies": {
"@octokit/tsconfig": "^3.0.0",
Expand All @@ -39,11 +40,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 @@ -54,6 +59,9 @@
"functions": 100,
"lines": 100
}
},
"moduleNameMapper": {
"^(.+)\\.jsx?$": "$1"
}
},
"release": {
Expand Down
44 changes: 15 additions & 29 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",
target: "es2022",
format: "esm",
platform: "neutral",
};

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 @@ -33,29 +34,12 @@ async function main() {
await rm(typeFile);
}

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: ["./pkg/dist-src/index.js"],
outdir: "pkg/dist-bundle",
bundle: true,
...sharedOptions,
});

// Copy the README, LICENSE to the pkg folder
await copyFile("LICENSE", "pkg/LICENSE");
Expand All @@ -74,10 +58,12 @@ 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",
},
},
sideEffects: false,
},
null,
Expand Down
Loading

0 comments on commit 90e12d0

Please sign in to comment.