webpacker 5.2.1 → 5.4.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -9,7 +9,7 @@ if File.exist?(package_json)
9
9
  package = JSON.parse(File.read(package_json))
10
10
  package["dependencies"] ||= {}
11
11
 
12
- if package["dependencies"].keys.include?("react")
12
+ if package["dependencies"].key?("react")
13
13
  additional_packages = "@types/react @types/react-dom"
14
14
  example_source = "react"
15
15
  end
@@ -9,13 +9,12 @@ namespace :webpacker do
9
9
  pkg_path = Pathname.new("#{__dir__}/../../../package.json").realpath
10
10
  yarn_range = JSON.parse(pkg_path.read)["engines"]["yarn"]
11
11
  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, ">=4.0.0") rescue false
13
13
 
14
14
  unless is_valid
15
15
  $stderr.puts "Webpacker requires Yarn \"#{yarn_range}\" and you are using #{yarn_version}"
16
16
  if is_unsupported
17
17
  $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"
19
18
  else
20
19
  $stderr.puts "Please upgrade Yarn https://yarnpkg.com/lang/en/docs/install/"
21
20
  end
@@ -5,6 +5,12 @@ namespace :webpacker do
5
5
  node_env = ENV.fetch("NODE_ENV") do
6
6
  valid_node_envs.include?(Rails.env) ? Rails.env : "production"
7
7
  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}")
9
15
  end
10
16
  end
@@ -23,7 +23,7 @@ class Webpacker::Commands
23
23
  .each_with_index
24
24
  .drop_while do |(mtime, _), index|
25
25
  max_age = [0, Time.now - Time.at(mtime)].max
26
- max_age < age && index < count
26
+ max_age < age || index < count
27
27
  end
28
28
  .each do |(_, files), index|
29
29
  files.each do |file|
@@ -93,8 +93,12 @@ class Webpacker::Configuration
93
93
  end
94
94
 
95
95
  def load
96
- YAML.load(config_path.read)[env].deep_symbolize_keys
97
-
96
+ config = begin
97
+ YAML.load_file(config_path.to_s, aliases: true)
98
+ rescue ArgumentError
99
+ YAML.load_file(config_path.to_s)
100
+ end
101
+ config[env].deep_symbolize_keys
98
102
  rescue Errno::ENOENT => e
99
103
  raise "Webpacker configuration file not found #{config_path}. " \
100
104
  "Please run rails webpacker:install " \
@@ -107,8 +111,15 @@ class Webpacker::Configuration
107
111
  end
108
112
 
109
113
  def defaults
110
- @defaults ||= \
111
- HashWithIndifferentAccess.new(YAML.load_file(File.expand_path("../../install/config/webpacker.yml", __FILE__))[env])
114
+ @defaults ||= begin
115
+ path = File.expand_path("../../install/config/webpacker.yml", __FILE__)
116
+ config = begin
117
+ YAML.load_file(path, aliases: true)
118
+ rescue ArgumentError
119
+ YAML.load_file(path)
120
+ end
121
+ HashWithIndifferentAccess.new(config[env])
122
+ end
112
123
  end
113
124
 
114
125
  def globbed_path_with_extensions(path)
data/lib/webpacker/env.rb CHANGED
@@ -27,7 +27,11 @@ class Webpacker::Env
27
27
 
28
28
  def available_environments
29
29
  if config_path.exist?
30
- YAML.load(config_path.read).keys
30
+ begin
31
+ YAML.load_file(config_path.to_s, aliases: true)
32
+ rescue ArgumentError
33
+ YAML.load_file(config_path.to_s)
34
+ end
31
35
  else
32
36
  [].freeze
33
37
  end
@@ -1,4 +1,4 @@
1
1
  module Webpacker
2
2
  # Change the version in package.json too, please!
3
- VERSION = "5.2.1".freeze
3
+ VERSION = "5.4.4".freeze
4
4
  end
@@ -1,4 +1,4 @@
1
- const { join } = require('path')
1
+ const { join, normalize } = require('path')
2
2
  const { source_path: sourcePath, static_assets_extensions: fileExtensions } = require('../config')
3
3
 
