Skip to content

Commit bf0592e

Browse files
committed
fix(data-schemas): add local type declaration for DailyRotateFile transport
The `winston-daily-rotate-file` package ships a module augmentation for `winston/lib/winston/transports`, but it fails when winston and winston-daily-rotate-file resolve from different node_modules trees (which happens in this monorepo due to npm hoisting). Add a local `.d.ts` declaration that augments the same module path from within data-schemas' compilation unit, so `tsc --noEmit` passes while keeping the original runtime pattern (`new winston.transports.DailyRotateFile`).
1 parent 5345010 commit bf0592e

File tree

5 files changed

+41
-9
lines changed

5 files changed

+41
-9
lines changed

package-lock.json

Lines changed: 1 addition & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/data-schemas/package.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,8 +61,7 @@
6161
"rollup-plugin-peer-deps-external": "^2.2.4",
6262
"rollup-plugin-typescript2": "^0.35.0",
6363
"ts-node": "^10.9.2",
64-
"typescript": "^5.0.4",
65-
"winston-daily-rotate-file": "^5.0.0"
64+
"typescript": "^5.0.4"
6665
},
6766
"peerDependencies": {
6867
"jsonwebtoken": "^9.0.2",

packages/data-schemas/src/config/meiliLogger.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import winston from 'winston';
2-
import DailyRotateFile from 'winston-daily-rotate-file';
2+
import 'winston-daily-rotate-file';
33
import { getLogDirectory } from './utils';
44

55
const logDir = getLogDirectory();
@@ -42,7 +42,7 @@ const fileFormat = winston.format.combine(
4242

4343
const logLevel = useDebugLogging ? 'debug' : 'error';
4444
const transports: winston.transport[] = [
45-
new DailyRotateFile({
45+
new winston.transports.DailyRotateFile({
4646
level: logLevel,
4747
filename: `${logDir}/meiliSync-%DATE%.log`,
4848
datePattern: 'YYYY-MM-DD',

packages/data-schemas/src/config/winston.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import winston from 'winston';
2-
import DailyRotateFile from 'winston-daily-rotate-file';
2+
import 'winston-daily-rotate-file';
33
import { redactFormat, redactMessage, debugTraverse, jsonTruncateFormat } from './parsers';
44
import { getLogDirectory } from './utils';
55

@@ -44,7 +44,7 @@ const fileFormat = winston.format.combine(
4444
);
4545

4646
const transports: winston.transport[] = [
47-
new DailyRotateFile({
47+
new winston.transports.DailyRotateFile({
4848
level: 'error',
4949
filename: `${logDir}/error-%DATE%.log`,
5050
datePattern: 'YYYY-MM-DD',
@@ -57,7 +57,7 @@ const transports: winston.transport[] = [
5757

5858
if (useDebugLogging) {
5959
transports.push(
60-
new DailyRotateFile({
60+
new winston.transports.DailyRotateFile({
6161
level: 'debug',
6262
filename: `${logDir}/debug-%DATE%.log`,
6363
datePattern: 'YYYY-MM-DD',
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
import type TransportStream from 'winston-transport';
2+
3+
/**
4+
* Module augmentation for winston's transports namespace.
5+
*
6+
* `winston-daily-rotate-file` ships its own augmentation targeting
7+
* `'winston/lib/winston/transports'`, but it fails when winston and
8+
* winston-daily-rotate-file resolve from different node_modules trees
9+
* (which happens in this monorepo due to npm hoisting). This local
10+
* declaration bridges the gap so `tsc --noEmit` passes.
11+
*/
12+
declare module 'winston/lib/winston/transports' {
13+
interface Transports {
14+
DailyRotateFile: new (
15+
opts?: {
16+
level?: string;
17+
filename?: string;
18+
datePattern?: string;
19+
zippedArchive?: boolean;
20+
maxSize?: string | number;
21+
maxFiles?: string | number;
22+
dirname?: string;
23+
stream?: NodeJS.WritableStream;
24+
frequency?: string;
25+
utc?: boolean;
26+
extension?: string;
27+
createSymlink?: boolean;
28+
symlinkName?: string;
29+
auditFile?: string;
30+
format?: import('logform').Format;
31+
} & TransportStream.TransportStreamOptions,
32+
) => TransportStream;
33+
}
34+
}

0 commit comments

Comments
 (0)