shakapacker 7.3.0.beta.1 → 8.0.0.rc.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (231) hide show
  1. checksums.yaml +4 -4
  2. data/.eslintignore +1 -1
  3. data/.eslintrc.js +29 -8
  4. data/.github/PULL_REQUEST_TEMPLATE.md +10 -3
  5. data/.github/workflows/dummy.yml +6 -1
  6. data/.github/workflows/generator.yml +14 -18
  7. data/.github/workflows/node.yml +56 -0
  8. data/.github/workflows/ruby.yml +29 -17
  9. data/.node-version +1 -1
  10. data/.rubocop.yml +1 -0
  11. data/CHANGELOG.md +56 -5
  12. data/README.md +101 -48
  13. data/Rakefile +1 -7
  14. data/docs/customizing_babel_config.md +2 -2
  15. data/docs/deployment.md +13 -6
  16. data/docs/react.md +7 -13
  17. data/docs/troubleshooting.md +4 -4
  18. data/docs/using_esbuild_loader.md +1 -1
  19. data/docs/using_swc_loader.md +1 -1
  20. data/docs/v6_upgrade.md +1 -1
  21. data/docs/v8_upgrade.md +148 -0
  22. data/gemfiles/Gemfile-rails.7.1.x +12 -0
  23. data/jest.config.js +4 -0
  24. data/lib/install/config/shakapacker.yml +2 -2
  25. data/lib/install/template.rb +36 -30
  26. data/lib/shakapacker/base_strategy.rb +2 -1
  27. data/lib/shakapacker/compiler.rb +6 -21
  28. data/lib/shakapacker/configuration.rb +2 -46
  29. data/lib/shakapacker/deprecation_helper.rb +0 -78
  30. data/lib/shakapacker/dev_server.rb +1 -16
  31. data/lib/shakapacker/dev_server_runner.rb +2 -21
  32. data/lib/shakapacker/env.rb +1 -1
  33. data/lib/shakapacker/helper.rb +3 -3
  34. data/lib/shakapacker/instance.rb +1 -3
  35. data/lib/shakapacker/manifest.rb +1 -1
  36. data/lib/shakapacker/railtie.rb +7 -0
  37. data/lib/shakapacker/runner.rb +4 -18
  38. data/lib/shakapacker/utils/manager.rb +58 -0
  39. data/lib/shakapacker/utils/misc.rb +0 -12
  40. data/lib/shakapacker/version.rb +1 -1
  41. data/lib/shakapacker/version_checker.rb +9 -30
  42. data/lib/shakapacker/webpack_runner.rb +2 -21
  43. data/lib/shakapacker.rb +0 -2
  44. data/lib/tasks/shakapacker/check_binstubs.rake +12 -26
  45. data/lib/tasks/shakapacker/check_manager.rake +3 -8
  46. data/lib/tasks/shakapacker/info.rake +6 -15
  47. data/package/babel/preset.js +15 -15
  48. data/package/config.js +15 -19
  49. data/package/dev_server.js +4 -4
  50. data/package/env.js +19 -17
  51. data/package/environments/base.js +41 -24
  52. data/package/environments/development.js +6 -6
  53. data/package/environments/production.js +16 -16
  54. data/package/environments/test.js +1 -1
  55. data/package/esbuild/index.js +6 -6
  56. data/package/index.d.ts +0 -2
  57. data/package/index.js +17 -46
  58. data/package/rules/babel.js +6 -8
  59. data/package/rules/coffee.js +2 -2
  60. data/package/rules/css.js +1 -1
  61. data/package/rules/erb.js +4 -4
  62. data/package/rules/esbuild.js +5 -7
  63. data/package/rules/file.js +14 -7
  64. data/package/rules/index.js +11 -11
  65. data/package/rules/jscommon.js +8 -5
  66. data/package/rules/less.js +10 -9
  67. data/package/rules/raw.js +1 -1
  68. data/package/rules/sass.js +4 -4
  69. data/package/rules/stylus.js +12 -7
  70. data/package/rules/swc.js +5 -7
  71. data/package/swc/index.js +10 -10
  72. data/package/utils/configPath.js +3 -18
  73. data/package/utils/defaultConfigPath.js +1 -1
  74. data/package/utils/{get_style_rule.js → getStyleRule.js} +6 -6
  75. data/package/utils/helpers.js +2 -43
  76. data/package/utils/inliningCss.js +4 -3
  77. data/package/utils/snakeToCamelCase.js +5 -0
  78. data/package/webpackDevServerConfig.js +28 -25
  79. data/package.json +12 -18
  80. data/prettier.config.js +4 -0
  81. data/shakapacker.gemspec +1 -1
  82. data/spec/dummy/app/javascript/packs/application.js +1 -1
  83. data/spec/dummy/config/application.rb +3 -0
  84. data/spec/dummy/config/initializers/react_on_rails.rb +2 -2
  85. data/spec/dummy/config/shakapacker.yml +3 -4
  86. data/spec/dummy/config/webpack/commonWebpackConfig.js +0 -1
  87. data/spec/dummy/config/webpack/webpack.config.js +1 -1
  88. data/spec/dummy/package.json +2 -1
  89. data/spec/dummy/yarn.lock +2 -3
  90. data/spec/fixtures/github_url_package-lock.v1.json +1 -1
  91. data/spec/fixtures/github_url_package-lock.v2.json +2 -2
  92. data/spec/fixtures/github_url_package.json +1 -1
  93. data/spec/fixtures/github_url_pnpm-lock.v7.yaml +1 -1
  94. data/spec/fixtures/github_url_pnpm-lock.v8.yaml +1 -1
  95. data/spec/fixtures/github_url_yarn.v1.lock +1 -1
  96. data/spec/fixtures/github_url_yarn.v2.lock +2 -2
  97. data/spec/generator_specs/e2e_template/template.rb +15 -28
  98. data/spec/generator_specs/generator_spec.rb +6 -136
  99. data/spec/mounted_app/test/dummy/config/webpacker.yml +0 -1
  100. data/spec/shakapacker/compiler_spec.rb +1 -3
  101. data/spec/shakapacker/configuration_spec.rb +4 -56
  102. data/spec/shakapacker/dev_server_runner_spec.rb +19 -102
  103. data/spec/shakapacker/dev_server_spec.rb +1 -16
  104. data/spec/shakapacker/engine_rake_tasks_spec.rb +1 -16
  105. data/spec/shakapacker/helper_spec.rb +3 -3
  106. data/spec/shakapacker/instance_spec.rb +1 -3
  107. data/spec/shakapacker/rake_tasks_spec.rb +2 -14
  108. data/spec/shakapacker/shakapacker_spec.rb +0 -1
  109. data/spec/shakapacker/test_app/config/shakapacker_css_extract_ignore_order_warnings.yml +0 -1
  110. data/spec/shakapacker/test_app/config/shakapacker_manifest_path.yml +0 -1
  111. data/spec/shakapacker/test_app/config/shakapacker_nested_entries.yml +0 -1
  112. data/spec/shakapacker/test_app/config/shakapacker_other_location.yml +0 -1
  113. data/spec/shakapacker/test_app/package.json +2 -1
  114. data/spec/shakapacker/utils_manager_spec.rb +125 -0
  115. data/spec/shakapacker/version_checker_spec.rb +5 -5
  116. data/spec/shakapacker/webpack_runner_spec.rb +19 -28
  117. data/spec/support/package_json_helpers.rb +7 -4
  118. data/test/helpers.js +67 -0
  119. data/test/package/config.test.js +50 -0
  120. data/test/package/dev_server.test.js +44 -0
  121. data/test/package/development.test.js +43 -0
  122. data/test/package/env.test.js +57 -0
  123. data/test/package/environments/base.test.js +105 -0
  124. data/test/package/environments/development.test.js +50 -0
  125. data/test/package/environments/production.test.js +106 -0
  126. data/test/package/index.test.js +45 -0
  127. data/test/package/production.test.js +32 -0
  128. data/test/package/rules/babel.test.js +58 -0
  129. data/test/package/rules/esbuild.test.js +59 -0
  130. data/test/package/rules/file.test.js +81 -0
  131. data/test/package/rules/index.test.js +7 -0
  132. data/test/package/rules/raw.test.js +12 -0
  133. data/test/package/rules/swc.test.js +59 -0
  134. data/test/package/staging.test.js +31 -0
  135. data/test/package/test.test.js +28 -0
  136. data/yarn.lock +1278 -421
  137. metadata +50 -100
  138. data/.github/workflows/jest.yml +0 -33
  139. data/.github/workflows/js-lint.yml +0 -33
  140. data/.github/workflows/rubocop.yml +0 -28
  141. data/.github/workflows/ruby-backward-compatibility.yml +0 -51
  142. data/lib/install/package.json +0 -15
  143. data/lib/tasks/shakapacker/check_yarn.rake +0 -34
  144. data/lib/tasks/shakapacker/yarn_install.rake +0 -24
  145. data/lib/tasks/webpacker/binstubs.rake +0 -9
  146. data/lib/tasks/webpacker/check_binstubs.rake +0 -9
  147. data/lib/tasks/webpacker/check_node.rake +0 -9
  148. data/lib/tasks/webpacker/check_yarn.rake +0 -9
  149. data/lib/tasks/webpacker/clean.rake +0 -9
  150. data/lib/tasks/webpacker/clobber.rake +0 -11
  151. data/lib/tasks/webpacker/compile.rake +0 -9
  152. data/lib/tasks/webpacker/info.rake +0 -9
  153. data/lib/tasks/webpacker/install.rake +0 -9
  154. data/lib/tasks/webpacker/verify_config.rake +0 -9
  155. data/lib/tasks/webpacker/verify_install.rake +0 -9
  156. data/lib/tasks/webpacker/yarn_install.rake +0 -9
  157. data/lib/tasks/webpacker.rake +0 -20
  158. data/lib/webpacker/dev_server_runner.rb +0 -9
  159. data/lib/webpacker/webpack_runner.rb +0 -9
  160. data/lib/webpacker.rb +0 -4
  161. data/package/__tests__/config-bc.js +0 -27
  162. data/package/__tests__/config.js +0 -46
  163. data/package/__tests__/dev_server-bc.js +0 -46
  164. data/package/__tests__/dev_server.js +0 -46
  165. data/package/__tests__/development-bc.js +0 -66
  166. data/package/__tests__/development.js +0 -66
  167. data/package/__tests__/env-bc.js +0 -59
  168. data/package/__tests__/env.js +0 -59
  169. data/package/__tests__/index-bc.js +0 -22
  170. data/package/__tests__/index.js +0 -46
  171. data/package/__tests__/production-bc.js +0 -51
  172. data/package/__tests__/production.js +0 -51
  173. data/package/__tests__/staging-bc.js +0 -53
  174. data/package/__tests__/staging.js +0 -53
  175. data/package/__tests__/test-bc.js +0 -43
  176. data/package/__tests__/test.js +0 -43
  177. data/package/environments/__tests__/base-bc.js +0 -107
  178. data/package/environments/__tests__/base.js +0 -107
  179. data/package/environments/__tests__/development.js +0 -53
  180. data/package/environments/__tests__/production.js +0 -92
  181. data/package/rules/__tests__/__utils__/webpack.js +0 -50
  182. data/package/rules/__tests__/babel.js +0 -63
  183. data/package/rules/__tests__/esbuild.js +0 -64
  184. data/package/rules/__tests__/file.js +0 -79
  185. data/package/rules/__tests__/index.js +0 -7
  186. data/package/rules/__tests__/raw.js +0 -18
  187. data/package/rules/__tests__/swc.js +0 -63
  188. data/package/utils/snakeToCamelCase +0 -7
  189. data/spec/backward_compatibility_specs/command_spec.rb +0 -116
  190. data/spec/backward_compatibility_specs/compiler_spec.rb +0 -59
  191. data/spec/backward_compatibility_specs/compiler_strategy_spec.rb +0 -24
  192. data/spec/backward_compatibility_specs/configuration_spec.rb +0 -294
  193. data/spec/backward_compatibility_specs/dev_server_runner_spec.rb +0 -206
  194. data/spec/backward_compatibility_specs/dev_server_spec.rb +0 -47
  195. data/spec/backward_compatibility_specs/digest_strategy_spec.rb +0 -38
  196. data/spec/backward_compatibility_specs/engine_rake_tasks_spec.rb +0 -67
  197. data/spec/backward_compatibility_specs/env_spec.rb +0 -23
  198. data/spec/backward_compatibility_specs/helper_spec.rb +0 -243
  199. data/spec/backward_compatibility_specs/instance_spec.rb +0 -31
  200. data/spec/backward_compatibility_specs/manifest_spec.rb +0 -100
  201. data/spec/backward_compatibility_specs/mtime_strategy_spec.rb +0 -55
  202. data/spec/backward_compatibility_specs/rake_tasks_spec.rb +0 -41
  203. data/spec/backward_compatibility_specs/spec_helper_initializer.rb +0 -24
  204. data/spec/backward_compatibility_specs/webpack_runner_spec.rb +0 -86
  205. data/spec/backward_compatibility_specs/webpacker_spec.rb +0 -41
  206. data/spec/backward_compatibility_specs/webpacker_test_app/.gitignore +0 -2
  207. data/spec/backward_compatibility_specs/webpacker_test_app/Rakefile +0 -3
  208. data/spec/backward_compatibility_specs/webpacker_test_app/app/packs/entrypoints/application.js +0 -10
  209. data/spec/backward_compatibility_specs/webpacker_test_app/app/packs/entrypoints/generated/something.js +0 -2
  210. data/spec/backward_compatibility_specs/webpacker_test_app/app/packs/entrypoints/multi_entry.css +0 -4
  211. data/spec/backward_compatibility_specs/webpacker_test_app/app/packs/entrypoints/multi_entry.js +0 -4
  212. data/spec/backward_compatibility_specs/webpacker_test_app/bin/webpacker +0 -13
  213. data/spec/backward_compatibility_specs/webpacker_test_app/bin/webpacker-dev-server +0 -13
  214. data/spec/backward_compatibility_specs/webpacker_test_app/config/application.rb +0 -11
  215. data/spec/backward_compatibility_specs/webpacker_test_app/config/environment.rb +0 -4
  216. data/spec/backward_compatibility_specs/webpacker_test_app/config/initializers/inspect_autoload_paths.rb +0 -1
  217. data/spec/backward_compatibility_specs/webpacker_test_app/config/webpack/webpack.config.js +0 -0
  218. data/spec/backward_compatibility_specs/webpacker_test_app/config/webpacker.yml +0 -83
  219. data/spec/backward_compatibility_specs/webpacker_test_app/config/webpacker_css_extract_ignore_order_warnings.yml +0 -84
  220. data/spec/backward_compatibility_specs/webpacker_test_app/config/webpacker_defaults_fallback.yml +0 -11
  221. data/spec/backward_compatibility_specs/webpacker_test_app/config/webpacker_manifest_path.yml +0 -80
  222. data/spec/backward_compatibility_specs/webpacker_test_app/config/webpacker_nested_entries.yml +0 -83
  223. data/spec/backward_compatibility_specs/webpacker_test_app/config/webpacker_no_precompile.yml +0 -7
  224. data/spec/backward_compatibility_specs/webpacker_test_app/config/webpacker_other_location.yml +0 -85
  225. data/spec/backward_compatibility_specs/webpacker_test_app/config/webpacker_public_root.yml +0 -18
  226. data/spec/backward_compatibility_specs/webpacker_test_app/config.ru +0 -5
  227. data/spec/backward_compatibility_specs/webpacker_test_app/package.json +0 -13
  228. data/spec/backward_compatibility_specs/webpacker_test_app/public/packs/manifest.json +0 -58
  229. data/spec/backward_compatibility_specs/webpacker_test_app/some.config.js +0 -0
  230. data/spec/backward_compatibility_specs/webpacker_test_app/tmp/shakapacker/last-compilation-digest-production +0 -1
  231. data/spec/backward_compatibility_specs/webpacker_test_app/yarn.lock +0 -11
