Skip to content

refactor: Abstract executable detection and invocation pattern #738

@BYK

Description

@BYK

Summary

The pattern of detecting an executable and invoking it with commands is repeated across many targets. This should be abstracted into a helper utility.

Current Pattern

const executable = await findExecutable(BIN, customBin);
if (!executable) {
  throw new ConfigurationError(`Cannot find '${BIN}' for publishing.`);
}
await spawnProcess(executable, [...args]);

Proposed Solution

Create a helper like:

interface ExecutableConfig {
  binName: string;
  customBinEnvVar?: string;
  errorContext: string;
}

async function runWithExecutable(
  config: ExecutableConfig,
  args: string[],
  options?: SpawnOptions
): Promise<Buffer>;

Affected Targets

  • npm
  • pypi
  • crates
  • gem
  • pub-dev
  • hex
  • nuget
  • Others

Related

Spawned from PR #707 review comment.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions