Skip to content

cfcli script doesn't set CWD #94

@oising

Description

@oising

I just installed cfcli (windows 11, arm64, node 24) and it doesn't seem to work out of the box. The script stub is found, but the node implementation looks for supporting files relative to the stub, not the nodejs implementation, i.e.

Image

So I added a try/finally with a pushd/popd pairing to set the write working directory:

#!/usr/bin/env pwsh
$basedir=Split-Path $MyInvocation.MyCommand.Definition -Parent

$exe=""
if ($PSVersionTable.PSVersion -lt "6.0" -or $IsWindows) {
  # Fix case when both the Windows and Linux builds of Node
  # are installed in the same directory
  $exe=".exe"
}

$ret=0

try {
# set cwd
pushd (join-path $basedir "node_modules/cloudflare-cli/")

if (Test-Path "$basedir/node$exe") {
  # Support pipeline input
  if ($MyInvocation.ExpectingInput) {
    $input | & "$basedir/node$exe"  "$basedir/node_modules/cloudflare-cli/bin/cfcli" $args
  } else {
    & "$basedir/node$exe"  "$basedir/node_modules/cloudflare-cli/bin/cfcli" $args
  }
  $ret=$LASTEXITCODE
} else {
  # Support pipeline input
  if ($MyInvocation.ExpectingInput) {
    $input | & "node$exe"  "$basedir/node_modules/cloudflare-cli/bin/cfcli" $args
  } else {
    & "node$exe"  "$basedir/node_modules/cloudflare-cli/bin/cfcli" $args
  }
  $ret=$LASTEXITCODE
}

} finally { popd }

exit $ret

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