shakapacker 7.0.3 → 7.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (67) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/dummy.yml +3 -1
  3. data/.github/workflows/generator.yml +3 -1
  4. data/.github/workflows/jest.yml +4 -2
  5. data/.github/workflows/js-lint.yml +4 -2
  6. data/.github/workflows/rubocop.yml +3 -1
  7. data/.github/workflows/ruby-backward-compatibility.yml +3 -1
  8. data/.github/workflows/ruby.yml +4 -2
  9. data/CHANGELOG.md +7 -0
  10. data/README.md +29 -20
  11. data/docs/troubleshooting.md +4 -8
  12. data/docs/using_esbuild_loader.md +2 -4
  13. data/lib/install/template.rb +2 -2
  14. data/lib/shakapacker/deprecation_helper.rb +1 -1
  15. data/lib/shakapacker/dev_server_runner.rb +2 -1
  16. data/lib/shakapacker/version.rb +1 -1
  17. data/lib/shakapacker/version_checker.rb +35 -2
  18. data/lib/shakapacker/webpack_runner.rb +4 -3
  19. data/package/__tests__/index.js +24 -0
  20. data/package/index.d.ts +1 -1
  21. data/package/index.js +8 -2
  22. data/package.json +1 -1
  23. data/spec/backward_compatibility_specs/compiler_strategy_spec.rb +5 -3
  24. data/spec/backward_compatibility_specs/configuration_spec.rb +12 -4
  25. data/spec/backward_compatibility_specs/dev_server_runner_spec.rb +17 -16
  26. data/spec/backward_compatibility_specs/dev_server_spec.rb +1 -1
  27. data/spec/backward_compatibility_specs/digest_strategy_spec.rb +2 -0
  28. data/spec/backward_compatibility_specs/engine_rake_tasks_spec.rb +2 -1
  29. data/spec/backward_compatibility_specs/helper_spec.rb +20 -20
  30. data/spec/backward_compatibility_specs/instance_spec.rb +3 -3
  31. data/spec/backward_compatibility_specs/manifest_spec.rb +12 -12
  32. data/spec/backward_compatibility_specs/mtime_strategy_spec.rb +3 -3
  33. data/spec/backward_compatibility_specs/rake_tasks_spec.rb +9 -5
  34. data/spec/backward_compatibility_specs/webpack_runner_spec.rb +14 -18
  35. data/spec/dummy/config/webpack/commonWebpackConfig.js +1 -1
  36. data/spec/fixtures/beta_pnpm-lock.v7.yaml +116 -0
  37. data/spec/fixtures/beta_pnpm-lock.v8.yaml +2537 -0
  38. data/spec/fixtures/git_url_pnpm-lock.v7.yaml +126 -0
  39. data/spec/fixtures/git_url_pnpm-lock.v8.yaml +3728 -0
  40. data/spec/fixtures/github_url_pnpm-lock.v7.yaml +126 -0
  41. data/spec/fixtures/github_url_pnpm-lock.v8.yaml +3728 -0
  42. data/spec/fixtures/relative_path_pnpm-lock.v7.yaml +18 -0
  43. data/spec/fixtures/relative_path_pnpm-lock.v8.yaml +22 -0
  44. data/spec/fixtures/semver_caret_pnpm-lock.v7.yaml +117 -0
  45. data/spec/fixtures/semver_caret_pnpm-lock.v8.yaml +2558 -0
  46. data/spec/fixtures/semver_exact_pnpm-lock.v7.yaml +117 -0
  47. data/spec/fixtures/semver_exact_pnpm-lock.v8.yaml +2558 -0
  48. data/spec/fixtures/semver_tilde_pnpm-lock.v7.yaml +116 -0
  49. data/spec/fixtures/semver_tilde_pnpm-lock.v8.yaml +2558 -0
  50. data/spec/fixtures/without_pnpm-lock.v7.yaml +23 -0
  51. data/spec/fixtures/without_pnpm-lock.v8.yaml +27 -0
  52. data/spec/generator_specs/generator_spec.rb +7 -3
  53. data/spec/shakapacker/compiler_strategy_spec.rb +5 -3
  54. data/spec/shakapacker/configuration_spec.rb +12 -2
  55. data/spec/shakapacker/dev_server_runner_spec.rb +22 -16
  56. data/spec/shakapacker/dev_server_spec.rb +1 -1
  57. data/spec/shakapacker/digest_strategy_spec.rb +2 -0
  58. data/spec/shakapacker/engine_rake_tasks_spec.rb +2 -1
  59. data/spec/shakapacker/helper_spec.rb +20 -20
  60. data/spec/shakapacker/instance_spec.rb +2 -2
  61. data/spec/shakapacker/manifest_spec.rb +12 -12
  62. data/spec/shakapacker/mtime_strategy_spec.rb +3 -3
  63. data/spec/shakapacker/rake_tasks_spec.rb +5 -2
  64. data/spec/shakapacker/shakapacker_spec.rb +4 -4
  65. data/spec/shakapacker/version_checker_spec.rb +468 -121
  66. data/spec/shakapacker/webpack_runner_spec.rb +14 -18
  67. metadata +19 -3
@@ -17,22 +17,25 @@ describe "DevServerRunner" do
17
17
 
18
18
  let(:test_app_path) { File.expand_path("webpacker_test_app", __dir__) }
19
19
 
20
- it "run cmd via node modules" do
20
+ it "supports running via node modules" do
21
21
  cmd = ["#{test_app_path}/node_modules/.bin/webpack", "serve", "--config", "#{test_app_path}/config/webpack/webpack.config.js"]
22
+
22
23
  verify_command(cmd, use_node_modules: true)
23
24
  end
24
25
 
