shakapacker 6.5.5 → 6.6.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (144) 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 +18 -0
  7. data/.github/workflows/ruby.yml +3 -1
  8. data/.gitignore +3 -3
  9. data/.rspec +1 -0
  10. data/CHANGELOG.md +20 -2
  11. data/CONTRIBUTING.md +11 -1
  12. data/Gemfile.development_dependencies +3 -1
  13. data/README.md +41 -8
  14. data/Rakefile +4 -5
  15. data/docs/v6_upgrade.md +1 -1
  16. data/gemfiles/Gemfile-rails-edge +1 -1
  17. data/gemfiles/Gemfile-rails.5.2.x +1 -1
  18. data/gemfiles/Gemfile-rails.6.0.x +1 -1
  19. data/gemfiles/Gemfile-rails.6.1.x +1 -1
  20. data/gemfiles/Gemfile-rails.7.0.x +1 -1
  21. data/lib/install/template.rb +21 -16
  22. data/lib/tasks/webpacker/compile.rake +5 -10
  23. data/lib/webpacker/helper.rb +20 -9
  24. data/lib/webpacker/instance.rb +3 -1
  25. data/lib/webpacker/version.rb +1 -1
  26. data/package/rules/__tests__/__utils__/webpack.js +50 -0
  27. data/package/rules/__tests__/babel.js +63 -0
  28. data/package/rules/__tests__/esbuild.js +64 -0
  29. data/package/rules/__tests__/index.js +0 -4
  30. data/package/rules/__tests__/swc.js +64 -0
  31. data/package/rules/babel.js +13 -24
  32. data/package/rules/esbuild.js +2 -13
  33. data/package/rules/jscommon.js +26 -0
  34. data/package/rules/swc.js +2 -13
  35. data/package/utils/helpers.js +1 -1
  36. data/package.json +8 -2
  37. data/spec/command_spec.rb +114 -0
  38. data/spec/compiler_spec.rb +57 -0
  39. data/spec/compiler_strategy_spec.rb +20 -0
  40. data/spec/configuration_spec.rb +281 -0
  41. data/{test/dev_server_runner_test.rb → spec/dev_server_runner_spec.rb} +30 -40
  42. data/spec/dev_server_spec.rb +45 -0
  43. data/spec/digest_strategy_spec.rb +33 -0
  44. data/{test/engine_rake_tasks_test.rb → spec/engine_rake_tasks_spec.rb} +17 -9
  45. data/spec/env_spec.rb +21 -0
  46. data/spec/helper_spec.rb +241 -0
  47. data/spec/manifest_spec.rb +98 -0
  48. data/spec/mtime_strategy_spec.rb +53 -0
  49. data/spec/rake_tasks_spec.rb +32 -0
  50. data/spec/spec_helper.rb +123 -0
  51. data/{test → spec}/test_app/public/packs/manifest.json +8 -0
  52. data/spec/version_checker_spec.rb +950 -0
  53. data/{test/webpack_runner_test.rb → spec/webpack_runner_spec.rb} +12 -15
  54. data/spec/webpacker_spec.rb +61 -0
  55. data/yarn.lock +846 -844
  56. metadata +104 -187
  57. data/.github/ISSUE_TEMPLATE/feature-request.md +0 -18
  58. data/lib/tasks/yarn.rake +0 -44
  59. data/test/command_test.rb +0 -109
  60. data/test/compiler_strategy_test.rb +0 -27
  61. data/test/compiler_test.rb +0 -60
  62. data/test/configuration_test.rb +0 -186
  63. data/test/dev_server_test.rb +0 -47
  64. data/test/digest_strategy_test.rb +0 -33
  65. data/test/env_test.rb +0 -23
  66. data/test/helper_test.rb +0 -248
  67. data/test/manifest_test.rb +0 -89
  68. data/test/mtime_strategy_test.rb +0 -42
  69. data/test/rake_tasks_test.rb +0 -37
  70. data/test/test_helper.rb +0 -33
  71. data/test/version_checker_test.rb +0 -826
  72. data/test/webpacker_test.rb +0 -49
  73. /data/{test → spec}/fixtures/beta_package-lock.v1.json +0 -0
  74. /data/{test → spec}/fixtures/beta_package-lock.v2.json +0 -0
  75. /data/{test → spec}/fixtures/beta_package.json +0 -0
  76. /data/{test → spec}/fixtures/beta_yarn.v1.lock +0 -0
  77. /data/{test → spec}/fixtures/beta_yarn.v2.lock +0 -0
  78. /data/{test → spec}/fixtures/git_url_package-lock.v1.json +0 -0
  79. /data/{test → spec}/fixtures/git_url_package-lock.v2.json +0 -0
  80. /data/{test → spec}/fixtures/git_url_package.json +0 -0
  81. /data/{test → spec}/fixtures/git_url_yarn.v1.lock +0 -0
  82. /data/{test → spec}/fixtures/git_url_yarn.v2.lock +0 -0
  83. /data/{test → spec}/fixtures/github_url_package-lock.v1.json +0 -0
  84. /data/{test → spec}/fixtures/github_url_package-lock.v2.json +0 -0
  85. /data/{test → spec}/fixtures/github_url_package.json +0 -0
  86. /data/{test → spec}/fixtures/github_url_yarn.v1.lock +0 -0
  87. /data/{test → spec}/fixtures/github_url_yarn.v2.lock +0 -0
  88. /data/{test → spec}/fixtures/relative_path_package-lock.v1.json +0 -0
  89. /data/{test → spec}/fixtures/relative_path_package-lock.v2.json +0 -0
  90. /data/{test → spec}/fixtures/relative_path_package.json +0 -0
  91. /data/{test → spec}/fixtures/relative_path_yarn.v1.lock +0 -0
  92. /data/{test → spec}/fixtures/relative_path_yarn.v2.lock +0 -0
  93. /data/{test → spec}/fixtures/semver_caret_package-lock.v1.json +0 -0
  94. /data/{test → spec}/fixtures/semver_caret_package-lock.v2.json +0 -0
  95. /data/{test → spec}/fixtures/semver_caret_package.json +0 -0
  96. /data/{test → spec}/fixtures/semver_caret_yarn.v1.lock +0 -0
  97. /data/{test → spec}/fixtures/semver_caret_yarn.v2.lock +0 -0
  98. /data/{test → spec}/fixtures/semver_exact_package-lock.v1.json +0 -0
  99. /data/{test → spec}/fixtures/semver_exact_package-lock.v2.json +0 -0
  100. /data/{test → spec}/fixtures/semver_exact_package.json +0 -0
  101. /data/{test → spec}/fixtures/semver_exact_yarn.v1.lock +0 -0
  102. /data/{test → spec}/fixtures/semver_exact_yarn.v2.lock +0 -0
  103. /data/{test → spec}/fixtures/semver_tilde_package-lock.v1.json +0 -0
  104. /data/{test → spec}/fixtures/semver_tilde_package-lock.v2.json +0 -0
  105. /data/{test → spec}/fixtures/semver_tilde_package.json +0 -0
  106. /data/{test → spec}/fixtures/semver_tilde_yarn.v1.lock +0 -0
  107. /data/{test → spec}/fixtures/semver_tilde_yarn.v2.lock +0 -0
  108. /data/{test → spec}/fixtures/without_package-lock.v1.json +0 -0
  109. /data/{test → spec}/fixtures/without_package-lock.v2.json +0 -0
  110. /data/{test → spec}/fixtures/without_package.json +0 -0
  111. /data/{test → spec}/fixtures/without_yarn.v1.lock +0 -0
  112. /data/{test → spec}/fixtures/without_yarn.v2.lock +0 -0
  113. /data/{test → spec}/mounted_app/Rakefile +0 -0
  114. /data/{test → spec}/mounted_app/test/dummy/Rakefile +0 -0
  115. /data/{test → spec}/mounted_app/test/dummy/bin/rails +0 -0
  116. /data/{test → spec}/mounted_app/test/dummy/bin/rake +0 -0
  117. /data/{test → spec}/mounted_app/test/dummy/config/application.rb +0 -0
  118. /data/{test → spec}/mounted_app/test/dummy/config/environment.rb +0 -0
  119. /data/{test → spec}/mounted_app/test/dummy/config/webpacker.yml +0 -0
  120. /data/{test → spec}/mounted_app/test/dummy/config.ru +0 -0
  121. /data/{test → spec}/mounted_app/test/dummy/package.json +0 -0
  122. /data/{test → spec}/test_app/Rakefile +0 -0
  123. /data/{test → spec}/test_app/app/packs/entrypoints/application.js +0 -0
  124. /data/{test → spec}/test_app/app/packs/entrypoints/generated/something.js +0 -0
  125. /data/{test → spec}/test_app/app/packs/entrypoints/multi_entry.css +0 -0
  126. /data/{test → spec}/test_app/app/packs/entrypoints/multi_entry.js +0 -0
  127. /data/{test → spec}/test_app/bin/webpacker +0 -0
  128. /data/{test → spec}/test_app/bin/webpacker-dev-server +0 -0
  129. /data/{test → spec}/test_app/config/application.rb +0 -0
  130. /data/{test → spec}/test_app/config/environment.rb +0 -0
  131. /data/{test → spec}/test_app/config/initializers/inspect_autoload_paths.rb +0 -0
  132. /data/{test → spec}/test_app/config/webpack/webpack.config.js +0 -0
  133. /data/{test → spec}/test_app/config/webpacker.yml +0 -0
  134. /data/{test → spec}/test_app/config/webpacker_css_extract_ignore_order_warnings.yml +0 -0
  135. /data/{test → spec}/test_app/config/webpacker_defaults_fallback.yml +0 -0
  136. /data/{test → spec}/test_app/config/webpacker_manifest_path.yml +0 -0
  137. /data/{test → spec}/test_app/config/webpacker_nested_entries.yml +0 -0
  138. /data/{test → spec}/test_app/config/webpacker_no_precompile.yml +0 -0
  139. /data/{test → spec}/test_app/config/webpacker_other_location.yml +0 -0
  140. /data/{test → spec}/test_app/config/webpacker_public_root.yml +0 -0
  141. /data/{test → spec}/test_app/config.ru +0 -0
  142. /data/{test → spec}/test_app/package.json +0 -0
  143. /data/{test → spec}/test_app/some.config.js +0 -0
  144. /data/{test → spec}/test_app/yarn.lock +0 -0
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 646fe9e24edc5f5db2658497319212b5185062398497652d0e30f0438bb26a58
4
- data.tar.gz: e8664c72e8122fb658e33ba7018edbd5f6aad9ceb3ddda8fca0fa6f019f9ae6b
3
+ metadata.gz: 667631baa338ba0105550f29536e148bed8b21475daf816b148ab22be98209f9
4
+ data.tar.gz: 1f49260d3dd206242d022a07200c8d5dbf370fbc72e1dedf10ab033add63dc52
5
5
  SHA512:
