Skip to content

Commit

Permalink
feat: support custom reporters (#8)
Browse files Browse the repository at this point in the history
  • Loading branch information
maraisr authored May 27, 2021
1 parent 8a201f9 commit fb67814
Show file tree
Hide file tree
Showing 18 changed files with 551 additions and 2,105 deletions.
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,6 @@ node_modules

# Code
/types
/lib
/diary
/json
/utils
11 changes: 4 additions & 7 deletions bench/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
process.env.DEBUG = 'standard';
// @ts-ignore
process.env.ROARR_LOG = true; // for roarr
// @ts-nocheck

import { Suite } from 'benchmark';
import bunyan from 'bunyan';
Expand All @@ -11,7 +9,7 @@ import ulog from 'ulog';
import { Logger } from '@graphile/logger';
import { equal } from 'uvu/assert';
import winston from 'winston';
import { diary, after } from '../src';
import { diary } from '../src';

const trap_console = (verb: keyof typeof console) => {
const old = console[verb];
Expand Down Expand Up @@ -64,11 +62,10 @@ global.ROARR.write = ROARR.write = () => {};
(async function () {
await runner({
diary() {
const suite = diary('standard');
let events: any[] = [];
after((logEvent) => {
const suite = diary('standard', (logEvent) => {
events.push(logEvent);
}, suite);
});
suite.info('info message');
return events;
},
Expand Down
43 changes: 43 additions & 0 deletions bin/build.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
const pkg = require('../package.json');
const esbuild = require('esbuild');

const externals = ['diary/utils', 'diary'];

/**
* @param {string} input
* @param {Record<'import'|'require', string>} files
*/
async function bundle(input, files) {
await esbuild.build({
entryPoints: [input],
bundle: true,
format: 'esm',
platform: 'neutral',
outfile: files.import,
external: externals,
});

await esbuild.build({
entryPoints: [input],
bundle: true,
format: 'cjs',
platform: 'neutral',
outfile: files.require,
external: externals,
});
}

Promise.all([
bundle('src/index.ts', pkg.exports['.']),
bundle('src/json.ts', pkg.exports['./json']),
bundle('src/utils.ts', pkg.exports['./utils']),
esbuild.build({
entryPoints: ['src/index.ts'],
bundle: true,
format: 'cjs',
platform: 'browser',
outfile: 'diary/index.min.js',
minify: true,
external: externals,
}),
]);
2 changes: 1 addition & 1 deletion example.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { debug, diary, error, info, warn, log } from './src';
import { debug, diary, error, info, warn, log } from 'diary';

error('im a generic error');
warn('im a generic warn');
Expand Down
56 changes: 35 additions & 21 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "diary",
"version": "0.0.12",
"version": "0.1.1",
"description": "Fast logging library for both Node and Browser.",
"keywords": [
"fast",
Expand All @@ -18,25 +18,42 @@
"sideEffects": false,
"exports": {
".": {
"import": "./lib/index.mjs",
"require": "./lib/index.js"
"import": "./diary/index.mjs",
"require": "./diary/index.js"
},
"./json": {
"import": "./json/index.mjs",
"require": "./json/index.js"
},
"./utils": {
"import": "./utils/index.mjs",
"require": "./utils/index.js"
},
"./package.json": "./package.json"
},
"main": "lib/index.js",
"unpkg": "lib/index.min.js",
"module": "lib/index.mjs",
"main": "diary/index.js",
"unpkg": "diary/index.min.js",
"module": "diary/index.mjs",
"types": "types/index.d.ts",
"typesVersions": {
"*": {
"*": [
"types/*"
]
}
},
"files": [
"types",
"lib"
"diary",
"json",
"utils"
],
"scripts": {
"bench": "node -r ts-node/register bench/index.ts",
"build": "rollup -c",
"format": "prettier --write --list-different \"{*,bench/**/*,.github/**/*}.+(ts|json|yml|md)\"",
"bench": "cross-env TS_NODE_PROJECT=tsconfig.test.json DEBUG=standard ROARR_LOG=true node -r ts-eager/register bench/index.ts",
"build": "node bin/build && tsc --declaration true --emitDeclarationOnly --outDir types --rootDir src --noEmit false",
"format": "prettier --write --list-different \"{*,bench/**/*,.github/**/*,test/*}.+(ts|json|yml|md)\"",
"prepublishOnly": "pnpm run build",
"test": "cross-env DEBUG=* uvu -r ts-node/register -i helpers.ts test",
"test": "cross-env DEBUG=* TS_NODE_PROJECT=tsconfig.test.json uvu -r ts-eager/register -i helpers.ts test",
"typecheck": "tsc --noEmit"
},
"prettier": {
Expand All @@ -62,24 +79,21 @@
]
},
"devDependencies": {
"@graphile/logger": "^0.2.0",
"@graphile/logger": "0.2.0",
"@marais/tsconfig": "0.0.1",
"@rollup/plugin-node-resolve": "13.0.0",
"@types/benchmark": "2.1.0",
"@types/node": "15.6.0",
"@types/node": "15.6.1",
"benchmark": "2.1.4",
"bunyan": "1.8.15",
"cross-env": "^7.0.3",
"cross-env": "7.0.3",
"debug": "4.3.1",
"esbuild": "0.12.2",
"pino": "6.11.3",
"prettier": "2.3.0",
"roarr": "4.2.5",
"rollup": "2.48.0",
"rollup-plugin-dts": "3.0.2",
"rollup-plugin-filesize": "9.1.1",
"rollup-plugin-terser": "7.0.2",
"rollup-plugin-typescript2": "0.30.0",
"ts-node": "9.1.1",
"ts-eager": "2.0.2",
"tsconfig-paths": "3.9.0",
"tslib": "2.2.0",
"typescript": "4.2.4",
"ulog": "2.0.0-beta.18",
"uvu": "0.5.1",
Expand Down
Loading

0 comments on commit fb67814

Please sign in to comment.