Skip to content

Commit

Permalink
feat: package is now ESM (#280)
Browse files Browse the repository at this point in the history
BREAKING CHANGE: package is now ESM
  • Loading branch information
wolfy1339 committed Feb 25, 2024
1 parent ccf4d60 commit c4edb47
Show file tree
Hide file tree
Showing 5 changed files with 77 additions and 69 deletions.
3 changes: 1 addition & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,7 @@ Node
Install with <code>npm install @octokit/auth-unauthenticated</code>

```js
const { createUnauthenticatedAuth } = require("@octokit/auth-unauthenticated");
// or: import { createUnauthenticatedAuth } from "@octokit/auth-unauthenticated";
import { createUnauthenticatedAuth } from "@octokit/auth-unauthenticated";
```

</td></tr>
Expand Down
99 changes: 47 additions & 52 deletions package-lock.json

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

17 changes: 11 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,15 @@
"publishConfig": {
"access": "public"
},
"type": "module",
"version": "0.0.0-development",
"description": "GitHub API token authentication for browsers and Node.js",
"scripts": {
"build": "node scripts/build.mjs && tsc -p tsconfig.json",
"lint": "prettier --check 'src/**/*.ts' 'test/**/*.ts' '*.md' package.json",
"lint:fix": "prettier --write 'src/**/*.ts' 'test/**/*.ts' '*.md' package.json",
"pretest": "npm run lint -s",
"test": "jest --coverage"
"test": "NODE_OPTIONS=\"$NODE_OPTIONS --experimental-vm-modules\" npx jest --coverage"
},
"repository": "github:octokit/auth-unauthenticated.js",
"keywords": [
Expand All @@ -22,13 +23,13 @@
"author": "Gregor Martynus (https://github.com/gr2m)",
"license": "MIT",
"dependencies": {
"@octokit/request-error": "^5.0.0",
"@octokit/request-error": "^6.0.1",
"@octokit/types": "^12.0.0"
},
"devDependencies": {
"@octokit/core": "^5.0.0",
"@octokit/request": "^8.0.2",
"@octokit/tsconfig": "^2.0.0",
"@octokit/core": "^6.0.0",
"@octokit/request": "^9.0.0",
"@octokit/tsconfig": "^3.0.0",
"@types/jest": "^29.0.0",
"esbuild": "^0.20.0",
"fetch-mock": "npm:@gr2m/fetch-mock@^9.11.0-pull-request-644.1",
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 Down
26 changes: 18 additions & 8 deletions scripts/build.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ const sharedOptions = {
minify: false,
allowOverwrite: true,
packages: "external",
format: "esm",
};

async function main() {
Expand All @@ -23,7 +24,6 @@ async function main() {
outdir: "pkg/dist-src",
bundle: false,
platform: "neutral",
format: "esm",
...sharedOptions,
sourcemap: false,
});
Expand All @@ -46,8 +46,7 @@ async function main() {
outdir: "pkg/dist-node",
bundle: true,
platform: "node",
target: "node14",
format: "cjs",
target: "node18",
...sharedOptions,
}),
// Build an ESM browser bundle
Expand All @@ -56,7 +55,6 @@ async function main() {
outdir: "pkg/dist-web",
bundle: true,
platform: "browser",
format: "esm",
...sharedOptions,
}),
]);
Expand All @@ -78,10 +76,22 @@ async function main() {
{
...pkg,
files: ["dist-*/**", "bin/**"],
main: "dist-node/index.js",
module: "dist-web/index.js",
types: "dist-types/index.d.ts",
source: "dist-src/index.js",
exports: {
".": {
node: {
types: "./dist-types/index.d.ts",
import: "./dist-node/index.js",
},
browser: {
types: "./dist-types/web.d.ts",
import: "./dist-web/index.js",
},
default: {
types: "./dist-types/index.d.ts",
import: "./dist-node/index.js",
},
},
},
sideEffects: false,
},
null,
Expand Down
1 change: 0 additions & 1 deletion test/tsconfig.test.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
"compilerOptions": {
"emitDeclarationOnly": false,
"noEmit": true,
"verbatimModuleSyntax": false,
"allowImportingTsExtensions": true
},
"include": ["src/**/*"]
Expand Down

0 comments on commit c4edb47

Please sign in to comment.