Skip to content

Commit

Permalink
Remove yarn integrity check (#2518)
Browse files Browse the repository at this point in the history
* Remove the yarn integrity check

The `yarn check` command has been removed in Yarn 2.0.

The yarn integrity check in Webpacker has commonly been a source of
confusion and frustration among developers. Its behavior at times does
not always match expectation.

Yarn's maintainer has described `yarn check` as buggy and discourages
its use: yarnpkg/yarn#6427 (comment)

This PR removes the yarn integrity check from the Webpacker railtie as
well as references to its setting in Webpacker::Configuration.

The Webpacker::Configuration#check_yarn_integrity= method has been left
in with a deprecation warning to avoid a breaking change.

* Add deployment note in README

It's recommended to use `yarn install --frozen-lockfile` in a deployment
context prior to compiling assets for production. This practice may help
offset potential concerns with the removal of the yarn integrity check,
at least in production environemnts.

* Update README with note about yarn install
  • Loading branch information
rossta authored Apr 11, 2020
1 parent 9e0c3c2 commit 09caeed
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 74 deletions.
29 changes: 8 additions & 21 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ in which case you may not even need the asset pipeline. This is mostly relevant
- [Webpack Configuration](#webpack-configuration)
- [Custom Rails environments](#custom-rails-environments)
- [Upgrading](#upgrading)
- [Yarn Integrity](#yarn-integrity)
- [Integrations](#integrations)
- [React](./docs/integrations.md#react)
- [Angular with TypeScript](./docs/integrations.md#angular-with-typescript)
Expand Down Expand Up @@ -107,6 +106,12 @@ Optional: To fix ["unmet peer dependency" warnings](https://github.com/rails/web
yarn upgrade
```

When `package.json` and/or `yarn.lock` changes, such as when pulling down changes to your local environemnt in a team settings, be sure to keep your NPM packages up-to-date:

```bash
yarn install
```

### Usage

Once installed, you can start writing modern ES6-flavored JavaScript apps right away:
Expand Down Expand Up @@ -300,26 +305,6 @@ yarn upgrade webpack-dev-server --latest
yarn add @rails/webpacker@next
```

### Yarn Integrity

By default, in development, webpacker runs a yarn integrity check to ensure that all local JavaScript packages are up-to-date. This is similar to what bundler does currently in Rails, but for JavaScript packages. If your system is out of date, then Rails will not initialize. You will be asked to upgrade your local JavaScript packages by running `yarn install`.

To turn off this option, you will need to change the default setting in `config/webpacker.yml`:

```yaml
# config/webpacker.yml
development:
...
# Verifies that correct packages and versions are installed by inspecting package.json, yarn.lock, and node_modules
check_yarn_integrity: false
```

You may also turn on this feature by adding the config option for any Rails environment in `config/webpacker.yml`:

```yaml
check_yarn_integrity: true
```

## Integrations

Webpacker ships with basic out-of-the-box integration. You can see a list of available commands/tasks by running `bundle exec rails webpacker`.
Expand Down Expand Up @@ -413,6 +398,8 @@ Webpacker::Compiler.watched_paths << 'bower_components'

Webpacker hooks up a new `webpacker:compile` task to `assets:precompile`, which gets run whenever you run `assets:precompile`. If you are not using Sprockets, `webpacker:compile` is automatically aliased to `assets:precompile`. Similar to sprockets both rake tasks will compile packs in production mode but will use `RAILS_ENV` to load configuration from `config/webpacker.yml` (if available).

When compiling assets for production on a remote server, such as a continuous integration environment, it's recommended to use `yarn install --frozen-lockfile` to install NPM packages on the remote host to ensure that the installed packages match the `yarn.lock` file.

## Docs

- [Development](https://github.com/rails/webpacker#development)
Expand Down
4 changes: 0 additions & 4 deletions lib/install/config/webpacker.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ default: &default
public_root_path: public
public_output_path: packs
cache_path: tmp/cache/webpacker
check_yarn_integrity: false
webpack_compile_output: true

# Additional paths webpack should lookup modules
Expand Down Expand Up @@ -52,9 +51,6 @@ development:
<<: *default
compile: true

# Verifies that correct packages and versions are installed by inspecting package.json, yarn.lock, and node_modules
check_yarn_integrity: true

# Reference: https://webpack.js.org/configuration/dev-server/
dev_server:
https: false
Expand Down
6 changes: 1 addition & 5 deletions lib/webpacker/configuration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -64,11 +64,7 @@ def extensions
end

def check_yarn_integrity=(value)
data[:check_yarn_integrity] = value
end

def check_yarn_integrity?
fetch(:check_yarn_integrity)
warn "Webpacker::Configuration#check_yarn_integrity=(value) has been deprecated. The integrity check has been removed from Webpacker so changing this setting will have no effect."
end

def webpack_compile_output?
Expand Down
43 changes: 0 additions & 43 deletions lib/webpacker/railtie.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,49 +7,6 @@ class Webpacker::Engine < ::Rails::Engine
# Allows Webpacker config values to be set via Rails env config files
config.webpacker = ActiveSupport::OrderedOptions.new

initializer "webpacker.set_configs" do |app|
if app.config.webpacker.key?(:check_yarn_integrity)
Webpacker.config.check_yarn_integrity = app.config.webpacker.check_yarn_integrity
end
end

# ================================
# Check Yarn Integrity Initializer
# ================================
#
# development (on by default):
#
# to turn off:
# - edit config/environments/development.rb
# - add `config.webpacker.check_yarn_integrity = false`
#
# production (off by default):
#
# to turn on:
# - edit config/environments/production.rb
# - add `config.webpacker.check_yarn_integrity = true`
initializer "webpacker.yarn_check" do |app|
if File.exist?("yarn.lock") && Webpacker.config.config_path.exist? && Webpacker.config.check_yarn_integrity?
output = `yarn check --integrity && yarn check --verify-tree 2>&1`

unless $?.success?
$stderr.puts "\n\n"
$stderr.puts "========================================"
$stderr.puts " Your Yarn packages are out of date!"
$stderr.puts " Please run `yarn install --check-files` to update."
$stderr.puts "========================================"
$stderr.puts "\n\n"
$stderr.puts "To disable this check, please change `check_yarn_integrity`"
$stderr.puts "to `false` in your webpacker config file (config/webpacker.yml)."
$stderr.puts "\n\n"
$stderr.puts output
$stderr.puts "\n\n"

exit(1)
end
end
end

initializer "webpacker.proxy" do |app|
insert_middleware = Webpacker.config.dev_server.present? rescue nil
if insert_middleware
Expand Down
1 change: 0 additions & 1 deletion test/test_app/config/application.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ module TestApp
class Application < ::Rails::Application
config.secret_key_base = "abcdef"
config.eager_load = true
config.webpacker.check_yarn_integrity = false
config.active_support.test_order = :sorted
end
end

0 comments on commit 09caeed

Please sign in to comment.