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
Show file tree
Hide file tree
Changes from 1 commit
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
Next Next commit
chore: esm only
  • Loading branch information
Uzlopak authored and wolfy1339 committed Jan 30, 2025
commit 4e5a2ff4e21afa8236284529d2bedde5e813d6f9
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,
Expand Down
25 changes: 10 additions & 15 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;
type 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 }
}

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

export = getTransformStream
export {
getTransformStream
}
12 changes: 4 additions & 8 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
"use strict";

const { Transform } = require("node:stream");
import { Transform } from "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",
Expand Down Expand Up @@ -40,7 +40,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;
Expand Down Expand Up @@ -161,7 +161,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
Expand Up @@ -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": {
Expand Down
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 =
Expand Down
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);
Expand Down
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://username@example.com/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 =
Expand Down
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);
Expand Down