简体   繁体   中英

Globally installed package command files generated oddly

I've been working on a command line program and I'm having a problem trying to get it to install globally.

I set up the bin in the package.json so it looks like

"bin" : { "bsp" : "bsp.js" }

Whenever it generates the command files in %appdata%/npm though, it generates them like this:

bsp

"$basedir/node_modules/BlueStacksProfiles/bsp.js"   "$@"
exit $?

bsp.cmd

"%~dp0\node_modules\BlueStacksProfiles\bsp.js"   %*

Notice it's missing the node command in both of them, and in the first one it doesn't set the basedir properly (which is bad because if you try to run it from git bash it'll assume the wrong basedir).

As opposed to say, http-server

http-server

#!/bin/sh
basedir=`dirname "$0"`

case `uname` in
    *CYGWIN*) basedir=`cygpath -w "$basedir"`;;
esac

if [ -x "$basedir/node" ]; then
  "$basedir/node"  "$basedir/node_modules/http-server/bin/http-server" "$@"
  ret=$?
else 
  node  "$basedir/node_modules/http-server/bin/http-server" "$@"
  ret=$?
fi
exit $ret

http-server.cmd

@IF EXIST "%~dp0\node.exe" (
  "%~dp0\node.exe"  "%~dp0\node_modules\http-server\bin\http-server" %*
) ELSE (
  node  "%~dp0\node_modules\http-server\bin\http-server" %*
)

and that's just the generic template, all other globally installed npm apps I have installed look something like that. I feel like I'm missing something from my package.json, but I can't find much material on creating globally installed node apps.

So, what am I doing wrong?

So, for anybody else having this problem, it was because my bin file didn't start with

#!/usr/bin/env node

Adding that fixed the problem.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM