shakapacker 7.3.0.beta.1 → 8.0.0.rc.2

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.
Files changed (231) hide show
  1. checksums.yaml +4 -4
  2. data/.eslintignore +1 -1
  3. data/.eslintrc.js +29 -8
  4. data/.github/PULL_REQUEST_TEMPLATE.md +10 -3
  5. data/.github/workflows/dummy.yml +6 -1
  6. data/.github/workflows/generator.yml +14 -18
  7. data/.github/workflows/node.yml +56 -0
  8. data/.github/workflows/ruby.yml +29 -17
  9. data/.node-version +1 -1
  10. data/.rubocop.yml +1 -0
  11. data/CHANGELOG.md +56 -5
  12. data/README.md +101 -48
  13. data/Rakefile +1 -7
  14. data/docs/customizing_babel_config.md +2 -2
  15. data/docs/deployment.md +13 -6
  16. data/docs/react.md +7 -13
  17. data/docs/troubleshooting.md +4 -4
  18. data/docs/using_esbuild_loader.md +1 -1
  19. data/docs/using_swc_loader.md +1 -1
  20. data/docs/v6_upgrade.md +1 -1
  21. data/docs/v8_upgrade.md +148 -0
  22. data/gemfiles/Gemfile-rails.7.1.x +12 -0
  23. data/jest.config.js +4 -0
  24. data/lib/install/config/shakapacker.yml +2 -2
  25. data/lib/install/template.rb +36 -30
  26. data/lib/shakapacker/base_strategy.rb +2 -1
  27. data/lib/shakapacker/compiler.rb +6 -21
  28. data/lib/shakapacker/configuration.rb +2 -46
  29. data/lib/shakapacker/deprecation_helper.rb +0 -78
  30. data/lib/shakapacker/dev_server.rb +1 -16
  31. data/lib/shakapacker/dev_server_runner.rb +2 -21
  32. data/lib/shakapacker/env.rb +1 -1
  33. data/lib/shakapacker/helper.rb +3 -3
  34. data/lib/shakapacker/instance.rb +1 -3
  35. data/lib/shakapacker/manifest.rb +1 -1
  36. data/lib/shakapacker/railtie.rb +7 -0
  37. data/lib/shakapacker/runner.rb +4 -18
  38. data/lib/shakapacker/utils/manager.rb +58 -0
  39. data/lib/shakapacker/utils/misc.rb +0 -12
  40. data/lib/shakapacker/version.rb +1 -1
  41. data/lib/shakapacker/version_checker.rb +9 -30
  42. data/lib/shakapacker/webpack_runner.rb +2 -21
  43. data/lib/shakapacker.rb +0 -2
  44. data/lib/tasks/shakapacker/check_binstubs.rake +12 -26
  45. data/lib/tasks/shakapacker/check_manager.rake +3 -8
  46. data/lib/tasks/shakapacker/info.rake +6 -15
  47. data/package/babel/preset.js +15 -15
  48. data/package/config.js +15 -19
  49. data/package/dev_server.js +4 -4
  50. data/package/env.js +19 -17
  51. data/package/environments/base.js +41 -24
  52. data/package/environments/development.js +6 -6
  53. data/package/environments/production.js +16 -16
  54. data/package/environments/test.js +1 -1
  55. data/package/esbuild/index.js +6 -6
  56. data/package/index.d.ts +0 -2
  57. data/package/index.js +17 -46
  58. data/package/rules/babel.js +6 -8
  59. data/package/rules/coffee.js +2 -2
  60. data/package/rules/css.js +1 -1
  61. data/package/rules/erb.js +4 -4
  62. data/package/rules/esbuild.js +5 -7
  63. data/package/rules/file.js +14 -7
  64. data/package/rules/index.js +11 -11
  65. data/package/rules/jscommon.js +8 -5
  66. data/package/rules/less.js +10 -9
  67. data/package/rules/raw.js +1 -1
  68. data/package/rules/sass.js +4 -4
  69. data/package/rules/stylus.js +12 -7
  70. data/package/rules/swc.js +5 -7
  71. data/package/swc/index.js +10 -10
  72. data/package/utils/configPath.js +3 -18
  73. data/package/utils/defaultConfigPath.js +1 -1
  74. data/package/utils/{get_style_rule.js → getStyleRule.js} +6 -6
  75. data/package/utils/helpers.js +2 -43
  76. data/package/utils/inliningCss.js +4 -3
  77. data/package/utils/snakeToCamelCase.js +5 -0
  78. data/package/webpackDevServerConfig.js +28 -25
  79. data/package.json +12 -18
  80. data/prettier.config.js +4 -0
  81. data/shakapacker.gemspec +1 -1
  82. data/spec/dummy/app/javascript/packs/application.js +1 -1
  83. data/spec/dummy/config/application.rb +3 -0
  84. data/spec/dummy/config/initializers/react_on_rails.rb +2 -2
  85. data/spec/dummy/config/shakapacker.yml +3 -4
  86. data/spec/dummy/config/webpack/commonWebpackConfig.js +0 -1
  87. data/spec/dummy/config/webpack/webpack.config.js +1 -1
  88. data/spec/dummy/package.json +2 -1
  89. data/spec/dummy/yarn.lock +2 -3
  90. data/spec/fixtures/github_url_package-lock.v1.json +1 -1
  91. data/spec/fixtures/github_url_package-lock.v2.json +2 -2
  92. data/spec/fixtures/github_url_package.json +1 -1
  93. data/spec/fixtures/github_url_pnpm-lock.v7.yaml +1 -1
  94. data/spec/fixtures/github_url_pnpm-lock.v8.yaml +1 -1
  95. data/spec/fixtures/github_url_yarn.v1.lock +1 -1
  96. data/spec/fixtures/github_url_yarn.v2.lock +2 -2
  97. data/spec/generator_specs/e2e_template/template.rb +15 -28
  98. data/spec/generator_specs/generator_spec.rb +6 -136
  99. data/spec/mounted_app/test/dummy/config/webpacker.yml +0 -1
  100. data/spec/shakapacker/compiler_spec.rb +1 -3
  101. data/spec/shakapacker/configuration_spec.rb +4 -56
  102. data/spec/shakapacker/dev_server_runner_spec.rb +19 -102
  103. data/spec/shakapacker/dev_server_spec.rb +1 -16
  104. data/spec/shakapacker/engine_rake_tasks_spec.rb +1 -16
  105. data/spec/shakapacker/helper_spec.rb +3 -3
  106. data/spec/shakapacker/instance_spec.rb +1 -3
  107. data/spec/shakapacker/rake_tasks_spec.rb +2 -14
  108. data/spec/shakapacker/shakapacker_spec.rb +0 -1
  109. data/spec/shakapacker/test_app/config/shakapacker_css_extract_ignore_order_warnings.yml +0 -1
  110. data/spec/shakapacker/test_app/config/shakapacker_manifest_path.yml +0 -1
  111. data/spec/shakapacker/test_app/config/shakapacker_nested_entries.yml +0 -1
  112. data/spec/shakapacker/test_app/config/shakapacker_other_location.yml +0 -1
  113. data/spec/shakapacker/test_app/package.json +2 -1
  114. data/spec/shakapacker/utils_manager_spec.rb +125 -0
  115. data/spec/shakapacker/version_checker_spec.rb +5 -5
  116. data/spec/shakapacker/webpack_runner_spec.rb +19 -28
  117. data/spec/support/package_json_helpers.rb +7 -4
  118. data/test/helpers.js +67 -0
  119. data/test/package/config.test.js +50 -0
  120. data/test/package/dev_server.test.js +44 -0
  121. data/test/package/development.test.js +43 -0
  122. data/test/package/env.test.js +57 -0
  123. data/test/package/environments/base.test.js +105 -0
  124. data/test/package/environments/development.test.js +50 -0
  125. data/test/package/environments/production.test.js +106 -0
  126. data/test/package/index.test.js +45 -0
  127. data/test/package/production.test.js +32 -0
  128. data/test/package/rules/babel.test.js +58 -0
  129. data/test/package/rules/esbuild.test.js +59 -0
  130. data/test/package/rules/file.test.js +81 -0
  131. data/test/package/rules/index.test.js +7 -0
  132. data/test/package/rules/raw.test.js +12 -0
  133. data/test/package/rules/swc.test.js +59 -0
  134. data/test/package/staging.test.js +31 -0
  135. data/test/package/test.test.js +28 -0
  136. data/yarn.lock +1278 -421
  137. metadata +50 -100
  138. data/.github/workflows/jest.yml +0 -33
  139. data/.github/workflows/js-lint.yml +0 -33
  140. data/.github/workflows/rubocop.yml +0 -28
  141. data/.github/workflows/ruby-backward-compatibility.yml +0 -51
  142. data/lib/install/package.json +0 -15
  143. data/lib/tasks/shakapacker/check_yarn.rake +0 -34
  144. data/lib/tasks/shakapacker/yarn_install.rake +0 -24
  145. data/lib/tasks/webpacker/binstubs.rake +0 -9
  146. data/lib/tasks/webpacker/check_binstubs.rake +0 -9
  147. data/lib/tasks/webpacker/check_node.rake +0 -9
  148. data/lib/tasks/webpacker/check_yarn.rake +0 -9
  149. data/lib/tasks/webpacker/clean.rake +0 -9
  150. data/lib/tasks/webpacker/clobber.rake +0 -11
  151. data/lib/tasks/webpacker/compile.rake +0 -9
  152. data/lib/tasks/webpacker/info.rake +0 -9
  153. data/lib/tasks/webpacker/install.rake +0 -9
  154. data/lib/tasks/webpacker/verify_config.rake +0 -9
  155. data/lib/tasks/webpacker/verify_install.rake +0 -9
  156. data/lib/tasks/webpacker/yarn_install.rake +0 -9
  157. data/lib/tasks/webpacker.rake +0 -20
  158. data/lib/webpacker/dev_server_runner.rb +0 -9
  159. data/lib/webpacker/webpack_runner.rb +0 -9
  160. data/lib/webpacker.rb +0 -4
  161. data/package/__tests__/config-bc.js +0 -27
  162. data/package/__tests__/config.js +0 -46
  163. data/package/__tests__/dev_server-bc.js +0 -46
  164. data/package/__tests__/dev_server.js +0 -46
  165. data/package/__tests__/development-bc.js +0 -66
  166. data/package/__tests__/development.js +0 -66
  167. data/package/__tests__/env-bc.js +0 -59
  168. data/package/__tests__/env.js +0 -59
  169. data/package/__tests__/index-bc.js +0 -22
  170. data/package/__tests__/index.js +0 -46
  171. data/package/__tests__/production-bc.js +0 -51
  172. data/package/__tests__/production.js +0 -51
  173. data/package/__tests__/staging-bc.js +0 -53
  174. data/package/__tests__/staging.js +0 -53
  175. data/package/__tests__/test-bc.js +0 -43
  176. data/package/__tests__/test.js +0 -43
  177. data/package/environments/__tests__/base-bc.js +0 -107
  178. data/package/environments/__tests__/base.js +0 -107
  179. data/package/environments/__tests__/development.js +0 -53
  180. data/package/environments/__tests__/production.js +0 -92
  181. data/package/rules/__tests__/__utils__/webpack.js +0 -50
  182. data/package/rules/__tests__/babel.js +0 -63
  183. data/package/rules/__tests__/esbuild.js +0 -64
  184. data/package/rules/__tests__/file.js +0 -79
  185. data/package/rules/__tests__/index.js +0 -7
  186. data/package/rules/__tests__/raw.js +0 -18
  187. data/package/rules/__tests__/swc.js +0 -63
  188. data/package/utils/snakeToCamelCase +0 -7
  189. data/spec/backward_compatibility_specs/command_spec.rb +0 -116
  190. data/spec/backward_compatibility_specs/compiler_spec.rb +0 -59
  191. data/spec/backward_compatibility_specs/compiler_strategy_spec.rb +0 -24
  192. data/spec/backward_compatibility_specs/configuration_spec.rb +0 -294
  193. data/spec/backward_compatibility_specs/dev_server_runner_spec.rb +0 -206
  194. data/spec/backward_compatibility_specs/dev_server_spec.rb +0 -47
  195. data/spec/backward_compatibility_specs/digest_strategy_spec.rb +0 -38
  196. data/spec/backward_compatibility_specs/engine_rake_tasks_spec.rb +0 -67
  197. data/spec/backward_compatibility_specs/env_spec.rb +0 -23
  198. data/spec/backward_compatibility_specs/helper_spec.rb +0 -243
  199. data/spec/backward_compatibility_specs/instance_spec.rb +0 -31
  200. data/spec/backward_compatibility_specs/manifest_spec.rb +0 -100
  201. data/spec/backward_compatibility_specs/mtime_strategy_spec.rb +0 -55
  202. data/spec/backward_compatibility_specs/rake_tasks_spec.rb +0 -41
  203. data/spec/backward_compatibility_specs/spec_helper_initializer.rb +0 -24
  204. data/spec/backward_compatibility_specs/webpack_runner_spec.rb +0 -86
  205. data/spec/backward_compatibility_specs/webpacker_spec.rb +0 -41
  206. data/spec/backward_compatibility_specs/webpacker_test_app/.gitignore +0 -2
  207. data/spec/backward_compatibility_specs/webpacker_test_app/Rakefile +0 -3
  208. data/spec/backward_compatibility_specs/webpacker_test_app/app/packs/entrypoints/application.js +0 -10
  209. data/spec/backward_compatibility_specs/webpacker_test_app/app/packs/entrypoints/generated/something.js +0 -2
  210. data/spec/backward_compatibility_specs/webpacker_test_app/app/packs/entrypoints/multi_entry.css +0 -4
  211. data/spec/backward_compatibility_specs/webpacker_test_app/app/packs/entrypoints/multi_entry.js +0 -4
  212. data/spec/backward_compatibility_specs/webpacker_test_app/bin/webpacker +0 -13
  213. data/spec/backward_compatibility_specs/webpacker_test_app/bin/webpacker-dev-server +0 -13
  214. data/spec/backward_compatibility_specs/webpacker_test_app/config/application.rb +0 -11
  215. data/spec/backward_compatibility_specs/webpacker_test_app/config/environment.rb +0 -4
  216. data/spec/backward_compatibility_specs/webpacker_test_app/config/initializers/inspect_autoload_paths.rb +0 -1
  217. data/spec/backward_compatibility_specs/webpacker_test_app/config/webpack/webpack.config.js +0 -0
  218. data/spec/backward_compatibility_specs/webpacker_test_app/config/webpacker.yml +0 -83
  219. data/spec/backward_compatibility_specs/webpacker_test_app/config/webpacker_css_extract_ignore_order_warnings.yml +0 -84
  220. data/spec/backward_compatibility_specs/webpacker_test_app/config/webpacker_defaults_fallback.yml +0 -11
  221. data/spec/backward_compatibility_specs/webpacker_test_app/config/webpacker_manifest_path.yml +0 -80
  222. data/spec/backward_compatibility_specs/webpacker_test_app/config/webpacker_nested_entries.yml +0 -83
  223. data/spec/backward_compatibility_specs/webpacker_test_app/config/webpacker_no_precompile.yml +0 -7
  224. data/spec/backward_compatibility_specs/webpacker_test_app/config/webpacker_other_location.yml +0 -85
  225. data/spec/backward_compatibility_specs/webpacker_test_app/config/webpacker_public_root.yml +0 -18
  226. data/spec/backward_compatibility_specs/webpacker_test_app/config.ru +0 -5
  227. data/spec/backward_compatibility_specs/webpacker_test_app/package.json +0 -13
  228. data/spec/backward_compatibility_specs/webpacker_test_app/public/packs/manifest.json +0 -58
  229. data/spec/backward_compatibility_specs/webpacker_test_app/some.config.js +0 -0
  230. data/spec/backward_compatibility_specs/webpacker_test_app/tmp/shakapacker/last-compilation-digest-production +0 -1
  231. data/spec/backward_compatibility_specs/webpacker_test_app/yarn.lock +0 -11