6
- metadata.gz: e41b38e5d64053e31e0077a31bca784b719601cee52da5237a0a310519d54121750b723cb7a35a4b826d2ecc781dabfa00652fd2fb6fe29e321373f0b0537cf4
7
- data.tar.gz: eb96874304522ce04a1d1ba88162333336857606075f1cb00360f4016dfe09827eb421113b5d0c09b08f876d07b0815d4841bb8254895fe75297fe211bcbccc4
6
+ metadata.gz: c830769b5fc9a2c40c0e686848421ee39b6df1ae4866f6ad0f00a60b34e1d3262c2fa7b39012e92cbc5d1a985f200c38a636597a8a4adf339c5961960d457fe2
7
+ data.tar.gz: 818526e1d7b2f5a355a4ffe86c3b09e30ae1ca957fd077e685475aab512fe1107ce3f548e1100811a226c8cce6ed3a5f5a2e1511a9f822112eee9b091e9704c1
data/.eslintrc.js CHANGED
@@ -5,6 +5,7 @@ module.exports = {
5
5
  'import/no-unresolved': 'off',
6
6
  'import/no-extraneous-dependencies': 'off',
7
7
  'import/extensions': 'off',
8
+ "indent": ["error", 2],
8
9
  semi: ['error', 'never']
9
10
  },