25
- it "run cmd via yarn" do
26
+ it "supports running via yarn" do
26
27
  cmd = ["yarn", "webpack", "serve", "--config", "#{test_app_path}/config/webpack/webpack.config.js"]
28
+
27
29
  verify_command(cmd, use_node_modules: false)
28
30
  end
29
31
 
30
- it "run cmd argv" do
32
+ it "passes on arguments" do
31
33
  cmd = ["#{test_app_path}/node_modules/.bin/webpack", "serve", "--config", "#{test_app_path}/config/webpack/webpack.config.js", "--quiet"]
34
+
32
35
  verify_command(cmd, argv: (["--quiet"]))
33
36
  end
34
37
 
35
- it "run cmd argv with https" do
38
+ it "supports the https flag" do
36
39
  cmd = ["#{test_app_path}/node_modules/.bin/webpack", "serve", "--config", "#{test_app_path}/config/webpack/webpack.config.js", "--https"]
37
40
 
38
41
  dev_server = double()
@@ -54,26 +57,24 @@ describe "DevServerRunner" do
54
57
  # ENV["WEBPACKER_CONFIG"] is the interface and env["SHAKAPACKER_CONFIG"] is internal
55
58
  ENV["WEBPACKER_CONFIG"] = env["SHAKAPACKER_CONFIG"] = "#{test_app_path}/config/webpacker_other_location.yml"
56
59
  env["WEBPACK_SERVE"] = "true"
60
+
57
61
  verify_command(cmd, env: env)
58
62
  end
59
63
 
60
64
  private
61
65
 
62
66
  def verify_command(cmd, use_node_modules: true, argv: [], env: Webpacker::Compiler.env)
63
- cwd = Dir.pwd
64
- Dir.chdir(test_app_path)
65
- klass = Webpacker::DevServerRunner
66
- instance = klass.new(argv)
67
-
68
- allow(klass).to receive(:new).and_return(instance)
69
- allow(instance).to receive(:node_modules_bin_exist?).and_return(use_node_modules)
70
- allow(Kernel).to receive(:exec).with(env, *cmd)
67
+ Dir.chdir(test_app_path) do
68
+ klass = Webpacker::DevServerRunner
69
+ instance = klass.new(argv)
71
70
 
72
- klass.run(argv)
71
+ allow(klass).to receive(:new).and_return(instance)
72
+ allow(instance).to receive(:node_modules_bin_exist?).and_return(use_node_modules)
73
+ allow(Kernel).to receive(:exec).with(env, *cmd)
73
74
 
74
- expect(Kernel).to have_received(:exec).with(env, *cmd)
75
+ klass.run(argv)
75
76
 
76
- ensure
77
- Dir.chdir(cwd)
77
+ expect(Kernel).to have_received(:exec).with(env, *cmd)
78
+ end
78
79
  end
79
80
  end
@@ -41,7 +41,7 @@ describe "DevServer" do
41
41
  end
42
42
  end
43
43
 
44
- it "users SHAKAPACKER_DEV_SERVER for DEFAULT_ENV_PREFIX" do
44
+ it "uses SHAKAPACKER_DEV_SERVER for DEFAULT_ENV_PREFIX" do
45
45
  expect(Webpacker::DevServer::DEFAULT_ENV_PREFIX).to eq "SHAKAPACKER_DEV_SERVER"
46
46
  end
47
47
  end
@@ -23,6 +23,7 @@ describe "DigestStrategy" do
23
23
 
24
24
  it "is fresh after compilation" do
25
25
  @digest_strategy.after_compile_hook
26
+
26
27
  expect(@digest_strategy.stale?).to be false
27
28
  expect(@digest_strategy.fresh?).to be true
28
29
  end
@@ -30,6 +31,7 @@ describe "DigestStrategy" do
30
31
  it "generates correct compilation_digest_path" do
31
32
  actual_path = @digest_strategy.send(:compilation_digest_path).basename.to_s
32
33
  expected_path = "last-compilation-digest-#{Webpacker.env}"
34
+
33
35
  expect(actual_path).to eq expected_path
34
36
  end
35
37
  end
@@ -11,11 +11,12 @@ describe "EngineRakeTasks" do
11
11
 
12
12
  it "mounts app:webpacker task successfully" do
13
13
  output = Dir.chdir(mounted_app_path) { `rake -T` }
14
+
14
15
  expect(output).to match /app:webpacker.+DEPRECATED/
15
16
  expect(output).to match /app:webpacker:binstubs.+DEPRECATED/
16
17
  end
17
18
 
18
- it "binstubs adds only expected files to bin directory" do
19
+ it "only adds expected files to bin directory when binstubs is run" do
19
20
  Dir.chdir(mounted_app_path) { `bundle exec rake app:webpacker:binstubs` }
20
21
  expected_binstub_paths.each { |path| expect(File.exist?(path)).to be true }
21
22
  end
@@ -22,17 +22,17 @@ module ActionView::TestCase::Behavior
22
22
  @javascript_pack_tag_loaded = nil
23
23
  end
24
24
 
25
- it "#asset_pack_path generates correct path" do
25
+ it "#asset_pack_path generates the correct path" do
26
26
  expect(asset_pack_path("bootstrap.js")).to eq "/packs/bootstrap-300631c4f0e0f9c865bc.js"
27
27
  expect(asset_pack_path("bootstrap.css")).to eq "/packs/bootstrap-c38deda30895059837cf.css"
28
28
  end
29
29
 
30
- it "#asset_pack_url generates correct url" do
30
+ it "#asset_pack_url generates the correct url" do
31
31
  expect(asset_pack_url("bootstrap.js")).to eq "https://example.com/packs/bootstrap-300631c4f0e0f9c865bc.js"
