Skip to content

Commit 99b03ed

Browse files
authoredFeb 25, 2024··
feat: package is now ESM (#517)
BREAKING CHANGE: package is now ESM
1 parent b61a5d5 commit 99b03ed

File tree

6 files changed

+96
-94
lines changed

6 files changed

+96
-94
lines changed
 

‎README.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,8 @@ Node
3030
Install with `npm install @octokit/core @octokit/plugin-retry`. Optionally replace `@octokit/core` with a core-compatible module
3131

3232
```js
33-
const { Octokit } = require("@octokit/core");
34-
const { retry } = require("@octokit/plugin-retry");
33+
import { Octokit } from "@octokit/core";
34+
import { retry } from "@octokit/plugin-retry";
3535
```
3636

3737
</td></tr>

‎package-lock.json

+68-43
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎package.json

+11-6
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,14 @@
44
"publishConfig": {
55
"access": "public"
66
},
7+
"type": "module",
78
"description": "Automatic retry plugin for octokit",
89
"scripts": {
910
"build": "node scripts/build.mjs && tsc -p tsconfig.json",
1011
"lint": "prettier --check '{src,test}/**/*' README.md package.json",
1112
"lint:fix": "prettier --write '{src,test}/**/*' 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
},
1516
"repository": "github:octokit/plugin-retry.js",
1617
"author": "Simon Grondin (http://github.com/SGrondin)",
@@ -21,16 +22,16 @@
2122
"bottleneck": "^2.15.3"
2223
},
2324
"peerDependencies": {
24-
"@octokit/core": ">=5"
25+
"@octokit/core": ">=6"
2526
},
2627
"devDependencies": {
27-
"@octokit/core": "^5.0.0",
28-
"@octokit/tsconfig": "^2.0.0",
28+
"@octokit/core": "^6.0.0",
29+
"@octokit/tsconfig": "^3.0.0",
2930
"@types/fetch-mock": "^7.3.1",
3031
"@types/jest": "^29.0.0",
3132
"@types/node": "^20.0.0",
3233
"esbuild": "^0.20.0",
33-
"fetch-mock": "^9.0.0",
34+
"fetch-mock": "npm:@gr2m/fetch-mock@9.11.0-pull-request-644.1",
3435
"glob": "^10.2.6",
3536
"jest": "^29.0.0",
3637
"prettier": "3.2.5",
@@ -40,11 +41,15 @@
4041
},
4142
"jest": {
4243
"preset": "ts-jest",
44+
"extensionsToTreatAsEsm": [
45+
".ts"
46+
],
4347
"transform": {
4448
"^.+\\.(ts|tsx)$": [
4549
"ts-jest",
4650
{
47-
"tsconfig": "test/tsconfig.test.json"
51+
"tsconfig": "test/tsconfig.test.json",
52+
"useESM": true
4853
}
4954
]
5055
},

‎scripts/build.mjs

+15-27
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@ const sharedOptions = {
88
minify: false,
99
allowOverwrite: true,
1010
packages: "external",
11+
platform: "neutral",
12+
target: "es2022",
13+
format: "esm",
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
});
@@ -35,27 +36,12 @@ async function main() {
3536

3637
const entryPoints = ["./pkg/dist-src/index.js"];
3738

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-
]);
39+
await esbuild.build({
40+
entryPoints,
41+
outdir: "pkg/dist-bundle",
42+
bundle: true,
43+
...sharedOptions,
44+
});
5945

6046
// Copy the README, LICENSE to the pkg folder
6147
await copyFile("LICENSE", "pkg/LICENSE");
@@ -74,10 +60,12 @@ async function main() {
7460
{
7561
...pkg,
7662
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",
63+
exports: {
64+
".": {
65+
types: "./dist-types/index.d.ts",
66+
import: "./dist-bundle/index.js",
67+
},
68+
},
8169
sideEffects: false,
8270
},
8371
null,

‎scripts/fix-package-json.js

-15
This file was deleted.

‎test/tsconfig.test.json

-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
"compilerOptions": {
44
"emitDeclarationOnly": false,
55
"noEmit": true,
6-
"verbatimModuleSyntax": false,
76
"allowImportingTsExtensions": true
87
},
98
"include": ["src/**/*"]

0 commit comments

Comments
 (0)