Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

javascript-bun environment created #13

Merged
merged 6 commits into from
Nov 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
| **Languages:** |
| `go` | ✅ | ✅ | ✅ | |
| `python-poetry` | ✅ | ✅ | ✅ | Python environment using poerty |
| `javascript-bun` | ✅ | ✅ | ✅ | Javascript environment with Bun |
| `ruby` | ✅ | ✅ | ✅ | Ruby environment |
| `rust` | ✅ | ✅ | ✅ | Rust environment |
| **Databases:** |
Expand Down
4 changes: 4 additions & 0 deletions javascript-bun/.flox/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
run/
cache/
lib/
log/
4 changes: 4 additions & 0 deletions javascript-bun/.flox/env.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"name": "javascript-bun",
"version": 1
}
205 changes: 205 additions & 0 deletions javascript-bun/.flox/env/manifest.lock
Original file line number Diff line number Diff line change
@@ -0,0 +1,205 @@
{
"lockfile-version": 1,
"manifest": {
"version": 1,
"install": {
"bun": {
"pkg-path": "bun"
},
"gum": {
"pkg-path": "gum"
}
},
"hook": {
"on-activate": "\nexport FLOX_JAVASCRIPT_BUN_CACHE_DIR=\"$FLOX_ENV_CACHE/javascript-bun\"\nmkdir -p \"$FLOX_JAVASCRIPT_BUN_CACHE_DIR\"\n\nexport FLOX_JAVASCRIPT_BUN_PACKAGES_HASH_FILE=\"$FLOX_JAVASCRIPT_BUN_CACHE_DIR/packages-hash\"\n\nfunction with_spinner() {\n if [[ \"$FLOX_ENVS_TESTING\" == \"1\" ]]; then\n bash -c \"$1\"\n else\n gum spin \\\n --show-error \\\n --spinner line \\\n --spinner.foreground=\"#cccccc\" \\\n --title \">>> $2 ...\" \\\n --title.foreground=\"#cccccc\" \\\n -- bash -c \"$1\"\n fi\n}\n\nfunction install_packages() { \n bun install --frozen-lockfile\n}\nexport -f install_packages\n\n\nif [ -f \"package.json\" ] && [ -f \"bun.lockb\" ]; then\n export FLOX_JAVASCRIPT_BUN_PACKAGES_HASH=\"false\"\n if [ -f \"$FLOX_JAVASCRIPT_BUN_PACKAGES_HASH_FILE\" ] ; then\n export FLOX_JAVASCRIPT_BUN_PACKAGES_HASH=$(cat package.json bun.lockb | sha256sum | cut -d\" \" -f 1)\n fi\n if [ \"$FLOX_JAVASCRIPT_BUN_PACKAGES_HASH\" != \"$(cat $FLOX_JAVASCRIPT_BUN_PACKAGES_HASH_FILE 2>/dev/null)\" ]; then\n with_spinner install_packages \"Installing Javascript packages (with Bun)\"\n echo -e \"{{ Foreground \\\"#ffffff\\\" \\\"✅ Javascript packages installed (with Bun).\\\" }}\\n\" \\\n | gum format -t template\n echo \"$FLOX_JAVASCRIPT_BUN_PACKAGES_HASH\" > \"$FLOX_JAVASCRIPT_BUN_PACKAGES_HASH_FILE\"\n fi\nfi\n"
},
"profile": {},
"options": {
"systems": [
"aarch64-darwin",
"aarch64-linux",
"x86_64-linux"
],
"allow": {
"licenses": []
},
"semver": {}
}
},
"packages": [
{
"attr_path": "bun",
"broken": false,
"derivation": "/nix/store/bgj47nj2jji1hp0y6fkffqa35gf9d3iz-bun-1.1.29.drv",
"description": "Incredibly fast JavaScript runtime, bundler, transpiler and package manager – all in one",
"install_id": "bun",
"license": "[ MIT, LGPL-2.1-only ]",
"locked_url": "https://github.com/flox/nixpkgs?rev=1997e4aa514312c1af7e2bda7fad1644e778ff26",
"name": "bun-1.1.29",
"pname": "bun",
"rev": "1997e4aa514312c1af7e2bda7fad1644e778ff26",
"rev_count": 695081,
"rev_date": "2024-10-20T08:35:21Z",
"scrape_date": "2024-10-23T03:58:08Z",
"stabilities": [
"unstable"
],
"unfree": false,
"version": "1.1.29",
"outputs_to_install": [
"out"
],
"outputs": {
"out": "/nix/store/q8gjb6x9dgz2vq761dr50aifd69lsyhk-bun-1.1.29"
},
"system": "aarch64-darwin",
"group": "toplevel",
"priority": 5
},
{
"attr_path": "bun",
"broken": false,
"derivation": "/nix/store/dpmd8j2ha61jfmnrr4sn238hk0lqn4hd-bun-1.1.29.drv",
"description": "Incredibly fast JavaScript runtime, bundler, transpiler and package manager – all in one",
"install_id": "bun",
"license": "[ MIT, LGPL-2.1-only ]",
"locked_url": "https://github.com/flox/nixpkgs?rev=1997e4aa514312c1af7e2bda7fad1644e778ff26",
"name": "bun-1.1.29",
"pname": "bun",
"rev": "1997e4aa514312c1af7e2bda7fad1644e778ff26",
"rev_count": 695081,
"rev_date": "2024-10-20T08:35:21Z",
"scrape_date": "2024-10-23T03:58:08Z",
"stabilities": [
"unstable"
],
"unfree": false,
"version": "1.1.29",
"outputs_to_install": [
"out"
],
"outputs": {
"out": "/nix/store/9dxgpcvzl461f4q3dgz3c1xcl4h4xwjv-bun-1.1.29"
},
"system": "aarch64-linux",
"group": "toplevel",
"priority": 5
},
{
"attr_path": "bun",
"broken": false,
"derivation": "/nix/store/qig6gh0qpb9c8nl79k7fq7dbzw58wzv0-bun-1.1.29.drv",
"description": "Incredibly fast JavaScript runtime, bundler, transpiler and package manager – all in one",
"install_id": "bun",
"license": "[ MIT, LGPL-2.1-only ]",
"locked_url": "https://github.com/flox/nixpkgs?rev=1997e4aa514312c1af7e2bda7fad1644e778ff26",
"name": "bun-1.1.29",
"pname": "bun",
"rev": "1997e4aa514312c1af7e2bda7fad1644e778ff26",
"rev_count": 695081,
"rev_date": "2024-10-20T08:35:21Z",
"scrape_date": "2024-10-23T03:58:08Z",
"stabilities": [
"unstable"
],
"unfree": false,
"version": "1.1.29",
"outputs_to_install": [
"out"
],
"outputs": {
"out": "/nix/store/1xgl28bhcsvmw14vfyxlrb5qhmlzjifi-bun-1.1.29"
},
"system": "x86_64-linux",
"group": "toplevel",
"priority": 5
},
{
"attr_path": "gum",
"broken": false,
"derivation": "/nix/store/ippvngi4fvlm7wcjv66q35882kk0d782-gum-0.14.5.drv",
"description": "Tasty Bubble Gum for your shell",
"install_id": "gum",
"license": "MIT",
"locked_url": "https://github.com/flox/nixpkgs?rev=1997e4aa514312c1af7e2bda7fad1644e778ff26",
"name": "gum-0.14.5",
"pname": "gum",
"rev": "1997e4aa514312c1af7e2bda7fad1644e778ff26",
"rev_count": 695081,
"rev_date": "2024-10-20T08:35:21Z",
"scrape_date": "2024-10-23T03:58:08Z",
"stabilities": [
"unstable"
],
"unfree": false,
"version": "0.14.5",
"outputs_to_install": [
"out"
],
"outputs": {
"out": "/nix/store/s4yb9a7cvj5vd5yw0nvssf51lmpa5id0-gum-0.14.5"
},
"system": "aarch64-darwin",
"group": "toplevel",
"priority": 5
},
{
"attr_path": "gum",
"broken": false,
"derivation": "/nix/store/yjf86f3qgpirr5lc9wsds4nlqyf8riw0-gum-0.14.5.drv",
"description": "Tasty Bubble Gum for your shell",
"install_id": "gum",
"license": "MIT",
"locked_url": "https://github.com/flox/nixpkgs?rev=1997e4aa514312c1af7e2bda7fad1644e778ff26",
"name": "gum-0.14.5",
"pname": "gum",
"rev": "1997e4aa514312c1af7e2bda7fad1644e778ff26",
"rev_count": 695081,
"rev_date": "2024-10-20T08:35:21Z",
"scrape_date": "2024-10-23T03:58:08Z",
"stabilities": [
"unstable"
],
"unfree": false,
"version": "0.14.5",
"outputs_to_install": [
"out"
],
"outputs": {
"out": "/nix/store/bw0ii1jjvxd8albrmvi0lin6h1ssz4yi-gum-0.14.5"
},
"system": "aarch64-linux",
"group": "toplevel",
"priority": 5
},
{
"attr_path": "gum",
"broken": false,
"derivation": "/nix/store/vsq73s5cq771rh6nz9hsjhiy74xsyh1r-gum-0.14.5.drv",
"description": "Tasty Bubble Gum for your shell",
"install_id": "gum",
"license": "MIT",
"locked_url": "https://github.com/flox/nixpkgs?rev=1997e4aa514312c1af7e2bda7fad1644e778ff26",
"name": "gum-0.14.5",
"pname": "gum",
"rev": "1997e4aa514312c1af7e2bda7fad1644e778ff26",
"rev_count": 695081,
"rev_date": "2024-10-20T08:35:21Z",
"scrape_date": "2024-10-23T03:58:08Z",
"stabilities": [
"unstable"
],
"unfree": false,
"version": "0.14.5",
"outputs_to_install": [
"out"
],
"outputs": {
"out": "/nix/store/kma26ygxqp39pm6fl32yjach0czasc3j-gum-0.14.5"
},
"system": "x86_64-linux",
"group": "toplevel",
"priority": 5
}
]
}
60 changes: 60 additions & 0 deletions javascript-bun/.flox/env/manifest.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
version = 1

