mirror of
https://github.com/webinstall/webi-installers.git
synced 2026-02-14 17:49:53 +00:00
feat: add bun
This commit is contained in:
160
bun/README.md
Normal file
160
bun/README.md
Normal file
@@ -0,0 +1,160 @@
|
||||
---
|
||||
title: Bun
|
||||
homepage: https://bun.sh
|
||||
tagline: |
|
||||
Bun is a fast all-in-one JavaScript runtime
|
||||
---
|
||||
|
||||
To update or switch versions, run `webi bun@<tag>`. \
|
||||
(you can use `@beta` for pre-releases, or `@x.y.z` for a specific version)
|
||||
|
||||
### Files
|
||||
|
||||
These are the files / directories that are created and/or modified with this
|
||||
install:
|
||||
|
||||
```txt
|
||||
~/.config/envman/PATH.env
|
||||
~/.local/opt/bun/
|
||||
~/.local/opt/bun-<VERSION>/
|
||||
```
|
||||
|
||||
## Cheat Sheet
|
||||
|
||||
> Bun is a wicked-fast JavaScript runtime for developer tooling, API servers,
|
||||
> and edge computing.
|
||||
>
|
||||
> It's built in Zig and provides a more curated, "batteries-included" approach
|
||||
> to developing with JavaScript and JavaScript-ish languages - such as
|
||||
> TypeScript, JSX, and TSX.
|
||||
|
||||
Run some <strong><em>x</em></strong>Script:
|
||||
|
||||
```sh
|
||||
bun run ./hello.js
|
||||
bun run ./hello.jsx
|
||||
bun run ./hello.ts
|
||||
bun run ./hello.tsx
|
||||
```
|
||||
|
||||
Run a package from `npm`:
|
||||
|
||||
```sh
|
||||
bun x jswt
|
||||
```
|
||||
|
||||
More goodies:
|
||||
|
||||
```
|
||||
bun help
|
||||
```
|
||||
|
||||
(there's also a built-in **development server** and lots of stuff)
|
||||
|
||||
### bun<span>.</span>sh/install vs webi
|
||||
|
||||
Bun has an official installer:
|
||||
|
||||
```sh
|
||||
export BUN_INSTALL="$HOME/.bun"
|
||||
curl -fsSL https://bun.sh/install | bash
|
||||
```
|
||||
|
||||
You might want to still use webi if you want to be able to switch between
|
||||
versions.
|
||||
|
||||
### How to install command line completions
|
||||
|
||||
```sh
|
||||
bun completions
|
||||
```
|
||||
|
||||
### How to create a bun executable
|
||||
|
||||
1. Create your script
|
||||
```sh
|
||||
vim ./hello
|
||||
```
|
||||
```js
|
||||
#!/usr/bin/env bun
|
||||
console.log('hello');
|
||||
```
|
||||
2. Make it executable
|
||||
```sh
|
||||
chmod a+x ./hello
|
||||
```
|
||||
3. Run it
|
||||
```sh
|
||||
./hello
|
||||
```
|
||||
|
||||
### How to publish bun packages
|
||||
|
||||
At the time of this writing (bun v0.5.1), you'll still need to publish with
|
||||
`npm`.
|
||||
|
||||
`npm` is installed with [node](/node).
|
||||
|
||||
See
|
||||
[Getting Started with NPM (as a developer)](https://gist.github.com/coolaj86/1318304).
|
||||
|
||||
### How to install bun packages
|
||||
|
||||
You can run it with `bun x`:
|
||||
|
||||
```sh
|
||||
bun x <whatever>
|
||||
```
|
||||
|
||||
Or you can put the `#!/usr/bin/env bun` shebang before publishing, and install
|
||||
from npm:
|
||||
|
||||
```sh
|
||||
bun install -g <whatever>
|
||||
<whatever>
|
||||
```
|
||||
|
||||
### How to run a Bun program as a service
|
||||
|
||||
As a system service on Linux:
|
||||
|
||||
(**note**: swap 'my-project' and './my-project' for the name of your project and
|
||||
file)
|
||||
|
||||
1. Install serviceman (compatible with systemd)
|
||||
```sh
|
||||
webi serviceman
|
||||
source ~/.config/envman/PATH.env
|
||||
```
|
||||
2. Go into your program's directory
|
||||
```sh
|
||||
pushd ./my-project/
|
||||
```
|
||||
3. Add your project to the system launcher, running as the current user
|
||||
```sh
|
||||
sudo env PATH="$PATH" \
|
||||
serviceman add --path="$PATH" --system \
|
||||
--username "$(whoami)" --name my-project -- \
|
||||
bun run ./my-project.js
|
||||
```
|
||||
4. Restart the logging service
|
||||
```sh
|
||||
sudo systemctl restart systemd-journald
|
||||
```
|
||||
|
||||
For **macOS**:
|
||||
|
||||
1. Install serviceman (compatible with `launchctl`)
|
||||
```sh
|
||||
webi serviceman
|
||||
source ~/.config/envman/PATH.env
|
||||
```
|
||||
2. Go into your program's directory
|
||||
```sh
|
||||
pushd ./my-project/
|
||||
```
|
||||
3. Add your project to the system launcher, running as the current user
|
||||
```sh
|
||||
serviceman add --path="$PATH" --user --name my-project -- \
|
||||
bun run ./my-project.js
|
||||
```
|
||||
39
bun/install.sh
Normal file
39
bun/install.sh
Normal file
@@ -0,0 +1,39 @@
|
||||
#!/bin/sh
|
||||
|
||||
set -e
|
||||
set -u
|
||||
|
||||
# NOTE: pkg_* variables can be defined here
|
||||
# pkg_cmd_name
|
||||
# pkg_src, pkg_src_bin, pkg_src_cmd
|
||||
# pkg_dst, pkg_dst_bin, pkg_dst_cmd
|
||||
#
|
||||
# Their defaults are defined in _webi/template.sh at https://github.com/webinstall/packages
|
||||
|
||||
# Every package should define these 6 variables
|
||||
pkg_cmd_name="bun"
|
||||
|
||||
pkg_dst_cmd="$HOME/.local/opt/bun/bin/bun"
|
||||
pkg_dst_dir="$HOME/.local/opt/bun"
|
||||
pkg_dst="$pkg_dst_dir"
|
||||
|
||||
pkg_src_cmd="$HOME/.local/opt/bun-v$WEBI_VERSION/bin/bun"
|
||||
pkg_src_dir="$HOME/.local/opt/bun-v$WEBI_VERSION"
|
||||
pkg_src="$pkg_src_dir"
|
||||
|
||||
pkg_get_current_version() {
|
||||
# 'bun --version' only outputs the version:
|
||||
# 0.5.1
|
||||
# But we future-proof it a little anyway
|
||||
# 0.5.1
|
||||
bun --version 2> /dev/null | head -n 1 | cut -d' ' -f1
|
||||
}
|
||||
|
||||
# pkg_install must be defined by every package
|
||||
pkg_install() {
|
||||
# ~/.local/opt/bun-v0.5.1/bin
|
||||
mkdir -p "$(dirname "$pkg_src_cmd")"
|
||||
|
||||
# mv ./bun-*/bun ~/.local/opt/bun-v0.5.1/bin/bun
|
||||
mv ./bun-*/bun* "$pkg_src_cmd"
|
||||
}
|
||||
32
bun/releases.js
Normal file
32
bun/releases.js
Normal file
@@ -0,0 +1,32 @@
|
||||
'use strict';
|
||||
|
||||
var github = require('../_common/github.js');
|
||||
var owner = 'oven-sh';
|
||||
var repo = 'bun';
|
||||
|
||||
module.exports = function (request) {
|
||||
return github(request, owner, repo).then(function (all) {
|
||||
all.releases = all.releases
|
||||
.filter(function (r) {
|
||||
let isDebug = /-profile/.test(r.name);
|
||||
if (!isDebug) {
|
||||
return true;
|
||||
}
|
||||
})
|
||||
.map(function (r) {
|
||||
// bun-v0.5.1 => v0.5.1
|
||||
r.version = r.version.replace(/bun-/g, '');
|
||||
return r;
|
||||
});
|
||||
return all;
|
||||
});
|
||||
};
|
||||
|
||||
if (module === require.main) {
|
||||
module.exports(require('@root/request')).then(function (all) {
|
||||
all = require('../_webi/normalize.js')(all);
|
||||
// just select the first 5 for demonstration
|
||||
all.releases = all.releases.slice(0, 5);
|
||||
console.info(JSON.stringify(all, null, 2));
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user