Skip to content

Commit ad8df92

Browse files
authored
feat: package is now ESM (#372)
* feat: package is now ESM BREAKING CHANGE: package is now ESM * docs(README): update for ESM
1 parent cfeb8dd commit ad8df92

File tree

8 files changed

+86
-116
lines changed

8 files changed

+86
-116
lines changed

README.md

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,8 @@ Node
3030
Install with `npm install @octokit/core @octokit/plugin-request-log`. Optionally replace `@octokit/core` with a core-compatible module
3131

3232
```js
33-
const { Octokit } = require("@octokit/core");
34-
const { requestLog } = require("@octokit/plugin-request-log");
33+
import { Octokit } from "@octokit/core";
34+
import { requestLog } from "@octokit/plugin-request-log";
3535
```
3636

3737
</td></tr>
@@ -52,8 +52,9 @@ octokit.request("GET /oops");
5252
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
5353

5454
```js
55+
import consoleLogLevel from "console-log-level";
5556
const octokit = new MyOctokit({
56-
log: require("console-log-level")({
57+
log: consoleLogLevel({
5758
auth: "secret123",
5859
level: "info",
5960
}),

package-lock.json

Lines changed: 57 additions & 76 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,13 @@
22
"name": "@octokit/plugin-request-log",
33
"version": "0.0.0-development",
44
"description": "Log all requests and request errors",
5+
"type": "module",
56
"scripts": {
67
"build": "node scripts/build.mjs && tsc -p tsconfig.json",
78
"lint": "prettier --check '{src,test,scripts}/**/*' README.md package.json",
89
"lint:fix": "prettier --write '{src,test,scripts}/**/*' README.md package.json",
910
"pretest": "npm run -s lint",
10-
"test": "jest --coverage"
11+
"test": "NODE_OPTIONS=\"$NODE_OPTIONS --experimental-vm-modules\" npx jest --coverage"
1112
},
1213
"repository": "github:octokit/plugin-request-log.js",
1314
"keywords": [
@@ -19,11 +20,11 @@
1920
"author": "Gregor Martynus (https://twitter.com/gr2m)",
2021
"license": "MIT",
2122
"peerDependencies": {
22-
"@octokit/core": "5"
23+
"@octokit/core": ">=6"
2324
},
2425
"devDependencies": {
25-
"@octokit/core": "^5.0.0",
26-
"@octokit/tsconfig": "^2.0.0",
26+
"@octokit/core": "^6.0.0",
27+
"@octokit/tsconfig": "^3.0.0",
2728
"@types/fetch-mock": "^7.3.2",
2829
"@types/jest": "^29.0.0",
2930
"@types/node": "^20.0.0",
@@ -37,11 +38,15 @@
3738
"typescript": "^5.0.0"
3839
},
3940
"jest": {
41+
"extensionsToTreatAsEsm": [
42+
".ts"
43+
],
4044
"transform": {
4145
"^.+\\.(ts|tsx)$": [
4246
"ts-jest",
4347
{
44-
"tsconfig": "test/tsconfig.test.json"
48+
"tsconfig": "test/tsconfig.test.json",
49+
"useESM": true
4550
}
4651
]
4752
},
@@ -52,6 +57,9 @@
5257
"functions": 100,
5358
"lines": 100
5459
}
60+
},
61+
"moduleNameMapper": {
62+
"^(.+)\\.jsx?$": "$1"
5563
}
5664
},
5765
"release": {

scripts/build.mjs

Lines changed: 7 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -33,30 +33,6 @@ async function main() {
3333
await rm(typeFile);
3434
}
3535

36-
const entryPoints = ["./pkg/dist-src/index.js"];
37-
38-
await Promise.all([
39-
// Build the a CJS Node.js bundle
40-
esbuild.build({
41-
entryPoints,
42-
outdir: "pkg/dist-node",
43-
bundle: true,
44-
platform: "node",
45-
target: "node18",
46-
format: "cjs",
47-
...sharedOptions,
48-
}),
49-
// Build an ESM browser bundle
50-
esbuild.build({
51-
entryPoints,
52-
outdir: "pkg/dist-web",
53-
bundle: true,
54-
platform: "browser",
55-
format: "esm",
56-
...sharedOptions,
57-
}),
58-
]);
59-
6036
// Copy the README, LICENSE to the pkg folder
6137
await copyFile("LICENSE", "pkg/LICENSE");
6238
await copyFile("README.md", "pkg/README.md");
@@ -74,10 +50,14 @@ async function main() {
7450
{
7551
...pkg,
7652
files: ["dist-*/**", "bin/**"],
77-
main: "dist-node/index.js",
78-
browser: "dist-web/index.js",
53+
main: "dist-src/index.js",
7954
types: "dist-types/index.d.ts",
80-
module: "dist-src/index.js",
55+
exports: {
56+
".": {
57+
types: "./dist-types/index.d.ts",
58+
import: "./dist-src/index.js",
59+
},
60+
},
8161
sideEffects: false,
8262
},
8363
null,

src/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import type { Octokit } from "@octokit/core";
2-
import { VERSION } from "./version";
2+
import { VERSION } from "./version.js";
33

44
/**
55
* @param octokit Octokit instance

test/request-log.test.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
import { Octokit } from "@octokit/core";
22
import fetchMock from "fetch-mock";
3+
import { jest } from "@jest/globals";
34

4-
import { requestLog } from "../src";
5+
import { requestLog } from "../src/index.js";
56

67
describe("logging", () => {
78
it("logs sucessful 'GET /'", async () => {

test/smoke.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { requestLog } from "../src";
1+
import { requestLog } from "../src/index.js";
22

33
describe("Smoke test", () => {
44
it("is a function", () => {

0 commit comments

Comments
 (0)