# https://bun.sh/docs/quickstart

[install]
bun.pkg-path = "bun"

# helper tools
gum.pkg-path = "gum"


[hook]
on-activate = '''

export FLOX_JAVASCRIPT_BUN_CACHE_DIR="$FLOX_ENV_CACHE/javascript-bun"
mkdir -p "$FLOX_JAVASCRIPT_BUN_CACHE_DIR"

export FLOX_JAVASCRIPT_BUN_PACKAGES_HASH_FILE="$FLOX_JAVASCRIPT_BUN_CACHE_DIR/packages-hash"

function with_spinner() {
if [[ "$FLOX_ENVS_TESTING" == "1" ]]; then
bash -c "$1"
else
gum spin \
--show-error \
--spinner line \
--spinner.foreground="#cccccc" \
--title ">>> $2 ..." \
--title.foreground="#cccccc" \
-- bash -c "$1"
fi
}

function install_packages() {
bun install --frozen-lockfile
}
export -f install_packages


if [ -f "package.json" ] && [ -f "bun.lockb" ]; then
export FLOX_JAVASCRIPT_BUN_PACKAGES_HASH="false"
if [ -f "$FLOX_JAVASCRIPT_BUN_PACKAGES_HASH_FILE" ] ; then
export FLOX_JAVASCRIPT_BUN_PACKAGES_HASH=$(cat package.json bun.lockb | sha256sum | cut -d" " -f 1)
fi
if [ "$FLOX_JAVASCRIPT_BUN_PACKAGES_HASH" != "$(cat $FLOX_JAVASCRIPT_BUN_PACKAGES_HASH_FILE 2>/dev/null)" ]; then
with_spinner install_packages "Installing Javascript packages (with Bun)"
echo -e "{{ Foreground \"#ffffff\" \"✅ Javascript packages installed (with Bun).\" }}\n" \
| gum format -t template
echo "$FLOX_JAVASCRIPT_BUN_PACKAGES_HASH" > "$FLOX_JAVASCRIPT_BUN_PACKAGES_HASH_FILE"
fi
fi
'''

