From f3a107d2fa3451993932efa39e788879d96edcb3 Mon Sep 17 00:00:00 2001 From: Josh Bielick Date: Mon, 10 Feb 2020 14:01:00 -0500 Subject: [PATCH 1/8] Fix package.json engine semver ranges (node.js >=8.9 <13, yarn >=1 <2) (#2454) * Allow node.js 8.9 engine compatibility 8.16 is somewhat arbitrary as far as I can tell, so this allows earlier 8.x releases of node.js as the engine so that 8.9, 8.10, 8.12, etc from Ubuntu 18.04 LTS can install this package. https://github.com/rails/webpacker/pull/2228 * restrict to compatible yarn engine versions Co-Authored-By: Jake Niemiec * restrict to compatible node engine versions As 13 has been released, an upper limit is prudent as well. Co-Authored-By: Jake Niemiec Co-authored-by: Jake Niemiec --- package.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index c5287d335..1a9e06464 100644 --- a/package.json +++ b/package.json @@ -8,8 +8,8 @@ "lib/install/config/webpacker.yml" ], "engines": { - "node": ">=8.16.0", - "yarn": ">=1.0.0" + "node": ">=8.9 <13", + "yarn": ">=1 <2" }, "dependencies": { "@babel/core": "^7.7.2", From 07a62a9dfed300e0849c98089336db75724fd604 Mon Sep 17 00:00:00 2001 From: Jake Niemiec Date: Mon, 10 Feb 2020 14:49:55 -0600 Subject: [PATCH 2/8] Remove engines limitation for node 13+ Yarn enforces strict engine testing https://github.com/yarnpkg/rfcs/pull/69#issuecomment-308567694 so this manifests as an error rather than a warning. --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 1a9e06464..6bbb5b867 100644 --- a/package.json +++ b/package.json @@ -8,7 +8,7 @@ "lib/install/config/webpacker.yml" ], "engines": { - "node": ">=8.9 <13", + "node": ">=8.9", "yarn": ">=1 <2" }, "dependencies": { From 2e6e136aa0861d5be2434908c6dd09e3a71a479c Mon Sep 17 00:00:00 2001 From: Josh Bielick Date: Tue, 11 Feb 2020 14:33:26 -0500 Subject: [PATCH 3/8] add test for check_node, check_yarn tasks a valid semver engine version could be an illformed gem requirement, which raising an exception during the parsing of this value from the package.json in either of these tasks. --- test/rake_tasks_test.rb | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/test/rake_tasks_test.rb b/test/rake_tasks_test.rb index eb6e547bd..1693cc372 100644 --- a/test/rake_tasks_test.rb +++ b/test/rake_tasks_test.rb @@ -52,6 +52,16 @@ def test_rake_webpacker_yarn_install_in_production_environment "Expected only production dependencies to be installed" end + def test_check_node_version + output = Dir.chdir(test_app_path) { `rake webpacker:check_node 2>&1` } + assert_empty output + end + + def test_check_yarn_version + output = Dir.chdir(test_app_path) { `rake webpacker:check_yarn 2>&1` } + assert_empty output + end + private def test_app_path File.expand_path("test_app", __dir__) From bbf62d0f4bd52cd94531239543a9103bac1767b5 Mon Sep 17 00:00:00 2001 From: jake Date: Tue, 11 Feb 2020 16:21:00 -0600 Subject: [PATCH 4/8] Add better conditional messaging to check_yarn task --- Gemfile | 1 + Gemfile.lock | 3 +++ lib/tasks/webpacker/check_yarn.rake | 25 ++++++++++++++++--------- webpacker.gemspec | 7 ++++--- 4 files changed, 24 insertions(+), 12 deletions(-) diff --git a/Gemfile b/Gemfile index f45829379..8760baf61 100644 --- a/Gemfile +++ b/Gemfile @@ -5,6 +5,7 @@ gemspec gem "rails" gem "rake", ">= 11.1" gem "rack-proxy", require: false +gem "semantic_range", require: false group :test do gem "minitest", "~> 5.0" diff --git a/Gemfile.lock b/Gemfile.lock index 251abf40e..500dae0f2 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -5,6 +5,7 @@ PATH activesupport (>= 4.2) rack-proxy (>= 0.6.1) railties (>= 4.2) + semantic_range (>= 2.3.0) GEM remote: https://rubygems.org/ @@ -136,6 +137,7 @@ GEM rubocop-performance (1.3.0) rubocop (>= 0.68.0) ruby-progressbar (1.10.1) + semantic_range (2.3.0) sprockets (4.0.0) concurrent-ruby (~> 1.0) rack (> 1, < 3) @@ -165,6 +167,7 @@ DEPENDENCIES rake (>= 11.1) rubocop (< 0.69) rubocop-performance + semantic_range webpacker! BUNDLED WITH diff --git a/lib/tasks/webpacker/check_yarn.rake b/lib/tasks/webpacker/check_yarn.rake index 3445da9e1..d7c863c1b 100644 --- a/lib/tasks/webpacker/check_yarn.rake +++ b/lib/tasks/webpacker/check_yarn.rake @@ -1,3 +1,4 @@ +require "semantic_range" namespace :webpacker do desc "Verifies if Yarn is installed" task :check_yarn do @@ -6,19 +7,25 @@ namespace :webpacker do raise Errno::ENOENT if yarn_version.blank? pkg_path = Pathname.new("#{__dir__}/../../../package.json").realpath - yarn_requirement = JSON.parse(pkg_path.read)["engines"]["yarn"] + yarn_range = JSON.parse(pkg_path.read)["engines"]["yarn"] + is_valid = SemanticRange.satisfies?(yarn_version, yarn_range) rescue false + is_unsupported = SemanticRange.satisfies?(yarn_version, ">=2.0.0") rescue false - requirement = Gem::Requirement.new(yarn_requirement) - version = Gem::Version.new(yarn_version) - - unless requirement.satisfied_by?(version) - $stderr.puts "Webpacker requires Yarn #{requirement} and you are using #{version}" - $stderr.puts "Please upgrade Yarn https://yarnpkg.com/lang/en/docs/install/" - $stderr.puts "Exiting!" && exit! + unless is_valid + $stderr.puts "Webpacker requires Yarn \"#{yarn_range}\" and you are using #{yarn_version}" + if is_unsupported + $stderr.puts "This version of Webpacker does not support Yarn #{yarn_version}. Please downgrade to a supported version of Yarn https://yarnpkg.com/lang/en/docs/install/" + $stderr.puts "For information on using Webpacker with Yarn 2.0, see https://github.com/rails/webpacker/issues/2112" + else + $stderr.puts "Please upgrade Yarn https://yarnpkg.com/lang/en/docs/install/" + end + $stderr.puts "Exiting!" + exit! end rescue Errno::ENOENT $stderr.puts "Yarn not installed. Please download and install Yarn from https://yarnpkg.com/lang/en/docs/install/" - $stderr.puts "Exiting!" && exit! + $stderr.puts "Exiting!" + exit! end end end diff --git a/webpacker.gemspec b/webpacker.gemspec index c056bac1e..6ae568f9d 100644 --- a/webpacker.gemspec +++ b/webpacker.gemspec @@ -17,9 +17,10 @@ Gem::Specification.new do |s| s.required_ruby_version = ">= 2.3.0" - s.add_dependency "activesupport", ">= 4.2" - s.add_dependency "railties", ">= 4.2" - s.add_dependency "rack-proxy", ">= 0.6.1" + s.add_dependency "activesupport", ">= 4.2" + s.add_dependency "railties", ">= 4.2" + s.add_dependency "rack-proxy", ">= 0.6.1" + s.add_dependency "semantic_range", ">= 2.3.0" s.add_development_dependency "bundler", ">= 1.3.0" s.add_development_dependency "rubocop", "< 0.69" From 5e6c7309571b4b8c921db0733e1008dec2079899 Mon Sep 17 00:00:00 2001 From: jake Date: Tue, 11 Feb 2020 17:15:14 -0600 Subject: [PATCH 5/8] Fix tests for Travis CI --- test/rake_tasks_test.rb | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/test/rake_tasks_test.rb b/test/rake_tasks_test.rb index 1693cc372..bdeec2ad8 100644 --- a/test/rake_tasks_test.rb +++ b/test/rake_tasks_test.rb @@ -28,6 +28,17 @@ def test_rake_task_webpacker_check_binstubs refute_includes output, "webpack binstubs not found." end + def test_check_node_version + output = Dir.chdir(test_app_path) { `rake webpacker:check_node 2>&1` } + refute_includes output, "Webpacker requires Node.js" + end + + def test_check_yarn_version + output = Dir.chdir(test_app_path) { `rake webpacker:check_yarn 2>&1` } + refute_includes output, "Yarn not installed" + refute_includes output, "Webpacker requires Yarn" + end + def test_rake_webpacker_yarn_install_in_non_production_environments assert_includes test_app_dev_dependencies, "right-pad" @@ -52,16 +63,6 @@ def test_rake_webpacker_yarn_install_in_production_environment "Expected only production dependencies to be installed" end - def test_check_node_version - output = Dir.chdir(test_app_path) { `rake webpacker:check_node 2>&1` } - assert_empty output - end - - def test_check_yarn_version - output = Dir.chdir(test_app_path) { `rake webpacker:check_yarn 2>&1` } - assert_empty output - end - private def test_app_path File.expand_path("test_app", __dir__) From 7d40a625a62edc1a1417a9698bf96ee9f04e11ce Mon Sep 17 00:00:00 2001 From: jake Date: Tue, 11 Feb 2020 18:41:34 -0600 Subject: [PATCH 6/8] Add better conditional messaging to check_node & handle extended Node.JS versions closes https://github.com/rails/webpacker/issues/1598 --- lib/tasks/webpacker/check_node.rake | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/lib/tasks/webpacker/check_node.rake b/lib/tasks/webpacker/check_node.rake index 63cdd03d4..b6d03c290 100644 --- a/lib/tasks/webpacker/check_node.rake +++ b/lib/tasks/webpacker/check_node.rake @@ -1,3 +1,4 @@ +require "semantic_range" namespace :webpacker do desc "Verifies if Node.js is installed" task :check_node do @@ -6,19 +7,25 @@ namespace :webpacker do raise Errno::ENOENT if node_version.blank? pkg_path = Pathname.new("#{__dir__}/../../../package.json").realpath - node_requirement = JSON.parse(pkg_path.read)["engines"]["node"] + node_range = JSON.parse(pkg_path.read)["engines"]["node"] + is_valid = SemanticRange.satisfies?(node_version, node_range) rescue false + semver_major = node_version[/\d+/] rescue nil + is_unstable = semver_major.to_i.odd? rescue false - requirement = Gem::Requirement.new(node_requirement) - version = Gem::Version.new(node_version.strip.tr("v", "")) + if is_unstable + $stderr.puts "Warning: you are using an unstable release of Node.js (#{node_version}). If you encounter issues with Node.js, consider switching to an Active LTS release. More info: https://docs.npmjs.com/try-the-latest-stable-version-of-node" + end - unless requirement.satisfied_by?(version) - $stderr.puts "Webpacker requires Node.js #{requirement} and you are using #{version}" + unless is_valid + $stderr.puts "Webpacker requires Node.js \"#{node_range}\" and you are using #{node_version}" $stderr.puts "Please upgrade Node.js https://nodejs.org/en/download/" - $stderr.puts "Exiting!" && exit! + $stderr.puts "Exiting!" + exit! end rescue Errno::ENOENT $stderr.puts "Node.js not installed. Please download and install Node.js https://nodejs.org/en/download/" - $stderr.puts "Exiting!" && exit! + $stderr.puts "Exiting!" + exit! end end end From cd8c052de68318a19e343a8391294c12a735582a Mon Sep 17 00:00:00 2001 From: Alex Taylor Date: Mon, 17 Feb 2020 02:44:40 -0800 Subject: [PATCH 7/8] Allow Webpacker rake tasks to be conditionally skipped (#2455) --- lib/tasks/webpacker/clean.rake | 16 ++++++++++------ lib/tasks/webpacker/clobber.rake | 12 ++++++++---- 2 files changed, 18 insertions(+), 10 deletions(-) diff --git a/lib/tasks/webpacker/clean.rake b/lib/tasks/webpacker/clean.rake index 9303267aa..6d9d54311 100644 --- a/lib/tasks/webpacker/clean.rake +++ b/lib/tasks/webpacker/clean.rake @@ -11,11 +11,15 @@ namespace :webpacker do end end -# Run clean if the assets:clean is run -if Rake::Task.task_defined?("assets:clean") - Rake::Task["assets:clean"].enhance do - Rake::Task["webpacker:clean"].invoke +skip_webpacker_clean = %w(no false n f).include?(ENV["WEBPACKER_PRECOMPILE"]) + +unless skip_webpacker_clean + # Run clean if the assets:clean is run + if Rake::Task.task_defined?("assets:clean") + Rake::Task["assets:clean"].enhance do + Rake::Task["webpacker:clean"].invoke + end + else + Rake::Task.define_task("assets:clean" => "webpacker:clean") end -else - Rake::Task.define_task("assets:clean" => "webpacker:clean") end diff --git a/lib/tasks/webpacker/clobber.rake b/lib/tasks/webpacker/clobber.rake index 748ccd178..bf28731af 100644 --- a/lib/tasks/webpacker/clobber.rake +++ b/lib/tasks/webpacker/clobber.rake @@ -8,9 +8,13 @@ namespace :webpacker do end end -# Run clobber if the assets:clobber is run -if Rake::Task.task_defined?("assets:clobber") - Rake::Task["assets:clobber"].enhance do - Rake::Task["webpacker:clobber"].invoke +skip_webpacker_clobber = %w(no false n f).include?(ENV["WEBPACKER_PRECOMPILE"]) + +unless skip_webpacker_clobber + # Run clobber if the assets:clobber is run + if Rake::Task.task_defined?("assets:clobber") + Rake::Task["assets:clobber"].enhance do + Rake::Task["webpacker:clobber"].invoke + end end end From ac0c726d57d3b16df833b06bf041c7560c0a7a05 Mon Sep 17 00:00:00 2001 From: Pavel Pustovalov Date: Mon, 17 Feb 2020 12:46:54 +0200 Subject: [PATCH 8/8] Update terser-webpack-plugin (reduce memory usage) (#2444) --- package.json | 2 +- yarn.lock | 48 ++++++++++++++++++++++++++++++++++++++++++------ 2 files changed, 43 insertions(+), 7 deletions(-) diff --git a/package.json b/package.json index 6bbb5b867..6a97574da 100644 --- a/package.json +++ b/package.json @@ -45,7 +45,7 @@ "regenerator-runtime": "^0.13.3", "sass-loader": "7.3.1", "style-loader": "^1.0.0", - "terser-webpack-plugin": "^2.3.2", + "terser-webpack-plugin": "^2.3.4", "webpack": "^4.41.3", "webpack-assets-manifest": "^3.1.1", "webpack-cli": "^3.3.10", diff --git a/yarn.lock b/yarn.lock index 93e656651..896d62e24 100644 --- a/yarn.lock +++ b/yarn.lock @@ -3433,6 +3433,11 @@ has-flag@^3.0.0: resolved "https://registry.yarnpkg.com/has-flag/-/has-flag-3.0.0.tgz#b5d454dc2199ae225699f3467e5a07f3b955bafd" integrity sha1-tdRU3CGZriJWmfNGfloH87lVuv0= +has-flag@^4.0.0: + version "4.0.0" + resolved "https://registry.yarnpkg.com/has-flag/-/has-flag-4.0.0.tgz#944771fd9c81c81265c4d6941860da06bb59479b" + integrity sha512-EykJT/Q1KjTWctppgIAgfSO0tKVuZUjhgMr17kqTumMl6Afv3EISleU7qZUzoXDFTAHTDC4NOoG/ZxU3EvlMPQ== + has-symbols@^1.0.0: version "1.0.0" resolved "https://registry.yarnpkg.com/has-symbols/-/has-symbols-1.0.0.tgz#ba1a8f1af2a0fc39650f5c850367704122063b44" @@ -4399,6 +4404,14 @@ jest-worker@^24.6.0, jest-worker@^24.9.0: merge-stream "^2.0.0" supports-color "^6.1.0" +jest-worker@^25.1.0: + version "25.1.0" + resolved "https://registry.yarnpkg.com/jest-worker/-/jest-worker-25.1.0.tgz#75d038bad6fdf58eba0d2ec1835856c497e3907a" + integrity sha512-ZHhHtlxOWSxCoNOKHGbiLzXnl42ga9CxDr27H36Qn+15pQZd3R/F24jrmjDelw9j/iHUIWMWs08/u2QN50HHOg== + dependencies: + merge-stream "^2.0.0" + supports-color "^7.0.0" + jest@^24.9.0: version "24.9.0" resolved "https://registry.yarnpkg.com/jest/-/jest-24.9.0.tgz#987d290c05a08b52c56188c1002e368edb007171" @@ -5526,6 +5539,13 @@ p-limit@^2.0.0, p-limit@^2.2.0: dependencies: p-try "^2.0.0" +p-limit@^2.2.2: + version "2.2.2" + resolved "https://registry.yarnpkg.com/p-limit/-/p-limit-2.2.2.tgz#61279b67721f5287aa1c13a9a7fbbc48c9291b1e" + integrity sha512-WGR+xHecKTr7EbUEhyLSh5Dube9JtdiG78ufaeLxTgpudf/20KqyMioIUZJAezlTIi6evxuoUs9YXc11cU+yzQ== + dependencies: + p-try "^2.0.0" + p-locate@^2.0.0: version "2.0.0" resolved "https://registry.yarnpkg.com/p-locate/-/p-locate-2.0.0.tgz#20a0103b222a70c8fd39cc2e580680f3dde5ec43" @@ -7058,6 +7078,14 @@ schema-utils@^2.6.1: ajv "^6.10.2" ajv-keywords "^3.4.1" +schema-utils@^2.6.4: + version "2.6.4" + resolved "https://registry.yarnpkg.com/schema-utils/-/schema-utils-2.6.4.tgz#a27efbf6e4e78689d91872ee3ccfa57d7bdd0f53" + integrity sha512-VNjcaUxVnEeun6B2fiiUDjXXBtD4ZSH7pdbfIu1pOFwgptDPLMo/z9jr4sUfsjFVPqDCEin/F7IYlq7/E6yDbQ== + dependencies: + ajv "^6.10.2" + ajv-keywords "^3.4.1" + scss-tokenizer@^0.2.3: version "0.2.3" resolved "https://registry.yarnpkg.com/scss-tokenizer/-/scss-tokenizer-0.2.3.tgz#8eb06db9a9723333824d3f5530641149847ce5d1" @@ -7551,6 +7579,13 @@ supports-color@^5.3.0: dependencies: has-flag "^3.0.0" +supports-color@^7.0.0: + version "7.1.0" + resolved "https://registry.yarnpkg.com/supports-color/-/supports-color-7.1.0.tgz#68e32591df73e25ad1c4b49108a2ec507962bfd1" + integrity sha512-oRSIpR8pxT1Wr2FquTNnGet79b3BWljqOuoW/h4oBhxJ/HUbX5nX6JSruTkvXDCFMwDPvsaTTbvMLKZWSy0R5g== + dependencies: + has-flag "^4.0.0" + svgo@^1.0.0: version "1.3.2" resolved "https://registry.yarnpkg.com/svgo/-/svgo-1.3.2.tgz#b6dc511c063346c9e415b81e43401145b96d4167" @@ -7627,15 +7662,16 @@ terser-webpack-plugin@^1.4.3: webpack-sources "^1.4.0" worker-farm "^1.7.0" -terser-webpack-plugin@^2.3.2: - version "2.3.2" - resolved "https://registry.yarnpkg.com/terser-webpack-plugin/-/terser-webpack-plugin-2.3.2.tgz#6d3d1b0590c8f729bfbaeb7fb2528b8b62db4c74" - integrity sha512-SmvB/6gtEPv+CJ88MH5zDOsZdKXPS/Uzv2//e90+wM1IHFUhsguPKEILgzqrM1nQ4acRXN/SV4Obr55SXC+0oA== +terser-webpack-plugin@^2.3.4: + version "2.3.4" + resolved "https://registry.yarnpkg.com/terser-webpack-plugin/-/terser-webpack-plugin-2.3.4.tgz#ac045703bd8da0936ce910d8fb6350d0e1dee5fe" + integrity sha512-Nv96Nws2R2nrFOpbzF6IxRDpIkkIfmhvOws+IqMvYdFLO7o6wAILWFKONFgaYy8+T4LVz77DQW0f7wOeDEAjrg== dependencies: cacache "^13.0.1" find-cache-dir "^3.2.0" - jest-worker "^24.9.0" - schema-utils "^2.6.1" + jest-worker "^25.1.0" + p-limit "^2.2.2" + schema-utils "^2.6.4" serialize-javascript "^2.1.2" source-map "^0.6.1" terser "^4.4.3"