Enhance TypeScript configuration and logging setup
- Added "rootDir" to tsconfig.build.json for improved build structure. - Implemented dynamic import for fs/promises in nest-logger.config.ts to ensure compatibility in different environments and handle directory creation more robustly.
This commit is contained in:
parent
67c763016d
commit
807d37a729
@ -5,6 +5,7 @@
|
|||||||
"incremental": true,
|
"incremental": true,
|
||||||
"tsBuildInfoFile": "./tsconfig.build.tsbuildinfo",
|
"tsBuildInfoFile": "./tsconfig.build.tsbuildinfo",
|
||||||
"outDir": "./dist",
|
"outDir": "./dist",
|
||||||
|
"rootDir": "./src",
|
||||||
"sourceMap": true,
|
"sourceMap": true,
|
||||||
"declaration": false,
|
"declaration": false,
|
||||||
"removeComments": true,
|
"removeComments": true,
|
||||||
|
|||||||
@ -1,7 +1,19 @@
|
|||||||
// Lightweight, framework-agnostic factory that returns an object compatible
|
// Lightweight, framework-agnostic factory that returns an object compatible
|
||||||
// with nestjs-pino's LoggerModule.forRoot({ pinoHttp: {...} }) shape without importing types.
|
// with nestjs-pino's LoggerModule.forRoot({ pinoHttp: {...} }) shape without importing types.
|
||||||
import { join } from "path";
|
import { join } from "path";
|
||||||
import { mkdir } from "fs/promises";
|
|
||||||
|
// Dynamic import for fs/promises - will be resolved at runtime
|
||||||
|
async function getMkdir() {
|
||||||
|
if (typeof window !== 'undefined' || typeof process === 'undefined') {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
const fs = await import("fs/promises");
|
||||||
|
return fs.mkdir;
|
||||||
|
} catch {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
export async function createNestPinoConfig(configService: {
|
export async function createNestPinoConfig(configService: {
|
||||||
get<T = string>(key: string, defaultValue?: T): T;
|
get<T = string>(key: string, defaultValue?: T): T;
|
||||||
@ -11,10 +23,13 @@ export async function createNestPinoConfig(configService: {
|
|||||||
const appName = configService.get<string>("APP_NAME", "customer-portal-bff");
|
const appName = configService.get<string>("APP_NAME", "customer-portal-bff");
|
||||||
|
|
||||||
if (nodeEnv === "production") {
|
if (nodeEnv === "production") {
|
||||||
try {
|
const mkdir = await getMkdir();
|
||||||
await mkdir("logs", { recursive: true });
|
if (mkdir) {
|
||||||
} catch {
|
try {
|
||||||
// ignore
|
await mkdir("logs", { recursive: true });
|
||||||
|
} catch {
|
||||||
|
// ignore
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user