shakapacker 6.5.4 → 7.0.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (407) hide show
  1. checksums.yaml +4 -4
  2. data/.eslintrc.js +1 -0
  3. data/.github/FUNDING.yml +1 -0
  4. data/.github/ISSUE_TEMPLATE/bug_report.md +11 -7
  5. data/.github/ISSUE_TEMPLATE/feature_request.md +21 -0
  6. data/.github/PULL_REQUEST_TEMPLATE.md +14 -0
  7. data/.github/workflows/dummy.yml +21 -0
  8. data/.github/workflows/generator.yml +37 -0
  9. data/.github/workflows/jest.yml +2 -2
  10. data/.github/workflows/js-lint.yml +2 -2
  11. data/.github/workflows/rubocop.yml +1 -1
  12. data/.github/workflows/ruby-backward-compatibility.yml +39 -0
  13. data/.github/workflows/ruby.yml +5 -7
  14. data/.gitignore +6 -3
  15. data/.rspec +1 -0
  16. data/CHANGELOG.md +83 -2
  17. data/CONTRIBUTING.md +84 -18
  18. data/Gemfile.development_dependencies +3 -1
  19. data/README.md +159 -97
  20. data/Rakefile +46 -6
  21. data/config/shakapacker.yml +1 -0
  22. data/docs/deployment.md +11 -10
  23. data/docs/{developing_webpacker.md → developing_shakapacker.md} +5 -5
  24. data/docs/react.md +10 -6
  25. data/docs/style_loader_vs_mini_css.md +3 -3
  26. data/docs/troubleshooting.md +22 -18
  27. data/docs/using_esbuild_loader.md +5 -3
  28. data/docs/using_swc_loader.md +2 -2
  29. data/docs/v6_upgrade.md +9 -13
  30. data/docs/v7_upgrade.md +59 -0
  31. data/gemfiles/Gemfile-rails-edge +1 -1
  32. data/gemfiles/Gemfile-rails.6.0.x +1 -1
  33. data/gemfiles/Gemfile-rails.6.1.x +1 -1
  34. data/gemfiles/Gemfile-rails.7.0.x +1 -1
  35. data/lib/install/bin/shakapacker +13 -0
  36. data/lib/install/bin/shakapacker-dev-server +13 -0
  37. data/lib/install/binstubs.rb +3 -1
  38. data/lib/install/config/{webpacker.yml → shakapacker.yml} +28 -11
  39. data/lib/install/config/webpack/webpack.config.js +3 -2
  40. data/lib/install/template.rb +51 -34
  41. data/lib/{webpacker → shakapacker}/base_strategy.rb +2 -2
  42. data/lib/{webpacker → shakapacker}/commands.rb +4 -4
  43. data/lib/{webpacker → shakapacker}/compiler.rb +43 -15
  44. data/lib/{webpacker → shakapacker}/compiler_strategy.rb +6 -6
  45. data/lib/{webpacker → shakapacker}/configuration.rb +52 -21
  46. data/lib/shakapacker/deprecation_helper.rb +87 -0
  47. data/lib/{webpacker → shakapacker}/dev_server.rb +27 -4
  48. data/lib/{webpacker → shakapacker}/dev_server_proxy.rb +4 -4
  49. data/lib/shakapacker/dev_server_runner.rb +104 -0
  50. data/lib/{webpacker → shakapacker}/digest_strategy.rb +6 -6
  51. data/lib/{webpacker → shakapacker}/env.rb +8 -8
  52. data/lib/{webpacker → shakapacker}/helper.rb +40 -29
  53. data/lib/shakapacker/instance.rb +50 -0
  54. data/lib/{webpacker → shakapacker}/manifest.rb +14 -14
  55. data/lib/{webpacker → shakapacker}/mtime_strategy.rb +5 -5
  56. data/lib/shakapacker/railtie.rb +70 -0
  57. data/lib/shakapacker/runner.rb +28 -0
  58. data/lib/shakapacker/utils/version_syntax_converter.rb +2 -2
  59. data/lib/{webpacker → shakapacker}/version.rb +2 -2
  60. data/lib/{webpacker → shakapacker}/version_checker.rb +8 -8
  61. data/lib/shakapacker/webpack_runner.rb +67 -0
  62. data/lib/shakapacker.rb +51 -1
  63. data/lib/tasks/shakapacker/binstubs.rake +15 -0
  64. data/lib/tasks/shakapacker/check_binstubs.rake +29 -0
  65. data/lib/tasks/shakapacker/check_node.rake +31 -0
  66. data/lib/tasks/shakapacker/check_yarn.rake +33 -0
  67. data/lib/tasks/shakapacker/clean.rake +23 -0
  68. data/lib/tasks/shakapacker/clobber.rake +18 -0
  69. data/lib/tasks/shakapacker/compile.rake +28 -0
  70. data/lib/tasks/shakapacker/info.rake +21 -0
  71. data/lib/tasks/shakapacker/install.rake +17 -0
  72. data/lib/tasks/shakapacker/verify_config.rake +12 -0
  73. data/lib/tasks/shakapacker/verify_install.rake +4 -0
  74. data/lib/tasks/shakapacker/yarn_install.rake +24 -0
  75. data/lib/tasks/shakapacker.rake +18 -0
  76. data/lib/tasks/webpacker/binstubs.rake +5 -11
  77. data/lib/tasks/webpacker/check_binstubs.rake +6 -9
  78. data/lib/tasks/webpacker/check_node.rake +5 -27
  79. data/lib/tasks/webpacker/check_yarn.rake +5 -29
  80. data/lib/tasks/webpacker/clean.rake +5 -19
  81. data/lib/tasks/webpacker/clobber.rake +6 -13
  82. data/lib/tasks/webpacker/compile.rake +5 -38
  83. data/lib/tasks/webpacker/info.rake +5 -17
  84. data/lib/tasks/webpacker/install.rake +5 -13
  85. data/lib/tasks/webpacker/verify_config.rake +6 -11
  86. data/lib/tasks/webpacker/verify_install.rake +7 -2
  87. data/lib/tasks/webpacker/yarn_install.rake +5 -20
  88. data/lib/tasks/webpacker.rake +15 -13
  89. data/lib/webpacker/dev_server_runner.rb +9 -96
  90. data/lib/webpacker/webpack_runner.rb +9 -58
  91. data/lib/webpacker.rb +3 -47
  92. data/package/__tests__/config-bc.js +27 -0
  93. data/package/__tests__/config.js +6 -5
  94. data/package/__tests__/dev_server-bc.js +46 -0
  95. data/package/__tests__/dev_server.js +9 -8
  96. data/package/__tests__/development-bc.js +66 -0
  97. data/package/__tests__/development.js +36 -5
  98. data/package/__tests__/env-bc.js +59 -0
  99. data/package/__tests__/env.js +3 -2
  100. data/package/__tests__/index-bc.js +22 -0
  101. data/package/__tests__/index.js +13 -0
  102. data/package/__tests__/production-bc.js +51 -0
  103. data/package/__tests__/production.js +25 -3
  104. data/package/__tests__/staging-bc.js +53 -0
  105. data/package/__tests__/staging.js +27 -4
  106. data/package/__tests__/test-bc.js +43 -0
  107. data/package/__tests__/test.js +22 -4
  108. data/package/babel/preset.js +1 -4
  109. data/package/config.js +25 -7
  110. data/package/dev_server.js +7 -4
  111. data/package/env.js +22 -3
  112. data/package/environments/__tests__/base-bc.js +107 -0
  113. data/package/environments/__tests__/base.js +15 -15
  114. data/package/environments/__tests__/development.js +53 -0
  115. data/package/environments/__tests__/production.js +92 -0
  116. data/package/environments/base.js +5 -4
  117. data/package/environments/development.js +4 -46
  118. data/package/environments/production.js +10 -1
  119. data/package/index.js +35 -5
  120. data/package/rules/__tests__/__utils__/webpack.js +50 -0
  121. data/package/rules/__tests__/babel.js +63 -0
  122. data/package/rules/__tests__/esbuild.js +64 -0
  123. data/package/rules/__tests__/file.js +27 -0
  124. data/package/rules/__tests__/index.js +0 -4
  125. data/package/rules/__tests__/swc.js +63 -0
  126. data/package/rules/babel.js +13 -24
  127. data/package/rules/esbuild.js +2 -13
  128. data/package/rules/file.js +2 -2
  129. data/package/rules/jscommon.js +26 -0
  130. data/package/rules/swc.js +2 -13
  131. data/package/utils/configPath.js +19 -0
  132. data/package/utils/defaultConfigPath.js +2 -0
  133. data/package/utils/get_style_rule.js +5 -2
  134. data/package/utils/helpers.js +25 -2
  135. data/package/utils/inliningCss.js +7 -0
  136. data/package/utils/snakeToCamelCase +7 -0
  137. data/package/webpackDevServerConfig.js +68 -0
  138. data/package.json +11 -5
  139. data/{webpacker.gemspec → shakapacker.gemspec} +3 -3
  140. data/spec/backward_compatibility_specs/command_spec.rb +116 -0
  141. data/spec/backward_compatibility_specs/compiler_spec.rb +59 -0
  142. data/spec/backward_compatibility_specs/compiler_strategy_spec.rb +22 -0
  143. data/spec/backward_compatibility_specs/configuration_spec.rb +286 -0
  144. data/{test/dev_server_runner_test.rb → spec/backward_compatibility_specs/dev_server_runner_spec.rb} +37 -39
  145. data/spec/backward_compatibility_specs/dev_server_spec.rb +47 -0
  146. data/spec/backward_compatibility_specs/digest_strategy_spec.rb +35 -0
  147. data/spec/backward_compatibility_specs/engine_rake_tasks_spec.rb +44 -0
  148. data/spec/backward_compatibility_specs/env_spec.rb +23 -0
  149. data/spec/backward_compatibility_specs/helper_spec.rb +243 -0
  150. data/spec/backward_compatibility_specs/instance_spec.rb +31 -0
  151. data/spec/backward_compatibility_specs/manifest_spec.rb +100 -0
  152. data/spec/backward_compatibility_specs/mtime_strategy_spec.rb +55 -0
  153. data/spec/backward_compatibility_specs/rake_tasks_spec.rb +37 -0
  154. data/spec/backward_compatibility_specs/spec_helper_initializer.rb +24 -0
  155. data/{test/webpack_runner_test.rb → spec/backward_compatibility_specs/webpack_runner_spec.rb} +15 -16
  156. data/spec/backward_compatibility_specs/webpacker_spec.rb +41 -0
  157. data/spec/backward_compatibility_specs/webpacker_test_app/.gitignore +2 -0
  158. data/{test/test_app → spec/backward_compatibility_specs/webpacker_test_app}/app/packs/entrypoints/application.js +1 -1
  159. data/{lib/install → spec/backward_compatibility_specs/webpacker_test_app}/bin/webpacker +0 -0
  160. data/spec/backward_compatibility_specs/webpacker_test_app/config/application.rb +11 -0
  161. data/{test/test_app → spec/backward_compatibility_specs/webpacker_test_app}/config/webpacker.yml +1 -1
  162. data/{test/test_app → spec/backward_compatibility_specs/webpacker_test_app}/config/webpacker_css_extract_ignore_order_warnings.yml +1 -1
  163. data/{test/test_app → spec/backward_compatibility_specs/webpacker_test_app}/config/webpacker_defaults_fallback.yml +1 -1
  164. data/spec/backward_compatibility_specs/webpacker_test_app/config/webpacker_no_precompile.yml +7 -0
  165. data/spec/backward_compatibility_specs/webpacker_test_app/config/webpacker_other_location.yml +85 -0
  166. data/{test/test_app → spec/backward_compatibility_specs/webpacker_test_app}/config/webpacker_public_root.yml +1 -1
  167. data/spec/backward_compatibility_specs/webpacker_test_app/package.json +13 -0
  168. data/{test/test_app → spec/backward_compatibility_specs/webpacker_test_app}/public/packs/manifest.json +8 -0
  169. data/spec/backward_compatibility_specs/webpacker_test_app/tmp/shakapacker/last-compilation-digest-production +1 -0
  170. data/spec/dummy/.browserslistrc +1 -0
  171. data/spec/dummy/.gitignore +20 -0
  172. data/spec/dummy/.prettierrc.yaml +4 -0
  173. data/spec/dummy/Gemfile +63 -0
  174. data/spec/dummy/Procfile.dev +5 -0
  175. data/spec/dummy/Procfile.dev-static +9 -0
  176. data/spec/dummy/README.md +1 -0
  177. data/spec/dummy/Rakefile +6 -0
  178. data/spec/dummy/app/assets/config/manifest.js +2 -0
  179. data/spec/dummy/app/assets/images/.keep +0 -0
  180. data/spec/dummy/app/assets/stylesheets/application.css +15 -0
  181. data/spec/dummy/app/channels/application_cable/channel.rb +4 -0
  182. data/spec/dummy/app/channels/application_cable/connection.rb +4 -0
  183. data/spec/dummy/app/controllers/application_controller.rb +2 -0
  184. data/spec/dummy/app/controllers/concerns/.keep +0 -0
  185. data/spec/dummy/app/controllers/hello_world_controller.rb +9 -0
  186. data/spec/dummy/app/helpers/application_helper.rb +2 -0
  187. data/spec/dummy/app/javascript/Globals.d.ts +3 -0
  188. data/spec/dummy/app/javascript/bundles/HelloWorld/components/HelloWorld.module.css +25 -0
  189. data/spec/dummy/app/javascript/bundles/HelloWorld/components/HelloWorld.tsx +47 -0
  190. data/spec/dummy/app/javascript/bundles/HelloWorld/components/HelloWorldServer.tsx +5 -0
  191. data/spec/dummy/app/javascript/bundles/HelloWorld/components/logo.svg +7 -0
  192. data/spec/dummy/app/javascript/packs/application.js +17 -0
  193. data/spec/dummy/app/javascript/packs/hello-world-bundle.ts +8 -0
  194. data/spec/dummy/app/javascript/packs/server-bundle.ts +8 -0
  195. data/spec/dummy/app/jobs/application_job.rb +7 -0
  196. data/spec/dummy/app/mailers/application_mailer.rb +4 -0
  197. data/spec/dummy/app/models/application_record.rb +3 -0
  198. data/spec/dummy/app/models/concerns/.keep +0 -0
  199. data/spec/dummy/app/views/hello_world/index.html.erb +2 -0
  200. data/spec/dummy/app/views/layouts/application.html.erb +14 -0
  201. data/spec/dummy/app/views/layouts/hello_world.html.erb +13 -0
  202. data/spec/dummy/app/views/layouts/mailer.html.erb +13 -0
  203. data/spec/dummy/app/views/layouts/mailer.text.erb +1 -0
  204. data/spec/dummy/babel.config.js +30 -0
  205. data/spec/dummy/bin/bundle +114 -0
  206. data/spec/dummy/bin/dev +30 -0
  207. data/spec/dummy/bin/dev-static +30 -0
  208. data/spec/dummy/bin/rails +9 -0
  209. data/spec/dummy/bin/rake +9 -0
  210. data/spec/dummy/bin/setup +33 -0
  211. data/spec/dummy/bin/shakapacker +13 -0
  212. data/spec/dummy/bin/shakapacker-dev-server +13 -0
  213. data/spec/dummy/bin/spring +17 -0
  214. data/spec/dummy/bin/yarn +18 -0
  215. data/spec/dummy/config/application.rb +32 -0
  216. data/spec/dummy/config/boot.rb +4 -0
  217. data/spec/dummy/config/cable.yml +10 -0
  218. data/spec/dummy/config/credentials.yml.enc +1 -0
  219. data/spec/dummy/config/database.yml +25 -0
  220. data/spec/dummy/config/environment.rb +5 -0
  221. data/spec/dummy/config/environments/development.rb +54 -0
  222. data/spec/dummy/config/environments/production.rb +106 -0
  223. data/spec/dummy/config/environments/test.rb +49 -0
  224. data/spec/dummy/config/initializers/application_controller_renderer.rb +8 -0
  225. data/spec/dummy/config/initializers/backtrace_silencers.rb +7 -0
  226. data/spec/dummy/config/initializers/content_security_policy.rb +28 -0
  227. data/spec/dummy/config/initializers/cookies_serializer.rb +5 -0
  228. data/spec/dummy/config/initializers/filter_parameter_logging.rb +4 -0
  229. data/spec/dummy/config/initializers/inflections.rb +16 -0
  230. data/spec/dummy/config/initializers/mime_types.rb +4 -0
  231. data/spec/dummy/config/initializers/react_on_rails.rb +58 -0
  232. data/spec/dummy/config/initializers/wrap_parameters.rb +14 -0
  233. data/spec/dummy/config/locales/en.yml +33 -0
  234. data/spec/dummy/config/puma.rb +38 -0
  235. data/spec/dummy/config/routes.rb +6 -0
  236. data/spec/dummy/config/shakapacker.yml +62 -0
  237. data/spec/dummy/config/spring.rb +6 -0
  238. data/spec/dummy/config/storage.yml +34 -0
  239. data/spec/dummy/config/webpack/ServerClientOrBoth.js +34 -0
  240. data/spec/dummy/config/webpack/clientWebpackConfig.js +15 -0
  241. data/spec/dummy/config/webpack/commonWebpackConfig.js +18 -0
  242. data/spec/dummy/config/webpack/development.js +32 -0
  243. data/spec/dummy/config/webpack/production.js +9 -0
  244. data/spec/dummy/config/webpack/serverWebpackConfig.js +116 -0
  245. data/spec/dummy/config/webpack/test.js +7 -0
  246. data/spec/dummy/config/webpack/webpack.config.js +24 -0
  247. data/spec/dummy/config.ru +5 -0
  248. data/spec/dummy/db/seeds.rb +7 -0
  249. data/spec/dummy/lib/assets/.keep +0 -0
  250. data/spec/dummy/lib/tasks/.keep +0 -0
  251. data/spec/dummy/package.json +44 -0
  252. data/spec/dummy/postcss.config.js +12 -0
  253. data/spec/dummy/public/404.html +67 -0
  254. data/spec/dummy/public/422.html +67 -0
  255. data/spec/dummy/public/500.html +66 -0
  256. data/spec/dummy/public/apple-touch-icon-precomposed.png +0 -0
  257. data/spec/dummy/public/apple-touch-icon.png +0 -0
  258. data/spec/dummy/public/favicon.ico +0 -0
  259. data/spec/dummy/public/robots.txt +1 -0
  260. data/spec/dummy/spec/rails_helper.rb +118 -0
  261. data/spec/dummy/spec/spec_helper.rb +96 -0
  262. data/spec/dummy/spec/system/hello_world_spec.rb +19 -0
  263. data/spec/dummy/tsconfig.json +21 -0
  264. data/spec/dummy/vendor/.keep +0 -0
  265. data/spec/dummy/yarn.lock +4697 -0
  266. data/spec/generator_specs/e2e_template/files/app/controllers/home_controller.rb +4 -0
  267. data/spec/generator_specs/e2e_template/files/app/javascript/components/App.js +12 -0
  268. data/spec/generator_specs/e2e_template/files/app/javascript/packs/application.js +10 -0
  269. data/spec/generator_specs/e2e_template/files/app/views/home/index.html.erb +2 -0
  270. data/spec/generator_specs/e2e_template/files/app/views/layouts/application.html.erb +17 -0
  271. data/spec/generator_specs/e2e_template/files/config/routes.rb +3 -0
  272. data/spec/generator_specs/e2e_template/files/spec/system/test_react_component_renders_spec.rb +13 -0
  273. data/spec/generator_specs/e2e_template/template.rb +21 -0
  274. data/spec/generator_specs/generator_spec.rb +169 -0
  275. data/{test → spec}/mounted_app/test/dummy/config/application.rb +1 -1
  276. data/{test → spec}/mounted_app/test/dummy/config/webpacker.yml +11 -5
  277. data/spec/shakapacker/command_spec.rb +116 -0
  278. data/spec/shakapacker/compiler_spec.rb +59 -0
  279. data/spec/shakapacker/compiler_strategy_spec.rb +22 -0
  280. data/spec/shakapacker/configuration_spec.rb +323 -0
  281. data/spec/shakapacker/dev_server_runner_spec.rb +72 -0
  282. data/spec/shakapacker/dev_server_spec.rb +133 -0
  283. data/spec/shakapacker/digest_strategy_spec.rb +35 -0
  284. data/spec/shakapacker/engine_rake_tasks_spec.rb +43 -0
  285. data/spec/shakapacker/env_spec.rb +23 -0
  286. data/spec/shakapacker/helper_spec.rb +243 -0
  287. data/spec/shakapacker/instance_spec.rb +31 -0
  288. data/spec/shakapacker/manifest_spec.rb +100 -0
  289. data/spec/shakapacker/mtime_strategy_spec.rb +55 -0
  290. data/spec/shakapacker/rake_tasks_spec.rb +93 -0
  291. data/spec/shakapacker/shakapacker_spec.rb +41 -0
  292. data/spec/shakapacker/spec_helper_initializer.rb +24 -0
  293. data/spec/shakapacker/test_app/.gitignore +2 -0
  294. data/spec/shakapacker/test_app/Rakefile +3 -0
  295. data/spec/shakapacker/test_app/app/javascript/entrypoints/application.js +10 -0
  296. data/spec/shakapacker/test_app/app/javascript/entrypoints/generated/something.js +2 -0
  297. data/spec/shakapacker/test_app/app/javascript/entrypoints/multi_entry.css +4 -0
  298. data/spec/shakapacker/test_app/app/javascript/entrypoints/multi_entry.js +4 -0
  299. data/{test/test_app/bin/webpacker-dev-server → spec/shakapacker/test_app/bin/shakapacker} +3 -3
  300. data/{test/test_app/bin/webpacker → spec/shakapacker/test_app/bin/shakapacker-dev-server} +3 -3
  301. data/{test → spec/shakapacker}/test_app/config/application.rb +1 -1
  302. data/spec/shakapacker/test_app/config/environment.rb +4 -0
  303. data/spec/shakapacker/test_app/config/initializers/inspect_autoload_paths.rb +1 -0
  304. data/spec/shakapacker/test_app/config/shakapacker.yml +82 -0
  305. data/spec/shakapacker/test_app/config/shakapacker_css_extract_ignore_order_warnings.yml +84 -0
  306. data/spec/shakapacker/test_app/config/shakapacker_defaults_fallback.yml +11 -0
  307. data/{test/test_app/config/webpacker_other_location.yml → spec/shakapacker/test_app/config/shakapacker_manifest_path.yml} +6 -5
  308. data/spec/shakapacker/test_app/config/shakapacker_nested_entries.yml +83 -0
  309. data/spec/shakapacker/test_app/config/shakapacker_no_precompile.yml +7 -0
  310. data/spec/shakapacker/test_app/config/shakapacker_other_location.yml +85 -0
  311. data/spec/shakapacker/test_app/config/shakapacker_public_root.yml +18 -0
  312. data/spec/shakapacker/test_app/config/webpack/webpack.config.js +0 -0
  313. data/spec/shakapacker/test_app/config.ru +5 -0
  314. data/spec/shakapacker/test_app/public/packs/manifest.json +58 -0
  315. data/spec/shakapacker/test_app/some.config.js +0 -0
  316. data/spec/shakapacker/test_app/yarn.lock +11 -0
  317. data/spec/shakapacker/version_checker_spec.rb +951 -0
  318. data/spec/shakapacker/webpack_runner_spec.rb +55 -0
  319. data/spec/spec_helper.rb +98 -0
  320. data/yarn.lock +846 -844
  321. metadata +314 -213
  322. data/.github/ISSUE_TEMPLATE/feature-request.md +0 -18
  323. data/config/webpacker.yml +0 -1
  324. data/gemfiles/Gemfile-rails.5.2.x +0 -9
  325. data/lib/tasks/yarn.rake +0 -44
  326. data/lib/webpacker/instance.rb +0 -45
  327. data/lib/webpacker/railtie.rb +0 -70
  328. data/lib/webpacker/runner.rb +0 -23
  329. data/package/configPath.js +0 -3
  330. data/package/inliningCss.js +0 -7
  331. data/test/command_test.rb +0 -109
  332. data/test/compiler_strategy_test.rb +0 -27
  333. data/test/compiler_test.rb +0 -60
  334. data/test/configuration_test.rb +0 -186
  335. data/test/dev_server_test.rb +0 -47
  336. data/test/digest_strategy_test.rb +0 -33
  337. data/test/engine_rake_tasks_test.rb +0 -39
  338. data/test/env_test.rb +0 -23
  339. data/test/helper_test.rb +0 -248
  340. data/test/manifest_test.rb +0 -89
  341. data/test/mtime_strategy_test.rb +0 -42
  342. data/test/rake_tasks_test.rb +0 -37
  343. data/test/test_app/config/webpacker_no_precompile.yml +0 -7
  344. data/test/test_helper.rb +0 -33
  345. data/test/version_checker_test.rb +0 -826
  346. data/test/webpacker_test.rb +0 -49
  347. /data/{test/mounted_app/test/dummy → spec/backward_compatibility_specs/webpacker_test_app}/Rakefile +0 -0
  348. /data/{test/test_app → spec/backward_compatibility_specs/webpacker_test_app}/app/packs/entrypoints/generated/something.js +0 -0
  349. /data/{test/test_app → spec/backward_compatibility_specs/webpacker_test_app}/app/packs/entrypoints/multi_entry.css +0 -0
  350. /data/{test/test_app → spec/backward_compatibility_specs/webpacker_test_app}/app/packs/entrypoints/multi_entry.js +0 -0
  351. /data/{lib/install → spec/backward_compatibility_specs/webpacker_test_app}/bin/webpacker-dev-server +0 -0
  352. /data/{test/test_app → spec/backward_compatibility_specs/webpacker_test_app}/config/environment.rb +0 -0
  353. /data/{test/test_app → spec/backward_compatibility_specs/webpacker_test_app}/config/initializers/inspect_autoload_paths.rb +0 -0
  354. /data/{test/test_app → spec/backward_compatibility_specs/webpacker_test_app}/config/webpack/webpack.config.js +0 -0
  355. /data/{test/test_app → spec/backward_compatibility_specs/webpacker_test_app}/config/webpacker_manifest_path.yml +0 -0
  356. /data/{test/test_app → spec/backward_compatibility_specs/webpacker_test_app}/config/webpacker_nested_entries.yml +0 -0
  357. /data/{test/mounted_app/test/dummy → spec/backward_compatibility_specs/webpacker_test_app}/config.ru +0 -0
  358. /data/{test/test_app → spec/backward_compatibility_specs/webpacker_test_app}/some.config.js +0 -0
  359. /data/{test/test_app → spec/backward_compatibility_specs/webpacker_test_app}/yarn.lock +0 -0
  360. /data/{test → spec}/fixtures/beta_package-lock.v1.json +0 -0
  361. /data/{test → spec}/fixtures/beta_package-lock.v2.json +0 -0
  362. /data/{test → spec}/fixtures/beta_package.json +0 -0
  363. /data/{test → spec}/fixtures/beta_yarn.v1.lock +0 -0
  364. /data/{test → spec}/fixtures/beta_yarn.v2.lock +0 -0
  365. /data/{test → spec}/fixtures/git_url_package-lock.v1.json +0 -0
  366. /data/{test → spec}/fixtures/git_url_package-lock.v2.json +0 -0
  367. /data/{test → spec}/fixtures/git_url_package.json +0 -0
  368. /data/{test → spec}/fixtures/git_url_yarn.v1.lock +0 -0
  369. /data/{test → spec}/fixtures/git_url_yarn.v2.lock +0 -0
  370. /data/{test → spec}/fixtures/github_url_package-lock.v1.json +0 -0
  371. /data/{test → spec}/fixtures/github_url_package-lock.v2.json +0 -0
  372. /data/{test → spec}/fixtures/github_url_package.json +0 -0
  373. /data/{test → spec}/fixtures/github_url_yarn.v1.lock +0 -0
  374. /data/{test → spec}/fixtures/github_url_yarn.v2.lock +0 -0
  375. /data/{test → spec}/fixtures/relative_path_package-lock.v1.json +0 -0
  376. /data/{test → spec}/fixtures/relative_path_package-lock.v2.json +0 -0
  377. /data/{test → spec}/fixtures/relative_path_package.json +0 -0
  378. /data/{test → spec}/fixtures/relative_path_yarn.v1.lock +0 -0
  379. /data/{test → spec}/fixtures/relative_path_yarn.v2.lock +0 -0
  380. /data/{test → spec}/fixtures/semver_caret_package-lock.v1.json +0 -0
  381. /data/{test → spec}/fixtures/semver_caret_package-lock.v2.json +0 -0
  382. /data/{test → spec}/fixtures/semver_caret_package.json +0 -0
  383. /data/{test → spec}/fixtures/semver_caret_yarn.v1.lock +0 -0
  384. /data/{test → spec}/fixtures/semver_caret_yarn.v2.lock +0 -0
  385. /data/{test → spec}/fixtures/semver_exact_package-lock.v1.json +0 -0
  386. /data/{test → spec}/fixtures/semver_exact_package-lock.v2.json +0 -0
  387. /data/{test → spec}/fixtures/semver_exact_package.json +0 -0
  388. /data/{test → spec}/fixtures/semver_exact_yarn.v1.lock +0 -0
  389. /data/{test → spec}/fixtures/semver_exact_yarn.v2.lock +0 -0
  390. /data/{test → spec}/fixtures/semver_tilde_package-lock.v1.json +0 -0
  391. /data/{test → spec}/fixtures/semver_tilde_package-lock.v2.json +0 -0
  392. /data/{test → spec}/fixtures/semver_tilde_package.json +0 -0
  393. /data/{test → spec}/fixtures/semver_tilde_yarn.v1.lock +0 -0
  394. /data/{test → spec}/fixtures/semver_tilde_yarn.v2.lock +0 -0
  395. /data/{test → spec}/fixtures/without_package-lock.v1.json +0 -0
  396. /data/{test → spec}/fixtures/without_package-lock.v2.json +0 -0
  397. /data/{test → spec}/fixtures/without_package.json +0 -0
  398. /data/{test → spec}/fixtures/without_yarn.v1.lock +0 -0
  399. /data/{test → spec}/fixtures/without_yarn.v2.lock +0 -0
  400. /data/{test → spec}/mounted_app/Rakefile +0 -0
  401. /data/{test/test_app → spec/mounted_app/test/dummy}/Rakefile +0 -0
  402. /data/{test → spec}/mounted_app/test/dummy/bin/rails +0 -0
  403. /data/{test → spec}/mounted_app/test/dummy/bin/rake +0 -0
  404. /data/{test → spec}/mounted_app/test/dummy/config/environment.rb +0 -0
  405. /data/{test/test_app → spec/mounted_app/test/dummy}/config.ru +0 -0
  406. /data/{test → spec}/mounted_app/test/dummy/package.json +0 -0
  407. /data/{test → spec/shakapacker}/test_app/package.json +0 -0
