shakapacker 8.0.0 → 8.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (249) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/dummy.yml +1 -1
  3. data/.github/workflows/generator.yml +5 -1
  4. data/.github/workflows/node.yml +1 -1
  5. data/.github/workflows/ruby.yml +8 -2
  6. data/.gitignore +0 -1
  7. data/.node-version +1 -1
  8. data/CHANGELOG.md +21 -12
  9. data/Gemfile.lock +257 -0
  10. data/README.md +11 -12
  11. data/docs/customizing_babel_config.md +32 -4
  12. data/docs/react.md +3 -2
  13. data/docs/troubleshooting.md +1 -1
  14. data/docs/v8_upgrade.md +2 -2
  15. data/lib/shakapacker/version.rb +1 -1
  16. data/package.json +2 -2
  17. data/shakapacker.gemspec +5 -2
  18. metadata +5 -235
  19. data/lib/install/bin/yarn +0 -18
  20. data/rakelib/release.rake +0 -65
  21. data/spec/dummy/.browserslistrc +0 -1
  22. data/spec/dummy/.gitignore +0 -20
  23. data/spec/dummy/.prettierrc.yaml +0 -4
  24. data/spec/dummy/Gemfile +0 -61
  25. data/spec/dummy/Procfile.dev +0 -5
  26. data/spec/dummy/Procfile.dev-static +0 -9
  27. data/spec/dummy/README.md +0 -1
  28. data/spec/dummy/Rakefile +0 -6
  29. data/spec/dummy/app/assets/config/manifest.js +0 -2
  30. data/spec/dummy/app/assets/images/.keep +0 -0
  31. data/spec/dummy/app/assets/stylesheets/application.css +0 -15
  32. data/spec/dummy/app/channels/application_cable/channel.rb +0 -4
  33. data/spec/dummy/app/channels/application_cable/connection.rb +0 -4
  34. data/spec/dummy/app/controllers/application_controller.rb +0 -2
  35. data/spec/dummy/app/controllers/concerns/.keep +0 -0
  36. data/spec/dummy/app/controllers/hello_world_controller.rb +0 -9
  37. data/spec/dummy/app/helpers/application_helper.rb +0 -2
  38. data/spec/dummy/app/javascript/Globals.d.ts +0 -3
  39. data/spec/dummy/app/javascript/bundles/HelloWorld/components/HelloWorld.module.css +0 -25
  40. data/spec/dummy/app/javascript/bundles/HelloWorld/components/HelloWorld.tsx +0 -47
  41. data/spec/dummy/app/javascript/bundles/HelloWorld/components/HelloWorldServer.tsx +0 -5
  42. data/spec/dummy/app/javascript/bundles/HelloWorld/components/logo.svg +0 -7
  43. data/spec/dummy/app/javascript/packs/application.js +0 -17
  44. data/spec/dummy/app/javascript/packs/hello-world-bundle.ts +0 -8
  45. data/spec/dummy/app/javascript/packs/server-bundle.ts +0 -8
  46. data/spec/dummy/app/jobs/application_job.rb +0 -7
  47. data/spec/dummy/app/mailers/application_mailer.rb +0 -4
  48. data/spec/dummy/app/models/application_record.rb +0 -3
  49. data/spec/dummy/app/models/concerns/.keep +0 -0
  50. data/spec/dummy/app/views/hello_world/index.html.erb +0 -2
  51. data/spec/dummy/app/views/layouts/application.html.erb +0 -14
  52. data/spec/dummy/app/views/layouts/hello_world.html.erb +0 -13
  53. data/spec/dummy/app/views/layouts/mailer.html.erb +0 -13
  54. data/spec/dummy/app/views/layouts/mailer.text.erb +0 -1
  55. data/spec/dummy/babel.config.js +0 -30
  56. data/spec/dummy/bin/bundle +0 -114
  57. data/spec/dummy/bin/dev +0 -30
  58. data/spec/dummy/bin/dev-static +0 -30
  59. data/spec/dummy/bin/rails +0 -9
  60. data/spec/dummy/bin/rake +0 -9
  61. data/spec/dummy/bin/setup +0 -33
  62. data/spec/dummy/bin/shakapacker +0 -13
  63. data/spec/dummy/bin/shakapacker-dev-server +0 -13
  64. data/spec/dummy/bin/spring +0 -17
  65. data/spec/dummy/bin/yarn +0 -18
  66. data/spec/dummy/config/application.rb +0 -35
  67. data/spec/dummy/config/boot.rb +0 -4
  68. data/spec/dummy/config/cable.yml +0 -10
  69. data/spec/dummy/config/credentials.yml.enc +0 -1
  70. data/spec/dummy/config/database.yml +0 -25
  71. data/spec/dummy/config/environment.rb +0 -5
  72. data/spec/dummy/config/environments/development.rb +0 -54
  73. data/spec/dummy/config/environments/production.rb +0 -106
  74. data/spec/dummy/config/environments/test.rb +0 -49
  75. data/spec/dummy/config/initializers/application_controller_renderer.rb +0 -8
  76. data/spec/dummy/config/initializers/backtrace_silencers.rb +0 -7
  77. data/spec/dummy/config/initializers/content_security_policy.rb +0 -28
  78. data/spec/dummy/config/initializers/cookies_serializer.rb +0 -5
  79. data/spec/dummy/config/initializers/filter_parameter_logging.rb +0 -4
  80. data/spec/dummy/config/initializers/inflections.rb +0 -16
  81. data/spec/dummy/config/initializers/mime_types.rb +0 -4
  82. data/spec/dummy/config/initializers/react_on_rails.rb +0 -58
  83. data/spec/dummy/config/initializers/wrap_parameters.rb +0 -14
  84. data/spec/dummy/config/locales/en.yml +0 -33
  85. data/spec/dummy/config/puma.rb +0 -38
  86. data/spec/dummy/config/routes.rb +0 -6
  87. data/spec/dummy/config/shakapacker.yml +0 -61
  88. data/spec/dummy/config/spring.rb +0 -6
  89. data/spec/dummy/config/storage.yml +0 -34
  90. data/spec/dummy/config/webpack/ServerClientOrBoth.js +0 -34
  91. data/spec/dummy/config/webpack/clientWebpackConfig.js +0 -15
  92. data/spec/dummy/config/webpack/commonWebpackConfig.js +0 -17
  93. data/spec/dummy/config/webpack/development.js +0 -32
  94. data/spec/dummy/config/webpack/production.js +0 -9
  95. data/spec/dummy/config/webpack/serverWebpackConfig.js +0 -116
  96. data/spec/dummy/config/webpack/test.js +0 -7
  97. data/spec/dummy/config/webpack/webpack.config.js +0 -24
  98. data/spec/dummy/config.ru +0 -5
  99. data/spec/dummy/db/seeds.rb +0 -7
  100. data/spec/dummy/lib/assets/.keep +0 -0
  101. data/spec/dummy/lib/tasks/.keep +0 -0
  102. data/spec/dummy/package.json +0 -44
  103. data/spec/dummy/postcss.config.js +0 -12
  104. data/spec/dummy/public/404.html +0 -67
  105. data/spec/dummy/public/422.html +0 -67
  106. data/spec/dummy/public/500.html +0 -66
  107. data/spec/dummy/public/apple-touch-icon-precomposed.png +0 -0
  108. data/spec/dummy/public/apple-touch-icon.png +0 -0
  109. data/spec/dummy/public/favicon.ico +0 -0
  110. data/spec/dummy/public/robots.txt +0 -1
  111. data/spec/dummy/spec/rails_helper.rb +0 -118
  112. data/spec/dummy/spec/spec_helper.rb +0 -96
  113. data/spec/dummy/spec/system/hello_world_spec.rb +0 -19
  114. data/spec/dummy/tsconfig.json +0 -21
  115. data/spec/dummy/vendor/.keep +0 -0
  116. data/spec/dummy/yarn.lock +0 -4696
  117. data/spec/fixtures/beta_package-lock.v1.json +0 -119
  118. data/spec/fixtures/beta_package-lock.v2.json +0 -6777
  119. data/spec/fixtures/beta_package.json +0 -13
  120. data/spec/fixtures/beta_pnpm-lock.v7.yaml +0 -116
  121. data/spec/fixtures/beta_pnpm-lock.v8.yaml +0 -2537
  122. data/spec/fixtures/beta_pnpm-lock.v9.yaml +0 -2885
  123. data/spec/fixtures/beta_yarn.v1.lock +0 -106
  124. data/spec/fixtures/beta_yarn.v2.lock +0 -164
  125. data/spec/fixtures/git_url_package-lock.v1.json +0 -118
  126. data/spec/fixtures/git_url_package-lock.v2.json +0 -10263
  127. data/spec/fixtures/git_url_package.json +0 -13
  128. data/spec/fixtures/git_url_pnpm-lock.v7.yaml +0 -126
  129. data/spec/fixtures/git_url_pnpm-lock.v8.yaml +0 -3728
  130. data/spec/fixtures/git_url_pnpm-lock.v9.yaml +0 -4544
  131. data/spec/fixtures/git_url_yarn.v1.lock +0 -106
  132. data/spec/fixtures/git_url_yarn.v2.lock +0 -165
  133. data/spec/fixtures/github_url_package-lock.v1.json +0 -118
  134. data/spec/fixtures/github_url_package-lock.v2.json +0 -10263
  135. data/spec/fixtures/github_url_package.json +0 -13
  136. data/spec/fixtures/github_url_pnpm-lock.v7.yaml +0 -126
  137. data/spec/fixtures/github_url_pnpm-lock.v8.yaml +0 -3728
  138. data/spec/fixtures/github_url_pnpm-lock.v9.yaml +0 -4544
  139. data/spec/fixtures/github_url_yarn.v1.lock +0 -105
  140. data/spec/fixtures/github_url_yarn.v2.lock +0 -165
  141. data/spec/fixtures/relative_path_package-lock.v1.json +0 -3468
  142. data/spec/fixtures/relative_path_package-lock.v2.json +0 -105
  143. data/spec/fixtures/relative_path_package.json +0 -13
  144. data/spec/fixtures/relative_path_pnpm-lock.v7.yaml +0 -18
  145. data/spec/fixtures/relative_path_pnpm-lock.v8.yaml +0 -22
  146. data/spec/fixtures/relative_path_pnpm-lock.v9.yaml +0 -28
  147. data/spec/fixtures/relative_path_yarn.v1.lock +0 -104
  148. data/spec/fixtures/relative_path_yarn.v2.lock +0 -165
  149. data/spec/fixtures/semver_caret_package-lock.v1.json +0 -119
  150. data/spec/fixtures/semver_caret_package-lock.v2.json +0 -10264
  151. data/spec/fixtures/semver_caret_package.json +0 -13
  152. data/spec/fixtures/semver_caret_pnpm-lock.v7.yaml +0 -117
  153. data/spec/fixtures/semver_caret_pnpm-lock.v8.yaml +0 -2558
  154. data/spec/fixtures/semver_caret_pnpm-lock.v9.yaml +0 -4285
  155. data/spec/fixtures/semver_caret_yarn.v1.lock +0 -106
  156. data/spec/fixtures/semver_caret_yarn.v2.lock +0 -165
  157. data/spec/fixtures/semver_exact_package-lock.v1.json +0 -119
  158. data/spec/fixtures/semver_exact_package-lock.v2.json +0 -6819
  159. data/spec/fixtures/semver_exact_package.json +0 -13
  160. data/spec/fixtures/semver_exact_pnpm-lock.v7.yaml +0 -117
  161. data/spec/fixtures/semver_exact_pnpm-lock.v8.yaml +0 -2558
  162. data/spec/fixtures/semver_exact_pnpm-lock.v9.yaml +0 -2908
  163. data/spec/fixtures/semver_exact_yarn.v1.lock +0 -106
  164. data/spec/fixtures/semver_exact_yarn.v2.lock +0 -165
  165. data/spec/fixtures/semver_tilde_package-lock.v1.json +0 -119
  166. data/spec/fixtures/semver_tilde_package-lock.v2.json +0 -6777
  167. data/spec/fixtures/semver_tilde_package.json +0 -13
  168. data/spec/fixtures/semver_tilde_pnpm-lock.v7.yaml +0 -116
  169. data/spec/fixtures/semver_tilde_pnpm-lock.v8.yaml +0 -2558
  170. data/spec/fixtures/semver_tilde_pnpm-lock.v9.yaml +0 -2885
  171. data/spec/fixtures/semver_tilde_yarn.v1.lock +0 -106
  172. data/spec/fixtures/semver_tilde_yarn.v2.lock +0 -164
  173. data/spec/fixtures/without_package-lock.v1.json +0 -19
  174. data/spec/fixtures/without_package-lock.v2.json +0 -47
  175. data/spec/fixtures/without_package.json +0 -13
  176. data/spec/fixtures/without_pnpm-lock.v7.yaml +0 -23
  177. data/spec/fixtures/without_pnpm-lock.v8.yaml +0 -27
  178. data/spec/fixtures/without_pnpm-lock.v9.yaml +0 -34
  179. data/spec/fixtures/without_yarn.v1.lock +0 -13
  180. data/spec/fixtures/without_yarn.v2.lock +0 -29
  181. data/spec/generator_specs/e2e_template/files/app/controllers/home_controller.rb +0 -4
  182. data/spec/generator_specs/e2e_template/files/app/javascript/components/App.js +0 -12
  183. data/spec/generator_specs/e2e_template/files/app/javascript/packs/application.js +0 -10
  184. data/spec/generator_specs/e2e_template/files/app/views/home/index.html.erb +0 -2
  185. data/spec/generator_specs/e2e_template/files/app/views/layouts/application.html.erb +0 -17
  186. data/spec/generator_specs/e2e_template/files/config/routes.rb +0 -3
  187. data/spec/generator_specs/e2e_template/files/spec/system/test_react_component_renders_spec.rb +0 -13
  188. data/spec/generator_specs/e2e_template/template.rb +0 -29
  189. data/spec/generator_specs/fake-bin/bun +0 -10
  190. data/spec/generator_specs/fake-bin/npm +0 -10
  191. data/spec/generator_specs/fake-bin/pnpm +0 -10
  192. data/spec/generator_specs/fake-bin/yarn +0 -10
  193. data/spec/generator_specs/generator_spec.rb +0 -193
  194. data/spec/mounted_app/Rakefile +0 -4
  195. data/spec/mounted_app/package.json +0 -1
  196. data/spec/mounted_app/test/dummy/Rakefile +0 -3
  197. data/spec/mounted_app/test/dummy/bin/rails +0 -3
  198. data/spec/mounted_app/test/dummy/bin/rake +0 -3
  199. data/spec/mounted_app/test/dummy/config/application.rb +0 -10
  200. data/spec/mounted_app/test/dummy/config/environment.rb +0 -3
  201. data/spec/mounted_app/test/dummy/config/webpacker.yml +0 -81
  202. data/spec/mounted_app/test/dummy/config.ru +0 -5
  203. data/spec/mounted_app/test/dummy/package.json +0 -7
  204. data/spec/shakapacker/command_spec.rb +0 -134
  205. data/spec/shakapacker/compiler_spec.rb +0 -57
  206. data/spec/shakapacker/compiler_strategy_spec.rb +0 -24
  207. data/spec/shakapacker/configuration_spec.rb +0 -377
  208. data/spec/shakapacker/dev_server_runner_spec.rb +0 -136
  209. data/spec/shakapacker/dev_server_spec.rb +0 -118
  210. data/spec/shakapacker/digest_strategy_spec.rb +0 -59
  211. data/spec/shakapacker/engine_rake_tasks_spec.rb +0 -50
  212. data/spec/shakapacker/env_spec.rb +0 -23
  213. data/spec/shakapacker/helper_spec.rb +0 -243
  214. data/spec/shakapacker/instance_spec.rb +0 -29
  215. data/spec/shakapacker/manifest_spec.rb +0 -100
  216. data/spec/shakapacker/mtime_strategy_spec.rb +0 -55
  217. data/spec/shakapacker/rake_tasks_spec.rb +0 -85
  218. data/spec/shakapacker/shakapacker_spec.rb +0 -40
  219. data/spec/shakapacker/spec_helper_initializer.rb +0 -24
  220. data/spec/shakapacker/test_app/.gitignore +0 -2
  221. data/spec/shakapacker/test_app/Rakefile +0 -3
  222. data/spec/shakapacker/test_app/app/javascript/entrypoints/application.js +0 -10
  223. data/spec/shakapacker/test_app/app/javascript/entrypoints/generated/something.js +0 -2
  224. data/spec/shakapacker/test_app/app/javascript/entrypoints/multi_entry.css +0 -4
  225. data/spec/shakapacker/test_app/app/javascript/entrypoints/multi_entry.js +0 -4
  226. data/spec/shakapacker/test_app/bin/shakapacker +0 -14
  227. data/spec/shakapacker/test_app/bin/shakapacker-dev-server +0 -14
  228. data/spec/shakapacker/test_app/config/application.rb +0 -11
  229. data/spec/shakapacker/test_app/config/environment.rb +0 -4
  230. data/spec/shakapacker/test_app/config/initializers/inspect_autoload_paths.rb +0 -1
  231. data/spec/shakapacker/test_app/config/shakapacker.yml +0 -82
  232. data/spec/shakapacker/test_app/config/shakapacker_css_extract_ignore_order_warnings.yml +0 -83
  233. data/spec/shakapacker/test_app/config/shakapacker_defaults_fallback.yml +0 -11
  234. data/spec/shakapacker/test_app/config/shakapacker_manifest_path.yml +0 -79
  235. data/spec/shakapacker/test_app/config/shakapacker_nested_entries.yml +0 -82
  236. data/spec/shakapacker/test_app/config/shakapacker_no_precompile.yml +0 -7
  237. data/spec/shakapacker/test_app/config/shakapacker_other_location.yml +0 -84
  238. data/spec/shakapacker/test_app/config/shakapacker_public_root.yml +0 -18
  239. data/spec/shakapacker/test_app/config/webpack/webpack.config.js +0 -0
  240. data/spec/shakapacker/test_app/config.ru +0 -5
  241. data/spec/shakapacker/test_app/package.json +0 -14
  242. data/spec/shakapacker/test_app/public/packs/manifest.json +0 -58
  243. data/spec/shakapacker/test_app/some.config.js +0 -0
  244. data/spec/shakapacker/test_app/yarn.lock +0 -11
  245. data/spec/shakapacker/utils_manager_spec.rb +0 -125
  246. data/spec/shakapacker/version_checker_spec.rb +0 -1469
  247. data/spec/shakapacker/webpack_runner_spec.rb +0 -76
  248. data/spec/spec_helper.rb +0 -100
  249. data/spec/support/package_json_helpers.rb +0 -19
