webpacker 4.0.7 → 5.4.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (114) hide show
  1. checksums.yaml +4 -4
  2. data/.eslintrc.js +8 -8
  3. data/.github/workflows/jest.yml +38 -0
  4. data/.github/workflows/js-lint.yml +39 -0
  5. data/.github/workflows/rubocop.yml +39 -0
  6. data/.github/workflows/ruby.yml +46 -0
  7. data/.node-version +1 -1
  8. data/.rubocop.yml +118 -14
  9. data/CHANGELOG.md +301 -138
  10. data/CONTRIBUTING.md +1 -1
  11. data/Gemfile +1 -0
  12. data/Gemfile.lock +123 -92
  13. data/README.md +86 -211
  14. data/docs/css.md +72 -6
  15. data/docs/deployment.md +40 -11
  16. data/docs/docker.md +33 -14
  17. data/docs/engines.md +53 -3
  18. data/docs/env.md +0 -2
  19. data/docs/es6.md +19 -1
  20. data/docs/integrations.md +220 -0
  21. data/docs/target.md +22 -0
  22. data/docs/testing.md +2 -3
  23. data/docs/troubleshooting.md +39 -9
  24. data/docs/typescript.md +93 -26
  25. data/docs/webpack-dev-server.md +2 -2
  26. data/docs/webpack.md +18 -3
  27. data/gemfiles/Gemfile-rails-edge +1 -1
  28. data/gemfiles/{Gemfile-rails.4.2.x → Gemfile-rails.6.0.x} +1 -1
  29. data/lib/install/bin/webpack +0 -1
  30. data/lib/install/bin/webpack-dev-server +0 -1
  31. data/lib/install/coffee.rb +1 -1
  32. data/lib/install/config/babel.config.js +23 -13
  33. data/lib/install/config/webpacker.yml +3 -6
  34. data/lib/install/elm.rb +1 -1
  35. data/lib/install/erb.rb +2 -2
  36. data/lib/install/examples/angular/hello_angular/polyfills.ts +2 -2
  37. data/lib/install/examples/react/babel.config.js +28 -14
  38. data/lib/install/examples/react/tsconfig.json +2 -1
  39. data/lib/install/examples/svelte/app.svelte +11 -0
  40. data/lib/install/examples/svelte/hello_svelte.js +20 -0
  41. data/lib/install/examples/typescript/tsconfig.json +2 -1
  42. data/lib/install/loaders/elm.js +9 -6
  43. data/lib/install/loaders/svelte.js +9 -0
  44. data/lib/install/svelte.rb +29 -0
  45. data/lib/install/template.rb +14 -6
  46. data/lib/install/typescript.rb +6 -13
  47. data/lib/install/vue.rb +1 -1
  48. data/lib/tasks/installers.rake +1 -0
  49. data/lib/tasks/webpacker/check_node.rake +15 -8
  50. data/lib/tasks/webpacker/check_yarn.rake +16 -10
  51. data/lib/tasks/webpacker/clean.rake +25 -0
  52. data/lib/tasks/webpacker/clobber.rake +8 -4
  53. data/lib/tasks/webpacker/compile.rake +2 -10
  54. data/lib/tasks/webpacker/yarn_install.rake +11 -1
  55. data/lib/tasks/webpacker.rake +2 -0
  56. data/lib/webpacker/commands.rb +53 -1
  57. data/lib/webpacker/compiler.rb +21 -10
  58. data/lib/webpacker/configuration.rb +36 -13
  59. data/lib/webpacker/dev_server.rb +1 -1
  60. data/lib/webpacker/dev_server_proxy.rb +5 -9
  61. data/lib/webpacker/dev_server_runner.rb +6 -6
  62. data/lib/webpacker/env.rb +6 -2
  63. data/lib/webpacker/helper.rb +70 -25
  64. data/lib/webpacker/manifest.rb +4 -4
  65. data/lib/webpacker/railtie.rb +6 -43
  66. data/lib/webpacker/runner.rb +1 -0
  67. data/lib/webpacker/version.rb +1 -1
  68. data/lib/webpacker/webpack_runner.rb +2 -2
  69. data/lib/webpacker.rb +9 -1
  70. data/package/__tests__/config.js +12 -24
  71. data/package/__tests__/dev_server.js +2 -0
  72. data/package/__tests__/development.js +14 -1
  73. data/package/config.js +6 -11
  74. data/package/configPath.js +3 -0
  75. data/package/config_types/config_list.js +3 -3
  76. data/package/config_types/config_object.js +1 -1
  77. data/package/dev_server.js +1 -1
  78. data/package/env.js +1 -2
  79. data/package/environments/__tests__/base.js +29 -2
  80. data/package/environments/base.js +18 -8
  81. data/package/environments/development.js +39 -37
  82. data/package/environments/production.js +12 -2
  83. data/package/rules/babel.js +12 -5
  84. data/package/rules/file.js +3 -2
  85. data/package/rules/node_modules.js +3 -5
  86. data/package/rules/sass.js +11 -2
  87. data/package/utils/__tests__/get_style_rule.js +9 -0
  88. data/package/utils/deep_merge.js +5 -5
  89. data/package/utils/get_style_rule.js +7 -12
  90. data/package/utils/helpers.js +10 -10
  91. data/package.json +43 -43
  92. data/test/command_test.rb +6 -0
  93. data/test/compiler_test.rb +10 -6
  94. data/test/configuration_test.rb +40 -30
  95. data/test/dev_server_runner_test.rb +1 -1
  96. data/test/dev_server_test.rb +22 -0
  97. data/test/helper_test.rb +58 -9
  98. data/test/manifest_test.rb +37 -6
  99. data/test/rake_tasks_test.rb +17 -0
  100. data/test/test_app/app/javascript/packs/multi_entry.css +4 -0
  101. data/test/test_app/app/javascript/packs/multi_entry.js +4 -0
  102. data/test/test_app/bin/webpack +0 -1
  103. data/test/test_app/bin/webpack-dev-server +0 -1
  104. data/test/test_app/config/application.rb +0 -1
  105. data/test/test_app/config/webpacker.yml +8 -1
  106. data/test/test_app/public/packs/manifest.json +4 -0
  107. data/test/webpack_runner_test.rb +1 -1
  108. data/webpacker.gemspec +6 -4
  109. data/yarn.lock +4350 -4099
  110. metadata +63 -23
  111. data/.travis.yml +0 -53
  112. data/gemfiles/Gemfile-rails.5.0.x +0 -9
  113. data/gemfiles/Gemfile-rails.5.1.x +0 -9
  114. data/lib/install/loaders/typescript.js +0 -11
