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
@@ -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
@@ -1,10 +1,10 @@
1
1
  require "rack/proxy"
2
2
 
3
- class Webpacker::DevServerProxy < Rack::Proxy
4
- delegate :config, :dev_server, to: :@webpacker
3
+ class Shakapacker::DevServerProxy < Rack::Proxy
4
+ delegate :config, :dev_server, to: :@instance
5
5
 
6
6
  def initialize(app = nil, opts = {})
7
- @webpacker = opts.delete(:webpacker) || Webpacker.instance
7
+ @instance = opts.delete(:shakapacker) || Shakapacker.instance
8
8
  opts[:streaming] = false if Rails.env.test? && !opts.key?(:streaming)
9
9
  super
10
10
  end
@@ -15,7 +15,7 @@ class Webpacker::DevServerProxy < Rack::Proxy
15
15
  env["HTTP_X_FORWARDED_SERVER"] = dev_server.host_with_port
16
16
  env["HTTP_PORT"] = env["HTTP_X_FORWARDED_PORT"] = dev_server.port.to_s
17
17
  env["HTTP_X_FORWARDED_PROTO"] = env["HTTP_X_FORWARDED_SCHEME"] = dev_server.protocol
18
- unless dev_server.https?
18
+ unless dev_server.protocol == "https"
19
19
  env["HTTPS"] = env["HTTP_X_FORWARDED_SSL"] = "off"
20
20
  end
21
21
  env["SCRIPT_NAME"] = ""
@@ -0,0 +1,104 @@
1
+ require "shellwords"
2
+ require "socket"
3
+ require "shakapacker/configuration"
4
+ require "shakapacker/dev_server"
5
+ require "shakapacker/runner"
6
+
7
+ module Shakapacker
8
+ class DevServerRunner < Shakapacker::Runner
9
+ def run
10
+ load_config
11
+ detect_unsupported_switches!
12
+ detect_port!
13
+ execute_cmd
14
+ end
15
+
16
+ private
17
+
18
+ def load_config
19
+ app_root = Pathname.new(@app_path)
20
+
21
+ @config = Configuration.new(
22
+ root_path: app_root,
23
+ config_path: Pathname.new(@shakapacker_config),
24
+ env: ENV["RAILS_ENV"]
25
+ )
26
+
27
+ dev_server = DevServer.new(@config)
28
+
29
+ @hostname = dev_server.host
30
+ @port = dev_server.port
31
+ @pretty = dev_server.pretty?
32
+ @https = dev_server.protocol == "https"
33
+ @hot = dev_server.hmr?
34
+
35
+ rescue Errno::ENOENT, NoMethodError
36
+ $stdout.puts "webpack 'dev_server' configuration not found in #{@config.config_path}[#{ENV["RAILS_ENV"]}]."
37
+ $stdout.puts "Please run bundle exec rails shakapacker:install to install Shakapacker"
38
+ exit!
39
+ end
40
+
41
+ UNSUPPORTED_SWITCHES = %w[--host --port]
42
+ private_constant :UNSUPPORTED_SWITCHES
43
+ def detect_unsupported_switches!
44
+ unsupported_switches = UNSUPPORTED_SWITCHES & @argv
45
+ if unsupported_switches.any?
46
+ $stdout.puts "The following CLI switches are not supported by Shakapacker: #{unsupported_switches.join(' ')}. Please edit your command and try again."
47
+ exit!
48
+ end
49
+
50
+ if @argv.include?("--https") && !@https
51
+ $stdout.puts "Please set https: true in shakapacker.yml to use the --https command line flag."
52
+ exit!
53
+ end
54
+ end
55
+
56
+ def detect_port!
57
+ server = TCPServer.new(@hostname, @port)
58
+ server.close
59
+
60
+ rescue Errno::EADDRINUSE
61
+ $stdout.puts "Another program is running on port #{@port}. Set a new port in #{@config.config_path} for dev_server"
62
+ exit!
63
+ end
64
+
65
+ def execute_cmd
66
+ env = Shakapacker::Compiler.env
67
+ env["SHAKAPACKER_CONFIG"] = @shakapacker_config
68
+ env["WEBPACK_SERVE"] = "true"
69
+
70
+ cmd = if node_modules_bin_exist?
71
+ ["#{@node_modules_bin_path}/webpack", "serve"]
72
+ else
73
+ ["yarn", "webpack", "serve"]
74
+ end
75
+
76
+ if @argv.include?("--debug-webpacker")
77
+ Shakapacker.puts_deprecation_message(
78
+ Shakapacker.short_deprecation_message(
79
+ "--debug-webpacker",
80
+ "--debug-shakapacker"
81
+ )
82
+ )
83
+ end
84
+
85
+ if @argv.delete("--debug-shakapacker") || @argv.delete("--debug-webpacker")
86
+ cmd = [ "node", "--inspect-brk", "--trace-warnings" ] + cmd
87
+ end
88
+
89
+ cmd += ["--config", @webpack_config]
90
+ cmd += ["--progress", "--color"] if @pretty
91
+
92
+ cmd += ["--hot"] if @hot
93
+ cmd += @argv
94
+
95
+ Dir.chdir(@app_path) do
96
+ Kernel.exec env, *cmd
97
+ end
98
+ end
99
+
100
+ def node_modules_bin_exist?
101
+ File.exist?("#{@node_modules_bin_path}/webpack-dev-server")
102
+ end
103
+ end
104
+ end
@@ -1,7 +1,7 @@
1
1
  require "digest/sha1"