@@ -1,15 +1,17 @@
1
- # Note: You must restart bin/webpacker-dev-server for changes to take effect
1
+ # Note: You must restart bin/shakapacker-dev-server for changes to take effect
2
+ # This file contains the defaults used by shakapacker.
2
3
 
3
4
  default: &default
4
5
  source_path: app/javascript
5
6
 
6
7
  # You can have a subdirectory of the source_path, like 'packs' (recommended).
7
8
  # Alternatively, you can use '/' to use the whole source_path directory.
8
- source_entry_path: /
9
+ # Notice that this is a relative path to source_path
10
+ source_entry_path: packs
9
11
 
10
12
  # If nested_entries is true, then we'll pick up subdirectories within the source_entry_path.
11
13
  # You cannot set this option to true if you set source_entry_path to '/'
12
- nested_entries: false
14
+ nested_entries: true
13
15
 
14
16
  # While using a File-System-based automated bundle generation feature, miscellaneous warnings suggesting css order
15
17
  # conflicts may arise due to the mini-css-extract-plugin. For projects where css ordering has been mitigated through
@@ -19,10 +21,10 @@ default: &default
19
21
 
20
22
  public_root_path: public
21
23
  public_output_path: packs
22
- cache_path: tmp/webpacker
24
+ cache_path: tmp/shakapacker
23
25
  webpack_compile_output: true
