shakapacker 6.6.0 → 7.0.0.rc.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (323) hide show
  1. checksums.yaml +4 -4
  2. data/.github/PULL_REQUEST_TEMPLATE.md +4 -8
  3. data/.github/workflows/dummy.yml +21 -0
  4. data/.github/workflows/generator.yml +37 -0
  5. data/.github/workflows/jest.yml +2 -2
  6. data/.github/workflows/js-lint.yml +2 -2
  7. data/.github/workflows/rubocop.yml +1 -1
  8. data/.github/workflows/ruby-backward-compatibility.yml +39 -0
  9. data/.github/workflows/ruby.yml +2 -6
  10. data/.gitignore +3 -0
  11. data/CHANGELOG.md +48 -4
  12. data/CONTRIBUTING.md +78 -22
  13. data/Gemfile.development_dependencies +1 -1
  14. data/README.md +115 -88
  15. data/Rakefile +46 -5
  16. data/config/shakapacker.yml +1 -0
  17. data/docs/deployment.md +11 -10
  18. data/docs/{developing_webpacker.md → developing_shakapacker.md} +5 -5
  19. data/docs/react.md +10 -6
  20. data/docs/style_loader_vs_mini_css.md +2 -2
  21. data/docs/troubleshooting.md +22 -18
  22. data/docs/using_esbuild_loader.md +5 -3
  23. data/docs/using_swc_loader.md +2 -2
  24. data/docs/v6_upgrade.md +2 -2
  25. data/docs/v7_upgrade.md +56 -0
  26. data/lib/install/bin/shakapacker +13 -0
  27. data/lib/install/bin/shakapacker-dev-server +13 -0
  28. data/lib/install/binstubs.rb +3 -1
  29. data/lib/install/config/{webpacker.yml → shakapacker.yml} +13 -8
  30. data/lib/install/config/webpack/webpack.config.js +3 -2
  31. data/lib/install/template.rb +30 -18
  32. data/lib/{webpacker → shakapacker}/base_strategy.rb +2 -2
  33. data/lib/{webpacker → shakapacker}/commands.rb +4 -4
  34. data/lib/{webpacker → shakapacker}/compiler.rb +43 -15
  35. data/lib/{webpacker → shakapacker}/compiler_strategy.rb +6 -6
  36. data/lib/{webpacker → shakapacker}/configuration.rb +52 -21
  37. data/lib/shakapacker/deprecation_helper.rb +87 -0
  38. data/lib/{webpacker → shakapacker}/dev_server.rb +27 -4
  39. data/lib/{webpacker → shakapacker}/dev_server_proxy.rb +4 -4
  40. data/lib/shakapacker/dev_server_runner.rb +104 -0
  41. data/lib/{webpacker → shakapacker}/digest_strategy.rb +6 -6
  42. data/lib/{webpacker → shakapacker}/env.rb +8 -8
  43. data/lib/{webpacker → shakapacker}/helper.rb +20 -20
  44. data/lib/{webpacker → shakapacker}/instance.rb +13 -10
  45. data/lib/{webpacker → shakapacker}/manifest.rb +14 -14
  46. data/lib/{webpacker → shakapacker}/mtime_strategy.rb +5 -5
  47. data/lib/shakapacker/railtie.rb +70 -0
  48. data/lib/shakapacker/runner.rb +28 -0
  49. data/lib/shakapacker/utils/version_syntax_converter.rb +2 -2
  50. data/lib/{webpacker → shakapacker}/version.rb +2 -2
  51. data/lib/{webpacker → shakapacker}/version_checker.rb +8 -8
  52. data/lib/shakapacker/webpack_runner.rb +67 -0
  53. data/lib/shakapacker.rb +51 -1
  54. data/lib/tasks/shakapacker/binstubs.rake +15 -0
  55. data/lib/tasks/shakapacker/check_binstubs.rake +29 -0
  56. data/lib/tasks/shakapacker/check_node.rake +31 -0
  57. data/lib/tasks/shakapacker/check_yarn.rake +33 -0
  58. data/lib/tasks/shakapacker/clean.rake +23 -0
  59. data/lib/tasks/shakapacker/clobber.rake +18 -0
  60. data/lib/tasks/shakapacker/compile.rake +26 -0
  61. data/lib/tasks/shakapacker/info.rake +21 -0
  62. data/lib/tasks/shakapacker/install.rake +17 -0
  63. data/lib/tasks/shakapacker/verify_config.rake +12 -0
  64. data/lib/tasks/shakapacker/verify_install.rake +4 -0
  65. data/lib/tasks/shakapacker/yarn_install.rake +24 -0
  66. data/lib/tasks/shakapacker.rake +18 -0
  67. data/lib/tasks/webpacker/binstubs.rake +5 -11
  68. data/lib/tasks/webpacker/check_binstubs.rake +6 -9
  69. data/lib/tasks/webpacker/check_node.rake +5 -27
  70. data/lib/tasks/webpacker/check_yarn.rake +5 -29
  71. data/lib/tasks/webpacker/clean.rake +5 -19
  72. data/lib/tasks/webpacker/clobber.rake +6 -13
  73. data/lib/tasks/webpacker/compile.rake +5 -33
  74. data/lib/tasks/webpacker/info.rake +5 -17
  75. data/lib/tasks/webpacker/install.rake +5 -13
  76. data/lib/tasks/webpacker/verify_config.rake +6 -11
  77. data/lib/tasks/webpacker/verify_install.rake +7 -2
  78. data/lib/tasks/webpacker/yarn_install.rake +5 -20
  79. data/lib/tasks/webpacker.rake +15 -13
  80. data/lib/webpacker/dev_server_runner.rb +9 -96
  81. data/lib/webpacker/webpack_runner.rb +9 -58
  82. data/lib/webpacker.rb +3 -47
  83. data/package/__tests__/config-bc.js +27 -0
  84. data/package/__tests__/config.js +6 -5
  85. data/package/__tests__/dev_server-bc.js +46 -0
  86. data/package/__tests__/dev_server.js +9 -8
  87. data/package/__tests__/development-bc.js +66 -0
  88. data/package/__tests__/development.js +36 -5
  89. data/package/__tests__/env-bc.js +59 -0
  90. data/package/__tests__/env.js +3 -2
  91. data/package/__tests__/index.js +13 -0
  92. data/package/__tests__/production-bc.js +51 -0
  93. data/package/__tests__/production.js +25 -3
  94. data/package/__tests__/staging-bc.js +53 -0
  95. data/package/__tests__/staging.js +27 -4
  96. data/package/__tests__/test-bc.js +43 -0
  97. data/package/__tests__/test.js +22 -4
  98. data/package/babel/preset.js +1 -4
  99. data/package/config.js +25 -7
  100. data/package/dev_server.js +7 -4
  101. data/package/env.js +22 -3
  102. data/package/environments/__tests__/base-bc.js +107 -0
  103. data/package/environments/__tests__/base.js +13 -13
  104. data/package/environments/base.js +1 -1
  105. data/package/environments/development.js +4 -46
  106. data/package/environments/production.js +1 -1
  107. data/package/index.js +27 -4
  108. data/package/rules/__tests__/__utils__/webpack.js +1 -1
  109. data/package/rules/__tests__/file.js +27 -0
  110. data/package/rules/__tests__/swc.js +1 -2
  111. data/package/rules/file.js +2 -2
  112. data/package/utils/configPath.js +19 -0
  113. data/package/utils/defaultConfigPath.js +2 -0
  114. data/package/utils/get_style_rule.js +5 -2
  115. data/package/utils/helpers.js +25 -2
  116. data/package/utils/inliningCss.js +7 -0
  117. data/package/utils/snakeToCamelCase +7 -0
  118. data/package/webpackDevServerConfig.js +68 -0
  119. data/package.json +2 -2
  120. data/{webpacker.gemspec → shakapacker.gemspec} +3 -3
  121. data/spec/{command_spec.rb → backward_compatibility_specs/command_spec.rb} +2 -0
  122. data/spec/{compiler_spec.rb → backward_compatibility_specs/compiler_spec.rb} +6 -4
  123. data/spec/{compiler_strategy_spec.rb → backward_compatibility_specs/compiler_strategy_spec.rb} +2 -0
  124. data/spec/{configuration_spec.rb → backward_compatibility_specs/configuration_spec.rb} +25 -20
  125. data/spec/{dev_server_runner_spec.rb → backward_compatibility_specs/dev_server_runner_spec.rb} +10 -2
  126. data/spec/{dev_server_spec.rb → backward_compatibility_specs/dev_server_spec.rb} +4 -2
  127. data/spec/{digest_strategy_spec.rb → backward_compatibility_specs/digest_strategy_spec.rb} +2 -0
  128. data/spec/{engine_rake_tasks_spec.rb → backward_compatibility_specs/engine_rake_tasks_spec.rb} +12 -15
  129. data/spec/{env_spec.rb → backward_compatibility_specs/env_spec.rb} +3 -1
  130. data/spec/{helper_spec.rb → backward_compatibility_specs/helper_spec.rb} +2 -0
  131. data/spec/backward_compatibility_specs/instance_spec.rb +31 -0
  132. data/spec/{manifest_spec.rb → backward_compatibility_specs/manifest_spec.rb} +4 -2
  133. data/spec/{mtime_strategy_spec.rb → backward_compatibility_specs/mtime_strategy_spec.rb} +2 -0
  134. data/spec/backward_compatibility_specs/rake_tasks_spec.rb +37 -0
  135. data/spec/backward_compatibility_specs/spec_helper_initializer.rb +24 -0
  136. data/spec/{webpack_runner_spec.rb → backward_compatibility_specs/webpack_runner_spec.rb} +3 -1
  137. data/spec/{webpacker_spec.rb → backward_compatibility_specs/webpacker_spec.rb} +3 -23
  138. data/spec/backward_compatibility_specs/webpacker_test_app/.gitignore +2 -0
  139. data/spec/{test_app → backward_compatibility_specs/webpacker_test_app}/app/packs/entrypoints/application.js +1 -1
  140. data/{lib/install → spec/backward_compatibility_specs/webpacker_test_app}/bin/webpacker +0 -0
  141. data/spec/backward_compatibility_specs/webpacker_test_app/config/application.rb +11 -0
  142. data/spec/{test_app → backward_compatibility_specs/webpacker_test_app}/config/webpacker.yml +1 -1
  143. data/spec/{test_app → backward_compatibility_specs/webpacker_test_app}/config/webpacker_css_extract_ignore_order_warnings.yml +1 -1
  144. data/spec/{test_app → backward_compatibility_specs/webpacker_test_app}/config/webpacker_defaults_fallback.yml +1 -1
  145. data/spec/backward_compatibility_specs/webpacker_test_app/config/webpacker_no_precompile.yml +7 -0
  146. data/spec/{test_app → backward_compatibility_specs/webpacker_test_app}/config/webpacker_other_location.yml +1 -1
  147. data/spec/{test_app → backward_compatibility_specs/webpacker_test_app}/config/webpacker_public_root.yml +1 -1
  148. data/spec/backward_compatibility_specs/webpacker_test_app/package.json +13 -0
  149. data/spec/backward_compatibility_specs/webpacker_test_app/tmp/shakapacker/last-compilation-digest-production +1 -0
  150. data/spec/dummy/.browserslistrc +1 -0
  151. data/spec/dummy/.gitignore +20 -0
  152. data/spec/dummy/.prettierrc.yaml +4 -0
  153. data/spec/dummy/Gemfile +63 -0
  154. data/spec/dummy/Procfile.dev +5 -0
  155. data/spec/dummy/Procfile.dev-static +9 -0
  156. data/spec/dummy/README.md +1 -0
  157. data/spec/dummy/Rakefile +6 -0
  158. data/spec/dummy/app/assets/config/manifest.js +2 -0
  159. data/spec/dummy/app/assets/images/.keep +0 -0
  160. data/spec/dummy/app/assets/stylesheets/application.css +15 -0
  161. data/spec/dummy/app/channels/application_cable/channel.rb +4 -0
  162. data/spec/dummy/app/channels/application_cable/connection.rb +4 -0
  163. data/spec/dummy/app/controllers/application_controller.rb +2 -0
  164. data/spec/dummy/app/controllers/concerns/.keep +0 -0
  165. data/spec/dummy/app/controllers/hello_world_controller.rb +9 -0
  166. data/spec/dummy/app/helpers/application_helper.rb +2 -0
  167. data/spec/dummy/app/javascript/Globals.d.ts +3 -0
  168. data/spec/dummy/app/javascript/bundles/HelloWorld/components/HelloWorld.module.css +25 -0
  169. data/spec/dummy/app/javascript/bundles/HelloWorld/components/HelloWorld.tsx +47 -0
  170. data/spec/dummy/app/javascript/bundles/HelloWorld/components/HelloWorldServer.tsx +5 -0
  171. data/spec/dummy/app/javascript/bundles/HelloWorld/components/logo.svg +7 -0
  172. data/spec/dummy/app/javascript/packs/application.js +17 -0
  173. data/spec/dummy/app/javascript/packs/hello-world-bundle.ts +8 -0
  174. data/spec/dummy/app/javascript/packs/server-bundle.ts +8 -0
  175. data/spec/dummy/app/jobs/application_job.rb +7 -0
  176. data/spec/dummy/app/mailers/application_mailer.rb +4 -0
  177. data/spec/dummy/app/models/application_record.rb +3 -0
  178. data/spec/dummy/app/models/concerns/.keep +0 -0
  179. data/spec/dummy/app/views/hello_world/index.html.erb +2 -0
  180. data/spec/dummy/app/views/layouts/application.html.erb +14 -0
  181. data/spec/dummy/app/views/layouts/hello_world.html.erb +13 -0
  182. data/spec/dummy/app/views/layouts/mailer.html.erb +13 -0
  183. data/spec/dummy/app/views/layouts/mailer.text.erb +1 -0
  184. data/spec/dummy/babel.config.js +30 -0
  185. data/spec/dummy/bin/bundle +114 -0
  186. data/spec/dummy/bin/dev +30 -0
  187. data/spec/dummy/bin/dev-static +30 -0
  188. data/spec/dummy/bin/rails +9 -0
  189. data/spec/dummy/bin/rake +9 -0
  190. data/spec/dummy/bin/setup +33 -0
  191. data/spec/dummy/bin/shakapacker +13 -0
  192. data/spec/dummy/bin/shakapacker-dev-server +13 -0
  193. data/spec/dummy/bin/spring +17 -0
  194. data/spec/dummy/bin/yarn +18 -0
  195. data/spec/dummy/config/application.rb +32 -0
  196. data/spec/dummy/config/boot.rb +4 -0
  197. data/spec/dummy/config/cable.yml +10 -0
  198. data/spec/dummy/config/credentials.yml.enc +1 -0
  199. data/spec/dummy/config/database.yml +25 -0
  200. data/spec/dummy/config/environment.rb +5 -0
  201. data/spec/dummy/config/environments/development.rb +54 -0
  202. data/spec/dummy/config/environments/production.rb +106 -0
  203. data/spec/dummy/config/environments/test.rb +49 -0
  204. data/spec/dummy/config/initializers/application_controller_renderer.rb +8 -0
  205. data/spec/dummy/config/initializers/backtrace_silencers.rb +7 -0
  206. data/spec/dummy/config/initializers/content_security_policy.rb +28 -0
  207. data/spec/dummy/config/initializers/cookies_serializer.rb +5 -0
  208. data/spec/dummy/config/initializers/filter_parameter_logging.rb +4 -0
  209. data/spec/dummy/config/initializers/inflections.rb +16 -0
  210. data/spec/dummy/config/initializers/mime_types.rb +4 -0
  211. data/spec/dummy/config/initializers/react_on_rails.rb +58 -0
  212. data/spec/dummy/config/initializers/wrap_parameters.rb +14 -0
  213. data/spec/dummy/config/locales/en.yml +33 -0
  214. data/spec/dummy/config/puma.rb +38 -0
  215. data/spec/dummy/config/routes.rb +6 -0
  216. data/spec/dummy/config/shakapacker.yml +62 -0
  217. data/spec/dummy/config/spring.rb +6 -0
  218. data/spec/dummy/config/storage.yml +34 -0
  219. data/spec/dummy/config/webpack/ServerClientOrBoth.js +34 -0
  220. data/spec/dummy/config/webpack/clientWebpackConfig.js +15 -0
  221. data/spec/dummy/config/webpack/commonWebpackConfig.js +18 -0
  222. data/spec/dummy/config/webpack/development.js +32 -0
  223. data/spec/dummy/config/webpack/production.js +9 -0
  224. data/spec/dummy/config/webpack/serverWebpackConfig.js +116 -0
  225. data/spec/dummy/config/webpack/test.js +7 -0
  226. data/spec/dummy/config/webpack/webpack.config.js +24 -0
  227. data/spec/dummy/config.ru +5 -0
  228. data/spec/dummy/db/seeds.rb +7 -0
  229. data/spec/dummy/lib/assets/.keep +0 -0
  230. data/spec/dummy/lib/tasks/.keep +0 -0
  231. data/spec/dummy/package.json +44 -0
  232. data/spec/dummy/postcss.config.js +12 -0
  233. data/spec/dummy/public/404.html +67 -0
  234. data/spec/dummy/public/422.html +67 -0
  235. data/spec/dummy/public/500.html +66 -0
  236. data/spec/dummy/public/apple-touch-icon-precomposed.png +0 -0
  237. data/spec/dummy/public/apple-touch-icon.png +0 -0
  238. data/spec/dummy/public/favicon.ico +0 -0
  239. data/spec/dummy/public/robots.txt +1 -0
  240. data/spec/dummy/spec/rails_helper.rb +118 -0
  241. data/spec/dummy/spec/spec_helper.rb +96 -0
  242. data/spec/dummy/spec/system/hello_world_spec.rb +19 -0
  243. data/spec/dummy/tsconfig.json +21 -0
  244. data/spec/dummy/vendor/.keep +0 -0
  245. data/spec/dummy/yarn.lock +4697 -0
  246. data/spec/generator_specs/e2e_template/files/app/controllers/home_controller.rb +4 -0
  247. data/spec/generator_specs/e2e_template/files/app/javascript/components/App.js +12 -0
  248. data/spec/generator_specs/e2e_template/files/app/javascript/packs/application.js +10 -0
  249. data/spec/generator_specs/e2e_template/files/app/views/home/index.html.erb +2 -0
  250. data/spec/generator_specs/e2e_template/files/app/views/layouts/application.html.erb +17 -0
  251. data/spec/generator_specs/e2e_template/files/config/routes.rb +3 -0
  252. data/spec/generator_specs/e2e_template/files/spec/system/test_react_component_renders_spec.rb +13 -0
  253. data/spec/generator_specs/e2e_template/template.rb +21 -0
  254. data/spec/generator_specs/generator_spec.rb +169 -0
  255. data/spec/mounted_app/test/dummy/config/application.rb +1 -1
  256. data/spec/mounted_app/test/dummy/config/webpacker.yml +3 -3
  257. data/spec/shakapacker/command_spec.rb +116 -0
  258. data/spec/shakapacker/compiler_spec.rb +59 -0
  259. data/spec/shakapacker/compiler_strategy_spec.rb +22 -0
  260. data/spec/shakapacker/configuration_spec.rb +323 -0
  261. data/spec/shakapacker/dev_server_runner_spec.rb +72 -0
  262. data/spec/shakapacker/dev_server_spec.rb +133 -0
  263. data/spec/shakapacker/digest_strategy_spec.rb +35 -0
  264. data/spec/shakapacker/engine_rake_tasks_spec.rb +43 -0
  265. data/spec/shakapacker/env_spec.rb +23 -0
  266. data/spec/shakapacker/helper_spec.rb +243 -0
  267. data/spec/shakapacker/instance_spec.rb +31 -0
  268. data/spec/shakapacker/manifest_spec.rb +100 -0
  269. data/spec/shakapacker/mtime_strategy_spec.rb +55 -0
  270. data/spec/shakapacker/rake_tasks_spec.rb +93 -0
  271. data/spec/shakapacker/shakapacker_spec.rb +41 -0
  272. data/spec/shakapacker/spec_helper_initializer.rb +24 -0
  273. data/spec/shakapacker/test_app/.gitignore +2 -0
  274. data/spec/shakapacker/test_app/Rakefile +3 -0
  275. data/spec/shakapacker/test_app/app/javascript/entrypoints/application.js +10 -0
  276. data/spec/shakapacker/test_app/app/javascript/entrypoints/generated/something.js +2 -0
  277. data/spec/shakapacker/test_app/app/javascript/entrypoints/multi_entry.css +4 -0
  278. data/spec/shakapacker/test_app/app/javascript/entrypoints/multi_entry.js +4 -0
  279. data/spec/{test_app/bin/webpacker-dev-server → shakapacker/test_app/bin/shakapacker} +3 -3
  280. data/spec/{test_app/bin/webpacker → shakapacker/test_app/bin/shakapacker-dev-server} +3 -3
  281. data/spec/{test_app → shakapacker/test_app}/config/application.rb +1 -1
  282. data/spec/shakapacker/test_app/config/environment.rb +4 -0
  283. data/spec/shakapacker/test_app/config/initializers/inspect_autoload_paths.rb +1 -0
  284. data/spec/shakapacker/test_app/config/shakapacker.yml +82 -0
  285. data/spec/shakapacker/test_app/config/shakapacker_css_extract_ignore_order_warnings.yml +84 -0
  286. data/spec/shakapacker/test_app/config/shakapacker_defaults_fallback.yml +11 -0
  287. data/spec/shakapacker/test_app/config/shakapacker_manifest_path.yml +80 -0
  288. data/spec/shakapacker/test_app/config/shakapacker_nested_entries.yml +83 -0
  289. data/spec/shakapacker/test_app/config/shakapacker_no_precompile.yml +7 -0
  290. data/spec/shakapacker/test_app/config/shakapacker_other_location.yml +85 -0
  291. data/spec/shakapacker/test_app/config/shakapacker_public_root.yml +18 -0
  292. data/spec/shakapacker/test_app/config/webpack/webpack.config.js +0 -0
  293. data/spec/shakapacker/test_app/config.ru +5 -0
  294. data/spec/shakapacker/test_app/public/packs/manifest.json +58 -0
  295. data/spec/shakapacker/test_app/some.config.js +0 -0
  296. data/spec/shakapacker/test_app/yarn.lock +11 -0
  297. data/spec/{version_checker_spec.rb → shakapacker/version_checker_spec.rb} +25 -24
  298. data/spec/shakapacker/webpack_runner_spec.rb +55 -0
  299. data/spec/spec_helper.rb +0 -25
  300. metadata +253 -72
  301. data/config/webpacker.yml +0 -1
  302. data/gemfiles/Gemfile-rails.5.2.x +0 -9
  303. data/lib/webpacker/railtie.rb +0 -70
  304. data/lib/webpacker/runner.rb +0 -23
  305. data/package/configPath.js +0 -3
  306. data/package/inliningCss.js +0 -7
  307. data/spec/rake_tasks_spec.rb +0 -32
  308. data/spec/test_app/config/webpacker_no_precompile.yml +0 -7
  309. /data/spec/{test_app → backward_compatibility_specs/webpacker_test_app}/Rakefile +0 -0
  310. /data/spec/{test_app → backward_compatibility_specs/webpacker_test_app}/app/packs/entrypoints/generated/something.js +0 -0
  311. /data/spec/{test_app → backward_compatibility_specs/webpacker_test_app}/app/packs/entrypoints/multi_entry.css +0 -0
  312. /data/spec/{test_app → backward_compatibility_specs/webpacker_test_app}/app/packs/entrypoints/multi_entry.js +0 -0
  313. /data/{lib/install → spec/backward_compatibility_specs/webpacker_test_app}/bin/webpacker-dev-server +0 -0
  314. /data/spec/{test_app → backward_compatibility_specs/webpacker_test_app}/config/environment.rb +0 -0
  315. /data/spec/{test_app → backward_compatibility_specs/webpacker_test_app}/config/initializers/inspect_autoload_paths.rb +0 -0
  316. /data/spec/{test_app → backward_compatibility_specs/webpacker_test_app}/config/webpack/webpack.config.js +0 -0
  317. /data/spec/{test_app → backward_compatibility_specs/webpacker_test_app}/config/webpacker_manifest_path.yml +0 -0
  318. /data/spec/{test_app → backward_compatibility_specs/webpacker_test_app}/config/webpacker_nested_entries.yml +0 -0
  319. /data/spec/{test_app → backward_compatibility_specs/webpacker_test_app}/config.ru +0 -0
  320. /data/spec/{test_app → backward_compatibility_specs/webpacker_test_app}/public/packs/manifest.json +0 -0
  321. /data/spec/{test_app → backward_compatibility_specs/webpacker_test_app}/some.config.js +0 -0
  322. /data/spec/{test_app → backward_compatibility_specs/webpacker_test_app}/yarn.lock +0 -0
  323. /data/spec/{test_app → shakapacker/test_app}/package.json +0 -0