@@ -17,41 +17,19 @@ module Shakapacker
17
17
 
18
18
  def raise_if_gem_and_node_package_versions_differ
19
19
  # Skip check if package is not in package.json or listed from relative path, git repo or github URL
20
- return if node_package_version.skip_processing?
20
+ # or if consistent version checking is not enabled
21
+ return if node_package_version.skip_processing? || !Shakapacker.config.ensure_consistent_versioning?
21
22
 
22
23
  node_major_minor_patch = node_package_version.major_minor_patch
23
24
  gem_major_minor_patch = gem_major_minor_patch_version
24
- versions_match = node_major_minor_patch[0] == gem_major_minor_patch[0] &&
25
- node_major_minor_patch[1] == gem_major_minor_patch[1] &&
26
- node_major_minor_patch[2] == gem_major_minor_patch[2]
27
25
 
28
- uses_wildcard = node_package_version.semver_wildcard?
26
+ raise_differing_versions_warning unless (
27
+ node_major_minor_patch[0] == gem_major_minor_patch[0] &&
28
+ node_major_minor_patch[1] == gem_major_minor_patch[1] &&
29
+ node_major_minor_patch[2] == gem_major_minor_patch[2]
30
+ )
29
31
 
30
- if !Shakapacker.config.ensure_consistent_versioning? && (uses_wildcard || !versions_match)
31
- check_failed = if uses_wildcard
32
- "Semver wildcard without a lockfile detected"
33
- else
34
- "Version mismatch detected"
35
- end
36
-
37
- warn <<-MSG.strip_heredoc
38
- Shakapacker::VersionChecker - #{check_failed}
39
-
40
- You are currently not checking for consistent versions of shakapacker gem and npm package. A version mismatch or usage of semantic versioning wildcard (~ or ^) without a lockfile has been detected.
41
-
42
- Version mismatch can lead to incorrect behavior and bugs. You should ensure that both the gem and npm package dependencies are locked to the same version.
43
-
44
- You can enable the version check by setting `ensure_consistent_versioning: true` in your `shakapacker.yml` file.
45
-
46
- Checking for gem and npm package versions mismatch or wildcard will be enabled by default in the next major version of shakapacker.
47
- MSG
48
-
49
- return
50
- end
51
-
52
- raise_differing_versions_warning unless versions_match
53
-
54
- raise_node_semver_version_warning if uses_wildcard
32
+ raise_node_semver_version_warning if node_package_version.semver_wildcard?
55
33
  end
