cloudflare-cli
cloudflare-cli copied to clipboard
cfcli script doesn't set CWD
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.
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
-
Edit the installed module file at:
-
Windows:
%APPDATA%\npm\node_modules\cloudflare-cli\index.js -
macOS/Linux:
/usr/local/lib/node_modules/cloudflare-cli/index.jsor~/.nvm/versions/node/v*/lib/node_modules/cloudflare-cli/index.js
-
Windows:
-
Add these imports after line 6 (after
import path from 'path';):
import { fileURLToPath } from 'url';
import { dirname } from 'path';
- Replace line 365 (the showHelp method) with:
showHelp() {
return Promise.resolve(new Result([fs.readFileSync(path.join(dirname(fileURLToPath(import.meta.url)), 'doc', 'help.txt'), 'utf8')]));
}