From 74335fbb686edd63e5965c50b6cfc853abd07717 Mon Sep 17 00:00:00 2001 From: Koen Kanters Date: Mon, 6 Oct 2025 20:06:41 +0200 Subject: [PATCH] fix: Remove Moment.js dependency (#28797) --- lib/util/logger.ts | 11 +++++------ lib/util/settings.schema.json | 2 +- package.json | 1 - pnpm-lock.yaml | 8 -------- 4 files changed, 6 insertions(+), 16 deletions(-) diff --git a/lib/util/logger.ts b/lib/util/logger.ts index a15ad507..5abe6360 100644 --- a/lib/util/logger.ts +++ b/lib/util/logger.ts @@ -2,10 +2,8 @@ import assert from "node:assert"; import fs from "node:fs"; import path from "node:path"; -import moment from "moment"; import {rimrafSync} from "rimraf"; import winston from "winston"; - import * as settings from "./settings"; const NAMESPACE_SEPARATOR = ":"; @@ -31,7 +29,7 @@ class Logger { // What transports to enable this.output = settings.get().advanced.log_output; // Directory to log to - const timestamp = moment(Date.now()).format("YYYY-MM-DD.HH-mm-ss"); + const timestamp = new Date().toISOString().slice(0, 19).replace("T", ".").replace(/:/g, "-"); this.directory = settings.get().advanced.log_directory.replace("%TIMESTAMP%", timestamp); const logFilename = settings.get().advanced.log_file.replace("%TIMESTAMP%", timestamp); this.level = settings.get().advanced.log_level; @@ -40,11 +38,12 @@ class Logger { assert(settings.LOG_LEVELS.includes(this.level), `'${this.level}' is not valid log_level, use one of '${settings.LOG_LEVELS.join(", ")}'`); - const timestampFormat = (): string => moment().format(settings.get().advanced.timestamp_format); - this.logger = winston.createLogger({ level: "debug", - format: winston.format.combine(winston.format.errors({stack: true}), winston.format.timestamp({format: timestampFormat})), + format: winston.format.combine( + winston.format.errors({stack: true}), + winston.format.timestamp({format: settings.get().advanced.timestamp_format}), + ), levels: winston.config.syslog.levels, }); diff --git a/lib/util/settings.schema.json b/lib/util/settings.schema.json index e02d79a3..b8db4c0b 100644 --- a/lib/util/settings.schema.json +++ b/lib/util/settings.schema.json @@ -784,7 +784,7 @@ "type": "string", "title": "Timestamp format", "requiresRestart": true, - "description": "Log timestamp format", + "description": "Log timestamp format (see https://github.com/taylorhakes/fecha?tab=readme-ov-file#formatting-tokens for all supported tokens)", "default": "YYYY-MM-DD HH:mm:ss", "examples": ["YYYY-MM-DD HH:mm:ss.SSS"] }, diff --git a/package.json b/package.json index 4611668b..c3ff6963 100644 --- a/package.json +++ b/package.json @@ -52,7 +52,6 @@ "js-yaml": "^4.1.0", "json-stable-stringify-without-jsonify": "^1.0.1", "jszip": "^3.10.1", - "moment": "^2.30.1", "mqtt": "^5.14.1", "object-assign-deep": "^0.4.0", "rimraf": "^6.0.1", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 34eb7bd9..da11f7eb 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -41,9 +41,6 @@ importers: jszip: specifier: ^3.10.1 version: 3.10.1 - moment: - specifier: ^2.30.1 - version: 2.30.1 mqtt: specifier: ^5.14.1 version: 5.14.1 @@ -1170,9 +1167,6 @@ packages: resolution: {integrity: sha512-imbHQNRglyaplMmjBLL3V5R6Bfq5oM+ivds3SKgc6oRtzErEnBUUc5No11Z2pilkUvl42gJvi285xTNswcKCMA==} engines: {node: '>=6'} - moment@2.30.1: - resolution: {integrity: sha512-uEmtNhbDOrWPFS+hdjFCBfy9f2YoyzRpwcl+DqpC6taX21FzsTLQVbMV/W7PzNSX6x/bhC1zA3c2UQ5NzH6how==} - mqtt-packet@9.0.2: resolution: {integrity: sha512-MvIY0B8/qjq7bKxdN1eD+nrljoeaai+qjLJgfRn3TiMuz0pamsIWY2bFODPZMSNmabsLANXsLl4EMoWvlaTZWA==} @@ -2614,8 +2608,6 @@ snapshots: mixin-deep@2.0.1: {} - moment@2.30.1: {} - mqtt-packet@9.0.2: dependencies: bl: 6.1.3