Skip to content

Conversation

@BioPhoton
Copy link
Collaborator

@BioPhoton BioPhoton commented Sep 8, 2025

This PR includes:

  • move all command helper into 1 file - command.ts
  • adjust executeProgress - removed hard dependencies to other functions so it is easier to use in nx-plugin
  • used import for executeProcess.ts in nx-plugin

@BioPhoton BioPhoton marked this pull request as ready for review October 4, 2025 11:10
@BioPhoton BioPhoton requested a review from matejchalk as a code owner October 4, 2025 11:10
@github-actions github-actions bot removed 🧩 core 🧩 js-packages-plugin Plugin for audit and outdated dependencies labels Oct 23, 2025
@BioPhoton BioPhoton requested a review from matejchalk October 23, 2025 13:17
John Doe added 2 commits November 9, 2025 15:49
…/utils/command-helper

# Conflicts:
#	packages/nx-plugin/src/executors/cli/executor.int.test.ts
#	packages/nx-plugin/src/internal/execute-process.ts
#	packages/utils/src/lib/execute-process.ts
const {
command,
args,
observer,

Check warning

Code scanning / CodeQL

Unsafe shell command constructed from library input Medium

This shell argument which depends on
library input
is later used in a
shell command
.
This shell argument which depends on library input is later used in a
shell command
.
This shell argument which depends on library input is later used in a
shell command
.
This shell argument which depends on library input is later used in a
shell command
.
This shell argument which depends on library input is later used in a
shell command
.
This shell argument which depends on library input is later used in a
shell command
.
This shell argument which depends on library input is later used in a
shell command
.
Copy link
Collaborator

@matejchalk matejchalk left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The more I see in this PR, the more confused I am about what it solves.

  • De-duplicating executeProcess? No, I did that already in #1137.
  • De-duplicating helper functions like objectToCliArgs? No, in fact, this PR makes it even worse. It adds duplicate implementations and tests of many helper functions in packages/utils/src/lib/command.ts, but they aren't imported anywhere. So functions like objectToCliArgs are now duplicated in 3 places, not 2. And there's no reason for it.
    • There's a much simpler solution to avoid duplicating the helper functions, which is to dynamically import @code-pushup/utils. From what I saw when I un-duplicated executeProcess, there really isn't that much code being used anyway. I'm happy to create a small PR that removes all the duplicates, so we can close this topic.

In the interest of saving time, I would abandon this PR. I don't think it solves anything anymore.

Comment on lines -1 to -11
/**
* Dynamically imports and executes function from utils.
*
* This is a workaround for Nx only supporting plugins in CommonJS format.
*/
export async function executeProcess(
cfg: import('@code-pushup/utils').ProcessConfig,
): Promise<import('@code-pushup/utils').ProcessResult> {
const { executeProcess } = await import('@code-pushup/utils');
return executeProcess(cfg);
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Was it intentional to delete this wrapper? I created it to simplify usage within the nx-plugin.

Comment on lines +43 to 44
const { executeProcess } = await import('@code-pushup/utils');
await executeProcess({
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The dynamic import wouldn't be needed here if you imported executeProcess from the packages/nx-plugin/src/internal/execute-process.ts you deleted (see previous comment).

It's up to you, though. I don't really mind either way as long as the implementation is being dynamically imported. The local wrapper is just for convenience.

Comment on lines +173 to +181
if (isVerbose() || verbose === true) {
loggerInstance.info(
formatCommandLog({
command,
args,
cwd: cfg.cwd ? String(cfg.cwd) : process.cwd(),
}),
);
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please revert changes to this file. They're not compatible with the work I did in #1137.

  • The logger now handles the verbose flag internally.
  • The logger.command method below already prints the command and args, so this would log a duplicate.
  • An option to pass custom logger instances introduces unnecessary complexity, and we don't need it for anything.

Comment on lines +83 to +100
export function formatCommandLog(options: FormatCommandLogOptions): string {
const { command, args = [], cwd = process.cwd(), env } = options;
const relativeDir = path.relative(process.cwd(), cwd);

return [
...(relativeDir && relativeDir !== '.'
? [ansis.italic(ansis.gray(relativeDir))]
: []),
ansis.yellow('$'),
...(env && Object.keys(env).length > 0
? Object.entries(env).map(([key, value]) => {
return ansis.gray(`${key}=${formatEnvValue(value)}`);
})
: []),
ansis.gray(command),
ansis.gray(args.join(' ')),
].join(' ');
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This function was integrated into the new logger, and I removed this helper in #1137.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All these functions and tests are now duplicated. And I don't understand why. The command.ts module isn't being used anywhere.

'error',
{ ignoredDependencies: ['esbuild'] }, // esbuild is a peer dependency of bundle-require
{
ignoredDependencies: ['esbuild', 'ora'], // esbuild is a peer dependency of bundle-require, ora has transitive dependencies with different versions
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The ora package is a direct dependency of @code-pushup/utils, so there's no need to ignore anything. The linter passes in the main branch, so I don't see what change is needed.

@BioPhoton
Copy link
Collaborator Author

BioPhoton commented Nov 10, 2025

The goal of this pr was in fact to dedupe and move code in one place.

As it was long hanging due to feedback and travel overlap other PR's (you mentioned yours for example) got merged.

I did merged main and must have missed these changes your PR introduced and other duplicates.

I will give it a cleanup as I still see it helpful to have all command related things in 1 place/file.

Thanks for your patience and pointing out that you could help with a PR that includes the above changes to save time. I feel I'm more motivated to finish the implementation my self, so I will try it another time. I will share PR descriptions first.

To reduce feedback and discussion:

  • I can remove passing verbose into the process helper so we only control logging over env vars (which I feel is a bit odd compared to other code prices in this repo).
  • make sure no duplicate code is president
  • check if additional cont highlighting in logs for env vars is already present in recent PRs I missed.

Update:

I'll close and reopen new one after I'm steady available again.

@BioPhoton BioPhoton closed this Nov 10, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants