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

feat/migrate to npm from yarn #6173

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
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
6 changes: 3 additions & 3 deletions .dockerignore
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,6 @@

/public/packs
/public/packs-test
/yarn-error.log
yarn-debug.log*
.yarn-integrity
/node_modules
/npm-debug.log
/npm-error.log
4 changes: 2 additions & 2 deletions .github/labeler.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,12 @@ erb:

javascript:
- changed-files:
- any-glob-to-any-file: ["**/*.js", "package*.json", "yarn.lock"]
- any-glob-to-any-file: ["**/*.js", "package*.json", "package-lock.json"]

Tests! 🎉💖👏:
- changed-files:
- any-glob-to-any-file: ["app/javascript/__tests__/**.test.js", "spec/**/*_spec.rb"]

dependencies:
- changed-files:
- any-glob-to-any-file: ["Gemfile*", "package*.json", "yarn.lock"]
- any-glob-to-any-file: ["Gemfile*", "package*.json", "package-lock.json"]
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ jobs:
uses: actions/setup-node@v4
with:
node-version-file: '.nvmrc'
cache: "yarn"
cache: "npm"

rspec_parallel:
needs: [preparation]
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: yarn lint
name: npm lint

on:
push:
Expand All @@ -8,7 +8,7 @@ on:
- '**/*.js'
- '**/*.json'
- '**/*.jsx'
- 'yarn.lock'
- 'package.lock.json'
- '.github/workflows/*.yml'
pull_request:
branches:
Expand All @@ -17,12 +17,11 @@ on:
- '**/*.js'
- '**/*.json'
- '**/*.jsx'
- 'yarn.lock'
- 'package.lock.json'
- '.github/workflows/*.yml'

jobs:
yarn_lint:

npm_lint:
runs-on: ubuntu-latest

steps:
Expand All @@ -32,6 +31,6 @@ jobs:
with:
node-version-file: '.nvmrc'

- run: yarn
- run: yarn lint
- run: yarn test
- run: npm ci
- run: npm run lint
- run: npm run test
4 changes: 2 additions & 2 deletions .github/workflows/rspec.yml
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,8 @@ jobs:
uses: actions/setup-node@v4
with:
node-version-file: '.nvmrc'
cache: "yarn"
- run: yarn
cache: "npm"
- run: npm ci

- name: Install PostgreSQL client
run: |
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/rspec_parallel.yml
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,8 @@ jobs:
uses: actions/setup-node@v4
with:
node-version-file: '.nvmrc'
cache: "yarn"
- run: yarn
cache: "npm"
- run: npm ci

- name: Install PostgreSQL client
run: |
Expand Down
2 changes: 1 addition & 1 deletion .tool-versions
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
ruby 3.3.6
yarn 1.22.22
npm 11.0.0
nodejs 22.11.0
6 changes: 3 additions & 3 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,9 @@ RUN apk add --no-cache --repository http://dl-cdn.alpinelinux.org/alpine/edge/m
WORKDIR $RAILS_ROOT

COPY . .
RUN npm install --global yarn
RUN yarn install
RUN yarn build && yarn build:css
RUN npm install --global npm
RUN npm install
RUN npm run build && npm run build:css

COPY --from=builder /usr/local/bundle/ /usr/local/bundle/

