Skip to content

Commit 03d9c29

Browse files
committed
Add namespaces to debug methods
1 parent 6f5728a commit 03d9c29

File tree

8 files changed

+263
-26
lines changed

8 files changed

+263
-26
lines changed

package-lock.json

Lines changed: 161 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

registry/lib/constants/env.d.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
declare interface ENV {
22
readonly CI: boolean
3+
readonly DEBUG: string
34
readonly NODE_AUTH_TOKEN: string
45
readonly NODE_ENV: string
56
readonly PRE_COMMIT: boolean
7+
readonly SOCKET_CLI_DEBUG: boolean
68
readonly TAP: boolean
79
readonly VITEST: boolean
810
}

registry/lib/constants/env.js

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,18 @@ const { envAsBoolean, envAsString } = /*@__PURE__*/ require('../env')
44

55
const { env } = process
66

7+
const DEBUG = envAsString(env.DEBUG)
8+
79
module.exports = Object.freeze({
810
__proto__: null,
911
// CI is always set to 'true' in a GitHub action.
1012
// https://docs.github.com/en/actions/writing-workflows/choosing-what-your-workflow-does/store-information-in-variables#default-environment-variables
1113
CI: envAsBoolean(env.CI),
14+
// Flag set to enable debug logging.
15+
DEBUG,
16+
// Variable to set the debug log level
17+
// (notice, error, warn, info, verbose, http, silly).
18+
LOG_LEVEL: envAsString(env.LOG_LEVEL),
1219
// .github/workflows/provenance.yml defines this.
1320
// https://docs.github.com/en/actions/use-cases-and-examples/publishing-packages/publishing-nodejs-packages
1421
NODE_AUTH_TOKEN: envAsString(env.NODE_AUTH_TOKEN),
@@ -20,10 +27,8 @@ module.exports = Object.freeze({
2027
// PRE_COMMIT is set to '1' by our 'test-pre-commit' script run by the
2128
// .husky/pre-commit hook.
2229
PRE_COMMIT: envAsBoolean(env.PRE_COMMIT),
23-
// Flag set to help debug Socket CLI.
24-
// eslint-disable-next-line no-warning-comments
25-
// TODO: Make the environment variable name configurable.
26-
SOCKET_CLI_DEBUG: envAsBoolean(env.SOCKET_CLI_DEBUG),
30+
// Flag set to enable debug logging in Socket CLI.
31+
SOCKET_CLI_DEBUG: !!DEBUG || envAsBoolean(env.SOCKET_CLI_DEBUG),
2732
// TAP=1 is set by the tap-run test runner.
2833
// https://node-tap.org/environment/#environment-variables-used-by-tap
2934
TAP: envAsBoolean(env.TAP),

registry/lib/debug.d.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
1+
import { InspectOptions } from 'node:util'
2+
13
declare const Debug: {
2-
isDebug(): boolean
3-
debugDir: typeof console.dir
4-
debugFn: typeof console.log
5-
debugLog: typeof console.log
4+
isDebug(namespace?: string | undefined): boolean
5+
debugDir(namespace: string, obj: any, options?: InspectOptions): void
6+
debugFn(namespace: string, message?: any, ...optionalParams: any[]): void
7+
debugLog(namespace: string, message?: any, ...optionalParams: any[]): void
68
}
79
declare namespace Debug {}
810
export = Debug

0 commit comments

Comments
 (0)