32
32
  expect(asset_pack_url("bootstrap.css")).to eq "https://example.com/packs/bootstrap-c38deda30895059837cf.css"
33
33
  end
34
34
 
35
- it "#image_pack_path generates correct path" do
35
+ it "#image_pack_path generates the correct path" do
36
36
  expect(image_pack_path("application.png")).to eq "/packs/application-k344a6d59eef8632c9d1.png"
37
37
  expect(image_pack_path("image.jpg")).to eq "/packs/static/image-c38deda30895059837cf.jpg"
38
38
  expect(image_pack_path("static/image.jpg")).to eq "/packs/static/image-c38deda30895059837cf.jpg"
@@ -40,7 +40,7 @@ module ActionView::TestCase::Behavior
40
40
  expect(image_pack_path("static/nested/image.jpg")).to eq "/packs/static/nested/image-c38deda30895059837cf.jpg"
41
41
  end
42
42
 
43
- it "#image_pack_url generates correct path" do
43
+ it "#image_pack_url generates the correct path" do
44
44
  expect(image_pack_url("application.png")).to eq "https://example.com/packs/application-k344a6d59eef8632c9d1.png"
45
45
  expect(image_pack_url("image.jpg")).to eq "https://example.com/packs/static/image-c38deda30895059837cf.jpg"
46
46
  expect(image_pack_url("static/image.jpg")).to eq "https://example.com/packs/static/image-c38deda30895059837cf.jpg"
@@ -48,7 +48,7 @@ module ActionView::TestCase::Behavior
48
48
  expect(image_pack_url("static/nested/image.jpg")).to eq "https://example.com/packs/static/nested/image-c38deda30895059837cf.jpg"
49
49
  end
50
50
 
51
- it "#image_pack_tag generates correct tags" do
51
+ it "#image_pack_tag generates the correct tags" do
52
52
  expect(image_pack_tag("application.png", size: "16x10", alt: "Edit Entry")).to eq "<img alt=\"Edit Entry\" src=\"/packs/application-k344a6d59eef8632c9d1.png\" width=\"16\" height=\"10\" />"
53
53
  expect(image_pack_tag("image.jpg", size: "16x10", alt: "Edit Entry")).to eq "<img alt=\"Edit Entry\" src=\"/packs/static/image-c38deda30895059837cf.jpg\" width=\"16\" height=\"10\" />"
54
54
  expect(image_pack_tag("static/image.jpg", size: "16x10", alt: "Edit Entry")).to eq "<img alt=\"Edit Entry\" src=\"/packs/static/image-c38deda30895059837cf.jpg\" width=\"16\" height=\"10\" />"
@@ -57,7 +57,7 @@ module ActionView::TestCase::Behavior
57
57
  expect(image_pack_tag("static/image.jpg", srcset: { "static/image-2x.jpg" => "2x" })).to eq "<img srcset=\"/packs/static/image-2x-7cca48e6cae66ec07b8e.jpg 2x\" src=\"/packs/static/image-c38deda30895059837cf.jpg\" />"
58
58
  end
59
59
 
60
- it "#favicon_pack_tag generates correct tags" do
60
+ it "#favicon_pack_tag generates the correct tags" do
61
61
  expect(favicon_pack_tag("application.png", rel: "apple-touch-icon", type: "image/png")).to eq "<link rel=\"apple-touch-icon\" type=\"image/png\" href=\"/packs/application-k344a6d59eef8632c9d1.png\" />"
62
62
  expect(favicon_pack_tag("mb-icon.png", rel: "apple-touch-icon", type: "image/png")).to eq "<link rel=\"apple-touch-icon\" type=\"image/png\" href=\"/packs/static/mb-icon-c38deda30895059837cf.png\" />"
63
63
  expect(favicon_pack_tag("static/mb-icon.png", rel: "apple-touch-icon", type: "image/png")).to eq "<link rel=\"apple-touch-icon\" type=\"image/png\" href=\"/packs/static/mb-icon-c38deda30895059837cf.png\" />"
@@ -65,7 +65,7 @@ module ActionView::TestCase::Behavior
65
65
  expect(favicon_pack_tag("static/nested/mb-icon.png", rel: "apple-touch-icon", type: "image/png")).to eq "<link rel=\"apple-touch-icon\" type=\"image/png\" href=\"/packs/static/nested/mb-icon-c38deda30895059837cf.png\" />"
66
66
  end
67
67
 
68
- it "#preload_pack_asset generates correct tag" do
68
+ it "#preload_pack_asset generates the correct tag" do
69
69
  if self.class.method_defined?(:preload_link_tag)
70
70
  expect(preload_pack_asset("fonts/fa-regular-400.woff2")).to eq %(<link rel="preload" href="/packs/fonts/fa-regular-400-944fb546bd7018b07190a32244f67dc9.woff2" as="font" type="font/woff2" crossorigin="anonymous">)
71
71
  else
@@ -73,7 +73,7 @@ module ActionView::TestCase::Behavior
73
73
  end
74
74
  end
75
75
 
76
- it "#javascript_pack_tag generates correct tags" do
76
+ it "#javascript_pack_tag generates the correct tags" do
77
77
  expected = <<~HTML.chomp
78
78
  <script src="/packs/vendors~application~bootstrap-c20632e7baf2c81200d3.chunk.js" defer="defer"></script>
79
79
  <script src="/packs/vendors~application-e55f2aae30c07fb6d82a.chunk.js" defer="defer"></script>
@@ -84,7 +84,7 @@ module ActionView::TestCase::Behavior
84
84
  expect(javascript_pack_tag("application", "bootstrap")).to eq expected
85
85
  end
86
86
 
