Skip to content

Commit

Permalink
feat: package is now ESM (#517)
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 b61a5d5 commit 99b03ed
Show file tree
Hide file tree
Showing 6 changed files with 96 additions and 94 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ Node
Install with `npm install @octokit/core @octokit/plugin-retry`. Optionally replace `@octokit/core` with a core-compatible module

```js
const { Octokit } = require("@octokit/core");
const { retry } = require("@octokit/plugin-retry");
import { Octokit } from "@octokit/core";
import { retry } from "@octokit/plugin-retry";
```

</td></tr>
Expand Down
111 changes: 68 additions & 43 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 @@ -4,13 +4,14 @@
"publishConfig": {
"access": "public"
},
"type": "module",
"description": "Automatic retry plugin for octokit",
"scripts": {
"build": "node scripts/build.mjs && tsc -p tsconfig.json",
"lint": "prettier --check '{src,test}/**/*' README.md package.json",
"lint:fix": "prettier --write '{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/plugin-retry.js",
"author": "Simon Grondin (http://github.com/SGrondin)",
Expand All @@ -21,16 +22,16 @@
"bottleneck": "^2.15.3"
},
"peerDependencies": {
"@octokit/core": ">=5"
"@octokit/core": ">=6"
},
"devDependencies": {
"@octokit/core": "^5.0.0",
"@octokit/tsconfig": "^2.0.0",
"@octokit/core": "^6.0.0",
"@octokit/tsconfig": "^3.0.0",
"@types/fetch-mock": "^7.3.1",
"@types/jest": "^29.0.0",
"@types/node": "^20.0.0",
"esbuild": "^0.20.0",
"fetch-mock": "^9.0.0",
"fetch-mock": "npm:@gr2m/[email protected]",
"glob": "^10.2.6",
"jest": "^29.0.0",
"prettier": "3.2.5",
Expand All @@ -40,11 +41,15 @@
},
"jest": {
"preset": "ts-jest",
"extensionsToTreatAsEsm": [
".ts"
],
"transform": {
"^.+\\.(ts|tsx)$": [
"ts-jest",
{
"tsconfig": "test/tsconfig.test.json"
"tsconfig": "test/tsconfig.test.json",
"useESM": true
}
]
},
Expand Down
42 changes: 15 additions & 27 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",
platform: "neutral",
target: "es2022",
format: "esm",
};

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 @@ -35,27 +36,12 @@ async function main() {

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: "node18",
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,
outdir: "pkg/dist-bundle",
bundle: true,
...sharedOptions,
});

// Copy the README, LICENSE to the pkg folder
await copyFile("LICENSE", "pkg/LICENSE");
Expand All @@ -74,10 +60,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
15 changes: 0 additions & 15 deletions scripts/fix-package-json.js

This file was deleted.

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 99b03ed

Please sign in to comment.