10
11
  env: {
@@ -0,0 +1 @@
1
+ github: [shakacode]
@@ -7,14 +7,18 @@ assignees: ''
7
7
 
8
8
  ---
9
9
 
10
- A bug is a crash or incorrect behavior. If you have a debugging or troubleshooting question, please open a discussion on [Discussions Tab](https://github.com/shakacode/shakapacker/discussions).
10
+ _Notice: A bug is a crash or incorrect behavior. If you have a debugging or troubleshooting question, please open a discussion on the [Discussions Tab](https://github.com/shakacode/shakapacker/discussions). Otherwise, remove this line and fill out the following sections._
11
11
 
12
- Ruby version:
13
- Rails version:
14
- Shakapacker version:
12
+ ## Expected behavior:
15
13
 
16
- Expected behavior:
17
14
 
18
- Actual behavior:
15
+ ## Actual behavior:
19
16
 
20
- Small, reproducible repo:
17
+
18
+ ## Small, reproducible repo:
19
+
20
+
21
+ ## Setup environment:
22
+ - Ruby version:
23
+ - Rails version:
24
+ - Shakapacker version:
@@ -0,0 +1,21 @@
1
+ ---
2
+ name: Feature request
3
+ about: Create a request for new functionality
4
+ title: ''
5
+ labels: enhancement
6
+ assignees: ''
7
+
8
+ ---
9
+
10
+ _Notice: A feature request describes a suggested improvement. If you have a debugging or troubleshooting question, please open a discussion on the [Discussions Tab](https://github.com/shakacode/shakapacker/discussions). Otherwise, remove this line and fill out the following sections._
11
+
12
+ ## Desired behavior:
13
+
14
+
15
+ ## Actual behavior:
16
+
17
+
18
+ ## Setup environment:
19
+ - Ruby version:
20
+ - Rails version:
21
+ - Shakapacker version:
@@ -0,0 +1,18 @@
1
+ ### Summary
2
+
3
+ _Remove this paragraph and provide a general description of the code changes in your pull
4
+ request... were there any bugs you had fixed? If so, mention them. If
5
+ these bugs have open GitHub issues, be sure to tag them here as well,
6
+ to keep the conversation linked together._
7
+
8
+ ### Pull Request checklist
9
+ _Remove this line after checking all the items here. If the item is not applicable to the PR, both check it out and wrap it by `~`._
10
+
11
+ - [ ] Add/update test to cover these changes
12
+ - [ ] Update documentation
13
+ - [ ] Update CHANGELOG file
14
+ _Add the CHANGELOG entry at the top of the file._
15
+
16
+ ### Other Information
17
+
18
+ _Remove this parapraph and mention any other important and relevant information such as benchmarks._
@@ -15,7 +15,9 @@ jobs:
15
15
  - gemfiles/Gemfile-rails.6.0.x
16
16
  - gemfiles/Gemfile-rails.6.1.x
17
17
  - gemfiles/Gemfile-rails.7.0.x
18
- - gemfiles/Gemfile-rails-edge
18
+ # Uncomment the following line only to ensure compatibility with the
19
+ # upcomming Rails versions, maybe before a release.
20
+ #- gemfiles/Gemfile-rails-edge
19
21
  exclude:
20
22
  - ruby: 2.6
21
23
  os: ubuntu-latest
data/.gitignore CHANGED
@@ -1,11 +1,11 @@
1
1
  /.bundle
2
2
  Gemfile.lock
3
3
  /pkg
4
- /test/mounted_app/test/dummy/log
5
- /test/test_app/log
4
+ /spec/mounted_app/test/dummy/log
5
+ /spec/test_app/log
6
6
  node_modules
7
7
  .byebug_history
8
- /test/test_app/tmp
8
+ /spec/test_app/tmp
9
9
  yarn-debug.log*
10
10
  yarn-error.log*
11
11
  .yarn-integrity
data/.rspec ADDED
@@ -0,0 +1 @@
1
+ --require spec_helper
data/CHANGELOG.md CHANGED
@@ -8,7 +8,23 @@ Changes since last non-beta release.
8
8
 
9
9
  _Please add entries here for your pull requests that are not yet released._
10
10
 
11
- ## [v6.5.5] - December 23, 2022
11
+ ## [v6.6.0] - March 7, 2023
12
+ ### Improved
13
+ - Allow configuration of webpacker.yml through env variable. [PR 254](https://github.com/shakacode/shakapacker/pull/254) by [alecslupu](https://github.com/alecslupu)
14
+
15
+ ## [v6.5.6] - February 11, 2023
16
+ ### Fixed
17
+ - Fixed failing to update `bin/setup` file due to different formats of the file in different versions of Rails. [PR 229](https://github.com/shakacode/shakapacker/pull/229) by [ahangarha](https://github.com/ahangarha)
18
+
19
+ - Upgrade several JS dependencies to fix security issues. [PR 243](https://github.com/shakacode/shakapacker/pull/243) by [ahangarha](https://github.com/ahangarha).
20
+
21
+ - Added `prepend_javascript_pack_tag` to helpers. Allows to move an entry to the top of queue. Handy when calling from the layout to make sure an entry goes before the view and partial `append_javascript_pack_tag` entries. [PR 235](https://github.com/shakacode/shakapacker/pull/235) by [paypro-leon](https://github.com/paypro-leon).
22
+
23
+ - Fixed [issue](https://github.com/shakacode/shakapacker/issues/208) to support directories under `node_modules/*` in the `additional_paths` property of `webpacker.yml` [PR 238](https://github.com/shakacode/shakapacker/pull/238) by [vaukalak](https://github.com/vaukalak).
24
+ - Remove duplicate yarn installs. [PR 238](https://github.com/shakacode/shakapacker/pull/238) by [justin808](https://github/justin808).
25
+ - Remove unneeded code related to CSP config for generator. [PR 223](https://github.com/shakacode/shakapacker/pull/223) by [ahangarha](https://github/ahangarha).
26
+
27
+ ## [v6.5.5] - December 28, 2022
12
28
 
13
29
  ### Improved
14
30
  - Describe keys different from `webpack-dev-server` in generated `webpacker.yml`. [PR 194](https://github.com/shakacode/shakapacker/pull/194) by [alexeyr](https://github.com/alexeyr).
@@ -193,7 +209,9 @@ Note: [Rubygem is 6.3.0.pre.rc.1](https://rubygems.org/gems/shakapacker/versions
193
209
  ## v5.4.3 and prior changes from rails/webpacker
194
210
  See [CHANGELOG.md in rails/webpacker (up to v5.4.3)](https://github.com/rails/webpacker/blob/master/CHANGELOG.md)
195
211
 
196
- [Unreleased]: https://github.com/shakacode/shakapacker/compare/v6.5.5...master
212
+ [Unreleased]: https://github.com/shakacode/shakapacker/compare/v6.6.0...master
213
+ [v6.6.0]: https://github.com/shakacode/shakapacker/compare/v6.5.6...v6.6.0
214
+ [v6.5.6]: https://github.com/shakacode/shakapacker/compare/v6.5.5...v6.5.6
197
215
  [v6.5.5]: https://github.com/shakacode/shakapacker/compare/v6.5.4...v6.5.5
198
216
  [v6.5.4]: https://github.com/shakacode/shakapacker/compare/v6.5.3...v6.5.4
199
217
  [v6.5.3]: https://github.com/shakacode/shakapacker/compare/v6.5.2...v6.5.3
data/CONTRIBUTING.md CHANGED
@@ -1,3 +1,10 @@
1
+ ## Contents
2
+ - [Setting Up a Development Environment](#setting-up-a-development-environment)
3
+ - [Making sure your changes pass all tests](#making-sure-your-changes-pass-all-tests)
4
+ - [Testing the generator](#testing-the-generator)
5
+ - [Find existing issues](#find-existing-issues)
6
+
7
+ ---
1
8
  ## Setting Up a Development Environment
2
9
 
3
10
  1. Install [Yarn](https://yarnpkg.com/)
@@ -51,7 +58,7 @@ bundle exec rake test TEST=test/rake_tasks_test.rb
51
58
  bundle exec ruby -I test test/rake_tasks_test.rb -n test_rake_webpacker_install
52
59
  ```
53
60
 
54
- # Testing the generator
61
+ ## Testing the generator
55
62
  If you change the generator, check that install instructions work.
56
63
 
57
64
  1. Update the gemfile so that gem "webpacker" has a line like this, pointing to your install of webpacker
@@ -60,3 +67,6 @@ If you change the generator, check that install instructions work.
60
67
  ```
61
68
  2. `bundle`
62
69
  3. Run the generator confirm that you got the right changes.
70
+
71
+ ## Find existing issues
72
+ You may look at the issues list to find existing known issues to be addressed. In this, we recommend to look at closed issues, particularly with "[help wanted](https://github.com/shakacode/shakapacker/issues?q=is%3Aissue+label%3A%22help+wanted%22+is%3Aclosed+)" label.
@@ -6,8 +6,10 @@ gem "rack-proxy", ">= 0.7.2"
6
6
  gem "nokogiri", ">= 1.13.6"
7
7
  gem "rails-html-sanitizer", ">= 1.4.3"
8
8
 
9
+ group :test, :development do
10
+ gem "rspec-rails", "~> 5.0.0"
11
+ end
9
12
 
10
13
  group :test do
11
- gem "minitest", "~> 5.0"
12
14
  gem "byebug"
13
15
  end
data/README.md CHANGED
@@ -21,12 +21,21 @@ Check out 6.1.1+ for [SWC](https://swc.rs/) and [esbuild-loader](https://github.
21
21
 
22
22
  See a comparison of [Shakapacker with jsbundling-rails](https://github.com/rails/jsbundling-rails/blob/main/docs/comparison_with_webpacker.md).
23
23
 
24
- Discussion forum and Slack to discuss debugging and troubleshooting tips. Please open issues for bugs and feature requests:
25
- 1. [Discussions tab](https://github.com/shakacode/shakapacker/discussions)
26
- 2. [Slack discussion channel](https://reactrails.slack.com/join/shared_invite/enQtNjY3NTczMjczNzYxLTlmYjdiZmY3MTVlMzU2YWE0OWM0MzNiZDI0MzdkZGFiZTFkYTFkOGVjODBmOWEyYWQ3MzA2NGE1YWJjNmVlMGE)
27
- 3. [Tweets with tag `#shakapacker`](https://twitter.com/hashtag/shakapacker?src=hashtag_click)
24
+ For discussions, see our [Slack Channel](https://reactrails.slack.com/join/shared_invite/enQtNjY3NTczMjczNzYxLTlmYjdiZmY3MTVlMzU2YWE0OWM0MzNiZDI0MzdkZGFiZTFkYTFkOGVjODBmOWEyYWQ3MzA2NGE1YWJjNmVlMGE).
28
25
 
29
- [ShakaCode](https://www.shakacode.com) offers support for upgrading from webpacker and using Shakapacker. If interested, contact Justin Gordon, [justin@shakacode.com](mailto:justin@shakacode.com). ShakaCode is [hiring passionate engineers](https://jobs.lever.co/shakacode/3bdbfdb3-4495-4611-a279-01dddb351abe) that love open source.
26
+ ---
27
+ ### ShakaCode Support
28
+
29
+ [ShakaCode](https://www.shakacode.com) offers support for upgrading from webpacker and using Shakapacker. If interested, contact Justin Gordon, [justin@shakacode.com](mailto:justin@shakacode.com). We're also [hiring](https://jobs.lever.co/shakacode/3bdbfdb3-4495-4611-a279-01dddb351abe)!
30
+
31
+ Here's a testimonial of how ShakaCode can help, from [Florian Gößler](https://github.com/FGoessler) of [Blinkist](https://www.blinkist.com/), January 2, 2023:
32
+ > Hey Justin 👋
33
+ >
34
+ > I just wanted to let you know that we today shipped the webpacker to shakapacker upgrades and it all seems to be running smoothly! Thanks again for all your support and your teams work! 😍
35
+ >
36
+ > On top of your work, it was now also very easy for me to upgrade Tailwind and include our external node_module based web component library which we were using for our other (more modern) apps already. That work is going to be shipped later this week though as we are polishing the last bits of it. 😉
37
+ >
38
+ > Have a great 2023 and maybe we get to work together again later in the year! 🙌
30
39
 
31
40
  ---
32
41
 
@@ -44,7 +53,7 @@ Discussion forum and Slack to discuss debugging and troubleshooting tips. Please
44
53
  - [Configuration and Code](#configuration-and-code)
45
54
  - [View Helpers](#view-helpers)
46
55
  - [View Helpers `javascript_pack_tag` and `stylesheet_pack_tag`](#view-helpers-javascript_pack_tag-and-stylesheet_pack_tag)
47
- - [View Helper `append_javascript_pack_tag` and `append_stylesheet_pack_tag`](#view-helper-append_javascript_pack_tag-and-append_stylesheet_pack_tag)
56
+ - [View Helpers `append_javascript_pack_tag`, `prepend_javascript_pack_tag` and `append_stylesheet_pack_tag`](#view-helper-append_javascript_pack_tag-prepend_javascript_pack_tag-and-append_stylesheet_pack_tag)
48
57
  - [View Helper: `asset_pack_path`](#view-helper-asset_pack_path)
49
58
  - [View Helper: `image_pack_tag`](#view-helper-image_pack_tag)
50
59
  - [View Helper: `favicon_pack_tag`](#view-helper-favicon_pack_tag)
@@ -258,7 +267,7 @@ While this also generally applies to `stylesheet_pack_tag`, you may use multiple
258
267
  <%= stylesheet_pack_tag 'print', media: 'print' %>
259
268
  ```
260
269
 
261
- #### View Helper `append_javascript_pack_tag` and `append_stylesheet_pack_tag`
270
+ #### View Helper `append_javascript_pack_tag`, `prepend_javascript_pack_tag` and `append_stylesheet_pack_tag`
262
271
 
263
272
  If you need configure your script pack names or stylesheet pack names from the view for a route or partials, then you will need some logic to ensure you call the helpers only once with multiple arguments. The new view helpers, `append_javascript_pack_tag` and `append_stylesheet_pack_tag` can solve this problem. The helper `append_javascript_pack_tag` will queue up script packs when the `javascript_pack_tag` is finally used. Similarly,`append_stylesheet_pack_tag` will queue up style packs when the `stylesheet_pack_tag` is finally used.
264
273
 
@@ -291,7 +300,7 @@ However, you typically can't do that in the main layout, as the view and partial
291
300
 
292
301
  Thus, you can distribute the logic of what packs are needed for any route. All the magic of splitting up the code and CSS was automatic!
293
302
 
294
- **Important:** Both `append_(javascript/stylesheet)_pack_tag` helpers can be used anywhere in your application as long as they are executed BEFORE `(javascript/stylesheet)_pack_tag` respectively. If you attempt to call one of the `append_(javascript/stylesheet)_pack_tag` helpers after the respective `(javascript/stylesheet)_pack_tag`, an error will be raised.
303
+ **Important:** These helpers can be used anywhere in your application as long as they are executed BEFORE `(javascript/stylesheet)_pack_tag` respectively. If you attempt to call one of these helpers after the respective `(javascript/stylesheet)_pack_tag`, an error will be raised.
295
304
 
296
305
  The typical issue is that your layout might reference some partials that need to configure packs. A good way to solve this problem is to use `content_for` to ensure that the code to render your partial comes before the call to `javascript_pack_tag`.
297
306
 
@@ -304,6 +313,30 @@ The typical issue is that your layout might reference some partials that need to
304
313
  <%= content_for :footer %>
305
314
  ```
306
315
 
316
+ There is also `prepend_javascript_pack_tag` that will put the entry at the front of the queue. This is handy when you want an entry in the main layout to go before the partial and main layout `append_javascript_pack_tag` entries.
317
+
318
+ Main view:
319
+ ```erb
320
+ <% append_javascript_pack_tag 'map' %>
321
+ ```
322
+
323
+ Some partial:
324
+ ```erb
325
+ <% append_javascript_pack_tag 'map' %>
326
+ ```
327
+
328
+ And the main layout has:
329
+ ```erb
330
+ <% prepend_javascript_pack_tag 'main' %>
331
+ <%= javascript_pack_tag 'application' %>
332
+ ```
333
+
334
+ is the same as using this in the main layout:
335
+
336
+ ```erb
337
+ <%= javascript_pack_tag 'main', 'calendar', 'map', application' %>
338
+ ```
339
+
307
340
  For alternative options of setting the additional packs, [see this discussion](https://github.com/shakacode/shakapacker/issues/39).
308
341
 
309
342
  #### View Helper: `asset_pack_path`
data/Rakefile CHANGED
@@ -1,11 +1,10 @@
1
1
  # frozen_string_literal: true
2
2
  require "bundler/gem_tasks"
3
- require "rake/testtask"
4
3
 
5
- Rake::TestTask.new do |t|
6
- t.libs << "test"
7
- t.test_files = FileList["test/**/*_test.rb"]
8
- t.verbose = true
4
+ begin
5
+ require "rspec/core/rake_task"
6
+ RSpec::Core::RakeTask.new(:test)
7
+ rescue LoadError
9
8
  end
10
9
 
11
10
  task default: :test
data/docs/v6_upgrade.md CHANGED
@@ -19,7 +19,7 @@ See an example migration here: [PR 27](https://github.com/shakacode/react_on_rai
19
19
  1. Remove setting the NODE_ENV in your `bin/webpacker` and `bin/webpacker-dev-server` bin stubs as these are not set in the webpack runner file.
20
20
 
21
21
  ### Update Steps to v6.0.0 from v6.0.0.rc.6
22
- _If you're on webpacker v5, follow below steps to get to v6.0.0.rc.6 first._
22
+ _If you're on webpacker v5, follow [how to upgrade to webpacker v6.0.0.rc.6 from v5](#how-to-upgrade-to-webpacker-v600rc6-from-v5) to get to v6.0.0.rc.6 first._
23
23
 
24
24
  1. Change the gem name from `webpacker` to `shakapacker` and the NPM package from `@rails/webpacker` to `shakapacker`.
25
25
  1. Install the peer dependencies. Run `yarn add @babel/core @babel/plugin-transform-runtime @babel/preset-env @babel/runtime babel-loader compression-webpack-plugin terser-webpack-plugin webpack webpack-assets-manifest webpack-cli webpack-merge webpack-sources webpack-dev-server`. You may have old versions of libraries. Run `yarn install` and check for warnings like `warning " > shakapacker@6.1.1" has incorrect peer dependency "compression-webpack-plugin@^9.0.0"` and `file-loader@1.1.11" has incorrect peer dependency "webpack@^2.0.0 || ^3.0.0 || ^4.0.0"`. In other words, warnings like these are **serious** and will cause considerable confusion if not respected.
@@ -8,5 +8,5 @@ gem "rails", github: "rails/rails", branch: "main"
8
8
  gem "arel", github: "rails/arel"
9
9
  gem "rake", ">= 11.1"
10
10
  gem "rack-proxy", require: false
11
- gem "minitest", "~> 5.0"
11
+ gem "rspec-rails", "~> 6.0.0"
12
12
  gem "byebug"
@@ -5,5 +5,5 @@ gemspec path: "../"
5
5
  gem "rails", "~> 5.2.0"
6
6
  gem "rake", ">= 11.1"
7
7
  gem "rack-proxy", require: false
8
- gem "minitest", "~> 5.0"
8
+ gem "rspec-rails", "~> 5.0.0"
9
9
  gem "byebug"
@@ -5,5 +5,5 @@ gemspec path: "../"
5
5
  gem "rails", "~> 6.0.0.rc2"
6
6
  gem "rake", ">= 11.1"
7
7
  gem "rack-proxy", require: false
8
- gem "minitest", "~> 5.0"
8
+ gem "rspec-rails", "~> 5.0.0"
9
9
  gem "byebug"
@@ -8,5 +8,5 @@ gem "rails", '~>6.1.0'
8
8
  gem "arel", github: "rails/arel"
9
9
  gem "rake", ">= 11.1"
10
10
  gem "rack-proxy", require: false
11
- gem "minitest", "~> 5.0"
11
+ gem "rspec-rails", "~> 6.0.0"
12
12
  gem "byebug"
@@ -8,5 +8,5 @@ gem "rails", '~>7.0.0'
8
8
  gem "arel", github: "rails/arel"
9
9
  gem "rake", ">= 11.1"
10
10
  gem "rack-proxy", require: false
11
- gem "minitest", "~> 5.0"
11
+ gem "rspec-rails", "~> 6.0.0"
12
12
  gem "byebug"
@@ -36,21 +36,33 @@ else
36
36
  say %( Add <%= javascript_pack_tag "application" %> within the <head> tag in your custom layout.)
37
37
  end
38
38
 
39
+ # Ensure there is `system!("bin/yarn")` command in `./bin/setup` file
39
40
  if (setup_path = Rails.root.join("bin/setup")).exist?
40
41
  say "Run bin/yarn during bin/setup"
41
- insert_into_file setup_path.to_s, <<-RUBY, after: %( system("bundle check") || system!("bundle install")\n)
42
+
43
+ if File.read(setup_path).match? Regexp.escape(" # system('bin/yarn')\n")
44
+ gsub_file(setup_path, "# system('bin/yarn')", "system!('bin/yarn')")
45
+ else
46
+ # Due to the inconsistency of quotation usage in Rails 7 compared to
47
+ # earlier versions, we check both single and double quotations here.
48
+ pattern = /system\(['"]bundle check['"]\) \|\| system!\(['"]bundle install['"]\)\n/
49
+
50
+ string_to_add = <<-RUBY
42
51
 
43
52
  # Install JavaScript dependencies
44
- system! "bin/yarn"
53
+ system!("bin/yarn")
45
54
  RUBY
46
- end
47
55
 
48
- if (csp_config_path = Rails.root.join("config/initializers/content_security_policy.rb")).exist?
49
- say "Make note of webpack-dev-server exemption needed to csp"
50
- insert_into_file csp_config_path, <<-RUBY, after: %(# Rails.application.config.content_security_policy do |policy|)
51
- # # If you are using webpack-dev-server then specify webpack-dev-server host
52
- # policy.connect_src :self, :https, "http://localhost:3035", "ws://localhost:3035" if Rails.env.development?
53
- RUBY
56
+ if File.read(setup_path).match? pattern
57
+ insert_into_file(setup_path, string_to_add, after: pattern)
58
+ else
59
+ say <<~MSG, :red
60
+ It seems your `bin/setup` file doesn't have the expected content.
61
+ Please review the file and manually add `system!("bin/yarn")` before any
62
+ other command that requires JavaScript dependencies being already installed.
63
+ MSG
64
+ end
65
+ end
54
66
  end
55
67
 
56
68
  results = []
@@ -78,13 +90,6 @@ Dir.chdir(Rails.root) do
78
90
  results << run("yarn add --dev webpack-dev-server")
79
91
  end
80
92
 
81
- if Rails::VERSION::MAJOR == 5 && Rails::VERSION::MINOR > 1
82
- say "You need to allow webpack-dev-server host as allowed origin for connect-src.", :yellow
83
- say "This can be done in Rails 5.2+ for development environment in the CSP initializer", :yellow
84
- say "config/initializers/content_security_policy.rb with a snippet like this:", :yellow
85
- say "policy.connect_src :self, :https, \"http://localhost:3035\", \"ws://localhost:3035\" if Rails.env.development?", :yellow
86
- end
87
-
88
93
  unless results.all?
89
94
  say "Webpacker installation failed 😭 See above for details.", :red
90
95
  exit 1
@@ -1,16 +1,7 @@
1
1
  $stdout.sync = true
2
2
 
3
- def yarn_install_available?
4
- rails_major = Rails::VERSION::MAJOR
5
- rails_minor = Rails::VERSION::MINOR
6
-
7
- rails_major > 5 || (rails_major == 5 && rails_minor >= 1)
8
- end
9
-
10
3
  def enhance_assets_precompile
11
- # yarn:install was added in Rails 5.1
12
- deps = yarn_install_available? ? [] : ["webpacker:yarn_install"]
13
- Rake::Task["assets:precompile"].enhance(deps) do |task|
4
+ Rake::Task["assets:precompile"].enhance do |task|
14
5
  prefix = task.name.split(/#|assets:precompile/).first
15
6
 
16
7
  Rake::Task["#{prefix}webpacker:compile"].invoke
@@ -35,8 +26,12 @@ end
35
26
 
36
27
  if Webpacker.config.webpacker_precompile?
37
28
  if Rake::Task.task_defined?("assets:precompile")
29
+ # Rails already adds `yarn install` after 5.2
30
+ # https://github.com/shakacode/shakapacker/issues/237
38
31
  enhance_assets_precompile
39
32
  else
33
+ # Only add `yarn install` if Rails was not doing it (precompile was not defined).
34
+ # TODO: Remove this in Shakapacker 7.0
40
35
  Rake::Task.define_task("assets:precompile" => ["webpacker:yarn_install", "webpacker:compile"])
41
36
  end
42
37
  end
@@ -169,7 +169,7 @@ module Webpacker::Helper
169
169
  def append_stylesheet_pack_tag(*names)
170
170
  if @stylesheet_pack_tag_loaded
171
171
  raise "You can only call append_stylesheet_pack_tag before stylesheet_pack_tag helper. " \
172
- "Please refer to https://github.com/shakacode/shakapacker/blob/master/README.md#view-helper-append_javascript_pack_tag-and-append_stylesheet_pack_tag for the usage guide"
172
+ "Please refer to https://github.com/shakacode/shakapacker/blob/master/README.md#view-helper-append_javascript_pack_tag-prepend_javascript_pack_tag-and-append_stylesheet_pack_tag for the usage guide"
173
173
  end
174
174
 
175
175
  @stylesheet_pack_tag_queue ||= []
@@ -180,20 +180,31 @@ module Webpacker::Helper
180
180
  end
181
181
 
182
182
  def append_javascript_pack_tag(*names, defer: true)
183
- if @javascript_pack_tag_loaded
184
- raise "You can only call append_javascript_pack_tag before javascript_pack_tag helper. " \
185
- "Please refer to https://github.com/shakacode/shakapacker/blob/master/README.md#view-helper-append_javascript_pack_tag-and-append_stylesheet_pack_tag for the usage guide"
183
+ update_javascript_pack_tag_queue(defer: defer) do |hash_key|
184
+ javascript_pack_tag_queue[hash_key] |= names
186
185
  end
186
+ end
187
187
 
188
- hash_key = defer ? :deferred : :non_deferred
189
- javascript_pack_tag_queue[hash_key] |= names
190
-
191
- # prevent rendering Array#to_s representation when used with <%= … %> syntax
192
- nil
188
+ def prepend_javascript_pack_tag(*names, defer: true)
189
+ update_javascript_pack_tag_queue(defer: defer) do |hash_key|
190
+ javascript_pack_tag_queue[hash_key].unshift(*names)
191
+ end
193
192
  end
194
193
 
195
194
  private
196
195
 
196
+ def update_javascript_pack_tag_queue(defer:)
197
+ if @javascript_pack_tag_loaded
198
+ raise "You can only call #{caller_locations(1..1).first.label} before javascript_pack_tag helper. " \
199
+ "Please refer to https://github.com/shakacode/shakapacker/blob/master/README.md#view-helper-append_javascript_pack_tag-prepend_javascript_pack_tag-and-append_stylesheet_pack_tag for the usage guide"
200
+ end
201
+
202
+ yield(defer ? :deferred : :non_deferred)
203
+
204
+ # prevent rendering Array#to_s representation when used with <%= … %> syntax
205
+ nil
206
+ end
207
+
197
208
  def javascript_pack_tag_queue
198
209
  @javascript_pack_tag_queue ||= {
199
210
  deferred: [],
@@ -1,10 +1,12 @@
1
+ require "pathname"
1
2
  class Webpacker::Instance
2
3
  cattr_accessor(:logger) { ActiveSupport::TaggedLogging.new(ActiveSupport::Logger.new(STDOUT)) }
3
4
 
4
5
  attr_reader :root_path, :config_path
5
6
 
6
7
  def initialize(root_path: Rails.root, config_path: Rails.root.join("config/webpacker.yml"))
7
- @root_path, @config_path = root_path, config_path
8
+ @root_path = root_path
9
+ @config_path = Pathname.new(ENV["WEBPACKER_CONFIG"] || config_path)
8
10
  end
9
11
 
10
12
  def env
@@ -1,4 +1,4 @@
1
1
  module Webpacker
2
2
  # Change the version in package.json too, please!
3
- VERSION = "6.5.5".freeze
3
+ VERSION = "6.6.0".freeze
4
4
  end
@@ -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/packs");
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
+ });