@steve02081504/virtual-console 0.0.7 → 0.0.8

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 (3) hide show
  1. package/browser.mjs +15 -14
  2. package/main.mjs +1 -3
  3. package/package.json +1 -1
package/browser.mjs CHANGED
@@ -16,7 +16,7 @@ function formatArgs(args) {
16
16
  if (arg instanceof Error && arg.stack) return arg.stack
17
17
  try {
18
18
  return JSON.stringify(arg, null, '\t')
19
- }
19
+ }
20
20
  catch {
21
21
  return String(arg)
22
22
  }
@@ -56,25 +56,25 @@ export class VirtualConsole {
56
56
  }
57
57
 
58
58
  const methods = ['log', 'info', 'warn', 'debug', 'error', 'table', 'dir', 'assert', 'count', 'countReset', 'time', 'timeLog', 'timeEnd', 'group', 'groupCollapsed', 'groupEnd']
59
- for (const method of methods)
60
- if (typeof this.#base_console[method] === 'function')
59
+ for (const method of methods)
60
+ if (typeof this.#base_console[method] === 'function')
61
61
  this[method] = (...args) => {
62
62
  this.#loggedFreshLineId = null // 任何常规输出都会中断 freshLine 序列
63
-
63
+
64
64
  if (this.options.recordOutput)
65
65
  this.outputs += formatArgs(args) + '\n'
66
-
66
+
67
67
  // 实际输出
68
68
  if (this.options.realConsoleOutput)
69
69
  this.#base_console[method](...args)
70
70
  }
71
-
72
-
71
+
72
+
73
73
 
74
74
  this.freshLine = this.freshLine.bind(this)
75
75
  this.clear = this.clear.bind(this)
76
76
  }
77
-
77
+
78
78
  /**
79
79
  * 在新的异步上下文中执行fn,并将该上下文的控制台替换为此对象。
80
80
  * 这是对 Node.js 中 AsyncLocalStorage.run 的浏览器模拟。
@@ -123,9 +123,9 @@ export class VirtualConsole {
123
123
  clear() {
124
124
  this.#loggedFreshLineId = null
125
125
  this.outputs = ''
126
- if (this.options.realConsoleOutput)
126
+ if (this.options.realConsoleOutput)
127
127
  this.#base_console.clear()
128
-
128
+
129
129
  }
130
130
  }
131
131
 
@@ -148,9 +148,9 @@ let consoleReflectSet = (v) => {
148
148
  currentAsyncConsole = v
149
149
  }
150
150
 
151
- /**
151
+ /**
152
152
  * @template T
153
- * @type {(value: VirtualConsole, fn: () => T | Promise<T>) => Promise<T>}
153
+ * @type {(value: VirtualConsole, fn: () => T | Promise<T>) => Promise<T>}
154
154
  */
155
155
  let consoleReflectRun = async (v, fn) => {
156
156
  const previousConsole = currentAsyncConsole
@@ -158,7 +158,8 @@ let consoleReflectRun = async (v, fn) => {
158
158
  try {
159
159
  const result = fn()
160
160
  return await Promise.resolve(result)
161
- } finally {
161
+ }
162
+ finally {
162
163
  currentAsyncConsole = previousConsole
163
164
  }
164
165
  }
@@ -188,4 +189,4 @@ export const console = globalThis.console = new FullProxy(() => Object.assign({}
188
189
  globalConsoleAdditionalProperties[property] = value
189
190
  return true
190
191
  }
191
- })
192
+ })
package/main.mjs CHANGED
@@ -1,6 +1,4 @@
1
- const module = await import(
2
- globalThis.document ? './browser.mjs' : './node.mjs'
3
- )
1
+ const module = await import(globalThis.document ? './browser.mjs' : './node.mjs')
4
2
 
5
3
  export const consoleAsyncStorage = module.consoleAsyncStorage
6
4
  export const VirtualConsole = module.VirtualConsole
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@steve02081504/virtual-console",
3
- "version": "0.0.7",
3
+ "version": "0.0.8",
4
4
  "description": "A virtual console for capturing and manipulating terminal output.",
5
5
  "main": "main.mjs",
6
6
  "type": "module",