Skip to content

Commit 1774975

Browse files
authored
chore: esm only (#338)
BREAKING CHANGE: This module is now ESM only.
1 parent 5c78706 commit 1774975

9 files changed

+48
-49
lines changed

bin/cli.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
"use strict";
22

3-
const pump = require("pump");
4-
const split = require("split2");
3+
import pump from "pump";
4+
import split from "split2";
55

6-
const { getTransformStream } = require("..");
6+
import { getTransformStream } from "../index.js";
77

88
const options = {
99
logFormat: process.env.LOG_FORMAT,

example.js

+1-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
1-
"use strict";
2-
3-
var pino = require("pino")({
1+
const pino = (await import("pino")).default({
42
name: "probot",
53
});
64

index.d.ts

+9-14
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,15 @@
11
import { Transform } from "node:stream";
22

3-
type getTransformStream = (options?: getTransformStream.Options) => Transform;
3+
declare function getTransformStream(options?: Options): Transform;
44

5-
declare namespace getTransformStream {
6-
export type LogLevel = "trace" | "debug" | "info" | "warn" | "error" | "fatal";
5+
export type LogLevel = "trace" | "debug" | "info" | "warn" | "error" | "fatal";
76

8-
export type Options = {
9-
logFormat?: "json" | "pretty";
10-
logLevelInString?: boolean;
11-
sentryDsn?: string;
12-
};
7+
export type Options = {
8+
logFormat?: "json" | "pretty";
9+
logLevelInString?: boolean;
10+
sentryDsn?: string;
11+
};
1312

14-
export const getTransformStream: getTransformStream
15-
export { getTransformStream as default }
13+
export {
14+
getTransformStream
1615
}
17-
18-
declare function getTransformStream(...params: Parameters<getTransformStream>): ReturnType<getTransformStream>
19-
20-
export = getTransformStream

index.js

+4-10
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
1-
"use strict";
1+
import { Transform } from "node:stream";
22

3-
const { Transform } = require("node:stream");
4-
5-
const { prettyFactory } = require("pino-pretty");
6-
const { init, withScope, captureException } = require("@sentry/node");
3+
import { prettyFactory } from "pino-pretty";
4+
import { init, withScope, captureException } from "@sentry/node";
75

86
const LEVEL_MAP = {
97
10: "trace",
@@ -40,7 +38,7 @@ const pinoErrorProps = [
4038
* @returns Transform
4139
* @see https://getpino.io/#/docs/transports
4240
*/
43-
function getTransformStream(options = {}) {
41+
export function getTransformStream(options = {}) {
4442
const formattingEnabled = options.logFormat !== "json";
4543

4644
const levelAsString = options.logLevelInString;
@@ -161,7 +159,3 @@ function toSentryError(data) {
161159
error.stack = data.stack;
162160
return error;
163161
}
164-
165-
module.exports = getTransformStream;
166-
module.exports.default = getTransformStream;
167-
module.exports.getTransformStream = getTransformStream;

package.json

+1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
"pino-probot": "./bin/cli.js"
1010
},
1111
"description": "formats pino logs and sends errors to Sentry",
12+
"type": "module",
1213
"main": "index.js",
1314
"types": "index.d.ts",
1415
"scripts": {

test/cli.test.js

+10-4
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,16 @@
11
"use strict";
22

3-
const { join: pathJoin } = require("node:path");
4-
const { spawn } = require("node:child_process");
5-
const { test } = require("tap");
3+
import {
4+
dirname as pathDirname,
5+
join as pathJoin,
6+
resolve as pathResolve,
7+
} from "node:path";
8+
import { spawn } from "node:child_process";
9+
import { test } from "tap";
10+
import { fileURLToPath } from "node:url";
611

7-
const cliPath = require.resolve(pathJoin(__dirname, "..", "bin", "cli.js"));
12+
const __dirname = pathDirname(fileURLToPath(import.meta.url));
13+
const cliPath = pathResolve(pathJoin(__dirname, "..", "bin", "cli.js"));
814
const nodeBinaryPath = process.argv[0];
915

1016
const logLine =

test/index.test.js

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
"use strict";
22

3-
const { Writable: WritableStream } = require("stream");
3+
import { Writable as WritableStream } from "stream";
44

5-
const { test } = require("tap");
6-
const { pino } = require("pino");
7-
const { getTransformStream } = require("..");
5+
import { test } from "tap";
6+
import { pino } from "pino";
7+
import { getTransformStream } from "../index.js";
88

99
test("API", (t) => {
1010
let env = Object.assign({}, process.env);

test/sentry.cli.test.js

+12-7
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,19 @@
11
"use strict";
22

3-
const { join: pathJoin } = require("node:path");
4-
const { spawn } = require("node:child_process");
5-
const { createServer } = require("node:http");
6-
const { test } = require("tap");
7-
const { once } = require("node:events");
3+
import {
4+
dirname as pathDirname,
5+
join as pathJoin,
6+
resolve as pathResolve,
7+
} from "node:path";
8+
import { spawn } from "node:child_process";
9+
import { createServer } from "node:http";
10+
import { test } from "tap";
11+
import { once } from "node:events";
12+
import { fileURLToPath } from "node:url";
813

914
const SENTRY_DSN = "http://[email protected]/1234";
10-
11-
const cliPath = require.resolve(pathJoin(__dirname, "..", "bin", "cli.js"));
15+
const __dirname = pathDirname(fileURLToPath(import.meta.url));
16+
const cliPath = pathResolve(pathJoin(__dirname, "..", "bin", "cli.js"));
1217
const nodeBinaryPath = process.argv[0];
1318

1419
const errorLine =

test/sentry.runtime.test.js

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
"use strict";
22

3-
const { withScope } = require("@sentry/node");
3+
import { withScope } from "@sentry/node";
44

5-
const { test } = require("tap");
6-
const { pino } = require("pino");
7-
const { getTransformStream } = require("..");
5+
import { test } from "tap";
6+
import { pino } from "pino";
7+
import { getTransformStream } from "../index.js";
88

99
test("API", (t) => {
1010
t.plan(1);

0 commit comments

Comments
 (0)