Skip to content
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

feat: package is now ESM #372

Merged
merged 2 commits into from
Mar 5, 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
7 changes: 4 additions & 3 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-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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { requestLog } from "../src";
import { requestLog } from "../src/index.js";

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