Skip to content

Commit

Permalink
Merge pull request #2994 from AlchemyCMS/use-bun-as-bundler
Browse files Browse the repository at this point in the history
Switch to Bun as bundler and script runner
  • Loading branch information
tvdeyen authored Aug 12, 2024
2 parents 47f370e + 8f83214 commit cd87b54
Show file tree
Hide file tree
Showing 10 changed files with 99 additions and 4,489 deletions.
50 changes: 25 additions & 25 deletions .github/workflows/build_test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,51 +14,49 @@ on:
pull_request:

jobs:
check_yarn_lock:
check_bun_lock:
runs-on: ubuntu-latest
name: Check yarn.lock
name: Check bun.lockdb
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0 # Fetch all history
- name: Get changed files
id: changed-yarn-lock
id: changed-bun-lock
uses: tj-actions/changed-files@v41
with:
files: yarn.lock
files: bun.lockdb
outputs:
yarn_lock_changed: ${{ steps.changed-yarn-lock.outputs.any_changed }}
bun_lock_changed: ${{ steps.changed-bun-lock.outputs.any_changed }}

build_javascript:
runs-on: ubuntu-latest
name: Build JS packages
needs: check_yarn_lock
if: needs.check_yarn_lock.outputs.yarn_lock_changed == 'true'
needs: check_bun_lock
if: needs.check_bun_lock.outputs.bun_lock_changed == 'true'
steps:
- uses: actions/checkout@v4
- name: Setup Node
uses: actions/setup-node@v4
with:
cache: "yarn"
- name: Setup Bun
uses: oven-sh/setup-bun@v2
- name: Restore node_modules cache
uses: actions/cache@v4
with:
path: node_modules
key: ${{ runner.os }}-node-modules-${{ hashFiles('yarn.lock') }}
key: ${{ runner.os }}-node-modules-${{ hashFiles('bun.lockdb') }}
restore-keys: |
${{ runner.os }}-node-modules
- name: Install dependencies
run: yarn install
- name: YARN build
run: yarn build
run: bun install
- name: bun build
run: bun run --bun build
- uses: actions/upload-artifact@v4
with:
name: javascript-bundles
path: vendor/javascript

RSpec:
needs: [check_yarn_lock, build_javascript]
if: ${{ success('check_yarn_lock') && !failure('build_javascript') }}
needs: [check_bun_lock, build_javascript]
if: ${{ success('check_bun_lock') && !failure('build_javascript') }}
runs-on: ubuntu-latest
strategy:
fail-fast: false
Expand Down Expand Up @@ -141,7 +139,7 @@ jobs:
sudo apt install -qq --fix-missing libmysqlclient-dev -o dir::cache::archives="/home/runner/apt/cache"
sudo chown -R runner /home/runner/apt/cache
- uses: actions/download-artifact@v4
if: needs.check_yarn_lock.outputs.yarn_lock_changed == 'true'
if: needs.check_bun_lock.outputs.bun_lock_changed == 'true'
with:
name: javascript-bundles
path: vendor/javascript
Expand All @@ -165,7 +163,7 @@ jobs:

