Skip to content

Commit 2f0f955

Browse files
authoredJan 21, 2021
Support to Yarn v2/berry for webpacker 5.x (#2889)
1 parent 9ec5daa commit 2f0f955

File tree

5 files changed

+21
-4
lines changed

5 files changed

+21
-4
lines changed
 

‎CHANGELOG.md

+4
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22

33
**Please note that Webpacker 4.1.0 has an installer bug. Please use 4.2.0 or above**
44

5+
## [[5.3.0]](https://github.com/rails/webpacker/compare/v5.3.0...5.2.1) - 2021-TBD
6+
7+
- Adds experimental Yarn 2 support. Note you must manually set `nodeLinker: node-modules` in your `.yarnrc.yml`.
8+
59
## [[5.2.1]](https://github.com/rails/webpacker/compare/v5.2.0...5.2.1) - 2020-08-17
610

711
- Revert [#1311](https://github.com/rails/webpacker/pull/1311).

‎lib/install/template.rb

+8
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,14 @@
4242
run "yarn add @rails/webpacker@next"
4343
end
4444

45+
package_json = File.read("#{__dir__}/../../package.json")
46+
webpack_version = package_json.match(/"webpack": "(.*)"/)[1]
47+
webpack_cli_version = package_json.match(/"webpack-cli": "(.*)"/)[1]
48+
49+
# needed for experimental Yarn 2 support and should not harm Yarn 1
50+
say "Installing webpack and webpack-cli as direct dependencies"
51+
run "yarn add webpack@#{webpack_version} webpack-cli@#{webpack_cli_version}"
52+
4553
say "Installing dev server for live reloading"
4654
run "yarn add --dev webpack-dev-server"
4755

‎lib/tasks/webpacker/check_yarn.rake

+1-2
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,12 @@ namespace :webpacker do
99
pkg_path = Pathname.new("#{__dir__}/../../../package.json").realpath
1010
yarn_range = JSON.parse(pkg_path.read)["engines"]["yarn"]
1111
is_valid = SemanticRange.satisfies?(yarn_version, yarn_range) rescue false
12-
is_unsupported = SemanticRange.satisfies?(yarn_version, ">=2.0.0") rescue false
12+
is_unsupported = SemanticRange.satisfies?(yarn_version, ">=3.0.0") rescue false
1313

1414
unless is_valid
1515
$stderr.puts "Webpacker requires Yarn \"#{yarn_range}\" and you are using #{yarn_version}"
1616
if is_unsupported
1717
$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/"
18-
$stderr.puts "For information on using Webpacker with Yarn 2.0, see https://github.com/rails/webpacker/issues/2112"
1918
else
2019
$stderr.puts "Please upgrade Yarn https://yarnpkg.com/lang/en/docs/install/"
2120
end

‎lib/tasks/webpacker/yarn_install.rake

+7-1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,12 @@ namespace :webpacker do
55
node_env = ENV.fetch("NODE_ENV") do
66
valid_node_envs.include?(Rails.env) ? Rails.env : "production"
77
end
8-
system({ "NODE_ENV" => node_env }, "yarn install --no-progress --frozen-lockfile")
8+
yarn_flags =
9+
if `yarn --version`.start_with?("1")
10+
"--no-progress --frozen-lockfile"
11+
else
12+
"--immutable"
13+
end
14+
system({ "NODE_ENV" => node_env }, "yarn install #{yarn_flags}")
915
end
1016
end

‎package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
],
1010
"engines": {
1111
"node": ">=10.17.0",
12-
"yarn": ">=1 <2"
12+
"yarn": ">=1 <3"
1313
},
1414
"dependencies": {
1515
"@babel/core": "^7.11.1",

0 commit comments

Comments
 (0)
Please sign in to comment.