Skip to content

Commit

Permalink
fix: independent-target-command
Browse files Browse the repository at this point in the history
  • Loading branch information
gearonix committed Mar 13, 2024
1 parent 4436f5b commit 4ad5f8c
Showing 1 changed file with 11 additions and 16 deletions.
27 changes: 11 additions & 16 deletions src/commands/run/utils/independent-target-command.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,41 +17,36 @@ export function createIndependentTargetCommand(
opts: AnyTarget,
{ defaultArgs, projectCwd }: CreateIndependentCommandOptions
) {
const normalizeCommand = ({
command,
commands,
parallel
}: Partial<AnyTarget>): string => {
const normalizeCommand = () => {
const cmd = opts.command

invariant(
command ?? commands,
cmd ?? opts.commands,
'Either "command" or "commands" must be provided.'
)

const result = Array.isArray(command) ? command.join(' ') : command
const result = Array.isArray(cmd) ? cmd.join(' ') : cmd

if (!result) {
const separator = parallel
const separator = opts.parallel
? TargetSeparators.PARALLEL
: TargetSeparators.NORMAL

return commands!.join(separator)
return opts.commands!.join(separator)
}

return result
}

const normalizeEnv = ({
env,
envFile
}: Partial<AnyTarget>): Record<string, string> | undefined => {
if (envFile) return envfile.parse(toAbsolutePath(envFile))
const normalizeEnv = (): Record<string, string> | undefined => {
if (opts.envFile) return envfile.parse(toAbsolutePath(opts.envFile))
if (env) return env
return undefined
}

const command = normalizeCommand(opts)
const command = normalizeCommand()
const args = compact([defaultArgs, opts.args]).join(' ')
const env = normalizeEnv(opts)
const env = normalizeEnv()
const cwd = toAbsolutePath(opts.cwd ?? projectCwd ?? process.cwd())

return {
Expand Down

0 comments on commit 4ad5f8c

Please sign in to comment.