4
4
  module.exports = {
@@ -8,7 +8,7 @@ module.exports = {
8
8
  loader: 'file-loader',
9
9
  options: {
10
10
  name(file) {
11
- if (file.includes(sourcePath)) {
11
+ if (file.includes(normalize(sourcePath))) {
12
12
  return 'media/[path][name]-[hash].[ext]'
13
13
  }
14
14
  return 'media/[folder]/[name]-[hash:8].[ext]'
@@ -1,3 +1,5 @@
1
+ /* eslint global-require: 0 */
2
+
1
3
  const getStyleRule = require('../utils/get_style_rule')
2
4
  const { additional_paths: includePaths } = require('../config')
3
5
 
@@ -6,6 +8,7 @@ module.exports = getStyleRule(/\.(scss|sass)(\.erb)?$/i, false, [
6
8
  loader: 'sass-loader',
7
9
  options: {
8
10
  sourceMap: true,
11
+ implementation: require('sass'),
9
12
  sassOptions: {
10
13
  includePaths
11
14
  }
data/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rails/webpacker",
3
- "version": "5.2.1",
3
+ "version": "5.4.3",
4
4
  "description": "Use webpack to manage app-like JavaScript modules in Rails",
5
5
  "main": "package/index.js",
6
6
  "files": [
@@ -9,55 +9,55 @@
9
9
  ],
10
10
  "engines": {
11
11
  "node": ">=10.17.0",
12
- "yarn": ">=1 <2"
12
+ "yarn": ">=1 <4"
13
13
  },
14
14
  "dependencies": {
15
- "@babel/core": "^7.11.1",
16
- "@babel/plugin-proposal-class-properties": "^7.10.4",
17
- "@babel/plugin-proposal-object-rest-spread": "^7.10.1",
15
+ "@babel/core": "^7.15.0",
16
+ "@babel/plugin-proposal-class-properties": "^7.14.5",
17
+ "@babel/plugin-proposal-object-rest-spread": "^7.14.7",
18
18
  "@babel/plugin-syntax-dynamic-import": "^7.8.3",
19
- "@babel/plugin-transform-destructuring": "^7.10.1",
20
- "@babel/plugin-transform-regenerator": "^7.10.1",
21
- "@babel/plugin-transform-runtime": "^7.11.0",
22
- "@babel/preset-env": "^7.11.0",
23
- "@babel/runtime": "^7.11.2",
24
- "babel-loader": "^8.1.0",
19
+ "@babel/plugin-transform-destructuring": "^7.14.7",
20
+ "@babel/plugin-transform-regenerator": "^7.14.5",
21
+ "@babel/plugin-transform-runtime": "^7.15.0",
22
+ "@babel/preset-env": "^7.15.0",
23
+ "@babel/runtime": "^7.15.3",
24
+ "babel-loader": "^8.2.2",
25
25
  "babel-plugin-dynamic-import-node": "^2.3.3",
26
26
  "babel-plugin-macros": "^2.8.0",
27
- "case-sensitive-paths-webpack-plugin": "^2.3.0",
28
- "compression-webpack-plugin": "^4.0.0",
29
- "core-js": "^3.6.5",
30
- "css-loader": "^3.5.3",
31
- "file-loader": "^6.0.0",
32
- "flatted": "^3.0.4",
33
- "glob": "^7.1.6",
34
- "js-yaml": "^3.14.0",
27
+ "case-sensitive-paths-webpack-plugin": "^2.4.0",
28
+ "compression-webpack-plugin": "^4.0.1",
29
+ "core-js": "^3.16.2",
30
+ "css-loader": "^3.6.0",
31
+ "file-loader": "^6.2.0",
32
+ "flatted": "^3.2.2",
33
+ "glob": "^7.1.7",
34
+ "js-yaml": "^3.14.1",
35
35
  "mini-css-extract-plugin": "^0.9.0",
36
- "node-sass": "^4.14.1",
37
- "optimize-css-assets-webpack-plugin": "^5.0.3",
36
+ "optimize-css-assets-webpack-plugin": "^5.0.8",
38
37
  "path-complete-extname": "^1.0.0",
39
- "pnp-webpack-plugin": "^1.6.4",
38
+ "pnp-webpack-plugin": "^1.7.0",
40
39
  "postcss-flexbugs-fixes": "^4.2.1",
41
40
  "postcss-import": "^12.0.1",
42
41
  "postcss-loader": "^3.0.0",
43
42
  "postcss-preset-env": "^6.7.0",
44
43
  "postcss-safe-parser": "^4.0.2",
45
- "regenerator-runtime": "^0.13.7",
46
- "sass-loader": "^8.0.2",
47
- "style-loader": "^1.2.1",
48
- "terser-webpack-plugin": "^4.0.0",
49
- "webpack": "^4.44.1",
44
+ "regenerator-runtime": "^0.13.9",
45
+ "sass": "^1.38.0",
46
+ "sass-loader": "10.1.1",
47
+ "style-loader": "^1.3.0",
48
+ "terser-webpack-plugin": "^4.2.3",
49
+ "webpack": "^4.46.0",
50
50
  "webpack-assets-manifest": "^3.1.1",
51
51
  "webpack-cli": "^3.3.12",
52
52
  "webpack-sources": "^1.4.3"
53
53
  },
54
54
  "devDependencies": {
55
- "eslint": "^7.6.0",
56
- "eslint-config-airbnb": "^18.2.0",
57
- "eslint-plugin-import": "^2.22.0",
58
- "eslint-plugin-jsx-a11y": "^6.3.1",
59
- "eslint-plugin-react": "^7.20.5",
60
- "jest": "^26.2.2"
55
+ "eslint": "^7.32.0",
56
+ "eslint-config-airbnb": "^18.2.1",
57
+ "eslint-plugin-import": "^2.24.0",
58
+ "eslint-plugin-jsx-a11y": "^6.4.1",
59
+ "eslint-plugin-react": "^7.24.0",
60
+ "jest": "^27.0.6"
61
61
  },
62
62
  "jest": {
63
63
  "testRegex": "(/__tests__/.*|(\\.|/))\\.jsx?$",
data/test/helper_test.rb CHANGED
@@ -117,29 +117,41 @@ class HelperTest < ActionView::TestCase
117
117
  end
118
118
 
119
119
  def test_stylesheet_pack_tag_split_chunks
120
- assert_equal \
121
- %(<link rel="stylesheet" media="screen" href="/packs/1-c20632e7baf2c81200d3.chunk.css" />\n) +
120
+ assert_equal stylesheet_packs_with_chunks_tag("application", "hello_stimulus").in?([
121
+ %(<link rel="stylesheet" href="/packs/1-c20632e7baf2c81200d3.chunk.css" media="screen" />\n) +
122
+ %(<link rel="stylesheet" href="/packs/application-k344a6d59eef8632c9d1.chunk.css" media="screen" />\n) +
123
+ %(<link rel="stylesheet" href="/packs/hello_stimulus-k344a6d59eef8632c9d1.chunk.css" media="screen" />),
124
+
125
+ %(<link rel="stylesheet" media="screen" href="/packs/1-c20632e7baf2c81200d3.chunk.css" />\n) +
122
126
  %(<link rel="stylesheet" media="screen" href="/packs/application-k344a6d59eef8632c9d1.chunk.css" />\n) +
123
127
  %(<link rel="stylesheet" media="screen" href="/packs/hello_stimulus-k344a6d59eef8632c9d1.chunk.css" />),
124
- stylesheet_packs_with_chunks_tag("application", "hello_stimulus")
128
+ ]),
129
+ true
125
130
  end
126
131
 
127
132
  def test_stylesheet_pack_tag
128
- assert_equal \
133
+ assert_equal stylesheet_pack_tag("bootstrap.css").in?([
134
+ %(<link rel="stylesheet" href="/packs/bootstrap-c38deda30895059837cf.css" media="screen" />),
135
+
129
136
  %(<link rel="stylesheet" media="screen" href="/packs/bootstrap-c38deda30895059837cf.css" />),
130
- stylesheet_pack_tag("bootstrap.css")
137
+ ]), true
131
138
  end
132
139
 
133
140
  def test_stylesheet_pack_tag_symbol
134
- assert_equal \
141
+ assert_equal stylesheet_pack_tag(:bootstrap).in?([
142
+ %(<link rel="stylesheet" href="/packs/bootstrap-c38deda30895059837cf.css" media="screen" />),
143
+
135
144
  %(<link rel="stylesheet" media="screen" href="/packs/bootstrap-c38deda30895059837cf.css" />),
136
- stylesheet_pack_tag(:bootstrap)
145
+ ]), true
137
146
  end
138
147
 
139
148
  def test_stylesheet_pack_tag_splat
140
- assert_equal \
149
+ assert_equal stylesheet_pack_tag("bootstrap.css", "application.css", media: "all").in?([
150
+ %(<link rel="stylesheet" href="/packs/bootstrap-c38deda30895059837cf.css" media="all" />\n) +
151
+ %(<link rel="stylesheet" href="/packs/application-dd6b1cd38bfa093df600.css" media="all" />),
152
+
141
153
  %(<link rel="stylesheet" media="all" href="/packs/bootstrap-c38deda30895059837cf.css" />\n) +
142
154
  %(<link rel="stylesheet" media="all" href="/packs/application-dd6b1cd38bfa093df600.css" />),
143
- stylesheet_pack_tag("bootstrap.css", "application.css", media: "all")
155
+ ]), true
144
156
  end
145
157
  end
data/webpacker.gemspec CHANGED
@@ -23,7 +23,7 @@ Gem::Specification.new do |s|
23
23
  s.add_dependency "semantic_range", ">= 2.3.0"
24
24
 
25
25
  s.add_development_dependency "bundler", ">= 1.3.0"
26
- s.add_development_dependency "rubocop", "< 0.69"
26
+ s.add_development_dependency "rubocop", "0.93.1"
27
27
  s.add_development_dependency "rubocop-performance"
28
28
 
29
29
  s.files = `git ls-files`.split("\n")