data/test/helper_test.rb CHANGED
@@ -50,6 +50,27 @@ class HelperTest < ActionView::TestCase
50
50
  assert_equal \
51
51
  "<img alt=\"Edit Entry\" src=\"/packs/media/images/nested/image-c38deda30895059837cf.jpg\" width=\"16\" height=\"10\" />",
52
52
  image_pack_tag("media/images/nested/image.jpg", size: "16x10", alt: "Edit Entry")
53
+ assert_equal \
54
+ "<img srcset=\"/packs/media/images/image-2x-7cca48e6cae66ec07b8e.jpg 2x\" src=\"/packs/media/images/image-c38deda30895059837cf.jpg\" />",
55
+ image_pack_tag("media/images/image.jpg", srcset: { "media/images/image-2x.jpg" => "2x" })
56
+ end
57
+
58
+ def test_favicon_pack_tag
59
+ assert_equal \
60
+ "<link rel=\"apple-touch-icon\" type=\"image/png\" href=\"/packs/application-k344a6d59eef8632c9d1.png\" />",
61
+ favicon_pack_tag("application.png", rel: "apple-touch-icon", type: "image/png")
62
+ assert_equal \
63
+ "<link rel=\"apple-touch-icon\" type=\"image/png\" href=\"/packs/media/images/mb-icon-c38deda30895059837cf.png\" />",
64
+ favicon_pack_tag("mb-icon.png", rel: "apple-touch-icon", type: "image/png")
65
+ assert_equal \
66
+ "<link rel=\"apple-touch-icon\" type=\"image/png\" href=\"/packs/media/images/mb-icon-c38deda30895059837cf.png\" />",
67
+ favicon_pack_tag("media/images/mb-icon.png", rel: "apple-touch-icon", type: "image/png")
68
+ assert_equal \
69
+ "<link rel=\"apple-touch-icon\" type=\"image/png\" href=\"/packs/media/images/nested/mb-icon-c38deda30895059837cf.png\" />",
70
+ favicon_pack_tag("nested/mb-icon.png", rel: "apple-touch-icon", type: "image/png")
71
+ assert_equal \
72
+ "<link rel=\"apple-touch-icon\" type=\"image/png\" href=\"/packs/media/images/nested/mb-icon-c38deda30895059837cf.png\" />",
73
+ favicon_pack_tag("media/images/nested/mb-icon.png", rel: "apple-touch-icon", type: "image/png")
53
74
  end