PushJavascript:
runs-on: ubuntu-latest
needs: [check_yarn_lock, RSpec]
needs: [check_bun_lock, RSpec]
if: github.event_name == 'pull_request'
steps:
- uses: actions/checkout@v4
Expand All @@ -174,7 +172,7 @@ jobs:
persist-credentials: false # otherwise, the token used is the GITHUB_TOKEN, instead of our personal access token.
fetch-depth: 0 # otherwise, there would be errors pushing refs to the destination repository.
- uses: actions/download-artifact@v4
if: needs.check_yarn_lock.outputs.yarn_lock_changed == 'true'
if: needs.check_bun_lock.outputs.bun_lock_changed == 'true'
with:
name: javascript-bundles
path: vendor/javascript
Expand All @@ -201,14 +199,16 @@ jobs:
NODE_ENV: test
steps:
- uses: actions/checkout@v4
- name: Setup Bun
uses: oven-sh/setup-bun@v2
- name: Restore node modules cache
uses: actions/cache@v4
with:
path: node_modules
key: ${{ runner.os }}-yarn-${{ hashFiles('./package.json') }}
key: ${{ runner.os }}-bun-${{ hashFiles('bun.lockdb') }}
restore-keys: |
${{ runner.os }}-yarn-
- name: Install yarn
run: yarn install
${{ runner.os }}-bun-
- name: Install dependencies
run: bun install
- name: Run jest
run: yarn jest --verbose
run: bun run jest --verbose
24 changes: 10 additions & 14 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,38 +25,34 @@ jobs:
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Setup Node
uses: actions/setup-node@v4
with:
node-version: "18"
- name: Setup Bun
uses: oven-sh/setup-bun@v2
- name: Restore node_modules cache
uses: actions/cache@v4
with:
path: node_modules
key: ${{ runner.os }}-node-modules-${{ hashFiles('package.json') }}
key: ${{ runner.os }}-node-modules-${{ hashFiles('bun.lockdb') }}
restore-keys: |
${{ runner.os }}-node-modules
- name: Install dependencies
run: yarn install
run: bun install
- name: Lint code
run: yarn eslint
run: bun run --bun eslint
Prettier:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Setup Node
uses: actions/setup-node@v4
with:
node-version: "18"
- name: Setup Bun
uses: oven-sh/setup-bun@v2
- name: Restore node_modules cache
uses: actions/cache@v4
with:
path: node_modules
key: ${{ runner.os }}-node-modules-${{ hashFiles('package.json') }}
key: ${{ runner.os }}-node-modules-${{ hashFiles('bun.lockdb') }}
restore-keys: |
${{ runner.os }}-node-modules
- name: Install dependencies
run: yarn install
run: bun install
- name: Lint code
run: yarn lint
run: bun run --bun lint
2 changes: 1 addition & 1 deletion alchemy_cms.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ Gem::Specification.new do |gem|
gem.requirements << "ImageMagick (libmagick), v6.6 or greater."
gem.required_ruby_version = ">= 3.0.0"
gem.license = "BSD-3-Clause"
gem.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^spec/|yarn|^\.}) }
gem.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^spec/|bun\.lockdb|package\.json|^\.}) }
gem.require_paths = ["lib"]

%w[
Expand Down
2 changes: 2 additions & 0 deletions bin/setup
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ end
FileUtils.chdir GEM_ROOT do
system! "gem install bundler --conservative"
system("bundle check") || system!("bundle install")
system("bun -v &> /dev/null") || system!("curl -fsSL https://bun.sh/install | bash")
system!("bun install")
end

FileUtils.chdir APP_ROOT do
Expand Down
Binary file added bun.lockb
Binary file not shown.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"eslint": "eslint app/javascript/**/*.js",
"build:js": "rollup -c",
"build:css": "sass --style=compressed --source-map --load-path app/assets/stylesheets --load-path vendor/assets/stylesheets app/assets/stylesheets/alchemy/admin.scss:app/assets/builds/alchemy/admin.css app/assets/stylesheets/alchemy/admin/print.scss:app/assets/builds/alchemy/admin/print.css app/assets/stylesheets/alchemy/welcome.scss:app/assets/builds/alchemy/welcome.css app/assets/stylesheets/tinymce/skins/content/alchemy/content.scss:app/assets/builds/tinymce/skins/content/alchemy/content.min.css app/assets/stylesheets/tinymce/skins/ui/alchemy/skin.scss:app/assets/builds/tinymce/skins/ui/alchemy/skin.min.css",
"build": "yarn build:js && yarn build:css"
"build": "bun run --bun build:js && bun run --bun build:css"
},
"keywords": [],
"author": "Thomas von Deyen",
Expand Down
2 changes: 1 addition & 1 deletion spec/dummy/Procfile.dev
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
web: env RUBY_DEBUG_OPEN=true bin/rails server
css: bin/rails dartsass:watch
sass: cd ../../ && yarn build:css --watch
sass: cd ../../ && bun run --bun build:css --watch
116 changes: 58 additions & 58 deletions vendor/javascript/shoelace.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion vendor/javascript/tinymce.min.js

Large diffs are not rendered by default.

Loading

0 comments on commit cd87b54

Please sign in to comment.