Skip to content

feat: package is now ESM #675

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
Feb 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
121 changes: 57 additions & 64 deletions package-lock.json

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

30 changes: 19 additions & 11 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,37 +4,38 @@
"publishConfig": {
"access": "public"
},
"type": "module",
"description": "Octokit plugin for GitHub's recommended request throttling",
"scripts": {
"build": "node scripts/build.mjs && tsc -p tsconfig.json",
"lint": "prettier --check '{src,scripts,test}/**/*' '!*/generated/**' README.md package.json",
"lint:fix": "prettier --write '{src,scripts,test}/**/*' '!*/generated/**' README.md package.json",
"pretest": "npm run -s lint",
"test": "jest --coverage",
"test": "NODE_OPTIONS=\"$NODE_OPTIONS --experimental-vm-modules\" npx jest --coverage",
"update-endpoints": "npm-run-all update-endpoints:*",
"update-endpoints:fetch-json": "node scripts/update-endpoints/fetch-json",
"update-endpoints:code": "node scripts/update-endpoints/code",
"validate:ts": "npm run build && tsc --noEmit --noImplicitAny --target es2020 --esModuleInterop --moduleResolution node test/typescript-validate.ts"
"update-endpoints:fetch-json": "node scripts/update-endpoints/fetch-json.js",
"update-endpoints:code": "node scripts/update-endpoints/code.js",
"validate:ts": "tsc --noEmit --noImplicitAny --target es2022 --esModuleInterop --moduleResolution node16 --module node16 test/typescript-validate.ts"
},
"repository": "github:octokit/plugin-throttling.js",
"author": "Simon Grondin (http://github.com/SGrondin)",
"license": "MIT",
"dependencies": {
"@octokit/types": "^12.2.0",
"@octokit/types": "^12.6.0",
"bottleneck": "^2.15.3"
},
"peerDependencies": {
"@octokit/core": "^5.0.0"
"@octokit/core": "^6.0.0"
},
"devDependencies": {
"@octokit/core": "^5.0.0",
"@octokit/request-error": "^5.0.0",
"@octokit/tsconfig": "^2.0.0",
"@octokit/core": "^6.0.0",
"@octokit/request-error": "^6.0.1",
"@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]",
"github-openapi-graphql-query": "^4.0.0",
"glob": "^10.2.6",
"jest": "^29.0.0",
Expand All @@ -45,11 +46,15 @@
"typescript": "^5.0.0"
},
"jest": {
"extensionsToTreatAsEsm": [
".ts"
],
"transform": {
"^.+\\.(ts|tsx)$": [
"ts-jest",
{
"tsconfig": "test/tsconfig.test.json"
"tsconfig": "test/tsconfig.test.json",
"useESM": true
}
]
},
Expand All @@ -60,6 +65,9 @@
"functions": 100,
"lines": 100
}
},
"moduleNameMapper": {
"^(.+)\\.jsx?$": "$1"
}
},
"release": {
Expand Down
39 changes: 14 additions & 25 deletions scripts/build.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -35,27 +35,14 @@ 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,
platform: "neutral",
format: "esm",
...sharedOptions,
});

// Copy the README, LICENSE to the pkg folder
await copyFile("LICENSE", "pkg/LICENSE");
Expand All @@ -74,10 +61,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
8 changes: 5 additions & 3 deletions scripts/update-endpoints/code.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,13 @@
* trigger notifications. So instead we automatically generate a file that
* only contains these paths when @octokit/openapi has a new release.
*/
const { writeFileSync } = require("fs");
import { writeFileSync, readFileSync } from "node:fs";

const prettier = require("prettier");
import prettier from "prettier";

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

for (const endpoint of ENDPOINTS) {
Expand Down
Loading