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

build: yarn to bun #4083

Draft
wants to merge 10 commits into
base: master
Choose a base branch
from
Draft
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 .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
*.lockb binary diff=lockb
8 changes: 3 additions & 5 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,8 @@ jobs:
- uses: actions/setup-node@v4
with:
node-version: '22'
cache: 'yarn'
- run: make yarn
- run: 'echo "nodeLinker: node-modules" >>.yarnrc.yml'
- run: yarn install
cache: 'bun'
- run: make node_modules
- uses: reviewdog/action-eslint@v1
with:
reporter: github-pr-review
Expand All @@ -33,4 +31,4 @@ jobs:
level: warning
fail_on_error: true
- name: tsc
run: yarn run check
run: ./bin/tools/bun run check
1 change: 1 addition & 0 deletions .labelignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@
go.mod
go.sum
.yarn/releases/*
*.lockb
17 changes: 4 additions & 13 deletions .storybook/main.ts
Original file line number Diff line number Diff line change
@@ -1,24 +1,15 @@
import type { StorybookConfig } from '@storybook/react-vite'

import { join, dirname } from 'path'

/**
* This function is used to resolve the absolute path of a package.
* It is needed in projects that use Yarn PnP or are set up within a monorepo.
*/
function getAbsolutePath(value: string): any {
return dirname(require.resolve(join(value, 'package.json')))
}
const config: StorybookConfig = {
staticDirs: ['./static'],
stories: ['../web/src/**/*.stories.@(js|jsx|mjs|ts|tsx)'],
addons: [
getAbsolutePath('@storybook/addon-links'),
getAbsolutePath('@storybook/addon-essentials'),
getAbsolutePath('@storybook/addon-interactions'),
'@storybook/addon-links',
'@storybook/addon-essentials',
'@storybook/addon-interactions',
],
framework: {
name: getAbsolutePath('@storybook/react-vite'),
name: '@storybook/react-vite',
options: {},
},
docs: {
Expand Down
894 changes: 0 additions & 894 deletions .yarn/releases/yarn-4.3.1.cjs

This file was deleted.

17 changes: 0 additions & 17 deletions .yarnrc.yml

This file was deleted.

93 changes: 37 additions & 56 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,10 @@ SWO_DB_URL_NEXT = $(shell go run ./devtools/scripts/db-url "$(DB_URL)" "$(SWO_DB

LOG_DIR=
GOPATH:=$(shell go env GOPATH)
YARN_VERSION=4.3.1
PG_VERSION=13

# add all files except those under web/src/build and web/src/cypress
NODE_DEPS=.pnp.cjs .yarnrc.yml .gitrev $(shell find web/src -path web/src/build -prune -o -path web/src/cypress -prune -o -type f -print) web/src/app/editor/expr-parser.ts
NODE_DEPS=.gitrev $(shell find web/src -path web/src/build -prune -o -path web/src/cypress -prune -o -type f -print) web/src/app/editor/expr-parser.ts node_modules

# Use sha256sum on linux and shasum -a 256 on mac
SHA_CMD := $(shell if [ -x "$(shell command -v sha256sum 2>/dev/null)" ]; then echo "sha256sum"; else echo "shasum -a 256"; fi)
Expand All @@ -35,7 +34,7 @@ export CY_ACTION = open
export CY_BROWSER = chrome

export CGO_ENABLED = 0
export PATH := $(PWD)/bin:$(PATH)
export PATH := $(PWD)/bin:$(PWD)/bin/tools:$(PATH)
export GOOS = $(shell go env GOOS)
export GOALERT_DB_URL_NEXT = $(DB_URL_NEXT)

Expand Down Expand Up @@ -78,6 +77,16 @@ $(BIN_DIR)/tools/mailpit: mailpit.version
$(BIN_DIR)/tools/sqlc: sqlc.version
go run ./devtools/gettool -t sqlc -v $(shell cat sqlc.version) -o $@

$(BIN_DIR)/tools/bun: bun.version
go run ./devtools/gettool -t bun -v $(shell cat bun.version) -o $@

bun.lockb: $(BIN_DIR)/tools/bun
$(BIN_DIR)/tools/bun install

node_modules: $(BIN_DIR)/tools/bun package.json bun.lockb
$(BIN_DIR)/tools/bun install
touch "$@"

$(BIN_DIR)/tools/prometheus: prometheus.version
go run ./devtools/gettool -t prometheus -v $(shell cat prometheus.version) -o $@

Expand Down Expand Up @@ -112,9 +121,8 @@ goalert-client.key: system.ca.pem plugin.ca.key plugin.ca.pem
goalert-client.ca.pem: system.ca.pem plugin.ca.key plugin.ca.pem
go run ./cmd/goalert gen-cert client

cypress: bin/goalert.cover bin/psql-lite bin/pgmocktime $(NODE_DEPS) web/src/schema.d.ts $(BIN_DIR)/build/integration/cypress/plugins/index.js
$(MAKE) ensure-yarn
yarn cypress install
cypress: bin/goalert.cover bin/psql-lite bin/pgmocktime $(NODE_DEPS) web/src/schema.d.ts $(BIN_DIR)/build/integration/cypress/plugins/index.js node_modules
$(BIN_DIR)/tools/bun run cypress install

cy-wide: cypress ## Start cypress tests in desktop mode with dev build in UI mode
GOALERT_VERSION=$(GIT_VERSION) CONTAINER_TOOL=$(CONTAINER_TOOL) CYPRESS_viewportWidth=1440 CYPRESS_viewportHeight=900 go run ./devtools/runproc -f Procfile.cypress
Expand Down Expand Up @@ -184,8 +192,7 @@ start-integration: web/src/build/static/app.js bin/goalert bin/psql-lite bin/wai
GOALERT_DB_URL="$(INT_DB_URL)" ./bin/runproc -f Procfile.integration

jest: $(NODE_DEPS)
$(MAKE) ensure-yarn
yarn run jest $(JEST_ARGS)
$(BIN_DIR)/tools/bun run jest $(JEST_ARGS)

test: $(NODE_DEPS) jest $(BIN_DIR)/tools/mailpit ## Run all unit tests
rm -rf $(PWD)/test/coverage/unit
Expand All @@ -195,28 +202,10 @@ test: $(NODE_DEPS) jest $(BIN_DIR)/tools/mailpit ## Run all unit tests
check: check-go check-js ## Run all lint checks
./devtools/ci/tasks/scripts/codecheck.sh

.yarnrc.yml: package.json
$(MAKE) yarn
touch "$@"

.yarn/releases/yarn-$(YARN_VERSION).cjs:
yarn set version $(YARN_VERSION) || $(MAKE) yarn

ensure-yarn: # Yarn ensures the correct version of yarn is installed
@echo "Checking yarn version..."
@yarn --version | grep -q -F "$(YARN_VERSION)" || $(MAKE) yarn
$(MAKE) .yarn/releases/yarn-$(YARN_VERSION).cjs

yarn:
corepack enable
corepack prepare yarn@$(YARN_VERSION) --activate

check-js: generate $(NODE_DEPS)
$(MAKE) ensure-yarn
yarn install
yarn run fmt
yarn run lint
yarn run check
$(BIN_DIR)/tools/bun run fmt
$(BIN_DIR)/tools/bun run lint
$(BIN_DIR)/tools/bun run check

check-go: generate $(BIN_DIR)/tools/golangci-lint
@go mod tidy
Expand Down Expand Up @@ -248,26 +237,24 @@ test-smoke: smoketest
test-unit: test

test-components: $(NODE_DEPS) bin/waitfor
yarn build-storybook --test --quiet 2>/dev/null
yarn playwright install chromium
yarn concurrently -k -s first -n "SB,TEST" -c "magenta,blue" \
"yarn http-server storybook-static -a 127.0.0.1 --port 6008 --silent" \
"./bin/waitfor tcp://localhost:6008 && yarn test-storybook --ci --url http://127.0.0.1:6008 --maxWorkers 2"
$(BIN_DIR)/tools/bun run build-storybook --test --quiet 2>/dev/null
$(BIN_DIR)/tools/bun run playwright install chromium
$(BIN_DIR)/tools/bun run concurrently -k -s first -n "SB,TEST" -c "magenta,blue" \
"$(BIN_DIR)/tools/bun run http-server storybook-static -a 127.0.0.1 --port 6008 --silent" \
"./bin/waitfor tcp://localhost:6008 && $(BIN_DIR)/tools/bun run test-storybook --ci --url http://127.0.0.1:6008 --maxWorkers 2"

storybook: ensure-yarn $(NODE_DEPS) # Start the Storybook UI
yarn storybook
storybook: $(NODE_DEPS) # Start the Storybook UI
$(BIN_DIR)/tools/bun run storybook

playwright-run: $(NODE_DEPS) bin/mockoidc web/src/build/static/app.js bin/goalert.cover web/src/schema.d.ts $(BIN_DIR)/tools/prometheus $(BIN_DIR)/tools/mailpit reset-integration ## Start playwright tests in headless mode
$(MAKE) ensure-yarn
rm -rf test/coverage/integration/playwright
mkdir -p test/coverage/integration/playwright
yarn playwright install chromium
GOCOVERDIR=test/coverage/integration/playwright yarn playwright test
$(BIN_DIR)/tools/bun run playwright install chromium
GOCOVERDIR=test/coverage/integration/playwright $(BIN_DIR)/tools/bun run playwright test

playwright-ui: $(NODE_DEPS) bin/mockoidc web/src/build/static/app.js bin/goalert web/src/schema.d.ts $(BIN_DIR)/tools/prometheus $(BIN_DIR)/tools/mailpit reset-integration ## Start the Playwright UI
$(MAKE) ensure-yarn
yarn playwright install chromium
yarn playwright test --ui
playwright-ui: $(NODE_DEPS) bin/mockoidc web/src/build/static/app.js bin/goalert web/src/schema.d.ts $(BIN_DIR)/tools/prometheus reset-integration $(BIN_DIR)/tools/mailpit ## Start the Playwright UI
$(BIN_DIR)/tools/bun run playwright install chromium
$(BIN_DIR)/tools/bun run playwright test --ui

smoketest: $(BIN_DIR)/tools/mailpit
rm -rf test/coverage/smoke
Expand Down Expand Up @@ -296,27 +283,24 @@ tools:
go get -u golang.org/x/tools/cmd/goimports
go get -u golang.org/x/tools/cmd/stringer

.pnp.cjs: yarn.lock Makefile package.json .yarnrc.yml
$(MAKE) ensure-yarn
yarn install && touch "$@"


web/src/app/editor/expr-parser.ts: web/src/app/editor/expr.grammar .pnp.cjs

web/src/app/editor/expr-parser.ts: web/src/app/editor/expr.grammar node_modules
# we need to use .tmp.ts as the extension because lezer-generator will append .ts to the output file
yarn run lezer-generator $< --noTerms --typeScript -o [email protected]
yarn run prettier -l --write [email protected]
bin/tools/bun run lezer-generator $< --noTerms --typeScript -o [email protected]
bin/tools/bun run prettier -l --write [email protected]
cat [email protected] | sed "s/You probably shouldn't edit it./DO NOT EDIT/" >$@
rm [email protected]

web/src/build/static/explore.js: web/src/build/static/app.js
web/src/build/static/app.js: $(NODE_DEPS)
$(MAKE) ensure-yarn
rm -rf web/src/build/static
mkdir -p web/src/build/static
cp -f web/src/app/public/icons/favicon-* web/src/app/public/logos/lightmode_* web/src/app/public/logos/darkmode_* web/src/build/static/
# used for email templates
cp web/src/app/public/logos/goalert-alt-logo.png web/src/build/static/
GOALERT_VERSION=$(GIT_VERSION) yarn run esbuild --prod
GOALERT_VERSION=$(GIT_VERSION) $(BIN_DIR)/tools/bun run esbuild --prod
touch "$@"

notification/desttype_string.go: notification/desttype.go
Expand Down Expand Up @@ -359,11 +343,8 @@ new-migration:
@echo "-- +migrate Up\n\n\n-- +migrate Down\n" >migrate/migrations/$(shell date +%Y%m%d%H%M%S)-$(NAME).sql
@echo "Created: migrate/migrations/$(shell date +%Y%m%d%H%M%S)-$(NAME).sql"

vscode: $(NODE_DEPS)
yarn dlx @yarnpkg/sdks vscode

upgrade-js: ## Interactively upgrade javascript packages
yarn upgrade-interactive
vscode:
echo "make vscode is no longer necessary since the migration to bun"

test/coverage/total.out: test/coverage/integration/*/* test/coverage/*/* Makefile
rm -rf test/coverage/total
Expand Down
4 changes: 2 additions & 2 deletions Makefile.binaries.mk
Original file line number Diff line number Diff line change
Expand Up @@ -78,9 +78,9 @@ ifeq ($(PUSH),1)
podman manifest push --all $(IMAGE_REPO)/goalert:$(IMAGE_TAG) docker://$(IMAGE_REPO)/goalert:$(IMAGE_TAG)
endif

$(BIN_DIR)/build/integration/cypress/plugins/index.js: package.json yarn.lock web/src/esbuild.cypress.js $(shell find ./web/src/cypress)
$(BIN_DIR)/build/integration/cypress/plugins/index.js: package.json bun.lockb web/src/esbuild.cypress.js $(shell find ./web/src/cypress)
rm -rf $@
yarn run esbuild-cy
$(BIN_DIR)/tools/bun run esbuild-cy
mkdir -p $@/plugins
cp web/src/cypress/plugins/index.js $@/plugins/index.js
touch $@
Expand Down
2 changes: 1 addition & 1 deletion Procfile
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ smtp: ./bin/tools/mailpit -s localhost:1025 -l localhost:8025
prom: bin/tools/prometheus --log.level=warn --config.file=devtools/prometheus/prometheus.yml --storage.tsdb.path=bin/prom-data/ --web.listen-address=localhost:9090

@watch-file=./web/src/esbuild.config.js
ui: yarn run esbuild --watch
ui: ./bin/tools/bun run esbuild --watch

grpcui: go run ./devtools/waitfor tcp://localhost:1234 && go run github.com/fullstorydev/grpcui/cmd/grpcui -plaintext -open-browser=false -port 8234 localhost:1234

Expand Down
6 changes: 3 additions & 3 deletions Procfile.cypress
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,16 @@ build: while true; do make -qs bin/goalert.cover || make bin/goalert.cover || (e
goalert: go run ./devtools/waitfor postgres://[email protected]:5433 && go run ./devtools/procwrap -test=127.0.0.1:3042 bin/goalert.cover -l=127.0.0.1:3042 --ui-dir=web/src/build --db-url=postgres://[email protected]:5433 --slack-base-url=http://127.0.0.1:3040/slack --stub-notifiers --log-errors-only --public-url=http://127.0.0.1:3040$HTTP_PREFIX

@watch-file=./web/src/esbuild.config.js
ui: yarn run esbuild --watch
ui: ./bin/tools/bun run esbuild --watch

@watch-file=./web/src/esbuild.cypress.js
build-cy: yarn run esbuild-cy --watch
build-cy: ./bin/tools/bun run esbuild-cy --watch

slack: go run ./devtools/mockslack/cmd/mockslack -client-id=000000000000.000000000000 -client-secret=00000000000000000000000000000000 -access-token=xoxp-000000000000-000000000000-000000000000-00000000000000000000000000000000 -prefix=/slack -single-user=bob -addr=127.0.0.1:3046

proxy: go run ./devtools/simpleproxy -addr=127.0.0.1:3040 /slack/=http://127.0.0.1:3046 http://127.0.0.1:3042

@oneshot
cypress: go run ./devtools/waitfor http://127.0.0.1:3042 && CYPRESS_DB_URL=postgres://[email protected]:5433 yarn cypress open --config baseUrl=http://127.0.0.1:3040$HTTP_PREFIX
cypress: go run ./devtools/waitfor http://127.0.0.1:3042 && CYPRESS_DB_URL=postgres://[email protected]:5433 ./bin/tools/bun run cypress open --config baseUrl=http://127.0.0.1:3040$HTTP_PREFIX

db: $CONTAINER_TOOL rm -f smoketest-postgres || true; $CONTAINER_TOOL run -it --rm --name smoketest-postgres -p5433:5432 -e=POSTGRES_HOST_AUTH_METHOD=trust postgres:13-alpine
2 changes: 1 addition & 1 deletion Procfile.cypress.ci
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
@oneshot
cypress: go run ./devtools/waitfor http://127.0.0.1:3042 && CYPRESS_DB_URL=$DB_URL yarn cypress $CY_ACTION --config baseUrl=http://127.0.0.1:3040$HTTP_PREFIX
cypress: go run ./devtools/waitfor http://127.0.0.1:3042 && CYPRESS_DB_URL=$DB_URL ./bin/tools/bun run cypress $CY_ACTION --config baseUrl=http://127.0.0.1:3040$HTTP_PREFIX

goalert: go run ./devtools/waitfor $DB_URL && go run ./devtools/procwrap -test=127.0.0.1:3042 bin/goalert.cover -l=127.0.0.1:3042 --db-url=$DB_URL --slack-base-url=http://127.0.0.1:3040/slack --stub-notifiers --log-errors-only --public-url=http://127.0.0.1:3040$HTTP_PREFIX

Expand Down
6 changes: 3 additions & 3 deletions Procfile.cypress.prod
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@ slack: go run ./devtools/mockslack/cmd/mockslack -client-id=000000000000.0000000
proxy: go run ./devtools/simpleproxy -addr=127.0.0.1:3040 /slack/=http://127.0.0.1:3046 http://127.0.0.1:3042

@oneshot
cypress: go run ./devtools/waitfor http://127.0.0.1:3042 && CYPRESS_DB_URL=postgres://[email protected]:5433 yarn cypress $CY_ACTION --config baseUrl=http://127.0.0.1:3040$HTTP_PREFIX
cypress: go run ./devtools/waitfor http://127.0.0.1:3042 && CYPRESS_DB_URL=postgres://[email protected]:5433 ./bin/tools/bun run cypress $CY_ACTION --config baseUrl=http://127.0.0.1:3040$HTTP_PREFIX

db: $CONTAINER_TOOL rm -f smoketest-postgres || true; $CONTAINER_TOOL run -it --rm --name smoketest-postgres -p5433:5432 -e=POSTGRES_HOST_AUTH_METHOD=trust postgres:13-alpine


@watch-file=./web/src/esbuild.config.js
ui: yarn run esbuild --watch --prod
ui: ./bin/tools/bun run esbuild --watch --prod

@watch-file=./web/src/esbuild.cypress.js
build-cy: yarn run esbuild-cy --watch
build-cy: ./bin/tools/bun run esbuild-cy --watch
2 changes: 1 addition & 1 deletion Procfile.swo
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ smtp: ./bin/tools/mailpit -s localhost:1025 -l localhost:8025
prom: bin/tools/prometheus --log.level=warn --config.file=devtools/prometheus/prometheus-swo.yml --storage.tsdb.path=bin/prom-data/ --web.listen-address=localhost:9090

@watch-file=./web/src/esbuild.config.js
ui: yarn run esbuild --watch
ui: ./bin/tools/bun run esbuild --watch

@watch-file=./bin/goalert
ga2: ./bin/goalert -l=localhost:3050 --ui-dir=web/src/build --db-url=postgres://goalert@localhost:5435/goalert?sslmode=disable --listen-prometheus=localhost:2113 --db-url-next=postgres://goalert@localhost:5435/goalert2 --api-only
Expand Down
Binary file added bun.lockb
Binary file not shown.
1 change: 1 addition & 0 deletions bun.version
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
1.1.29
4 changes: 2 additions & 2 deletions devtools/genmake/template.mk
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,9 @@ ifeq ($(PUSH),1)
podman manifest push --all $(IMAGE_REPO)/goalert:$(IMAGE_TAG) docker://$(IMAGE_REPO)/goalert:$(IMAGE_TAG)
endif

$(BIN_DIR)/build/integration/cypress/plugins/index.js: package.json yarn.lock web/src/esbuild.cypress.js $(shell find ./web/src/cypress)
$(BIN_DIR)/build/integration/cypress/plugins/index.js: package.json bun.lockb web/src/esbuild.cypress.js $(shell find ./web/src/cypress)
rm -rf $@
yarn run esbuild-cy
$(BIN_DIR)/tools/bun run esbuild-cy
mkdir -p $@/plugins
cp web/src/cypress/plugins/index.js $@/plugins/index.js
touch $@
Expand Down
47 changes: 47 additions & 0 deletions devtools/gettool/getbun.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
package main

import (
"archive/zip"
"fmt"
"path/filepath"
"runtime"
)

func getBun(version, output string) error {
var arch string
switch runtime.GOARCH {
case "amd64":
arch = "x64"
case "arm64":
arch = "aarch64"
default:
return fmt.Errorf("unsupported arch: %s", runtime.GOARCH)
}

url := fmt.Sprintf("https://github.com/oven-sh/bun/releases/download/bun-v%s/bun-%s-%s.zip",
version, runtime.GOOS, arch,
)
fd, n, err := fetchFile(url)
if err != nil {
return fmt.Errorf("fetch: %w", err)
}
defer fd.Close()

name := fmt.Sprintf("bun-%s-%s/bun", runtime.GOOS, arch)
if runtime.GOOS == "windows" {
name += ".exe"
}

outDir := filepath.Dir(output)
z, err := zip.NewReader(fd, n)
if err != nil {
return fmt.Errorf("unzip: %w", err)
}

err = extractFromZip(z, name, filepath.Join(outDir, "bun"), true)
if err != nil {
return fmt.Errorf("extract bin: %w", err)
}

return nil
}
2 changes: 2 additions & 0 deletions devtools/gettool/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ func main() {
err = getGolangCiLint(*version, *output)
case "sqlc":
err = getSqlc(*version, *output)
case "bun":
err = getBun(*version, *output)
case "mailpit":
err = getMailpit(*version, *output)
case "k6":
Expand Down
Loading
Loading