Expand Down
4 changes: 2 additions & 2 deletions Procfile.dev
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
web: bin/rails server -p 3000 -b 0.0.0.0
js: yarn build --watch
css: yarn build:css --watch
js: npm run build --watch
css: npm run build:css --watch
7 changes: 3 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,6 @@ The complete [role description of a CASA volunteer](https://pgcasa.org/volunteer
1. (Recommended) Install [nvm](https://github.com/nvm-sh/nvm#installing-and-updating), which is a **n**ode **v**ersion **m**anager.
- If you use asdf, the node version from `.tool-versions` will be used, but may be out of sync with the codename version in `.nvmrc`. To use the version from `.nvmrc`, see one of these options: [legacy file codename support](https://github.com/asdf-vm/asdf-nodejs?tab=readme-ov-file#partial-and-codename-versions) or [installing via custom script](https://github.com/asdf-vm/asdf-nodejs/issues/382#issuecomment-2258647554).
1. Install a current LTS version of Node. Running `nvm install` from this directory will read the `.nvmrc` file to install the correct version.
1. Install [yarn](https://classic.yarnpkg.com/en/docs/install). On Ubuntu, [make sure you install it from the official Yarn repo instead of cmdtest](https://classic.yarnpkg.com/en/docs/install/#debian-stable).

**PostgreSQL ("postgres")**
1. Make sure that postgres is installed.
Expand Down Expand Up @@ -180,7 +179,7 @@ To see local email previews, check out http://localhost:3000/rails/mailers

**Running Tests**
- run the ruby test suite `bin/rails spec`
- run the javascript test suite `yarn test`
- run the javascript test suite `npm run test`

If you have trouble running tests, check out CI scripts in [`.github/workflows/`](.github/workflows/) for sample commands.
Test coverage is run by simplecov on all builds and aggregated by CodeClimate
Expand All @@ -191,7 +190,7 @@ Run `bin/lint` to run all linters and fix issues. This will run:

1. `bundle exec standardrb --fix` auto-fix Ruby linting issues [more linter info](https://github.com/testdouble/standard)
1. `bundle exec erblint --lint-all --autocorrect` [ERB linter](https://github.com/Shopify/erb-lint)
1. `yarn lint:fix` to run the [JS linter](https://standardjs.com/index.html) and fix issues
1. `npm run lint:fix` to run the [JS linter](https://standardjs.com/index.html) and fix issues
1. `rake factory_bot:lint` if you have been editing factories and want to find factories and traits which produce invalid objects

If additional work arises from your pull request that is outside the scope of the issue it resolves, please open a new issue.
Expand All @@ -216,7 +215,7 @@ Alternatively, every time you pull the main branch, run:
bin/update
```

which will run any database migrations, update gems and yarn packages, and run
which will run any database migrations, update gems and node packages, and run
the after party post-deployment tasks.

# Other Documentation
Expand Down
8 changes: 4 additions & 4 deletions bin/git_hooks/build-assets
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ repo_root="$(git rev-parse --show-toplevel)"

log info "Building Assets"

if ! [ -x "$(command -v yarn)" ]; then
log error "Command yarn could not be found"
if ! [ -x "$(command -v npm)" ]; then
log error "Command npm could not be found"
exit 1
fi

yarn build
yarn build:css
npm run build
npm run build:css
8 changes: 4 additions & 4 deletions bin/git_hooks/lint
Original file line number Diff line number Diff line change
Expand Up @@ -89,12 +89,12 @@ if test $js_changed_count -gt 0; then

cd $repo_root/app

if ! [ -x "$(command -v yarn)" ]; then
log error "Command yarn could not be found"
if ! [ -x "$(command -v npm)" ]; then
log error "Command npm could not be found"
exit 1
else
if ! yarn lint:fix ; then
log error "yarn linting failed, could not fix 1 or more issues\n See above output for more details"
if ! npm run lint:fix ; then
log error "npm linting failed, could not fix 1 or more issues\n See above output for more details"
exit 1
fi
fi
Expand Down
14 changes: 5 additions & 9 deletions bin/git_hooks/update-dependencies
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ if ! [ -x "$(command -v bundle)" ]; then
exit 1
fi

if ! [ -x "$(command -v yarn)" ]; then
log error "Command yarn could not be found"
if ! [ -x "$(command -v npm)" ]; then
log error "Command npm could not be found"
exit 1
fi

Expand All @@ -26,13 +26,9 @@ else
log success "Dependencies up to date"
fi

# run yarn if package.json or yarn.lock has been changed
# Credit to
# https://gist.github.com/foca/3148204

log info "Checking javascript dependency status"

if [ $(git diff HEAD@{1}..HEAD@{0} -- "yarn.lock" | wc -l) -gt 0 ] || [ $(git diff HEAD@{1}..HEAD@{0} -- "package.json" | wc -l) -gt 0 ]; then
log info "Updating javascript dependencies"
yarn
if [ $(git diff HEAD@{1}..HEAD@{0} -- "package-lock.json" | wc -l) -gt 0 ] || [ $(git diff HEAD@{1}..HEAD@{0} -- "package.json" | wc -l) -gt 0 ]; then
log info "Updating JavaScript dependencies"
npm install
fi
2 changes: 1 addition & 1 deletion bin/lint
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@

bundle exec standardrb --fix --format progress
bundle exec erb_lint --lint-all --autocorrect
yarn lint:fix
npm run lint:fix
echo "Linting Factories"
rails factory_bot:lint
18 changes: 18 additions & 0 deletions bin/npm
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#!/usr/bin/env ruby
APP_ROOT = File.expand_path('..', __dir__)
Dir.chdir(APP_ROOT) do
npm = ENV["PATH"].split(File::PATH_SEPARATOR).
select { |dir| File.expand_path(dir) != __dir__ }.
product(["npm", "npm.cmd", "npm.ps1"]).
map { |dir, file| File.expand_path(file, dir) }.
find { |file| File.executable?(file) }

if npm
command = ARGV.empty? ? ["install"] : ARGV
exec npm, *command
else
$stderr.puts "npm executable was not detected in the system."
$stderr.puts "Download npm by installing Node.js from https://nodejs.org/"
exit 1
end
end
10 changes: 5 additions & 5 deletions bin/setup
Original file line number Diff line number Diff line change
Expand Up @@ -49,12 +49,12 @@ FileUtils.chdir APP_ROOT do
puts "\n== Running post-deployment tasks =="
system! 'bin/rake after_party:run'

puts "\n== Installing yarn packages =="
system!('yarn') || abort('install yarn and try again')
puts "\n== Installing npm packages =="
system!('npm ci') || abort('install npm and try again')

puts "\n==Building assets =="
system!('yarn build')
system!('yarn build:css')
puts "\n== Building assets =="
system!('npm run build')
system!('npm run build:css')

puts "\n== Done =="
end
11 changes: 6 additions & 5 deletions bin/update
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,9 @@ chdir APP_ROOT do
system! 'gem install bundler --conservative'
system('bundle check') || system!('bundle install')

puts 'Updating yarn'
system('yarn install') || abort("install yarn and try again")
puts 'Updating npm'
system('npm install') || abort("Install npm and try again")


puts "\n== Updating database =="
system! 'bin/rails db:migrate'
Expand All @@ -33,9 +34,9 @@ chdir APP_ROOT do
puts "\n== Restarting application server =="
system! 'bin/rails restart'

puts "\n==Building assets =="
system!('yarn build')
system!('yarn build:css')
puts "\n== Building assets =="
system('npm run build') || abort("Failed to build assets. Ensure npm is installed and try again.")
system('npm run build:css') || abort("Failed to build CSS assets. Ensure npm is installed and try again.")

puts "\n== Done =="
end
17 changes: 0 additions & 17 deletions bin/yarn

This file was deleted.

6 changes: 3 additions & 3 deletions doc/DOCKER.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,9 @@ The following commands should just be run for the initial setup only. Rebuilding
3. Run `docker compose build` to build images for all services.
4. Run `docker compose run --rm web bundle install` to install ruby dependencies
5. Run `docker compose run --rm web rails db:reset` to create the dev and test databases, load the schema, and run the seeds file.
6. Run `docker compose run --rm web yarn` to install javascript dependencies
7. Run `docker compose run --rm web yarn build` to bundle javascript assets
8. Run `docker compose run --rm web yarn build:css` to bundle the css
6. Run `docker compose run --rm web npm install` to install javascript dependencies
7. Run `docker compose run --rm web npm run build` to bundle javascript assets
8. Run `docker compose run --rm web npm run build:css` to bundle the css
9. Run `docker compose up` to start all the remaining services. Or use `docker compose up -d` to start containers in the background.
10. Run `docker compose ps` to view status of the containers. All should have state "Up". Check the [logs](#viewing-logs) if there are any containers that did not start.
11. The web application will be available at http://localhost:3000
Expand Down
11 changes: 3 additions & 8 deletions doc/LINUX_SETUP.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,11 +67,6 @@ nvm install
npm i -g npm@latest
```

```
# Install Yarn
npm i -g yarn
```

```
# add node and node tools to the path
nvm alias default lts/jod
Expand Down Expand Up @@ -146,8 +141,8 @@ bundle exec rails db:setup # Create your local test database
bundle exec rails db:migrate # Update the database if it's out of date
bundle exec rake after_party:run # Run post deployment tasks

yarn # install javascript dependencies
yarn build # compile javascript
yarn build:css # compile css
npm install # install javascript dependencies
npm run build # compile javascript
npm run build:css # compile css
```
[Back to the main readme for steps to test your installation.](https://github.com/rubyforgood/casa#running-the-app--verifying-installation)
12 changes: 4 additions & 8 deletions doc/MAC_SETUP.md
Original file line number Diff line number Diff line change
Expand Up @@ -70,16 +70,12 @@ rbenv local 3.3.6

## Nodejs

The Casa package frontend leverages several javascript packages managed through `yarn`, so if you are working on those elements you will want to have node, npm, and yarn installed.
The Casa package frontend leverages several javascript packages managed through `npm`.

```bash
brew install node
```

```
brew install yarn
```

## Chrome
Many of the frontend tests are run using Google Chrome, so if you don't already have that installed you may wish to include it:

Expand All @@ -103,19 +99,19 @@ bin/rails db:setup

Install javascript dependencies with:
```bash
yarn install
npm install
```

Compile assets with:

```bash
yarn build
npm run build
```

and then:

```bash
yarn build:css
npm run build:css
```

And lastly, run the app with:
Expand Down
2 changes: 1 addition & 1 deletion doc/NIX_SETUP.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

If you have [Nix](https://nixos.org) installed you can use the [flake.nix](flake.nix)
configuration file located at the root of the project to build and develop within an environment
without needing to install `rvm`, `nodejs`, `yarn`, `postgresql` or other tools separately.
without needing to install `rvm`, `nodejs`, `postgresql` or other tools separately.
The environment also uses the `gemset.nix` file to automatically download and install all the gems
necessary to get the server up and running:

Expand Down
Loading
Loading