Skip to content

Commit 3559ff7

Browse files
committed
Fix debug logging condition and consolidate duplicated logic in dlx.mts
- Changed condition from 'CI && VITEST' (string constants that are always truthy) to 'constants.ENV.CI && constants.ENV.VITEST' (actual boolean environment values) - Created logSpawnOutput() helper function to consolidate duplicated debug logging logic between success and error paths
1 parent 54ae20b commit 3559ff7

File tree

1 file changed

+20
-20
lines changed

1 file changed

+20
-20
lines changed

src/utils/dlx.mts

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,10 @@ import { spawn } from '@socketsecurity/registry/lib/spawn'
2525

2626
import { getDefaultOrgSlug } from '../commands/ci/fetch-default-org-slug.mts'
2727
import constants, {
28-
CI,
2928
FLAG_QUIET,
3029
FLAG_SILENT,
3130
NPM,
3231
PNPM,
33-
VITEST,
3432
YARN,
3533
} from '../constants.mts'
3634
import { getErrorCause } from './errors.mts'
@@ -44,6 +42,24 @@ import type { SpawnExtra } from '@socketsecurity/registry/lib/spawn'
4442

4543
const require = createRequire(import.meta.url)
4644

45+
/**
46+
* Logs spawn output when running in e2e-tests workflow for debugging.
47+
*/
48+
function logSpawnOutput(
49+
stdout: string | undefined,
50+
stderr: string | undefined,
51+
): void {
52+
// Only log when running e2e-tests in CI.
53+
if (constants.ENV.CI && constants.ENV.VITEST) {
54+
if (stdout) {
55+
console.log(stdout)
56+
}
57+
if (stderr) {
58+
console.error(stderr)
59+
}
60+
}
61+
}
62+
4763
const { PACKAGE_LOCK_JSON, PNPM_LOCK_YAML, YARN_LOCK } = constants
4864

4965
export type DlxOptions = ShadowBinOptions & {
@@ -277,28 +293,12 @@ export async function spawnCoanaDlx(
277293
spawnExtra,
278294
)
279295
const output = await result.spawnPromise
280-
// Print output when running in e2e-tests workflow for debugging.
281-
if (CI && VITEST) {
282-
if (output.stdout) {
283-
console.log(output.stdout)
284-
}
285-
if (output.stderr) {
286-
console.error(output.stderr)
287-
}
288-
}
296+
logSpawnOutput(output.stdout, output.stderr)
289297
return { ok: true, data: output.stdout }
290298
} catch (e) {
291299
const stdout = (e as any)?.stdout
292300
const stderr = (e as any)?.stderr
293-
// Print output when running in e2e-tests workflow for debugging.
294-
if (CI && VITEST) {
295-
if (stdout) {
296-
console.log(stdout)
297-
}
298-
if (stderr) {
299-
console.error(stderr)
300-
}
301-
}
301+
logSpawnOutput(stdout, stderr)
302302
const cause = getErrorCause(e)
303303
const message = stderr || cause
304304
return {

0 commit comments

Comments
 (0)