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

Sign up to get free protection for your applications and to get access to all the features.
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
@@ -1,206 +0,0 @@
1
- require_relative "spec_helper_initializer"
2
- # Requiring from webpacker directory to ensure old ./bin/webpacker-dev-server works fine
3
- require "webpacker/dev_server_runner"
4
-
5
- describe "DevServerRunner" do
6
- before do
7
- @original_node_env, ENV["NODE_ENV"] = ENV["NODE_ENV"], "development"
8
- @original_rails_env, ENV["RAILS_ENV"] = ENV["RAILS_ENV"], "development"
9
- @original_webpacker_config = ENV["WEBPACKER_CONFIG"]
10
- end
11
-
12
- after do
13
- ENV["NODE_ENV"] = @original_node_env
14
- ENV["RAILS_ENV"] = @original_rails_env
15
- ENV["WEBPACKER_CONFIG"] = @original_webpacker_config
16
- end
17
-
18
- let(:test_app_path) { File.expand_path("webpacker_test_app", __dir__) }
19
-
20
- NODE_PACKAGE_MANAGERS.each do |fallback_manager|
21
- context "when using package_json with #{fallback_manager} as the manager" do
22
- with_use_package_json_gem(enabled: true, fallback_manager: fallback_manager)
23
-
24
- let(:package_json) { PackageJson.read(test_app_path) }
25
-
26
- require "package_json"
27
-
28
- it "uses the expected package manager", unless: fallback_manager == "yarn_classic" do
29
- cmd = package_json.manager.native_exec_command("webpack", ["serve", "--config", "#{test_app_path}/config/webpack/webpack.config.js"])
30
-
31
- manager_name = fallback_manager.split("_")[0]
32
-
33
- expect(cmd).to start_with(manager_name)
34
- end
35
-
36
- it "runs the command using the manager" do
37
- cmd = package_json.manager.native_exec_command("webpack", ["serve", "--config", "#{test_app_path}/config/webpack/webpack.config.js"])
38
-
39
- verify_command(cmd)
40
- end
41
-
42
- it "passes on arguments" do
43
- cmd = package_json.manager.native_exec_command("webpack", ["serve", "--config", "#{test_app_path}/config/webpack/webpack.config.js", "--quiet"])
44
-
45
- verify_command(cmd, argv: (["--quiet"]))
46
- end
47
-
48
- it "does not automatically pass the --https flag" do
49
- cmd = package_json.manager.native_exec_command("webpack", ["serve", "--config", "#{test_app_path}/config/webpack/webpack.config.js"])
50
-
51
- allow(Shakapacker::DevServer).to receive(:new).and_return(
52
- double(
53
- host: "localhost",
54
- port: "3035",
55
- pretty?: false,
56
- protocol: "https",
57
- hmr?: true
58
- )
59
- )
60
-
61
- verify_command(cmd)
62
- end
63
-
64
- it "supports the https flag" do
65
- cmd = package_json.manager.native_exec_command("webpack", ["serve", "--config", "#{test_app_path}/config/webpack/webpack.config.js", "--https"])
66
-
67
- allow(Shakapacker::DevServer).to receive(:new).and_return(
68
- double(
69
- host: "localhost",
70
- port: "3035",
71
- pretty?: false,
72
- protocol: "https",
73
- hmr?: true
74
- )
75
- )
76
-
77
- verify_command(cmd, argv: ["--https"])
78
- end
79
-
80
- it "supports disabling hot module reloading" do
81
- cmd = package_json.manager.native_exec_command("webpack", ["serve", "--config", "#{test_app_path}/config/webpack/webpack.config.js", "--no-hot"])
82
-
83
- allow(Shakapacker::DevServer).to receive(:new).and_return(
84
- double(
85
- host: "localhost",
86
- port: "3035",
87
- pretty?: false,
88
- protocol: "http",
89
- hmr?: false
90
- )
91
- )
92
-
93
- verify_command(cmd)
94
- end
95
-
96
- it "accepts environment variables" do
97
- cmd = package_json.manager.native_exec_command("webpack", ["serve", "--config", "#{test_app_path}/config/webpack/webpack.config.js"])
98
- env = Webpacker::Compiler.env.dup
99
-
100
- # ENV["WEBPACKER_CONFIG"] is the interface and env["SHAKAPACKER_CONFIG"] is internal
101
- ENV["WEBPACKER_CONFIG"] = env["SHAKAPACKER_CONFIG"] = "#{test_app_path}/config/webpacker_other_location.yml"
102
- env["WEBPACK_SERVE"] = "true"
103
-
104
- verify_command(cmd, env: env)
105
- end
106
- end
107
- end
108
-
109
- context "when not using package_json" do
110
- with_use_package_json_gem(enabled: false)
111
-
112
- it "supports running via node modules" do
113
- cmd = ["#{test_app_path}/node_modules/.bin/webpack", "serve", "--config", "#{test_app_path}/config/webpack/webpack.config.js"]
114
-
115
- verify_command(cmd, use_node_modules: true)
116
- end
117
-
118
- it "supports running via yarn" do
119
- cmd = ["yarn", "webpack", "serve", "--config", "#{test_app_path}/config/webpack/webpack.config.js"]
120
-
121
- verify_command(cmd, use_node_modules: false)
122
- end
123
-
124
- it "passes on arguments" do
125
- cmd = ["#{test_app_path}/node_modules/.bin/webpack", "serve", "--config", "#{test_app_path}/config/webpack/webpack.config.js", "--quiet"]
126
-
127
- verify_command(cmd, argv: (["--quiet"]))
128
- end
129
-
130
- it "does not automatically pass the --https flag" do
131
- cmd = ["#{test_app_path}/node_modules/.bin/webpack", "serve", "--config", "#{test_app_path}/config/webpack/webpack.config.js"]
132
-
133
- allow(Shakapacker::DevServer).to receive(:new).and_return(
134
- double(
135
- host: "localhost",
136
- port: "3035",
137
- pretty?: false,
138
- protocol: "https",
139
- hmr?: true
140
- )
141
- )
142
-
143
- verify_command(cmd)
144
- end
145
-
146
- it "supports the https flag" do
147
- cmd = ["#{test_app_path}/node_modules/.bin/webpack", "serve", "--config", "#{test_app_path}/config/webpack/webpack.config.js", "--https"]
148
-
149
- allow(Shakapacker::DevServer).to receive(:new).and_return(
150
- double(
151
- host: "localhost",
152
- port: "3035",
153
- pretty?: false,
154
- protocol: "https",
155
- hmr?: true
156
- )
157
- )
158
-
159
- verify_command(cmd, argv: ["--https"])
160
- end
161
-
162
- it "supports disabling hot module reloading" do
163
- cmd = ["#{test_app_path}/node_modules/.bin/webpack", "serve", "--config", "#{test_app_path}/config/webpack/webpack.config.js", "--no-hot"]
164
-
165
- allow(Shakapacker::DevServer).to receive(:new).and_return(
166
- double(
167
- host: "localhost",
168
- port: "3035",
169
- pretty?: false,
170
- protocol: "http",
171
- hmr?: false
172
- )
173
- )
174
-
175
- verify_command(cmd)
176
- end
177
-
178
- it "accepts environment variables" do
179
- cmd = ["#{test_app_path}/node_modules/.bin/webpack", "serve", "--config", "#{test_app_path}/config/webpack/webpack.config.js"]
180
- env = Webpacker::Compiler.env.dup
181
-
182
- # ENV["WEBPACKER_CONFIG"] is the interface and env["SHAKAPACKER_CONFIG"] is internal
183
- ENV["WEBPACKER_CONFIG"] = env["SHAKAPACKER_CONFIG"] = "#{test_app_path}/config/webpacker_other_location.yml"
184
- env["WEBPACK_SERVE"] = "true"
185
-
186
- verify_command(cmd, env: env)
187
- end
188
- end
189
-
190
- private
191
-
192
- def verify_command(cmd, use_node_modules: true, argv: [], env: Webpacker::Compiler.env)
193
- Dir.chdir(test_app_path) do
194
- klass = Webpacker::DevServerRunner
195
- instance = klass.new(argv)
196
-
197
- allow(klass).to receive(:new).and_return(instance)
198
- allow(instance).to receive(:node_modules_bin_exist?).and_return(use_node_modules)
199
- allow(Kernel).to receive(:exec).with(env, *cmd)
200
-
201
- klass.run(argv)
202
-
203
- expect(Kernel).to have_received(:exec).with(env, *cmd)
204
- end
205
- end
206
- end
@@ -1,47 +0,0 @@
1
- require_relative "spec_helper_initializer"
2
-
3
- describe "DevServer" do
4
- it "doesn't run by default" do
5
- expect(Webpacker.dev_server.running?).to be_falsy
6
- end
7
-
8
- it "uses localhost as host in development environment" do
9
- with_rails_env("development") do
10
- expect(Webpacker.dev_server.host).to eq "localhost"
11
- end
12
- end
13
-
14
- it "uses port 3035 in development environment" do
15
- with_rails_env("development") do
16
- expect(Webpacker.dev_server.port).to eq 3035
17
- end
18
- end
19
-
20
- it "doesn't use https in development environment" do
21
- with_rails_env("development") do
22
- expect(Webpacker.dev_server.https?).to be false
23
- end
24
- end
25
-
26
- it "uses http protocol in development environment" do
27
- with_rails_env("development") do
28
- expect(Webpacker.dev_server.protocol).to eq "http"
29
- end
30
- end
31
-
32
- it "sets host_with_port to localhost:3035 in development environment" do
33
- with_rails_env("development") do
34
- expect(Webpacker.dev_server.host_with_port).to eq "localhost:3035"
35
- end
36
- end
37
-
38
- it "doesn't use pretty in development environment" do
39
- with_rails_env("development") do
40
- expect(Webpacker.dev_server.pretty?).to be false
41
- end
42
- end
43
-
44
- it "uses SHAKAPACKER_DEV_SERVER for DEFAULT_ENV_PREFIX" do
45
- expect(Webpacker::DevServer::DEFAULT_ENV_PREFIX).to eq "SHAKAPACKER_DEV_SERVER"
46
- end
47
- end
@@ -1,38 +0,0 @@
1
- require_relative "spec_helper_initializer"
2
-
3
- describe "DigestStrategy" do
4
- def remove_compilation_digest_path
5
- @digest_strategy.send(:compilation_digest_path).tap do |path|
6
- path.delete if path.exist?
7
- end
8
- end
9
-
10
- before :all do
11
- @digest_strategy = Webpacker::DigestStrategy.new
12
- ENV["SHAKAPACKER_ASSET_HOST"] = nil
13
- remove_compilation_digest_path
14
- end
15
-
16
- after :all do
17
- remove_compilation_digest_path
18
- end
19
-
20
- it "is not fresh before compilation" do
21
- expect(@digest_strategy.stale?).to be true
22
- expect(@digest_strategy.fresh?).to be_falsy
23
- end
24
-
25
- it "is fresh after compilation" do
26
- @digest_strategy.after_compile_hook
27
-
28
- expect(@digest_strategy.stale?).to be false
29
- expect(@digest_strategy.fresh?).to be true
30
- end
31
-
32
- it "generates correct compilation_digest_path" do
33
- actual_path = @digest_strategy.send(:compilation_digest_path).basename.to_s
34
- expected_path = "last-compilation-digest-#{Webpacker.env}"
35
-
36
- expect(actual_path).to eq expected_path
37
- end
38
- end
@@ -1,67 +0,0 @@
1
- require_relative "spec_helper_initializer"
2
-
3
- describe "EngineRakeTasks" do
4
- before :context do
5
- remove_webpack_binstubs
6
- end
7
-
8
- after :context do
9
- remove_webpack_binstubs
10
- end
11
-
12
- NODE_PACKAGE_MANAGERS.each do |fallback_manager|
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)
15
-
16
- it "mounts app:webpacker task successfully" do
17
- output = Dir.chdir(mounted_app_path) { `rake -T` }
18
-
19
- expect(output).to match /app:webpacker.+DEPRECATED/
20
- expect(output).to match /app:webpacker:binstubs.+DEPRECATED/
21
- end
22
-
23
- it "only adds expected files to bin directory when binstubs is run" do
24
- Dir.chdir(mounted_app_path) { `bundle exec rake app:webpacker:binstubs` }
25
- expected_binstub_paths.each { |path| expect(File.exist?(path)).to be true }
26
- end
27
- end
28
- end
29
-
30
- context "when not using package_json" do
31
- with_use_package_json_gem(enabled: false)
32
-
33
- it "mounts app:webpacker task successfully" do
34
- output = Dir.chdir(mounted_app_path) { `rake -T` }
35
-
36
- expect(output).to match /app:webpacker.+DEPRECATED/
37
- expect(output).to match /app:webpacker:binstubs.+DEPRECATED/
38
- end
39
-
40
- it "only adds expected files to bin directory when binstubs is run" do
41
- Dir.chdir(mounted_app_path) { `bundle exec rake app:webpacker:binstubs` }
42
- expected_binstub_paths.each { |path| expect(File.exist?(path)).to be true }
43
- end
44
- end
45
-
46
- private
47
- def mounted_app_path
48
- File.expand_path("../mounted_app", __dir__)
49
- end
50
-
51
- def current_files_in_bin
52
- Dir.glob("#{mounted_app_path}/test/dummy/bin/*")
53
- end
54
-
55
- def expected_binstub_paths
56
- gem_path = File.expand_path("../..", __dir__)
57
- Dir.chdir("#{gem_path}/lib/install/bin") do
58
- Dir.glob("*").map { |file| "#{mounted_app_path}/test/dummy/bin/#{file}" }
59
- end
60
- end
61
-
62
- def remove_webpack_binstubs
63
- expected_binstub_paths.each do |path|
64
- File.delete(path) if File.exist?(path)
65
- end
66
- end
67
- end
@@ -1,23 +0,0 @@
1
- require_relative "spec_helper_initializer"
2
-
3
- RSpec.describe "Webpacker.env" do
4
- it "uses the same env for Rails and Webpacker" do
5
- expect(Webpacker.env).to eq Rails.env
6
- end
7
-
8
- it "uses production env without config" do
9
- with_rails_env("foo") do
10
- expect(Webpacker.env).to eq "production"
11
- end
12
- end
13
-
14
- it "uses the given env in custom config" do
15
- with_rails_env("staging") do
16
- expect(Webpacker.env).to eq "staging"
17
- end
18
- end
19
-
20
- it "uses 'production' as default env" do
21
- expect(Webpacker::DEFAULT_ENV).to eq "production"
22
- end
23
- end
@@ -1,243 +0,0 @@
1
- require_relative "spec_helper_initializer"
2
-
3
- module ActionView::TestCase::Behavior
4
- attr_accessor :request
5
-
6
- describe "Webpacker::Helper" do
7
- let(:application_stylesheet_chunks) { %w[/packs/1-c20632e7baf2c81200d3.chunk.css /packs/application-k344a6d59eef8632c9d1.chunk.css] }
8
- let(:hello_stimulus_stylesheet_chunks) { %w[/packs/1-c20632e7baf2c81200d3.chunk.css /packs/hello_stimulus-k344a6d59eef8632c9d1.chunk.css] }
9
-
10
- before :each do
11
- extend Webpacker::Helper
12
- extend ActionView::Helpers
13
- extend ActionView::Helpers::AssetTagHelper
14
- extend ActionView::TestCase::Behavior
15
-
16
- @request = Class.new do
17
- def send_early_hints(links) end
18
- def base_url
19
- "https://example.com"
20
- end
21
- end.new
22
- @javascript_pack_tag_loaded = nil
23
- end
24
-
25
- it "#asset_pack_path generates the correct path" do
26
- expect(asset_pack_path("bootstrap.js")).to eq "/packs/bootstrap-300631c4f0e0f9c865bc.js"
27
- expect(asset_pack_path("bootstrap.css")).to eq "/packs/bootstrap-c38deda30895059837cf.css"
28
- end
29
-
30
- it "#asset_pack_url generates the correct url" do
31
- expect(asset_pack_url("bootstrap.js")).to eq "https://example.com/packs/bootstrap-300631c4f0e0f9c865bc.js"
32
- expect(asset_pack_url("bootstrap.css")).to eq "https://example.com/packs/bootstrap-c38deda30895059837cf.css"
33
- end
34
-
35
- it "#image_pack_path generates the correct path" do
36
- expect(image_pack_path("application.png")).to eq "/packs/application-k344a6d59eef8632c9d1.png"
37
- expect(image_pack_path("image.jpg")).to eq "/packs/static/image-c38deda30895059837cf.jpg"
38
- expect(image_pack_path("static/image.jpg")).to eq "/packs/static/image-c38deda30895059837cf.jpg"
39
- expect(image_pack_path("nested/image.jpg")).to eq "/packs/static/nested/image-c38deda30895059837cf.jpg"
40
- expect(image_pack_path("static/nested/image.jpg")).to eq "/packs/static/nested/image-c38deda30895059837cf.jpg"
41
- end
42
-
43
- it "#image_pack_url generates the correct path" do
44
- expect(image_pack_url("application.png")).to eq "https://example.com/packs/application-k344a6d59eef8632c9d1.png"
45
- expect(image_pack_url("image.jpg")).to eq "https://example.com/packs/static/image-c38deda30895059837cf.jpg"
46
- expect(image_pack_url("static/image.jpg")).to eq "https://example.com/packs/static/image-c38deda30895059837cf.jpg"
47
- expect(image_pack_url("nested/image.jpg")).to eq "https://example.com/packs/static/nested/image-c38deda30895059837cf.jpg"
48
- expect(image_pack_url("static/nested/image.jpg")).to eq "https://example.com/packs/static/nested/image-c38deda30895059837cf.jpg"
49
- end
50
-
51
- it "#image_pack_tag generates the correct tags" do
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
- 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
- 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\" />"
55
- expect(image_pack_tag("nested/image.jpg", size: "16x10", alt: "Edit Entry")).to eq "<img alt=\"Edit Entry\" src=\"/packs/static/nested/image-c38deda30895059837cf.jpg\" width=\"16\" height=\"10\" />"
56
- expect(image_pack_tag("static/nested/image.jpg", size: "16x10", alt: "Edit Entry")).to eq "<img alt=\"Edit Entry\" src=\"/packs/static/nested/image-c38deda30895059837cf.jpg\" width=\"16\" height=\"10\" />"
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
- end
59
-
60
- it "#favicon_pack_tag generates the correct tags" do
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
- 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
- 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\" />"
64
- expect(favicon_pack_tag("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\" />"
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
- end
67
-
68
- it "#preload_pack_asset generates the correct tag" do
69
- if self.class.method_defined?(:preload_link_tag)
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
- else
72
- expect { preload_pack_asset("fonts/fa-regular-400.woff2") }.to raise_error "You need Rails >= 5.2 to use this tag."
73
- end
74
- end
75
-
76
- it "#javascript_pack_tag generates the correct tags" do
77
- expected = <<~HTML.chomp
78
- <script src="/packs/vendors~application~bootstrap-c20632e7baf2c81200d3.chunk.js" defer="defer"></script>
79
- <script src="/packs/vendors~application-e55f2aae30c07fb6d82a.chunk.js" defer="defer"></script>
80
- <script src="/packs/application-k344a6d59eef8632c9d1.js" defer="defer"></script>
81
- <script src="/packs/bootstrap-300631c4f0e0f9c865bc.js" defer="defer"></script>
82
- HTML
83
-
84
- expect(javascript_pack_tag("application", "bootstrap")).to eq expected
85
- end
86
-
87
- it "#javascript_pack_tag generates the correct tags when passing `defer: false`" do
88
- expected = <<~HTML.chomp
89
- <script src="/packs/vendors~application~bootstrap-c20632e7baf2c81200d3.chunk.js"></script>
90
- <script src="/packs/vendors~application-e55f2aae30c07fb6d82a.chunk.js"></script>
91
- <script src="/packs/application-k344a6d59eef8632c9d1.js"></script>
92
- <script src="/packs/bootstrap-300631c4f0e0f9c865bc.js"></script>
93
- HTML
94
-
95
- expect(javascript_pack_tag("application", "bootstrap", defer: false)).to eq expected
96
- end
97
-
98
- it "#javascript_pack_tag generates the correct appended tag" do
99
- append_javascript_pack_tag("bootstrap", defer: false)
100
-
101
- expected = <<~HTML.chomp
102
- <script src="/packs/vendors~application~bootstrap-c20632e7baf2c81200d3.chunk.js" defer="defer"></script>
103
- <script src="/packs/vendors~application-e55f2aae30c07fb6d82a.chunk.js" defer="defer"></script>
104
- <script src="/packs/application-k344a6d59eef8632c9d1.js" defer="defer"></script>
105
- <script src="/packs/bootstrap-300631c4f0e0f9c865bc.js"></script>
106
- HTML
107
-
108
- expect(javascript_pack_tag("application")).to eq expected
109
- end
110
-
111
- it "#javascript_pack_tag generates the correct prepended tag" do
112
- append_javascript_pack_tag("bootstrap")
113
- prepend_javascript_pack_tag("main")
114
-
115
- expected = <<~HTML.chomp
116
- <script src="/packs/main-e323a53c7f30f5d53cbb.js" defer="defer"></script>
117
- <script src="/packs/bootstrap-300631c4f0e0f9c865bc.js" defer="defer"></script>
118
- <script src="/packs/vendors~application~bootstrap-c20632e7baf2c81200d3.chunk.js" defer="defer"></script>
119
- <script src="/packs/vendors~application-e55f2aae30c07fb6d82a.chunk.js" defer="defer"></script>
120
- <script src="/packs/application-k344a6d59eef8632c9d1.js" defer="defer"></script>
121
- HTML
122
-
123
- expect(javascript_pack_tag("application")).to eq expected
124
- end
125
-
126
- it "#append_javascript_pack_tag raises an error if called after calling #javascript_pack_tag" do
127
- expected_error_message = \
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"
130
-
131
- expect {
132
- javascript_pack_tag("application")
133
- append_javascript_pack_tag("bootstrap", defer: false)
134
- }.to raise_error(expected_error_message)
135
- end
136
-
137
- it "#prepend_javascript_pack_tag raises an error if called after calling #javascript_pack_tag" do
138
- expected_error_message = \
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"
141
-
142
- expect {
143
- javascript_pack_tag("application")
144
- prepend_javascript_pack_tag("bootstrap", defer: false)
145
- }.to raise_error(expected_error_message)
146
- end
147
-
148
- it "#javascript_pack_tag generates the correct tags when passing `defer: true`" do
149
- expected = <<~HTML.chomp
150
- <script src="/packs/vendors~application~bootstrap-c20632e7baf2c81200d3.chunk.js" defer="defer"></script>
151
- <script src="/packs/vendors~application-e55f2aae30c07fb6d82a.chunk.js" defer="defer"></script>
152
- <script src="/packs/application-k344a6d59eef8632c9d1.js" defer="defer"></script>
153
- HTML
154
-
155
- expect(javascript_pack_tag("application", defer: true)).to eq expected
156
- end
157
-
158
- it "#javascript_pack_tag generates the correct tags when passing a symbol" do
159
- expected = <<~HTML.chomp
160
- <script src="/packs/vendors~application~bootstrap-c20632e7baf2c81200d3.chunk.js" defer="defer"></script>
161
- <script src="/packs/vendors~application-e55f2aae30c07fb6d82a.chunk.js" defer="defer"></script>
162
- <script src="/packs/application-k344a6d59eef8632c9d1.js" defer="defer"></script>
163
- HTML
164
-
165
- expect(javascript_pack_tag(:application)).to eq expected
166
- end
167
-
168
- it "#javascript_pack_tag rases error on multiple invocations" do
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"
171
-
172
- expect {
173
- javascript_pack_tag(:application)
174
- javascript_pack_tag(:bootstrap)
175
- }.to raise_error(expected_error_message)
176
- end
177
-
178
- it "#stylesheet_pack_tag generates the correct link tag with string arguments" do
179
- expected = (application_stylesheet_chunks + hello_stimulus_stylesheet_chunks)
180
- .uniq
181
- .map { |chunk| stylesheet_link_tag(chunk) }
182
- .join("\n")
183
-
184
- expect(stylesheet_pack_tag("application", "hello_stimulus")).to eq expected
185
- end
186
-
187
- it "#stylesheet_pack_tag generates the correct link tag with symbol arguments" do
188
- expected = (application_stylesheet_chunks + hello_stimulus_stylesheet_chunks)
189
- .uniq
190
- .map { |chunk| stylesheet_link_tag(chunk) }
191
- .join("\n")
192
-
193
- expect(stylesheet_pack_tag(:application, :hello_stimulus)).to eq expected
194
- end
195
-
196
- it "#stylesheet_pack_tag generates the correct link tag with mixed arguments" do
197
- expected = (application_stylesheet_chunks)
198
- .map { |chunk| stylesheet_link_tag(chunk, media: "all") }
199
- .join("\n")
200
-
201
- expect(stylesheet_pack_tag("application", media: "all")).to eq expected
202
- end
203
-
204
- it "#stylesheet_pack_tag allows multiple invocations" do
205
- app_style = stylesheet_pack_tag(:application)
206
- stimulus_style = stylesheet_pack_tag(:hello_stimulus)
207
-
208
- expect(app_style).to eq application_stylesheet_chunks.map { |chunk| stylesheet_link_tag(chunk) }.join("\n")
209
-
210
- expect(stimulus_style).to eq hello_stimulus_stylesheet_chunks.map { |chunk| stylesheet_link_tag(chunk) }.join("\n")
211
-
212
- expect {
213
- stylesheet_pack_tag(:application)
214
- stylesheet_pack_tag(:hello_stimulus)
215
- }.to_not raise_error
216
- end
217
-
218
- it "#stylesheet_pack_tag appends tags" do
219
- append_stylesheet_pack_tag(:hello_stimulus)
220
-
221
- expect(stylesheet_pack_tag(:application)).to eq \
222
- (application_stylesheet_chunks + hello_stimulus_stylesheet_chunks).uniq.map { |chunk| stylesheet_link_tag(chunk) }.join("\n")
223
- end
224
-
225
- it "#stylesheet_pack_tag appends duplicate" do
226
- append_stylesheet_pack_tag(:hello_stimulus)
227
- append_stylesheet_pack_tag(:application)
228
-
229
- expect(stylesheet_pack_tag(:application)).to eq \
230
- (application_stylesheet_chunks + hello_stimulus_stylesheet_chunks).uniq.map { |chunk| stylesheet_link_tag(chunk) }.join("\n")
231
- end
232
-
233
- it "#stylesheet_pack_tag supports multiple invocations with different media attr values" do
234
- app_style = stylesheet_pack_tag(:application)
235
- app_style_with_media = stylesheet_pack_tag(:application, media: "print")
236
- hello_stimulus_style_with_media = stylesheet_pack_tag(:hello_stimulus, media: "all")
237
-
238
- expect(app_style).to eq application_stylesheet_chunks.map { |chunk| stylesheet_link_tag(chunk) }.join("\n")
239
- expect(app_style_with_media).to eq application_stylesheet_chunks.map { |chunk| stylesheet_link_tag(chunk, media: "print") }.join("\n")
240
- expect(hello_stimulus_style_with_media).to eq hello_stimulus_stylesheet_chunks.map { |chunk| stylesheet_link_tag(chunk, media: "all") }.join("\n")
241
- end
242
- end
243
- end
@@ -1,31 +0,0 @@
1
- require_relative "spec_helper_initializer"
2
-
3
- describe "Webpacker::Instance" do
4
- before :each do
5
- ENV.delete("WEBPACKER_CONFIG")
6
- ENV.delete("SHAKAPACKER_CONFIG")
7
- Webpacker.instance = Webpacker::Instance.new
8
- end
9
-
10
- after :each do
11
- ENV.delete("WEBPACKER_CONFIG")
12
- ENV.delete("SHAKAPACKER_CONFIG")
13
- Webpacker.instance = Webpacker::Instance.new
14
- end
15
-
16
- it "uses the default config path if no env variable defined" do
17
- actual_config_path = Rails.root.join("config/webpacker.yml")
18
- expected_config_path = Webpacker.config.config_path
19
-
20
- expect(expected_config_path).to eq(actual_config_path)
21
- end
22
-
23
- it "uses the WEBPACKER_CONFIG env variable for the config file path" do
24
- ENV["WEBPACKER_CONFIG"] = "/some/random/path.yml"
25
-
26
- actual_config_path = "/some/random/path.yml"
27
- expected_config_path = Webpacker.config.config_path.to_s
28
-
29
- expect(expected_config_path).to eq(actual_config_path)
30
- end
31
- end