Skip to content

Commit

Permalink
upgrade more packages (#31)
Browse files Browse the repository at this point in the history
Co-authored-by: fraliv13 <[email protected]>
  • Loading branch information
alexandra-c and fraliv13 authored Nov 6, 2024
1 parent 1251634 commit 31d2ace
Show file tree
Hide file tree
Showing 14 changed files with 289 additions and 258 deletions.
9 changes: 9 additions & 0 deletions .changeset/long-wasps-knock.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
---
'@totalsoft/key-per-file-configuration': major
'@totalsoft/pino-opentelemetry': major
'@totalsoft/graceful-shutdown': major
'@totalsoft/correlation': major
'@totalsoft/opentracing': major
---

update dependencies for the following packages: correlation, graceful-shutdown, key-per-file-configuration, opentracing, pino-opentelemetry
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"packageManager": "[email protected]",
"private": true,
"engines": {
"node": ">=18.x"
"node": ">=20.x"
},
"workspaces": [
"packages/*"
Expand Down
2 changes: 1 addition & 1 deletion packages/correlation/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
"devDependencies": {
"@jest/types": "^29.6.3",
"@types/jest": "^29.5.14",
"@types/node": "^22.8.7",
"@types/node": "^22.9.0",
"@types/uuid": "^10.0.0",
"jest": "^29.7.0",
"rimraf": "^6.0.1",
Expand Down
16 changes: 8 additions & 8 deletions packages/graceful-shutdown/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,14 @@
"test": "jest --collectCoverage --passWithNoTests --verbose --silent=false --runInBand"
},
"devDependencies": {
"@jest/types": "^28.1.0",
"@types/jest": "^27.5.1",
"@types/node": "^17.0.32",
"@types/uuid": "^8.3.4",
"jest": "^28.1.0",
"rimraf": "^3.0.2",
"ts-jest": "^28.0.3",
"typescript": "^4.7.2"
"@jest/types": "^29.6.3",
"@types/jest": "^29.5.14",
"@types/node": "^22.9.0",
"@types/uuid": "^10.0.0",
"jest": "^29.7.0",
"rimraf": "^6.0.1",
"ts-jest": "^29.2.5",
"typescript": "^5.6.3"
},
"jest": {
"preset": "ts-jest",
Expand Down
2 changes: 1 addition & 1 deletion packages/key-per-file-configuration/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ await configWatcher.close()

```javascript
Options {
// The path where the configuration files can be found (supports glob)
// The path where the configuration files can be found
configPath?: string;
}
```
5 changes: 5 additions & 0 deletions packages/key-per-file-configuration/__mocks__/fs/promises.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
// Copyright (c) TotalSoft.
// This source code is licensed under the MIT license.

import { fs } from 'memfs'
export = fs.promises
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ describe('key-per-file configuration tests:', () => {
expect(process.env.ENV2).toBe(env2Value)
})

it('reads config from custom glob location', async () => {
it('fails to reads config from custom glob location', async () => {
//arrange
const env1Value = 'ENV1-value'
const env2Value = 'ENV2-value'
Expand All @@ -50,12 +50,12 @@ describe('key-per-file configuration tests:', () => {
})

//act
const watcher = load({ configPath: 'customLocation/**', logger: emptyLogger })
await watcher.close()
const tryLoad = () => {
const _watcher = load({ configPath: 'customLocation/**', logger: emptyLogger })
}

//assert
expect(process.env.ENV1).toBe(env1Value)
expect(process.env.ENV2).toBe(env2Value)
expect(tryLoad).toThrow('Glob patterns are not supported in the config path')
})

it('reads config from custom direcotry location', async () => {
Expand Down
28 changes: 14 additions & 14 deletions packages/key-per-file-configuration/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,22 +26,22 @@
"test": "jest --collectCoverage --passWithNoTests --verbose --silent=false --runInBand"
},
"devDependencies": {
"@jest/types": "^28.1.0",
"@types/glob": "^7.2.0",
"@types/jest": "^27.5.1",
"@types/node": "^17.0.32",
"@types/ramda": "0.28.0",
"@types/rimraf": "^3",
"@types/uuid": "^8.3.4",
"jest": "^28.1.0",
"memfs": "^3.4.7",
"rimraf": "^3.0.2",
"ts-jest": "^28.0.3",
"typescript": "^4.7.2"
"@jest/types": "^29.6.3",
"@types/glob": "^8.1.0",
"@types/jest": "^29.5.14",
"@types/node": "^22.9.0",
"@types/ramda": "0.30.2",
"@types/rimraf": "^4",
"@types/uuid": "^10.0.0",
"jest": "^29.7.0",
"memfs": "^4.14.0",
"rimraf": "^6.0.1",
"ts-jest": "^29.2.5",
"typescript": "^5.6.3"
},
"dependencies": {
"chokidar": "^3.5.3",
"glob": "^8.0.3"
"chokidar": "^4.0.1",
"glob": "^11.0.0"
},
"jest": {
"preset": "ts-jest",
Expand Down
32 changes: 19 additions & 13 deletions packages/key-per-file-configuration/src/keyPerFileConfiguration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,41 +11,47 @@ const { KEY_PER_FILE_CONFIG_PATH } = process.env
const defaultConfigPath = 'runtime'

export function load(options?: Options): ConfigWatcher {
const cleanConfigPath = _cleanConfigPath(options?.configPath)
const configFolderPath = _getAbsolutePath(options?.configPath)
const logger = options?.logger ?? console

logger.info(`Loading "Key per File" configuration at: ${cleanConfigPath}`)
logger.info(`Loading "Key per File" configuration at: ${configFolderPath}`)

// Load files to env
const filePaths = glob.sync(cleanConfigPath, { nodir: true })
const filePaths = _getFilePaths(configFolderPath)
const loadValue = _loadValue(logger)
filePaths.forEach(loadValue)

// Watch for file changes
const watcher = chokidar
.watch(cleanConfigPath, { awaitWriteFinish: true /*, usePolling: true*/ })
.watch(configFolderPath, { awaitWriteFinish: true /*, usePolling: true*/ })
.on('unlink', _removeValue)
.on('add', loadValue)
.on('change', loadValue)

return { close: () => watcher.close() }
}

function _cleanConfigPath(configPath = KEY_PER_FILE_CONFIG_PATH || defaultConfigPath): string {
let cleanConfigPath = path.join(process.cwd(), configPath)
function _getAbsolutePath(configPath = KEY_PER_FILE_CONFIG_PATH || defaultConfigPath): string {
const cleanConfigPath = path.join(process.cwd(), configPath)

if (!glob.hasMagic(cleanConfigPath)) {
if (!fs.existsSync(cleanConfigPath) || fs.lstatSync(cleanConfigPath).isDirectory()) {
cleanConfigPath = path.join(cleanConfigPath, '**')
}
if (glob.hasMagic(cleanConfigPath)) {
throw 'Glob patterns are not supported in the config path'
}

// glob only works with forward slashes
cleanConfigPath = cleanConfigPath.replace(/\\/g, '/')

return cleanConfigPath
}

function _getFilePaths(configPath: string) {

if (!fs.existsSync(configPath) || fs.lstatSync(configPath).isDirectory()) {
configPath = path.join(configPath, '**')
}

configPath = configPath.replace(/\\/g, '/')

return glob.sync(configPath, { nodir: true })
}

function _loadValue(logger: Logger) {
return function (filePath: string) {
const key = path.basename(filePath)
Expand Down
2 changes: 1 addition & 1 deletion packages/key-per-file-configuration/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,5 @@ export interface Options {
}

export interface ConfigWatcher {
close: () => Promise<void>
close: () => Promise<void> | undefined
}
14 changes: 7 additions & 7 deletions packages/opentracing/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,13 @@
"opentracing": "^0.14.7"
},
"devDependencies": {
"@jest/types": "^28.1.0",
"@types/jest": "^27.5.1",
"@types/node": "^17.0.32",
"jest": "^28.1.0",
"rimraf": "^3.0.2",
"ts-jest": "^28.0.3",
"typescript": "^4.7.2"
"@jest/types": "^29.6.3",
"@types/jest": "^29.5.14",
"@types/node": "^22.9.0",
"jest": "^29.7.0",
"rimraf": "^6.0.1",
"ts-jest": "^29.2.5",
"typescript": "^5.6.3"
},
"jest": {
"preset": "ts-jest",
Expand Down
30 changes: 15 additions & 15 deletions packages/pino-opentelemetry/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,23 +26,23 @@
"test": "jest --collectCoverage --passWithNoTests --verbose --silent=false --runInBand"
},
"devDependencies": {
"@jest/types": "^28.1.0",
"@types/jest": "^27.5.1",
"@types/node": "^17.0.32",
"@types/ramda": "^0.28.15",
"@types/split2": "^3.2.1",
"@types/uuid": "^8.3.4",
"jest": "^28.1.0",
"rimraf": "^3.0.2",
"ts-jest": "^28.0.3",
"typescript": "^4.7.2"
"@jest/types": "^29.6.3",
"@types/jest": "^29.5.14",
"@types/node": "^22.9.0",
"@types/ramda": "^0.30.2",
"@types/split2": "^4.2.3",
"@types/uuid": "^10.0.0",
"jest": "^29.7.0",
"rimraf": "^6.0.1",
"ts-jest": "^29.2.5",
"typescript": "^5.6.3"
},
"dependencies": {
"@opentelemetry/api": "^1.4.0",
"@opentelemetry/semantic-conventions": "^1.9.1",
"pino": "^8.5.0",
"ramda": "^0.28.0",
"split2": "^4.1.0"
"@opentelemetry/api": "^1.9.0",
"@opentelemetry/semantic-conventions": "^1.27.0",
"pino": "^9.5.0",
"ramda": "^0.30.1",
"split2": "^4.2.0"
},
"jest": {
"preset": "ts-jest",
Expand Down
12 changes: 6 additions & 6 deletions packages/pino-opentelemetry/src/openTelemetryTracingTransport.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// This source code is licensed under the MIT license.

import { Attributes, trace } from '@opentelemetry/api'
import { SemanticAttributes } from '@opentelemetry/semantic-conventions'
import { SEMATTRS_EXCEPTION_MESSAGE, SEMATTRS_EXCEPTION_STACKTRACE, SEMATTRS_EXCEPTION_TYPE } from '@opentelemetry/semantic-conventions'
import pino from 'pino'
import split from 'split2'

Expand All @@ -16,15 +16,15 @@ function setTags(logObj: any) {
if (logObj.level >= pino.levels.values['error']) {
if (exception) {
if (exception.code) {
attributes[SemanticAttributes.EXCEPTION_TYPE] = exception.code.toString()
attributes[SEMATTRS_EXCEPTION_TYPE] = exception.code.toString()
} else if (exception.name) {
attributes[SemanticAttributes.EXCEPTION_TYPE] = exception.name
attributes[SEMATTRS_EXCEPTION_TYPE] = exception.name
}
if (exception.message) {
attributes[SemanticAttributes.EXCEPTION_MESSAGE] = exception.message
attributes[SEMATTRS_EXCEPTION_MESSAGE] = exception.message
}
if (exception.stack) {
attributes[SemanticAttributes.EXCEPTION_STACKTRACE] = exception.stack
attributes[SEMATTRS_EXCEPTION_STACKTRACE] = exception.stack
}
}
}
Expand All @@ -37,7 +37,7 @@ function setTags(logObj: any) {
* @param _options - options for creating the stream
* @returns - the pino stream
*/
export default function (_options: {} = {}) {
export default function (_options: object = {}) {
const result = split((data: string) => {
try {
const log = JSON.parse(data)
Expand Down
Loading

0 comments on commit 31d2ace

Please sign in to comment.