[READ-ONLY] a fast, modern browser for the npm registry
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

feat: add debug mode to npmx-connector (#912)

authored by

Mikołaj Misztal and committed by
GitHub
1f03429e 8571a329

+17 -3
+1
cli/package.json
··· 28 28 "scripts": { 29 29 "build": "tsdown", 30 30 "dev": "NPMX_CLI_DEV=true node src/cli.ts", 31 + "dev:debug": "DEBUG=npmx-connector NPMX_CLI_DEV=true node src/cli.ts", 31 32 "test:types": "tsc --noEmit" 32 33 }, 33 34 "dependencies": {
+16 -3
cli/src/npm-client.ts
··· 7 7 import { join } from 'node:path' 8 8 import * as v from 'valibot' 9 9 import { PackageNameSchema, UsernameSchema, OrgNameSchema, ScopeTeamSchema } from './schemas.ts' 10 - import { logCommand, logSuccess, logError } from './logger.ts' 10 + import { logCommand, logSuccess, logError, logDebug } from './logger.ts' 11 11 12 12 const execFileAsync = promisify(execFile) 13 13 ··· 75 75 'EOTP', 76 76 'one-time password', 77 77 'This operation requires a one-time password', 78 + 'OTP required for authentication', 78 79 '--otp=<code>', 79 80 ] 80 81 const lowerStderr = stderr.toLowerCase() 81 - return otpPatterns.some(pattern => lowerStderr.includes(pattern.toLowerCase())) 82 + logDebug('Checking for OTP requirement in stderr:', stderr) 83 + logDebug('OTP patterns:', otpPatterns) 84 + const result = otpPatterns.some(pattern => lowerStderr.includes(pattern.toLowerCase())) 85 + logDebug('OTP required:', result) 86 + return result 82 87 } 83 88 84 89 function detectAuthFailure(stderr: string): boolean { ··· 96 101 'npm adduser', 97 102 ] 98 103 const lowerStderr = stderr.toLowerCase() 99 - return authPatterns.some(pattern => lowerStderr.includes(pattern.toLowerCase())) 104 + logDebug('Checking for auth failure in stderr:', stderr) 105 + logDebug('Auth patterns:', authPatterns) 106 + const result = authPatterns.some(pattern => lowerStderr.includes(pattern.toLowerCase())) 107 + logDebug('Auth failure:', result) 108 + return result 100 109 } 101 110 102 111 function filterNpmWarnings(stderr: string): string { ··· 123 132 } 124 133 125 134 try { 135 + logDebug('Executing npm command:', { command: 'npm', args: npmArgs }) 126 136 // Use execFile instead of exec to avoid shell injection vulnerabilities 127 137 // On Windows, shell: true is required to execute .cmd files (like npm.cmd) 128 138 // On Unix, we keep it false for better security and performance ··· 131 141 env: { ...process.env, FORCE_COLOR: '0' }, 132 142 shell: process.platform === 'win32', 133 143 }) 144 + 145 + logDebug('Command succeeded:', { stdout, stderr }) 134 146 135 147 if (!options.silent) { 136 148 logSuccess('Done') ··· 144 156 } catch (error) { 145 157 const err = error as { stdout?: string; stderr?: string; code?: number } 146 158 const stderr = err.stderr?.trim() ?? String(error) 159 + logDebug('Command failed:', { error, stdout: err.stdout, stderr: err.stderr, code: err.code }) 147 160 const requiresOtp = detectOtpRequired(stderr) 148 161 const authFailure = detectAuthFailure(stderr) 149 162