@steve02081504/virtual-console 0.0.4 → 0.0.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/main.mjs +13 -8
  2. package/package.json +1 -1
package/main.mjs CHANGED
@@ -1,9 +1,11 @@
1
1
  import { AsyncLocalStorage } from 'node:async_hooks'
2
2
  import { Console } from 'node:console'
3
+ import process from 'node:process'
3
4
  import { Writable } from 'node:stream'
5
+
4
6
  import ansiEscapes from 'ansi-escapes'
5
- import supportsAnsi from 'supports-ansi'
6
7
  import { FullProxy } from 'full-proxy'
8
+ import supportsAnsi from 'supports-ansi'
7
9
 
8
10
  export const consoleAsyncStorage = new AsyncLocalStorage()
9
11
  const cleanupRegistry = new FinalizationRegistry(cleanupToken => {
@@ -71,8 +73,17 @@ export class VirtualConsole extends Console {
71
73
  ...options,
72
74
  }
73
75
  this.freshLine = this.freshLine.bind(this)
74
- this.error = this.error.bind(this)
75
76
  this.clear = this.clear.bind(this)
77
+ for (const method of ['log', 'info', 'warn', 'debug', 'error']) {
78
+ if (!this[method]) continue
79
+ const originalMethod = this[method]
80
+ this[method] = (...args) => {
81
+ if (method == 'error' && this.options.error_handler && args.length === 1 && args[0] instanceof Error) return this.options.error_handler(args[0])
82
+ if (!this.options.realConsoleOutput || this.options.recordOutput) return originalMethod.apply(this, args)
83
+ this.#loggedFreshLineId = null
84
+ return this.#base_console[method](...args)
85
+ }
86
+ }
76
87
  }
77
88
 
78
89
  get base_console() {
@@ -140,12 +151,6 @@ export class VirtualConsole extends Console {
140
151
  this.#loggedFreshLineId = id
141
152
  }
142
153
 
143
- error(...args) {
144
- if (this.options.error_handler && args.length === 1 && args[0] instanceof Error)
145
- return this.options.error_handler(args[0])
146
- super.error(...args)
147
- }
148
-
149
154
  clear() {
150
155
  this.#loggedFreshLineId = null
151
156
  this.outputs = ''
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@steve02081504/virtual-console",
3
- "version": "0.0.4",
3
+ "version": "0.0.6",
4
4
  "description": "A virtual console for capturing and manipulating terminal output.",
5
5
  "main": "main.mjs",
6
6
  "type": "module",