From 03add4d62973a74dd51580e55c3c99339a38f5c4 Mon Sep 17 00:00:00 2001 From: wolfy1339 Date: Sun, 25 Feb 2024 15:34:18 -0500 Subject: [PATCH] feat: package is now ESM BREAKING CHANGE: package is now ESM --- README.md | 4 +- package-lock.json | 111 ++++++++++++++++++++++-------------- package.json | 17 ++++-- scripts/build.mjs | 42 +++++--------- scripts/fix-package-json.js | 15 ----- test/tsconfig.test.json | 1 - 6 files changed, 96 insertions(+), 94 deletions(-) delete mode 100644 scripts/fix-package-json.js diff --git a/README.md b/README.md index 854766a7..767debd1 100644 --- a/README.md +++ b/README.md @@ -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"; ``` diff --git a/package-lock.json b/package-lock.json index 52985ebb..e0d465b6 100644 --- a/package-lock.json +++ b/package-lock.json @@ -14,13 +14,13 @@ "bottleneck": "^2.15.3" }, "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/fetch-mock@9.11.0-pull-request-644.1", "glob": "^10.2.6", "jest": "^29.0.0", "prettier": "3.2.5", @@ -32,7 +32,7 @@ "node": ">= 18" }, "peerDependencies": { - "@octokit/core": ">=5" + "@octokit/core": ">=6" } }, "node_modules/@ampproject/remapping": { @@ -1711,54 +1711,66 @@ } }, "node_modules/@octokit/auth-token": { - "version": "4.0.0", - "resolved": "https://registry.npmjs.org/@octokit/auth-token/-/auth-token-4.0.0.tgz", - "integrity": "sha512-tY/msAuJo6ARbK6SPIxZrPBms3xPbfwBrulZe0Wtr/DIY9lje2HeV1uoebShn6mx7SjCHif6EjMvoREj+gZ+SA==", + "version": "5.0.0", + "resolved": "https://registry.npmjs.org/@octokit/auth-token/-/auth-token-5.0.0.tgz", + "integrity": "sha512-JpQdKWTuu79A6YDaOfl9/HFvdhEwlRSTE/MFLGl8eU+XK6jIuqhxEftJNDpQjem1J7GLcs+4sapP1JXNPTDP/A==", "dev": true, "engines": { "node": ">= 18" } }, "node_modules/@octokit/core": { - "version": "5.1.0", - "resolved": "https://registry.npmjs.org/@octokit/core/-/core-5.1.0.tgz", - "integrity": "sha512-BDa2VAMLSh3otEiaMJ/3Y36GU4qf6GI+VivQ/P41NC6GHcdxpKlqV0ikSZ5gdQsmS3ojXeRx5vasgNTinF0Q4g==", + "version": "6.0.0", + "resolved": "https://registry.npmjs.org/@octokit/core/-/core-6.0.0.tgz", + "integrity": "sha512-0JifUnQKGoX83rMhy5bk2QNAPcO5hjD082YZ+wjqUa509RaZIn3F5SeqbKJoc2Zh+ld7rEQmlIeJzhVamSW2Xw==", "dev": true, "dependencies": { - "@octokit/auth-token": "^4.0.0", - "@octokit/graphql": "^7.0.0", - "@octokit/request": "^8.0.2", - "@octokit/request-error": "^5.0.0", + "@octokit/auth-token": "^5.0.0", + "@octokit/graphql": "^8.0.0", + "@octokit/request": "^9.0.0", + "@octokit/request-error": "^6.0.1", "@octokit/types": "^12.0.0", - "before-after-hook": "^2.2.0", - "universal-user-agent": "^6.0.0" + "before-after-hook": "^3.0.2", + "universal-user-agent": "^7.0.0" + }, + "engines": { + "node": ">= 18" + } + }, + "node_modules/@octokit/core/node_modules/@octokit/request-error": { + "version": "6.0.1", + "resolved": "https://registry.npmjs.org/@octokit/request-error/-/request-error-6.0.1.tgz", + "integrity": "sha512-EPeILOAEGqwmEG6g7dYlbvqkjJ5nWNcZvQpgeLEn1MieIcJ0xK0CJtvVcIMXqzIM8DOWzvI6zL5FQAwjTvk/Tg==", + "dev": true, + "dependencies": { + "@octokit/types": "^12.0.0" }, "engines": { "node": ">= 18" } }, "node_modules/@octokit/endpoint": { - "version": "9.0.4", - "resolved": "https://registry.npmjs.org/@octokit/endpoint/-/endpoint-9.0.4.tgz", - "integrity": "sha512-DWPLtr1Kz3tv8L0UvXTDP1fNwM0S+z6EJpRcvH66orY6Eld4XBMCSYsaWp4xIm61jTWxK68BrR7ibO+vSDnZqw==", + "version": "10.0.0", + "resolved": "https://registry.npmjs.org/@octokit/endpoint/-/endpoint-10.0.0.tgz", + "integrity": "sha512-emBcNDxBdC1y3+knJonS5zhUB/CG6TihubxM2U1/pG/Z1y3a4oV0Gzz3lmkCvWWQI6h3tqBAX9MgCBFp+M68Jw==", "dev": true, "dependencies": { "@octokit/types": "^12.0.0", - "universal-user-agent": "^6.0.0" + "universal-user-agent": "^7.0.2" }, "engines": { "node": ">= 18" } }, "node_modules/@octokit/graphql": { - "version": "7.0.2", - "resolved": "https://registry.npmjs.org/@octokit/graphql/-/graphql-7.0.2.tgz", - "integrity": "sha512-OJ2iGMtj5Tg3s6RaXH22cJcxXRi7Y3EBqbHTBRq+PQAqfaS8f/236fUrWhfSn8P4jovyzqucxme7/vWSSZBX2Q==", + "version": "8.0.0", + "resolved": "https://registry.npmjs.org/@octokit/graphql/-/graphql-8.0.0.tgz", + "integrity": "sha512-9B2HwWSb12ldwrp6pC8BFTsSCeidW7do0lMgWNH65IXRVteN503JJSWPH1VEM+qP8+/Ka1pw3MTs+3Q6Bjqukw==", "dev": true, "dependencies": { - "@octokit/request": "^8.0.1", + "@octokit/request": "^9.0.0", "@octokit/types": "^12.0.0", - "universal-user-agent": "^6.0.0" + "universal-user-agent": "^7.0.0" }, "engines": { "node": ">= 18" @@ -1770,15 +1782,15 @@ "integrity": "sha512-6G+ywGClliGQwRsjvqVYpklIfa7oRPA0vyhPQG/1Feh+B+wU0vGH1JiJ5T25d3g1JZYBHzR2qefLi9x8Gt+cpw==" }, "node_modules/@octokit/request": { - "version": "8.2.0", - "resolved": "https://registry.npmjs.org/@octokit/request/-/request-8.2.0.tgz", - "integrity": "sha512-exPif6x5uwLqv1N1irkLG1zZNJkOtj8bZxuVHd71U5Ftuxf2wGNvAJyNBcPbPC+EBzwYEbBDdSFb8EPcjpYxPQ==", + "version": "9.0.0", + "resolved": "https://registry.npmjs.org/@octokit/request/-/request-9.0.0.tgz", + "integrity": "sha512-hShsrZ40W8dz3TkyD5ifHNcrYfYpYF7Sh2x+ZKafA+eO0zNeKDTsbF1E0xrUf0mVYGeKL+NLMO5SnfAP22l05Q==", "dev": true, "dependencies": { - "@octokit/endpoint": "^9.0.0", - "@octokit/request-error": "^5.0.0", + "@octokit/endpoint": "^10.0.0", + "@octokit/request-error": "^6.0.1", "@octokit/types": "^12.0.0", - "universal-user-agent": "^6.0.0" + "universal-user-agent": "^7.0.2" }, "engines": { "node": ">= 18" @@ -1797,10 +1809,22 @@ "node": ">= 18" } }, + "node_modules/@octokit/request/node_modules/@octokit/request-error": { + "version": "6.0.1", + "resolved": "https://registry.npmjs.org/@octokit/request-error/-/request-error-6.0.1.tgz", + "integrity": "sha512-EPeILOAEGqwmEG6g7dYlbvqkjJ5nWNcZvQpgeLEn1MieIcJ0xK0CJtvVcIMXqzIM8DOWzvI6zL5FQAwjTvk/Tg==", + "dev": true, + "dependencies": { + "@octokit/types": "^12.0.0" + }, + "engines": { + "node": ">= 18" + } + }, "node_modules/@octokit/tsconfig": { - "version": "2.0.0", - "resolved": "https://registry.npmjs.org/@octokit/tsconfig/-/tsconfig-2.0.0.tgz", - "integrity": "sha512-tWnrai3quGt8+gRN2edzo9fmraWekeryXPeXDomMw2oFSpu/lH3VSWGn/q4V+rwjTRMeeXk/ci623/01Zet4VQ==", + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/@octokit/tsconfig/-/tsconfig-3.0.0.tgz", + "integrity": "sha512-tQLwgXYfBq9iUbOq26kWCzsJL6DY7qjOLzqcg5tCFQ4ob48H47iX98NudHW7S5OQ/fpSKYJhb3eQehyBNzYjfA==", "dev": true }, "node_modules/@octokit/types": { @@ -2210,9 +2234,9 @@ "dev": true }, "node_modules/before-after-hook": { - "version": "2.2.3", - "resolved": "https://registry.npmjs.org/before-after-hook/-/before-after-hook-2.2.3.tgz", - "integrity": "sha512-NzUnlZexiaH/46WDhANlyR2bXRopNg4F/zuSA3OpZnllCUgRaOF2znDioDWrmbNVsuZk6l9pMquQB38cfBZwkQ==", + "version": "3.0.2", + "resolved": "https://registry.npmjs.org/before-after-hook/-/before-after-hook-3.0.2.tgz", + "integrity": "sha512-Nik3Sc0ncrMK4UUdXQmAnRtzmNQTAAXmXIopizwZ1W1t8QmfJj+zL4OA2I7XPTPW5z5TDqv4hRo/JzouDJnX3A==", "dev": true }, "node_modules/bottleneck": { @@ -2887,9 +2911,10 @@ } }, "node_modules/fetch-mock": { - "version": "9.11.0", - "resolved": "https://registry.npmjs.org/fetch-mock/-/fetch-mock-9.11.0.tgz", - "integrity": "sha512-PG1XUv+x7iag5p/iNHD4/jdpxL9FtVSqRMUQhPab4hVDt80T1MH5ehzVrL2IdXO9Q2iBggArFvPqjUbHFuI58Q==", + "name": "@gr2m/fetch-mock", + "version": "9.11.0-pull-request-644.1", + "resolved": "https://registry.npmjs.org/@gr2m/fetch-mock/-/fetch-mock-9.11.0-pull-request-644.1.tgz", + "integrity": "sha512-gTp6RCHzlOXS1qRb0APfuyz48Lw/JFPa4uiar+kEgL1STsDwth75HJZ4x30tBlXMJXV8XDTDzJ2Hz9w3RWiHJA==", "dev": true, "dependencies": { "@babel/core": "^7.0.0", @@ -6191,9 +6216,9 @@ "dev": true }, "node_modules/universal-user-agent": { - "version": "6.0.1", - "resolved": "https://registry.npmjs.org/universal-user-agent/-/universal-user-agent-6.0.1.tgz", - "integrity": "sha512-yCzhz6FN2wU1NiiQRogkTQszlQSlpWaw8SvVegAc+bDxbzHgh1vX8uIe8OYyMH6DwH+sdTJsgMl36+mSMdRJIQ==", + "version": "7.0.2", + "resolved": "https://registry.npmjs.org/universal-user-agent/-/universal-user-agent-7.0.2.tgz", + "integrity": "sha512-0JCqzSKnStlRRQfCdowvqy3cy0Dvtlb8xecj/H8JFZuCze4rwjPZQOgvFvn0Ws/usCHQFGpyr+pB9adaGwXn4Q==", "dev": true }, "node_modules/update-browserslist-db": { diff --git a/package.json b/package.json index 9c428656..b1f59e7c 100644 --- a/package.json +++ b/package.json @@ -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)", @@ -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/fetch-mock@9.11.0-pull-request-644.1", "glob": "^10.2.6", "jest": "^29.0.0", "prettier": "3.2.5", @@ -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 } ] }, diff --git a/scripts/build.mjs b/scripts/build.mjs index 67f82f14..41994069 100644 --- a/scripts/build.mjs +++ b/scripts/build.mjs @@ -8,6 +8,9 @@ const sharedOptions = { minify: false, allowOverwrite: true, packages: "external", + platform: "neutral", + target: "es2022", + format: "esm", }; async function main() { @@ -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, }); @@ -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"); @@ -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, diff --git a/scripts/fix-package-json.js b/scripts/fix-package-json.js deleted file mode 100644 index d10147c6..00000000 --- a/scripts/fix-package-json.js +++ /dev/null @@ -1,15 +0,0 @@ -const fs = require("fs"); -const path = require("path"); -const {EOL} = require("os"); - -const pkgPath = path.join(__dirname, "../pkg/package.json"); -const pkg = JSON.parse(fs.readFileSync(pkgPath, "utf8")); - -pkg.files = pkg.files.map((file) => { - if (file.endsWith("/")) { - return file + "**"; - } - return file; -}); - -fs.writeFileSync(pkgPath, JSON.stringify(pkg, null, 2) + EOL, "utf8"); diff --git a/test/tsconfig.test.json b/test/tsconfig.test.json index 5e8dc248..cf1f2005 100644 --- a/test/tsconfig.test.json +++ b/test/tsconfig.test.json @@ -3,7 +3,6 @@ "compilerOptions": { "emitDeclarationOnly": false, "noEmit": true, - "verbatimModuleSyntax": false, "allowImportingTsExtensions": true }, "include": ["src/**/*"]