diff --git a/package.json b/package.json index 332d36d..d1aa7b6 100644 --- a/package.json +++ b/package.json @@ -25,9 +25,6 @@ "default": "./dist/logger.js" }, "sideEffects": false, - "dependencies": { - "@proc7ts/context-values": "7.1.1" - }, "devDependencies": { "@jest/globals": "^29.7.0", "@proc7ts/context-builder": "^7.0.2", diff --git a/src/logger.spec.ts b/src/logger.spec.ts deleted file mode 100644 index 0a3971c..0000000 --- a/src/logger.spec.ts +++ /dev/null @@ -1,67 +0,0 @@ -import { afterEach, beforeEach, describe, expect, it, jest } from '@jest/globals'; -import { CxBuilder, cxConstAsset } from '@proc7ts/context-builder'; -import { CxGlobals } from '@proc7ts/context-values'; -import { Mock, spyOn } from 'jest-mock'; -import { Logger } from './logger.js'; -import { consoleLogger } from './loggers/mod.js'; - -describe('Logger', () => { - let cxBuilder: CxBuilder; - - beforeEach(() => { - cxBuilder = new CxBuilder(get => ({ get })); - cxBuilder.provide(cxConstAsset(CxGlobals, cxBuilder.context)); - }); - - let logger: Logger; - - beforeEach(() => { - logger = cxBuilder.get(Logger); - }); - - it('logs to most recent logger', () => { - const testLogger = { - error: jest.fn<(...args: unknown[]) => void>(), - } as Partial as Logger; - - cxBuilder.provide(cxConstAsset(Logger, testLogger)); - - const error = new Error('Test'); - - logger.error('Error', error); - - expect(testLogger.error).toHaveBeenCalledWith('Error', error); - expect(testLogger.error).toHaveBeenCalledTimes(1); - }); - it('is singleton', () => { - const cxBuilder2 = new CxBuilder(get => ({ get }), cxBuilder); - - expect(cxBuilder2.get(Logger)).toBe(logger); - }); - - describe('by default', () => { - let errorSpy: Mock<(...args: unknown[]) => void>; - - beforeEach(() => { - errorSpy = spyOn(consoleLogger, 'error').mockImplementation(() => void 0) as typeof errorSpy; - }); - afterEach(() => { - errorSpy.mockRestore(); - }); - - it('logs to console', () => { - const error = new Error('Test'); - - logger.error('Error', error); - - expect(errorSpy).toHaveBeenCalledWith('Error', error); - expect(errorSpy).toHaveBeenCalledTimes(1); - }); - }); - - describe('toString', () => { - it('provides string representation', () => { - expect(String(Logger)).toBe('[Logger]'); - }); - }); -}); diff --git a/src/logger.ts b/src/logger.ts index 149dfa6..324ea90 100644 --- a/src/logger.ts +++ b/src/logger.ts @@ -1,6 +1,3 @@ -import { CxEntry, CxGlobals, cxRecent, cxScoped } from '@proc7ts/context-values'; -import { consoleLogger, proxyLogger } from './loggers/mod.js'; - /** * Basic logger interface. */ @@ -42,24 +39,3 @@ export interface Logger { */ trace(...args: unknown[]): void; } - -/** - * Global context entry containing logger to use. - * - * Logs to {@link consoleLogger console} by default. - */ -export const Logger: CxEntry = { - perContext: /*#__PURE__*/ cxScoped( - CxGlobals, - /*#__PURE__*/ cxRecent({ - create: (recent, _) => recent, - byDefault: _ => consoleLogger, - assign({ get, to }) { - const logger = proxyLogger(get); - - return receiver => to((_, by) => receiver(logger, by)); - }, - }), - ), - toString: () => '[Logger]', -}; diff --git a/tsconfig.json b/tsconfig.json index e78aa82..730a28d 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -2,8 +2,6 @@ "extends": "@run-z/project-config/tsconfig.lib.json", "compilerOptions": { "lib": ["DOM", "ES2022"], - "module": "ES2022", - "moduleResolution": "Node", "outDir": "target/js" }, "include": ["src/**/*"]