Skip to content

Commit

Permalink
WIP bun
Browse files Browse the repository at this point in the history
  • Loading branch information
joepio committed Jan 17, 2024
1 parent f7c695a commit c220acf
Show file tree
Hide file tree
Showing 18 changed files with 95 additions and 69 deletions.
2 changes: 1 addition & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
"eslint.alwaysShowStatus": true,
"eslint.format.enable": true,
"eslint.lintTask.enable": true,
"eslint.packageManager": "pnpm",
"eslint.packageManager": "bun",
"eslint.quiet": true,
"editor.codeActionsOnSave": {
"source.fixAll.eslint": "explicit"
Expand Down
6 changes: 3 additions & 3 deletions .vscode/tasks.json
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,8 @@
"problemMatcher": [
"$tsc-watch"
],
"label": "run data-browser dev server (pnpm start)",
"detail": "pnpm workspace @tomic/data-browser start",
"label": "run data-browser dev server (bun start)",
"detail": "bun workspace @tomic/data-browser start",
"isBackground": true,
"path": "browser",
"group": "build"
Expand All @@ -90,7 +90,7 @@
],
"label": "test data-browser e2e",
"path": "browser",
"detail": "pnpm test-e2e",
"detail": "bun test-e2e",
"isBackground": true,
"group": "test"
},
Expand Down
4 changes: 2 additions & 2 deletions CONTRIBUTE.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ TL;DR Clone the repo and run `cargo run` from each folder (e.g. `cli` or `server
### Running locally (with local development browser)

- Run `cargo run` to start the server
- Go to `browser`, run `pnpm install` (if you haven't already), and run `pnpm dev` to start the browser
- Go to `browser`, run `bun install` (if you haven't already), and run `bun dev` to start the browser
- Visit your `localhost` in your locally running `atomic-data-browser` instance: (e.g. `http://localhost:5173/app/show?subject=http%3A%2F%2Flocalhost`)
- use `cargo watch -- cargo run` to automatically recompile `atomic-server` when you update JS assets in `browser`

Expand Down Expand Up @@ -113,7 +113,7 @@ cargo run
# now, open new terminal window
cd server/e2e_tests/ && npm i && npm run test
# if things go wrong, debug!
pnpm run test-query {testname}
bun run test-query {testname}
```

<!--
Expand Down
14 changes: 7 additions & 7 deletions Earthfile
Original file line number Diff line number Diff line change
Expand Up @@ -88,25 +88,25 @@ docker-musl:

setup-playwright:
FROM mcr.microsoft.com/playwright:v1.38.0-jammy
RUN curl -f https://get.pnpm.io/v6.14.js | node - add --global pnpm
RUN curl -fsSL https://bun.sh/install | bash
RUN apt update && apt install -y zip
RUN pnpx playwright install --with-deps
RUN npm install -g netlify-cli
RUN bunx playwright install --with-deps
RUN npm install --global netlify-cli

e2e:
FROM +setup-playwright
COPY --keep-ts browser/e2e/package.json /app/e2e/package.json
WORKDIR /app/e2e
RUN pnpm install
RUN bun install
COPY --keep-ts --dir browser/e2e /app
RUN pnpm install
RUN bun install
ENV LANGUAGE="en_GB"
ENV DELETE_PREVIOUS_TEST_DRIVES="false"
ENV FRONTEND_URL=http://localhost:9883
COPY --chmod=0755 +build/atomic-server /atomic-server-bin
# We'll have to zip it https://github.com/earthly/earthly/issues/2817
TRY
RUN nohup /atomic-server-bin --initialize & pnpm run test-e2e ; zip -r test.zip /app/e2e/playwright-report
RUN nohup /atomic-server-bin --initialize & bun run test-e2e ; zip -r test.zip /app/e2e/playwright-report
FINALLY
SAVE ARTIFACT test.zip AS LOCAL artifact/test-results.zip
END
Expand All @@ -119,7 +119,7 @@ e2e:
# WITH DOCKER \
# --load test:latest=+docker
# RUN docker run -d -p 80:80 test:latest & \
# pnpm run test-e2e
# bun run test-e2e
# END
# FINALLY
# SAVE ARTIFACT /app/data-browser/test-results AS LOCAL artifact/test-results
Expand Down
22 changes: 11 additions & 11 deletions browser/CONTRIBUTE.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,32 +10,32 @@ Talk with other devs on our [Discord][discord-url]!

## Publishing

- `pnpm lint-fix`
- `bun lint-fix`
- commit any changes (if they are there)
- `pnpm build` to build typescript files (don't skip this!)
- `pnpm build-server` builds and copies assets to `../atomic-data-rust` folder (.js builds and playwright end-to-end tests). Make sure that `atomic-data-rust` directory exists on your machine as a sibling of `atomic-data-browser`.
- `pnpm test` (don't you publish a broken build!), make sure `atomic-server` is running on `localhost`.
- `bun build` to build typescript files (don't skip this!)
- `bun build-server` builds and copies assets to `../atomic-data-rust` folder (.js builds and playwright end-to-end tests). Make sure that `atomic-data-rust` directory exists on your machine as a sibling of `atomic-data-browser`.
- `bun test` (don't you publish a broken build!), make sure `atomic-server` is running on `localhost`.
- Update the `package.json` files for `lib`, `rust`, and `data-browser` with a new version number. Try to match the version number with `atomic-data-rust`
- Check the [changelog](changelog.md), make sure the headers are correct
- commit any changes, name it `vX.XX.XX`
- `pnpm publish -r`
- `bun publish -r`
- Choose a new version. Versions should match `atomic-data-rs`.
- This updates the `package.json` files, creates a commit, tags it, pushes it to github, and publishes the builds to npm.
- If this fails, try `pnpm version patch` and `pnpm publish`
- DONT run `pnpm npm publish`, as it will not resolve workspace dependencies correctly.
- If this fails, try `bun version patch` and `bun publish`
- DONT run `bun npm publish`, as it will not resolve workspace dependencies correctly.

## Understanding vite and pnpm workspaces
## Understanding vite and bun workspaces

This monorepo is orchestrated with pnpm workspaces.
pnpm workspaces are used to share dependencies.
This monorepo is orchestrated with bun workspaces.
bun workspaces are used to share dependencies.

Vite hosts the data-browser and targets `.ts` files which enables hot reload / hot module replacement, which is great for developing the data browser and the libraries at the same time.

## Iterative builds

If you're editing `@tomic/lib` or `@tomic/react`, you need to re-build the library, as `atomic-data-browser` imports the `.js` files.
You can auto re-build using the `watch` commands in `@tomic/lib` and `@tomic/react`.
If you run `pnpm start` from the root, these will be run automatically.
If you run `bun start` from the root, these will be run automatically.
Note that you may need to refresh your screen manually to show updates from these libraries.

There are two possible solutions for improving this workflow:
Expand Down
14 changes: 7 additions & 7 deletions browser/Earthfile
Original file line number Diff line number Diff line change
Expand Up @@ -10,28 +10,28 @@ all:
BUILD +typedoc

deps:
RUN curl -f https://get.pnpm.io/v6.14.js | node - add --global pnpm
COPY package.json pnpm-lock.yaml pnpm-workspace.yaml .
RUN curl -fsSL https://bun.sh/install | bash
COPY package.json bun.lockb .
COPY data-browser/package.json data-browser/.
COPY lib/package.json lib/.
COPY react/package.json react/.
COPY svelte/package.json svelte/.
COPY cli/package.json cli/.
RUN pnpm install --frozen-lockfile --shamefully-hoist
RUN bun install --frozen-lockfile
COPY . .

test:
FROM +deps
RUN pnpm run build
RUN pnpm run test
RUN bun run build
RUN bun run test

lint:
FROM +deps
RUN pnpm run lint
RUN bun run lint

build:
FROM +deps
RUN pnpm run build
RUN bun run build
SAVE ARTIFACT ./data-browser/dist

typedoc:
Expand Down
4 changes: 2 additions & 2 deletions browser/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ https://user-images.githubusercontent.com/2183313/139728539-d69b899f-6f9b-44cb-a

```sh
# To run, simply run the following commands:
pnpm install # install dependencies
pnpm start # run the server!
bun install # install dependencies
bun start # run the server!
# visit http://localhost:5173
```

Expand Down
Binary file modified browser/bun.lockb
Binary file not shown.
4 changes: 2 additions & 2 deletions browser/cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@
"build": "tsc",
"lint": "eslint ./src --ext .js,.ts",
"lint-fix": "eslint ./src --ext .js,.ts --fix",
"prepublishOnly": "pnpm run build && pnpm run lint-fix",
"prepublishOnly": "bun run build && bun run lint-fix",
"watch": "tsc --build --watch",
"start": "pnpm watch",
"start": "bun watch",
"tsc": "tsc --build",
"typecheck": "tsc --noEmit"
},
Expand Down
16 changes: 8 additions & 8 deletions browser/data-browser/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,9 @@ Designed for interacting with [`atomic-server`](https://github.com/atomicdata-de

```sh
# Install dependencies
pnpm
bun
# Run dev server
pnpm start
bun start
# Open browser at http://localhost:5173
```

Expand Down Expand Up @@ -77,15 +77,15 @@ You can set the Agent on the `/app/agent` route.
The tests are located in `tests` and have `.spec` in their filename.
They use the PlayWright framework and run in the browser.

- make sure the data-browser server is running (`pnpm start`) at `http://localhost:5173`
- make sure the data-browser server is running (`bun start`) at `http://localhost:5173`
- make sure an [`atomic-server`](https://crates.io/crates/atomic-server/) instance is running at `http://localhost:9883`
- make sure the `http://localhost/setup` invite has at least one available usage. You can set a higher amount [here](http://localhost/app/edit?subject=http%3A%2F%2Flocalhost%2Fsetup), or run `atomic-server --inititalize` to reset it to 1.
- Install the Playwright dependencies: `pnpm playwright-install`
- `pnpm test` launches the E2E tests (make sure the dev server is running at `http://localhost:5173`)
- `pnpm test-debug` launches the E2E tests in debug mode (a window opens with debug tools)
- `pnpm test-new` create new tests by clicking through the app
- Install the Playwright dependencies: `bun playwright-install`
- `bun test` launches the E2E tests (make sure the dev server is running at `http://localhost:5173`)
- `bun test-debug` launches the E2E tests in debug mode (a window opens with debug tools)
- `bun test-new` create new tests by clicking through the app
- Use the `data-test` attribute in HTML elements to make playwright tests more maintainable (and prevent failing tests on changing translations)
- `pnpm test-query {word}` run e2e tests in debug mode containing `{word}`
- `bun test-query {word}` run e2e tests in debug mode containing `{word}`

## CI

Expand Down
14 changes: 7 additions & 7 deletions browser/e2e/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,19 @@ We use `playwright` to run end-to-end tests in the browser.

```sh
# install deps
pnpm i
bun i
# install chromium
pnpm playwright-install
bun playwright-install
# run all tests, creates a `playwright-report` folder with HTML files + images
pnpm test-e2e
bun test-e2e
# run all tests and updates snapshots
pnpm test-update
bun test-update
# run all tests in debug mode
pnpm test-debug
bun test-debug
# run a single test (e.g. 'table')
pnpm test-query table
bun test-query table
# create a new test
pnpm test-new
bun test-new
# deploy report to netlify
netlify deploy --dir playwright-report --prod --site atomic-tests
```
2 changes: 1 addition & 1 deletion browser/e2e/tests/e2e.spec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// This file is copied from `atomic-data-browser` to `atomic-data-server` when `pnpm build-server` is run.
// This file is copied from `atomic-data-browser` to `atomic-data-server` when `bun build-server` is run.
// This is why the `testConfig` is imported.
import { test, expect } from '@playwright/test';
import {
Expand Down
4 changes: 2 additions & 2 deletions browser/lib/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@
"generate-ontologies": "ad-generate ontologies",
"lint": "eslint ./src --ext .js,.jsx,.ts,.tsx",
"lint-fix": "eslint ./src --ext .js,.jsx,.ts,.tsx --fix",
"prepublishOnly": "pnpm run build && pnpm run lint-fix",
"start": "pnpm watch",
"prepublishOnly": "bun run build && bun run lint-fix",
"start": "bun watch",
"test": "NODE_OPTIONS='--experimental-vm-modules' ../node_modules/jest/bin/jest.js",
"tsc": "tsc --build",
"typecheck": "tsc --noEmit",
Expand Down
23 changes: 12 additions & 11 deletions browser/package.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"devDependencies": {
"@manypkg/cli": "^0.21.2",
"@types/bun": "^1.0.1",
"@types/node": "^16.11.4",
"@types/react": "^18.2.34",
Expand Down Expand Up @@ -29,21 +30,21 @@
"private": true,
"type": "module",
"scripts": {
"dev": "pnpm run start",
"lint": "pnpm run -r lint",
"lint-fix": "pnpm run -r lint-fix",
"build": "pnpm --filter \"@tomic/lib\" run build && pnpm --filter=!./lib run -r build ",
"dev": "./run-all.sh start",
"lint": "./run-all.sh lint",
"lint-fix": "bun run -r lint-fix",
"build": "bun --filter \"@tomic/lib\" run build && bun --filter=!./lib run -r build ",
"test": "bun test .test.ts",
"test-e2e": "pnpm run --filter @tomic/e2e test-e2e",
"test-query": "pnpm run --filter @tomic/e2e test-query",
"start": "pnpm run -r --parallel start",
"test-e2e": "bun run --filter @tomic/e2e test-e2e",
"test-query": "bun run --filter @tomic/e2e test-query",
"start": "bun run -r --parallel start",
"typedoc": "typedoc --options ./typedoc.json",
"typedoc-publish": "pnpm run typedoc && netlify deploy --dir data-browser/publish/docs/ --prod --auth $NETLIFY_AUTH_TOKEN --site atomic-lib",
"typecheck": "pnpm run -r --parallel typecheck"
"typedoc-publish": "bun run typedoc && netlify deploy --dir data-browser/publish/docs/ --prod --auth $NETLIFY_AUTH_TOKEN --site atomic-lib",
"typecheck": "bun run -r --parallel typecheck"
},
"husky": {
"hooks": {
"pre-commit": "pnpm run lint-fix"
"pre-commit": "bun run lint-fix"
}
},
"workspaces": {
Expand All @@ -56,7 +57,7 @@
"cli"
]
},
"packageManager": "[email protected]",
"packageManager": "[email protected]",
"dependencies": {
"eslint-plugin-import": "^2.26.0"
}
Expand Down
4 changes: 2 additions & 2 deletions browser/react/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@
"build": "tsc",
"lint": "eslint ./src --ext .js,.jsx,.ts,.tsx",
"lint-fix": "eslint ./src --ext .js,.jsx,.ts,.tsx --fix",
"prepublishOnly": "pnpm run lint-fix && pnpm run build",
"start": "pnpm watch",
"prepublishOnly": "bun run lint-fix && bun run build",
"start": "bun watch",
"watch": "tsc --build --watch",
"tsc": "tsc --build",
"typecheck": "tsc --noEmit"
Expand Down
25 changes: 25 additions & 0 deletions browser/run-all.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#!/bin/bash

# Check if an argument is provided
if [ $# -eq 0 ]; then
echo "No arguments provided. Usage: ./run-all.sh [script]"
exit 1
fi

# The script to run (e.g., build, test, lint)
script=$1

# Define your list of projects
declare -a projects=("lib" "react" "cli" "svelte" "data-browser")

# Loop over the list of projects
for project in "${projects[@]}"; do
dir="$project"
if [ -d "$dir" ]; then
echo "Running 'bun run $script' in $dir"
# Navigate into the directory, run 'bun run [script]', and then go back
(cd "$dir" && bun run $script)
else
echo "Directory $dir does not exist."
fi
done
2 changes: 1 addition & 1 deletion browser/svelte/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
"module": "./dist/index.js",
"main-dev": "src/index.ts",
"name": "@tomic/svelte",
"packageManager": "[email protected]",
"packageManager": "[email protected]",
"peerDependencies": {
"@tomic/lib": "workspace:*"
},
Expand Down
4 changes: 2 additions & 2 deletions docs/src/atomicserver/installation.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ atomic-server
## 4. Compile from source

```sh
# make sure pnpm is installed and available in path! https://pnpm.io/
pnpm --version
# make sure bun is installed and available in path! https://bun.sh/
bun --version
git clone [email protected]:atomicdata-dev/atomic-server.git
cd atomic-server/server
cargo run
Expand Down

0 comments on commit c220acf

Please sign in to comment.