Skip to content

Latest commit

 

History

History
84 lines (54 loc) · 2.32 KB

File metadata and controls

84 lines (54 loc) · 2.32 KB

Updating Ruby and JavaScript Dependencies

If you frequently update dependencies in small batches, you will avoid large and painful updates later. Then again, if you don't have good test coverage, it's hazardous to update dependencies at any time.

Ruby

Delete any unwanted version constraints from your Gemfile and run:

bundle update

Node Dependencies

Run the commands below from the directory that contains your package.json. In current React on Rails apps, that is usually the app root rather than a client/ subdirectory.

Checking for Outdated Packages

Check for outdated versions of packages:

pnpm outdated

Use the equivalent npm outdated or yarn outdated command if your app uses a different package manager. Read CHANGELOGs of major updated packages before you update. You might not be ready for some updates.

Updating All Dependencies

Option 1: Using npm-check-updates (Recommended)

  1. Install npm-check-updates

  2. Run these commands. You may or may not need to rm -rf your node_modules directory.

    pnpm dlx npm-check-updates -u -a
    pnpm install

Some combinations that I often run:

  • Remove old installed node_modules so you only get what corresponds to package.json:

    pnpm dlx npm-check-updates -u -a && rm -rf node_modules && pnpm install

Use the equivalent npx npm-check-updates -u -a && npm install or yarn dlx npm-check-updates -u -a && yarn install flow if your app does not use pnpm.

Option 2: Using your package manager's upgrade command

To update all dependencies:

pnpm up --latest

To upgrade a specific package:

pnpm up [package] --latest

Equivalent commands for other package managers are npm update / npm install <package>@latest and yarn upgrade / yarn add <package>@latest.

Adding New Dependencies

Typically, you can add your Node dependencies as you normally would:

pnpm add module_name@version
# or for dev dependencies
pnpm add -D module_name@version

If your app uses npm or yarn, use the corresponding npm install or yarn add command in the same directory as package.json.

Verify After Updates

Confirm that the hot replacement dev server and the Rails server both work after updating dependencies.