oven-sh / bun

Incredibly fast JavaScript runtime, bundler, test runner, and package manager – all in one
https://bun.sh
Other
74.17k stars 2.77k forks source link

`bun shell` command for quick, cross platform `package.json` scripts #9299

Open mangs opened 8 months ago

mangs commented 8 months ago

What is the problem this feature would solve?

Having access to the Bun shell would be really nice to have when writing out package.json scripts, especially when considering its cross-platform benefits.

What is the feature you are proposing to solve the problem?

bun shell <command>

Extracting values, response codes, etc from template strings can potentially be ignored in this use case. Looking over the Bun shell examples, there are quite a few that are simple strings that would fit this use case.

Some examples from the documentation that would work:

bun shell 'echo bun! > greeting.txt'
bun shell 'bun run index.ts 2> errors.txt'
bun shell 'echo "Hello World!" | wc -w'

Some other examples that may be useful

bun shell 'rm -rf dist/*' # clean the build directory
bun shell 'cd node_modules && du -sh -- * | sort -h' # audit node_modules packages sizes
bun shell "cd dist && rm -f index.zip && zip index.zip *.{map,mjs} && echo -n 'Zip file size: ' && stat --format=%s index.zip | numfmt --to=iec" # zip a lambda then report its zipped size

What alternatives have you considered?

Populating a scripts/ directory with Bun shell code, but that requires more setup than a simple inline script

mangs commented 7 months ago

I discovered that the bun exec command does this already, but there may be confusion between bun run and bun exec for some people due to the similarities in colloquial use of terms exec and run; they're often used interchangeably. This suggestion would make the intent more clear in my opinion.

xerullian commented 7 months ago

This took entirely too long to figure out. Well, once I came across this post only a few minutes. Here's an example that works:

package.json

{
  "scripts": {
    "clean": "bun exec 'rm -rf ./dist'"
  }
}

then in your terminal

bun run clean