diff --git a/index.ts b/index.ts index 0c62f7a..bc6c9cd 100644 --- a/index.ts +++ b/index.ts @@ -19,9 +19,8 @@ * purchase a proprietary commercial license. Please contact us at * to get commercial licensing options. */ -import { Logger } from './src'; +import { Logger } from './src/index.js'; -export * from './src'; +export * from './src/index.js'; -// noinspection JSUnusedGlobalSymbols export default new Logger(); diff --git a/package-lock.json b/package-lock.json index b6764a3..9b5b5dc 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,15 +1,14 @@ { "name": "@imqueue/async-logger", - "version": "3.0.1", + "version": "3.1.0", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "@imqueue/async-logger", - "version": "3.0.1", + "version": "3.1.0", "license": "GPL-3.0-only", "dependencies": { - "@imqueue/core": "^3.1.1", "winston": "^3.19.0", "winston-transport": "^4.9.0" }, @@ -18,6 +17,9 @@ "oxfmt": "0.57.0", "oxlint": "1.72.0", "typescript": "^7.0.2" + }, + "engines": { + "node": ">=22.12.0" } }, "node_modules/@colors/colors": { @@ -40,21 +42,6 @@ "kuler": "^2.0.0" } }, - "node_modules/@imqueue/core": { - "version": "3.1.1", - "resolved": "https://registry.npmjs.org/@imqueue/core/-/core-3.1.1.tgz", - "integrity": "sha512-iI/35LQCZ6xKwtVVrvIIU9Us9F8tMrtWQFmto3uqzQDHoDvNka+VjLuFbC6/N/TbARlH50mEBC0dUsWj3BENtg==", - "license": "GPL-3.0-only", - "dependencies": { - "ioredis": "^5.11.1" - } - }, - "node_modules/@ioredis/commands": { - "version": "1.10.0", - "resolved": "https://registry.npmjs.org/@ioredis/commands/-/commands-1.10.0.tgz", - "integrity": "sha512-UmeW7z4LfctwoQ5wkhVzgq8tXkreED2xZGpX+Bg+zA+WJFZCT6c062AfCK/Dfk81xZnnwdhJCUMkitihRaoC2Q==", - "license": "MIT" - }, "node_modules/@oxfmt/binding-android-arm-eabi": { "version": "0.57.0", "resolved": "https://registry.npmjs.org/@oxfmt/binding-android-arm-eabi/-/binding-android-arm-eabi-0.57.0.tgz", @@ -1121,15 +1108,6 @@ "integrity": "sha512-htCUDlxyyCLMgaM3xXg0C0LW2xqfuQ6p05pCEIsXuyQ+a1koYKTuBMzRNwmybfLgvJDMd0r1LTn4+E0Ti6C2AA==", "license": "MIT" }, - "node_modules/cluster-key-slot": { - "version": "1.1.1", - "resolved": "https://registry.npmjs.org/cluster-key-slot/-/cluster-key-slot-1.1.1.tgz", - "integrity": "sha512-rwHwUfXL40Chm1r08yrhU3qpUvdVlgkKNeyeGPOxnW8/SyVDvgRaed/Uz54AqWNaTCAThlj6QAs3TZcKI0xDEw==", - "license": "Apache-2.0", - "engines": { - "node": ">=0.10.0" - } - }, "node_modules/color": { "version": "5.0.3", "resolved": "https://registry.npmjs.org/color/-/color-5.0.3.tgz", @@ -1176,32 +1154,6 @@ "node": ">=18" } }, - "node_modules/debug": { - "version": "4.4.3", - "resolved": "https://registry.npmjs.org/debug/-/debug-4.4.3.tgz", - "integrity": "sha512-RGwwWnwQvkVfavKVt22FGLw+xYSdzARwm0ru6DhTVA3umU5hZc28V3kO4stgYryrTlLpuvgI9GiijltAjNbcqA==", - "license": "MIT", - "dependencies": { - "ms": "^2.1.3" - }, - "engines": { - "node": ">=6.0" - }, - "peerDependenciesMeta": { - "supports-color": { - "optional": true - } - } - }, - "node_modules/denque": { - "version": "2.1.0", - "resolved": "https://registry.npmjs.org/denque/-/denque-2.1.0.tgz", - "integrity": "sha512-HVQE3AAb/pxF8fQAoiqpvg9i3evqug3hoiwakOyZAwJm+6vZehbkYXZ0l4JxS+I3QxM97v5aaRNhj8v5oBhekw==", - "license": "Apache-2.0", - "engines": { - "node": ">=0.10" - } - }, "node_modules/enabled": { "version": "2.0.0", "resolved": "https://registry.npmjs.org/enabled/-/enabled-2.0.0.tgz", @@ -1226,28 +1178,6 @@ "integrity": "sha512-k/vGaX4/Yla3WzyMCvTQOXYeIHvqOKtnqBduzTHpzpQZzAskKMhZ2K+EnBiSM9zGSoIFeMpXKxa4dYeZIQqewQ==", "license": "ISC" }, - "node_modules/ioredis": { - "version": "5.11.1", - "resolved": "https://registry.npmjs.org/ioredis/-/ioredis-5.11.1.tgz", - "integrity": "sha512-ehuGcf94bQXhfagULNXrJdfnWO38v070jxSx/qE87Kjzmu2fU7ro5EFAb+OPituLqgfyuQaym5DlrNydW2sJ9A==", - "license": "MIT", - "dependencies": { - "@ioredis/commands": "1.10.0", - "cluster-key-slot": "1.1.1", - "debug": "4.4.3", - "denque": "2.1.0", - "redis-errors": "1.2.0", - "redis-parser": "3.0.0", - "standard-as-callback": "2.1.0" - }, - "engines": { - "node": ">=12.22.0" - }, - "funding": { - "type": "opencollective", - "url": "https://opencollective.com/ioredis" - } - }, "node_modules/is-stream": { "version": "2.0.1", "resolved": "https://registry.npmjs.org/is-stream/-/is-stream-2.0.1.tgz", @@ -1413,27 +1343,6 @@ "node": ">= 6" } }, - "node_modules/redis-errors": { - "version": "1.2.0", - "resolved": "https://registry.npmjs.org/redis-errors/-/redis-errors-1.2.0.tgz", - "integrity": "sha512-1qny3OExCf0UvUV/5wpYKf2YwPcOqXzkwKKSmKHiE6ZMQs5heeE/c8eXK+PNllPvmjgAbfnsbpkGZWy8cBpn9w==", - "license": "MIT", - "engines": { - "node": ">=4" - } - }, - "node_modules/redis-parser": { - "version": "3.0.0", - "resolved": "https://registry.npmjs.org/redis-parser/-/redis-parser-3.0.0.tgz", - "integrity": "sha512-DJnGAeenTdpMEH6uAJRK/uiyEIH9WVsUmoLwzudwGJUwZPp80PDBWPHXSAGNPwNvIXAbe7MSUB1zQFugFml66A==", - "license": "MIT", - "dependencies": { - "redis-errors": "^1.0.0" - }, - "engines": { - "node": ">=4" - } - }, "node_modules/safe-buffer": { "version": "5.2.1", "resolved": "https://registry.npmjs.org/safe-buffer/-/safe-buffer-5.2.1.tgz", @@ -1472,12 +1381,6 @@ "node": "*" } }, - "node_modules/standard-as-callback": { - "version": "2.1.0", - "resolved": "https://registry.npmjs.org/standard-as-callback/-/standard-as-callback-2.1.0.tgz", - "integrity": "sha512-qoRRSyROncaz1z0mvYqIE4lCd9p2R90i6GxW3uZv5ucSu8tU7B5HXUP1gG8pVZsYNVaXjk8ClXHPttLyxAL48A==", - "license": "MIT" - }, "node_modules/string_decoder": { "version": "1.3.0", "resolved": "https://registry.npmjs.org/string_decoder/-/string_decoder-1.3.0.tgz", diff --git a/package.json b/package.json index fdbf1e3..d4bb8d7 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@imqueue/async-logger", - "version": "3.0.1", + "version": "3.1.0", "description": "Configurable async logger over winston for @imqueue services", "keywords": [ "logger", @@ -38,7 +38,6 @@ "author": "imqueue.com (https://imqueue.com)", "license": "GPL-3.0-only", "dependencies": { - "@imqueue/core": "^3.1.1", "winston": "^3.19.0", "winston-transport": "^4.9.0" }, @@ -49,5 +48,16 @@ "typescript": "^7.0.2" }, "main": "index.js", - "types": "index.d.ts" + "types": "index.d.ts", + "type": "module", + "engines": { + "node": ">=22.12.0" + }, + "exports": { + ".": { + "types": "./index.d.ts", + "default": "./index.js" + }, + "./package.json": "./package.json" + } } diff --git a/src/Logger.ts b/src/Logger.ts index efd0d82..af73c82 100644 --- a/src/Logger.ts +++ b/src/Logger.ts @@ -19,20 +19,20 @@ * purchase a proprietary commercial license. Please contact us at * to get commercial licensing options. */ -import { ILogger, JsonObject } from '@imqueue/core'; +import { type ILogger, type JsonObject } from './types.js'; import { createLogger, format, Logger as WinstonLogger, - LoggerOptions, + type LoggerOptions, } from 'winston'; import { buildMessage, defaultMetadata, getTransport, transportsConfig, -} from './helpers'; -import { TransportOptions } from './TransportOptions'; +} from './helpers/index.js'; +import { type TransportOptions } from './TransportOptions.js'; export interface AsyncLoggerOptions { transports: TransportOptions[]; diff --git a/src/TransportOptions.ts b/src/TransportOptions.ts index 554611e..4a3a005 100644 --- a/src/TransportOptions.ts +++ b/src/TransportOptions.ts @@ -19,7 +19,7 @@ * purchase a proprietary commercial license. Please contact us at * to get commercial licensing options. */ -import { LoggerOptions } from 'winston'; +import { type LoggerOptions } from 'winston'; /** * Interface IConfig diff --git a/src/helpers/env.ts b/src/helpers/env.ts index aa23633..21a443d 100644 --- a/src/helpers/env.ts +++ b/src/helpers/env.ts @@ -19,10 +19,10 @@ * purchase a proprietary commercial license. Please contact us at * to get commercial licensing options. */ -import { JsonObject } from '@imqueue/core'; +import { type JsonObject } from '../types.js'; import { resolve } from 'path'; -import { existsSync as exists } from 'fs'; -import { TransportOptions } from '../TransportOptions'; +import { existsSync as exists, readFileSync } from 'fs'; +import { type TransportOptions } from '../TransportOptions.js'; const RX_NAME = /%name/g; const RX_VERSION = /%version/g; @@ -35,7 +35,7 @@ const RX_VERSION = /%version/g; export function pkg(): { name: string; version: string } { const pkgPath = resolve(process.cwd(), 'package.json'); const { name, version } = exists(pkgPath) - ? require(pkgPath) + ? JSON.parse(readFileSync(pkgPath, 'utf8')) : { name: 'logger', version: '' }; return { name, version }; diff --git a/src/helpers/index.ts b/src/helpers/index.ts index f308761..ade08a9 100644 --- a/src/helpers/index.ts +++ b/src/helpers/index.ts @@ -19,6 +19,6 @@ * purchase a proprietary commercial license. Please contact us at * to get commercial licensing options. */ -export * from './env'; -export * from './message'; -export * from './transport'; +export * from './env.js'; +export * from './message.js'; +export * from './transport.js'; diff --git a/src/helpers/transport.ts b/src/helpers/transport.ts index db5c7ab..5759d82 100644 --- a/src/helpers/transport.ts +++ b/src/helpers/transport.ts @@ -20,11 +20,11 @@ * to get commercial licensing options. */ import { transports } from 'winston'; -import * as Transport from 'winston-transport'; -import { +import type Transport from 'winston-transport'; +import type { FileTransportOptions, HttpTransportOptions, -} from 'winston/lib/winston/transports'; +} from 'winston/lib/winston/transports/index.js'; /** * Used for get configured transport by type diff --git a/src/index.ts b/src/index.ts index c6d5b26..e612c5a 100644 --- a/src/index.ts +++ b/src/index.ts @@ -19,6 +19,7 @@ * purchase a proprietary commercial license. Please contact us at * to get commercial licensing options. */ -export * from './helpers'; -export * from './TransportOptions'; -export * from './Logger'; +export * from './types.js'; +export * from './helpers/index.js'; +export * from './TransportOptions.js'; +export * from './Logger.js'; diff --git a/src/types.ts b/src/types.ts new file mode 100644 index 0000000..32af21b --- /dev/null +++ b/src/types.ts @@ -0,0 +1,85 @@ +/*! + * I'm Queue Software Project + * Copyright (C) 2026 imqueue.com + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + * + * If you want to use this code in a closed source (commercial) project, you can + * purchase a proprietary commercial license. Please contact us at + * to get commercial licensing options. + */ + +/** + * Structural copies of the @imqueue/core types this package uses, kept + * local so the logger carries no runtime dependency on the queue library. + * The shapes match @imqueue/core exactly, so values typed here remain + * assignment-compatible with code written against the core interfaces. + */ + +/** + * Represents any JSON-serializable value + */ +export type AnyJson = + | boolean + | number + | string + | null + | undefined + | JsonArray + | JsonObject; + +/** + * Represents JSON serializable object + */ +export interface JsonObject { + [key: string]: AnyJson; +} + +/** + * Represents JSON-serializable array + */ +export interface JsonArray extends Array {} + +/** + * Logger interface + */ +export interface ILogger { + /** + * Log level function + * + * @param {...unknown[]} args + */ + log(...args: unknown[]): void; + + /** + * Info level function + * + * @param {...unknown[]} args + */ + info(...args: unknown[]): void; + + /** + * Warning level function + * + * @param {...unknown[]} args + */ + warn(...args: unknown[]): void; + + /** + * Error level function + * + * @param {...unknown[]} args + */ + error(...args: unknown[]): void; +} diff --git a/test/Logger.spec.ts b/test/Logger.spec.ts index 2d40a32..46f53f3 100644 --- a/test/Logger.spec.ts +++ b/test/Logger.spec.ts @@ -25,7 +25,7 @@ import { describe, it, type TestContext } from 'node:test'; import assert from 'node:assert/strict'; import { tmpdir } from 'node:os'; import { join } from 'node:path'; -import logger, { Logger } from '..'; +import logger, { Logger } from '../index.js'; const LOG_FILE = join(tmpdir(), 'imq-async-logger-test.log'); diff --git a/test/helpers/env.spec.ts b/test/helpers/env.spec.ts index 5021274..76a8be8 100644 --- a/test/helpers/env.spec.ts +++ b/test/helpers/env.spec.ts @@ -23,12 +23,15 @@ */ import { afterEach, describe, it } from 'node:test'; import assert from 'node:assert/strict'; +import { readFileSync } from 'node:fs'; import { tmpdir } from 'node:os'; -import { defaultMetadata, pkg, transportsConfig } from '../..'; +import { defaultMetadata, pkg, transportsConfig } from '../../index.js'; // the package manifest of this repository, as pkg() should see it when the // process runs from the repository root -const self = require('../../package.json'); +const self = JSON.parse( + readFileSync(new URL('../../package.json', import.meta.url), 'utf8'), +); describe('helpers/pkg()', () => { it('should return name and version of the current package', () => { diff --git a/test/helpers/message.spec.ts b/test/helpers/message.spec.ts index af43ed5..f366341 100644 --- a/test/helpers/message.spec.ts +++ b/test/helpers/message.spec.ts @@ -23,7 +23,7 @@ */ import { describe, it } from 'node:test'; import assert from 'node:assert/strict'; -import { buildMessage } from '../..'; +import { buildMessage } from '../../index.js'; describe('helpers/buildMessage()', () => { it('should be a function', () => { diff --git a/test/helpers/transport.spec.ts b/test/helpers/transport.spec.ts index b5618d1..d2ad973 100644 --- a/test/helpers/transport.spec.ts +++ b/test/helpers/transport.spec.ts @@ -26,7 +26,7 @@ import assert from 'node:assert/strict'; import { tmpdir } from 'node:os'; import { join } from 'node:path'; import { transports } from 'winston'; -import { getTransport } from '../..'; +import { getTransport } from '../../index.js'; describe('helpers/getTransport()', () => { it('should be a function', () => { diff --git a/tsconfig.json b/tsconfig.json index e3bd55a..8b0e4ff 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -1,13 +1,14 @@ { "compilerOptions": { - "target": "es2023", - "lib": ["es2023"], + "target": "es2024", + "lib": ["es2024"], "moduleDetection": "force", "module": "nodenext", "moduleResolution": "nodenext", "resolveJsonModule": true, "esModuleInterop": true, + "verbatimModuleSyntax": true, "types": ["node"], @@ -19,6 +20,8 @@ "removeComments": false, "newLine": "lf", + "skipLibCheck": true, + "strict": true, "noImplicitOverride": true, "noFallthroughCasesInSwitch": true