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
@@ -0,0 +1,107 @@
1
+ /* global test expect, describe, afterAll, beforeEach */
2
+
3
+ // environment.js expects to find config/webapacker.yml and resolved modules from
4
+ // the root of a Rails project
5
+
6
+ const { resetEnv, chdirWebpackerTestApp } = require('../../utils/helpers')
7
+
8
+ const rootPath = process.cwd()
9
+ chdirWebpackerTestApp()
10
+
11
+ const { resolve } = require('path')
12
+
13
+ const baseConfig = require('../base')
14
+ const config = require("../../config");
15
+
16
+ describe('Base config', () => {
17
+ beforeEach(() => jest.resetModules() && resetEnv())
18
+ afterAll(() => process.chdir(rootPath))
19
+
20
+ describe('config', () => {
21
+ test('should return entry', () => {
22
+ expect(baseConfig.entry.application).toEqual(
23
+ resolve('app', 'packs', 'entrypoints', 'application.js')
24
+ )
25
+ })
26
+
27
+ test('should return false for css_extract_ignore_order_warnings when using default config', () => {
28
+ expect(config.css_extract_ignore_order_warnings).toEqual(false)
29
+ })
30
+
31
+ test('should return true for css_extract_ignore_order_warnings when configured', () => {
32
+ process.env.WEBPACKER_CONFIG = 'config/webpacker_css_extract_ignore_order_warnings.yml'
33
+ const config = require("../../config");
34
+
35
+ expect(config.css_extract_ignore_order_warnings).toEqual(true)
36
+ })
37
+
38
+ test('should return only 2 entry points with config.nested_entries == false', () => {
39
+ expect(config.nested_entries).toEqual(false)
40
+
41
+ expect(baseConfig.entry.multi_entry.sort()).toEqual([
42
+ resolve('app', 'packs', 'entrypoints', 'multi_entry.css'),
43
+ resolve('app', 'packs', 'entrypoints', 'multi_entry.js')
44
+ ])
45
+ expect(baseConfig.entry['generated/something']).toEqual(undefined)
46
+ })
47
+
48
+ test('should returns top level and nested entry points with config.nested_entries == true', () => {
49
+ process.env.WEBPACKER_CONFIG = 'config/webpacker_nested_entries.yml'
50
+ const config = require("../../config");
51
+ const baseConfig = require('../base')
52
+
53
+ expect(config.nested_entries).toEqual(true)
54
+
55
+ expect(baseConfig.entry.application).toEqual(
56
+ resolve('app', 'packs', 'entrypoints', 'application.js')
57
+ )
58
+ expect(baseConfig.entry.multi_entry.sort()).toEqual([
59
+ resolve('app', 'packs', 'entrypoints', 'multi_entry.css'),
60
+ resolve('app', 'packs', 'entrypoints', 'multi_entry.js')
61
+ ])
62
+ expect(baseConfig.entry['generated/something']).toEqual(
63
+ resolve('app', 'packs', 'entrypoints', 'generated', 'something.js')
64
+ )
65
+ })
66
+
67
+ test('should return output', () => {
68
+ expect(baseConfig.output.filename).toEqual('js/[name]-[contenthash].js')
69
+ expect(baseConfig.output.chunkFilename).toEqual(
70
+ 'js/[name]-[contenthash].chunk.js'
71
+ )
72
+ })
73
+
74
+ test('should return default loader rules for each file in config/loaders', () => {
75
+ const rules = require('../../rules')
76
+
77
+ const defaultRules = Object.keys(rules)
78
+ const configRules = baseConfig.module.rules
79
+
80
+ expect(defaultRules.length).toEqual(3)
81
+ expect(configRules.length).toEqual(3)
82
+ })
83
+
84
+ test('should return default plugins', () => {
85
+ expect(baseConfig.plugins.length).toEqual(2)
86
+ })
87
+
88
+ test('should return default resolveLoader', () => {
89
+ expect(baseConfig.resolveLoader.modules).toEqual(['node_modules'])
90
+ })
91
+
92
+ test('should return default resolve.modules with additions', () => {
93
+ expect(baseConfig.resolve.modules).toEqual([
94
+ resolve('app', 'packs'),
95
+ resolve('app/assets'),
96
+ resolve('/etc/yarn'),
97
+ resolve('some.config.js'),
98
+ resolve('app/elm'),
99
+ 'node_modules'
100
+ ])
101
+ })
102
+
103
+ test('returns plugins property as Array', () => {
104
+ expect(baseConfig.plugins).toBeInstanceOf(Array)
105
+ })
106
+ })
107
+ })
@@ -1,10 +1,11 @@
1
1
  /* global test expect, describe, afterAll, beforeEach */