54
75
 
55
76
  def test_javascript_pack_tag
@@ -79,30 +100,58 @@ class HelperTest < ActionView::TestCase
79
100
  javascript_packs_with_chunks_tag("application")
80
101
  end
81
102
 
103
+ def test_preload_pack_asset
104
+ if self.class.method_defined?(:preload_link_tag)
105
+ assert_equal \
106
+ %(<link rel="preload" href="/packs/fonts/fa-regular-400-944fb546bd7018b07190a32244f67dc9.woff2" as="font" type="font/woff2" crossorigin="anonymous">),
107
+ preload_pack_asset("fonts/fa-regular-400.woff2")
108
+ else
109
+ error = assert_raises do
110
+ preload_pack_asset("fonts/fa-regular-400.woff2")
111
+ end
112
+
113
+ assert_equal \
114
+ "You need Rails >= 5.2 to use this tag.",
115
+ error.message
116
+ end
117
+ end
118
+
82
119
  def test_stylesheet_pack_tag_split_chunks
83
- assert_equal \
84
- %(<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) +
85
126
  %(<link rel="stylesheet" media="screen" href="/packs/application-k344a6d59eef8632c9d1.chunk.css" />\n) +
86
127
  %(<link rel="stylesheet" media="screen" href="/packs/hello_stimulus-k344a6d59eef8632c9d1.chunk.css" />),
87
- stylesheet_packs_with_chunks_tag("application", "hello_stimulus")
128
+ ]),
129
+ true
88
130
  end
89
131
 
90
132
  def test_stylesheet_pack_tag
91
- assert_equal \
133
+ assert_equal stylesheet_pack_tag("bootstrap.css").in?([
134
+ %(<link rel="stylesheet" href="/packs/bootstrap-c38deda30895059837cf.css" media="screen" />),
135
+
92
136
  %(<link rel="stylesheet" media="screen" href="/packs/bootstrap-c38deda30895059837cf.css" />),
93
- stylesheet_pack_tag("bootstrap.css")
137
+ ]), true
94
138
  end
95
139
 
96
140
  def test_stylesheet_pack_tag_symbol
97
- assert_equal \
141
+ assert_equal stylesheet_pack_tag(:bootstrap).in?([
142
+ %(<link rel="stylesheet" href="/packs/bootstrap-c38deda30895059837cf.css" media="screen" />),
143
+
98
144
  %(<link rel="stylesheet" media="screen" href="/packs/bootstrap-c38deda30895059837cf.css" />),
99
- stylesheet_pack_tag(:bootstrap)
145
+ ]), true
100
146
  end
101
147
 
102
148
  def test_stylesheet_pack_tag_splat
103
- 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
+
104
153
  %(<link rel="stylesheet" media="all" href="/packs/bootstrap-c38deda30895059837cf.css" />\n) +
105
154
  %(<link rel="stylesheet" media="all" href="/packs/application-dd6b1cd38bfa093df600.css" />),
106
- stylesheet_pack_tag("bootstrap.css", "application.css", media: "all")
155
+ ]), true
107
156
  end
108
157
  end
@@ -2,16 +2,23 @@ require "test_helper"
2
2
 
3
3
  class ManifestTest < Minitest::Test
4
4
  def test_lookup_exception!
5
- manifest_path = File.expand_path File.join(File.dirname(__FILE__), "test_app/public/packs", "manifest.json").to_s
6
5
  asset_file = "calendar.js"
7
6
 
8
- Webpacker.config.stub :compile?, false do
9
- error = assert_raises Webpacker::Manifest::MissingEntryError do
10
- Webpacker.manifest.lookup!(asset_file)
11
- end
7
+ error = assert_raises_manifest_missing_entry_error do
8
+ Webpacker.manifest.lookup!(asset_file)
9
+ end
10
+
11
+ assert_match "Webpacker can't find #{asset_file} in #{manifest_path}", error.message
12
+ end
13
+
14
+ def test_lookup_with_type_exception!
15
+ asset_file = "calendar"
12
16
 
13
- assert_match "Webpacker can't find #{asset_file} in #{manifest_path}", error.message
17
+ error = assert_raises_manifest_missing_entry_error do
18
+ Webpacker.manifest.lookup!(asset_file, type: :javascript)
14
19
  end
20
+
21
+ assert_match "Webpacker can't find #{asset_file}.js in #{manifest_path}", error.message
15
22
  end
16
23
 