87
- it "#javascript_pack_tag generates correct tags by passing `defer: false`" do
87
+ it "#javascript_pack_tag generates the correct tags when passing `defer: false`" do
88
88
  expected = <<~HTML.chomp
89
89
  <script src="/packs/vendors~application~bootstrap-c20632e7baf2c81200d3.chunk.js"></script>
90
90
  <script src="/packs/vendors~application-e55f2aae30c07fb6d82a.chunk.js"></script>
@@ -95,7 +95,7 @@ module ActionView::TestCase::Behavior
95
95
  expect(javascript_pack_tag("application", "bootstrap", defer: false)).to eq expected
96
96
  end
97
97
 
98
- it "#javascript_pack_tag generates correct appended tag" do
98
+ it "#javascript_pack_tag generates the correct appended tag" do
99
99
  append_javascript_pack_tag("bootstrap", defer: false)
100
100
 
101
101
  expected = <<~HTML.chomp
@@ -108,7 +108,7 @@ module ActionView::TestCase::Behavior
108
108
  expect(javascript_pack_tag("application")).to eq expected
109
109
  end
110
110
 
111
- it "#javascript_pack_tag generates correct prepended tag" do
111
+ it "#javascript_pack_tag generates the correct prepended tag" do
112
112
  append_javascript_pack_tag("bootstrap")
113
113
  prepend_javascript_pack_tag("main")
114
114
 
@@ -123,7 +123,7 @@ module ActionView::TestCase::Behavior
123
123
  expect(javascript_pack_tag("application")).to eq expected
124
124
  end
125
125
 
126
- it "#append_javascript_pack_tag raises error if called after calling #javascript_pack_tag" do
126
+ it "#append_javascript_pack_tag raises an error if called after calling #javascript_pack_tag" do
127
127
  expected_error_message = \
128
128
  "You can only call append_javascript_pack_tag before javascript_pack_tag helper. " +
129
129
  "Please refer to https://github.com/shakacode/shakapacker/blob/master/README.md#view-helper-append_javascript_pack_tag-prepend_javascript_pack_tag-and-append_stylesheet_pack_tag for the usage guide"
@@ -134,7 +134,7 @@ module ActionView::TestCase::Behavior
134
134
  }.to raise_error(expected_error_message)
135
135
  end
136
136
 
137
- it "#prepend_javascript_pack_tag raises error if called after calling #javascript_pack_tag" do
137
+ it "#prepend_javascript_pack_tag raises an error if called after calling #javascript_pack_tag" do
138
138
  expected_error_message = \
139
139
  "You can only call prepend_javascript_pack_tag before javascript_pack_tag helper. " +
140
140
  "Please refer to https://github.com/shakacode/shakapacker/blob/master/README.md#view-helper-append_javascript_pack_tag-prepend_javascript_pack_tag-and-append_stylesheet_pack_tag for the usage guide"
@@ -145,7 +145,7 @@ module ActionView::TestCase::Behavior
145
145
  }.to raise_error(expected_error_message)
146
146
  end
147
147
 
148
- it "#javascript_pack_tag generates correct tags by passing `defer: true`" do
148
+ it "#javascript_pack_tag generates the correct tags when passing `defer: true`" do
149
149
  expected = <<~HTML.chomp
150
150
  <script src="/packs/vendors~application~bootstrap-c20632e7baf2c81200d3.chunk.js" defer="defer"></script>
151
151
  <script src="/packs/vendors~application-e55f2aae30c07fb6d82a.chunk.js" defer="defer"></script>
@@ -155,7 +155,7 @@ module ActionView::TestCase::Behavior
155
155
  expect(javascript_pack_tag("application", defer: true)).to eq expected
156
156
  end
157
157
 
158
- it "#javascript_pack_tag generates correct tags by passing symbol" do
158
+ it "#javascript_pack_tag generates the correct tags when passing a symbol" do
159
159
  expected = <<~HTML.chomp
160
160
  <script src="/packs/vendors~application~bootstrap-c20632e7baf2c81200d3.chunk.js" defer="defer"></script>
161
161
  <script src="/packs/vendors~application-e55f2aae30c07fb6d82a.chunk.js" defer="defer"></script>
@@ -175,7 +175,7 @@ module ActionView::TestCase::Behavior
175
175
  }.to raise_error(expected_error_message)
176
176
  end
177
177
 
178
- it "#stylesheet_pack_tag generates correct link tag with string arguments" do
178
+ it "#stylesheet_pack_tag generates the correct link tag with string arguments" do
179
179
  expected = (application_stylesheet_chunks + hello_stimulus_stylesheet_chunks)
180
180
  .uniq
181
181
  .map { |chunk| stylesheet_link_tag(chunk) }
@@ -184,7 +184,7 @@ module ActionView::TestCase::Behavior
184
184
  expect(stylesheet_pack_tag("application", "hello_stimulus")).to eq expected
185
185
  end
186
186
 
187
- it "#stylesheet_pack_tag generates correct link tag with symbol arguments" do
187
+ it "#stylesheet_pack_tag generates the correct link tag with symbol arguments" do
188
188
  expected = (application_stylesheet_chunks + hello_stimulus_stylesheet_chunks)
189
189
  .uniq
190
190
  .map { |chunk| stylesheet_link_tag(chunk) }
@@ -193,7 +193,7 @@ module ActionView::TestCase::Behavior
193
193
  expect(stylesheet_pack_tag(:application, :hello_stimulus)).to eq expected
194
194
  end
195
195
 
196
- it "#stylesheet_pack_tag generates correct link tag with mixed arguments" do
196
+ it "#stylesheet_pack_tag generates the correct link tag with mixed arguments" do
197
197
  expected = (application_stylesheet_chunks)