56
34
 
57
35
  private
@@ -87,6 +65,7 @@ module Shakapacker
87
65
  [match[1], match[2], match[3]]
88
66
  end
89
67
 
68
+ # TODO: this might as well use package_json
90
69
  class NodePackageVersion
91
70
  attr_reader :package_json
92
71
 
@@ -23,16 +23,7 @@ module Shakapacker
23
23
 
24
24
  cmd = build_cmd
25
25
 
26
- if @argv.include?("--debug-webpacker")
27
- Shakapacker.puts_deprecation_message(
28
- Shakapacker.short_deprecation_message(
29
- "--debug-webpacker",
30
- "--debug-shakapacker"
31
- )
32
- )
33
- end
34
-
35
- if @argv.delete("--debug-shakapacker") || @argv.delete("--debug-webpacker")
26
+ if @argv.delete("--debug-shakapacker")
36
27
  env["NODE_OPTIONS"] = "#{env["NODE_OPTIONS"]} --inspect-brk"
37
28
  end
38
29
 
@@ -59,17 +50,7 @@ module Shakapacker
59
50
  private
60
51
 
61
52
  def build_cmd
62
- if Shakapacker::Utils::Misc.use_package_json_gem
63
- return package_json.manager.native_exec_command("webpack")
64
- end
65
-
66
- return ["#{@node_modules_bin_path}/webpack"] if node_modules_bin_exist?
67
-
68
- ["yarn", "webpack"]
69
- end
70
-
71
- def node_modules_bin_exist?
72
- File.exist?("#{@node_modules_bin_path}/webpack")
53
+ package_json.manager.native_exec_command("webpack")
73
54
  end
