Skip to content

Commit

Permalink
Merge pull request #26 from commenthol/chore-bump
Browse files Browse the repository at this point in the history
Chore bump
  • Loading branch information
commenthol authored Jul 21, 2024
2 parents 2b52bd9 + f3931fe commit 082a14e
Show file tree
Hide file tree
Showing 22 changed files with 99 additions and 76 deletions.
23 changes: 11 additions & 12 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
# This workflow will do a clean install of node dependencies, cache/restore them, build the source code and run tests across different versions of node
# For more information see: https://github.com/marketplace/actions/setup-node-js-environment
# @see: https://github.com/marketplace/actions/setup-node-js-environment

name: CI

Expand All @@ -17,14 +16,14 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
node-version: [18.x, 20.x]
# See supported Node.js release schedule at https://nodejs.org/en/about/releases/
node: [ 20 ]
name: Node ${{ matrix.node }}
steps:
- uses: actions/checkout@v3
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v3
with:
node-version: ${{ matrix.node-version }}
# cache: 'npm'
- run: npm install --ignore-scripts
- run: npm run all
- uses: actions/checkout@v4
- name: Setup node
uses: actions/setup-node@v4
with:
node-version: ${{ matrix.node }}
- run: npm version
- run: npm install --ignore-scripts
- run: npm run all
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,5 @@ tmp/
package-lock.json
yarn.lock
pnpm-lock.yaml

