budo
budo copied to clipboard
Default port should be used if `port` is empty/invalid
I want to allow folks to spawn budo with a custom default port (instead of 9966) like this:
PORT=3000 npm start
But this won't work:
"start": "budo --port $PORT"
budo tries to parse the empty string with parseInt and the NaN gets passed as an (invalid) port, thereby preventing budo from starting the server.
I'd say this works as intended; if --port is passed it's your responsibility to set it. To set a default value regardless try this:
$ if [ $PORT ]; then budo --port $PORT; else budo; fi
I'm not sure what the error looks like you're getting, if it's unclear we could perhaps improve that? Cheers!
Also to clarify: setting variables before running the script works:
"derp": "echo $foo"
$ foo='bar' npm run foo
bar
Yeah typically CLIs will error out when you pass undefined stuff. I think we could add a clearer error message.
I would write the command like this, but I recently discovered Git Bash on Windows doesn't like this format:
$ if [ $PORT ]; then budo --port $PORT; else budo; fi
And it's also not kind of a pain to type in each project's npm scripts.
before
empty
--port

invalid (non-numeric)
--port swag

after
valid
--port 7000

empty
--port

environment variables
PORT='' … --port $PORT
PORT=7000 … --port $PORT

invalid
--port swag

Seems like a pretty legitimate use case, I've run into similar issues with Unix stuff not working in Windows. Should be merged in latest, I'll cut a new release soon.
Going to reopen this while we figure out another way to allow user-override port/host in a cross-platform manner.