74
55
  end
75
56
  end
data/lib/shakapacker.rb CHANGED
@@ -47,5 +47,3 @@ require "shakapacker/dev_server"
47
47
  require "shakapacker/deprecation_helper"
48
48
 
49
49
  require "shakapacker/railtie" if defined?(Rails)
50
-
51
- Webpacker = Shakapacker
@@ -1,34 +1,20 @@
1
1
  namespace :shakapacker do
2
2
  desc "Verifies that bin/shakapacker is present"
3
3
  task :check_binstubs do
4
- verify_file_existence("bin/shakapacker", "bin/webpacker")
5
- verify_file_existence("bin/shakapacker-dev-server", "bin/webpacker-dev-server")
4
+ verify_file_existence("bin/shakapacker")
5
+ verify_file_existence("bin/shakapacker-dev-server")
6
6
  end
7
7
  end
8
8
 
9
- def verify_file_existance(main_file, alternative_file)
10
- puts "verify_file_existance is deprecated - use verify_file_existence instead"
11
- verify_file_existence(main_file, alternative_file)
12
- end
13
-
14
- def verify_file_existence(main_file, alternative_file)
15
- unless File.exist?(Rails.root.join(main_file))
16
- if File.exist?(Rails.root.join(alternative_file))
17
- Shakapacker.puts_deprecation_message(
18
- Shakapacker.short_deprecation_message(
19
- alternative_file,
20
- main_file
21
- )
22
- )
23
- else
24
- puts <<~MSG
25
- Couldn't find shakapacker binstubs!
26
- Possible solutions:
27
- - Ensure you have run `rails shakapacker:install`.
28
- - Run `rails shakapacker:binstubs` if you have already installed shakapacker.
29
- - Ensure the `bin` directory, `bin/shakapacker`, and `bin/shakapacker-dev-server` are not included in .gitignore.
30
- MSG
31
- exit!
32
- end
9
+ def verify_file_existence(binstub_file)
10
+ unless File.exist?(Rails.root.join(binstub_file))
11
+ puts <<~MSG
12
+ Couldn't find shakapacker binstubs!
13
+ Possible solutions:
14
+ - Ensure you have run `rails shakapacker:install`.
15
+ - Run `rails shakapacker:binstubs` if you have already installed shakapacker.
16
+ - Ensure the `bin` directory, `bin/shakapacker`, and `bin/shakapacker-dev-server` are not included in .gitignore.
17
+ MSG
18
+ exit!
33
19
  end