.env*
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
> debug with levels
[![NPM version](https://badge.fury.io/js/debug-level.svg)](https://www.npmjs.com/package/debug-level/)
[![Build Status](https://github.com/commenthol/debug-level/workflows/CI/badge.svg?branch=main&event=push)](https://github.com/commenthol/debug-level/actions/workflows/ci.yml?query=branch%3Amain)
[![CI](https://github.com/commenthol/debug-level/actions/workflows/ci.yml/badge.svg?branch=main)](https://github.com/commenthol/debug-level/actions/workflows/ci.yml)

A universal JavaScript logging/ debugging utility which works in node and
browsers.
Expand Down
25 changes: 12 additions & 13 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,6 @@
"example": "npm run build:example && npm run start:example",
"changelog": "conv-changelog -i CHANGELOG.md -o",
"lint": "eslint --ext .js .",
"prepublishOnly": "npm run all",
"readme": "markedpp --github -i README.md -o README.md",
"start:example": "DEBUG=* node examples/app/server.cjs",
"test": "mocha",
Expand All @@ -79,15 +78,15 @@
"flatstr": "^1.0.12",
"map-lru": "^2.0.0",
"ms": "^2.1.3",
"sonic-boom": "^3.8.0"
"sonic-boom": "^4.0.1"
},
"devDependencies": {
"@babel/cli": "^7.23.9",
"@babel/core": "^7.24.0",
"@babel/preset-env": "^7.24.0",
"@babel/cli": "^7.24.8",
"@babel/core": "^7.24.9",
"@babel/preset-env": "^7.24.8",
"assert": "^2.1.0",
"babel-loader": "^9.1.3",
"c8": "^9.1.0",
"c8": "^10.1.2",
"conv-changelog": "^1.0.0",
"eslint": "^8.57.0",
"eslint-config-standard": "^17.1.0",
Expand All @@ -102,13 +101,13 @@
"karma-sourcemap-loader": "^0.4.0",
"karma-spec-reporter": "^0.0.36",
"karma-webpack": "^5.0.1",
"mocha": "^10.3.0",
"npm-run-all2": "^6.1.2",
"rimraf": "^5.0.5",
"rollup": "^4.13.0",
"sinon": "^17.0.1",
"typescript": "^5.4.2",
"webpack": "^5.90.3",
"mocha": "^10.7.0",
"npm-run-all2": "^6.2.2",
"rimraf": "^6.0.1",
"rollup": "^4.19.0",
"sinon": "^18.0.0",
"typescript": "^5.5.3",
"webpack": "^5.93.0",
"webpack-cli": "^5.1.4"
},
"optionalDependencies": {
Expand Down
13 changes: 11 additions & 2 deletions src/Format.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,22 @@ export class Format {
}

_formatOpts () {
/**
* @param {any} any
* @returns {string}
*/
// @ts-expect-error
const stringify = (any) => fastStringify(any, null, this.opts.spaces)
this.formatOpts = {
// @ts-expect-error
stringify: (o) => fastStringify(o, null, this.opts.spaces),
stringify,
spaces: this.opts.spaces
}
}

/**
* @param {...any} args
* @returns {string}
*/
stringify (...args) {
// @ts-expect-error
return fastStringify(...args)
Expand Down
2 changes: 1 addition & 1 deletion src/LogBase.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ const time = {
}

/**
* @typedef {import('./utils').Level} Level
* @typedef {import('./utils.js').Level} Level
*
* @typedef {object} ExtLogBaseOptions
* @property {Level} [level] log level
Expand Down
13 changes: 9 additions & 4 deletions src/Sonic.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ export class Sonic {

const { fd, path } = streamDescriptor(stream)

/** @type {import('sonic-boom').SonicBoom} */
// @ts-expect-error
this.stream = new SonicBoom({ fd, dest: path, minLength, sync: true })
this.stream.on('error', filterBrokenPipe.bind(null, this.stream))

Expand Down Expand Up @@ -90,10 +92,13 @@ export class SonicStreams extends Map {
* @returns {string}
*/
static hash (opts) {
return 'sonic!' + Object.keys(opts || {})
.sort()
.map((key) => `${key}:${opts[key]}`)
.join('!')
return (
'sonic!' +
Object.keys(opts || {})
.sort()
.map((key) => `${key}:${opts[key]}`)
.join('!')
)
}

/**
Expand Down
4 changes: 2 additions & 2 deletions src/browser.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ import { wrapConsole } from './wrapConsole.js'
import { errSerializer } from './serializers/err.js'

/**
* @typedef {import('./utils').Level} Level
* @typedef {import('./LogBase').LogBaseOptions} LogBaseOptions
* @typedef {import('./utils.js').Level} Level
* @typedef {import('./LogBase.js').LogBaseOptions} LogBaseOptions
*
* @typedef {object} ExtLogOptionsBrowser
* @property {string} [url] url to report errors
Expand Down
1 change: 0 additions & 1 deletion src/httpLogs.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ export function httpLogs (namespace, opts) {
}
options.serializers = {
...serializers,
// @ts-expect-error
...(options.Log.serializers || {}),
...(options.serializers || {})
}
Expand Down
2 changes: 1 addition & 1 deletion src/index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/** @typedef {import('./utils').Level} Level */
/** @typedef {import('./utils.js').Level} Level */
/** @typedef {import('./node.js').LogOptions & {Log: typeof Log}} LogOptions */
/** @typedef {import('./node.js').LogOptionWrapConsole} LogOptionWrapConsole */
/** @typedef {import('./node.js').LogOptionHandleExitEvents} LogOptionHandleExitEvents */
Expand Down
9 changes: 6 additions & 3 deletions src/node.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,16 @@ import { LogBase } from './LogBase.js'
import { wrapConsole } from './wrapConsole.js'
import { wrapDebug } from './wrapDebug.js'
import { Sonic, sonicStreams } from './Sonic.js'
import { errSerializer } from './serializers/err.js'
import { errSerializer } from './serializers/index.js'
import { Format } from './Format.js'

const env = process.env.NODE_ENV || 'development'
const isDevEnv = /^dev/.test(env) // anything which starts with dev is seen as development env

const EXIT_EVENTS = ['unhandledRejection', 'uncaughtException']

/** @typedef {import('./LogBase').LogBaseOptions} LogBaseOptions */
/** @typedef {import('./utils').Level} Level */
/** @typedef {import('./LogBase.js').LogBaseOptions} LogBaseOptions */
/** @typedef {import('./utils.js').Level} Level */
/**
* @typedef {object} ExtLogOptions
* @property {boolean} [serverinfo] log serverinfo like hostname and pid
Expand Down Expand Up @@ -304,6 +304,9 @@ export class Log extends LogBase {

Log.isDevEnv = isDevEnv
Log.Sonic = Sonic
Log.serializers = {
err: errSerializer
}

/**
* @credits pino/lib/tools.js
Expand Down
15 changes: 7 additions & 8 deletions tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,22 +1,21 @@
{
"compilerOptions": {
"allowSyntheticDefaultImports": true,
"allowJs": true,
"allowSyntheticDefaultImports": true,
"checkJs": true,
"declaration": true,
"declarationDir": "types",
"moduleResolution": "node",
"emitDeclarationOnly": true,
"module": "nodenext",
"moduleResolution": "nodenext",
"noEmitOnError": false,
"noImplicitAny": false,
"skipLibCheck": true,
"strict": true,
"module": "esnext",
"target": "esnext",
"emitDeclarationOnly": true,
"noEmitOnError": true
},
"include": [
"src/*.js",
"src/serializers/*.js",
"src/ecs/*.js",
"src",
],
"exclude": [
"node_modules",
Expand Down
6 changes: 5 additions & 1 deletion types/Format.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,13 @@ export class Format {
get spaces(): number | undefined;
_formatOpts(): void;
formatOpts: {
stringify: (o: any) => string;
stringify: (any: any) => string;
spaces: number | undefined;
} | undefined;
/**
* @param {...any} args
* @returns {string}
*/
stringify(...args: any[]): string;
/**
* formats arguments like `util.format`
Expand Down
8 changes: 4 additions & 4 deletions types/LogBase.d.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* @typedef {import('./utils').Level} Level
* @typedef {import('./utils.js').Level} Level
*
* @typedef {object} ExtLogBaseOptions
* @property {Level} [level] log level
Expand Down Expand Up @@ -67,8 +67,8 @@ export class LogBase {
*/
protected _log(nlevel: any, fmt: any, args: any): void;
}
export type Timestamp = 'epoch' | 'unix' | 'iso';
export type Level = import('./utils').Level;
export type Timestamp = "epoch" | "unix" | "iso";
export type Level = import("./utils.js").Level;
export type ExtLogBaseOptions = {
/**
* log level
Expand Down Expand Up @@ -107,6 +107,6 @@ export type ExtLogBaseOptions = {
*/
serializers?: object;
};
export type FormatOption = import('./Format.js').FormatOption;
export type FormatOption = import("./Format.js").FormatOption;
export type LogBaseOptions = FormatOption & ExtLogBaseOptions;
import { Format } from './Format.js';
4 changes: 2 additions & 2 deletions types/Sonic.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ export class Sonic {
constructor(stream: NodeJS.WriteStream, opts?: SonicOptions);
_timer: any;
_timeout: number;
stream: SonicBoom;
/** @type {import('sonic-boom').SonicBoom} */
stream: import("sonic-boom").SonicBoom;
/**
* @param {string} data
* @returns {boolean}
Expand Down Expand Up @@ -46,4 +47,3 @@ export type SonicOptions = {
*/
timeout?: number | undefined;
};
import SonicBoom from 'sonic-boom';
8 changes: 4 additions & 4 deletions types/browser.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ export class Log extends LogBase {
/**
* log level
*/
level: import("./utils.js").Level;
level: import("./LogBase.js").Level;
/**
* namespaces for logging
*/
Expand Down Expand Up @@ -73,7 +73,7 @@ export class Log extends LogBase {
/**
* serializers to be applied on object properties
*/
serializers: any;
serializers: object;
/**
* url to report errors
*/
Expand Down Expand Up @@ -127,8 +127,8 @@ export namespace Log {
}
}
export default Log;
export type Level = import('./utils').Level;
export type LogBaseOptions = import('./LogBase').LogBaseOptions;
export type Level = import("./utils.js").Level;
export type LogBaseOptions = import("./LogBase.js").LogBaseOptions;
export type ExtLogOptionsBrowser = {
/**
* url to report errors
Expand Down
2 changes: 1 addition & 1 deletion types/ecs/LogEcs.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export namespace LogEcs {
export { ecsSerializers as serializers };
}
export type EcsSerializer = (val: any, escFields: object) => void;
export type LogOptionsEcs = import('../node.js').LogOptions & {
export type LogOptionsEcs = import("../node.js").LogOptions & {
serializers: Record<string, EcsSerializer>;
};
import { Log } from '../node.js';
Expand Down
6 changes: 3 additions & 3 deletions types/httpLogs.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@
* @returns {(req: IncomingMessageWithId, res: ServerResponse, next: Function) => void} connect middleware
*/
export function httpLogs(namespace?: string | undefined, opts?: LogOptionsHttpLog | undefined): (req: IncomingMessageWithId, res: ServerResponse, next: Function) => void;
export type IncomingMessage = import('node:http').IncomingMessage;
export type ServerResponse = import('node:http').ServerResponse;
export type LogOptions = import('./node.js').LogOptions;
export type IncomingMessage = import("node:http").IncomingMessage;
export type ServerResponse = import("node:http").ServerResponse;
export type LogOptions = import("./node.js").LogOptions;
export type ExtIncomingMessageId = {
/**
* request Id
Expand Down
16 changes: 8 additions & 8 deletions types/index.d.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
export default Log;
export type Level = import('./utils').Level;
export type LogOptions = import('./node.js').LogOptions & {
export type Level = import("./utils.js").Level;
export type LogOptions = import("./node.js").LogOptions & {
Log: typeof Log;
};
export type LogOptionWrapConsole = import('./node.js').LogOptionWrapConsole;
export type LogOptionHandleExitEvents = import('./node.js').LogOptionHandleExitEvents;
export type LogOptionsEcs = import('./ecs/LogEcs.js').LogOptionsEcs;
export type MwLogOption = import('./browserLogs.js').MwLogOption;
export type LogOptionsHttpLog = import('./httpLogs.js').LogOptionsHttpLog;
export type IncomingMessageWithId = import('./httpLogs.js').IncomingMessageWithId;
export type LogOptionWrapConsole = import("./node.js").LogOptionWrapConsole;
export type LogOptionHandleExitEvents = import("./node.js").LogOptionHandleExitEvents;
export type LogOptionsEcs = import("./ecs/LogEcs.js").LogOptionsEcs;
export type MwLogOption = import("./browserLogs.js").MwLogOption;
export type LogOptionsHttpLog = import("./httpLogs.js").LogOptionsHttpLog;
export type IncomingMessageWithId = import("./httpLogs.js").IncomingMessageWithId;
import { Log } from './node.js';
import { LogEcs } from './ecs/LogEcs.js';
import { logger } from './logger.js';
Expand Down
2 changes: 1 addition & 1 deletion types/logger.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@
* @param {LogOptions} [opts]
*/
export function logger(namespace: string, opts?: import("./index.js").LogOptions | undefined): any;
export type LogOptions = import('./index.js').LogOptions;
export type LogOptions = import("./index.js").LogOptions;
Loading

0 comments on commit 082a14e

Please sign in to comment.