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

chore: esm only #338

Merged
merged 5 commits into from
Jan 31, 2025
Merged
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
6 changes: 3 additions & 3 deletions bin/cli.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
"use strict";

const pump = require("pump");
const split = require("split2");
import pump from "pump";
import split from "split2";

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

const options = {
logFormat: process.env.LOG_FORMAT,
4 changes: 1 addition & 3 deletions example.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
"use strict";

var pino = require("pino")({
const pino = (await import("pino")).default({
name: "probot",
});

23 changes: 9 additions & 14 deletions index.d.ts
Original file line number Diff line number Diff line change
@@ -1,20 +1,15 @@
import { Transform } from "node:stream";

type getTransformStream = (options?: getTransformStream.Options) => Transform;
declare function getTransformStream(options?: Options): Transform;

declare namespace getTransformStream {
export type LogLevel = "trace" | "debug" | "info" | "warn" | "error" | "fatal";
export type LogLevel = "trace" | "debug" | "info" | "warn" | "error" | "fatal";

export type Options = {
logFormat?: "json" | "pretty";
logLevelInString?: boolean;
sentryDsn?: string;
};
export type Options = {
logFormat?: "json" | "pretty";
logLevelInString?: boolean;
sentryDsn?: string;
};

export const getTransformStream: getTransformStream
export { getTransformStream as default }
export {
getTransformStream
}

declare function getTransformStream(...params: Parameters<getTransformStream>): ReturnType<getTransformStream>

export = getTransformStream
14 changes: 4 additions & 10 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
"use strict";
import { Transform } from "node:stream";

const { Transform } = require("node:stream");

const { prettyFactory } = require("pino-pretty");
const { init, withScope, captureException } = require("@sentry/node");
import { prettyFactory } from "pino-pretty";
import { init, withScope, captureException } from "@sentry/node";

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

const levelAsString = options.logLevelInString;
@@ -161,7 +159,3 @@ function toSentryError(data) {
error.stack = data.stack;
return error;
}

module.exports = getTransformStream;
module.exports.default = getTransformStream;
module.exports.getTransformStream = getTransformStream;
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -9,6 +9,7 @@
"pino-probot": "./bin/cli.js"
},
"description": "formats pino logs and sends errors to Sentry",
"type": "module",
"main": "index.js",
"types": "index.d.ts",
"scripts": {
14 changes: 10 additions & 4 deletions test/cli.test.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,16 @@
"use strict";

const { join: pathJoin } = require("node:path");
const { spawn } = require("node:child_process");
const { test } = require("tap");
import {
dirname as pathDirname,
join as pathJoin,
resolve as pathResolve,
} from "node:path";
import { spawn } from "node:child_process";
import { test } from "tap";
import { fileURLToPath } from "node:url";

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

const logLine =
8 changes: 4 additions & 4 deletions test/index.test.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
"use strict";

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

const { test } = require("tap");
const { pino } = require("pino");
const { getTransformStream } = require("..");
import { test } from "tap";
import { pino } from "pino";
import { getTransformStream } from "../index.js";

test("API", (t) => {
let env = Object.assign({}, process.env);
19 changes: 12 additions & 7 deletions test/sentry.cli.test.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,19 @@
"use strict";

const { join: pathJoin } = require("node:path");
const { spawn } = require("node:child_process");
const { createServer } = require("node:http");
const { test } = require("tap");
const { once } = require("node:events");
import {
dirname as pathDirname,
join as pathJoin,
resolve as pathResolve,
} from "node:path";
import { spawn } from "node:child_process";
import { createServer } from "node:http";
import { test } from "tap";
import { once } from "node:events";
import { fileURLToPath } from "node:url";

const SENTRY_DSN = "http://[email protected]/1234";

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

const errorLine =
8 changes: 4 additions & 4 deletions test/sentry.runtime.test.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
"use strict";

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

const { test } = require("tap");
const { pino } = require("pino");
const { getTransformStream } = require("..");
import { test } from "tap";
import { pino } from "pino";
import { getTransformStream } from "../index.js";

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