@@ -0,0 +1,243 @@
1
+ require_relative "spec_helper_initializer"
2
+
3
+ module ActionView::TestCase::Behavior
4
+ attr_accessor :request
5
+
6
+ describe "Shakapacker::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 Shakapacker::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 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 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 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 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 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 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 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 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 correct tags by 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 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 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 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 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 correct tags by 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 correct tags by passing 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 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 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 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" 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" 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
@@ -0,0 +1,31 @@
1
+ require_relative "spec_helper_initializer"
2
+
3
+ describe "Shakapacker::Instance" do
4
+ before :each do
5
+ ENV.delete("WEBPACKER_CONFIG")
6
+ ENV.delete("SHAKAPACKER_CONFIG")
7
+ Shakapacker.instance = Shakapacker::Instance.new
8
+ end
9
+
10
+ after :each do
11
+ ENV.delete("WEBPACKER_CONFIG")
12
+ ENV.delete("SHAKAPACKER_CONFIG")
13
+ Shakapacker.instance = Shakapacker::Instance.new
14
+ end
15
+
16
+ it "uses default config path if no env variable defined" do
17
+ actual_config_path = Rails.root.join("config/shakapacker.yml")
18
+ expected_config_path = Shakapacker.config.config_path
19
+
20
+ expect(expected_config_path).to eq(actual_config_path)
21
+ end
22
+
23
+ it "uses SHAKAPACKER_CONFIG env variable for config file" do
24
+ ENV["SHAKAPACKER_CONFIG"] = "/some/random/path.yml"
25
+
26
+ actual_config_path = "/some/random/path.yml"
27
+ expected_config_path = Shakapacker.config.config_path.to_s
28
+
29
+ expect(expected_config_path).to eq(actual_config_path)
30
+ end
31
+ end
@@ -0,0 +1,100 @@
1
+ require_relative "spec_helper_initializer"
2
+
3
+ describe "Shakapacker::Manifest" do
4
+ let(:manifest_path) { File.expand_path File.join(File.dirname(__FILE__), "./test_app/public/packs", "manifest.json").to_s }
5
+
6
+ it "#lookup! throws exception for a non-existing asset file" do
7
+ asset_file = "calendar.js"
8
+ expected_error_message = "Shakapacker can't find #{asset_file} in #{manifest_path}"
9
+
10
+ allow(Shakapacker.config).to receive(:compile?).and_return(false)
11
+
12
+ expect {
13
+ Shakapacker.manifest.lookup!(asset_file)
14
+ }.to raise_error(Shakapacker::Manifest::MissingEntryError, /#{expected_error_message}/)
15
+ end
16
+
17
+ it "#lookup! throws exception for a non-existing asset file with type and without extension" do
18
+ asset_file = "calendar"
19
+ expected_error_message = "Shakapacker can't find #{asset_file}.js in #{manifest_path}"
20
+
21
+ allow(Shakapacker.config).to receive(:compile?).and_return(false)
22
+
23
+ expect {
24
+ Shakapacker.manifest.lookup!(asset_file, type: :javascript)
25
+ }.to raise_error(Shakapacker::Manifest::MissingEntryError, /#{expected_error_message}/)
26
+ end
27
+
28
+ it "#lookup! returns path to bundled bootstrap.js" do
29
+ actual = Shakapacker.manifest.lookup!("bootstrap.js")
30
+ expected = "/packs/bootstrap-300631c4f0e0f9c865bc.js"
31
+
32
+ expect(actual).to eq expected
33
+ end
34
+
35
+ it "#lookup_pack_with_chunks! returns array of path to bundled bootstrap with type of javascript" do
36
+ actual = Shakapacker.manifest.lookup_pack_with_chunks!("bootstrap", type: :javascript)
37
+ expected = ["/packs/bootstrap-300631c4f0e0f9c865bc.js"]
38
+
39
+ expect(actual).to eq expected
40
+ end
41
+
42
+ it "#lookup_with_chunks! returns array of path to bundled bootstrap.js with type of javascript" do
43
+ actual = Shakapacker.manifest.lookup_pack_with_chunks!("bootstrap.js", type: :javascript)
44
+ expected = ["/packs/bootstrap-300631c4f0e0f9c865bc.js"]
45
+
46
+ expect(actual).to eq expected
47
+ end
48
+
49
+ it "#lookup_with_chunks! returns array of path to bundled 'print/application' without extension and in a sub-directory" do
50
+ actual = Shakapacker.manifest.lookup_pack_with_chunks!("print/application", type: :css)
51
+ expected = ["/packs/print/application-983b6c164a47f7ed49cd.css"]
52
+
53
+ expect(actual).to eq expected
54
+ end
55
+
56
+ it "#lookup_with_chunks! returns array of path to bundled 'print/application.css' in a sub-directory" do
57
+ actual = Shakapacker.manifest.lookup_pack_with_chunks!("print/application.css", type: :css)
58
+ expected = ["/packs/print/application-983b6c164a47f7ed49cd.css"]
59
+
60
+ expect(actual).to eq expected
61
+ end
62
+
63
+ it "#lookup returns nil for non-existing asset file" do
64
+ expect(Shakapacker.manifest.lookup("foo.js")).to be nil
65
+ end
66
+
67
+ it "#lookup_pack_with_chunks returns nil for non-existing asset file" do
68
+ expect(Shakapacker.manifest.lookup_pack_with_chunks("foo.js")).to be nil
69
+ end
70
+
71
+ it "#lookup returns path for bootstrap.js" do
72
+ actual = Shakapacker.manifest.lookup("bootstrap.js")
73
+ expected = "/packs/bootstrap-300631c4f0e0f9c865bc.js"
74
+
75
+ expect(actual).to eq expected
76
+ end
77
+
78
+ it "#lookup_pack_with_chunks! throws exception for a non-existing asset file" do
79
+ asset_file = "calendar"
80
+
81
+ expected_error_message = "Shakapacker can't find #{asset_file}.js in #{manifest_path}"
82
+
83
+ allow(Shakapacker.config).to receive(:compile?).and_return(false)
84
+
85
+ expect {
86
+ Shakapacker.manifest.lookup_pack_with_chunks!(asset_file, type: :javascript)
87
+ }.to raise_error(Shakapacker::Manifest::MissingEntryError, /#{expected_error_message}/)
88
+ end
89
+
90
+ it "#lookup_pack_with_chunks! returns array of paths to bundled js files with 'application' in their name" do
91
+ actual_application_entrypoints = Shakapacker.manifest.lookup_pack_with_chunks!("application", type: :javascript)
92
+ expected_application_entrypoints = [
93
+ "/packs/vendors~application~bootstrap-c20632e7baf2c81200d3.chunk.js",
94
+ "/packs/vendors~application-e55f2aae30c07fb6d82a.chunk.js",
95
+ "/packs/application-k344a6d59eef8632c9d1.js"
96
+ ]
97
+
98
+ expect(actual_application_entrypoints).to eq expected_application_entrypoints
99
+ end
100
+ end
@@ -0,0 +1,55 @@
1
+ require_relative "spec_helper_initializer"
2
+
3
+ describe "Shakapacker::MtimeStrategy" do
4
+ let(:mtime_strategy) { Shakapacker::MtimeStrategy.new }
5
+ let(:manifest_timestamp) { Time.parse("2021-01-01 12:34:56 UTC") }
6
+
7
+ describe "#fresh?" do
8
+ it "returns false when manifest is missing" do
9
+ latest_timestamp = manifest_timestamp + 3600
10
+
11
+ with_stubs(latest_timestamp: latest_timestamp.to_i, manifest_exists: false) do
12
+ expect(mtime_strategy.fresh?).to be false
13
+ end
14
+ end
15
+
16
+ it "returns false when manifest is older" do
17
+ latest_timestamp = manifest_timestamp + 3600
18
+
19
+ with_stubs(latest_timestamp: latest_timestamp.to_i) do
20
+ expect(mtime_strategy.fresh?).to be false
21
+ end
22
+ end
23
+
24
+ it "returns true when manifest is new" do
25
+ latest_timestamp = manifest_timestamp - 3600
26
+
27
+ with_stubs(latest_timestamp: latest_timestamp.to_i) do
28
+ expect(mtime_strategy.fresh?).to be true
29
+ end
30
+ end
31
+ end
32
+
33
+ describe "#stale?" do
34
+ it "returns false when #fresh? is true" do
35
+ expect(mtime_strategy).to receive(:fresh?).and_return(true)
36
+
37
+ expect(mtime_strategy.stale?).to be false
38
+ end
39
+
40
+ it "returns true when #fresh? is false" do
41
+ expect(mtime_strategy).to receive(:fresh?).and_return(false)
42
+
43
+ expect(mtime_strategy.stale?).to be true
44
+ end
45
+ end
46
+
47
+ private
48
+
49
+ def with_stubs(latest_timestamp:, manifest_exists: true)
50
+ allow(mtime_strategy).to receive(:latest_modified_timestamp).and_return(latest_timestamp)
51
+ allow(FileTest).to receive(:exist?).and_return(manifest_exists)
52
+ allow(File).to receive(:mtime).and_return(manifest_timestamp)
53
+ yield
54
+ end
55
+ end
@@ -0,0 +1,93 @@
1
+ require_relative "spec_helper_initializer"
2
+
3
+ describe "RakeTasks" do
4
+ TEST_APP_PATH = File.expand_path("./test_app", __dir__)
5
+
6
+ it "`rake -T` lists Shakapacker tasks" do
7
+ output = Dir.chdir(TEST_APP_PATH) { `rake -T` }
8
+ expect(output).to include "shakapacker"
9
+ expect(output).to include "shakapacker:check_binstubs"
10
+ expect(output).to include "shakapacker:check_node"
11
+ expect(output).to include "shakapacker:check_yarn"
12
+ expect(output).to include "shakapacker:clean"
13
+ expect(output).to include "shakapacker:clobber"
14
+ expect(output).to include "shakapacker:compile"
15
+ expect(output).to include "shakapacker:install"
16
+ expect(output).to include "shakapacker:verify_install"
17
+ end
18
+
19
+ it "`shakapacker:check_binstubs` doesn't get 'webpack binstub not found' error" do
20
+ output = Dir.chdir(TEST_APP_PATH) { `rake shakapacker:check_binstubs 2>&1` }
21
+ expect(output).to_not include "webpack binstub not found."
22
+ end
23
+
24
+ it "`shakapacker:check_node` doesn't get 'shakapacker requires Node.js' error" do
25
+ output = Dir.chdir(TEST_APP_PATH) { `rake shakapacker:check_node 2>&1` }
26
+ expect(output).to_not include "Shakapacker requires Node.js"
27
+ end
28
+
29
+ it "`shakapacker:check_yarn` doesn't get error related to yarn" do
30
+ output = Dir.chdir(TEST_APP_PATH) { `rake shakapacker:check_yarn 2>&1` }
31
+ expect(output).to_not include "Yarn not installed"
32
+ expect(output).to_not include "Shakapacker requires Yarn"
33
+ end
34
+
35
+ describe "`shakapacker:check_binstubs`" do
36
+ def with_temporary_file(file_name, &block)
37
+ FileUtils.touch(file_name, verbose: false)
38
+ yield if block_given?
39
+ ensure
40
+ FileUtils.rm_f(file_name, verbose: false)
41
+ end
42
+
43
+ before :all do
44
+ Dir.chdir(TEST_APP_PATH)
45
+ end
46
+
47
+ context "with existing `./bin/shapapacker` and `./bin/shapapacker-dev-server`" do
48
+ it "passes" do
49
+ expect { system("bundle exec rake shakapacker:check_binstubs") }.to output("").to_stdout_from_any_process
50
+ end
51
+ end
52
+
53
+ context "without `./bin/shakapacker`" do
54
+ before :all do
55
+ FileUtils.mv("bin/shakapacker", "bin/shakapacker_renamed")
56
+ end
57
+
58
+ after :all do
59
+ FileUtils.mv("bin/shakapacker_renamed", "bin/shakapacker")
60
+ end
61
+
62
+ it "passes if `./bin/webpacker exist" do
63
+ with_temporary_file("bin/webpacker") do
64
+ expect { system("bundle exec rake shakapacker:check_binstubs") }.to output(/DEPRECATION/).to_stdout_from_any_process
65
+ end
66
+ end
67
+
68
+ it "fails otherwise" do
69
+ expect { system("bundle exec rake shakapacker:check_binstubs") }.to output(/Couldn't find shakapacker binstubs!/).to_stdout_from_any_process
70
+ end
71
+ end
72
+
73
+ context "without `./bin/shakapacker-dev-server`" do
74
+ before :all do
75
+ FileUtils.mv("bin/shakapacker-dev-server", "bin/shakapacker-dev-server_renamed")
76
+ end
77
+
78
+ after :all do
79
+ FileUtils.mv("bin/shakapacker-dev-server_renamed", "bin/shakapacker-dev-server")
80
+ end
81
+
82
+ it "passes if `./bin/webpacker-dev-server exist" do
83
+ with_temporary_file("bin/webpacker-dev-server") do
84
+ expect { system("bundle exec rake shakapacker:check_binstubs") }.to output(/DEPRECATION/).to_stdout_from_any_process
85
+ end
86
+ end
87
+
88
+ it "fails otherwise" do
89
+ expect { system("bundle exec rake shakapacker:check_binstubs") }.to output(/Couldn't find shakapacker binstubs!/).to_stdout_from_any_process
90
+ end
91
+ end
92
+ end
93
+ end
@@ -0,0 +1,41 @@
1
+ require_relative "spec_helper_initializer"
2
+
3
+ describe "Shakapacker" do
4
+ describe "#inline_css?" do
5
+ let(:dev_server) { instance_double("Shakapacker::DevServer") }
6
+
7
+ before :each do
8
+ allow(dev_server).to receive(:host).and_return("localhost")
9
+ allow(dev_server).to receive(:port).and_return("3035")
10
+ allow(dev_server).to receive(:pretty?).and_return(false)
11
+ allow(dev_server).to receive(:https?).and_return(true)
12
+ allow(dev_server).to receive(:running?).and_return(true)
13
+ end
14
+
15
+ it "returns nil with disabled dev_server" do
16
+ expect(Shakapacker.inlining_css?).to be nil
17
+ end
18
+
19
+ it "returns true with enabled hmr" do
20
+ allow(dev_server).to receive(:hmr?).and_return(true)
21
+ allow(dev_server).to receive(:inline_css?).and_return(true)
22
+
23
+ allow(Shakapacker.instance).to receive(:dev_server).and_return(dev_server)
24
+
25
+ expect(Shakapacker.inlining_css?).to be true
26
+ end
27
+
28
+ it "returns false with enabled hmr and explicitly setting inline_css to false" do
29
+ allow(dev_server).to receive(:hmr?).and_return(true)
30
+ allow(dev_server).to receive(:inline_css?).and_return(false)
31
+
32
+ allow(Shakapacker.instance).to receive(:dev_server).and_return(dev_server)
33
+
34
+ expect(Shakapacker.inlining_css?).to be false
35
+ end
36
+ end
37
+
38
+ it "has app_autoload_paths cleanup" do
39
+ expect($test_app_autoload_paths_in_initializer).to eq []
40
+ end
41
+ end
@@ -0,0 +1,24 @@
1
+ require_relative "./test_app/config/environment"
2
+
3
+ Rails.env = "production"
4
+
5
+ Shakapacker.instance = ::Shakapacker::Instance.new
6
+
7
+ def reloaded_config
8
+ Shakapacker.instance.instance_variable_set(:@env, nil)
9
+ Shakapacker.instance.instance_variable_set(:@config, nil)
10
+ Shakapacker.instance.instance_variable_set(:@dev_server, nil)
11
+ Shakapacker.env
12
+ Shakapacker.config
13
+ Shakapacker.dev_server
14
+ end
15
+
16
+ def with_rails_env(env)
17
+ original = Rails.env
18
+ Rails.env = ActiveSupport::StringInquirer.new(env)
19
+ reloaded_config
20
+ yield
21
+ ensure
22
+ Rails.env = ActiveSupport::StringInquirer.new(original)
23
+ reloaded_config
24
+ end
@@ -0,0 +1,2 @@
1
+ log/
2
+ tmp/
@@ -0,0 +1,3 @@
1
+ require_relative "config/application"
2
+
3
+ Rails.application.load_tasks
@@ -0,0 +1,10 @@
1
+ /* eslint no-console:0 */
2
+ // This file is automatically compiled by Webpack, along with any other files
3
+ // present in this directory. You're encouraged to place your actual application logic in
4
+ // a relevant structure within app/javascript and only use these pack files to reference
5
+ // that code so it'll be compiled.
6
+ //
7
+ // To reference this file, add <%= javascript_pack_tag 'application' %> to the appropriate
8
+ // layout file, like app/views/layouts/application.html.erb
9
+
10
+ console.log('Hello World from shakapacker')
@@ -0,0 +1,2 @@
1
+ /* eslint no-console:0 */
2
+ console.log('entrypoints/nested/something')
@@ -0,0 +1,4 @@
1
+ /*
2
+ * Dummy file #1 for Multi File Entry points: https://webpack.js.org/guides/entry-advanced/
3
+ * This file must be named the same
4
+ */
@@ -0,0 +1,4 @@
1
+ /*
2
+ * Dummy file #2 for Multi File Entry points: https://webpack.js.org/guides/entry-advanced/
3
+ * This file must be named the same
4
+ */
@@ -9,6 +9,6 @@ ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../Gemfile",
9
9
 
10
10
  require "bundler/setup"
11
11
 
12
- require "webpacker"
13
- require "webpacker/dev_server_runner"
14
- Webpacker::DevServerRunner.run(ARGV)
12
+ require "shakapacker"
13
+ require "shakapacker/webpack_runner"
14
+ Shakapacker::WebpackRunner.run(ARGV)
@@ -9,6 +9,6 @@ ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../Gemfile",
9
9
 
10
10
  require "bundler/setup"
11
11
 
12
- require "webpacker"
13
- require "webpacker/webpack_runner"
14
- Webpacker::WebpackRunner.run(ARGV)
12
+ require "shakapacker"
13
+ require "shakapacker/dev_server_runner"
14
+ Shakapacker::DevServerRunner.run(ARGV)
@@ -1,6 +1,6 @@
1
1
  require "action_controller/railtie"
2
2
  require "action_view/railtie"
3
- require "webpacker"
3
+ require "shakapacker"
4
4
 
5
5
  module TestApp
6
6
  class Application < ::Rails::Application