From 8e7be7ab32fa65d2e4bbed7a7a6730ca8dcbfe98 Mon Sep 17 00:00:00 2001 From: Harjun751 Date: Mon, 9 Mar 2026 09:50:22 +0800 Subject: [PATCH 1/5] Upgrade winton to v3 Winston is on v2. v2 doesn't have proper ESM support, resulting in a workaround being required to import it. Upgrade winston package dependency so that normal `import` syntax may be used. --- package-lock.json | 305 +++++++++++++++++------ packages/cli/package.json | 4 +- packages/cli/src/util/logger-wrapper.cjs | 13 - packages/cli/src/util/logger.ts | 15 +- 4 files changed, 235 insertions(+), 102 deletions(-) delete mode 100644 packages/cli/src/util/logger-wrapper.cjs diff --git a/package-lock.json b/package-lock.json index 7e016c8985..d7c77c24e3 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1766,7 +1766,9 @@ "license": "MIT" }, "node_modules/@colors/colors": { - "version": "1.5.0", + "version": "1.6.0", + "resolved": "https://registry.npmjs.org/@colors/colors/-/colors-1.6.0.tgz", + "integrity": "sha512-Ir+AOibqzrIsL6ajt3Rz3LskB7OiMVHqltZmspbW/TJuTVuyOMirVqAkjfY6JISiLHgyNqicAC8AyHHGzNd/dA==", "license": "MIT", "engines": { "node": ">=0.1.90" @@ -1854,6 +1856,17 @@ "postcss-selector-parser": "^6.0.13" } }, + "node_modules/@dabh/diagnostics": { + "version": "2.0.8", + "resolved": "https://registry.npmjs.org/@dabh/diagnostics/-/diagnostics-2.0.8.tgz", + "integrity": "sha512-R4MSXTVnuMzGD7bzHdW2ZhhdPC/igELENcq5IjEverBvq5hn1SXCWcsi6eSsdWP0/Ur+SItRRjAktmdoX/8R/Q==", + "license": "MIT", + "dependencies": { + "@so-ric/colorspace": "^1.1.6", + "enabled": "2.0.x", + "kuler": "^2.0.0" + } + }, "node_modules/@discoveryjs/json-ext": { "version": "0.6.3", "dev": true, @@ -4769,6 +4782,16 @@ "@sinonjs/commons": "^3.0.0" } }, + "node_modules/@so-ric/colorspace": { + "version": "1.1.6", + "resolved": "https://registry.npmjs.org/@so-ric/colorspace/-/colorspace-1.1.6.tgz", + "integrity": "sha512-/KiKkpHNOBgkFJwu9sh48LkHSMYGyuTcSFK/qMBdnOAlrRJzRSXAOFB5qwzaVQuDl8wAvHVMkaASQDReTahxuw==", + "license": "MIT", + "dependencies": { + "color": "^5.0.2", + "text-hex": "1.0.x" + } + }, "node_modules/@stylistic/stylelint-plugin": { "version": "2.1.0", "dev": true, @@ -7503,6 +7526,19 @@ "node": ">=0.10.0" } }, + "node_modules/color": { + "version": "5.0.3", + "resolved": "https://registry.npmjs.org/color/-/color-5.0.3.tgz", + "integrity": "sha512-ezmVcLR3xAVp8kYOm4GS45ZLLgIE6SPAFoduLr6hTDajwb3KZ2F46gulK3XpcwRFb5KKGCSezCBAY4Dw4HsyXA==", + "license": "MIT", + "dependencies": { + "color-convert": "^3.1.3", + "color-string": "^2.1.3" + }, + "engines": { + "node": ">=18" + } + }, "node_modules/color-convert": { "version": "2.0.1", "license": "MIT", @@ -7517,6 +7553,27 @@ "version": "1.1.4", "license": "MIT" }, + "node_modules/color-string": { + "version": "2.1.4", + "resolved": "https://registry.npmjs.org/color-string/-/color-string-2.1.4.tgz", + "integrity": "sha512-Bb6Cq8oq0IjDOe8wJmi4JeNn763Xs9cfrBcaylK1tPypWzyoy2G3l90v9k64kjphl/ZJjPIShFztenRomi8WTg==", + "license": "MIT", + "dependencies": { + "color-name": "^2.0.0" + }, + "engines": { + "node": ">=18" + } + }, + "node_modules/color-string/node_modules/color-name": { + "version": "2.1.0", + "resolved": "https://registry.npmjs.org/color-name/-/color-name-2.1.0.tgz", + "integrity": "sha512-1bPaDNFm0axzE4MEAzKPuqKWeRaT43U/hyxKPBdqTfmPF+d6n7FSoTFxLVULUJOmiLp01KjhIPPH+HrXZJN4Rg==", + "license": "MIT", + "engines": { + "node": ">=12.20" + } + }, "node_modules/color-support": { "version": "1.1.3", "dev": true, @@ -7525,6 +7582,27 @@ "color-support": "bin.js" } }, + "node_modules/color/node_modules/color-convert": { + "version": "3.1.3", + "resolved": "https://registry.npmjs.org/color-convert/-/color-convert-3.1.3.tgz", + "integrity": "sha512-fasDH2ont2GqF5HpyO4w0+BcewlhHEZOFn9c1ckZdHpJ56Qb7MHhH/IcJZbBGgvdtwdwNbLvxiBEdg336iA9Sg==", + "license": "MIT", + "dependencies": { + "color-name": "^2.0.0" + }, + "engines": { + "node": ">=14.6" + } + }, + "node_modules/color/node_modules/color-name": { + "version": "2.1.0", + "resolved": "https://registry.npmjs.org/color-name/-/color-name-2.1.0.tgz", + "integrity": "sha512-1bPaDNFm0axzE4MEAzKPuqKWeRaT43U/hyxKPBdqTfmPF+d6n7FSoTFxLVULUJOmiLp01KjhIPPH+HrXZJN4Rg==", + "license": "MIT", + "engines": { + "node": ">=12.20" + } + }, "node_modules/colord": { "version": "2.9.3", "dev": true, @@ -8945,6 +9023,12 @@ "node": ">= 4" } }, + "node_modules/enabled": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/enabled/-/enabled-2.0.0.tgz", + "integrity": "sha512-AKrN98kuwOzMIdAizXGI86UFBoo26CL21UM763y1h/GMSJ4/OHU9k2YlsmBpyScFo/wbLzWQJBMCW4+IO3/+OQ==", + "license": "MIT" + }, "node_modules/encodeurl": { "version": "1.0.2", "license": "MIT", @@ -10040,10 +10124,6 @@ "dev": true, "license": "MIT" }, - "node_modules/fast-safe-stringify": { - "version": "2.1.1", - "license": "MIT" - }, "node_modules/fast-uri": { "version": "3.0.6", "dev": true, @@ -10102,10 +10182,6 @@ "bser": "2.1.1" } }, - "node_modules/fecha": { - "version": "2.3.3", - "license": "MIT" - }, "node_modules/figlet": { "version": "1.10.0", "license": "MIT", @@ -10195,13 +10271,6 @@ "url": "https://opencollective.com/webpack" } }, - "node_modules/file-stream-rotator": { - "version": "0.4.1", - "license": "MIT", - "dependencies": { - "moment": "^2.11.2" - } - }, "node_modules/file-uri-to-path": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/file-uri-to-path/-/file-uri-to-path-1.0.0.tgz", @@ -10346,6 +10415,12 @@ "dev": true, "license": "ISC" }, + "node_modules/fn.name": { + "version": "1.1.0", + "resolved": "https://registry.npmjs.org/fn.name/-/fn.name-1.1.0.tgz", + "integrity": "sha512-GRnmB5gPyJpAhTQdSZTSp9uaPSvl09KoYcMQtsB9rQoOmzs9dH6ffeccH+Z+cv6P68Hu5bC6JjRh4Ah/mHSNRw==", + "license": "MIT" + }, "node_modules/focus-trap": { "version": "7.8.0", "dev": true, @@ -11931,7 +12006,6 @@ }, "node_modules/is-stream": { "version": "2.0.1", - "dev": true, "license": "MIT", "engines": { "node": ">=8" @@ -13441,6 +13515,12 @@ "dev": true, "license": "MIT" }, + "node_modules/kuler": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/kuler/-/kuler-2.0.0.tgz", + "integrity": "sha512-Xq9nH7KlWZmXAtodXDDRE7vs6DU1gTU8zYDHDiWLSip45Egwq3plLHzPn27NgvzL2r1LMPC1vdqh98sQxtqj4A==", + "license": "MIT" + }, "node_modules/lerna": { "version": "8.2.4", "dev": true, @@ -14485,17 +14565,6 @@ "url": "https://github.com/sponsors/sindresorhus" } }, - "node_modules/logform": { - "version": "1.10.0", - "license": "MIT", - "dependencies": { - "colors": "^1.2.1", - "fast-safe-stringify": "^2.0.4", - "fecha": "^2.3.3", - "ms": "^2.1.1", - "triple-beam": "^1.2.0" - } - }, "node_modules/lru-cache": { "version": "5.1.1", "dev": true, @@ -16195,13 +16264,6 @@ "node": ">=0.10.0" } }, - "node_modules/object-hash": { - "version": "1.3.1", - "license": "MIT", - "engines": { - "node": ">= 0.10.0" - } - }, "node_modules/object-inspect": { "version": "1.13.4", "dev": true, @@ -16311,6 +16373,15 @@ "wrappy": "1" } }, + "node_modules/one-time": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/one-time/-/one-time-1.0.0.tgz", + "integrity": "sha512-5DXOiRKwuSEcQ/l0kGCF6Q3jcADFv5tSmRaJck/OqkVFcOzutB134KRSfF0xDrL39MNnqxbHBbUUcjZIhTgb2g==", + "license": "MIT", + "dependencies": { + "fn.name": "1.x.x" + } + }, "node_modules/onetime": { "version": "5.1.2", "dev": true, @@ -20121,6 +20192,12 @@ "node": ">=0.10" } }, + "node_modules/text-hex": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/text-hex/-/text-hex-1.0.0.tgz", + "integrity": "sha512-uuVGNWzgJ4yhRaNSiubPY7OjISw4sw4E5Uv0wbjp+OzcbmVU/rsT8ujgcXJhn9ypzsgr5vlzpPqP+MBBKcGvbg==", + "license": "MIT" + }, "node_modules/text-table": { "version": "0.2.0", "dev": true, @@ -20413,8 +20490,13 @@ } }, "node_modules/triple-beam": { - "version": "1.3.0", - "license": "MIT" + "version": "1.4.1", + "resolved": "https://registry.npmjs.org/triple-beam/-/triple-beam-1.4.1.tgz", + "integrity": "sha512-aZbgViZrg1QNcG+LULa7nhZpJTZSLm/mXnHXnbAbjmN5aSa0y7V+wvv6+4WaBtpISJzThKy+PIPxc1Nq1EJ9mg==", + "license": "MIT", + "engines": { + "node": ">= 14.0.0" + } }, "node_modules/ts-jest": { "version": "29.4.6", @@ -21590,69 +21672,41 @@ "node": ">= 0.10.0" } }, - "node_modules/winston-compat": { - "version": "0.1.5", - "license": "MIT", - "dependencies": { - "cycle": "~1.0.3", - "logform": "^1.6.0", - "triple-beam": "^1.2.0" - }, - "engines": { - "node": ">= 6.4.0" - } - }, - "node_modules/winston-daily-rotate-file": { - "version": "3.10.0", - "license": "MIT", - "dependencies": { - "file-stream-rotator": "^0.4.1", - "object-hash": "^1.3.0", - "semver": "^6.2.0", - "triple-beam": "^1.3.0", - "winston-compat": "^0.1.4", - "winston-transport": "^4.2.0" - }, - "engines": { - "node": ">=6" - }, - "peerDependencies": { - "winston": "^2 || ^3" - } - }, - "node_modules/winston-daily-rotate-file/node_modules/semver": { - "version": "6.3.1", - "license": "ISC", - "bin": { - "semver": "bin/semver.js" - } - }, "node_modules/winston-transport": { - "version": "4.5.0", + "version": "4.9.0", + "resolved": "https://registry.npmjs.org/winston-transport/-/winston-transport-4.9.0.tgz", + "integrity": "sha512-8drMJ4rkgaPo1Me4zD/3WLfI/zPdA9o2IipKODunnGDcuqbHwjsbB79ylv04LCGGzU0xQ6vTznOMpQGaLhhm6A==", "license": "MIT", "dependencies": { - "logform": "^2.3.2", - "readable-stream": "^3.6.0", + "logform": "^2.7.0", + "readable-stream": "^3.6.2", "triple-beam": "^1.3.0" }, "engines": { - "node": ">= 6.4.0" + "node": ">= 12.0.0" } }, "node_modules/winston-transport/node_modules/fecha": { "version": "4.2.3", + "resolved": "https://registry.npmjs.org/fecha/-/fecha-4.2.3.tgz", + "integrity": "sha512-OP2IUU6HeYKJi3i0z4A19kHMQoLVs4Hc+DPqqxI2h/DPZHTm/vjsfC6P0b4jCMy14XizLBqvndQ+UilD7707Jw==", "license": "MIT" }, "node_modules/winston-transport/node_modules/logform": { - "version": "2.5.1", + "version": "2.7.0", + "resolved": "https://registry.npmjs.org/logform/-/logform-2.7.0.tgz", + "integrity": "sha512-TFYA4jnP7PVbmlBIfhlSe+WKxs9dklXMTEGcBCIvLhE/Tn3H6Gk1norupVW7m5Cnd4bLcr08AytbyV/xj7f/kQ==", "license": "MIT", "dependencies": { - "@colors/colors": "1.5.0", + "@colors/colors": "1.6.0", "@types/triple-beam": "^1.3.2", "fecha": "^4.2.0", "ms": "^2.1.1", "safe-stable-stringify": "^2.3.1", "triple-beam": "^1.3.0" + }, + "engines": { + "node": ">= 12.0.0" } }, "node_modules/winston/node_modules/colors": { @@ -21892,8 +21946,8 @@ "live-server": "1.2.1", "lodash": "^4.17.15", "url-parse": "^1.5.10", - "winston": "^2.4.4", - "winston-daily-rotate-file": "^3.10.0" + "winston": "^3.19.0", + "winston-daily-rotate-file": "^5.0.0" }, "bin": { "markbind": "dist/index.js" @@ -21928,6 +21982,12 @@ "dev": true, "license": "MIT" }, + "packages/cli/node_modules/async": { + "version": "3.2.6", + "resolved": "https://registry.npmjs.org/async/-/async-3.2.6.tgz", + "integrity": "sha512-htCUDlxyyCLMgaM3xXg0C0LW2xqfuQ6p05pCEIsXuyQ+a1koYKTuBMzRNwmybfLgvJDMd0r1LTn4+E0Ti6C2AA==", + "license": "MIT" + }, "packages/cli/node_modules/chalk": { "version": "3.0.0", "license": "MIT", @@ -21939,6 +21999,21 @@ "node": ">=8" } }, + "packages/cli/node_modules/fecha": { + "version": "4.2.3", + "resolved": "https://registry.npmjs.org/fecha/-/fecha-4.2.3.tgz", + "integrity": "sha512-OP2IUU6HeYKJi3i0z4A19kHMQoLVs4Hc+DPqqxI2h/DPZHTm/vjsfC6P0b4jCMy14XizLBqvndQ+UilD7707Jw==", + "license": "MIT" + }, + "packages/cli/node_modules/file-stream-rotator": { + "version": "0.6.1", + "resolved": "https://registry.npmjs.org/file-stream-rotator/-/file-stream-rotator-0.6.1.tgz", + "integrity": "sha512-u+dBid4PvZw17PmDeRcNOtCP9CCK/9lRN2w+r1xIS7yOL9JFrIBKTvrYsxT4P0pGtThYTn++QS5ChHaUov3+zQ==", + "license": "MIT", + "dependencies": { + "moment": "^2.29.1" + } + }, "packages/cli/node_modules/ignore": { "version": "7.0.5", "dev": true, @@ -21947,6 +22022,23 @@ "node": ">= 4" } }, + "packages/cli/node_modules/logform": { + "version": "2.7.0", + "resolved": "https://registry.npmjs.org/logform/-/logform-2.7.0.tgz", + "integrity": "sha512-TFYA4jnP7PVbmlBIfhlSe+WKxs9dklXMTEGcBCIvLhE/Tn3H6Gk1norupVW7m5Cnd4bLcr08AytbyV/xj7f/kQ==", + "license": "MIT", + "dependencies": { + "@colors/colors": "1.6.0", + "@types/triple-beam": "^1.3.2", + "fecha": "^4.2.0", + "ms": "^2.1.1", + "safe-stable-stringify": "^2.3.1", + "triple-beam": "^1.3.0" + }, + "engines": { + "node": ">= 12.0.0" + } + }, "packages/cli/node_modules/memfs": { "version": "4.56.2", "dev": true, @@ -21975,6 +22067,15 @@ "tslib": "2" } }, + "packages/cli/node_modules/object-hash": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/object-hash/-/object-hash-3.0.0.tgz", + "integrity": "sha512-RSn9F68PjH9HqtltsSnqYC1XXoWe9Bju5+213R98cNGttag9q9yAOTzdbsqvIa7aNm5WffBZFpWYr2aWrklWAw==", + "license": "MIT", + "engines": { + "node": ">= 6" + } + }, "packages/cli/node_modules/pretty-format": { "version": "29.7.0", "dev": true, @@ -22004,6 +22105,46 @@ "dev": true, "license": "MIT" }, + "packages/cli/node_modules/winston": { + "version": "3.19.0", + "resolved": "https://registry.npmjs.org/winston/-/winston-3.19.0.tgz", + "integrity": "sha512-LZNJgPzfKR+/J3cHkxcpHKpKKvGfDZVPS4hfJCc4cCG0CgYzvlD6yE/S3CIL/Yt91ak327YCpiF/0MyeZHEHKA==", + "license": "MIT", + "dependencies": { + "@colors/colors": "^1.6.0", + "@dabh/diagnostics": "^2.0.8", + "async": "^3.2.3", + "is-stream": "^2.0.0", + "logform": "^2.7.0", + "one-time": "^1.0.0", + "readable-stream": "^3.4.0", + "safe-stable-stringify": "^2.3.1", + "stack-trace": "0.0.x", + "triple-beam": "^1.3.0", + "winston-transport": "^4.9.0" + }, + "engines": { + "node": ">= 12.0.0" + } + }, + "packages/cli/node_modules/winston-daily-rotate-file": { + "version": "5.0.0", + "resolved": "https://registry.npmjs.org/winston-daily-rotate-file/-/winston-daily-rotate-file-5.0.0.tgz", + "integrity": "sha512-JDjiXXkM5qvwY06733vf09I2wnMXpZEhxEVOSPenZMii+g7pcDcTBt2MRugnoi8BwVSuCT2jfRXBUy+n1Zz/Yw==", + "license": "MIT", + "dependencies": { + "file-stream-rotator": "^0.6.1", + "object-hash": "^3.0.0", + "triple-beam": "^1.4.1", + "winston-transport": "^4.7.0" + }, + "engines": { + "node": ">=8" + }, + "peerDependencies": { + "winston": "^3" + } + }, "packages/core": { "name": "@markbind/core", "version": "6.3.1", diff --git a/packages/cli/package.json b/packages/cli/package.json index 8e1334bf0e..96f6fd46e2 100644 --- a/packages/cli/package.json +++ b/packages/cli/package.json @@ -46,8 +46,8 @@ "live-server": "1.2.1", "lodash": "^4.17.15", "url-parse": "^1.5.10", - "winston": "^2.4.4", - "winston-daily-rotate-file": "^3.10.0" + "winston": "^3.19.0", + "winston-daily-rotate-file": "^5.0.0" }, "devDependencies": { "@types/jest": "^29.4.6", diff --git a/packages/cli/src/util/logger-wrapper.cjs b/packages/cli/src/util/logger-wrapper.cjs deleted file mode 100644 index 427838c5c7..0000000000 --- a/packages/cli/src/util/logger-wrapper.cjs +++ /dev/null @@ -1,13 +0,0 @@ -/** - * CommonJS wrapper for winston v2 compatibility with ES Modules - * This file allows winston v2 (CommonJS) to be used in ESM projects - */ - -const winston = require('winston'); -require('winston-daily-rotate-file'); - -module.exports = { - winston, - transports: winston.transports, - configure: winston.configure, -}; diff --git a/packages/cli/src/util/logger.ts b/packages/cli/src/util/logger.ts index 0e7b3e19cc..39a6a28ad1 100644 --- a/packages/cli/src/util/logger.ts +++ b/packages/cli/src/util/logger.ts @@ -1,22 +1,27 @@ import chalk from 'chalk'; import figlet from 'figlet'; +import winston from 'winston'; +import DailyRotateFile from 'winston-daily-rotate-file'; -import { winston, transports } from './logger-wrapper.cjs'; +const { transports, format } = winston; + +const consoleFormat = format.combine( + format.colorize(), + format.printf(info => `${info.level}: ${info.message}`), +); // @markbind/core's consoleTransport but with level: info const consoleTransport = new transports.Console({ - colorize: true, + format: consoleFormat, handleExceptions: true, - humanReadableUnhandledException: true, level: 'info', - showLevel: true, }); function useDebugConsole(): void { consoleTransport.level = 'debug'; } -const dailyRotateFileTransport = new transports.DailyRotateFile({ +const dailyRotateFileTransport = new DailyRotateFile({ datePattern: 'YYYY-MM-DD', dirname: '_markbind/logs', filename: 'markbind-%DATE%.log', From b38a6d736caf6c513195eac0b5bfd4879353e27c Mon Sep 17 00:00:00 2001 From: Harjun751 Date: Mon, 9 Mar 2026 10:00:56 +0800 Subject: [PATCH 2/5] Add configuration for dailyrotate audit file DailyRotateFile's updated version now outputs an audit file to track files. This interferes with the CLI log-cleaning function on a failed build. Explicitly specify an audit file output directory that is in line with the other log directories. Update cleaning function to remove this on failed build. --- packages/cli/src/util/cliUtil.ts | 23 ++++++++++++++++++++--- packages/cli/src/util/logger.ts | 1 + 2 files changed, 21 insertions(+), 3 deletions(-) diff --git a/packages/cli/src/util/cliUtil.ts b/packages/cli/src/util/cliUtil.ts index 60544390e6..eae63c1a39 100644 --- a/packages/cli/src/util/cliUtil.ts +++ b/packages/cli/src/util/cliUtil.ts @@ -15,8 +15,23 @@ function tryDeleteFolder(pathName: string) { if (!fs.pathExistsSync(pathName)) { return; } + fs.rmdirSync(pathName); +} + +function tryDeleteFile(pathName: string) { + if (!fs.existsSync(pathName)) { + return; + } + fs.rmSync(pathName); +} + +function tryDelete(pathName: string, isFile: boolean) { try { - fs.rmdirSync(pathName); + if (isFile) { + tryDeleteFile(pathName); + } else { + tryDeleteFolder(pathName); + } } catch (error) { if (hasErrorCodeAndMessage(error)) { // If directory is not empty, fail silently @@ -58,7 +73,9 @@ export function findRootFolder( export function cleanupFailedMarkbindBuild() { const markbindDir = path.join(process.cwd(), '_markbind'); const logsDir = path.join(markbindDir, 'logs'); + const auditFileDir = path.join(logsDir, 'audit.json'); - tryDeleteFolder(logsDir); - tryDeleteFolder(markbindDir); + tryDelete(auditFileDir, true); + tryDelete(logsDir, false); + tryDelete(markbindDir, false); } diff --git a/packages/cli/src/util/logger.ts b/packages/cli/src/util/logger.ts index 39a6a28ad1..ad18e99e6b 100644 --- a/packages/cli/src/util/logger.ts +++ b/packages/cli/src/util/logger.ts @@ -28,6 +28,7 @@ const dailyRotateFileTransport = new DailyRotateFile({ handleExceptions: true, level: 'debug', maxFiles: 5, + auditFile: '_markbind/logs/audit.json', }); // Reconfigure the default instance logger winston provides with DailyRotateFile for markbind-cli From cd4012a6c0fa20b5f537c163649adba646032f98 Mon Sep 17 00:00:00 2001 From: Harjun751 Date: Thu, 12 Mar 2026 10:26:41 +0800 Subject: [PATCH 3/5] Update winston in core to v3 Core winston uses v2 CLI logging uses the fact that the shared winston object can be configured to add on trasports (like file logging). This means that if different winston versions are used across core and cli, the shared winston object becomes individual to each package, ultimately resulting in the logging not working properly. --- package-lock.json | 163 ++++++++---------------------- packages/core/package.json | 2 +- packages/core/src/utils/logger.ts | 11 +- 3 files changed, 52 insertions(+), 124 deletions(-) diff --git a/package-lock.json b/package-lock.json index d7c77c24e3..230cc41c4b 100644 --- a/package-lock.json +++ b/package-lock.json @@ -6356,11 +6356,10 @@ } }, "node_modules/async": { - "version": "2.6.4", - "license": "MIT", - "dependencies": { - "lodash": "^4.17.14" - } + "version": "3.2.6", + "resolved": "https://registry.npmjs.org/async/-/async-3.2.6.tgz", + "integrity": "sha512-htCUDlxyyCLMgaM3xXg0C0LW2xqfuQ6p05pCEIsXuyQ+a1koYKTuBMzRNwmybfLgvJDMd0r1LTn4+E0Ti6C2AA==", + "license": "MIT" }, "node_modules/async-each": { "version": "1.0.6", @@ -8414,12 +8413,6 @@ "version": "4.16.3", "license": "MIT" }, - "node_modules/cycle": { - "version": "1.0.3", - "engines": { - "node": ">=0.4.0" - } - }, "node_modules/danger": { "version": "13.0.4", "dev": true, @@ -10084,12 +10077,6 @@ "node": ">=0.10.0" } }, - "node_modules/eyes": { - "version": "0.1.8", - "engines": { - "node": "> 0.1.90" - } - }, "node_modules/fast-deep-equal": { "version": "3.1.3", "dev": true, @@ -10182,6 +10169,12 @@ "bser": "2.1.1" } }, + "node_modules/fecha": { + "version": "4.2.3", + "resolved": "https://registry.npmjs.org/fecha/-/fecha-4.2.3.tgz", + "integrity": "sha512-OP2IUU6HeYKJi3i0z4A19kHMQoLVs4Hc+DPqqxI2h/DPZHTm/vjsfC6P0b4jCMy14XizLBqvndQ+UilD7707Jw==", + "license": "MIT" + }, "node_modules/figlet": { "version": "1.10.0", "license": "MIT", @@ -10833,10 +10826,6 @@ "node": ">=10" } }, - "node_modules/gh-pages/node_modules/async": { - "version": "3.2.5", - "license": "MIT" - }, "node_modules/gh-pages/node_modules/commander": { "version": "13.1.0", "license": "MIT", @@ -12127,10 +12116,6 @@ "node": ">=0.10.0" } }, - "node_modules/isstream": { - "version": "0.1.2", - "license": "MIT" - }, "node_modules/istanbul-lib-coverage": { "version": "3.2.0", "dev": true, @@ -12260,11 +12245,6 @@ "node": ">=10" } }, - "node_modules/jake/node_modules/async": { - "version": "3.2.6", - "dev": true, - "license": "MIT" - }, "node_modules/jest": { "version": "29.7.0", "dev": true, @@ -14565,6 +14545,23 @@ "url": "https://github.com/sponsors/sindresorhus" } }, + "node_modules/logform": { + "version": "2.7.0", + "resolved": "https://registry.npmjs.org/logform/-/logform-2.7.0.tgz", + "integrity": "sha512-TFYA4jnP7PVbmlBIfhlSe+WKxs9dklXMTEGcBCIvLhE/Tn3H6Gk1norupVW7m5Cnd4bLcr08AytbyV/xj7f/kQ==", + "license": "MIT", + "dependencies": { + "@colors/colors": "1.6.0", + "@types/triple-beam": "^1.3.2", + "fecha": "^4.2.0", + "ms": "^2.1.1", + "safe-stable-stringify": "^2.3.1", + "triple-beam": "^1.3.0" + }, + "engines": { + "node": ">= 12.0.0" + } + }, "node_modules/lru-cache": { "version": "5.1.1", "dev": true, @@ -21658,18 +21655,25 @@ "license": "MIT" }, "node_modules/winston": { - "version": "2.4.7", + "version": "3.19.0", + "resolved": "https://registry.npmjs.org/winston/-/winston-3.19.0.tgz", + "integrity": "sha512-LZNJgPzfKR+/J3cHkxcpHKpKKvGfDZVPS4hfJCc4cCG0CgYzvlD6yE/S3CIL/Yt91ak327YCpiF/0MyeZHEHKA==", "license": "MIT", "dependencies": { - "async": "^2.6.4", - "colors": "1.0.x", - "cycle": "1.0.x", - "eyes": "0.1.x", - "isstream": "0.1.x", - "stack-trace": "0.0.x" + "@colors/colors": "^1.6.0", + "@dabh/diagnostics": "^2.0.8", + "async": "^3.2.3", + "is-stream": "^2.0.0", + "logform": "^2.7.0", + "one-time": "^1.0.0", + "readable-stream": "^3.4.0", + "safe-stable-stringify": "^2.3.1", + "stack-trace": "0.0.x", + "triple-beam": "^1.3.0", + "winston-transport": "^4.9.0" }, "engines": { - "node": ">= 0.10.0" + "node": ">= 12.0.0" } }, "node_modules/winston-transport": { @@ -21686,36 +21690,6 @@ "node": ">= 12.0.0" } }, - "node_modules/winston-transport/node_modules/fecha": { - "version": "4.2.3", - "resolved": "https://registry.npmjs.org/fecha/-/fecha-4.2.3.tgz", - "integrity": "sha512-OP2IUU6HeYKJi3i0z4A19kHMQoLVs4Hc+DPqqxI2h/DPZHTm/vjsfC6P0b4jCMy14XizLBqvndQ+UilD7707Jw==", - "license": "MIT" - }, - "node_modules/winston-transport/node_modules/logform": { - "version": "2.7.0", - "resolved": "https://registry.npmjs.org/logform/-/logform-2.7.0.tgz", - "integrity": "sha512-TFYA4jnP7PVbmlBIfhlSe+WKxs9dklXMTEGcBCIvLhE/Tn3H6Gk1norupVW7m5Cnd4bLcr08AytbyV/xj7f/kQ==", - "license": "MIT", - "dependencies": { - "@colors/colors": "1.6.0", - "@types/triple-beam": "^1.3.2", - "fecha": "^4.2.0", - "ms": "^2.1.1", - "safe-stable-stringify": "^2.3.1", - "triple-beam": "^1.3.0" - }, - "engines": { - "node": ">= 12.0.0" - } - }, - "node_modules/winston/node_modules/colors": { - "version": "1.0.3", - "license": "MIT", - "engines": { - "node": ">=0.1.90" - } - }, "node_modules/word-wrap": { "version": "1.2.5", "dev": true, @@ -21982,12 +21956,6 @@ "dev": true, "license": "MIT" }, - "packages/cli/node_modules/async": { - "version": "3.2.6", - "resolved": "https://registry.npmjs.org/async/-/async-3.2.6.tgz", - "integrity": "sha512-htCUDlxyyCLMgaM3xXg0C0LW2xqfuQ6p05pCEIsXuyQ+a1koYKTuBMzRNwmybfLgvJDMd0r1LTn4+E0Ti6C2AA==", - "license": "MIT" - }, "packages/cli/node_modules/chalk": { "version": "3.0.0", "license": "MIT", @@ -21999,12 +21967,6 @@ "node": ">=8" } }, - "packages/cli/node_modules/fecha": { - "version": "4.2.3", - "resolved": "https://registry.npmjs.org/fecha/-/fecha-4.2.3.tgz", - "integrity": "sha512-OP2IUU6HeYKJi3i0z4A19kHMQoLVs4Hc+DPqqxI2h/DPZHTm/vjsfC6P0b4jCMy14XizLBqvndQ+UilD7707Jw==", - "license": "MIT" - }, "packages/cli/node_modules/file-stream-rotator": { "version": "0.6.1", "resolved": "https://registry.npmjs.org/file-stream-rotator/-/file-stream-rotator-0.6.1.tgz", @@ -22022,23 +21984,6 @@ "node": ">= 4" } }, - "packages/cli/node_modules/logform": { - "version": "2.7.0", - "resolved": "https://registry.npmjs.org/logform/-/logform-2.7.0.tgz", - "integrity": "sha512-TFYA4jnP7PVbmlBIfhlSe+WKxs9dklXMTEGcBCIvLhE/Tn3H6Gk1norupVW7m5Cnd4bLcr08AytbyV/xj7f/kQ==", - "license": "MIT", - "dependencies": { - "@colors/colors": "1.6.0", - "@types/triple-beam": "^1.3.2", - "fecha": "^4.2.0", - "ms": "^2.1.1", - "safe-stable-stringify": "^2.3.1", - "triple-beam": "^1.3.0" - }, - "engines": { - "node": ">= 12.0.0" - } - }, "packages/cli/node_modules/memfs": { "version": "4.56.2", "dev": true, @@ -22105,28 +22050,6 @@ "dev": true, "license": "MIT" }, - "packages/cli/node_modules/winston": { - "version": "3.19.0", - "resolved": "https://registry.npmjs.org/winston/-/winston-3.19.0.tgz", - "integrity": "sha512-LZNJgPzfKR+/J3cHkxcpHKpKKvGfDZVPS4hfJCc4cCG0CgYzvlD6yE/S3CIL/Yt91ak327YCpiF/0MyeZHEHKA==", - "license": "MIT", - "dependencies": { - "@colors/colors": "^1.6.0", - "@dabh/diagnostics": "^2.0.8", - "async": "^3.2.3", - "is-stream": "^2.0.0", - "logform": "^2.7.0", - "one-time": "^1.0.0", - "readable-stream": "^3.4.0", - "safe-stable-stringify": "^2.3.1", - "stack-trace": "0.0.x", - "triple-beam": "^1.3.0", - "winston-transport": "^4.9.0" - }, - "engines": { - "node": ">= 12.0.0" - } - }, "packages/cli/node_modules/winston-daily-rotate-file": { "version": "5.0.0", "resolved": "https://registry.npmjs.org/winston-daily-rotate-file/-/winston-daily-rotate-file-5.0.0.tgz", @@ -22191,7 +22114,7 @@ "uuid": "^8.3.1", "vue": "3.3.11", "walk-sync": "^2.0.2", - "winston": "^2.4.4" + "winston": "^3.19.0" }, "devDependencies": { "@jest/globals": "^29.5.0", diff --git a/packages/core/package.json b/packages/core/package.json index 9f845e5c66..24b51c3a3b 100644 --- a/packages/core/package.json +++ b/packages/core/package.json @@ -95,7 +95,7 @@ "uuid": "^8.3.1", "vue": "3.3.11", "walk-sync": "^2.0.2", - "winston": "^2.4.4" + "winston": "^3.19.0" }, "devDependencies": { "@jest/globals": "^29.5.0", diff --git a/packages/core/src/utils/logger.ts b/packages/core/src/utils/logger.ts index 24db451cc0..29ac2f5578 100644 --- a/packages/core/src/utils/logger.ts +++ b/packages/core/src/utils/logger.ts @@ -1,6 +1,8 @@ import winston from 'winston'; import type { ProgressBar } from '../lib/progress'; +const { format } = winston; + let progressBar: ProgressBar | null = null; const setProgressBar = (bar: ProgressBar) => { @@ -10,12 +12,15 @@ const removeProgressBar = () => { progressBar = null; }; +const consoleFormat = format.combine( + format.colorize(), + format.printf(info => `${info.level}: ${info.message}`), +); + const consoleTransport = new winston.transports.Console({ - colorize: true, + format: consoleFormat, handleExceptions: true, - humanReadableUnhandledException: true, level: 'debug', - showLevel: true, }); winston.configure({ From d06f647775bc79d1d93d4c2e3782751db6c8d156 Mon Sep 17 00:00:00 2001 From: Harjun751 Date: Thu, 12 Mar 2026 10:28:35 +0800 Subject: [PATCH 4/5] Standardize file format logging --- packages/cli/src/util/logger.ts | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/packages/cli/src/util/logger.ts b/packages/cli/src/util/logger.ts index ad18e99e6b..30a37b92b6 100644 --- a/packages/cli/src/util/logger.ts +++ b/packages/cli/src/util/logger.ts @@ -5,9 +5,16 @@ import DailyRotateFile from 'winston-daily-rotate-file'; const { transports, format } = winston; +const LEVEL_AND_MESSAGE = (info: winston.Logform.TransformableInfo) => `${info.level}: ${info.message}`; + const consoleFormat = format.combine( format.colorize(), - format.printf(info => `${info.level}: ${info.message}`), + format.printf(LEVEL_AND_MESSAGE), +); + +const fileFormat = format.combine( + format.timestamp(), + format.printf(info => `${info.timestamp} - ${LEVEL_AND_MESSAGE(info)}`), ); // @markbind/core's consoleTransport but with level: info @@ -22,6 +29,7 @@ function useDebugConsole(): void { } const dailyRotateFileTransport = new DailyRotateFile({ + format: fileFormat, datePattern: 'YYYY-MM-DD', dirname: '_markbind/logs', filename: 'markbind-%DATE%.log', From 1a804b8605fe75249fa803279f0ef0ff368f37a9 Mon Sep 17 00:00:00 2001 From: Harjun751 Date: Thu, 12 Mar 2026 17:32:28 +0800 Subject: [PATCH 5/5] Add log error message format into log --- packages/cli/src/util/cliUtil.ts | 9 +++++---- packages/cli/src/util/logger.ts | 4 +++- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/packages/cli/src/util/cliUtil.ts b/packages/cli/src/util/cliUtil.ts index eae63c1a39..6fcf0ccbaa 100644 --- a/packages/cli/src/util/cliUtil.ts +++ b/packages/cli/src/util/cliUtil.ts @@ -33,6 +33,7 @@ function tryDelete(pathName: string, isFile: boolean) { tryDeleteFolder(pathName); } } catch (error) { + const targetType = isFile ? 'file' : 'directory'; if (hasErrorCodeAndMessage(error)) { // If directory is not empty, fail silently if (error.code !== DIR_NOT_EMPTY_ERROR_CODE) { @@ -40,11 +41,11 @@ function tryDelete(pathName: string, isFile: boolean) { // Use `console` instead of logger as we don't want to create a new logger instance // that might pollute the working directory again. // eslint-disable-next-line no-console - console.warn(`WARNING: Failed to delete directory ${pathName}: ${error.message}`); + console.warn(`WARNING: Failed to delete ${targetType} ${pathName}: ${error.message}`); } } else { // eslint-disable-next-line no-console - console.warn(`WARNING: Failed to delete directory ${pathName}: Unknown err ${error}`); + console.warn(`WARNING: Failed to delete ${targetType} ${pathName}: Unknown err ${error}`); } } } @@ -73,9 +74,9 @@ export function findRootFolder( export function cleanupFailedMarkbindBuild() { const markbindDir = path.join(process.cwd(), '_markbind'); const logsDir = path.join(markbindDir, 'logs'); - const auditFileDir = path.join(logsDir, 'audit.json'); + const auditFilePath = path.join(logsDir, 'audit.json'); - tryDelete(auditFileDir, true); + tryDelete(auditFilePath, true); tryDelete(logsDir, false); tryDelete(markbindDir, false); } diff --git a/packages/cli/src/util/logger.ts b/packages/cli/src/util/logger.ts index 30a37b92b6..0c30d25daf 100644 --- a/packages/cli/src/util/logger.ts +++ b/packages/cli/src/util/logger.ts @@ -5,10 +5,12 @@ import DailyRotateFile from 'winston-daily-rotate-file'; const { transports, format } = winston; -const LEVEL_AND_MESSAGE = (info: winston.Logform.TransformableInfo) => `${info.level}: ${info.message}`; +const LEVEL_AND_MESSAGE = (info: winston.Logform.TransformableInfo) => + `${info.level}: ${info.stack || info.message}`; const consoleFormat = format.combine( format.colorize(), + format.printf(LEVEL_AND_MESSAGE), );