17
24
  def test_lookup_success!
@@ -30,6 +37,16 @@ class ManifestTest < Minitest::Test
30
37
  assert_equal Webpacker.manifest.lookup("bootstrap.js"), "/packs/bootstrap-300631c4f0e0f9c865bc.js"
31
38
  end
32
39
 
40
+ def test_lookup_entrypoint_exception!
41
+ asset_file = "calendar"
42
+
43
+ error = assert_raises_manifest_missing_entry_error do
44
+ Webpacker.manifest.lookup_pack_with_chunks!(asset_file, type: :javascript)
45
+ end
46
+
47
+ assert_match "Webpacker can't find #{asset_file}.js in #{manifest_path}", error.message
48
+ end
49
+
33
50
  def test_lookup_entrypoint
34
51
  application_entrypoints = [
35
52
  "/packs/vendors~application~bootstrap-c20632e7baf2c81200d3.chunk.js",
@@ -39,4 +56,18 @@ class ManifestTest < Minitest::Test
39
56
 
40
57
  assert_equal Webpacker.manifest.lookup_pack_with_chunks!("application", type: :javascript), application_entrypoints
41
58
  end
59
+
60
+ private
61
+
62
+ def assert_raises_manifest_missing_entry_error(&block)
63
+ error = nil
64
+ Webpacker.config.stub :compile?, false do
65
+ error = assert_raises Webpacker::Manifest::MissingEntryError, &block
66
+ end
67
+ error
68
+ end
69
+
70
+ def manifest_path
71
+ File.expand_path File.join(File.dirname(__FILE__), "test_app/public/packs", "manifest.json").to_s
72
+ end
42
73
  end
@@ -7,12 +7,18 @@ class RakeTasksTest < Minitest::Test
7
7
  assert_includes output, "webpacker:check_binstubs"
8
8
  assert_includes output, "webpacker:check_node"
9
9
  assert_includes output, "webpacker:check_yarn"
10
+ assert_includes output, "webpacker:clean"
10
11
  assert_includes output, "webpacker:clobber"
11
12
  assert_includes output, "webpacker:compile"
12
13
  assert_includes output, "webpacker:install"
13
14
  assert_includes output, "webpacker:install:angular"
15
+ assert_includes output, "webpacker:install:coffee"
14
16
  assert_includes output, "webpacker:install:elm"
17
+ assert_includes output, "webpacker:install:erb"
15
18
  assert_includes output, "webpacker:install:react"
19
+ assert_includes output, "webpacker:install:svelte"
20
+ assert_includes output, "webpacker:install:stimulus"
21
+ assert_includes output, "webpacker:install:typescript"
16
22
  assert_includes output, "webpacker:install:vue"
17
23
  assert_includes output, "webpacker:verify_install"
18
24
  end
@@ -22,6 +28,17 @@ class RakeTasksTest < Minitest::Test
22
28
  refute_includes output, "webpack binstubs not found."
23
29
  end
24
30
 
31
+ def test_check_node_version
32
+ output = Dir.chdir(test_app_path) { `rake webpacker:check_node 2>&1` }
33
+ refute_includes output, "Webpacker requires Node.js"
34
+ end
35
+
36
+ def test_check_yarn_version
37
+ output = Dir.chdir(test_app_path) { `rake webpacker:check_yarn 2>&1` }
38
+ refute_includes output, "Yarn not installed"
39
+ refute_includes output, "Webpacker requires Yarn"
40
+ end
41
+
25
42
  def test_rake_webpacker_yarn_install_in_non_production_environments
26
43
  assert_includes test_app_dev_dependencies, "right-pad"
27
44
 
@@ -0,0 +1,4 @@
1
+ /*
2
+ * Dummy file #1 for Multi File Entry points: https://webpack.js.org/guides/entry-advanced/
3
+ * This file must be named the same
4
+ */
@@ -0,0 +1,4 @@
1
+ /*
2
+ * Dummy file #2 for Multi File Entry points: https://webpack.js.org/guides/entry-advanced/
3
+ * This file must be named the same
4
+ */
@@ -7,7 +7,6 @@ require "pathname"
7
7
  ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../Gemfile",
8
8
  Pathname.new(__FILE__).realpath)
9
9
 
10
- require "rubygems"
11
10
  require "bundler/setup"
12
11
 
13
12
  require "webpacker"
@@ -7,7 +7,6 @@ require "pathname"
7
7
  ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../Gemfile",
8
8
  Pathname.new(__FILE__).realpath)
9
9
 
