Skip to content

Commit 09caeed

Browse files
authored
Remove yarn integrity check (#2518)
* 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
1 parent 9e0c3c2 commit 09caeed

File tree

5 files changed

+9
-74
lines changed

5 files changed

+9
-74
lines changed

README.md

+8-21
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ in which case you may not even need the asset pipeline. This is mostly relevant
2828
- [Webpack Configuration](#webpack-configuration)
2929
- [Custom Rails environments](#custom-rails-environments)
3030
- [Upgrading](#upgrading)
31-
- [Yarn Integrity](#yarn-integrity)
3231
- [Integrations](#integrations)
3332
- [React](./docs/integrations.md#react)
3433
- [Angular with TypeScript](./docs/integrations.md#angular-with-typescript)
@@ -107,6 +106,12 @@ Optional: To fix ["unmet peer dependency" warnings](https://github.com/rails/web
107106
yarn upgrade
108107
```
109108

109+
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:
110+
111+
```bash
112+
yarn install
113+
```
114+
110115
### Usage
111116

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

303-
### Yarn Integrity
304-
305-
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`.
306-
307-
To turn off this option, you will need to change the default setting in `config/webpacker.yml`:
308-
309-
```yaml
310-
# config/webpacker.yml
311-
development:
312-
...
313-
# Verifies that correct packages and versions are installed by inspecting package.json, yarn.lock, and node_modules
314-
check_yarn_integrity: false
315-
```
316-
317-
You may also turn on this feature by adding the config option for any Rails environment in `config/webpacker.yml`:
318-
319-
```yaml
320-
check_yarn_integrity: true
321-
```
322-
323308
## Integrations
324309

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

414399
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).
415400

401+
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.
402+
416403
## Docs
417404

418405
- [Development](https://github.com/rails/webpacker#development)

lib/install/config/webpacker.yml

-4
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ default: &default
66
public_root_path: public
77
public_output_path: packs
88
cache_path: tmp/cache/webpacker
9-
check_yarn_integrity: false
109
webpack_compile_output: true
1110

1211
# Additional paths webpack should lookup modules
@@ -52,9 +51,6 @@ development:
5251
<<: *default
5352
compile: true
5453

55-
# Verifies that correct packages and versions are installed by inspecting package.json, yarn.lock, and node_modules
56-
check_yarn_integrity: true
57-
5854
# Reference: https://webpack.js.org/configuration/dev-server/
5955
dev_server:
6056
https: false

lib/webpacker/configuration.rb

+1-5
Original file line numberDiff line numberDiff line change
@@ -64,11 +64,7 @@ def extensions
6464
end
6565

6666
def check_yarn_integrity=(value)
67-
data[:check_yarn_integrity] = value
68-
end
69-
70-
def check_yarn_integrity?
71-
fetch(:check_yarn_integrity)
67+
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."
7268
end
7369

7470
def webpack_compile_output?

lib/webpacker/railtie.rb

-43
Original file line numberDiff line numberDiff line change
@@ -7,49 +7,6 @@ class Webpacker::Engine < ::Rails::Engine
77
# Allows Webpacker config values to be set via Rails env config files
88
config.webpacker = ActiveSupport::OrderedOptions.new
99

10-
initializer "webpacker.set_configs" do |app|
11-
if app.config.webpacker.key?(:check_yarn_integrity)
12-
Webpacker.config.check_yarn_integrity = app.config.webpacker.check_yarn_integrity
13-
end
14-
end
15-
16-
# ================================
17-
# Check Yarn Integrity Initializer
18-
# ================================
19-
#
20-
# development (on by default):
21-
#
22-
# to turn off:
23-
# - edit config/environments/development.rb
24-
# - add `config.webpacker.check_yarn_integrity = false`
25-
#
26-
# production (off by default):
27-
#
28-
# to turn on:
29-
# - edit config/environments/production.rb
30-
# - add `config.webpacker.check_yarn_integrity = true`
31-
initializer "webpacker.yarn_check" do |app|
32-
if File.exist?("yarn.lock") && Webpacker.config.config_path.exist? && Webpacker.config.check_yarn_integrity?
33-
output = `yarn check --integrity && yarn check --verify-tree 2>&1`
34-
35-
unless $?.success?
36-
$stderr.puts "\n\n"
37-
$stderr.puts "========================================"
38-
$stderr.puts " Your Yarn packages are out of date!"
39-
$stderr.puts " Please run `yarn install --check-files` to update."
40-
$stderr.puts "========================================"
41-
$stderr.puts "\n\n"
42-
$stderr.puts "To disable this check, please change `check_yarn_integrity`"
43-
$stderr.puts "to `false` in your webpacker config file (config/webpacker.yml)."
44-
$stderr.puts "\n\n"
45-
$stderr.puts output
46-
$stderr.puts "\n\n"
47-
48-
exit(1)
49-
end
50-
end
51-
end
52-
5310
initializer "webpacker.proxy" do |app|
5411
insert_middleware = Webpacker.config.dev_server.present? rescue nil
5512
if insert_middleware

test/test_app/config/application.rb

-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ module TestApp
66
class Application < ::Rails::Application
77
config.secret_key_base = "abcdef"
88
config.eager_load = true
9-
config.webpacker.check_yarn_integrity = false
109
config.active_support.test_order = :sorted
1110
end
1211
end

0 commit comments

Comments
 (0)