@@ -1,377 +0,0 @@
1
- require_relative "spec_helper_initializer"
2
-
3
- describe "Shakapacker::Configuration" do
4
- ROOT_PATH = Pathname.new(File.expand_path("./test_app", __dir__))
5
-
6
- context "with standard shakapacker.yml" do
7
- let(:config) do
8
- Shakapacker::Configuration.new(
9
- root_path: ROOT_PATH,
10
- config_path: Pathname.new(File.expand_path("./test_app/config/shakapacker.yml", __dir__)),
11
- env: "production"
12
- )
13
- end
14
-
15
- it "#source_path returns correct path" do
16
- source_path = File.expand_path File.join(File.dirname(__FILE__), "./test_app/app/javascript").to_s
17
-
18
- expect(config.source_path.to_s).to eq source_path
19
- end
20
-
21
- it "#source_entry_path returns correct path" do
22
- source_entry_path = File.expand_path File.join(File.dirname(__FILE__), "./test_app/app/javascript", "entrypoints").to_s
23
-
24
- expect(config.source_entry_path.to_s).to eq source_entry_path
25
- end
26
-
27
- it "#public_root_path returns correct path" do
28
- public_root_path = File.expand_path File.join(File.dirname(__FILE__), "./test_app/public").to_s
29
-
30
- expect(config.public_path.to_s).to eq public_root_path
31
- end
32
-
33
- it "#public_output_path returns correct path" do
34
- public_output_path = File.expand_path File.join(File.dirname(__FILE__), "./test_app/public/packs").to_s
35
-
36
- expect(config.public_output_path.to_s).to eq public_output_path
37
- end
38
-
39
- it "#public_manifest_path returns correct path" do
40
- public_manifest_path = File.expand_path File.join(File.dirname(__FILE__), "./test_app/public/packs", "manifest.json").to_s
41
-
42
- expect(config.public_manifest_path.to_s).to eq public_manifest_path
43
- end
44
-
45
- it "#manifest_path returns correct path" do
46
- manifest_path = File.expand_path File.join(File.dirname(__FILE__), "./test_app/public/packs", "manifest.json").to_s
47
-
48
- expect(config.manifest_path.to_s).to eq manifest_path
49
- end
50
-
51
- it "#cache_path returns correct path" do
52
- cache_path = File.expand_path File.join(File.dirname(__FILE__), "./test_app/tmp/shakapacker").to_s
53
-
54
- expect(config.cache_path.to_s).to eq cache_path
55
- end
56
-
57
- it "#additional_paths returns correct path" do
58
- expect(config.additional_paths).to eq ["app/assets", "/etc/yarn", "some.config.js", "app/elm"]
59
- end
60
-
61
- describe "#cache_manifest?" do
62
- it "returns true in production environment" do
63
- expect(config.cache_manifest?).to be true
64
- end
65
-
66
- it "returns false in development environment" do
67
- with_rails_env("development") do
68
- expect(Shakapacker.config.cache_manifest?).to be false
69
- end
70
- end
71
-
72
- it "returns false in test environment" do
73
- with_rails_env("test") do
74
- expect(Shakapacker.config.cache_manifest?).to be false
75
- end
76
- end
77
- end
78
-
79
- describe "#compile?" do
80
- it "returns false in production environment" do
81
- expect(config.compile?).to be false
82
- end
83
-
84
- it "returns true in development environment" do
85
- with_rails_env("development") do
86
- expect(Shakapacker.config.compile?).to be true
87
- end
88
- end
89
-
90
- it "returns true in test environment" do
91
- with_rails_env("test") do
92
- expect(Shakapacker.config.compile?).to be true
93
- end
94
- end
95
- end
96
-
97
- describe "#nested_entries?" do
98
- it "returns false in production environment" do
99
- expect(config.nested_entries?).to be false
100
- end
101
-
102
- it "returns false in development environment" do
103
- with_rails_env("development") do
104
- expect(Shakapacker.config.nested_entries?).to be false
105
- end
106
- end
107
-
108
- it "returns false in test environment" do
109
- with_rails_env("test") do
110
- expect(Shakapacker.config.nested_entries?).to be false
111
- end
112
- end
113
- end
114
-
115
- describe "#ensure_consistent_versioning?" do
116
- it "returns true in production environment" do
117
- expect(config.ensure_consistent_versioning?).to be true
118
- end
119
-
120
- it "returns true in development environment" do
121
- with_rails_env("development") do
122
- expect(Shakapacker.config.ensure_consistent_versioning?).to be true
123
- end
124
- end
125
-
126
- it "returns true in test environment" do
127
- with_rails_env("test") do
128
- expect(Shakapacker.config.ensure_consistent_versioning?).to be true
129
- end
130
- end
131
- end
132
-
133
- describe "#shakapacker_precompile?" do
134
- before :each do
135
- ENV.delete("SHAKAPACKER_PRECOMPILE")
136
- end
137
-
138
- subject { config.shakapacker_precompile? }
139
-
140
- it "returns true when SHAKAPACKER_PRECOMPILE is unset" do
141
- is_expected.to be true
142
- end
143
-
144
- it "returns false when SHAKAPACKER_PRECOMPILE sets to no" do
145
- ENV["SHAKAPACKER_PRECOMPILE"] = "no"
146
- is_expected.to be false
147
- end
148
-
149
- it "returns true when SHAKAPACKER_PRECOMPILE sets to yes" do
150
- ENV["SHAKAPACKER_PRECOMPILE"] = "yes"
151
- is_expected.to be true
152
- end
153
-
154
- it "returns false when SHAKAPACKER_PRECOMPILE sets to false" do
155
- ENV["SHAKAPACKER_PRECOMPILE"] = "false"
156
- is_expected.to be false
157
- end
158
-
159
- it "returns true when SHAKAPACKER_PRECOMPILE sets to true" do
160
- ENV["SHAKAPACKER_PRECOMPILE"] = "true"
161
- is_expected.to be true
162
- end
163
-
164
- it "returns false when SHAKAPACKER_PRECOMPILE sets to n" do
165
- ENV["SHAKAPACKER_PRECOMPILE"] = "n"
166
- is_expected.to be false
167
- end
168
-
169
- it "returns true when SHAKAPACKER_PRECOMPILE sets to y" do
170
- ENV["SHAKAPACKER_PRECOMPILE"] = "y"
171
- is_expected.to be true
172
- end
173
-
174
- it "returns false when SHAKAPACKER_PRECOMPILE sets to f" do
175
- ENV["SHAKAPACKER_PRECOMPILE"] = "f"
176
- is_expected.to be false
177
- end
178
-
179
- it "returns true when SHAKAPACKER_PRECOMPILE sets to t" do
180
- ENV["SHAKAPACKER_PRECOMPILE"] = "t"
181
- is_expected.to be true
182
- end
183
- end
184
- end
185
-
186
- context "with shakapacker config file containing public_output_path entry" do
187
- config = Shakapacker::Configuration.new(
188
- root_path: ROOT_PATH,
189
- config_path: Pathname.new(File.expand_path("./test_app/config/shakapacker_public_root.yml", __dir__)),
190
- env: "production"
191
- )
192
-
193
- it "#public_output_path returns correct path" do
194
- expected_public_output_path = File.expand_path File.join(File.dirname(__FILE__), "./public/packs").to_s
195
-
196
- expect(config.public_output_path.to_s).to eq expected_public_output_path
197
- end
198
- end
199
-
200
- context "with shakapacker config file containing manifest_path entry" do
201
- config = Shakapacker::Configuration.new(
202
- root_path: ROOT_PATH,
203
- config_path: Pathname.new(File.expand_path("./test_app/config/shakapacker_manifest_path.yml", __dir__)),
204
- env: "production"
205
- )
206
-
207
- it "#manifest_path returns correct expected value" do
208
- expected_manifest_path = File.expand_path File.join(File.dirname(__FILE__), "./test_app/app/javascript", "manifest.json").to_s
209
-
210
- expect(config.manifest_path.to_s).to eq expected_manifest_path
211
- end
212
- end
213
-
214
- context "with shakapacker_precompile entry set to false" do
215
- describe "#shakapacker_precompile?" do
216
- before :each do
217
- ENV.delete("SHAKAPACKER_PRECOMPILE")
218
- end
219
-
220
- let(:config) {
221
- Shakapacker::Configuration.new(
222
- root_path: ROOT_PATH,
223
- config_path: Pathname.new(File.expand_path("./test_app/config/shakapacker_no_precompile.yml", __dir__)),
224
- env: "production"
225
- )
226
- }
227
-
228
- subject { config.shakapacker_precompile? }
229
-
230
- it "returns false with unset SHAKAPACKER_PRECOMPILE" do
231
- expect(subject).to be false
232
- end
233
-
234
- it "returns true with SHAKAPACKER_PRECOMPILE set to true" do
235
- ENV["SHAKAPACKER_PRECOMPILE"] = "true"
236
- expect(subject).to be true
237
- end
238
-
239
- it "returns false with SHAKAPACKER_PRECOMPILE set to nil" do
240
- ENV["SHAKAPACKER_PRECOMPILE"] = nil
241
- expect(subject).to be false
242
- end
243
- end
244
- end
245
-
246
- context "with shakapacker config file containing invalid path" do
247
- config = Shakapacker::Configuration.new(
248
- root_path: ROOT_PATH,
249
- config_path: Pathname.new(File.expand_path("./test_app/config/invalid_path.yml", __dir__)),
250
- env: "default"
251
- )
252
-
253
- it "#shakapacker_precompile? returns false" do
254
- expect(config.shakapacker_precompile?).to be false
255
- end
256
- end
257
-
258
- context "with shakapacker config file with defaults fallback" do
259
- let(:config) do
260
- Shakapacker::Configuration.new(
261
- root_path: ROOT_PATH,
262
- config_path: Pathname.new(File.expand_path("./test_app/config/shakapacker_defaults_fallback.yml", __dir__)),
263
- env: "default"
264
- )
265
- end
266
-
267
- it "#cache_manifest? falls back to 'default' config from bundled file" do
268
- expect(config.cache_manifest?).to be false
269
- end
270
-
271
- it "#shakapacker_precompile? uses 'default' config from custom file" do
272
- expect(config.shakapacker_precompile?).to be false
273
- end
274
- end
275
-
276
- context "falls back to bundled production config for custom environments" do
277
- let(:config) do
278
- Shakapacker::Configuration.new(
279
- root_path: ROOT_PATH,
280
- config_path: Pathname.new(File.expand_path("./test_app/config/shakapacker_defaults_fallback.yml", __dir__)),
281
- env: "staging"
282
- )
283
- end
284
-
285
- it "#cache_manifest? fall back to 'production' config from bundled file" do
286
- expect(config.cache_manifest?).to be true
287
- end
288
-
289
- it "#shakapacker_precompile? use 'staging' config from custom file" do
290
- expect(config.shakapacker_precompile?).to be false
291
- end
292
- end
293
-
294
- context "#source_entry_path" do
295
- let(:config) do
296
- Shakapacker::Configuration.new(
297
- root_path: ROOT_PATH,
298
- config_path: Pathname.new(File.expand_path("./test_app/config/shakapacker.yml", __dir__)),
299
- env: "production"
300
- )
301
- end
302
-
303
- it "returns correct path with source_entry_path starting with 'extra_path'" do
304
- allow(config).to receive(:fetch).with(:source_path).and_return("the_source_path")
305
- allow(config).to receive(:fetch).with(:source_entry_path).and_return("extra_path")
306
-
307
- actual = config.source_entry_path.to_s
308
- expected = "#{config.source_path.to_s}/extra_path"
309
-
310
- expect(actual).to eq(expected)
311
- end
312
-
313
- it "returns correct path with source_entry_path starting with /" do
314
- allow(config).to receive(:fetch).with(:source_path).and_return("the_source_path")
315
- allow(config).to receive(:fetch).with(:source_entry_path).and_return("/")
316
-
317
- actual = config.source_entry_path.to_s
318
- expected = config.source_path.to_s
319
-
320
- expect(actual).to eq(expected)
321
- end
322
-
323
- it "returns correct path with source_entry_path starting with /extra_path" do
324
- allow(config).to receive(:fetch).with(:source_path).and_return("the_source_path")
325
- allow(config).to receive(:fetch).with(:source_entry_path).and_return("/extra_path")
326
-
327
- actual = config.source_entry_path.to_s
328
- expected = "#{config.source_path.to_s}/extra_path"
329
-
330
- expect(actual).to eq(expected)
331
- end
332
- end
333
-
334
- describe "#asset_host" do
335
- let(:config) do
336
- Shakapacker::Configuration.new(
337
- root_path: ROOT_PATH,
338
- config_path: Pathname.new(File.expand_path("./test_app/config/shakapacker.yml", __dir__)),
339
- env: "production"
340
- )
341
- end
342
-
343
- it "returns the value of SHAKAPACKER_ASSET_HOST if set" do
344
- expect(ENV).to receive(:fetch).with("SHAKAPACKER_ASSET_HOST", nil).and_return("custom_host.abc")
345
-
346
- expect(config.asset_host).to eq "custom_host.abc"
347
- end
348
-
349
- context "without SHAKAPACKER_ASSET_HOST set" do
350
- it "returns asset_host in shakapacker.yml if set" do
351
- expect(config).to receive(:fetch).with(:asset_host).and_return("value-in-config-file.com")
352
- expect(ENV).to receive(:fetch).with("SHAKAPACKER_ASSET_HOST", "value-in-config-file.com").and_return("value-in-config-file.com")
353
-
354
- expect(config.asset_host).to eq "value-in-config-file.com"
355
- end
356
-
357
- context "without asset_host set in the shakapacker.yml" do
358
- it "returns ActionController::Base.helpers.compute_asset_host if SHAKAPACKER_ASSET_HOST is not set" do
359
- expect(config).to receive(:fetch).with(:asset_host).and_return(nil)
360
- expect(ActionController::Base.helpers).to receive(:compute_asset_host).and_return("domain.abc")
361
- allow(ENV).to receive(:fetch).with("SHAKAPACKER_ASSET_HOST", "domain.abc").and_return("domain.abc")
362
-
363
- expect(config.asset_host).to eq "domain.abc"
364
- end
365
-
366
- context "without ActionController::Base.helpers.compute_asset_host returing any value" do
367
- it "returns nil" do
368
- expect(ENV).to receive(:fetch).with("SHAKAPACKER_ASSET_HOST", nil).and_return(nil)
369
-
370
- expect(config.asset_host).to be nil
371
- end
372
- end
373
- end
374
- end
375
- end
376
-
377
- end
@@ -1,136 +0,0 @@
1
- require_relative "spec_helper_initializer"
2
- require "shakapacker/dev_server_runner"
3
-
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
-
12
- before do
13
- @original_node_env, ENV["NODE_ENV"] = ENV["NODE_ENV"], "development"
14
- @original_rails_env, ENV["RAILS_ENV"] = ENV["RAILS_ENV"], "development"
15
- @original_shakapacker_config = ENV["SHAKAPACKER_CONFIG"]
16
- end
17
-
18
- after do
19
- ENV["NODE_ENV"] = @original_node_env
20
- ENV["RAILS_ENV"] = @original_rails_env
21
- ENV["SHAKAPACKER_CONFIG"] = @original_shakapacker_config
22
- end
23
-
24
- let(:test_app_path) { Dir.pwd }
25
-
26
- NODE_PACKAGE_MANAGERS.each do |fallback_manager|
27
- context "when using package_json with #{fallback_manager} as the manager" do
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"
32
-
33
- PackageJson.read.merge! { { "packageManager" => "#{manager_name}@#{manager_version}" } }
34
-
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) }
39
-
40
- it "uses the expected package manager", unless: fallback_manager == "yarn_classic" do
41
- cmd = package_json.manager.native_exec_command("webpack", ["serve", "--config", "#{test_app_path}/config/webpack/webpack.config.js"])
42
-
43
- manager_name = fallback_manager.split("_")[0]
44
-
45
- expect(cmd).to start_with(manager_name)
46
- end
47
-
48
- it "runs the command using the manager" do
49
- cmd = package_json.manager.native_exec_command("webpack", ["serve", "--config", "#{test_app_path}/config/webpack/webpack.config.js"])
50
-
51
- verify_command(cmd)
52
- end
53
-
54
- it "passes on arguments" do
55
- cmd = package_json.manager.native_exec_command("webpack", ["serve", "--config", "#{test_app_path}/config/webpack/webpack.config.js", "--quiet"])
56
-
57
- verify_command(cmd, argv: (["--quiet"]))
58
- end
59
-
60
- it "does not automatically pass the --https flag" do
61
- cmd = package_json.manager.native_exec_command("webpack", ["serve", "--config", "#{test_app_path}/config/webpack/webpack.config.js"])
62
-
63
- allow(Shakapacker::DevServer).to receive(:new).and_return(
64
- double(
65
- host: "localhost",
66
- port: "3035",
67
- pretty?: false,
68
- protocol: "https",
69
- hmr?: true
70
- )
71
- )
72
-
73
- verify_command(cmd)
74
- end
75
-
76
- it "supports the https flag" do
77
- cmd = package_json.manager.native_exec_command("webpack", ["serve", "--config", "#{test_app_path}/config/webpack/webpack.config.js", "--https"])
78
-
79
- allow(Shakapacker::DevServer).to receive(:new).and_return(
80
- double(
81
- host: "localhost",
82
- port: "3035",
83
- pretty?: false,
84
- protocol: "https",
85
- hmr?: true
86
- )
87
- )
88
-
89
- verify_command(cmd, argv: ["--https"])
90
- end
91
-
92
- it "supports disabling hot module reloading" do
93
- cmd = package_json.manager.native_exec_command("webpack", ["serve", "--config", "#{test_app_path}/config/webpack/webpack.config.js", "--no-hot"])
94
-
95
- allow(Shakapacker::DevServer).to receive(:new).and_return(
96
- double(
97
- host: "localhost",
98
- port: "3035",
99
- pretty?: false,
100
- protocol: "http",
101
- hmr?: false
102
- )
103
- )
104
-
105
- verify_command(cmd)
106
- end
107
-
108
- it "accepts environment variables" do
109
- cmd = package_json.manager.native_exec_command("webpack", ["serve", "--config", "#{test_app_path}/config/webpack/webpack.config.js"])
110
-
111
- env = Shakapacker::Compiler.env.dup
112
- ENV["SHAKAPACKER_CONFIG"] = env["SHAKAPACKER_CONFIG"] = "#{test_app_path}/config/shakapacker_other_location.yml"
113
- env["WEBPACK_SERVE"] = "true"
114
-
115
- verify_command(cmd, env: env)
116
- end
117
- end
118
- end
119
-
120
- private
121
-
122
- def verify_command(cmd, argv: [], env: Shakapacker::Compiler.env)
123
- Dir.chdir(test_app_path) do
124
- klass = Shakapacker::DevServerRunner
125
- instance = klass.new(argv)
126
-
127
- allow(klass).to receive(:new).and_return(instance)
128
- allow(Kernel).to receive(:exec).with(env, *cmd)
129
-
130
- klass.run(argv)
131
-
132
- expect(Kernel).to have_received(:exec).with(env, *cmd)
133
- expect(Shakapacker::Utils::Manager).to have_received(:error_unless_package_manager_is_obvious!)
134
- end
135
- end
136
- end
@@ -1,118 +0,0 @@
1
- require_relative "spec_helper_initializer"
2
-
3
- describe "DevServer" do
4
- it "doesn't run by default" do
5
- expect(Shakapacker.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(Shakapacker.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(Shakapacker.dev_server.port).to eq 3035
17
- end
18
- end
19
-
20
- it "uses http protocol in development environment" do
21
- with_rails_env("development") do
22
- expect(Shakapacker.dev_server.protocol).to eq "http"
23
- end
24
- end
25
-
26
- it "sets host_with_port to localhost:3035 in development environment" do
27
- with_rails_env("development") do
28
- expect(Shakapacker.dev_server.host_with_port).to eq "localhost:3035"
29
- end
30
- end
31
-
32
- it "doesn't use pretty in development environment" do
33
- with_rails_env("development") do
34
- expect(Shakapacker.dev_server.pretty?).to be false
35
- end
36
- end
37
-
38
- it "uses SHAKAPACKER_DEV_SERVER for DEFAULT_ENV_PREFIX" do
39
- expect(Shakapacker::DevServer::DEFAULT_ENV_PREFIX).to eq "SHAKAPACKER_DEV_SERVER"
40
- end
41
-
42
- context "#protocol in development environment" do
43
- let(:dev_server) { Shakapacker.dev_server }
44
-
45
- it "returns `http` by default (with unset `server`)" do
46
- with_rails_env("development") do
47
- expect(dev_server.protocol).to eq "http"
48
- end
49
- end
50
-
51
- it "returns `https` when `server` is set to `https`" do
52
- expect(dev_server).to receive(:server).and_return("https")
53
-
54
- with_rails_env("development") do
55
- expect(dev_server.protocol).to eq "https"
56
- end
57
- end
58
- end
59
-
60
- context "#server in development environment" do
61
- let(:dev_server) { Shakapacker.dev_server }
62
-
63
- it "returns `http` when unset" do
64
- expect(dev_server).to receive(:fetch).with(:server).and_return(nil)
65
-
66
- with_rails_env("development") do
67
- expect(dev_server.server).to eq "http"
68
- end
69
- end
70
-
71
- it "returns `http` when set to `https`" do
72
- expect(dev_server).to receive(:fetch).with(:server).and_return("http")
73
-
74
- with_rails_env("development") do
75
- expect(dev_server.server).to eq "http"
76
- end
77
- end
78
-
79
- it "returns `http` when set to a hash with `type: http`" do
80
- expect(dev_server).to receive(:fetch).with(:server).and_return({
81
- type: "http",
82
- options: {}
83
- })
84
-
85
- with_rails_env("development") do
86
- expect(dev_server.server).to eq "http"
87
- end
88
- end
89
-
90
- it "returns `https` when set to `https`" do
91
- expect(dev_server).to receive(:fetch).with(:server).and_return("https")
92
-
93
- with_rails_env("development") do
94
- expect(dev_server.server).to eq "https"
95
- end
96
- end
97
-
98
- it "returns `https` when set to a hash with `type: https`" do
99
- expect(dev_server).to receive(:fetch).with(:server).and_return({
100
- type: "https",
101
- options: {}
102
- })
103
-
104
- with_rails_env("development") do
105
- expect(dev_server.server).to eq "https"
106
- end
107
- end
108
-
109
- it "returns `http` when set to any value except `http` and `https`" do
110
- expect(dev_server).to receive(:fetch).twice.with(:server).and_return("other-than-https")
111
-
112
- with_rails_env("development") do
113
- expect(dev_server.server).to eq "http"
114
- expect { dev_server.server }.to output(/WARNING/).to_stdout
115
- end
116
- end
117
- end
118
- end
@@ -1,59 +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 = Shakapacker::DigestStrategy.new
12
- remove_compilation_digest_path
13
- end
14
-
15
- after :all do
16
- remove_compilation_digest_path
17
- end
18
-
19
- it "is not fresh before compilation" do
20
- expect(@digest_strategy.stale?).to be true
21
- expect(@digest_strategy.fresh?).to be_falsy
22
- end
23
-
24
- it "is fresh after compilation" do
25
- @digest_strategy.after_compile_hook
26
-
27
- expect(@digest_strategy.stale?).to be false
28
- expect(@digest_strategy.fresh?).to be true
29
- end
30
-
31
- it "is stale when host changes" do
32
- allow(ENV).to receive(:fetch).with("SHAKAPACKER_ASSET_HOST", nil).and_return("old-host")
33
- # Record the digests for old-host
34
- @digest_strategy.after_compile_hook
35
-
36
- allow(ENV).to receive(:fetch).with("SHAKAPACKER_ASSET_HOST", nil).and_return("new-host")
37
- expect(@digest_strategy.stale?).to be true
38
- expect(@digest_strategy.fresh?).to be_falsey
39
- end
40
-
41
- it "generates correct compilation_digest_path" do
42
- allow(ENV).to receive(:fetch).with("SHAKAPACKER_ASSET_HOST", nil).and_return("custom-path")
43
-
44
- actual_path = @digest_strategy.send(:compilation_digest_path).basename.to_s
45
- host_hash = Digest::SHA1.hexdigest("custom-path")
46
- expected_path = "last-compilation-digest-#{Shakapacker.env}"
47
-
48
- expect(actual_path).to eq expected_path
49
- end
50
-
51
- it "generates correct compilation_digest_path without the digest of the asset host if asset host is not set" do
52
- allow(ENV).to receive(:fetch).with("SHAKAPACKER_ASSET_HOST", nil).and_return(nil)
53
-
54
- actual_path = @digest_strategy.send(:compilation_digest_path).basename.to_s
55
- expected_path = "last-compilation-digest-#{Shakapacker.env}"
56
-
57
- expect(actual_path).to eq expected_path
58
- end
59
- end