2
2
 
3
- // environment.js expects to find config/webpacker.yml and resolved modules from
3
+ // environment.js expects to find config/shakapacker.yml and resolved modules from
4
4
  // the root of a Rails project
5
5
 
6
6
  const { chdirTestApp, chdirCwd, resetEnv } = require('../../utils/helpers')
7
7
 
8
+ const rootPath = process.cwd()
8
9
  chdirTestApp()
9
10
 
10
11
  const { resolve } = require('path')
@@ -14,13 +15,12 @@ const config = require("../../config");
14
15
 
15
16
  describe('Base config', () => {
16
17
  beforeEach(() => jest.resetModules() && resetEnv())
17
-
18
- afterAll(chdirCwd)
18
+ afterAll(() => process.chdir(rootPath))
19
19
 
20
20
  describe('config', () => {
21
21
  test('should return entry', () => {
22
22
  expect(baseConfig.entry.application).toEqual(
23
- resolve('app', 'packs', 'entrypoints', 'application.js')
23
+ resolve('app', 'javascript', 'entrypoints', 'application.js')
24
24
  )
25
25
  })
26
26
 
@@ -29,7 +29,7 @@ describe('Base config', () => {
29
29
  })
30
30
 
31
31
  test('should return true for css_extract_ignore_order_warnings when configured', () => {
32
- process.env.WEBPACKER_CONFIG = 'config/webpacker_css_extract_ignore_order_warnings.yml'
32
+ process.env.SHAKAPACKER_CONFIG = 'config/shakapacker_css_extract_ignore_order_warnings.yml'
33
33
  const config = require("../../config");
34
34
 
35
35
  expect(config.css_extract_ignore_order_warnings).toEqual(true)
@@ -39,35 +39,35 @@ describe('Base config', () => {
39
39
  expect(config.nested_entries).toEqual(false)
40
40
 
41
41
  expect(baseConfig.entry.multi_entry.sort()).toEqual([
42
- resolve('app', 'packs', 'entrypoints', 'multi_entry.css'),
43
- resolve('app', 'packs', 'entrypoints', 'multi_entry.js')
42
+ resolve('app', 'javascript', 'entrypoints', 'multi_entry.css'),
43
+ resolve('app', 'javascript', 'entrypoints', 'multi_entry.js')
44
44
  ])
45
45
  expect(baseConfig.entry['generated/something']).toEqual(undefined)
46
46
  })
47
47
 
48
48
  test('should returns top level and nested entry points with config.nested_entries == true', () => {
49
- process.env.WEBPACKER_CONFIG = 'config/webpacker_nested_entries.yml'
49
+ process.env.SHAKAPACKER_CONFIG = 'config/shakapacker_nested_entries.yml'
50
50
  const config = require("../../config");
51
51
  const baseConfig = require('../base')
52
52
 
53
53
  expect(config.nested_entries).toEqual(true)
54
54
 
55
55
  expect(baseConfig.entry.application).toEqual(
56
- resolve('app', 'packs', 'entrypoints', 'application.js')
56
+ resolve('app', 'javascript', 'entrypoints', 'application.js')
57
57
  )
58
58
  expect(baseConfig.entry.multi_entry.sort()).toEqual([
59
- resolve('app', 'packs', 'entrypoints', 'multi_entry.css'),
60
- resolve('app', 'packs', 'entrypoints', 'multi_entry.js')
59
+ resolve('app', 'javascript', 'entrypoints', 'multi_entry.css'),
60
+ resolve('app', 'javascript', 'entrypoints', 'multi_entry.js')
61
61
  ])
62
62
  expect(baseConfig.entry['generated/something']).toEqual(
63
- resolve('app', 'packs', 'entrypoints', 'generated', 'something.js')
63
+ resolve('app', 'javascript', 'entrypoints', 'generated', 'something.js')
64
64
  )
65
65
  })
66
66
 
67
67
  test('should return output', () => {
68
- expect(baseConfig.output.filename).toEqual('js/[name].js')
68
+ expect(baseConfig.output.filename).toEqual('js/[name]-[contenthash].js')
69
69
  expect(baseConfig.output.chunkFilename).toEqual(
70
- 'js/[name].chunk.js'
70
+ 'js/[name]-[contenthash].chunk.js'
71
71
  )
72
72
  })
73
73
 
@@ -91,7 +91,7 @@ describe('Base config', () => {
91
91
 
92
92
  test('should return default resolve.modules with additions', () => {
93
93
  expect(baseConfig.resolve.modules).toEqual([
94
- resolve('app', 'packs'),
94
+ resolve('app', 'javascript'),
95
95
  resolve('app/assets'),
96
96
  resolve('/etc/yarn'),
97
97
  resolve('some.config.js'),
@@ -0,0 +1,53 @@
1
+ /* global test expect, describe, afterAll, beforeEach */
2
+
3
+ const { chdirTestApp, resetEnv } = require('../../utils/helpers')
4
+ const rootPath = process.cwd()
5
+ chdirTestApp()
6
+
7
+ describe('Development specific config', () => {
8
+ beforeEach(() => {
9
+ jest.resetModules()
10
+ resetEnv()
11
+ process.env['NODE_ENV'] = 'development'
12
+ })
13
+ afterAll(() => process.chdir(rootPath))
14
+
15
+ describe('with config.useContentHash = true', () => {
16
+ test('sets filename to use contentHash', () => {
17
+ const config = require("../../config");
18
+ config.useContentHash = true
19
+ const environmnetConfig = require('../development')
20
+
21
+ expect(environmnetConfig.output.filename).toEqual('js/[name]-[contenthash].js')
22
+ expect(environmnetConfig.output.chunkFilename).toEqual(
23
+ 'js/[name]-[contenthash].chunk.js'
24
+ )
25
+ })
26
+ })
27
+
28
+ describe('with config.useContentHash = false', () => {
29
+ test('sets filename without using contentHash', () => {
30
+ const config = require("../../config");
31
+ config.useContentHash = false
32
+ const environmnetConfig = require('../development')
33
+
34
+ expect(environmnetConfig.output.filename).toEqual('js/[name].js')
35
+ expect(environmnetConfig.output.chunkFilename).toEqual(
36
+ 'js/[name].chunk.js'
37
+ )
38
+ })
39
+ })
40
+
41
+ describe('with unset config.useContentHash', () => {
42
+ test('sets filename without using contentHash', () => {
43
+ const config = require("../../config");
44
+ delete config.useContentHash
45
+ const environmnetConfig = require('../development')
46
+
47
+ expect(environmnetConfig.output.filename).toEqual('js/[name].js')
48
+ expect(environmnetConfig.output.chunkFilename).toEqual(
49
+ 'js/[name].chunk.js'
50
+ )
51
+ })
52
+ })
53
+ })
@@ -0,0 +1,92 @@
1
+ /* global test expect, describe, afterAll, beforeEach */
2
+
3
+ const { chdirTestApp, resetEnv } = require('../../utils/helpers')
4
+ const rootPath = process.cwd()
5
+ chdirTestApp()
6
+
7
+ describe('Production specific config', () => {
8
+ beforeEach(() => {
9
+ jest.resetModules()
10
+ resetEnv()
11
+ process.env['NODE_ENV'] = 'production'
12
+ })
13
+ afterAll(() => process.chdir(rootPath))
14
+
15
+ describe('with config.useContentHash = true', () => {
16
+ test('sets filename to use contentHash', () => {
17
+ const config = require("../../config");
18
+ config.useContentHash = true
19
+ const environmnetConfig = require('../production')
20
+
21
+ expect(environmnetConfig.output.filename).toEqual('js/[name]-[contenthash].js')
22
+ expect(environmnetConfig.output.chunkFilename).toEqual(
23
+ 'js/[name]-[contenthash].chunk.js'
24
+ )
25
+ })
26
+
27
+ test("doesn't shows any warning message", () => {
28
+ const consoleWarnSpy = jest.spyOn(console, 'warn');
29
+ const config = require("../../config");
30
+ config.useContentHash = true
31
+ const environmnetConfig = require('../production')
32
+
33
+ expect(consoleWarnSpy).not.toHaveBeenCalledWith(
34
+ expect.stringMatching(/Setting 'useContentHash' to 'false' in the production environment/)
35
+ )
36
+
37
+ consoleWarnSpy.mockRestore()
38
+ })
39
+ })
40
+
41
+ describe('with config.useContentHash = false', () => {
42
+ test('sets filename to use contentHash', () => {
43
+ const config = require("../../config");
44
+ config.useContentHash = false
45
+ const environmnetConfig = require('../production')
46
+
47
+ expect(environmnetConfig.output.filename).toEqual('js/[name]-[contenthash].js')
48
+ expect(environmnetConfig.output.chunkFilename).toEqual(
49
+ 'js/[name]-[contenthash].chunk.js'
50
+ )
51
+ })
52
+
53
+ test('shows a warning message', () => {
54
+ const consoleWarnSpy = jest.spyOn(console, 'warn');
55
+ const config = require("../../config");
56
+ config.useContentHash = false
57
+ const environmnetConfig = require('../production')
58
+
59
+ expect(consoleWarnSpy).toHaveBeenCalledWith(
60
+ expect.stringMatching(/Setting 'useContentHash' to 'false' in the production environment/)
61
+ )
62
+
63
+ consoleWarnSpy.mockRestore()
64
+ })
65
+ })
66
+
67
+ describe('with unset config.useContentHash', () => {
68
+ test('sets filename to use contentHash', () => {
69
+ const config = require("../../config");
70
+ delete config.useContentHash
71
+ const environmnetConfig = require('../production')
72
+
73
+ expect(environmnetConfig.output.filename).toEqual('js/[name]-[contenthash].js')
74
+ expect(environmnetConfig.output.chunkFilename).toEqual(
75
+ 'js/[name]-[contenthash].chunk.js'
76
+ )
77
+ })
78
+
79
+ test("doesn't shows any warning message", () => {
80
+ const consoleWarnSpy = jest.spyOn(console, 'warn');
81
+ const config = require("../../config");
82
+ delete config.useContentHash
83
+ const environmnetConfig = require('../production')
84
+
85
+ expect(consoleWarnSpy).not.toHaveBeenCalledWith(
86
+ expect.stringMatching(/Setting 'useContentHash' to 'false' in the production environment/)
87
+ )
88
+
89
+ consoleWarnSpy.mockRestore()
90
+ })
91
+ })
92
+ })
@@ -7,8 +7,8 @@ const { sync: globSync } = require('glob')
7
7
  const WebpackAssetsManifest = require('webpack-assets-manifest')
8
8
  const webpack = require('webpack')
9
9
  const rules = require('../rules')
10
- const { isProduction } = require('../env')
11
10
  const config = require('../config')
11
+ const { isProduction } = require('../env')
12
12
  const { moduleExists } = require('../utils/helpers')
13
13
 
14
14
  const getEntryObject = () => {
@@ -16,7 +16,7 @@ const getEntryObject = () => {
16
16
  const rootPath = join(config.source_path, config.source_entry_path)
17
17
  if (config.source_entry_path === '/' && config.nested_entries) {
18
18
  throw new Error(
19
- "Your webpacker config specified using a source_entry_path of '/' with 'nested_entries' == " +
19
+ "Your shakapacker config specified using a source_entry_path of '/' with 'nested_entries' == " +
20
20
  "'true'. Doing this would result in packs for every one of your source files"
21
21
  )
22
22
  }
@@ -68,7 +68,7 @@ const getPlugins = () => {
68
68
  ]
69
69
 
70
70
  if (moduleExists('css-loader') && moduleExists('mini-css-extract-plugin')) {
71
- const hash = isProduction ? '-[contenthash:8]' : ''
71
+ const hash = isProduction || config.useContentHash ? '-[contenthash:8]' : ''
72
72
  const MiniCssExtractPlugin = require('mini-css-extract-plugin')
73
73
  plugins.push(
74
74
  new MiniCssExtractPlugin({
@@ -87,7 +87,8 @@ const getPlugins = () => {
87
87
 
88
88
  // Don't use contentHash except for production for performance
89
89
  // https://webpack.js.org/guides/build-performance/#avoid-production-specific-tooling
90
- const hash = isProduction ? '-[contenthash]' : ''
90
+ const hash = isProduction || config.useContentHash ? '-[contenthash]' : ''
91
+
91
92
  module.exports = {
92
93
  mode: 'production',
93
94
  output: {
@@ -1,55 +1,13 @@
1
1
  const { merge } = require('webpack-merge')
2
2
 
3
3
  const baseConfig = require('./base')
4
- const devServer = require('../dev_server')
4
+ const webpackDevServerConfig = require('../webpackDevServerConfig')
5
5
  const { runningWebpackDevServer } = require('../env')
6
6
 
7
- const { outputPath: contentBase, publicPath } = require('../config')
8
-
9
- let devConfig = {
7
+ const devConfig = {
10
8
  mode: 'development',
11
- devtool: 'cheap-module-source-map'
12
- }
13
-
14
- if (runningWebpackDevServer) {
15
- const liveReload = devServer.live_reload !== undefined ? devServer.live_reload : !devServer.hmr
16
-
17
- const devServerConfig = {
18
- devMiddleware: {
19
- publicPath
20
- },
21
- compress: devServer.compress,
22
- allowedHosts: devServer.allowed_hosts,
23
- host: devServer.host,
24
- port: devServer.port,
25
- https: devServer.https,
26
- hot: devServer.hmr,
27
- liveReload,
28
- historyApiFallback: { disableDotRule: true },
29
- headers: devServer.headers,
30
- static: {
31
- publicPath: contentBase
32
- }
33
- }
34
-
35
- if (devServer.static) {
36
- devServerConfig.static = { ...devServerConfig.static, ...devServer.static }
37
- }
38
-
39
- if (devServer.client) {
40
- devServerConfig.client = devServer.client
41
- }
42
-
43
- devConfig = merge(devConfig, {
44
- stats: {
45
- colors: true,
46
- entrypoints: false,
47
- errorDetails: true,
48
- modules: false,
49
- moduleTrace: false
50
- },
51
- devServer: devServerConfig
52
- })
9
+ devtool: 'cheap-module-source-map',
10
+ ...(runningWebpackDevServer && { devServer: webpackDevServerConfig() })
53
11
  }
54
12
 
55
13
  module.exports = merge(baseConfig, devConfig)
@@ -6,6 +6,7 @@ const CompressionPlugin = require('compression-webpack-plugin')
6
6
  const TerserPlugin = require('terser-webpack-plugin')
7
7
  const baseConfig = require('./base')
8
8
  const { moduleExists } = require('../utils/helpers')
9
+ const config = require('../config')
9
10
 
10
11
  const getPlugins = () => {
11
12
  const plugins = []
@@ -52,7 +53,7 @@ const productionConfig = {
52
53
  minimizer: [
53
54
  tryCssMinimizer(),
54
55
  new TerserPlugin({
55
- parallel: Number.parseInt(process.env.WEBPACKER_PARALLEL, 10) || true,
56
+ parallel: Number.parseInt(process.env.SHAKAPACKER_PARALLEL, 10) || true,
56
57
  terserOptions: {
57
58
  parse: {
58
59
  // Let terser parse ecma 8 code but always output
@@ -76,4 +77,12 @@ const productionConfig = {
76
77
  }
77
78
  }
78
79
 
80
+ if (config.useContentHash === false) {
81
+ // eslint-disable-next-line no-console
82
+ console.warn(`⚠️ WARNING
83
+ Setting 'useContentHash' to 'false' in the production environment (specified by NODE_ENV environment variable) is not allowed!
84
+ Content hashes get added to the filenames regardless of setting useContentHash in 'shakapacker.yml' to false.
85
+ `)
86
+ }
87
+
79
88
  module.exports = merge(baseConfig, productionConfig)
data/package/index.js CHANGED
@@ -10,19 +10,26 @@ const config = require('./config')
10
10
  const devServer = require('./dev_server')
11
11
  const env = require('./env')
12
12
  const { moduleExists, canProcess } = require('./utils/helpers')
13
- const inliningCss = require('./inliningCss')
13
+ const inliningCss = require('./utils/inliningCss')
14
14
 
15
- const webpackConfig = () => {
15
+ const globalMutableWebpackConfig = () => {
16
16
  const { nodeEnv } = env
17
17
  const path = resolve(__dirname, 'environments', `${nodeEnv}.js`)
18
18
  const environmentConfig = existsSync(path) ? require(path) : baseConfig
19
19
  return environmentConfig
20
20
  }
21
21
 
22
- module.exports = {
23
- config,
22
+ const generateWebpackConfig = () => {
23
+ const environmentConfig = globalMutableWebpackConfig()
24
+ const immutable = webpackMerge.merge({}, environmentConfig)
25
+ return immutable
26
+ }
27
+
28
+ const shakapackerObject = {
29
+ config, // shakapacker.yml
24
30
  devServer,
25
- webpackConfig: webpackConfig(),
31
+ generateWebpackConfig,
32
+ globalMutableWebpackConfig: globalMutableWebpackConfig(),
26
33
  baseConfig,
27
34
  env,
28
35
  rules,
@@ -31,3 +38,26 @@ module.exports = {
31
38
  inliningCss,
32
39
  ...webpackMerge
33
40
  }
41
+
42
+ // For backward compatibility
43
+ const shakapackerProxyHandler = {
44
+ get(target, prop) {
45
+ if (prop === 'webpackConfig') {
46
+ // eslint-disable-next-line no-console
47
+ console.warn(`⚠️
48
+ DEPRECATION NOTICE:
49
+ The 'webpackConfig' is deprecated and will be removed in a future version.
50
+ Please use 'globalMutableWebpackConfig' instead, or use
51
+ 'generateWebpackConfig()' to avoid unwanted config mutation across the app.
52
+
53
+ For more information, see version 7 upgrade documentation at:
54
+ https://github.com/shakacode/shakapacker/blob/master/docs/v7_upgrade.md
55
+ `)
56
+ return globalMutableWebpackConfig()
57
+ }
58
+
59
+ return target[prop]
60
+ }
61
+ }
62
+
63
+ module.exports = new Proxy(shakapackerObject, shakapackerProxyHandler)
@@ -0,0 +1,50 @@
1
+ const webpack = require("webpack");
2
+ const MemoryFS = require("memory-fs");
3
+ const thenify = require("thenify");
4
+ const path = require("path");
5
+
6
+ const createTrackLoader = () => {
7
+ const filesTracked = {};
8
+ return [
9
+ filesTracked,
10
+ (source) => {
11
+ filesTracked[source.resource] = true;
12
+ return source;
13
+ },
14
+ ];
15
+ };
16
+
17
+ const node_modules = path.resolve("node_modules");
18
+ const node_modules_included = path.resolve("node_modules/included");
19
+ const app_javascript = path.resolve("app/javascript");
20
+
21
+ const createInMemoryFs = () => {
22
+ const fs = new MemoryFS();
23
+
24
+ fs.mkdirpSync(node_modules);
25
+ fs.mkdirpSync(node_modules_included);
26
+ fs.mkdirpSync(app_javascript);
27
+
28
+ return fs;
29
+ };
30
+
31
+ const createTestCompiler = (config, fs = createInMemoryFs()) => {
32
+ Object.values(config.entry).forEach((file) => {
33
+ fs.writeFileSync(file, "console.log(1);");
34
+ });
35
+
36
+ const compiler = webpack(config);
37
+ compiler.run = thenify(compiler.run);
38
+ compiler.inputFileSystem = fs;
39
+ compiler.outputFileSystem = fs;
40
+ return compiler;
41
+ };
42
+
43
+ module.exports = {
44
+ createTrackLoader,
45
+ node_modules,
46
+ node_modules_included,
47
+ app_javascript,
48
+ createInMemoryFs,
49
+ createTestCompiler,
50
+ };
@@ -0,0 +1,63 @@
1
+ const path = require("path");
2
+ const {
3
+ app_javascript,
4
+ node_modules,
5
+ node_modules_included,
6
+ createTestCompiler,
7
+ createTrackLoader,
8
+ } = require("./__utils__/webpack");
9
+ const babelConfig = require("../babel");
10
+
11
+ jest.mock("../../config", () => {
12
+ const original = jest.requireActual("../../config");
13
+ return {
14
+ ...original,
15
+ additional_paths: [...original.additional_paths, "node_modules/included"],
16
+ };
17
+ });
18
+
19
+ const createWebpackConfig = (file, use) => {
20
+ return {
21
+ entry: { file },
22
+ module: {
23
+ rules: [
24
+ {
25
+ ...babelConfig,
26
+ use,
27
+ },
28
+ ],
29
+ },
30
+ output: {
31
+ path: "/",
32
+ filename: "scripts-bundled.js",
33
+ },
34
+ };
35
+ };
36
+
37
+ describe("babel", () => {
38
+ test("process source path", async () => {
39
+ const normalPath = `${app_javascript}/a.js`;
40
+ const [tracked, loader] = createTrackLoader();
41
+ const compiler = createTestCompiler(
42
+ createWebpackConfig(normalPath, loader)
43
+ );
44
+ await compiler.run();
45
+ expect(tracked[normalPath]).toBeTruthy();
46
+ });
47
+
48
+ test("exclude node_modules", async () => {
49
+ const ignored = `${node_modules}/a.js`;
50
+ const [tracked, loader] = createTrackLoader();
51
+ const compiler = createTestCompiler(createWebpackConfig(ignored, loader));
52
+ await compiler.run();
53
+ expect(tracked[ignored]).toBeUndefined();
54
+ });
55
+
56
+ test("explicitly included node_modules should be transpiled", async () => {
57
+ const included = `${node_modules_included}/a.js`;
58
+ const [tracked, loader] = createTrackLoader();
59
+ const compiler = createTestCompiler(createWebpackConfig(included, loader));
60
+ await compiler.run();
61
+ expect(tracked[included]).toBeTruthy();
62
+ });
63
+ });