24
26
  # See https://github.com/shakacode/shakapacker#deployment
25
- webpacker_precompile: true
27
+ shakapacker_precompile: true
26
28
 
27
29
  # Location for manifest.json, defaults to {public_output_path}/manifest.json if unset
28
30
  # manifest_path: public/packs/manifest.json
@@ -43,25 +45,36 @@ default: &default
43
45
  # Select whether the compiler will use SHA digest ('digest' option) or most most recent modified timestamp ('mtime') to determine freshness
44
46
  compiler_strategy: digest
45
47
 
48
+ # Select whether the compiler will always use a content hash and not just in production
49
+ # Don't use contentHash except for production for performance
50
+ # https://webpack.js.org/guides/build-performance/#avoid-production-specific-tooling
51
+ useContentHash: false
52
+
46
53
  development:
47
54
  <<: *default
48
55
  compile: true
49
56
  compiler_strategy: mtime
50
57
 
51
58
  # Reference: https://webpack.js.org/configuration/dev-server/
59
+ # Keys not described there are documented inline and in https://github.com/shakacode/shakapacker/
52
60
  dev_server:
53
- https: false
61
+ # For running dev server with https, set `server: https`.
62
+ # You may use `https: true` instead but notice that it is deprecated in favor of `server: https`
63
+ # Ensure only one of these entries is set.
64
+ # server: https
65
+
54
66
  host: localhost
