Skip to content

Commit

Permalink
Remove the yarn integrity check
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
rossta committed Apr 1, 2020
1 parent 8e8e745 commit 4538582
Show file tree
Hide file tree
Showing 5 changed files with 1 addition and 74 deletions.
21 changes: 0 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 @@ -300,26 +299,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
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 4538582

Please sign in to comment.