From 2355a1ec16421122335f057886abee602c8e97f9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=97=8D+85CD?= <50108258+kwaa@users.noreply.github.com> Date: Tue, 10 Dec 2024 15:21:53 +0800 Subject: [PATCH 1/4] refactor(utils): use `.toISOString` instead of `formatISO` --- src/utils.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/utils.ts b/src/utils.ts index a2e165a..70aa657 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -1,5 +1,5 @@ import chalk from 'chalk' -import { format, formatISO } from 'date-fns' +import { format } from 'date-fns' import { DEFAULT_TIME_FORMAT, logLevelStringToLogLevelMap, logLevelToChalkColorMap } from './constants' import type { Log, LogLevelString, LoggerConfig } from './types' import { LogLevel } from './types' @@ -57,7 +57,7 @@ export function newLog( } const raw: Log = { - '@timestamp': formatISO(new Date()), + '@timestamp': new Date().toISOString(), '@localetime': format(new Date(), timeFormat), 'level': logLevel, 'fields': fieldsObj, From cc42c74e34fd2cc4b5c35b250cd6fd31e95c3c13 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=97=8D+85CD?= <50108258+kwaa@users.noreply.github.com> Date: Tue, 10 Dec 2024 16:33:56 +0800 Subject: [PATCH 2/4] refactor: use `picocolors` instead of `chalk` --- package.json | 4 ++-- pnpm-lock.yaml | 30 +++++++++++++++--------------- src/constants.ts | 16 +++++++++------- src/utils.ts | 29 ++++++++++++----------------- 4 files changed, 38 insertions(+), 41 deletions(-) diff --git a/package.json b/package.json index 1f68a05..d98ef43 100644 --- a/package.json +++ b/package.json @@ -43,8 +43,8 @@ "test:run": "vitest run" }, "dependencies": { - "chalk": "^5.3.0", - "date-fns": "^4.1.0" + "date-fns": "^4.1.0", + "picocolors": "^1.1.1" }, "devDependencies": { "@antfu/eslint-config": "2.21", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 456580d..516d7a6 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -8,12 +8,12 @@ importers: .: dependencies: - chalk: - specifier: ^5.3.0 - version: 5.3.0 date-fns: specifier: ^4.1.0 version: 4.1.0 + picocolors: + specifier: ^1.1.1 + version: 1.1.1 devDependencies: '@antfu/eslint-config': specifier: '2.21' @@ -2167,8 +2167,8 @@ packages: perfect-debounce@1.0.0: resolution: {integrity: sha512-xCy9V055GLEqoFaHoC1SoLIaLmWctgCUaBaWxDZ7/Zx4CTyX7cJQLJOok/orfjZAh9kEYpjJa4d0KcJmCbctZA==} - picocolors@1.0.1: - resolution: {integrity: sha512-anP1Z8qwhkbmu7MFP5iTt+wQKXgwzf7zTyGlcdzabySa9vd0Xt392U0rVmz9poOaBj0uHJKyyo9/upk0HrEQew==} + picocolors@1.1.1: + resolution: {integrity: sha512-xceH2snhtb5M9liqDsmEw56le376mTZkEX/jEb/RxNFyegNul7eNslCXP9FDj/Lcu0X8KEyMceP2ntpaHrDEVA==} picomatch@2.3.1: resolution: {integrity: sha512-JU3teHTNjmE2VCGFzuY8EXzCDVwEqB2a8fsIvwaStHhAWJEeVd1o1QD80CU6+ZdEXXSLbSsuLwJjkCBWqRQUVA==} @@ -2866,7 +2866,7 @@ snapshots: jsonc-eslint-parser: 2.4.0 local-pkg: 0.5.0 parse-gitignore: 2.0.0 - picocolors: 1.0.1 + picocolors: 1.1.1 toml-eslint-parser: 0.10.0 vue-eslint-parser: 9.4.3(eslint@8.57.0) yaml-eslint-parser: 1.2.3 @@ -2887,7 +2887,7 @@ snapshots: '@babel/code-frame@7.24.7': dependencies: '@babel/highlight': 7.24.7 - picocolors: 1.0.1 + picocolors: 1.1.1 '@babel/compat-data@7.25.2': {} @@ -2966,7 +2966,7 @@ snapshots: '@babel/helper-validator-identifier': 7.24.7 chalk: 2.4.2 js-tokens: 4.0.0 - picocolors: 1.0.1 + picocolors: 1.1.1 '@babel/parser@7.25.0': dependencies: @@ -3000,13 +3000,13 @@ snapshots: '@clack/core@0.3.4': dependencies: - picocolors: 1.0.1 + picocolors: 1.1.1 sisteransi: 1.0.5 '@clack/prompts@0.7.0': dependencies: '@clack/core': 0.3.4 - picocolors: 1.0.1 + picocolors: 1.1.1 sisteransi: 1.0.5 '@es-joy/jsdoccomment@0.43.1': @@ -3728,7 +3728,7 @@ snapshots: caniuse-lite: 1.0.30001643 fraction.js: 4.3.7 normalize-range: 0.1.2 - picocolors: 1.0.1 + picocolors: 1.1.1 postcss: 8.4.40 postcss-value-parser: 4.2.0 @@ -4979,7 +4979,7 @@ snapshots: perfect-debounce@1.0.0: {} - picocolors@1.0.1: {} + picocolors@1.1.1: {} picomatch@2.3.1: {} @@ -5163,7 +5163,7 @@ snapshots: postcss@8.4.40: dependencies: nanoid: 3.3.7 - picocolors: 1.0.1 + picocolors: 1.1.1 source-map-js: 1.2.0 prelude-ls@1.2.1: {} @@ -5375,7 +5375,7 @@ snapshots: css-tree: 2.3.1 css-what: 6.1.0 csso: 5.0.5 - picocolors: 1.0.1 + picocolors: 1.1.1 synckit@0.6.2: dependencies: @@ -5499,7 +5499,7 @@ snapshots: dependencies: browserslist: 4.23.2 escalade: 3.1.2 - picocolors: 1.0.1 + picocolors: 1.1.1 uri-js@4.4.1: dependencies: diff --git a/src/constants.ts b/src/constants.ts index a34645c..ca6a6cb 100644 --- a/src/constants.ts +++ b/src/constants.ts @@ -1,7 +1,9 @@ -import chalk, { type ChalkInstance } from 'chalk' +import pc from 'picocolors' import { Format, LogLevel, LogLevelString } from './types' +type PicoColorsFormatter = (input: string | number | null | undefined) => string + export const logLevelStringToLogLevelMap: Record = { [LogLevelString.Error]: LogLevel.Error, [LogLevelString.Warning]: LogLevel.Warning, @@ -26,12 +28,12 @@ export const availableLogLevelStrings: LogLevelString[] = [ LogLevelString.Debug, ] -export const logLevelToChalkColorMap: Record = { - [LogLevel.Error]: chalk.red, - [LogLevel.Warning]: chalk.yellow, - [LogLevel.Log]: chalk.blue, - [LogLevel.Verbose]: chalk.cyan, - [LogLevel.Debug]: chalk.green, +export const logLevelToColorMap: Record = { + [LogLevel.Error]: pc.red, + [LogLevel.Warning]: pc.yellow, + [LogLevel.Log]: pc.blue, + [LogLevel.Verbose]: pc.cyan, + [LogLevel.Debug]: pc.green, } export const availableLogLevels: LogLevel[] = [ diff --git a/src/utils.ts b/src/utils.ts index 70aa657..58e858c 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -1,12 +1,9 @@ -import chalk from 'chalk' +import pc from 'picocolors' import { format } from 'date-fns' -import { DEFAULT_TIME_FORMAT, logLevelStringToLogLevelMap, logLevelToChalkColorMap } from './constants' +import { DEFAULT_TIME_FORMAT, logLevelStringToLogLevelMap, logLevelToColorMap } from './constants' import type { Log, LogLevelString, LoggerConfig } from './types' import { LogLevel } from './types' -// Force enable colors even in non-TTY environments -chalk.level = 3 - export interface ErrorLike { message: string stack?: string @@ -34,7 +31,6 @@ export function newLog( context: string, fields: Record, message: string, - // eslint-disable-next-line ts/no-unsafe-assignment timeFormat: string = DEFAULT_TIME_FORMAT, ...optionalParams: [...any, string?] ): Log { @@ -73,7 +69,6 @@ export function newErrorLog( fields: Record, message: string, errorStack?: string, - // eslint-disable-next-line ts/no-unsafe-assignment timeFormat: string = DEFAULT_TIME_FORMAT, ...optionalParams: [...any, string?] ): Log { @@ -92,26 +87,26 @@ export function toPrettyString(log: Log): string { messagePartials.push(log['@localetime']) messagePartials.push( - logLevelToChalkColorMap[logLevelStringToLogLevelMap[log.level]]( + logLevelToColorMap[logLevelStringToLogLevelMap[log.level]]( `[${log.level}]`, ), ) let contextString = '' if (log.fields.isNestSystemModule != null) { - contextString = chalk.magenta(`[${log.fields.nestSystemModule}]`) + contextString = pc.magenta(`[${log.fields.nestSystemModule}]`) delete log.fields.isNestSystemModule delete log.fields.nestSystemModule } if (log.fields.context != null) { - contextString = chalk.magenta(`[${log.fields.context}]`) + contextString = pc.magenta(`[${log.fields.context}]`) delete log.fields.context } if (contextString.length > 0) { messagePartials.push(contextString) } if ('module' in log.fields && log.fields.module != null) { - messagePartials.push(chalk.magenta(`[${log.fields.module}]`)) + messagePartials.push(pc.magenta(`[${log.fields.module}]`)) delete log.fields.module } @@ -143,16 +138,16 @@ export function toPrettyString(log: Log): string { else { switch (typeof value) { case 'number': - valueString = chalk.yellow(value) + valueString = pc.yellow(value) break case 'object': - valueString = chalk.green(JSON.stringify(value)) + valueString = pc.green(JSON.stringify(value)) break case 'boolean': - valueString = chalk.yellow(String(value)) + valueString = pc.yellow(String(value)) break case 'undefined': - valueString = chalk.gray('undefined') + valueString = pc.gray('undefined') break default: valueString = String(value) @@ -160,7 +155,7 @@ export function toPrettyString(log: Log): string { } } - messagePartials.push(`${chalk.gray(key)}${chalk.gray('=')}${valueString}`) + messagePartials.push(`${pc.gray(key)}${pc.gray('=')}${valueString}`) } if (fieldsEntries.length > 0) { @@ -197,6 +192,6 @@ export function shouldOutputErrorLevelLogWhenLogLevelIsOneOf(logLevel: LogLevel) export function initializeLogger(config?: LoggerConfig) { if (config?.forceColors) { - chalk.level = 3 + // chalk.level = 3 } } From 07b926dc9ba9ca63817cb348d379c36e70ce6248 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=97=8D+85CD?= <50108258+kwaa@users.noreply.github.com> Date: Tue, 10 Dec 2024 16:39:55 +0800 Subject: [PATCH 3/4] refactor: clean config, remove initializeLogger --- src/types.ts | 1 - src/utils.ts | 9 ++------- 2 files changed, 2 insertions(+), 8 deletions(-) diff --git a/src/types.ts b/src/types.ts index 1755793..25110e0 100644 --- a/src/types.ts +++ b/src/types.ts @@ -37,6 +37,5 @@ export interface Log { } export interface LoggerConfig { - forceColors?: boolean timeFormat?: string } diff --git a/src/utils.ts b/src/utils.ts index 58e858c..558b527 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -1,7 +1,7 @@ import pc from 'picocolors' import { format } from 'date-fns' import { DEFAULT_TIME_FORMAT, logLevelStringToLogLevelMap, logLevelToColorMap } from './constants' -import type { Log, LogLevelString, LoggerConfig } from './types' +import type { Log, LogLevelString } from './types' import { LogLevel } from './types' export interface ErrorLike { @@ -54,6 +54,7 @@ export function newLog( const raw: Log = { '@timestamp': new Date().toISOString(), + // eslint-disable-next-line ts/no-unsafe-assignment, ts/no-unsafe-call '@localetime': format(new Date(), timeFormat), 'level': logLevel, 'fields': fieldsObj, @@ -189,9 +190,3 @@ export function shouldOutputWarningLevelLogWhenLogLevelIsOneOf(logLevel: LogLeve export function shouldOutputErrorLevelLogWhenLogLevelIsOneOf(logLevel: LogLevel): boolean { return logLevel >= LogLevel.Error } - -export function initializeLogger(config?: LoggerConfig) { - if (config?.forceColors) { - // chalk.level = 3 - } -} From b8b1281456c7305e45e1e29a0c52d3e9867c5ecd Mon Sep 17 00:00:00 2001 From: Neko Date: Tue, 10 Dec 2024 17:05:33 +0800 Subject: [PATCH 4/4] perf: drop date-fns to reduce bundle size, inline picocolors for treeshaking (#1) --- build.config.ts | 7 +++ cspell.config.yaml | 2 + package.json | 9 ++- pnpm-lock.yaml | 144 ++++++++++++++++++++++----------------------- src/logger.ts | 4 +- src/types.ts | 2 +- src/utils.ts | 7 +-- 7 files changed, 86 insertions(+), 89 deletions(-) create mode 100644 build.config.ts diff --git a/build.config.ts b/build.config.ts new file mode 100644 index 0000000..6143714 --- /dev/null +++ b/build.config.ts @@ -0,0 +1,7 @@ +import { defineBuildConfig } from 'unbuild' + +export default defineBuildConfig({ + rollup: { + inlineDependencies: true, + }, +}) diff --git a/cspell.config.yaml b/cspell.config.yaml index 9c72d27..c23759b 100644 --- a/cspell.config.yaml +++ b/cspell.config.yaml @@ -4,7 +4,9 @@ dictionaryDefinitions: [] dictionaries: [] words: - Ayaka + - bumpp - colorette + - localetime - Logg - Neko ignoreWords: [] diff --git a/package.json b/package.json index d98ef43..57603e2 100644 --- a/package.json +++ b/package.json @@ -40,16 +40,15 @@ "package:publish": "pnpm build && pnpm publish --access public --no-git-checks", "test": "vitest", "test:ui": "vitest --ui", - "test:run": "vitest run" - }, - "dependencies": { - "date-fns": "^4.1.0", - "picocolors": "^1.1.1" + "test:run": "vitest run", + "typecheck": "tsc --noEmit" }, "devDependencies": { "@antfu/eslint-config": "2.21", "bumpp": "^9.8.1", "eslint": "8", + "picocolors": "^1.1.1", + "typescript": "^5.7.2", "unbuild": "^2.0.0", "vitest": "^2.1.6" } diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 516d7a6..4cbed63 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -7,26 +7,25 @@ settings: importers: .: - dependencies: - date-fns: - specifier: ^4.1.0 - version: 4.1.0 - picocolors: - specifier: ^1.1.1 - version: 1.1.1 devDependencies: '@antfu/eslint-config': specifier: '2.21' - version: 2.21.3(@vue/compiler-sfc@3.4.35)(eslint@8.57.0)(typescript@5.5.4)(vitest@2.1.6) + version: 2.21.3(@vue/compiler-sfc@3.4.35)(eslint@8.57.0)(typescript@5.7.2)(vitest@2.1.6) bumpp: specifier: ^9.8.1 version: 9.8.1 eslint: specifier: '8' version: 8.57.0 + picocolors: + specifier: ^1.1.1 + version: 1.1.1 + typescript: + specifier: ^5.7.2 + version: 5.7.2 unbuild: specifier: ^2.0.0 - version: 2.0.0(typescript@5.5.4) + version: 2.0.0(typescript@5.7.2) vitest: specifier: ^2.1.6 version: 2.1.6 @@ -1261,9 +1260,6 @@ packages: resolution: {integrity: sha512-0LrrStPOdJj+SPCCrGhzryycLjwcgUSHBtxNA8aIDxf0GLsRh1cKYhB00Gd1lDOS4yGH69+SNn13+TWbVHETFQ==} engines: {node: ^10 || ^12.20.0 || ^14.13.0 || >=15.0.0, npm: '>=7.0.0'} - date-fns@4.1.0: - resolution: {integrity: sha512-Ukq0owbQXxa/U3EGtsdVBkR1w7KOQ5gIBqdH2hkvknzZPYvBxb/aa6E8L7tmjFtkwZBu3UXBbjIgPo/Ez4xaNg==} - debug@3.2.7: resolution: {integrity: sha512-CFjzYYAi4ThfiQvizrFQevTTXHtnCqWfe7x1AhgEscTz6ZbLbfoLRLPugTQyBth6f8ZERVUSyWHFD/7Wu4t1XQ==} peerDependencies: @@ -2667,8 +2663,8 @@ packages: resolution: {integrity: sha512-4dbzIzqvjtgiM5rw1k5rEHtBANKmdudhGyBEajN01fEyhaAIhsoKNy6y7+IN93IfpFtwY9iqi7kD+xwKhQsNJA==} engines: {node: '>=8'} - typescript@5.5.4: - resolution: {integrity: sha512-Mtq29sKDAEYP7aljRgtPOpTvOfbwRWlS6dPRzwjdE+C0R4brX/GUyhHSecbHMFLNBLcJIPt9nl9yG5TZ1weH+Q==} + typescript@5.7.2: + resolution: {integrity: sha512-i5t66RHxDvVN40HfDd1PsEThGNnlMCMT3jMUuoh9/0TaqWevNontacunWyN02LA9/fIbEWlcHZcgTKb9QoaLfg==} engines: {node: '>=14.17'} hasBin: true @@ -2833,13 +2829,13 @@ snapshots: '@jridgewell/gen-mapping': 0.3.5 '@jridgewell/trace-mapping': 0.3.25 - '@antfu/eslint-config@2.21.3(@vue/compiler-sfc@3.4.35)(eslint@8.57.0)(typescript@5.5.4)(vitest@2.1.6)': + '@antfu/eslint-config@2.21.3(@vue/compiler-sfc@3.4.35)(eslint@8.57.0)(typescript@5.7.2)(vitest@2.1.6)': dependencies: '@antfu/install-pkg': 0.3.3 '@clack/prompts': 0.7.0 - '@stylistic/eslint-plugin': 2.6.0(eslint@8.57.0)(typescript@5.5.4) - '@typescript-eslint/eslint-plugin': 7.18.0(@typescript-eslint/parser@7.18.0(eslint@8.57.0)(typescript@5.5.4))(eslint@8.57.0)(typescript@5.5.4) - '@typescript-eslint/parser': 7.18.0(eslint@8.57.0)(typescript@5.5.4) + '@stylistic/eslint-plugin': 2.6.0(eslint@8.57.0)(typescript@5.7.2) + '@typescript-eslint/eslint-plugin': 7.18.0(@typescript-eslint/parser@7.18.0(eslint@8.57.0)(typescript@5.7.2))(eslint@8.57.0)(typescript@5.7.2) + '@typescript-eslint/parser': 7.18.0(eslint@8.57.0)(typescript@5.7.2) eslint: 8.57.0 eslint-config-flat-gitignore: 0.1.8 eslint-flat-config-utils: 0.2.5 @@ -2847,18 +2843,18 @@ snapshots: eslint-plugin-antfu: 2.3.4(eslint@8.57.0) eslint-plugin-command: 0.2.3(eslint@8.57.0) eslint-plugin-eslint-comments: 3.2.0(eslint@8.57.0) - eslint-plugin-import-x: 0.5.3(eslint@8.57.0)(typescript@5.5.4) + eslint-plugin-import-x: 0.5.3(eslint@8.57.0)(typescript@5.7.2) eslint-plugin-jsdoc: 48.10.2(eslint@8.57.0) eslint-plugin-jsonc: 2.16.0(eslint@8.57.0) eslint-plugin-markdown: 5.1.0(eslint@8.57.0) eslint-plugin-n: 17.10.1(eslint@8.57.0) eslint-plugin-no-only-tests: 3.1.0 - eslint-plugin-perfectionist: 2.11.0(eslint@8.57.0)(typescript@5.5.4)(vue-eslint-parser@9.4.3(eslint@8.57.0)) + eslint-plugin-perfectionist: 2.11.0(eslint@8.57.0)(typescript@5.7.2)(vue-eslint-parser@9.4.3(eslint@8.57.0)) eslint-plugin-regexp: 2.6.0(eslint@8.57.0) eslint-plugin-toml: 0.11.1(eslint@8.57.0) eslint-plugin-unicorn: 54.0.0(eslint@8.57.0) - eslint-plugin-unused-imports: 3.2.0(@typescript-eslint/eslint-plugin@7.18.0(@typescript-eslint/parser@7.18.0(eslint@8.57.0)(typescript@5.5.4))(eslint@8.57.0)(typescript@5.5.4))(eslint@8.57.0) - eslint-plugin-vitest: 0.5.4(@typescript-eslint/eslint-plugin@7.18.0(@typescript-eslint/parser@7.18.0(eslint@8.57.0)(typescript@5.5.4))(eslint@8.57.0)(typescript@5.5.4))(eslint@8.57.0)(typescript@5.5.4)(vitest@2.1.6) + eslint-plugin-unused-imports: 3.2.0(@typescript-eslint/eslint-plugin@7.18.0(@typescript-eslint/parser@7.18.0(eslint@8.57.0)(typescript@5.7.2))(eslint@8.57.0)(typescript@5.7.2))(eslint@8.57.0) + eslint-plugin-vitest: 0.5.4(@typescript-eslint/eslint-plugin@7.18.0(@typescript-eslint/parser@7.18.0(eslint@8.57.0)(typescript@5.7.2))(eslint@8.57.0)(typescript@5.7.2))(eslint@8.57.0)(typescript@5.7.2)(vitest@2.1.6) eslint-plugin-vue: 9.27.0(eslint@8.57.0) eslint-plugin-yml: 1.14.0(eslint@8.57.0) eslint-processor-vue-blocks: 0.1.2(@vue/compiler-sfc@3.4.35)(eslint@8.57.0) @@ -3434,31 +3430,31 @@ snapshots: estraverse: 5.3.0 picomatch: 4.0.2 - '@stylistic/eslint-plugin-plus@2.6.0(eslint@8.57.0)(typescript@5.5.4)': + '@stylistic/eslint-plugin-plus@2.6.0(eslint@8.57.0)(typescript@5.7.2)': dependencies: '@types/eslint': 9.6.0 - '@typescript-eslint/utils': 8.0.0(eslint@8.57.0)(typescript@5.5.4) + '@typescript-eslint/utils': 8.0.0(eslint@8.57.0)(typescript@5.7.2) eslint: 8.57.0 transitivePeerDependencies: - supports-color - typescript - '@stylistic/eslint-plugin-ts@2.6.0(eslint@8.57.0)(typescript@5.5.4)': + '@stylistic/eslint-plugin-ts@2.6.0(eslint@8.57.0)(typescript@5.7.2)': dependencies: '@stylistic/eslint-plugin-js': 2.6.0(eslint@8.57.0) '@types/eslint': 9.6.0 - '@typescript-eslint/utils': 8.0.0(eslint@8.57.0)(typescript@5.5.4) + '@typescript-eslint/utils': 8.0.0(eslint@8.57.0)(typescript@5.7.2) eslint: 8.57.0 transitivePeerDependencies: - supports-color - typescript - '@stylistic/eslint-plugin@2.6.0(eslint@8.57.0)(typescript@5.5.4)': + '@stylistic/eslint-plugin@2.6.0(eslint@8.57.0)(typescript@5.7.2)': dependencies: '@stylistic/eslint-plugin-js': 2.6.0(eslint@8.57.0) '@stylistic/eslint-plugin-jsx': 2.6.0(eslint@8.57.0) - '@stylistic/eslint-plugin-plus': 2.6.0(eslint@8.57.0)(typescript@5.5.4) - '@stylistic/eslint-plugin-ts': 2.6.0(eslint@8.57.0)(typescript@5.5.4) + '@stylistic/eslint-plugin-plus': 2.6.0(eslint@8.57.0)(typescript@5.7.2) + '@stylistic/eslint-plugin-ts': 2.6.0(eslint@8.57.0)(typescript@5.7.2) '@types/eslint': 9.6.0 eslint: 8.57.0 transitivePeerDependencies: @@ -3491,34 +3487,34 @@ snapshots: '@types/unist@2.0.10': {} - '@typescript-eslint/eslint-plugin@7.18.0(@typescript-eslint/parser@7.18.0(eslint@8.57.0)(typescript@5.5.4))(eslint@8.57.0)(typescript@5.5.4)': + '@typescript-eslint/eslint-plugin@7.18.0(@typescript-eslint/parser@7.18.0(eslint@8.57.0)(typescript@5.7.2))(eslint@8.57.0)(typescript@5.7.2)': dependencies: '@eslint-community/regexpp': 4.11.0 - '@typescript-eslint/parser': 7.18.0(eslint@8.57.0)(typescript@5.5.4) + '@typescript-eslint/parser': 7.18.0(eslint@8.57.0)(typescript@5.7.2) '@typescript-eslint/scope-manager': 7.18.0 - '@typescript-eslint/type-utils': 7.18.0(eslint@8.57.0)(typescript@5.5.4) - '@typescript-eslint/utils': 7.18.0(eslint@8.57.0)(typescript@5.5.4) + '@typescript-eslint/type-utils': 7.18.0(eslint@8.57.0)(typescript@5.7.2) + '@typescript-eslint/utils': 7.18.0(eslint@8.57.0)(typescript@5.7.2) '@typescript-eslint/visitor-keys': 7.18.0 eslint: 8.57.0 graphemer: 1.4.0 ignore: 5.3.1 natural-compare: 1.4.0 - ts-api-utils: 1.3.0(typescript@5.5.4) + ts-api-utils: 1.3.0(typescript@5.7.2) optionalDependencies: - typescript: 5.5.4 + typescript: 5.7.2 transitivePeerDependencies: - supports-color - '@typescript-eslint/parser@7.18.0(eslint@8.57.0)(typescript@5.5.4)': + '@typescript-eslint/parser@7.18.0(eslint@8.57.0)(typescript@5.7.2)': dependencies: '@typescript-eslint/scope-manager': 7.18.0 '@typescript-eslint/types': 7.18.0 - '@typescript-eslint/typescript-estree': 7.18.0(typescript@5.5.4) + '@typescript-eslint/typescript-estree': 7.18.0(typescript@5.7.2) '@typescript-eslint/visitor-keys': 7.18.0 debug: 4.3.6 eslint: 8.57.0 optionalDependencies: - typescript: 5.5.4 + typescript: 5.7.2 transitivePeerDependencies: - supports-color @@ -3532,15 +3528,15 @@ snapshots: '@typescript-eslint/types': 8.0.0 '@typescript-eslint/visitor-keys': 8.0.0 - '@typescript-eslint/type-utils@7.18.0(eslint@8.57.0)(typescript@5.5.4)': + '@typescript-eslint/type-utils@7.18.0(eslint@8.57.0)(typescript@5.7.2)': dependencies: - '@typescript-eslint/typescript-estree': 7.18.0(typescript@5.5.4) - '@typescript-eslint/utils': 7.18.0(eslint@8.57.0)(typescript@5.5.4) + '@typescript-eslint/typescript-estree': 7.18.0(typescript@5.7.2) + '@typescript-eslint/utils': 7.18.0(eslint@8.57.0)(typescript@5.7.2) debug: 4.3.6 eslint: 8.57.0 - ts-api-utils: 1.3.0(typescript@5.5.4) + ts-api-utils: 1.3.0(typescript@5.7.2) optionalDependencies: - typescript: 5.5.4 + typescript: 5.7.2 transitivePeerDependencies: - supports-color @@ -3548,7 +3544,7 @@ snapshots: '@typescript-eslint/types@8.0.0': {} - '@typescript-eslint/typescript-estree@7.18.0(typescript@5.5.4)': + '@typescript-eslint/typescript-estree@7.18.0(typescript@5.7.2)': dependencies: '@typescript-eslint/types': 7.18.0 '@typescript-eslint/visitor-keys': 7.18.0 @@ -3557,13 +3553,13 @@ snapshots: is-glob: 4.0.3 minimatch: 9.0.5 semver: 7.6.3 - ts-api-utils: 1.3.0(typescript@5.5.4) + ts-api-utils: 1.3.0(typescript@5.7.2) optionalDependencies: - typescript: 5.5.4 + typescript: 5.7.2 transitivePeerDependencies: - supports-color - '@typescript-eslint/typescript-estree@8.0.0(typescript@5.5.4)': + '@typescript-eslint/typescript-estree@8.0.0(typescript@5.7.2)': dependencies: '@typescript-eslint/types': 8.0.0 '@typescript-eslint/visitor-keys': 8.0.0 @@ -3572,29 +3568,29 @@ snapshots: is-glob: 4.0.3 minimatch: 9.0.5 semver: 7.6.3 - ts-api-utils: 1.3.0(typescript@5.5.4) + ts-api-utils: 1.3.0(typescript@5.7.2) optionalDependencies: - typescript: 5.5.4 + typescript: 5.7.2 transitivePeerDependencies: - supports-color - '@typescript-eslint/utils@7.18.0(eslint@8.57.0)(typescript@5.5.4)': + '@typescript-eslint/utils@7.18.0(eslint@8.57.0)(typescript@5.7.2)': dependencies: '@eslint-community/eslint-utils': 4.4.0(eslint@8.57.0) '@typescript-eslint/scope-manager': 7.18.0 '@typescript-eslint/types': 7.18.0 - '@typescript-eslint/typescript-estree': 7.18.0(typescript@5.5.4) + '@typescript-eslint/typescript-estree': 7.18.0(typescript@5.7.2) eslint: 8.57.0 transitivePeerDependencies: - supports-color - typescript - '@typescript-eslint/utils@8.0.0(eslint@8.57.0)(typescript@5.5.4)': + '@typescript-eslint/utils@8.0.0(eslint@8.57.0)(typescript@5.7.2)': dependencies: '@eslint-community/eslint-utils': 4.4.0(eslint@8.57.0) '@typescript-eslint/scope-manager': 8.0.0 '@typescript-eslint/types': 8.0.0 - '@typescript-eslint/typescript-estree': 8.0.0(typescript@5.5.4) + '@typescript-eslint/typescript-estree': 8.0.0(typescript@5.7.2) eslint: 8.57.0 transitivePeerDependencies: - supports-color @@ -3977,8 +3973,6 @@ snapshots: dependencies: css-tree: 2.2.1 - date-fns@4.1.0: {} - debug@3.2.7: dependencies: ms: 2.1.2 @@ -4183,9 +4177,9 @@ snapshots: eslint: 8.57.0 ignore: 5.3.1 - eslint-plugin-import-x@0.5.3(eslint@8.57.0)(typescript@5.5.4): + eslint-plugin-import-x@0.5.3(eslint@8.57.0)(typescript@5.7.2): dependencies: - '@typescript-eslint/utils': 7.18.0(eslint@8.57.0)(typescript@5.5.4) + '@typescript-eslint/utils': 7.18.0(eslint@8.57.0)(typescript@5.7.2) debug: 4.3.6 doctrine: 3.0.0 eslint: 8.57.0 @@ -4249,9 +4243,9 @@ snapshots: eslint-plugin-no-only-tests@3.1.0: {} - eslint-plugin-perfectionist@2.11.0(eslint@8.57.0)(typescript@5.5.4)(vue-eslint-parser@9.4.3(eslint@8.57.0)): + eslint-plugin-perfectionist@2.11.0(eslint@8.57.0)(typescript@5.7.2)(vue-eslint-parser@9.4.3(eslint@8.57.0)): dependencies: - '@typescript-eslint/utils': 7.18.0(eslint@8.57.0)(typescript@5.5.4) + '@typescript-eslint/utils': 7.18.0(eslint@8.57.0)(typescript@5.7.2) eslint: 8.57.0 minimatch: 9.0.5 natural-compare-lite: 1.4.0 @@ -4304,19 +4298,19 @@ snapshots: transitivePeerDependencies: - supports-color - eslint-plugin-unused-imports@3.2.0(@typescript-eslint/eslint-plugin@7.18.0(@typescript-eslint/parser@7.18.0(eslint@8.57.0)(typescript@5.5.4))(eslint@8.57.0)(typescript@5.5.4))(eslint@8.57.0): + eslint-plugin-unused-imports@3.2.0(@typescript-eslint/eslint-plugin@7.18.0(@typescript-eslint/parser@7.18.0(eslint@8.57.0)(typescript@5.7.2))(eslint@8.57.0)(typescript@5.7.2))(eslint@8.57.0): dependencies: eslint: 8.57.0 eslint-rule-composer: 0.3.0 optionalDependencies: - '@typescript-eslint/eslint-plugin': 7.18.0(@typescript-eslint/parser@7.18.0(eslint@8.57.0)(typescript@5.5.4))(eslint@8.57.0)(typescript@5.5.4) + '@typescript-eslint/eslint-plugin': 7.18.0(@typescript-eslint/parser@7.18.0(eslint@8.57.0)(typescript@5.7.2))(eslint@8.57.0)(typescript@5.7.2) - eslint-plugin-vitest@0.5.4(@typescript-eslint/eslint-plugin@7.18.0(@typescript-eslint/parser@7.18.0(eslint@8.57.0)(typescript@5.5.4))(eslint@8.57.0)(typescript@5.5.4))(eslint@8.57.0)(typescript@5.5.4)(vitest@2.1.6): + eslint-plugin-vitest@0.5.4(@typescript-eslint/eslint-plugin@7.18.0(@typescript-eslint/parser@7.18.0(eslint@8.57.0)(typescript@5.7.2))(eslint@8.57.0)(typescript@5.7.2))(eslint@8.57.0)(typescript@5.7.2)(vitest@2.1.6): dependencies: - '@typescript-eslint/utils': 7.18.0(eslint@8.57.0)(typescript@5.5.4) + '@typescript-eslint/utils': 7.18.0(eslint@8.57.0)(typescript@5.7.2) eslint: 8.57.0 optionalDependencies: - '@typescript-eslint/eslint-plugin': 7.18.0(@typescript-eslint/parser@7.18.0(eslint@8.57.0)(typescript@5.5.4))(eslint@8.57.0)(typescript@5.5.4) + '@typescript-eslint/eslint-plugin': 7.18.0(@typescript-eslint/parser@7.18.0(eslint@8.57.0)(typescript@5.7.2))(eslint@8.57.0)(typescript@5.7.2) vitest: 2.1.6 transitivePeerDependencies: - supports-color @@ -4821,7 +4815,7 @@ snapshots: mkdirp@1.0.4: {} - mkdist@1.5.4(typescript@5.5.4): + mkdist@1.5.4(typescript@5.7.2): dependencies: autoprefixer: 10.4.19(postcss@8.4.40) citty: 0.1.6 @@ -4837,7 +4831,7 @@ snapshots: postcss-nested: 6.2.0(postcss@8.4.40) semver: 7.6.3 optionalDependencies: - typescript: 5.5.4 + typescript: 5.7.2 mlly@1.7.1: dependencies: @@ -5234,11 +5228,11 @@ snapshots: dependencies: glob: 7.2.3 - rollup-plugin-dts@6.1.1(rollup@3.29.4)(typescript@5.5.4): + rollup-plugin-dts@6.1.1(rollup@3.29.4)(typescript@5.7.2): dependencies: magic-string: 0.30.11 rollup: 3.29.4 - typescript: 5.5.4 + typescript: 5.7.2 optionalDependencies: '@babel/code-frame': 7.24.7 @@ -5424,9 +5418,9 @@ snapshots: dependencies: eslint-visitor-keys: 3.4.3 - ts-api-utils@1.3.0(typescript@5.5.4): + ts-api-utils@1.3.0(typescript@5.7.2): dependencies: - typescript: 5.5.4 + typescript: 5.7.2 tslib@2.6.3: {} @@ -5442,11 +5436,11 @@ snapshots: type-fest@0.8.1: {} - typescript@5.5.4: {} + typescript@5.7.2: {} ufo@1.5.4: {} - unbuild@2.0.0(typescript@5.5.4): + unbuild@2.0.0(typescript@5.7.2): dependencies: '@rollup/plugin-alias': 5.1.0(rollup@3.29.4) '@rollup/plugin-commonjs': 25.0.8(rollup@3.29.4) @@ -5463,17 +5457,17 @@ snapshots: hookable: 5.5.3 jiti: 1.21.6 magic-string: 0.30.11 - mkdist: 1.5.4(typescript@5.5.4) + mkdist: 1.5.4(typescript@5.7.2) mlly: 1.7.1 pathe: 1.1.2 pkg-types: 1.1.3 pretty-bytes: 6.1.1 rollup: 3.29.4 - rollup-plugin-dts: 6.1.1(rollup@3.29.4)(typescript@5.5.4) + rollup-plugin-dts: 6.1.1(rollup@3.29.4)(typescript@5.7.2) scule: 1.3.0 untyped: 1.4.2 optionalDependencies: - typescript: 5.5.4 + typescript: 5.7.2 transitivePeerDependencies: - sass - supports-color diff --git a/src/logger.ts b/src/logger.ts index e580ed4..8869b0d 100644 --- a/src/logger.ts +++ b/src/logger.ts @@ -24,7 +24,6 @@ const GLOBAL_CONFIG = { configured: false, logLevel: LogLevel.Debug, format: Format.JSON, - // eslint-disable-next-line ts/no-unsafe-assignment timeFormat: DEFAULT_TIME_FORMAT, } @@ -91,7 +90,6 @@ export function setGlobalTimeFormat(timeFormat: string): void { } export function getGlobalTimeFormat(): string { - // eslint-disable-next-line ts/no-unsafe-return return GLOBAL_CONFIG.timeFormat } @@ -241,7 +239,7 @@ export function createLogg(context: string): Logger { logLevel: LogLevel.Debug, format: Format.JSON, shouldUseGlobalConfig: false, - // eslint-disable-next-line ts/no-unsafe-assignment + timeFormat: DEFAULT_TIME_FORMAT, useGlobalConfig: (): Logger => { logObj.shouldUseGlobalConfig = true diff --git a/src/types.ts b/src/types.ts index 25110e0..9aba431 100644 --- a/src/types.ts +++ b/src/types.ts @@ -20,7 +20,7 @@ export enum Format { } export interface Log { - '@timestamp': string + '@timestamp': number '@localetime': string 'level': LogLevelString 'fields': { diff --git a/src/utils.ts b/src/utils.ts index 558b527..9da44cf 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -1,5 +1,4 @@ import pc from 'picocolors' -import { format } from 'date-fns' import { DEFAULT_TIME_FORMAT, logLevelStringToLogLevelMap, logLevelToColorMap } from './constants' import type { Log, LogLevelString } from './types' import { LogLevel } from './types' @@ -31,7 +30,6 @@ export function newLog( context: string, fields: Record, message: string, - timeFormat: string = DEFAULT_TIME_FORMAT, ...optionalParams: [...any, string?] ): Log { let fieldsObj: { context?: string, [key: string]: any } = { context: '' } @@ -53,9 +51,8 @@ export function newLog( } const raw: Log = { - '@timestamp': new Date().toISOString(), - // eslint-disable-next-line ts/no-unsafe-assignment, ts/no-unsafe-call - '@localetime': format(new Date(), timeFormat), + '@timestamp': Date.now(), + '@localetime': new Date().toISOString(), 'level': logLevel, 'fields': fieldsObj, 'message': messageString,