Skip to content

Commit 4986fb0

Browse files
authored
feat: package is now ESM (#675)
BREAKING CHANGE: package is now ESM
1 parent 0404bc6 commit 4986fb0

15 files changed

+123
-133
lines changed

package-lock.json

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

package.json

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,37 +4,38 @@
44
"publishConfig": {
55
"access": "public"
66
},
7+
"type": "module",
78
"description": "Octokit plugin for GitHub's recommended request throttling",
89
"scripts": {
910
"build": "node scripts/build.mjs && tsc -p tsconfig.json",
1011
"lint": "prettier --check '{src,scripts,test}/**/*' '!*/generated/**' README.md package.json",
1112
"lint:fix": "prettier --write '{src,scripts,test}/**/*' '!*/generated/**' 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
"update-endpoints": "npm-run-all update-endpoints:*",
15-
"update-endpoints:fetch-json": "node scripts/update-endpoints/fetch-json",
16-
"update-endpoints:code": "node scripts/update-endpoints/code",
17-
"validate:ts": "npm run build && tsc --noEmit --noImplicitAny --target es2020 --esModuleInterop --moduleResolution node test/typescript-validate.ts"
16+
"update-endpoints:fetch-json": "node scripts/update-endpoints/fetch-json.js",
17+
"update-endpoints:code": "node scripts/update-endpoints/code.js",
18+
"validate:ts": "tsc --noEmit --noImplicitAny --target es2022 --esModuleInterop --moduleResolution node16 --module node16 test/typescript-validate.ts"
1819
},
1920
"repository": "github:octokit/plugin-throttling.js",
2021
"author": "Simon Grondin (http://github.com/SGrondin)",
2122
"license": "MIT",
2223
"dependencies": {
23-
"@octokit/types": "^12.2.0",
24+
"@octokit/types": "^12.6.0",
2425
"bottleneck": "^2.15.3"
2526
},
2627
"peerDependencies": {
27-
"@octokit/core": "^5.0.0"
28+
"@octokit/core": "^6.0.0"
2829
},
2930
"devDependencies": {
30-
"@octokit/core": "^5.0.0",
31-
"@octokit/request-error": "^5.0.0",
32-
"@octokit/tsconfig": "^2.0.0",
31+
"@octokit/core": "^6.0.0",
32+
"@octokit/request-error": "^6.0.1",
33+
"@octokit/tsconfig": "^3.0.0",
3334
"@types/fetch-mock": "^7.3.1",
3435
"@types/jest": "^29.0.0",
3536
"@types/node": "^20.0.0",
3637
"esbuild": "^0.20.0",
37-
"fetch-mock": "^9.0.0",
38+
"fetch-mock": "npm:@gr2m/fetch-mock@9.11.0-pull-request-644.1",
3839
"github-openapi-graphql-query": "^4.0.0",
3940
"glob": "^10.2.6",
4041
"jest": "^29.0.0",
@@ -45,11 +46,15 @@
4546
"typescript": "^5.0.0"
4647
},
4748
"jest": {
49+
"extensionsToTreatAsEsm": [
50+
".ts"
51+
],
4852
"transform": {
4953
"^.+\\.(ts|tsx)$": [
5054
"ts-jest",
5155
{
52-
"tsconfig": "test/tsconfig.test.json"
56+
"tsconfig": "test/tsconfig.test.json",
57+
"useESM": true
5358
}
5459
]
5560
},
@@ -60,6 +65,9 @@
6065
"functions": 100,
6166
"lines": 100
6267
}
68+
},
69+
"moduleNameMapper": {
70+
"^(.+)\\.jsx?$": "$1"
6371
}
6472
},
6573
"release": {

scripts/build.mjs

Lines changed: 14 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -35,27 +35,14 @@ 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-
]);
38+
await esbuild.build({
39+
entryPoints,
40+
outdir: "pkg/dist-bundle",
41+
bundle: true,
42+
platform: "neutral",
43+
format: "esm",
44+
...sharedOptions,
45+
});
5946

6047
// Copy the README, LICENSE to the pkg folder
6148
await copyFile("LICENSE", "pkg/LICENSE");
@@ -74,10 +61,12 @@ async function main() {
7461
{
7562
...pkg,
7663
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",
64+
exports: {
65+
".": {
66+
types: "./dist-types/index.d.ts",
67+
import: "./dist-bundle/index.js",
68+
},
69+
},
8170
sideEffects: false,
8271
},
8372
null,

scripts/update-endpoints/code.js

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,13 @@
44
* trigger notifications. So instead we automatically generate a file that
55
* only contains these paths when @octokit/openapi has a new release.
66
*/
7-
const { writeFileSync } = require("fs");
7+
import { writeFileSync, readFileSync } from "node:fs";
88

9-
const prettier = require("prettier");
9+
import prettier from "prettier";
1010

11-
const ENDPOINTS = require("./generated/endpoints.json");
11+
const ENDPOINTS = JSON.parse(
12+
readFileSync(new URL("./generated/endpoints.json", import.meta.url), "utf-8"),
13+
);
1214
const paths = [];
1315

1416
for (const endpoint of ENDPOINTS) {

0 commit comments

Comments
 (0)