198
198
  .map { |chunk| stylesheet_link_tag(chunk, media: "all") }
199
199
  .join("\n")
@@ -215,7 +215,7 @@ module ActionView::TestCase::Behavior
215
215
  }.to_not raise_error
216
216
  end
217
217
 
218
- it "#stylesheet_pack_tag appends" do
218
+ it "#stylesheet_pack_tag appends tags" do
219
219
  append_stylesheet_pack_tag(:hello_stimulus)
220
220
 
221
221
  expect(stylesheet_pack_tag(:application)).to eq \
@@ -230,7 +230,7 @@ module ActionView::TestCase::Behavior
230
230
  (application_stylesheet_chunks + hello_stimulus_stylesheet_chunks).uniq.map { |chunk| stylesheet_link_tag(chunk) }.join("\n")
231
231
  end
232
232
 
233
- it "#stylesheet_pack_tag supports multiple invocations with different media attr" do
233
+ it "#stylesheet_pack_tag supports multiple invocations with different media attr values" do
234
234
  app_style = stylesheet_pack_tag(:application)
235
235
  app_style_with_media = stylesheet_pack_tag(:application, media: "print")
236
236
  hello_stimulus_style_with_media = stylesheet_pack_tag(:hello_stimulus, media: "all")
@@ -13,19 +13,19 @@ describe "Webpacker::Instance" do
13
13
  Webpacker.instance = Webpacker::Instance.new
14
14
  end
15
15
 
16
- it "uses default config path if no env variable defined" do
16
+ it "uses the default config path if no env variable defined" do
17
17
  actual_config_path = Rails.root.join("config/webpacker.yml")
18
18
  expected_config_path = Webpacker.config.config_path
19
19
 
20
20
  expect(expected_config_path).to eq(actual_config_path)
21
21
  end
22
22
 
23
- it "uses WEBPACKER_CONFIG env variable for config file" do
23
+ it "uses the WEBPACKER_CONFIG env variable for the config file path" do
24
24
  ENV["WEBPACKER_CONFIG"] = "/some/random/path.yml"
25
25
 
26
26
  actual_config_path = "/some/random/path.yml"
27
27
  expected_config_path = Webpacker.config.config_path.to_s
28
28
 
29
- expect(Webpacker.config.config_path.to_s).to eq("/some/random/path.yml")
29
+ expect(expected_config_path).to eq(actual_config_path)
30
30
  end
31
31
  end
@@ -3,7 +3,7 @@ require_relative "spec_helper_initializer"
3
3
  describe "Webpacker::Manifest" do
4
4
  let(:manifest_path) { File.expand_path File.join(File.dirname(__FILE__), "webpacker_test_app/public/packs", "manifest.json").to_s }
5
5
 
6
- it "#lookup! throws exception for a non-existing asset file" do
6
+ it "#lookup! raises an exception for a non-existing asset file" do
7
7
  asset_file = "calendar.js"
8
8
  expected_error_message = "Shakapacker can't find #{asset_file} in #{manifest_path}"
9
9
 
