Skip to content

Commit

Permalink
fix: hotfixes importing issue w/ esm and pino
Browse files Browse the repository at this point in the history
  • Loading branch information
Figedi committed Sep 10, 2023
1 parent 19900b1 commit b8d579f
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 8 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,8 @@
"@figedi/metering": "^1.3.1",
"@figedi/typecop": "^1.3.1",
"@types/lodash-es": "^4.17.9",
"@types/semver": "^7.5.1",
"@types/minimist": "^1.2.2",
"@types/semver": "^7.5.1",
"axios": "^1.4.0",
"debug": "^4.3.4",
"envalid": "^7.3.1",
Expand Down
3 changes: 1 addition & 2 deletions src/app/types/app.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import type { Logger as PinoLogger } from "pino";
import type { Container } from "inversify";
import type { ValidatorSpec, Spec } from "envalid";
import type { ParsedArgs } from "minimist";
Expand Down Expand Up @@ -236,7 +235,7 @@ export type AppConfig = {
export interface BaseRegisterFnArgs<Config> {
config: UnpackTransformConfigTypes<Config>;
app: AppConfig;
logger: PinoLogger;
logger: Logger;
}
export interface DynamicConfigFnArgs<Config> extends BaseRegisterFnArgs<Config> {
awaited: DynamicPromiseTransformFn;
Expand Down
17 changes: 12 additions & 5 deletions src/app/utils/logger.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
import { pino, type Logger as PinoLogger, type LoggerOptions as PinoLoggerOptions } from "pino";
// eslint-disable-next-line import/no-named-default
import { isFunction } from "lodash-es";
import type { Logger as PinoLogger, LoggerOptions as PinoLoggerOptions } from "pino";
import * as pino from "pino";

export interface LoggerBaseProperties {
service: string;
Expand All @@ -10,9 +13,9 @@ export interface LoggerOptions<BaseProperties extends LoggerBaseProperties> {
}

export type Logger = PinoLogger;

export const createLogger = <T extends LoggerBaseProperties>(opts: LoggerOptions<T>): PinoLogger =>
pino({
export const createLogger = <T extends LoggerBaseProperties>(opts: LoggerOptions<T>): PinoLogger => {
const pinoFn = (isFunction(pino) ? pino : pino.pino ?? pino.default) as any;
return pinoFn({
level: opts.level,
redact: {
paths: ["*.password", "password", "*.token", "token", "*.secret", "secret"],
Expand All @@ -21,5 +24,9 @@ export const createLogger = <T extends LoggerBaseProperties>(opts: LoggerOptions
base: opts.base,
timestamp: () => `,"timestamp":"${new Date().toISOString()}"`,
});
};

export const createStubbedLogger = (): PinoLogger => pino({ enabled: false });
export const createStubbedLogger = (): PinoLogger => {
const pinoFn = (isFunction(pino) ? pino : pino.pino ?? pino.default) as any;
return pinoFn({ enabled: false });
};
1 change: 1 addition & 0 deletions tsup.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ export default defineConfig({
target: "es2022",

outDir: "dist",

sourcemap: false,
dts: true,
shims: false,
Expand Down

0 comments on commit b8d579f

Please sign in to comment.