Skip to content

Commit

Permalink
fix: debug properly
Browse files Browse the repository at this point in the history
  • Loading branch information
kanadgupta committed Nov 21, 2024
1 parent e864491 commit 17146c8
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions src/lib/baseCommand.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { format } from 'node:util';

import * as core from '@actions/core';
import { Command as OclifCommand } from '@oclif/core';
import debugPkg from 'debug';

import { isGHA, isTest } from './isCI.js';

Expand All @@ -15,17 +16,21 @@ export default abstract class BaseCommand<T extends typeof OclifCommand> extends
constructor(argv: string[], config: Config) {
super(argv, config);

const oclifDebug = this.debug;
// this scope is copied from the @oclif/core source
// see https://github.com/oclif/core/blob/eef2ddedf6a844b28d8968ef5afd38c92f5875db/src/command.ts#L140
const scope = this.id ? `${this.config.bin}:${this.id}` : this.config.bin;

// rather than using the @oclif/core debug function, we use the debug package
// so we have full control over the scope.
const debug = debugPkg(scope);
// this is a lightweight reimplementation of the @oclif/core debug function
// with some debug logging functionality for github actions
this.debug = (formatter: unknown, ...args: unknown[]) => {
if (isGHA() && !isTest()) {
core.debug(`${scope}: ${format(formatter, ...args)}`);
}

return oclifDebug(formatter, ...args);
return debug(formatter, ...args);
};
}

Expand Down

0 comments on commit 17146c8

Please sign in to comment.