getnote-cli icon indicating copy to clipboard operation
getnote-cli copied to clipboard

Windows: npm shims point at the macOS binary, so every `getnote` command silently no-ops

Open woodcore opened this issue 3 months ago • 0 comments

Windows: npm shims point at the macOS binary, so every getnote command silently no-ops

Summary

On Windows, a global install of @getnote/cli produces a getnote command that prints nothing and exits 0 for every subcommand. Nothing appears broken — there is no error message and the exit code is success — but the CLI is completely non-functional.

The cause is that the npm-generated shims invoke bin/getnote, which is the macOS binary, instead of bin/getnote.exe.

Root cause

After npm install -g @getnote/cli, the package's bin/ directory contains two binaries:

File First 4 bytes Format Platform
bin/getnote CF FA ED FE Mach-O 64-bit macOS
bin/getnote.exe 4D 5A 90 00 PE (MZ) Windows

package.json declares:

"bin": { "getnote": "./bin/getnote" }

npm generates its three shims from that literal, extensionless path, so all of them target the macOS binary:

getnote.cmd

"%dp0%\node_modules\@getnote\cli\bin\getnote"   %*

getnote.ps1 — note that it computes $exe = ".exe" and then never uses it:

$exe=""
if ($PSVersionTable.PSVersion -lt "6.0" -or $IsWindows) {
  $exe=".exe"
}
if ($MyInvocation.ExpectingInput) {
  $input | & "$basedir/node_modules/@getnote/cli/bin/getnote"   $args
} else {
  & "$basedir/node_modules/@getnote/cli/bin/getnote"   $args
}

getnote (the sh shim, used by Git Bash / MSYS)

exec "$basedir/node_modules/@getnote/cli/bin/getnote"   "$@"

Why the mac binary is there at all: postinstall.js downloads the Windows zip and runs Expand-Archive into bin/, which adds getnote.exe — but the repository's pre-existing bin/getnote (mac) is never removed, and files: ["bin/", ...] publishes it to npm. So both end up installed side by side.

The failure is silent rather than loud because cmd.exe cannot execute a Mach-O file but still returns 0 here. Under PowerShell, calling the extensionless path directly surfaces what is actually happening:

InvalidOperation: Cannot run a document in the middle of a pipeline:
C:\Users\<user>\AppData\Roaming\npm\node_modules\@getnote\cli\bin\getnote.

A related smaller bug: createSymlink() in postinstall.js targets path.join(npmPrefix, 'bin'), but on Windows the npm global prefix has no bin subdirectory — executables live directly in the prefix. npm prefix -g returns C:\Users\<user>\AppData\Roaming\npm, and Test-Path "...\npm\bin" is False, so that block silently does nothing on Windows.

Reproduction

npm install -g @getnote/cli

getnote version        # prints nothing
echo $LASTEXITCODE     # 0
getnote --help         # prints nothing
getnote auth status    # prints nothing

Confirm the shim is pointed at the wrong file:

$b = "$(npm prefix -g)\node_modules\@getnote\cli\bin"

# The exe works:
& "$b\getnote.exe" version
# -> getnote version v1.3.0

# What the shims actually call is a Mach-O binary:
[System.IO.File]::ReadAllBytes("$b\getnote")[0..3] | % { $_.ToString('X2') }
# -> CF FA ED FE

Environment

  • @getnote/cli 1.3.0 (installed via npm install -g)
  • Windows 11 Pro, 10.0.26200, x64
  • Node.js v24.18.0 (os.platform() = win32, os.arch() = x64)
  • PowerShell 7 (pwsh)
  • npm global prefix: C:\Users\<user>\AppData\Roaming\npm
  • Reproduced in both pwsh and cmd.exe

Suggested fixes

Any one of these resolves it; the first is the most robust.

1. Don't ship the mac binary in the published package. The binary is downloaded per-platform in postinstall anyway, so bin/getnote should not be in the tarball. Removing it means npm's extensionless shim resolves to getnote.exe via Windows' normal PATHEXT lookup, and all three shims work unchanged. Consider replacing files: ["bin/"] with a narrower entry, or having postinstall delete the non-matching binary for the current platform.

2. Have postinstall delete the foreign binary after download. In the Windows branch, after Expand-Archive succeeds, fs.unlinkSync(path.join(binDir, 'getnote')) when that file is not a PE.

3. Use a JS launcher as the bin entry. Point "bin" at a small bin/getnote.js that spawns the correct platform binary. This keeps npm's shim generation platform-agnostic and is the conventional approach for downloaded-binary packages.

Worth noting that fixes at the shim level alone are fragile: npm regenerates the shims on every install and update, so anything that edits them post-install is undone by the next npm update -g.

For anyone hitting this before a fix ships, the immediate workaround is to call getnote.exe directly, or repoint the shims (\bin\getnote" to \bin\getnote.exe" in getnote.cmd, and /bin/getnote" to /bin/getnote$exe" in getnote.ps1) — remembering that an update will revert them.

The README's existing Windows note covers the case where Expand-Archive errors, but not this one: here the download and extraction both succeed and the install reports success, yet the command is still dead.

woodcore avatar Aug 07 '26 07:08 woodcore