@@ -113,8 +113,8 @@ describe "Shakapacker::Configuration" do
113
113
  end
114
114
 
115
115
  describe "#ensure_consistent_versioning?" do
116
- it "returns false in production environment" do
117
- expect(config.ensure_consistent_versioning?).to be false
116
+ it "returns true in production environment" do
117
+ expect(config.ensure_consistent_versioning?).to be true
118
118
  end
119
119
 
120
120
  it "returns true in development environment" do
@@ -123,9 +123,9 @@ describe "Shakapacker::Configuration" do
123
123
  end
124
124
  end
125
125
 
126
- it "returns false in test environment" do
126
+ it "returns true in test environment" do
127
127
  with_rails_env("test") do
128
- expect(Shakapacker.config.ensure_consistent_versioning?).to be false
128
+ expect(Shakapacker.config.ensure_consistent_versioning?).to be true
129
129
  end
130
130
  end
131
131
  end
@@ -374,56 +374,4 @@ describe "Shakapacker::Configuration" do
374
374
  end
375
375
  end
376
376
 
377
- describe "#relative_url_root" do
378
- let(:config) do
379
- Shakapacker::Configuration.new(
380
- root_path: ROOT_PATH,
381
- config_path: Pathname.new(File.expand_path("./test_app/config/shakapacker.yml", __dir__)),
382
- env: "production"
383
- )
384
- end
385
-
386
- context "with SHAKAPACKER_RELATIVE_URL_ROOT set" do
387
- before do
388
- expect(ENV).to receive(:fetch).with("SHAKAPACKER_RELATIVE_URL_ROOT", nil).and_return("custom_value")
389
- end
390
- it "shows deprecation message" do
391
- expect { config.relative_url_root }.to output(/deprecated/).to_stdout
392
- end
393
-
394
- it "returns the value of SHAKAPACKER_RELATIVE_URL_ROOT" do
395
- expect(config.relative_url_root).to eq "custom_value"
396
- end
397
- end
398
-
399
- context "without SHAKAPACKER_RELATIVE_URL_ROOT set" do
400
- it "returns relative_url_root in shakapacker.yml if set" do
401
- expect(config).to receive(:fetch).with(:relative_url_root).and_return("value-in-config-file")
402
- expect(ENV).to receive(:fetch).with("SHAKAPACKER_RELATIVE_URL_ROOT", "value-in-config-file").and_return("value-in-config-file")
403
-
404
- expect(config.relative_url_root).to eq "value-in-config-file"
405
- end
406
-
407
- context "without relative_url_root set in the shakapacker.yml" do
408
- it "returns ActionController::Base.relative_url_root if SHAKAPACKER_RELATIVE_URL_ROOT is not set" do
409
- expect(ActionController::Base).to receive(:relative_url_root).and_return("abcd")
410
- expect(ENV).to receive(:fetch).with("SHAKAPACKER_RELATIVE_URL_ROOT", "abcd").and_return("abcd")
411
-
412
- expect(config.relative_url_root).to eq "abcd"
413
- end
414
-
415
- context "without ActionController::Base.relative_url_root returing any value" do
416
- it "returns an empty string" do
417
- expect(ENV).to receive(:fetch).with("SHAKAPACKER_RELATIVE_URL_ROOT", nil).and_return(nil)
418
-
419
- expect(config.relative_url_root).to be nil
420
- end
421
-
422
- it "doesn't shows deprecation message" do
423
- expect { config.relative_url_root }.to_not output(/deprecated/).to_stdout
424
- end
425
- end
426
- end
427
- end
428
- end
429
377
  end