10
- require "rubygems"
11
10
  require "bundler/setup"
12
11
 
13
12
  require "webpacker"
@@ -6,7 +6,6 @@ module TestApp
6
6
  class Application < ::Rails::Application
7
7
  config.secret_key_base = "abcdef"
8
8
  config.eager_load = true
9
- config.webpacker.check_yarn_integrity = false
10
9
  config.active_support.test_order = :sorted
11
10
  end
12
11
  end
@@ -10,10 +10,15 @@ default: &default
10
10
 
11
11
  # Additional paths webpack should lookup modules
12
12
  # ['app/assets', 'engine/foo/app/assets']
13
- resolved_paths:
13
+ additional_paths:
14
14
  - app/assets
15
15
  - /etc/yarn
16
16
 
17
+ # This configuration option is deprecated and is only here for testing, to
18
+ # ensure backwards-compatibility. Please use `additional_paths`.
19
+ resolved_paths:
20
+ - app/elm
21
+
17
22
  # Reload manifest.json on all requests so we reload latest compiled packs
18
23
  cache_manifest: false
19
24
 
@@ -43,6 +48,7 @@ default: &default
43
48
  - .gif
44
49
  - .jpeg
45
50
  - .jpg
51
+ - .elm
46
52
 
47
53
  development:
48
54
  <<: *default
@@ -60,6 +66,7 @@ development:
60
66
  overlay: true
61
67
  disable_host_check: true
62
68
  use_local_ip: false
69
+ pretty: false
63
70
 
64
71
  test:
65
72
  <<: *default
@@ -4,8 +4,12 @@
4
4
  "bootstrap.js": "/packs/bootstrap-300631c4f0e0f9c865bc.js",
5
5
  "application.js": "/packs/application-k344a6d59eef8632c9d1.js",
6
6
  "application.png": "/packs/application-k344a6d59eef8632c9d1.png",
7
+ "fonts/fa-regular-400.woff2": "/packs/fonts/fa-regular-400-944fb546bd7018b07190a32244f67dc9.woff2",
7
8
  "media/images/image.jpg": "/packs/media/images/image-c38deda30895059837cf.jpg",
9
+ "media/images/image-2x.jpg": "/packs/media/images/image-2x-7cca48e6cae66ec07b8e.jpg",
8
10
  "media/images/nested/image.jpg": "/packs/media/images/nested/image-c38deda30895059837cf.jpg",
11
+ "media/images/mb-icon.png": "/packs/media/images/mb-icon-c38deda30895059837cf.png",
12
+ "media/images/nested/mb-icon.png": "/packs/media/images/nested/mb-icon-c38deda30895059837cf.png",
9
13
  "entrypoints": {
10
14
  "application": {
11
15
  "js": [
@@ -36,7 +36,7 @@ class WebpackRunnerTest < Webpacker::Test
36
36
  klass = Webpacker::WebpackRunner
37
37
  instance = klass.new([])
38
38
  mock = Minitest::Mock.new
39
- mock.expect(:call, nil, [{}, *cmd])
39
+ mock.expect(:call, nil, [Webpacker::Compiler.env, *cmd])
40
40
 
41
41
  klass.stub(:new, instance) do
42
42
  instance.stub(:node_modules_bin_exist?, use_node_modules) do
data/webpacker.gemspec CHANGED
@@ -15,14 +15,16 @@ Gem::Specification.new do |s|
15
15
  "changelog_uri" => "https://github.com/rails/webpacker/blob/v#{Webpacker::VERSION}/CHANGELOG.md"
16
16
  }
17
17
 
18
- s.required_ruby_version = ">= 2.2.0"
18
+ s.required_ruby_version = ">= 2.4.0"
19
19
 
20
- s.add_dependency "activesupport", ">= 4.2"
21
- s.add_dependency "railties", ">= 4.2"
20
+ s.add_dependency "activesupport", ">= 5.2"
21
+ s.add_dependency "railties", ">= 5.2"
22
22
  s.add_dependency "rack-proxy", ">= 0.6.1"
23
+ s.add_dependency "semantic_range", ">= 2.3.0"
23
24
 
24
25
  s.add_development_dependency "bundler", ">= 1.3.0"
25
- s.add_development_dependency "rubocop", "< 0.69"
26
+ s.add_development_dependency "rubocop", "0.93.1"
27
+ s.add_development_dependency "rubocop-performance"
26
28
 
27
29
  s.files = `git ls-files`.split("\n")
28
30
  s.test_files = `git ls-files -- test/*`.split("\n")