55
67
  port: 3035
56
68
  # Hot Module Replacement updates modules while the application is running without a full reload
69
+ # Used instead of the `hot` key in https://webpack.js.org/configuration/dev-server/#devserverhot
57
70
  hmr: false
58
71
  # If HMR is on, CSS will by inlined by delivering it as part of the script payload via style-loader. Be sure
59
72
  # that you add style-loader to your project dependencies.
60
73
  #
61
- # If you want to instead deliver CSS via <link> with the mini-extract-css-plugin, set inline_css to false.
74
+ # If you want to instead deliver CSS via <link> with the mini-css-extract-plugin, set inline_css to false.
62
75
  # In that case, style-loader is not needed as a dependency.
63
76
  #
64
- # mini-extract-css-plugin is a required dependency in both cases.
77
+ # mini-css-extract-plugin is a required dependency in both cases.
65
78
  inline_css: true
66
79
  # Defaults to the inverse of hmr. Uncomment to manually set this.
67
80
  # live_reload: true
@@ -70,13 +83,14 @@ development:
70
83
  overlay: true
71
84
  # May also be a string
72
85
  # webSocketURL:
73
- # hostname: "0.0.0.0"
74
- # pathname: "/ws"
86
+ # hostname: '0.0.0.0'
87
+ # pathname: '/ws'
75
88
  # port: 8080
