diff --git a/bunfig.toml b/bunfig.toml deleted file mode 100644 index 0f705fb..0000000 --- a/bunfig.toml +++ /dev/null @@ -1,2 +0,0 @@ -[test] -preload = "./test/init.ts" diff --git a/package.json b/package.json index 1de3fa5..5a4b007 100644 --- a/package.json +++ b/package.json @@ -9,7 +9,6 @@ }, "dependencies": { - "log": "git+https://git.pband.ch/typescript/log.git", "yup": "^1.7.0" }, "devDependencies": { @@ -20,7 +19,6 @@ "eslint": "^9.35.0", "globals": "^16.4.0", "jiti": "^2.5.1", - "logger-console": "git+https://git.pband.ch/typescript/logger-console.git", "prettier": "^3.6.2", "tmp": "^0.2.5", "typescript": "^5.9.2", diff --git a/src/env.ts b/src/env.ts index b9bb5ec..0ff10c5 100644 --- a/src/env.ts +++ b/src/env.ts @@ -1,20 +1,18 @@ -import logger from 'log' import fs from 'node:fs/promises' import type {Ok} from './helpers' -const log = logger('config:env') const FILE_EXT = '__FILE' // Read from env or file export async function read_env(key: string): Promise> { const path = process.env[key + FILE_EXT] if (path !== undefined) { - log.debug(`Read ${key} from a file`) - log.trace('Path :', path) + console.debug(`Read ${key} from a file`) + console.trace('Path :', path) return from_file(path) } else { - log.debug(`Read ${key} from env`) + console.debug(`Read ${key} from env`) return {ok: true, data: process.env[key]} } } @@ -27,15 +25,15 @@ export async function from_file(path: string): Promise> { return content } export async function get_file_content(path: string): Promise> { - log.debug('Read file content') - log.trace('Path :', path) + console.debug('Read file content') + console.trace('Path :', path) try { const data = await fs.readFile(path, {encoding: 'utf-8'}) return {ok: true, data} } catch (e) { - log.warn('Failed to read file', path) - log.debug('Error :', e) + console.warn('Failed to read file', path) + console.debug('Error :', e) return {ok: false} } } diff --git a/src/parsing.ts b/src/parsing.ts index 8e79dee..a19b299 100644 --- a/src/parsing.ts +++ b/src/parsing.ts @@ -1,15 +1,12 @@ import * as yup from 'yup' -import logger from 'log' import {read_env} from './env' import type {Ok} from './helpers' -const log = logger('config:parsing') - export async function parse>(schema: yup.ObjectSchema): Promise> { - log.info('Parse from env') + console.log('Parse from env') - log.trace('Start parsing') + console.trace('Start parsing') const config = await object(schema) if (!config.ok) return config @@ -30,7 +27,7 @@ export async function object>( schema: yup.ObjectSchema, base_name: string = '' ): Promise> { - log.debug('Object') + console.debug('Object') if (base_name.length !== 0) base_name = base_name + '_' // @ts-expect-error Ugly hack with type S @@ -41,7 +38,7 @@ export async function object>( const sub_scheme = schema.fields[key] as yup.AnySchema const type = sub_scheme.describe().type - log.debug(`Parse ${sub_key} with type ${type}`) + console.debug(`Parse ${sub_key} with type ${type}`) // If it is an object, do not try to read from env let value: Ok @@ -59,7 +56,7 @@ export async function object>( if (def !== undefined) value = {ok: true, data: def} else if (sub_scheme.spec.optional) continue else { - log.warn('Missing value for', key) + console.warn('Missing value for', key) return {} } } else { @@ -79,11 +76,11 @@ export async function object>( } export async function generic(value: string | string[], scheme: yup.AnySchema): Promise> { - log.debug('Generic', scheme.describe().type) + console.debug('Generic', scheme.describe().type) if (!(await scheme.isValid(value))) { - log.warn('Invalid value') - log.debug('Value:', value) + console.warn('Invalid value') + console.debug('Value:', value) return {} } diff --git a/test/env.test.ts b/test/env.test.ts index c59ae9a..30741dc 100644 --- a/test/env.test.ts +++ b/test/env.test.ts @@ -25,7 +25,7 @@ describe('File IO', () => { const res = await env.from_file(file.name) expect(res).toEqual({ok: true, data: 'coucou'}) }) - test.todo('Fails safe if no access to read') + test.todo('Fails safe if no access to read', () => {}) }) describe('Folder', () => { let folder: DirResult diff --git a/test/init.ts b/test/init.ts deleted file mode 100644 index 9c3ad96..0000000 --- a/test/init.ts +++ /dev/null @@ -1,5 +0,0 @@ -import {Console} from 'logger-console' -import {Level, writers} from 'log' - -const logger = new Console({minLevel: Level.DEBUG, with_color: true}) -writers.set('console', logger)