34
20
  end
@@ -1,15 +1,10 @@
1
1
  require "shakapacker/utils/misc"
2
+ require "shakapacker/utils/manager"
2
3
 
3
4
  namespace :shakapacker do
4
5
  desc "Verifies if the expected JS package manager is installed"
5
- task :check_manager do |task|
6
- unless Shakapacker::Utils::Misc.use_package_json_gem
7
- prefix = task.name.split(/#|shakapacker:/).first
8
- Rake::Task["#{prefix}shakapacker:check_manager"].invoke
9
- next
10
- end
11
-
12
- require "package_json"
6
+ task :check_manager do
7
+ Shakapacker::Utils::Manager.error_unless_package_manager_is_obvious!
13
8
 
14
9
  package_json = PackageJson.read
15
10
  pm = package_json.manager.binary
@@ -1,5 +1,6 @@
1
1
  require "shakapacker/version"
2
2
  require "shakapacker/utils/misc"
3
+ require "shakapacker/utils/manager"
3
4
 
4
5
  namespace :shakapacker do
5
6
  desc "Provide information on Shakapacker's environment"
@@ -9,30 +10,20 @@ namespace :shakapacker do
9
10
  $stdout.puts "Rails: #{Rails.version}"
10
11
  $stdout.puts "Shakapacker: #{Shakapacker::VERSION}"
11
12
  $stdout.puts "Node: #{`node --version`}"
12
- if Shakapacker::Utils::Misc.use_package_json_gem
13
- require "package_json"
14
13
 
15
- pj_manager = PackageJson.read.manager
14
+ Shakapacker::Utils::Manager.error_unless_package_manager_is_obvious!
16
15
 
17
- $stdout.puts "#{pj_manager.binary}: #{pj_manager.version}"
18
- else
19
- $stdout.puts "Yarn: #{`yarn --version`}"
20
- end
16
+ pj_manager = PackageJson.read.manager
21
17
 
22
- if Shakapacker::Utils::Misc.use_package_json_gem
23
- node_package_version = Shakapacker::VersionChecker.build.node_package_version.raw
24
- else
25
- node_package_version = `npm list shakapacker version`
26
- end
18
+ $stdout.puts "#{pj_manager.binary}: #{pj_manager.version}"
19
+
20
+ node_package_version = Shakapacker::VersionChecker.build.node_package_version.raw
27
21
 
28
22
  $stdout.puts "\n"
29
23
  $stdout.puts "shakapacker: #{node_package_version}"
30
24
 
31
25
  $stdout.puts "Is bin/shakapacker present?: #{File.exist? 'bin/shakapacker'}"
32
26
  $stdout.puts "Is bin/shakapacker-dev-server present?: #{File.exist? 'bin/shakapacker-dev-server'}"
33
- unless Shakapacker::Utils::Misc.use_package_json_gem
34
- $stdout.puts "Is bin/yarn present?: #{File.exist? 'bin/yarn'}"
35
- end
36
27
  end
37
28
  end
38
29
  end
@@ -1,11 +1,11 @@
1
- const { moduleExists } = require('shakapacker')
1
+ const { moduleExists } = require("shakapacker")
2
2
 
3
3
  module.exports = function config(api) {
4
- const validEnv = ['development', 'test', 'production']
4
+ const validEnv = ["development", "test", "production"]
5
5
  const currentEnv = api.env()
6
- const isDevelopmentEnv = api.env('development')
7
- const isProductionEnv = api.env('production')
8
- const isTestEnv = api.env('test')
6
+ const isDevelopmentEnv = api.env("development")
7
+ const isProductionEnv = api.env("production")
8
+ const isTestEnv = api.env("test")
9
9
 
10
10
  if (!validEnv.includes(currentEnv)) {
11
11
  throw new Error(
@@ -17,21 +17,21 @@ module.exports = function config(api) {
17
17
 
18
18
  return {
19
19
  presets: [
20
- isTestEnv && ['@babel/preset-env', { targets: { node: 'current' } }],
20
+ isTestEnv && ["@babel/preset-env", { targets: { node: "current" } }],
21
21
  (isProductionEnv || isDevelopmentEnv) && [
22
- '@babel/preset-env',
22
+ "@babel/preset-env",
23
23
  {
24
- useBuiltIns: 'entry',
25
- corejs: '3.8',
26
- modules: 'auto',
24
+ useBuiltIns: "entry",
25
+ corejs: "3.8",
26
+ modules: "auto",
27
27
  bugfixes: true,
28
- exclude: ['transform-typeof-symbol']
28
+ exclude: ["transform-typeof-symbol"]
29
29
  }
30
30
  ],
31
- moduleExists('@babel/preset-typescript') && '@babel/preset-typescript'
31
+ moduleExists("@babel/preset-typescript") && "@babel/preset-typescript"
32
32
  ].filter(Boolean),
33
- plugins: [
34
- ['@babel/plugin-transform-runtime', { helpers: false }]
35
- ].filter(Boolean)
33
+ plugins: [["@babel/plugin-transform-runtime", { helpers: false }]].filter(
34
+ Boolean
35
+ )
36
36
  }
37
37
  }
data/package/config.js CHANGED
@@ -1,19 +1,16 @@
1
- const { resolve } = require('path')
2
- const { load } = require('js-yaml')
3
- const { existsSync, readFileSync } = require('fs')
1
+ const { resolve } = require("path")
2
+ const { load } = require("js-yaml")
3
+ const { existsSync, readFileSync } = require("fs")
4
4
 
5
- const { merge } = require('webpack-merge')
6
- const {
7
- ensureTrailingSlash,
8
- setShakapackerEnvVariablesForBackwardCompatibility
9
- } = require('./utils/helpers')
10
- const { railsEnv } = require('./env')
11
- const configPath = require('./utils/configPath')
5
+ const { merge } = require("webpack-merge")
6
+ const { ensureTrailingSlash } = require("./utils/helpers")
7
+ const { railsEnv } = require("./env")
8
+ const configPath = require("./utils/configPath")
12
9
 
13
- const defaultConfigPath = require('./utils/defaultConfigPath')
10
+ const defaultConfigPath = require("./utils/defaultConfigPath")
14
11
 
15
12
  const getDefaultConfig = () => {
16
- const defaultConfig = load(readFileSync(defaultConfigPath), 'utf8')
13
+ const defaultConfig = load(readFileSync(defaultConfigPath), "utf8")
17
14
  return defaultConfig[railsEnv] || defaultConfig.production
18
15
  }
19
16
 
@@ -21,12 +18,14 @@ const defaults = getDefaultConfig()
21
18
  let config
22
19
 
23
20
  if (existsSync(configPath)) {
24
- const appYmlObject = load(readFileSync(configPath), 'utf8')
21
+ const appYmlObject = load(readFileSync(configPath), "utf8")
25
22
  const envAppConfig = appYmlObject[railsEnv]
26
23
 
27
24
  if (!envAppConfig) {
28
25
  /* eslint no-console:0 */
29
- console.warn(`Warning: ${railsEnv} key not found in the configuration file. Using production configuration as a fallback.`)
26
+ console.warn(
27
+ `Warning: ${railsEnv} key not found in the configuration file. Using production configuration as a fallback.`
28
+ )
30
29
  }
31
30
 
32
31
  config = merge(defaults, envAppConfig || {})
@@ -39,8 +38,7 @@ config.outputPath = resolve(config.public_root_path, config.public_output_path)
39
38
  // Ensure that the publicPath includes our asset host so dynamic imports
40
39
  // (code-splitting chunks and static assets) load from the CDN instead of a relative path.
41
40
  const getPublicPath = () => {
42
- setShakapackerEnvVariablesForBackwardCompatibility()
43
- const rootUrl = ensureTrailingSlash(process.env.SHAKAPACKER_ASSET_HOST || '/')
41
+ const rootUrl = ensureTrailingSlash(process.env.SHAKAPACKER_ASSET_HOST || "/")
44
42
  return `${rootUrl}${config.public_output_path}/`
45
43
  }
46
44
 
@@ -50,9 +48,7 @@ config.publicPathWithoutCDN = `/${config.public_output_path}/`
50
48
  if (config.manifest_path) {
51
49
  config.manifestPath = resolve(config.manifest_path)
52
50
  } else {
53
- config.manifestPath = resolve(config.outputPath, 'manifest.json')
51
+ config.manifestPath = resolve(config.outputPath, "manifest.json")
54
52
  }
55
53
 
56
- config.includePaths = [config.source_path, ...config.additional_paths]
57
-
58
54
  module.exports = config
@@ -1,6 +1,6 @@
1
- // These are the raw webpacker dev server config settings from the YML file with ENV overrides applied.
2
- const { isBoolean } = require('./utils/helpers')
3
- const config = require('./config')
1
+ // These are the raw shakapacker dev server config settings from the YML file with ENV overrides applied.
2
+ const { isBoolean } = require("./utils/helpers")
3
+ const config = require("./config")
4
4
 
5
5
  const envFetch = (key) => {
6
6
  const value = process.env[key]
@@ -10,7 +10,7 @@ const envFetch = (key) => {
10
10
  const devServerConfig = config.dev_server
11
11
 
12
12
  if (devServerConfig) {
13
- const envPrefix = config.dev_server.env_prefix || 'SHAKAPACKER_DEV_SERVER'
13
+ const envPrefix = config.dev_server.env_prefix || "SHAKAPACKER_DEV_SERVER"
14
14
 
15
15
  Object.keys(devServerConfig).forEach((key) => {
16
16
  const envValue = envFetch(`${envPrefix}_${key.toUpperCase()}`)
data/package/env.js CHANGED
@@ -1,40 +1,42 @@
1
- const { load } = require('js-yaml')
2
- const { readFileSync } = require('fs')
3
- const defaultConfigPath = require('./utils/defaultConfigPath')
1
+ const { load } = require("js-yaml")
2
+ const { readFileSync } = require("fs")
3
+ const defaultConfigPath = require("./utils/defaultConfigPath")
4
4
 
5
- const NODE_ENVIRONMENTS = ['development', 'production', 'test']
6
- const DEFAULT = 'production'
7
- const configPath = require('./utils/configPath')
5
+ const NODE_ENVIRONMENTS = ["development", "production", "test"]
6
+ const DEFAULT = "production"
7
+ const configPath = require("./utils/configPath")
8
8
 
9
9
  const railsEnv = process.env.RAILS_ENV
10
10
  const rawNodeEnv = process.env.NODE_ENV
11
- const nodeEnv
12
- = rawNodeEnv && NODE_ENVIRONMENTS.includes(rawNodeEnv) ? rawNodeEnv : DEFAULT
13
- const isProduction = nodeEnv === 'production'
14
- const isDevelopment = nodeEnv === 'development'
11
+ const nodeEnv =
12
+ rawNodeEnv && NODE_ENVIRONMENTS.includes(rawNodeEnv) ? rawNodeEnv : DEFAULT
13
+ const isProduction = nodeEnv === "production"
14
+ const isDevelopment = nodeEnv === "development"
15
15
 
16
16
  let config
17
17
  try {
18
- config = load(readFileSync(configPath), 'utf8')
18
+ config = load(readFileSync(configPath), "utf8")
19
19
  } catch (error) {
20
- if (error.code === 'ENOENT') {
20
+ if (error.code === "ENOENT") {
21
21
  // File not found, use default configuration
22
- config = load(readFileSync(defaultConfigPath), 'utf8')
22
+ config = load(readFileSync(defaultConfigPath), "utf8")
23
23
  } else {
24
24
  throw error
25
25
  }
26
26
  }
27
27
 
28
- const availableEnvironments = Object.keys(config).join('|')
29
- const regex = new RegExp(`^(${availableEnvironments})$`, 'g')
28
+ const availableEnvironments = Object.keys(config).join("|")
29
+ const regex = new RegExp(`^(${availableEnvironments})$`, "g")
30
30
 
31
- const runningWebpackDevServer = process.env.WEBPACK_SERVE === 'true'
31
+ const runningWebpackDevServer = process.env.WEBPACK_SERVE === "true"
32
32
 
33
33
  const validatedRailsEnv = railsEnv && railsEnv.match(regex) ? railsEnv : DEFAULT
34
34
 
35
35
  if (railsEnv && validatedRailsEnv !== railsEnv) {
36
36
  /* eslint no-console:0 */
37
- console.warn(`Warning: '${railsEnv}' environment not found in the configuration. Using '${DEFAULT}' configuration as a fallback.`)
37
+ console.warn(
38
+ `Warning: '${railsEnv}' environment not found in the configuration. Using '${DEFAULT}' configuration as a fallback.`
39
+ )
38
40
  }
39
41
 
40
42
  module.exports = {
@@ -1,28 +1,45 @@
1
1
  /* eslint global-require: 0 */
2
2
  /* eslint import/no-dynamic-require: 0 */
3
3
 
4
- const { basename, dirname, join, relative, resolve } = require('path')
5
- const extname = require('path-complete-extname')
6
- const { sync: globSync } = require('glob')
7
- const WebpackAssetsManifest = require('webpack-assets-manifest')
8
- const webpack = require('webpack')
9
- const rules = require('../rules')
10
- const config = require('../config')
11
- const { isProduction } = require('../env')
12
- const { moduleExists } = require('../utils/helpers')
4
+ const { existsSync, readdirSync } = require("fs")
5
+ const { basename, dirname, join, relative, resolve } = require("path")
6
+ const extname = require("path-complete-extname")
7
+ const WebpackAssetsManifest = require("webpack-assets-manifest")
8
+ const webpack = require("webpack")
9
+ const rules = require("../rules")
10
+ const config = require("../config")
11
+ const { isProduction } = require("../env")
12
+ const { moduleExists } = require("../utils/helpers")
13
+
14
+ const getFilesInDirectory = (dir, includeNested) => {
15
+ if (!existsSync(dir)) {
16
+ return []
17
+ }
18
+
19
+ return readdirSync(dir, { withFileTypes: true }).flatMap((dirent) => {
20
+ const filePath = join(dir, dirent.name)
21
+
22
+ if (dirent.isDirectory() && includeNested) {
23
+ return getFilesInDirectory(filePath, includeNested)
24
+ }
25
+ if (dirent.isFile()) {
26
+ return filePath
27
+ }
28
+ return []
29
+ })
30
+ }
13
31
 
14
32
  const getEntryObject = () => {
15
33
  const entries = {}
16
34
  const rootPath = join(config.source_path, config.source_entry_path)
17
- if (config.source_entry_path === '/' && config.nested_entries) {
35
+ if (config.source_entry_path === "/" && config.nested_entries) {
18
36
  throw new Error(
19
37
  "Your shakapacker config specified using a source_entry_path of '/' with 'nested_entries' == " +
20
- "'true'. Doing this would result in packs for every one of your source files"
38
+ "'true'. Doing this would result in packs for every one of your source files"
21
39
  )
22
40
  }
23
- const nesting = config.nested_entries ? '**/' : ''
24
41
 
25
- globSync(`${rootPath}/${nesting}*.*`).forEach((path) => {
42
+ getFilesInDirectory(rootPath, config.nested_entries).forEach((path) => {
26
43
  const namespace = relative(join(rootPath), dirname(path))
27
44
  const name = join(namespace, basename(path, extname(path)))
28
45
  let assetPaths = resolve(path)
@@ -50,7 +67,7 @@ const getModulePaths = () => {
50
67
  if (config.additional_paths) {
51
68
  config.additional_paths.forEach((path) => result.push(resolve(path)))
52
69
  }
53
- result.push('node_modules')
70
+ result.push("node_modules")
54
71
 
55
72
  return result
56
73
  }
@@ -67,9 +84,9 @@ const getPlugins = () => {
67
84
  })
68
85
  ]
69
86
 
70
- if (moduleExists('css-loader') && moduleExists('mini-css-extract-plugin')) {
71
- const hash = isProduction || config.useContentHash ? '-[contenthash:8]' : ''
72
- const MiniCssExtractPlugin = require('mini-css-extract-plugin')
87
+ if (moduleExists("css-loader") && moduleExists("mini-css-extract-plugin")) {
88
+ const hash = isProduction || config.useContentHash ? "-[contenthash:8]" : ""
89
+ const MiniCssExtractPlugin = require("mini-css-extract-plugin")
73
90
  plugins.push(
74
91
  new MiniCssExtractPlugin({
75
92
  filename: `css/[name]${hash}.css`,
@@ -87,35 +104,35 @@ const getPlugins = () => {
87
104
 
88
105
  // Don't use contentHash except for production for performance
89
106
  // https://webpack.js.org/guides/build-performance/#avoid-production-specific-tooling
90
- const hash = isProduction || config.useContentHash ? '-[contenthash]' : ''
107
+ const hash = isProduction || config.useContentHash ? "-[contenthash]" : ""
91
108
 
92
109
  module.exports = {
93
- mode: 'production',
110
+ mode: "production",
94
111
  output: {
95
112
  filename: `js/[name]${hash}.js`,
96
113
  chunkFilename: `js/[name]${hash}.chunk.js`,
97
114
 
98
115
  // https://webpack.js.org/configuration/output/#outputhotupdatechunkfilename
99
- hotUpdateChunkFilename: 'js/[id].[fullhash].hot-update.js',
116
+ hotUpdateChunkFilename: "js/[id].[fullhash].hot-update.js",
100
117
  path: config.outputPath,
101
118
  publicPath: config.publicPath
102
119
  },
103
120
  entry: getEntryObject(),
104
121
  resolve: {
105
- extensions: ['.js', '.jsx', '.mjs', '.ts', '.tsx', '.coffee'],
122
+ extensions: [".js", ".jsx", ".mjs", ".ts", ".tsx", ".coffee"],
106
123
  modules: getModulePaths()
107
124
  },
108
125
 
109
126
  plugins: getPlugins(),
110
127
 
111
128
  resolveLoader: {
112
- modules: ['node_modules']
129
+ modules: ["node_modules"]
113
130
  },
114
131
 
115
132
  optimization: {
116
- splitChunks: { chunks: 'all' },
133
+ splitChunks: { chunks: "all" },
117
134
 
118
- runtimeChunk: 'single'
135
+ runtimeChunk: "single"
119
136
  },
120
137
 
121
138
  module: {
@@ -1,12 +1,12 @@
1
- const { merge } = require('webpack-merge')
1
+ const { merge } = require("webpack-merge")
2
2
 
3
- const baseConfig = require('./base')
4
- const webpackDevServerConfig = require('../webpackDevServerConfig')
5
- const { runningWebpackDevServer } = require('../env')
3
+ const baseConfig = require("./base")
4
+ const webpackDevServerConfig = require("../webpackDevServerConfig")
5
+ const { runningWebpackDevServer } = require("../env")
6
6
 
7
7
  const devConfig = {
8
- mode: 'development',
9
- devtool: 'cheap-module-source-map',
8
+ mode: "development",
9
+ devtool: "cheap-module-source-map",
10
10
  ...(runningWebpackDevServer && { devServer: webpackDevServerConfig() })
11
11
  }
12
12
 
@@ -1,29 +1,29 @@
1
1
  /* eslint global-require: 0 */
2
2
  /* eslint import/no-dynamic-require: 0 */
3
3
 
4
- const { merge } = require('webpack-merge')
5
- const CompressionPlugin = require('compression-webpack-plugin')
6
- const TerserPlugin = require('terser-webpack-plugin')
7
- const baseConfig = require('./base')
8
- const { moduleExists } = require('../utils/helpers')
9
- const config = require('../config')
4
+ const { merge } = require("webpack-merge")
5
+ const CompressionPlugin = require("compression-webpack-plugin")
6
+ const TerserPlugin = require("terser-webpack-plugin")
7
+ const baseConfig = require("./base")
8
+ const { moduleExists } = require("../utils/helpers")
9
+ const config = require("../config")
10
10
 
11
11
  const getPlugins = () => {
12
12
  const plugins = []
13
13
 
14
14
  plugins.push(
15
15
  new CompressionPlugin({
16
- filename: '[path][base].gz[query]',
17
- algorithm: 'gzip',
16
+ filename: "[path][base].gz[query]",
17
+ algorithm: "gzip",
18
18
  test: /\.(js|css|html|json|ico|svg|eot|otf|ttf|map)$/
19
19
  })
20
20
  )
21
21
 
22
- if ('brotli' in process.versions) {
22
+ if ("brotli" in process.versions) {
23
23
  plugins.push(
24
24
  new CompressionPlugin({
25
- filename: '[path][base].br[query]',
26
- algorithm: 'brotliCompress',
25
+ filename: "[path][base].br[query]",
26
+ algorithm: "brotliCompress",
27
27
  test: /\.(js|css|html|json|ico|svg|eot|otf|ttf|map)$/
28
28
  })
29
29
  )
@@ -34,10 +34,10 @@ const getPlugins = () => {
34
34
 
35
35
  const tryCssMinimizer = () => {
36
36
  if (
37
- moduleExists('css-loader') &&
38
- moduleExists('css-minimizer-webpack-plugin')
37
+ moduleExists("css-loader") &&
38
+ moduleExists("css-minimizer-webpack-plugin")
39
39
  ) {
40
- const CssMinimizerPlugin = require('css-minimizer-webpack-plugin')
40
+ const CssMinimizerPlugin = require("css-minimizer-webpack-plugin")
41
41
  return new CssMinimizerPlugin()
42
42
  }
43
43
 
@@ -45,8 +45,8 @@ const tryCssMinimizer = () => {
45
45
  }
46
46
 
47
47
  const productionConfig = {
48
- devtool: 'source-map',
49
- stats: 'normal',
48
+ devtool: "source-map",
49
+ stats: "normal",
50
50
  bail: true,
51
51
  plugins: getPlugins(),
52
52
  optimization: {
@@ -1,3 +1,3 @@
1
- const baseConfig = require('./base')
1
+ const baseConfig = require("./base")
2
2
 
3
3
  module.exports = baseConfig