Skip to content

Commit

Permalink
feat: output ESM for NodeJS
Browse files Browse the repository at this point in the history
BREAKING CHANGE: output ESM instead of CJS
  • Loading branch information
wolfy1339 committed Feb 23, 2024
1 parent 24da8ec commit 8c08ca9
Show file tree
Hide file tree
Showing 5 changed files with 55 additions and 20 deletions.
3 changes: 1 addition & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,7 @@ Node
Install with <code>npm install @octokit/endpoint</code>

```js
const { endpoint } = require("@octokit/endpoint");
// or: import { endpoint } from "@octokit/endpoint";
import { endpoint } from "@octokit/endpoint";
```

</td></tr>
Expand Down
46 changes: 38 additions & 8 deletions package-lock.json

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

13 changes: 9 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{
"name": "@octokit/endpoint",
"version": "0.0.0-development",
"type": "module",
"publishConfig": {
"access": "public"
},
Expand All @@ -10,7 +11,7 @@
"lint": "prettier --check '{scripts,src,test}/**/*' README.md package.json",
"lint:fix": "prettier --write '{scripts,src,test}/**/*' 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/endpoint.js",
"keywords": [
Expand All @@ -22,7 +23,7 @@
"author": "Gregor Martynus (https://github.com/gr2m)",
"license": "MIT",
"devDependencies": {
"@octokit/tsconfig": "^2.0.0",
"@octokit/tsconfig": "^3.0.0",
"@types/jest": "^29.0.0",
"@types/node": "^20.10.0",
"esbuild": "^0.20.0",
Expand All @@ -36,7 +37,7 @@
},
"dependencies": {
"@octokit/types": "^12.0.0",
"universal-user-agent": "^6.0.0"
"universal-user-agent": "^7.0.2"
},
"release": {
"branches": [
Expand Down Expand Up @@ -71,11 +72,15 @@
]
},
"jest": {
"extensionsToTreatAsEsm": [
".ts"
],
"transform": {
"^.+\\.(ts|tsx)$": [
"ts-jest",
{
"tsconfig": "test/tsconfig.test.json"
"tsconfig": "test/tsconfig.test.json",
"useESM": true
}
]
},
Expand Down
12 changes: 7 additions & 5 deletions scripts/build.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ async function main() {
bundle: true,
platform: "node",
target: "node18",
format: "cjs",
format: "esm",
...sharedOptions,
}),
// Build an ESM browser bundle
Expand Down Expand Up @@ -74,10 +74,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-src/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 8c08ca9

Please sign in to comment.