76
89
  # Should we use gzip compression?
77
90
  compress: true
78
91
  # Note that apps that do not check the host are vulnerable to DNS rebinding attacks
79
- allowed_hosts: "all"
92
+ allowed_hosts: 'auto'
93
+ # Shows progress and colorizes output of bin/shakapacker[-dev-server]
80
94
  pretty: true
81
95
  headers:
82
96
  'Access-Control-Allow-Origin': '*'
@@ -97,5 +111,8 @@ production:
97
111
  # Production depends on precompilation of packs prior to booting for performance.
98
112
  compile: false
99
113
 
114
+ # Use content hash for naming assets. Cannot be overridden by for production.
115
+ useContentHash: true
116
+
100
117
  # Cache manifest.json for performance
101
118
  cache_manifest: true
@@ -1,5 +1,6 @@
1
- const { webpackConfig } = require('shakapacker')
2
-
3
1
  // See the shakacode/shakapacker README and docs directory for advice on customizing your webpackConfig.
2
+ const { generateWebpackConfig } = require('shakapacker')
3
+
4
+ const webpackConfig = generateWebpackConfig()
4
5
 
5
6
  module.exports = webpackConfig
@@ -1,11 +1,16 @@
1
- # Install Webpacker
2
- copy_file "#{__dir__}/config/webpacker.yml", "config/webpacker.yml"
3
- copy_file "#{__dir__}/package.json", "package.json"
1
+ require "shakapacker/utils/version_syntax_converter"
2
+
3
+ # Install Shakapacker
4
+
5
+ force_option = ENV["FORCE"] ? { force: true } : {}
6
+
7
+ copy_file "#{__dir__}/config/shakapacker.yml", "config/shakapacker.yml", force_option
8
+ copy_file "#{__dir__}/package.json", "package.json", force_option
4
9
 
5
10
  say "Copying webpack core config"
6
- directory "#{__dir__}/config/webpack", "config/webpack"
11
+ directory "#{__dir__}/config/webpack", "config/webpack", force_option
7
12
 
8
- if Dir.exist?(Webpacker.config.source_path)
13
+ if Dir.exist?(Shakapacker.config.source_path)
9
14
  say "The packs app source directory already exists"
10
15
  else
11
16
  say "Creating packs app source directory"
