Skip to content

Commit

Permalink
feat: package is now ESM (#372)
Browse files Browse the repository at this point in the history
* feat: package is now ESM

BREAKING CHANGE: package is now ESM

* docs(README): update for ESM
  • Loading branch information
wolfy1339 committed Mar 5, 2024
1 parent cfeb8dd commit ad8df92
Show file tree
Hide file tree
Showing 8 changed files with 86 additions and 116 deletions.
7 changes: 4 additions & 3 deletions README.md
Expand Up @@ -30,8 +30,8 @@ Node
Install with `npm install @octokit/core @octokit/plugin-request-log`. Optionally replace `@octokit/core` with a core-compatible module

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

</td></tr>
Expand All @@ -52,8 +52,9 @@ octokit.request("GET /oops");
In order to log all request options, the `log.debug` option needs to be set. We recommend the [console-log-level](https://github.com/watson/console-log-level) package for a configurable log level

```js
import consoleLogLevel from "console-log-level";
const octokit = new MyOctokit({
log: require("console-log-level")({
log: consoleLogLevel({
auth: "secret123",
level: "info",
}),
Expand Down
133 changes: 57 additions & 76 deletions package-lock.json

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

18 changes: 13 additions & 5 deletions package.json
Expand Up @@ -2,12 +2,13 @@
"name": "@octokit/plugin-request-log",
"version": "0.0.0-development",
"description": "Log all requests and request errors",
"type": "module",
"scripts": {
"build": "node scripts/build.mjs && tsc -p tsconfig.json",
"lint": "prettier --check '{src,test,scripts}/**/*' README.md package.json",
"lint:fix": "prettier --write '{src,test,scripts}/**/*' 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-request-log.js",
"keywords": [
Expand All @@ -19,11 +20,11 @@
"author": "Gregor Martynus (https://twitter.com/gr2m)",
"license": "MIT",
"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.2",
"@types/jest": "^29.0.0",
"@types/node": "^20.0.0",
Expand All @@ -37,11 +38,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 @@ -52,6 +57,9 @@
"functions": 100,
"lines": 100
}
},
"moduleNameMapper": {
"^(.+)\\.jsx?$": "$1"
}
},
"release": {
Expand Down
34 changes: 7 additions & 27 deletions scripts/build.mjs
Expand Up @@ -33,30 +33,6 @@ async function main() {
await rm(typeFile);
}

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,
}),
]);

// Copy the README, LICENSE to the pkg folder
await copyFile("LICENSE", "pkg/LICENSE");
await copyFile("README.md", "pkg/README.md");
Expand All @@ -74,10 +50,14 @@ async function main() {
{
...pkg,
files: ["dist-*/**", "bin/**"],
main: "dist-node/index.js",
browser: "dist-web/index.js",
main: "dist-src/index.js",
types: "dist-types/index.d.ts",
module: "dist-src/index.js",
exports: {
".": {
types: "./dist-types/index.d.ts",
import: "./dist-src/index.js",
},
},
sideEffects: false,
},
null,
Expand Down
2 changes: 1 addition & 1 deletion src/index.ts
@@ -1,5 +1,5 @@
import type { Octokit } from "@octokit/core";
import { VERSION } from "./version";
import { VERSION } from "./version.js";

/**
* @param octokit Octokit instance
Expand Down
3 changes: 2 additions & 1 deletion test/request-log.test.ts
@@ -1,7 +1,8 @@
import { Octokit } from "@octokit/core";
import fetchMock from "fetch-mock";
import { jest } from "@jest/globals";

import { requestLog } from "../src";
import { requestLog } from "../src/index.js";

describe("logging", () => {
it("logs sucessful 'GET /'", async () => {
Expand Down
2 changes: 1 addition & 1 deletion test/smoke.test.ts
@@ -1,4 +1,4 @@
import { requestLog } from "../src";
import { requestLog } from "../src/index.js";

describe("Smoke test", () => {
it("is a function", () => {
Expand Down

0 comments on commit ad8df92

Please sign in to comment.