@@ -2,6 +2,13 @@ require_relative "spec_helper_initializer"
2
2
  require "shakapacker/dev_server_runner"
3
3
 
4
4
  describe "DevServerRunner" do
5
+ around do |example|
6
+ within_temp_directory do
7
+ FileUtils.cp_r(File.expand_path("./test_app", __dir__), Dir.pwd)
8
+ Dir.chdir("test_app") { example.run }
9
+ end
10
+ end
11
+
5
12
  before do
6
13
  @original_node_env, ENV["NODE_ENV"] = ENV["NODE_ENV"], "development"
7
14
  @original_rails_env, ENV["RAILS_ENV"] = ENV["RAILS_ENV"], "development"
@@ -14,15 +21,21 @@ describe "DevServerRunner" do
14
21
  ENV["SHAKAPACKER_CONFIG"] = @original_shakapacker_config
15
22
  end
16
23
 
17
- let(:test_app_path) { File.expand_path("./test_app", __dir__) }
24
+ let(:test_app_path) { Dir.pwd }
18
25
 
19
26
  NODE_PACKAGE_MANAGERS.each do |fallback_manager|
20
27
  context "when using package_json with #{fallback_manager} as the manager" do
21
- with_use_package_json_gem(enabled: true, fallback_manager: fallback_manager)
28
+ before do
29
+ manager_name = fallback_manager.split("_")[0]
30
+ manager_version = "1.2.3"
31
+ manager_version = "4.5.6" if fallback_manager == "yarn_berry"
22
32
 
