Skip to content

Commit

Permalink
feat: package is now ESM (#675)
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 0404bc6 commit 4986fb0
Show file tree
Hide file tree
Showing 15 changed files with 123 additions and 133 deletions.
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/fetch-mock@9.11.0-pull-request-644.1",
"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

0 comments on commit 4986fb0

Please sign in to comment.