From 62a1a9be2781efb0da430a002e0875a69a43508d Mon Sep 17 00:00:00 2001 From: CptSchnitz <12687466+CptSchnitz@users.noreply.github.com> Date: Mon, 23 Dec 2024 11:22:06 +0200 Subject: [PATCH] feat: moved to common tsconfig package --- package-lock.json | 14 ++++++++++++++ package.json | 3 ++- src/env.ts | 2 +- src/index.ts | 4 ++-- src/options.ts | 2 +- src/schemas.ts | 4 ++++ tsconfig.json | 16 +--------------- 7 files changed, 25 insertions(+), 20 deletions(-) diff --git a/package-lock.json b/package-lock.json index e344d94..4cae7a9 100644 --- a/package-lock.json +++ b/package-lock.json @@ -27,6 +27,7 @@ "@commitlint/cli": "^11.0.0", "@commitlint/config-conventional": "^11.0.0", "@map-colonies/eslint-config": "^4.0.0", + "@map-colonies/tsconfig": "^1.0.0", "@types/config": "^3.3.4", "@types/debug": "^4.1.12", "@types/jest": "^29.5.12", @@ -44,6 +45,9 @@ "ts-jest": "^29.1.5", "typescript": "^5.4.5" }, + "engines": { + "node": ">=20" + }, "peerDependencies": { "@map-colonies/schemas": "^1.0.0", "prom-client": "^15.0.0" @@ -3125,6 +3129,16 @@ "license": "MIT", "peer": true }, + "node_modules/@map-colonies/tsconfig": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/@map-colonies/tsconfig/-/tsconfig-1.0.0.tgz", + "integrity": "sha512-POVvNJXvlnw7WxxL69Pz1qutn6EiCoCqYpB0304IwGjvNGMi2UqhTvroA/GruXX9rzkVfGp8IGn4kxO5m0kCcQ==", + "dev": true, + "license": "MIT", + "engines": { + "node": ">=18" + } + }, "node_modules/@nicolo-ribaudo/eslint-scope-5-internals": { "version": "5.1.1-v1", "resolved": "https://registry.npmjs.org/@nicolo-ribaudo/eslint-scope-5-internals/-/eslint-scope-5-internals-5.1.1-v1.tgz", diff --git a/package.json b/package.json index 2b923c4..c83591a 100644 --- a/package.json +++ b/package.json @@ -93,6 +93,7 @@ "ts-jest": "^29.1.5", "typescript": "^5.4.5", "prom-client": "^15.0.0", - "jest-extended": "^4.0.2" + "jest-extended": "^4.0.2", + "@map-colonies/tsconfig": "^1.0.0" } } diff --git a/src/env.ts b/src/env.ts index cc53820..0fed720 100644 --- a/src/env.ts +++ b/src/env.ts @@ -53,7 +53,7 @@ function parseSchemaEnv(schema: JSONSchema): EnvMap { debug('going over object properties at path %s', key, path); const subSchema = schema.properties[key]; - if (typeof subSchema !== 'boolean') { + if (typeof subSchema !== 'boolean' && subSchema !== undefined) { iterateOverSchemaObject(subSchema, path === '' ? key : `${path}.${key}`); } } diff --git a/src/index.ts b/src/index.ts index ba7c5cc..7d77add 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,3 +1,3 @@ -export { ConfigOptions, ConfigInstance } from './types'; +export type { ConfigOptions, ConfigInstance } from './types'; export { config } from './config'; -export { ConfigErrors, isConfigError, ConfigError } from './errors'; +export { type ConfigErrors, isConfigError, ConfigError } from './errors'; diff --git a/src/options.ts b/src/options.ts index 5b1796c..6ef024d 100644 --- a/src/options.ts +++ b/src/options.ts @@ -38,7 +38,7 @@ export function initializeOptions(options: Partial): BaseOptions { const [errors, validatedOptions] = validate(ajvOptionsValidator, optionsSchema, mergedOptions); if (errors) { - debug('error validating options: %s', errors[0].message); + debug('error validating options: %s', errors[0] !== undefined ? errors[0].message : 'unknown error'); throw createConfigError( 'optionValidationError', 'An error occurred while validating the given options. please check both arguments and environment variables', diff --git a/src/schemas.ts b/src/schemas.ts index fafb65f..ad6024b 100644 --- a/src/schemas.ts +++ b/src/schemas.ts @@ -36,6 +36,10 @@ export async function loadSchema(schema: JSONSchema): ReturnType { const subPath = file.url.split(SCHEMA_DOMAIN)[1]; + if (subPath === undefined) { + throw createConfigError(`schemaNotFoundError`, `Schema url is not valid`, { schemaPath: file.url }); + } + return loadSpecificSchema(subPath); }, }, diff --git a/tsconfig.json b/tsconfig.json index ed338ea..5007944 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -1,19 +1,5 @@ { - "compilerOptions": { - "target": "ES2022", - "allowSyntheticDefaultImports": true, - "strict": true, - "module": "NodeNext", - "esModuleInterop": true, - "moduleResolution": "NodeNext", - "resolveJsonModule": true, - "outDir": "dist", - "sourceMap": true, - "declaration": true, - "declarationMap": true, - "noEmit": true, - "strictNullChecks": true - }, + "extends": "@map-colonies/tsconfig/tsconfig-library", "include": ["src"], "exclude": ["dist", "node_modules"] }