23
- let(:package_json) { PackageJson.read(test_app_path) }
33
+ PackageJson.read.merge! { { "packageManager" => "#{manager_name}@#{manager_version}" } }
24
34
 
25
- require "package_json"
35
+ allow(Shakapacker::Utils::Manager).to receive(:error_unless_package_manager_is_obvious!)
36
+ end
37
+
38
+ let(:package_json) { PackageJson.read(test_app_path) }
26
39
 
27
40
  it "uses the expected package manager", unless: fallback_manager == "yarn_classic" do
28
41
  cmd = package_json.manager.native_exec_command("webpack", ["serve", "--config", "#{test_app_path}/config/webpack/webpack.config.js"])
@@ -104,116 +117,20 @@ describe "DevServerRunner" do
104
117
  end
105
118
  end
106
119
 
107
- context "when not using package_json" do
108
- with_use_package_json_gem(enabled: false)
109
-
110
- it "supports running via node modules" do
111
- cmd = ["#{test_app_path}/node_modules/.bin/webpack", "serve", "--config", "#{test_app_path}/config/webpack/webpack.config.js"]
112
-
113
- verify_command(cmd, use_node_modules: true)
114
- end
115
-
116
- it "supports running via yarn" do
117
- cmd = ["yarn", "webpack", "serve", "--config", "#{test_app_path}/config/webpack/webpack.config.js"]
118
-
119
- verify_command(cmd, use_node_modules: false)
120
- end
121
-
122
- it "passes on arguments" do
123
- cmd = ["#{test_app_path}/node_modules/.bin/webpack", "serve", "--config", "#{test_app_path}/config/webpack/webpack.config.js", "--quiet"]
124
-
125
- verify_command(cmd, argv: (["--quiet"]))
126
- end
127
-
128
- it "does not automatically pass the --https flag" do
129
- cmd = ["#{test_app_path}/node_modules/.bin/webpack", "serve", "--config", "#{test_app_path}/config/webpack/webpack.config.js"]
130
-
131
- allow(Shakapacker::DevServer).to receive(:new).and_return(
132
- double(
133
- host: "localhost",
134
- port: "3035",
135
- pretty?: false,
136
- protocol: "https",
137
- hmr?: true
138
- )
139
- )
140
-
141
- verify_command(cmd)
142
- end
143
-
144
- it "supports the https flag" do
145
- cmd = ["#{test_app_path}/node_modules/.bin/webpack", "serve", "--config", "#{test_app_path}/config/webpack/webpack.config.js", "--https"]
146
-
147
- allow(Shakapacker::DevServer).to receive(:new).and_return(
148
- double(
149
- host: "localhost",
150
- port: "3035",
151
- pretty?: false,
152
- protocol: "https",
153
- hmr?: true
154
- )
155
- )
156
-
157
- verify_command(cmd, argv: ["--https"])
158
- end
159
-
160
- it "supports disabling hot module reloading" do
161
- cmd = ["#{test_app_path}/node_modules/.bin/webpack", "serve", "--config", "#{test_app_path}/config/webpack/webpack.config.js", "--no-hot"]
162
-
163
- allow(Shakapacker::DevServer).to receive(:new).and_return(
164
- double(
165
- host: "localhost",
166
- port: "3035",
167
- pretty?: false,
168
- protocol: "http",
169
- hmr?: false
170
- )
171
- )
172
-
173
- verify_command(cmd)
174
- end
175
-
176
- it "supports --hot being 'only'" do
177
- cmd = ["#{test_app_path}/node_modules/.bin/webpack", "serve", "--config", "#{test_app_path}/config/webpack/webpack.config.js", "--hot", "only"]
178
-
179
- allow(Shakapacker::DevServer).to receive(:new).and_return(
180
- double(
181
- host: "localhost",
182
- port: "3035",
183
- pretty?: false,
184
- protocol: "http",
185
- hmr?: "only"
186
- )
187
- )
188
-
189
- verify_command(cmd)
190
- end
191
-
192
- it "accepts environment variables" do
193
- cmd = ["#{test_app_path}/node_modules/.bin/webpack", "serve", "--config", "#{test_app_path}/config/webpack/webpack.config.js"]
194
- env = Shakapacker::Compiler.env.dup
195
-
196
- ENV["SHAKAPACKER_CONFIG"] = env["SHAKAPACKER_CONFIG"] = "#{test_app_path}/config/shakapacker_other_location.yml"
197
- env["WEBPACK_SERVE"] = "true"
198
-
199
- verify_command(cmd, env: env)
200
- end
201
- end
202
-
203
120
  private
