File tree Expand file tree Collapse file tree 4 files changed +69
-59
lines changed
Expand file tree Collapse file tree 4 files changed +69
-59
lines changed Original file line number Diff line number Diff line change 11#!/usr/bin/env node
22
33import { cosmiconfig } from 'cosmiconfig' ;
4+ import { useLoggingForCLI } from './utils/cli-logger.mjs' ;
45import { logger } from './utils/logger.mjs' ;
56import { build } from './index.mjs' ;
67
78try {
9+ await useLoggingForCLI ( ) ;
810 const explorer = cosmiconfig ( 'esbuild-jest' ) ;
911 const esbuildJestBaseConfig = await explorer . search ( ) ;
1012 await logger . trace . complete ( esbuildJestBaseConfig , 'esbuild-jest-cli' , ( ) => build ( esbuildJestBaseConfig . config ) ) ;
Original file line number Diff line number Diff line change 3232 },
3333 "homepage" : " https://github.com/wix-incubator/esbuild-jest-cli#readme" ,
3434 "dependencies" : {
35- "bunyamin" : " ^1.5.1" ,
36- "bunyan" : " ^2.0.0" ,
37- "bunyan-debug-stream" : " ^3.1.0" ,
38- "cosmiconfig" : " ^8.1.3" ,
35+ "bunyamin" : " ^1.6.3" ,
3936 "find-up" : " ^7.0.0" ,
4037 "import-from" : " ^4.0.0" ,
4138 "lodash.merge" : " ^4.6.2" ,
4239 "resolve-from" : " ^5.0.0"
4340 },
41+ "optionalDependencies" : {
42+ "bunyan" : " ^2.0.0" ,
43+ "bunyan-debug-stream" : " ^3.1.0" ,
44+ "cosmiconfig" : " ^9.0.0"
45+ },
4446 "peerDependencies" : {
4547 "esbuild" : " >=0.17.4"
4648 },
4749 "devDependencies" : {
4850 "@jest/transform" : " ^29.6.3" ,
4951 "@jest/types" : " ^29.6.3" ,
50- "esbuild" : " ^0.21.4 "
52+ "esbuild" : " ^0.24.2 "
5153 }
5254}
Original file line number Diff line number Diff line change 1+ import * as fs from 'node:fs' ;
2+ import * as path from 'node:path' ;
3+ import {
4+ bunyamin ,
5+ threadGroups ,
6+ traceEventStream ,
7+ } from 'bunyamin' ;
8+
9+ const PACKAGE_NAME = 'esbuild-jest-cli' ;
10+
11+ export async function useLoggingForCLI ( ) {
12+ const bunyan = await import ( 'bunyan' ) ;
13+ const bds = await import ( 'bunyan-debug-stream' ) ;
14+ const logPath = process . env . BUNYAMIN_LOG ;
15+
16+ const logger = bunyan . createLogger ( {
17+ name : PACKAGE_NAME ,
18+ streams : [
19+ {
20+ type : 'raw' ,
21+ level : 'warn' ,
22+ stream : bds . create ( {
23+ out : process . stderr ,
24+ showMetadata : false ,
25+ showDate : false ,
26+ showPid : false ,
27+ showProcess : false ,
28+ showLoggerName : false ,
29+ showLevel : false ,
30+ prefixers : {
31+ cat : ( value ) => String ( value ) . split ( ',' , 1 ) [ 0 ] ,
32+ } ,
33+ } ) ,
34+ } ,
35+ ...( logPath
36+ ? [
37+ {
38+ type : 'raw' ,
39+ level : 'trace' ,
40+ stream : traceEventStream ( {
41+ filePath : ensureCleanLog ( logPath ) ,
42+ threadGroups,
43+ } ) ,
44+ } ,
45+ ]
46+ : [ ] ) ,
47+ ] ,
48+ } ) ;
49+
50+ bunyamin . useLogger ( logger , 1 ) ;
51+ }
52+
53+ function ensureCleanLog ( filePath ) {
54+ fs . mkdirSync ( path . dirname ( filePath ) , { recursive : true } ) ;
55+ if ( fs . existsSync ( filePath ) ) {
56+ fs . unlinkSync ( filePath ) ;
57+ }
58+
59+ return filePath ;
60+ }
Original file line number Diff line number Diff line change 1- import * as fs from 'node:fs' ;
2- import * as path from 'node:path' ;
31import {
42 bunyamin ,
53 nobunyamin ,
64 isDebug ,
75 threadGroups ,
8- traceEventStream ,
96} from 'bunyamin' ;
10- import { createLogger } from 'bunyan' ;
11- import { create as createDebugStream } from 'bunyan-debug-stream' ;
127
138const PACKAGE_NAME = 'esbuild-jest-cli' ;
149
@@ -23,8 +18,6 @@ threadGroups.add({
2318 maxConcurrency : 100500 ,
2419} ) ;
2520
26- bunyamin . useLogger ( createBunyanImpl ( ) , 1 ) ;
27-
2821export const logger = bunyamin . child ( { tid : PACKAGE_NAME } ) ;
2922export const optimizedLogger = isDebug ( PACKAGE_NAME )
3023 ? logger
@@ -35,50 +28,3 @@ const noop = () => {};
3528export const optimizeTracing = isDebug ( PACKAGE_NAME )
3629 ? ( ( f ) => f )
3730 : ( ( ) => noop ) ;
38-
39- function createBunyanImpl ( ) {
40- const logPath = process . env . BUNYAMIN_LOG ;
41-
42- return createLogger ( {
43- name : PACKAGE_NAME ,
44- streams : [
45- {
46- type : 'raw' ,
47- level : 'warn' ,
48- stream : createDebugStream ( {
49- out : process . stderr ,
50- showMetadata : false ,
51- showDate : false ,
52- showPid : false ,
53- showProcess : false ,
54- showLoggerName : false ,
55- showLevel : false ,
56- prefixers : {
57- cat : ( value ) => String ( value ) . split ( ',' , 1 ) [ 0 ] ,
58- } ,
59- } ) ,
60- } ,
61- ...( logPath
62- ? [
63- {
64- type : 'raw' ,
65- level : 'trace' ,
66- stream : traceEventStream ( {
67- filePath : ensureCleanLog ( logPath ) ,
68- threadGroups,
69- } ) ,
70- } ,
71- ]
72- : [ ] ) ,
73- ] ,
74- } ) ;
75- }
76-
77- function ensureCleanLog ( filePath ) {
78- fs . mkdirSync ( path . dirname ( filePath ) , { recursive : true } ) ;
79- if ( fs . existsSync ( filePath ) ) {
80- fs . unlinkSync ( filePath ) ;
81- }
82-
83- return filePath ;
84- }
You can’t perform that action at this time.
0 commit comments