2
- require "webpacker/base_strategy"
2
+ require "shakapacker/base_strategy"
3
3
 
4
- module Webpacker
4
+ module Shakapacker
5
5
  class DigestStrategy < BaseStrategy
6
6
  # Returns true if all the compiled packs are up to date with the underlying asset files.
7
7
  def fresh?
@@ -31,10 +31,10 @@ module Webpacker
31
31
  def watched_files_digest
32
32
  if Rails.env.development?
33
33
  warn <<~MSG.strip
34
- Webpacker::Compiler - Slow setup for development
34
+ Shakapacker::Compiler - Slow setup for development
35
35
  Prepare JS assets with either:
36
- 1. Running `bin/webpacker-dev-server`
37
- 2. Set `compile` to false in webpacker.yml and run `bin/webpacker -w`
36
+ 1. Running `bin/shakapacker-dev-server`
37
+ 2. Set `compile` to false in shakapacker.yml and run `bin/shakapacker -w`
38
38
  MSG
39
39
  end
40
40
 
@@ -53,7 +53,7 @@ module Webpacker
53
53
  end
54
54
 
55
55
  def compilation_digest_path
56
- config.cache_path.join("last-compilation-digest-#{Webpacker.env}")
56
+ config.cache_path.join("last-compilation-digest-#{Shakapacker.env}")
57
57
  end
58
58
  end
59
59
  end
@@ -1,17 +1,17 @@
1
- class Webpacker::Env
2
- delegate :config_path, :logger, to: :@webpacker
1
+ class Shakapacker::Env
2
+ delegate :config_path, :logger, to: :@instance
3
3
 
4
- def self.inquire(webpacker)
5
- new(webpacker).inquire
4
+ def self.inquire(instance)
5
+ new(instance).inquire
6
6
  end
7
7
 
8
- def initialize(webpacker)
9
- @webpacker = webpacker
8
+ def initialize(instance)
9
+ @instance = instance
10
10
  end
11
11
 
12
12
  def inquire
13
13
  fallback_env_warning if config_path.exist? && !current
14
- current || Webpacker::DEFAULT_ENV.inquiry
14
+ current || Shakapacker::DEFAULT_ENV.inquiry
15
15
  end
16
16
 
17
17
  private
@@ -20,7 +20,7 @@ class Webpacker::Env
20
20
  end
21
21
 
22
22
  def fallback_env_warning
23
- logger.info "RAILS_ENV=#{Rails.env} environment is not defined in config/webpacker.yml, falling back to #{Webpacker::DEFAULT_ENV} environment"
23
+ logger.info "RAILS_ENV=#{Rails.env} environment is not defined in config/shakapacker.yml, falling back to #{Shakapacker::DEFAULT_ENV} environment"
24
24
  end
25
25
 
26
26
  def available_environments