204
121
 
205
- def verify_command(cmd, use_node_modules: true, argv: [], env: Shakapacker::Compiler.env)
122
+ def verify_command(cmd, argv: [], env: Shakapacker::Compiler.env)
206
123
  Dir.chdir(test_app_path) do
207
124
  klass = Shakapacker::DevServerRunner
208
125
  instance = klass.new(argv)
209
126
 
210
127
  allow(klass).to receive(:new).and_return(instance)
211
- allow(instance).to receive(:node_modules_bin_exist?).and_return(use_node_modules)
212
128
  allow(Kernel).to receive(:exec).with(env, *cmd)
213
129
 
214
130
  klass.run(argv)
215
131
 
216
132
  expect(Kernel).to have_received(:exec).with(env, *cmd)
133
+ expect(Shakapacker::Utils::Manager).to have_received(:error_unless_package_manager_is_obvious!)
217
134
  end
218
135
  end
219
136
  end
@@ -17,12 +17,6 @@ describe "DevServer" do
17
17
  end
18
18
  end
19
19
 
20
- it "doesn't use https in development environment" do
21
- with_rails_env("development") do
22
- expect(Shakapacker.dev_server.https?).to be false
23
- end
24
- end
25
-
26
20
  it "uses http protocol in development environment" do
27
21
  with_rails_env("development") do