@@ -14,7 +14,7 @@ describe "Webpacker::Manifest" do
14
14
  }.to raise_error(Webpacker::Manifest::MissingEntryError, /#{expected_error_message}/)
15
15
  end
16
16
 
17
- it "#lookup! throws exception for a non-existing asset file with type and without extension" do
17
+ it "#lookup! raises an exception for a non-existing asset file with type and without an extension" do
18
18
  asset_file = "calendar"
19
19
  expected_error_message = "Shakapacker can't find #{asset_file}.js in #{manifest_path}"
20
20
 
@@ -25,57 +25,57 @@ describe "Webpacker::Manifest" do
25
25
  }.to raise_error(Webpacker::Manifest::MissingEntryError, /#{expected_error_message}/)
26
26
  end
27
27
 
28
- it "#lookup! returns path to bundled bootstrap.js" do
28
+ it "#lookup! returns the path to the bundled bootstrap.js" do
29
29
  actual = Webpacker.manifest.lookup!("bootstrap.js")
30
30
  expected = "/packs/bootstrap-300631c4f0e0f9c865bc.js"
31
31
 
32
32
  expect(actual).to eq expected
33
33
  end
34
34
 
35
- it "#lookup_pack_with_chunks! returns array of path to bundled bootstrap with type of javascript" do
35
+ it "#lookup_pack_with_chunks! returns an array of paths to the bundled bootstrap of type javascript" do
36
36
  actual = Webpacker.manifest.lookup_pack_with_chunks!("bootstrap", type: :javascript)
37
37
  expected = ["/packs/bootstrap-300631c4f0e0f9c865bc.js"]
38
38
 
39
39
  expect(actual).to eq expected
40
40
  end
41
41
 
42
- it "#lookup_with_chunks! returns array of path to bundled bootstrap.js with type of javascript" do
42
+ it "#lookup_with_chunks! returns an array of paths to the bundled bootstrap.js of type javascript" do
43
43
  actual = Webpacker.manifest.lookup_pack_with_chunks!("bootstrap.js", type: :javascript)
44
44
  expected = ["/packs/bootstrap-300631c4f0e0f9c865bc.js"]
45
45
 
46
46
  expect(actual).to eq expected
47
47
  end
48
48
 
49
- it "#lookup_with_chunks! returns array of path to bundled 'print/application' without extension and in a sub-directory" do
49
+ it "#lookup_with_chunks! returns an array of paths to the bundled 'print/application' without an extension and in a sub-directory" do
50
50
  actual = Webpacker.manifest.lookup_pack_with_chunks!("print/application", type: :css)
51
51
  expected = ["/packs/print/application-983b6c164a47f7ed49cd.css"]
52
52
 
53
53
  expect(actual).to eq expected
54
54
  end
55
55
 
56
- it "#lookup_with_chunks! returns array of path to bundled 'print/application.css' in a sub-directory" do
56
+ it "#lookup_with_chunks! returns an array of paths to the bundled 'print/application.css' in a sub-directory" do
57
57
  actual = Webpacker.manifest.lookup_pack_with_chunks!("print/application.css", type: :css)
58
58
  expected = ["/packs/print/application-983b6c164a47f7ed49cd.css"]
59
59
 
60
60
  expect(actual).to eq expected
61
61
  end
62
62
 
63
- it "#lookup returns nil for non-existing asset file" do
63
+ it "#lookup returns nil for non-existing asset files" do
64
64
  expect(Webpacker.manifest.lookup("foo.js")).to be nil
65
65
  end
66
66
 
67
- it "#lookup_pack_with_chunks returns nil for non-existing asset file" do
67
+ it "#lookup_pack_with_chunks returns nil for non-existing asset files" do
68
68
  expect(Webpacker.manifest.lookup_pack_with_chunks("foo.js")).to be nil
69
69
  end
70
70
 
71
- it "#lookup returns path for bootstrap.js" do
71
+ it "#lookup returns the path for bootstrap.js" do
72
72
  actual = Webpacker.manifest.lookup("bootstrap.js")
73
73
  expected = "/packs/bootstrap-300631c4f0e0f9c865bc.js"
74
74
 
75
75
  expect(actual).to eq expected
76
76
  end
77
77
 
78
- it "#lookup_pack_with_chunks! throws exception for a non-existing asset file" do
78
+ it "#lookup_pack_with_chunks! raises an exception for non-existing asset files" do
79
79
  asset_file = "calendar"
80
80
 
81
81
  expected_error_message = "Shakapacker can't find #{asset_file}.js in #{manifest_path}"
@@ -87,7 +87,7 @@ describe "Webpacker::Manifest" do
87
87
  }.to raise_error(Shakapacker::Manifest::MissingEntryError, /#{expected_error_message}/)
88
88
  end
89
89
 
90
- it "#lookup_pack_with_chunks! returns array of paths to bundled js files with 'application' in their name" do
90
+ it "#lookup_pack_with_chunks! returns an array of paths to bundled js files with 'application' in their name" do
91
91
  actual_application_entrypoints = Webpacker.manifest.lookup_pack_with_chunks!("application", type: :javascript)
92
92
  expected_application_entrypoints = [
93
93
  "/packs/vendors~application~bootstrap-c20632e7baf2c81200d3.chunk.js",
@@ -5,7 +5,7 @@ describe "Webpacker::MtimeStrategy" do
5
5
  let(:manifest_timestamp) { Time.parse("2021-01-01 12:34:56 UTC") }
6
6
 
7
7
  describe "#fresh?" do
8
- it "returns false when manifest is missing" do
8
+ it "returns false when the manifest is missing" do
9
9
  latest_timestamp = manifest_timestamp + 3600
10
10
 
11
11
  with_stubs(latest_timestamp: latest_timestamp.to_i, manifest_exists: false) do
@@ -13,7 +13,7 @@ describe "Webpacker::MtimeStrategy" do
13
13
  end
14
14
  end
15
15
 
16
- it "returns false when manifest is older" do
16
+ it "returns false when the manifest is older" do
17
17
  latest_timestamp = manifest_timestamp + 3600
18
18
 
19
19
  with_stubs(latest_timestamp: latest_timestamp.to_i) do
@@ -21,7 +21,7 @@ describe "Webpacker::MtimeStrategy" do
21
21
  end
22
22
  end
23
23
 
24
- it "returns true when manifest is new" do
24
+ it "returns true when the manifest is new" do
25
25
  latest_timestamp = manifest_timestamp - 3600
26
26
 
27
27
  with_stubs(latest_timestamp: latest_timestamp.to_i) do
@@ -1,10 +1,11 @@
1
1
  require_relative "spec_helper_initializer"
2
2
 
3
3
  describe "RakeTasks" do
4
- let(:test_app_path) { File.expand_path("webpacker_test_app", __dir__) }
4
+ TEST_APP_PATH = File.expand_path("webpacker_test_app", __dir__)
5
5
 
6
6
  it "`rake -T` lists Webpacker tasks" do
7
- output = Dir.chdir(test_app_path) { `rake -T` }
7
+ output = Dir.chdir(TEST_APP_PATH) { `rake -T` }
8
+
8
9
  expect(output).to match /webpacker .+DEPRECATED/
9
10
  expect(output).to match /webpacker:check_binstubs.+DEPRECATED/
10
11
  expect(output).to match /webpacker:check_node.+DEPRECATED/
@@ -17,19 +18,22 @@ describe "RakeTasks" do
17
18
  end
18
19
 
19
20
  it "`webpacker:check_binstubs` doesn't get 'webpack binstub not found' error" do
20
- output = Dir.chdir(test_app_path) { `rake webpacker:check_binstubs 2>&1` }
21
+ output = Dir.chdir(TEST_APP_PATH) { `rake webpacker:check_binstubs 2>&1` }
22
+
21
23
  expect(output).to_not include "webpack binstub not found."
22
24
  expect(output).to include "DEPRECATION"
23
25
  end
24
26
 
25
27
  it "`webpacker:check_node` doesn't get 'webpacker requires Node.js' error" do
26
- output = Dir.chdir(test_app_path) { `rake webpacker:check_node 2>&1` }
28
+ output = Dir.chdir(TEST_APP_PATH) { `rake webpacker:check_node 2>&1` }
29
+
27
30
  expect(output).to_not include "Shakapacker requires Node.js"
28
31
  expect(output).to include "DEPRECATION"
29
32
  end
30
33
 
31
34
  it "`webpacker:check_yarn` doesn't get error related to yarn" do
32
- output = Dir.chdir(test_app_path) { `rake webpacker:check_yarn 2>&1` }
35
+ output = Dir.chdir(TEST_APP_PATH) { `rake webpacker:check_yarn 2>&1` }
36
+
33
37
  expect(output).to_not include "Yarn not installed"
34
38
  expect(output).to_not include "Shakapacker requires Yarn"
35
39
  expect(output).to include "DEPRECATION"
@@ -13,44 +13,40 @@ describe "WebpackRunner" do
13
13
  ENV["RAILS_ENV"] = @original_rails_env
14
14
  end
15
15
 
16
- it "runs cmd via node_modules" do
16
+ let(:test_app_path) { File.expand_path("./webpacker_test_app", __dir__) }
17
+
18
+ it "supports running via node_modules" do
17
19
  cmd = ["#{test_app_path}/node_modules/.bin/webpack", "--config", "#{test_app_path}/config/webpack/webpack.config.js"]
18
20
 
19
21
  verify_command(cmd, use_node_modules: true)
20
22
  end
21
23
 
22
- it "runs cmd via yarn" do
24
+ it "supports running via yarn" do
23
25
  cmd = ["yarn", "webpack", "--config", "#{test_app_path}/config/webpack/webpack.config.js"]
24
26
 
25
27
  verify_command(cmd, use_node_modules: false)
26
28
  end
27
29
 
28
- it "runs cmd argv" do
30
+ it "passes on arguments" do
29
31
  cmd = ["#{test_app_path}/node_modules/.bin/webpack", "--config", "#{test_app_path}/config/webpack/webpack.config.js", "--watch"]
30
32
 
31
33
  verify_command(cmd, argv: ["--watch"])
32
34
  end
33
35
 
34
36
  private
35
- def test_app_path
36
- File.expand_path("webpacker_test_app", __dir__)
37
- end
38
37
 
39
38
  def verify_command(cmd, use_node_modules: true, argv: [])
40
- cwd = Dir.pwd
41
- Dir.chdir(test_app_path)
42
-
43
- klass = Webpacker::WebpackRunner
44
- instance = klass.new(argv)
39
+ Dir.chdir(test_app_path) do
40
+ klass = Webpacker::WebpackRunner
41
+ instance = klass.new(argv)
45
42
 
46
- allow(klass).to receive(:new).and_return(instance)
47
- allow(instance).to receive(:node_modules_bin_exist?).and_return(use_node_modules)
48
- allow(Kernel).to receive(:exec)
43
+ allow(klass).to receive(:new).and_return(instance)
44
+ allow(instance).to receive(:node_modules_bin_exist?).and_return(use_node_modules)
45
+ allow(Kernel).to receive(:exec)
49
46
 
50
- klass.run(argv)
47
+ klass.run(argv)
51
48
 
52
- expect(Kernel).to have_received(:exec).with(Webpacker::Compiler.env, *cmd)
53
- ensure
54
- Dir.chdir(cwd)
49
+ expect(Kernel).to have_received(:exec).with(Webpacker::Compiler.env, *cmd)
50
+ end
55
51
  end
56
52
  end
@@ -13,6 +13,6 @@ const ignoreWarningsConfig = {
13
13
  };
14
14
  // Copy the object using merge b/c the baseClientWebpackConfig and commonOptions are mutable globals
15
15
  // const commonWebpackConfig = () => (merge({}, baseClientWebpackConfig, commonOptions))
16
- const commonWebpackConfig = () => (merge({}, generateWebpackConfig(), commonOptions, ignoreWarningsConfig))
16
+ const commonWebpackConfig = () => generateWebpackConfig(merge(commonOptions, ignoreWarningsConfig))
17
17
 
18
18
  module.exports = commonWebpackConfig
@@ -0,0 +1,116 @@
1
+ lockfileVersion: 5.4
2
+
3
+ specifiers:
4
+ right-pad: ^1.0.1
5
+ shakapacker: 6.1.0-beta.0
6
+
7
+ dependencies:
8
+ shakapacker: 6.1.0-beta.0
9
+
10
+ devDependencies:
11
+ right-pad: 1.0.1
12
+
13
+ packages:
14
+
15
+ /argparse/2.0.1:
16
+ resolution: {integrity: sha512-8+9WqebbFzpX9OR+Wa6O29asIogeRMzcGtAINdpMHHyAg10f05aSFVBbcEqGf/PXw1EjAZ+q2/bEBg3DvurK3Q==}
17
+ dev: false
18
+
19
+ /balanced-match/1.0.2:
20
+ resolution: {integrity: sha512-3oSeUO0TMV67hN1AmbXsK4yaqU7tjiHlbxRDZOpH0KW9+CeX4bRAaX0Anxt0tx2MrpRpWwQaPwIlISEJhYU5Pw==}
21
+ dev: false
22
+
23
+ /brace-expansion/1.1.11:
24
+ resolution: {integrity: sha512-iCuPHDFgrHX7H2vEI/5xpz07zSHB00TpugqhmYtVmMO6518mCuRMoOYFldEBl0g187ufozdaHgWKcYFb61qGiA==}
25
+ dependencies:
26
+ balanced-match: 1.0.2
27
+ concat-map: 0.0.1
28
+ dev: false
29
+
30
+ /concat-map/0.0.1:
31
+ resolution: {integrity: sha512-/Srv4dswyQNBfohGpz9o6Yb3Gz3SrUDqBH5rTuhGR7ahtlbYKnVxw2bCFMRljaA7EXHaXZ8wsHdodFvbkhKmqg==}
32
+ dev: false
33
+
34
+ /fs.realpath/1.0.0:
35
+ resolution: {integrity: sha512-OO0pH2lK6a0hZnAdau5ItzHPI6pUlvI7jMVnxUQRtw4owF2wk8lOSabtGDCTP4Ggrg2MbGnWO9X8K1t4+fGMDw==}
36
+ dev: false
37
+
38
+ /glob/7.2.3:
39
+ resolution: {integrity: sha512-nFR0zLpU2YCaRxwoCJvL6UvCH2JFyFVIvwTLsIf21AuHlMskA1hhTdk+LlYJtOlYt9v6dvszD2BGRqBL+iQK9Q==}
40
+ dependencies:
41
+ fs.realpath: 1.0.0
42
+ inflight: 1.0.6
43
+ inherits: 2.0.4
44
+ minimatch: 3.1.2
45
+ once: 1.4.0
46
+ path-is-absolute: 1.0.1
47
+ dev: false
48
+
49
+ /inflight/1.0.6:
50
+ resolution: {integrity: sha512-k92I/b08q4wvFscXCLvqfsHCrjrF7yiXsQuIVvVE7N82W3+aqpzuUdBbfhWcy/FZR3/4IgflMgKLOsvPDrGCJA==}
51
+ dependencies:
52
+ once: 1.4.0
53
+ wrappy: 1.0.2
54
+ dev: false
55
+
56
+ /inherits/2.0.4:
57
+ resolution: {integrity: sha512-k/vGaX4/Yla3WzyMCvTQOXYeIHvqOKtnqBduzTHpzpQZzAskKMhZ2K+EnBiSM9zGSoIFeMpXKxa4dYeZIQqewQ==}
58
+ dev: false
59
+
60
+ /js-yaml/4.1.0:
61
+ resolution: {integrity: sha512-wpxZs9NoxZaJESJGIZTyDEaYpl0FKSA+FB9aJiyemKhMwkxQg63h4T1KJgUGHpTqPDNRcmmYLugrRjJlBtWvRA==}
62
+ hasBin: true
63
+ dependencies:
64
+ argparse: 2.0.1
65
+ dev: false
66
+
67
+ /minimatch/3.1.2:
68
+ resolution: {integrity: sha512-J7p63hRiAjw1NDEww1W7i37+ByIrOWO5XQQAzZ3VOcL0PNybwpfmV/N05zFAzwQ9USyEcX6t3UO+K5aqBQOIHw==}
69
+ dependencies:
70
+ brace-expansion: 1.1.11
71
+ dev: false
72
+
73
+ /once/1.4.0:
74
+ resolution: {integrity: sha512-lNaJgI+2Q5URQBkccEKHTQOPaXdUxnZZElQTZY0MFUAuaEqe1E+Nyvgdz/aIyNi6Z9MzO5dv1H8n58/GELp3+w==}
75
+ dependencies:
76
+ wrappy: 1.0.2
77
+ dev: false
78
+
79
+ /path-complete-extname/1.0.0:
80
+ resolution: {integrity: sha512-CVjiWcMRdGU8ubs08YQVzhutOR5DEfO97ipRIlOGMK5Bek5nQySknBpuxVAVJ36hseTNs+vdIcv57ZrWxH7zvg==}
81
+ dev: false
82
+
83
+ /path-is-absolute/1.0.1:
84
+ resolution: {integrity: sha512-AVbw3UJ2e9bq64vSaS9Am0fje1Pa8pbGqTTsmXfaIiMpnr5DlDhfJOuLj9Sf95ZPVDAUerDfEk88MPmPe7UCQg==}
85
+ engines: {node: '>=0.10.0'}
86
+ dev: false
87
+
88
+ /right-pad/1.0.1:
89
+ resolution: {integrity: sha512-bYBjgxmkvTAfgIYy328fmkwhp39v8lwVgWhhrzxPV3yHtcSqyYKe9/XOhvW48UFjATg3VuJbpsp5822ACNvkmw==}
90
+ engines: {node: '>= 0.10'}
91
+ dev: true
92
+
93
+ /shakapacker/6.1.0-beta.0:
94
+ resolution: {integrity: sha512-SakBrvrL1x4Y/H1pc40P+rgQDIv54wnuGVflClHEIzCbPI6uQ7ehlgiropXjVkRX9495yCGGgqnXeEAihdJ4dg==}
95
+ engines: {node: ^12.13.0 || ^14 || >=16, yarn: '>=1 <4'}
96
+ peerDependencies:
97
+ '@babel/core': ^7.15.5
98
+ '@babel/plugin-transform-runtime': ^7.15.0
99
+ '@babel/preset-env': ^7.15.6
100
+ '@babel/runtime': ^7.15.4
101
+ babel-loader: ^8.2.2
102
+ compression-webpack-plugin: ^9.0.0
103
+ terser-webpack-plugin: ^5.2.4
104
+ webpack: ^5.53.0
105
+ webpack-assets-manifest: ^5.0.6
106
+ webpack-cli: ^4.8.0
107
+ webpack-merge: ^5.8.0
108
+ dependencies:
109
+ glob: 7.2.3
110
+ js-yaml: 4.1.0
111
+ path-complete-extname: 1.0.0
112
+ dev: false
113
+
114
+ /wrappy/1.0.2:
115
+ resolution: {integrity: sha512-l4Sp/DRseor9wL6EvV2+TuQn63dMkPjZ/sp9XkghTEbV9KlPS1xUsZ3u7/IQO4wxtcFB4bgpQPRcR3QCvezPcQ==}
116
+ dev: false