44 */
55
66import ENV from './constants/ENV'
7+ import {
8+ getDebug ,
9+ getIsUnicodeSupported ,
10+ getLogger ,
11+ getSpinner ,
12+ } from './dependencies/index'
713import { hasOwn } from './objects'
814import { applyLinePrefix } from './strings'
915
@@ -30,21 +36,6 @@ interface InspectOptions {
3036
3137export type { DebugOptions , NamespacesOrOptions , InspectOptions }
3238
33- let _debugJs : typeof import ( 'debug' ) | undefined
34- /**
35- * Lazily load the debug module.
36- * @private
37- */
38- /*@__NO_SIDE_EFFECTS__ */
39- function getDebugJs ( ) {
40- if ( _debugJs === undefined ) {
41- // The 'debug' package is browser safe.
42- const debugExport = /*@__PURE__ */ require ( '../external/debug' )
43- _debugJs = debugExport . default
44- }
45- return _debugJs !
46- }
47-
4839const debugByNamespace = new Map ( )
4940/**
5041 * Get or create a debug instance for a namespace.
@@ -56,7 +47,7 @@ function getDebugJsInstance(namespace: string) {
5647 if ( inst ) {
5748 return inst
5849 }
59- const debugJs = getDebugJs ( )
50+ const debugJs = getDebug ( )
6051 if (
6152 ! ENV . DEBUG &&
6253 ENV . SOCKET_CLI_DEBUG &&
@@ -91,8 +82,8 @@ function getUtil() {
9182 */
9283/*@__NO_SIDE_EFFECTS__ */
9384function customLog ( ) {
94- const { logger } = /* @__PURE__ */ require ( './logger.js' )
95- const debugJs = getDebugJs ( )
85+ const logger = getLogger ( )
86+ const debugJs = getDebug ( )
9687 const util = getUtil ( )
9788 const inspectOpts = debugJs . inspectOpts
9889 ? {
@@ -118,10 +109,10 @@ function customLog() {
118109 * @private
119110 */
120111/*@__NO_SIDE_EFFECTS__ */
121- function extractOptions ( namespaces : NamespacesOrOptions ) {
112+ function extractOptions ( namespaces : NamespacesOrOptions ) : DebugOptions {
122113 return namespaces !== null && typeof namespaces === 'object'
123- ? { __proto__ : null , ...namespaces }
124- : { __proto__ : null , namespaces }
114+ ? ( { __proto__ : null , ...namespaces } as DebugOptions )
115+ : ( { __proto__ : null , namespaces } as DebugOptions )
125116}
126117
127118/**
@@ -166,11 +157,11 @@ function debugDirNs(
166157) {
167158 const options = extractOptions ( namespacesOrOpts )
168159 const { namespaces } = options
169- if ( ! isEnabled ( namespaces ) ) {
160+ if ( ! isEnabled ( namespaces as string ) ) {
170161 return
171162 }
172163 if ( inspectOpts === undefined ) {
173- const debugJs = getDebugJs ( )
164+ const debugJs = getDebug ( )
174165 const opts = debugJs . inspectOpts
175166 if ( opts ) {
176167 inspectOpts = {
@@ -183,10 +174,10 @@ function debugDirNs(
183174 } as InspectOptions
184175 }
185176 }
186- const { spinner = /* @__PURE__ */ require ( './constants/ spinner.js' ) } = options
177+ const spinner = options . spinner || getSpinner ( )
187178 const wasSpinning = spinner . isSpinning
188179 spinner . stop ( )
189- const { logger } = /* @__PURE__ */ require ( './logger.js' )
180+ const logger = getLogger ( )
190181 logger . dir ( obj , inspectOpts )
191182 if ( wasSpinning ) {
192183 spinner . start ( )
@@ -201,7 +192,7 @@ let pointingTriangle: string | undefined
201192function debugFnNs ( namespacesOrOpts : NamespacesOrOptions , ...args : unknown [ ] ) {
202193 const options = extractOptions ( namespacesOrOpts )
203194 const { namespaces } = options
204- if ( ! isEnabled ( namespaces ) ) {
195+ if ( ! isEnabled ( namespaces as string ) ) {
205196 return
206197 }
207198 const { stack } = new Error ( )
@@ -240,8 +231,8 @@ function debugFnNs(namespacesOrOpts: NamespacesOrOptions, ...args: unknown[]) {
240231 }
241232 }
242233 if ( pointingTriangle === undefined ) {
243- const supported =
244- /* @__PURE__ */ require ( '../external/@socketregistry/is-unicode-supported' ) ( )
234+ const isUnicodeSupported = getIsUnicodeSupported ( )
235+ const supported = isUnicodeSupported ( )
245236 pointingTriangle = supported ? '▸' : '>'
246237 }
247238 const text = args . at ( 0 )
@@ -255,10 +246,10 @@ function debugFnNs(namespacesOrOpts: NamespacesOrOptions, ...args: unknown[]) {
255246 ...args . slice ( 1 ) ,
256247 ]
257248 : args
258- const { spinner = /* @__PURE__ */ require ( './constants/ spinner.js' ) } = options
249+ const spinner = options . spinner || getSpinner ( )
259250 const wasSpinning = spinner . isSpinning
260251 spinner . stop ( )
261- const { logger } = /* @__PURE__ */ require ( './logger.js' )
252+ const logger = getLogger ( )
262253 ReflectApply ( logger . info , logger , logArgs )
263254 if ( wasSpinning ) {
264255 spinner . start ( )
@@ -272,10 +263,10 @@ function debugFnNs(namespacesOrOpts: NamespacesOrOptions, ...args: unknown[]) {
272263function debugLogNs ( namespacesOrOpts : NamespacesOrOptions , ...args : unknown [ ] ) {
273264 const options = extractOptions ( namespacesOrOpts )
274265 const { namespaces } = options
275- if ( ! isEnabled ( namespaces ) ) {
266+ if ( ! isEnabled ( namespaces as string ) ) {
276267 return
277268 }
278- const { spinner = /* @__PURE__ */ require ( './constants/ spinner.js' ) } = options
269+ const spinner = options . spinner || getSpinner ( )
279270 const wasSpinning = spinner . isSpinning
280271 spinner . stop ( )
281272 ReflectApply ( customLog , undefined , args )
0 commit comments