28
22
  expect(Shakapacker.dev_server.protocol).to eq "http"
@@ -48,7 +42,7 @@ describe "DevServer" do
48
42
  context "#protocol in development environment" do
49
43
  let(:dev_server) { Shakapacker.dev_server }
50
44
 
51
- it "returns `http` by default (with unset `server` and `https`)" do
45
+ it "returns `http` by default (with unset `server`)" do
52
46
  with_rails_env("development") do
53
47
  expect(dev_server.protocol).to eq "http"
54
48
  end
@@ -61,15 +55,6 @@ describe "DevServer" do
61
55
  expect(dev_server.protocol).to eq "https"
62
56
  end
63
57
  end
64
-
65
- it "returns `https` with unset `server` and `https` set to `true`" do
66
- expect(dev_server).to receive(:server).and_return("http")
67
- expect(dev_server).to receive(:https?).and_return(true)
68
-
69
- with_rails_env("development") do
70
- expect(dev_server.protocol).to eq "https"
71
- end
72
- end
73
58
  end
74
59
 
75
60
  context "#server in development environment" do
@@ -11,7 +11,7 @@ describe "EngineRakeTasks" do
11
11
 
12
12
  NODE_PACKAGE_MANAGERS.each do |fallback_manager|
13
13
  context "when using package_json with #{fallback_manager} as the manager" do
14
- with_use_package_json_gem(enabled: true, fallback_manager: fallback_manager)
14
+ with_package_json_fallback_manager(fallback_manager)
15
15
 
16
16
  it "mounts app:shakapacker task successfully" do
17
17
  output = Dir.chdir(mounted_app_path) { `rake -T` }
@@ -26,21 +26,6 @@ describe "EngineRakeTasks" do
26
26
  end
27
27
  end
28
28
 
29
- context "when not using package_json" do
30
- with_use_package_json_gem(enabled: false)
31
-
32
- it "mounts app:shakapacker task successfully" do
33
- output = Dir.chdir(mounted_app_path) { `rake -T` }
34
-
35
- expect(output).to include "app:shakapacker"
36
- end
37
-
38
- it "only adds expected files to bin directory when binstubs is run" do
39
- Dir.chdir(mounted_app_path) { `bundle exec rake app:shakapacker:binstubs` }
40
- expected_binstub_paths.each { |path| expect(File.exist?(path)).to be true }
41
- end
42
- end
43
-
44
29
  private
45
30
  def mounted_app_path
46
31
  File.expand_path("../mounted_app", __dir__)
@@ -126,7 +126,7 @@ module ActionView::TestCase::Behavior
126
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
- "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"
129
+ "Please refer to https://github.com/shakacode/shakapacker/blob/main/README.md#view-helper-append_javascript_pack_tag-prepend_javascript_pack_tag-and-append_stylesheet_pack_tag for the usage guide"
130
130
 