@@ -36,56 +41,68 @@ else
36
41
  say %( Add <%= javascript_pack_tag "application" %> within the <head> tag in your custom layout.)
37
42
  end
38
43
 
44
+ # Ensure there is `system!("bin/yarn")` command in `./bin/setup` file
39
45
  if (setup_path = Rails.root.join("bin/setup")).exist?
40
46
  say "Run bin/yarn during bin/setup"
41
- insert_into_file setup_path.to_s, <<-RUBY, after: %( system("bundle check") || system!("bundle install")\n)
47
+
48
+ if File.read(setup_path).match? Regexp.escape(" # system('bin/yarn')\n")
49
+ gsub_file(setup_path, "# system('bin/yarn')", "system!('bin/yarn')")
50
+ else
51
+ # Due to the inconsistency of quotation usage in Rails 7 compared to
52
+ # earlier versions, we check both single and double quotations here.
53
+ pattern = /system\(['"]bundle check['"]\) \|\| system!\(['"]bundle install['"]\)\n/
54
+
55
+ string_to_add = <<-RUBY
42
56
 
43
57
  # Install JavaScript dependencies
44
- system! "bin/yarn"
58
+ system!("bin/yarn")
45
59
  RUBY
46
- end
47
60
 
48
- if (csp_config_path = Rails.root.join("config/initializers/content_security_policy.rb")).exist?
49
- say "Make note of webpack-dev-server exemption needed to csp"
50
- insert_into_file csp_config_path, <<-RUBY, after: %(# Rails.application.config.content_security_policy do |policy|)
51
- # # If you are using webpack-dev-server then specify webpack-dev-server host
52
- # policy.connect_src :self, :https, "http://localhost:3035", "ws://localhost:3035" if Rails.env.development?
53
- RUBY
61
+ if File.read(setup_path).match? pattern
62
+ insert_into_file(setup_path, string_to_add, after: pattern)
63
+ else
64
+ say <<~MSG, :red
65
+ It seems your `bin/setup` file doesn't have the expected content.
66
+ Please review the file and manually add `system!("bin/yarn")` before any
67
+ other command that requires JavaScript dependencies being already installed.
68
+ MSG
69
+ end
70
+ end
54
71
  end
55
72
 
56
73
  results = []
57
74
 
58
75
  Dir.chdir(Rails.root) do
59
- if Webpacker::VERSION.match?(/^[0-9]+\.[0-9]+\.[0-9]+$/)
60
- say "Installing shakapacker@#{Webpacker::VERSION}"
61
- results << run("yarn add shakapacker@#{Webpacker::VERSION} --exact")
62
- else
63
- say "Installing shakapacker@next"
64
- results << run("yarn add shakapacker@next --exact")
65
- end
76
+ npm_version = Shakapacker::Utils::VersionSyntaxConverter.new.rubygem_to_npm(Shakapacker::VERSION)
77
+ say "Installing shakapacker@#{npm_version}"
78
+ results << run("yarn add shakapacker@#{npm_version} --exact")
66
79
 
67
80
  package_json = File.read("#{__dir__}/../../package.json")
68
81
  peers = JSON.parse(package_json)["peerDependencies"]
69
- peers_to_add = peers.reduce([]) do |result, (package, version)|
82
+ dev_dependency_packages = ["webpack-dev-server"]
83
+
84
+ dependencies_to_add = []
85
+ dev_dependencies_to_add = []
86
+
87
+ peers.each do |(package, version)|
70
88
  major_version = version.match(/(\d+)/)[1]
71
- result << "#{package}@#{major_version}"
72
- end.join(" ")
89
+ entry = "#{package}@#{major_version}"
90
+
91
+ if dev_dependency_packages.include? package
92
+ dev_dependencies_to_add << entry
93
+ else
94
+ dependencies_to_add << entry
95
+ end
96
+ end
73
97
 
74
98
  say "Adding shakapacker peerDependencies"
75
- results << run("yarn add #{peers_to_add}")
99
+ results << run("yarn add #{dependencies_to_add.join(' ')}")
76
100
 
77
101
  say "Installing webpack-dev-server for live reloading as a development dependency"
78
- results << run("yarn add --dev webpack-dev-server")
79
- end
80
-
81
- if Rails::VERSION::MAJOR == 5 && Rails::VERSION::MINOR > 1
82
- say "You need to allow webpack-dev-server host as allowed origin for connect-src.", :yellow
83
- say "This can be done in Rails 5.2+ for development environment in the CSP initializer", :yellow
84
- say "config/initializers/content_security_policy.rb with a snippet like this:", :yellow
85
- say "policy.connect_src :self, :https, \"http://localhost:3035\", \"ws://localhost:3035\" if Rails.env.development?", :yellow
102
+ results << run("yarn add --dev #{dev_dependencies_to_add.join(' ')}")
86
103
  end
87
104
 
88
105
  unless results.all?
89
- say "Webpacker installation failed 😭 See above for details.", :red
106
+ say "Shakapacker installation failed 😭 See above for details.", :red
90
107
  exit 1
91
108
  end
@@ -1,7 +1,7 @@
1
- module Webpacker
1
+ module Shakapacker
2
2
  class BaseStrategy
3
3
  def initialize
4
- @config = Webpacker.config
4
+ @config = Shakapacker.config
5
5
  end
6
6
 
7
7
  def after_compile_hook
@@ -1,8 +1,8 @@
1
- class Webpacker::Commands
2
- delegate :config, :compiler, :manifest, :logger, to: :@webpacker
1
+ class Shakapacker::Commands
2
+ delegate :config, :compiler, :manifest, :logger, to: :@instance
3
3
 
4
- def initialize(webpacker)
5
- @webpacker = webpacker
4
+ def initialize(instance)
5
+ @instance = instance
6
6
  end
7
7
 
8
8
  # Cleanup old assets in the compile directory. By default it will
@@ -1,16 +1,17 @@
1
1
  require "open3"
2
- require "webpacker/compiler_strategy"
2
+ require "shakapacker/compiler_strategy"
3
+ require "fileutils"
3
4
 
4
- class Webpacker::Compiler
5
+ class Shakapacker::Compiler
5
6
  # Additional environment variables that the compiler is being run with
6
- # Webpacker::Compiler.env['FRONTEND_API_KEY'] = 'your_secret_key'
7
+ # Shakapacker::Compiler.env['FRONTEND_API_KEY'] = 'your_secret_key'
7
8
  cattr_accessor(:env) { {} }
8
9
 
9
- delegate :config, :logger, :strategy, to: :webpacker
10
+ delegate :config, :logger, :strategy, to: :instance
10
11
  delegate :fresh?, :stale?, :after_compile_hook, to: :strategy
11
12
 
12
- def initialize(webpacker)
13
- @webpacker = webpacker
13
+ def initialize(instance)
14
+ @instance = instance
14
15
  end
15
16
 
16
17
  def compile
@@ -32,7 +33,7 @@ class Webpacker::Compiler
32
33
  end
33
34
 
34
35
  private
35
- attr_reader :webpacker
36
+ attr_reader :instance
36
37
 
37
38
  def acquire_ipc_lock
38
39
  open_lock_file do |lf|
@@ -55,15 +56,24 @@ class Webpacker::Compiler
55
56
  end
56
57
 
57
58
  def open_lock_file
58
- lock_file_name = File.join(Dir.tmpdir, "shakapacker.lock")
59
- File.open(lock_file_name, File::CREAT) do |lf|
59
+ create_lock_file_dir unless File.exist?(lock_file_path)
60
+
61
+ File.open(lock_file_path, File::CREAT) do |lf|
60
62
  return yield lf
61
63
  end
62
64
  end
63
65
 
66
+ def create_lock_file_dir
67
+ dirname = File.dirname(lock_file_path)
68
+ FileUtils.mkdir_p(dirname)
69
+ end
70
+
71
+ def lock_file_path
72
+ config.root_path.join("tmp/shakapacker.lock")
73
+ end
74
+
64
75
  def optionalRubyRunner
65
- bin_webpack_path = config.root_path.join("bin/webpacker")
66
- first_line = File.readlines(bin_webpack_path).first.chomp
76
+ first_line = File.readlines(bin_shakapacker_path).first.chomp
67
77
  /ruby/.match?(first_line) ? RbConfig.ruby : ""
68
78
  end
69
79
 
@@ -72,7 +82,7 @@ class Webpacker::Compiler
72
82
 
73
83
  stdout, stderr, status = Open3.capture3(
74
84
  webpack_env,
75
- "#{optionalRubyRunner} ./bin/webpacker",
85
+ "#{optionalRubyRunner} #{bin_shakapacker_path}",
76
86
  chdir: File.expand_path(config.root_path)
77
87
  )
78
88
 
@@ -94,8 +104,26 @@ class Webpacker::Compiler
94
104
  def webpack_env
95
105
  return env unless defined?(ActionController::Base)
96
106
 
97
- env.merge("WEBPACKER_ASSET_HOST" => ENV.fetch("WEBPACKER_ASSET_HOST", ActionController::Base.helpers.compute_asset_host),
98
- "WEBPACKER_RELATIVE_URL_ROOT" => ENV.fetch("WEBPACKER_RELATIVE_URL_ROOT", ActionController::Base.relative_url_root),
99
- "WEBPACKER_CONFIG" => webpacker.config_path.to_s)
107
+ Shakapacker.set_shakapacker_env_variables_for_backward_compatibility
108
+
109
+ env.merge("SHAKAPACKER_ASSET_HOST" => ENV.fetch("SHAKAPACKER_ASSET_HOST", ActionController::Base.helpers.compute_asset_host),
110
+ "SHAKAPACKER_RELATIVE_URL_ROOT" => ENV.fetch("SHAKAPACKER_RELATIVE_URL_ROOT", ActionController::Base.relative_url_root),
111
+ "SHAKAPACKER_CONFIG" => instance.config_path.to_s)
112
+ end
113
+
114
+ def bin_shakapacker_path
115
+ if File.exist?(config.root_path.join("bin/shakapacker"))
116
+ config.root_path.join("bin/shakapacker")
117
+ elsif File.exist?(config.root_path.join("bin/webpacker"))
118
+ Shakapacker.puts_deprecation_message(
119
+ Shakapacker.short_deprecation_message(
120
+ "bin/webpacker",
121
+ "bin/shakapacker"
122
+ )
123
+ )
124
+ config.root_path.join("bin/webpacker")
125
+ else
126
+ config.root_path.join("bin/shakapacker")
127
+ end
100
128
  end
101
129
  end
@@ -1,16 +1,16 @@
1
- require "webpacker/mtime_strategy"
2
- require "webpacker/digest_strategy"
1
+ require "shakapacker/mtime_strategy"
2
+ require "shakapacker/digest_strategy"
3
3
 
4
- module Webpacker
4
+ module Shakapacker
5
5
  class CompilerStrategy
6
6
  def self.from_config
7
- strategy_from_config = Webpacker.config.compiler_strategy
7
+ strategy_from_config = Shakapacker.config.compiler_strategy
8
8
 
9
9
  case strategy_from_config
10
10
  when "mtime"
11
- Webpacker::MtimeStrategy.new
11
+ Shakapacker::MtimeStrategy.new
12
12
  when "digest"
13
- Webpacker::DigestStrategy.new
13
+ Shakapacker::DigestStrategy.new
14
14
  else
15
15
  raise "Unknown strategy '#{strategy_from_config}'. " \
16
16
  "Available options are 'mtime' and 'digest'."
@@ -2,7 +2,7 @@ require "yaml"
2
2
  require "active_support/core_ext/hash/keys"
3
3
  require "active_support/core_ext/hash/indifferent_access"
4
4
 
5
- class Webpacker::Configuration
5
+ class Shakapacker::Configuration
6
6
  class << self
7
7
  attr_accessor :installing
8
8
  end
@@ -11,8 +11,11 @@ class Webpacker::Configuration
11
11
 
12
12
  def initialize(root_path:, config_path:, env:)
13
13
  @root_path = root_path
14
- @config_path = config_path
15
14
  @env = env
15
+
16
+ # For backward compatibility
17
+ Shakapacker.set_shakapacker_env_variables_for_backward_compatibility
18
+ @config_path = Pathname.new(ENV["SHAKAPACKER_CONFIG"] || config_path)
16
19
  end
17
20
 
18
21
  def dev_server
@@ -31,13 +34,24 @@ class Webpacker::Configuration
31
34
  fetch(:ensure_consistent_versioning)
32
35
  end
33
36
 
34
- def webpacker_precompile?
37
+ def shakapacker_precompile?
35
38
  # ENV of false takes precedence
36
- return false if %w(no false n f).include?(ENV["WEBPACKER_PRECOMPILE"])
37
- return true if %w(yes true y t).include?(ENV["WEBPACKER_PRECOMPILE"])
39
+ return false if %w(no false n f).include?(ENV["SHAKAPACKER_PRECOMPILE"])
40
+ return true if %w(yes true y t).include?(ENV["SHAKAPACKER_PRECOMPILE"])
38
41
 
39
42
  return false unless config_path.exist?
40
- fetch(:webpacker_precompile)
43
+ fetch(:shakapacker_precompile)
44
+ end
45
+
46
+ def webpacker_precompile?
47
+ Shakapacker.puts_deprecation_message(
48
+ Shakapacker.short_deprecation_message(
49
+ "webpacker_precompile?",
50
+ "shakapacker_precompile?"
51
+ )
52
+ )
53
+
54
+ shakapacker_precompile?
41
55
  end
42
56
 
43
57
  def source_path
@@ -49,7 +63,7 @@ class Webpacker::Configuration
49
63
  end
50
64
 
51
65
  def source_entry_path
52
- source_path.join(fetch(:source_entry_path))
66
+ source_path.join(relative_path(fetch(:source_entry_path)))
53
67
  end
54
68
 
55
69
  def manifest_path
@@ -80,14 +94,6 @@ class Webpacker::Configuration
80
94
  root_path.join(fetch(:cache_path))
81
95
  end
82
96
 
83
- def check_yarn_integrity=(value)
84
- warn <<~EOS
85
- Webpacker::Configuration#check_yarn_integrity=(value) is obsolete. The integrity
86
- check has been removed from Webpacker (https://github.com/rails/webpacker/pull/2518)
87
- so changing this setting will have no effect.
88
- EOS
89
- end
90
-
91
97
  def webpack_compile_output?
92
98
  fetch(:webpack_compile_output)
93
99
  end
@@ -97,7 +103,17 @@ class Webpacker::Configuration
97
103
  end
98
104
 
99
105
  def fetch(key)
100
- data.fetch(key, defaults[key])
106
+ return data.fetch(key, defaults[key]) unless key == :webpacker_precompile
107
+
108
+ # for backward compatibility
109
+ Shakapacker.puts_deprecation_message(
110
+ Shakapacker.short_deprecation_message(
111
+ "webpacker_precompile",
112
+ "shakapacker_precompile"
113
+ )
114
+ )
115
+
116
+ data.fetch(key, defaults[:shakapacker_precompile])
101
117
  end
102
118
 
103
119
  private
@@ -111,13 +127,22 @@ class Webpacker::Configuration
111
127
  rescue ArgumentError
112
128
  YAML.load_file(config_path.to_s)
113
129
  end
114
- config[env].deep_symbolize_keys
130
+ symbolized_config = config[env].deep_symbolize_keys
131
+
132
+ # For backward compatibility
133
+ if symbolized_config.key?(:shakapacker_precompile) && !symbolized_config.key?(:webpacker_precompile)
134
+ symbolized_config[:webpacker_precompile] = symbolized_config[:shakapacker_precompile]
135
+ elsif !symbolized_config.key?(:shakapacker_precompile) && symbolized_config.key?(:webpacker_precompile)
136
+ symbolized_config[:shakapacker_precompile] = symbolized_config[:webpacker_precompile]
137
+ end
138
+
139
+ return symbolized_config
115
140
  rescue Errno::ENOENT => e
116
141
  if self.class.installing
117
142
  {}
118
143
  else
119
- raise "Webpacker configuration file not found #{config_path}. " \
120
- "Please run rails webpacker:install " \
144
+ raise "Shakapacker configuration file not found #{config_path}. " \
145
+ "Please run rails shakapacker:install " \
121
146
  "Error: #{e.message}"
122
147
  end
123
148
  rescue Psych::SyntaxError => e
@@ -128,13 +153,19 @@ class Webpacker::Configuration
128
153
 
129
154
  def defaults
130
155
  @defaults ||= begin
131
- path = File.expand_path("../../install/config/webpacker.yml", __FILE__)
156
+ path = File.expand_path("../../install/config/shakapacker.yml", __FILE__)
132
157
  config = begin
133
158
  YAML.load_file(path, aliases: true)
134
159
  rescue ArgumentError
135
160
  YAML.load_file(path)
136
161
  end
137
- HashWithIndifferentAccess.new(config[env] || config[Webpacker::DEFAULT_ENV])
162
+ HashWithIndifferentAccess.new(config[env] || config[Shakapacker::DEFAULT_ENV])
138
163
  end
139
164
  end
165
+
166
+ def relative_path(path)
167
+ return ".#{path}" if path.start_with?("/")
168
+
169
+ path
170
+ end
140
171
  end
@@ -0,0 +1,87 @@
1
+ require "thor"
2
+
3
+ module Shakapacker
4
+ DEPRECATION_GUIDE_URL = "https://github.com/shakacode/shakapacker/docs/v7_upgrade.md"
5
+ DEPRECATION_MESSAGE = <<~MSG
6
+ DEPRECATION NOTICE:
7
+
8
+ Using webpacker spelling is deprecated in Shakapacker.
9
+ Update your project with the new spelling.
10
+
11
+ For more information about this process, check:
12
+ #{DEPRECATION_GUIDE_URL}
13
+ MSG
14
+ SHELL = Thor::Shell::Color.new
15
+
16
+ def get_config_file_path_with_backward_compatibility(config_path)
17
+ if config_path.to_s.end_with?("shakapacker.yml") && !File.exist?(config_path)
18
+ webpacker_config_path = if config_path.class == Pathname
19
+ Pathname.new(config_path.to_s.gsub("shakapacker.yml", "webpacker.yml"))
20
+ else
21
+ config_path.gsub("shakapacker.yml", "webpacker.yml")
22
+ end
23
+
24
+ if File.exist?(webpacker_config_path)
25
+ puts_deprecation_message(
26
+ short_deprecation_message(
27
+ "config/webpacker.yml",
28
+ "config/shakapacker.yml"
29
+ )
30
+ )
31
+ return webpacker_config_path
32
+ end
33
+ end
34
+
35
+ config_path
36
+ end
37
+
38
+ def set_shakapacker_env_variables_for_backward_compatibility
39
+ webpacker_env_variables = ENV.select { |key| key.start_with?("WEBPACKER_") }
40
+
41
+ deprecation_message_body = ""
42
+
43
+ webpacker_env_variables.each do |webpacker_key, _|
44
+ shakapacker_key = webpacker_key.gsub("WEBPACKER_", "SHAKAPACKER_")
45
+ next if ENV.key?(shakapacker_key)
46
+
47
+ deprecation_message_body += <<~MSG
48
+ Use `#{shakapacker_key}` instead of the deprecated `#{webpacker_key}`.
49
+ MSG
50
+
51
+ ENV[shakapacker_key] = ENV[webpacker_key]
52
+ end
53
+
54
+ if deprecation_message_body.present?
55
+ Shakapacker.puts_deprecation_message(
56
+ <<~MSG
57
+ DEPRECATION NOTICE:
58
+
59
+ #{deprecation_message_body}
60
+ Read more: #{Shakapacker::DEPRECATION_GUIDE_URL}
61
+ MSG
62
+ )
63
+ end
64
+ end
65
+
66
+ def short_deprecation_message(old_usage, new_usage)
67
+ <<~MSG
68
+ DEPRECATION NOTICE:
69
+
70
+ Consider using `#{new_usage}` instead of the deprecated `#{old_usage}`.
71
+ Read more: #{DEPRECATION_GUIDE_URL}
72
+ MSG
73
+ end
74
+
75
+ def puts_deprecation_message(message)
76
+ SHELL.say "\n#{message}\n", :yellow
77
+ end
78
+
79
+ def puts_rake_deprecation_message(webpacker_task_name)
80
+ Shakapacker.puts_deprecation_message(
81
+ Shakapacker.short_deprecation_message(
82
+ "rake #{webpacker_task_name}",
83
+ "rake #{webpacker_task_name.gsub("webpacker", "shakapacker")}"
84
+ )
85
+ )
86
+ end
87
+ end
@@ -1,8 +1,8 @@
1
- class Webpacker::DevServer
2
- DEFAULT_ENV_PREFIX = "WEBPACKER_DEV_SERVER".freeze
1
+ class Shakapacker::DevServer
2
+ DEFAULT_ENV_PREFIX = "SHAKAPACKER_DEV_SERVER".freeze
3
3
 
4
4
  # Configure dev server connection timeout (in seconds), default: 0.1
5
- # Webpacker.dev_server.connect_timeout = 1
5
+ # Shakapacker.dev_server.connect_timeout = 1
6
6
  cattr_accessor(:connect_timeout) { 0.1 }
7
7
 
8
8
  attr_reader :config
@@ -39,8 +39,29 @@ class Webpacker::DevServer
39
39
  end
40
40
  end
41
41
 
42
+ def server
43
+ server_value = fetch(:server)
44
+ server_type = server_value.is_a?(Hash) ? server_value[:type] : server_value
45
+
46
+ return server_type if ["http", "https"].include?(server_type)
47
+
48
+ return "http" if server_type.nil?
49
+
50
+ puts <<~MSG
51
+ WARNING:
52
+ `server: #{server_type}` is not a valid configuration in Shakapacker.
53
+ Falling back to default `server: http`.
54
+ MSG
55
+
56
+ "http"
57
+ rescue KeyError
58
+ "http"
59
+ end
60
+
42
61
  def protocol
43
- https? ? "https" : "http"
62
+ return "https" if server == "https" || https? == true
63
+
64
+ "http"
44
65
  end
45
66
 
46
67
  def host_with_port
@@ -73,6 +94,8 @@ class Webpacker::DevServer
73
94
  return nil unless config.dev_server.present?
74
95
 
75
96
  ENV["#{env_prefix}_#{key.upcase}"] || config.dev_server.fetch(key, defaults[key])
97
+ rescue
98
+ nil
76
99
  end
77
100
 
78
101
  def defaults