[options]
systems = [
"aarch64-darwin",
"aarch64-linux",
#"x86_64-darwin", # not supported on 2024-11-12
"x86_64-linux",
]
1 change: 1 addition & 0 deletions javascript-bun/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
node_modules/
10 changes: 10 additions & 0 deletions javascript-bun/.prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"semi": false,
"singleQuote": true,
"trailingComma": "none",
"arrowParens": "avoid",
"tabWidth": 2,
"useTabs": false,
"printWidth": 80,
"endOfLine": "lf"
}
27 changes: 27 additions & 0 deletions javascript-bun/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# express-bun

To install dependencies:

```bash
flox activate
```

To run:

```bash
flox services start
# Verify that the server is up and running
curl localhost:3000
```

To view logs:
```bash
flox services logs express
```

To stop the server:
```bash
flox services stop
```

This project was created using `bun init` in bun v1.1.29. [Bun](https://bun.sh) is a fast all-in-one JavaScript runtime.
Binary file added javascript-bun/bun.lockb
Binary file not shown.
3 changes: 3 additions & 0 deletions javascript-bun/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import figlet from "figlet";

console.log(figlet.textSync("> Flox . Loves . Bun <"));
21 changes: 21 additions & 0 deletions javascript-bun/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"dependencies": {
"express": "^4.21.1",
"figlet": "^1.8.0"
},
"devDependencies": {
"@types/bun": "latest",
"@types/express": "^5.0.0",
"@types/figlet": "^1.7.0",
"prettier": "^3.3.3"
},
"scripts": {
"prettier": "prettier --write ."
},
"name": "javascript-bun",
"module": "index.ts",
"type": "module",
"peerDependencies": {
"typescript": "^5.0.0"
}
}
16 changes: 16 additions & 0 deletions javascript-bun/server.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import express, { type Request, type Response } from 'express'

const app = express()
const { PORT = 3000 } = process.env

app.get('/', (_req: Request, res: Response) => {
res.status(200).send('Hello, Flox!\n')
})

app.get('/ping', (_req: Request, res: Response) => {
res.status(200).send('pong\n')
})

app.listen(PORT, () => {
console.log(`Listening on port ${PORT}...`)
})
21 changes: 21 additions & 0 deletions javascript-bun/test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#!/usr/bin/env bash

set -eo pipefail

check_command() {
if ! command -v $1 2>&1 >/dev/null
then
echo "Error: '$1' command could not be found."
exit 1
fi
}

check_command bun


bun repl --eval "import figlet from 'figlet'"
echo ">>> figlet package installed"

bun run index.ts
echo ">>> script works"

Loading
Loading