131
131
  expect {
132
132
  javascript_pack_tag("application")
@@ -137,7 +137,7 @@ module ActionView::TestCase::Behavior
137
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
- "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"
140
+ "Please refer to https://github.com/shakacode/shakapacker/blob/main/README.md#view-helper-append_javascript_pack_tag-prepend_javascript_pack_tag-and-append_stylesheet_pack_tag for the usage guide"
141
141
 
142
142
  expect {
143
143
  javascript_pack_tag("application")
@@ -167,7 +167,7 @@ module ActionView::TestCase::Behavior
167
167
 
168
168
  it "#javascript_pack_tag rases error on multiple invocations" do
169
169
  expected_error_message = "To prevent duplicated chunks on the page, you should call javascript_pack_tag only once on the page. " +
170
- "Please refer to https://github.com/shakacode/shakapacker/blob/master/README.md#view-helpers-javascript_pack_tag-and-stylesheet_pack_tag for the usage guide"
170
+ "Please refer to https://github.com/shakacode/shakapacker/blob/main/README.md#view-helpers-javascript_pack_tag-and-stylesheet_pack_tag for the usage guide"
171
171
 
172
172
  expect {
173
173
  javascript_pack_tag(:application)
@@ -2,13 +2,10 @@ require_relative "spec_helper_initializer"
2
2
 
3
3
  describe "Shakapacker::Instance" do
4
4
  before :each do
5
- ENV.delete("WEBPACKER_CONFIG")
6
5
  ENV.delete("SHAKAPACKER_CONFIG")
7
- Shakapacker.instance = Shakapacker::Instance.new
8
6
  end
9
7
 
10
8
  after :each do
11
- ENV.delete("WEBPACKER_CONFIG")
12
9
  ENV.delete("SHAKAPACKER_CONFIG")
13
10
  Shakapacker.instance = Shakapacker::Instance.new
14
11
  end
@@ -22,6 +19,7 @@ describe "Shakapacker::Instance" do
22
19
 
23
20
  it "uses the SHAKAPACKER_CONFIG env variable for the config file path" do
24
21
  ENV["SHAKAPACKER_CONFIG"] = "/some/random/path.yml"
22
+ Shakapacker.instance = Shakapacker::Instance.new
25
23
 
26
24
  actual_config_path = "/some/random/path.yml"
27
25
  expected_config_path = Shakapacker.config.config_path.to_s
@@ -63,13 +63,7 @@ describe "RakeTasks" do
63
63
  FileUtils.mv("bin/shakapacker_renamed", "bin/shakapacker")
64
64
  end
65
65
 
66
- it "passes if `./bin/webpacker exist" do
67
- with_temporary_file("bin/webpacker") do
68
- expect { system("bundle exec rake shakapacker:check_binstubs") }.to output(/DEPRECATION/).to_stdout_from_any_process
69
- end
70
- end
71
-
72
- it "fails otherwise" do
66
+ it "fails" do
73
67
  expect { system("bundle exec rake shakapacker:check_binstubs") }.to output(/Couldn't find shakapacker binstubs!/).to_stdout_from_any_process
74
68
  end
75
69
  end
@@ -83,13 +77,7 @@ describe "RakeTasks" do
83
77
  FileUtils.mv("bin/shakapacker-dev-server_renamed", "bin/shakapacker-dev-server")
84
78
  end
85
79
 
86
- it "passes if `./bin/webpacker-dev-server exist" do
87
- with_temporary_file("bin/webpacker-dev-server") do
88
- expect { system("bundle exec rake shakapacker:check_binstubs") }.to output(/DEPRECATION/).to_stdout_from_any_process
89
- end
90
- end
91
-
92
- it "fails otherwise" do
80
+ it "fails" do
93
81
  expect { system("bundle exec rake shakapacker:check_binstubs") }.to output(/Couldn't find shakapacker binstubs!/).to_stdout_from_any_process
94
82
  end
95
83
  end
@@ -8,7 +8,6 @@ describe "Shakapacker" do
8
8
  allow(dev_server).to receive(:host).and_return("localhost")
9
9
  allow(dev_server).to receive(:port).and_return("3035")
10
10
  allow(dev_server).to receive(:pretty?).and_return(false)
11
- allow(dev_server).to receive(:https?).and_return(true)
12
11
  allow(dev_server).to receive(:running?).and_return(true)
13
12
  end
14
13
 
@@ -45,7 +45,6 @@ development:
45
45
 
46
46
  # Reference: https://webpack.js.org/configuration/dev-server/
47
47
  dev_server:
48
- https: false
49
48
  host: localhost
50
49
  port: 3035
51
50
  public: localhost:3035
@@ -41,7 +41,6 @@ development:
41
41
 
42
42
  # Reference: https://webpack.js.org/configuration/dev-server/
43
43
  dev_server:
44
- https: false
45
44
  host: localhost
46
45
  port: 3035
47
46
  public: localhost:3035
@@ -44,7 +44,6 @@ development:
44
44
 
45
45
  # Reference: https://webpack.js.org/configuration/dev-server/
46
46
  dev_server:
47
- https: false
48
47
  host: localhost
49
48
  port: 3035
50
49
  public: localhost:3035
@@ -38,7 +38,6 @@ development:
38
38
 
39
39
  # Reference: https://webpack.js.org/configuration/dev-server/
40
40
  dev_server:
41
- https: false
42
41
  host: localhost
43
42
  port: 3035
44
43
  public: localhost:3035
@@ -9,5 +9,6 @@
9
9
  },
10
10
  "devDependencies": {
11
11
  "right-pad": "^1.0.1"
12
- }
12
+ },
13
+ "packageManager": "yarn@1.22.24"
13
14
  }
@@ -0,0 +1,125 @@
1
+ require_relative "spec_helper_initializer"
2
+ require "shakapacker/utils/manager"
3
+
4
+ Struct.new("Status", :exit_code) do
5
+ def success?
6
+ exit_code.zero?
7
+ end
8
+
9
+ def exitstatus
10
+ exit_code
11
+ end
12
+ end
13
+
14
+ describe "Shakapacker::Utils::Manager" do
15
+ around do |example|
16
+ within_temp_directory { example.run }
17
+ end
18
+
19
+ describe "~error_unless_package_manager_is_obvious!" do
20
+ before do
21
+ allow(Shakapacker).to receive(:puts_deprecation_message)
22
+ end
23
+
24
+ context "when 'packageManager' is set in the package.json" do
25
+ before do
26
+ File.write("package.json", { "packageManager" => "pnpm" }.to_json)
27
+ end
28
+
29
+ it "does nothing" do
30
+ Shakapacker::Utils::Manager.error_unless_package_manager_is_obvious!
31
+
32
+ expect(Shakapacker).not_to have_received(:puts_deprecation_message)
33
+ end
34
+ end
35
+
36
+ context "when the guessed manager is npm" do
37
+ it "does nothing" do
38
+ File.write("package.json", {}.to_json)
39
+ FileUtils.touch("package-lock.json")
40
+
41
+ Shakapacker::Utils::Manager.error_unless_package_manager_is_obvious!
42
+
43
+ expect(Shakapacker).not_to have_received(:puts_deprecation_message)
44
+ end
45
+ end
46
+
47
+ Shakapacker::Utils::Manager::MANAGER_LOCKS.reject { |manager| manager == "npm" }.each do |manager, lock|
48
+ context "when there is a #{lock}" do
49
+ before do
50
+ allow(Open3).to receive(:capture3).and_return(["1.2.3\n", "", Struct::Status.new(0)])
51
+ end
52
+
53
+ it "raises an error about setting 'packageManager' for #{manager}" do
54
+ File.write("package.json", {}.to_json)
55
+ FileUtils.touch(lock)
56
+
57
+ expect { Shakapacker::Utils::Manager.error_unless_package_manager_is_obvious! }.to raise_error(Shakapacker::Utils::Manager::Error, <<~MSG)
58
+ You don't have "packageManager" set in your package.json
59
+ meaning that Shakapacker will use npm but you've got a #{lock}
60
+ file meaning you probably want to be using #{manager} instead.
61
+
62
+ To make this happen, set "packageManager" in your package.json to #{manager}@1.2.3
63
+ MSG
64
+ end
65
+ end
66
+ end
67
+ end
68
+
69
+ describe "~guess_binary" do
70
+ Shakapacker::Utils::Manager::MANAGER_LOCKS.each do |manager, lock|
71
+ context "when a #{lock} exists" do
72
+ before { FileUtils.touch(lock) }
73
+
74
+ it "guesses #{manager}" do
75
+ expect(Shakapacker::Utils::Manager.guess_binary).to eq manager
76
+ end
77
+ end
78
+ end
79
+
80
+ context "when there is no lockfile" do
81
+ it "returns npm" do
82
+ expect(Shakapacker::Utils::Manager.guess_binary).to eq "npm"
83
+ end
84
+ end
85
+ end
86
+
87
+ describe "~guess_version" do
88
+ before do
89
+ allow(Open3).to receive(:capture3).and_return(["1.2.3\n", "", Struct::Status.new(0)])
90
+ end
91
+
92
+ Shakapacker::Utils::Manager::MANAGER_LOCKS.each do |manager, lock|
93
+ context "when a #{lock} exists" do
94
+ before { FileUtils.touch(lock) }
95
+
96
+ it "calls #{manager} with --version" do
97
+ Shakapacker::Utils::Manager.guess_version
98
+
99
+ expect(Open3).to have_received(:capture3).with("#{manager} --version")
100
+ end
101
+ end
102
+ end
103
+
104
+ it "returns the output without a trailing newline" do
105
+ FileUtils.touch("package-lock.json")
106
+
107
+ expect(Shakapacker::Utils::Manager.guess_version).to eq("1.2.3")
108
+ end
109
+
110
+ context "when the command errors" do
111
+ before do
112
+ allow(Open3).to receive(:capture3).and_return(["", "oh noes!", Struct::Status.new(1)])
113
+ end
114
+
115
+ it "raises an error" do
116
+ FileUtils.touch("package-lock.json")
117
+
118
+ expect { Shakapacker::Utils::Manager.guess_version }.to raise_error(
119
+ Shakapacker::Utils::Manager::Error,
120
+ "npm --version failed with exit code 1: oh noes!"
121
+ )
122
+ end
123
+ end
124
+ end
125
+ end
@@ -29,19 +29,19 @@ describe "VersionChecker" do
29
29
  version_checker.raise_if_gem_and_node_package_versions_differ
30
30
  end
31
31
 
32
- it "prints error in stderr if consistency check is disabled and version mismatch" do
32
+ it "does nothing if consistency check is disabled and version mismatch" do
33
33
  node_package_version = NodePackageVersionDouble.new(raw: "6.1.0", major_minor_patch: ["6", "1", "0"])
34
34
 
35
35
  expect { check_version(node_package_version, "6.0.0", false) }
36
- .to output(/Shakapacker::VersionChecker - Version mismatch/)
36
+ .not_to output
37
37
  .to_stderr
38
38
  end
39
39
 
40
- it "prints error in stderr if consistency check is disabled and we have semver" do
40
+ it "does nothing if consistency check is disabled and we have semver" do
41
41
  node_package_version = NodePackageVersionDouble.new(raw: "^6.1.0", major_minor_patch: ["6", "1", "0"], semver_wildcard: true)
42
42
 
43
43
  expect { check_version(node_package_version, "6.0.0", false) }
44
- .to output(/Shakapacker::VersionChecker - Semver wildcard without a lockfile detected/)
44
+ .not_to output
45
45
  .to_stderr
46
46
  end
47
47
 
@@ -233,7 +233,7 @@ describe "VersionChecker::NodePackageVersion" do
233
233
  let(:node_package_version_from_github_url) { node_package_version(fixture_version: "github_url") }
234
234
 
235
235
  it "#raw returns the GitHub repo address" do
236
- expect(node_package_version_from_github_url.raw).to eq "shakacode/shakapacker#master"
236
+ expect(node_package_version_from_github_url.raw).to eq "shakacode/shakapacker#main"
237
237
  end
238
238
 
239
239
  it "#major_minor_patch returns nil" do