shakapacker 6.5.5 → 6.5.6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/ISSUE_TEMPLATE/bug_report.md +11 -7
- data/.github/ISSUE_TEMPLATE/feature_request.md +21 -0
- data/.github/workflows/ruby.yml +3 -1
- data/.gitignore +3 -3
- data/.rspec +1 -0
- data/CHANGELOG.md +18 -2
- data/CONTRIBUTING.md +11 -1
- data/Gemfile.development_dependencies +3 -1
- data/README.md +41 -8
- data/Rakefile +4 -5
- data/gemfiles/Gemfile-rails-edge +1 -1
- data/gemfiles/Gemfile-rails.5.2.x +1 -1
- data/gemfiles/Gemfile-rails.6.0.x +1 -1
- data/gemfiles/Gemfile-rails.6.1.x +1 -1
- data/gemfiles/Gemfile-rails.7.0.x +1 -1
- data/lib/install/template.rb +21 -16
- data/lib/tasks/webpacker/compile.rake +5 -10
- data/lib/webpacker/helper.rb +20 -9
- data/lib/webpacker/version.rb +1 -1
- data/package/rules/__tests__/__utils__/webpack.js +50 -0
- data/package/rules/__tests__/babel.js +63 -0
- data/package/rules/__tests__/esbuild.js +64 -0
- data/package/rules/__tests__/index.js +0 -4
- data/package/rules/__tests__/swc.js +64 -0
- data/package/rules/babel.js +3 -14
- data/package/rules/esbuild.js +2 -13
- data/package/rules/jscommon.js +26 -0
- data/package/rules/swc.js +2 -13
- data/package/utils/helpers.js +1 -1
- data/package.json +8 -2
- data/spec/command_spec.rb +114 -0
- data/spec/compiler_spec.rb +57 -0
- data/spec/compiler_strategy_spec.rb +20 -0
- data/spec/configuration_spec.rb +281 -0
- data/{test/dev_server_runner_test.rb → spec/dev_server_runner_spec.rb} +30 -40
- data/spec/dev_server_spec.rb +45 -0
- data/spec/digest_strategy_spec.rb +33 -0
- data/{test/engine_rake_tasks_test.rb → spec/engine_rake_tasks_spec.rb} +17 -9
- data/spec/env_spec.rb +21 -0
- data/{test → spec}/fixtures/beta_package-lock.v1.json +0 -0
- data/{test → spec}/fixtures/beta_package-lock.v2.json +0 -0
- data/{test → spec}/fixtures/beta_package.json +0 -0
- data/{test → spec}/fixtures/beta_yarn.v1.lock +0 -0
- data/{test → spec}/fixtures/beta_yarn.v2.lock +0 -0
- data/{test → spec}/fixtures/git_url_package-lock.v1.json +0 -0
- data/{test → spec}/fixtures/git_url_package-lock.v2.json +0 -0
- data/{test → spec}/fixtures/git_url_package.json +0 -0
- data/{test → spec}/fixtures/git_url_yarn.v1.lock +0 -0
- data/{test → spec}/fixtures/git_url_yarn.v2.lock +0 -0
- data/{test → spec}/fixtures/github_url_package-lock.v1.json +0 -0
- data/{test → spec}/fixtures/github_url_package-lock.v2.json +0 -0
- data/{test → spec}/fixtures/github_url_package.json +0 -0
- data/{test → spec}/fixtures/github_url_yarn.v1.lock +0 -0
- data/{test → spec}/fixtures/github_url_yarn.v2.lock +0 -0
- data/{test → spec}/fixtures/relative_path_package-lock.v1.json +0 -0
- data/{test → spec}/fixtures/relative_path_package-lock.v2.json +0 -0
- data/{test → spec}/fixtures/relative_path_package.json +0 -0
- data/{test → spec}/fixtures/relative_path_yarn.v1.lock +0 -0
- data/{test → spec}/fixtures/relative_path_yarn.v2.lock +0 -0
- data/{test → spec}/fixtures/semver_caret_package-lock.v1.json +0 -0
- data/{test → spec}/fixtures/semver_caret_package-lock.v2.json +0 -0
- data/{test → spec}/fixtures/semver_caret_package.json +0 -0
- data/{test → spec}/fixtures/semver_caret_yarn.v1.lock +0 -0
- data/{test → spec}/fixtures/semver_caret_yarn.v2.lock +0 -0
- data/{test → spec}/fixtures/semver_exact_package-lock.v1.json +0 -0
- data/{test → spec}/fixtures/semver_exact_package-lock.v2.json +0 -0
- data/{test → spec}/fixtures/semver_exact_package.json +0 -0
- data/{test → spec}/fixtures/semver_exact_yarn.v1.lock +0 -0
- data/{test → spec}/fixtures/semver_exact_yarn.v2.lock +0 -0
- data/{test → spec}/fixtures/semver_tilde_package-lock.v1.json +0 -0
- data/{test → spec}/fixtures/semver_tilde_package-lock.v2.json +0 -0
- data/{test → spec}/fixtures/semver_tilde_package.json +0 -0
- data/{test → spec}/fixtures/semver_tilde_yarn.v1.lock +0 -0
- data/{test → spec}/fixtures/semver_tilde_yarn.v2.lock +0 -0
- data/{test → spec}/fixtures/without_package-lock.v1.json +0 -0
- data/{test → spec}/fixtures/without_package-lock.v2.json +0 -0
- data/{test → spec}/fixtures/without_package.json +0 -0
- data/{test → spec}/fixtures/without_yarn.v1.lock +0 -0
- data/{test → spec}/fixtures/without_yarn.v2.lock +0 -0
- data/spec/helper_spec.rb +241 -0
- data/spec/manifest_spec.rb +98 -0
- data/{test → spec}/mounted_app/Rakefile +0 -0
- data/{test → spec}/mounted_app/test/dummy/Rakefile +0 -0
- data/{test → spec}/mounted_app/test/dummy/bin/rails +0 -0
- data/{test → spec}/mounted_app/test/dummy/bin/rake +0 -0
- data/{test → spec}/mounted_app/test/dummy/config/application.rb +0 -0
- data/{test → spec}/mounted_app/test/dummy/config/environment.rb +0 -0
- data/{test → spec}/mounted_app/test/dummy/config/webpacker.yml +0 -0
- data/{test → spec}/mounted_app/test/dummy/config.ru +0 -0
- data/{test → spec}/mounted_app/test/dummy/package.json +0 -0
- data/spec/mtime_strategy_spec.rb +53 -0
- data/spec/rake_tasks_spec.rb +32 -0
- data/spec/spec_helper.rb +123 -0
- data/{test → spec}/test_app/Rakefile +0 -0
- data/{test → spec}/test_app/app/packs/entrypoints/application.js +0 -0
- data/{test → spec}/test_app/app/packs/entrypoints/generated/something.js +0 -0
- data/{test → spec}/test_app/app/packs/entrypoints/multi_entry.css +0 -0
- data/{test → spec}/test_app/app/packs/entrypoints/multi_entry.js +0 -0
- data/{test → spec}/test_app/bin/webpacker +0 -0
- data/{test → spec}/test_app/bin/webpacker-dev-server +0 -0
- data/{test → spec}/test_app/config/application.rb +0 -0
- data/{test → spec}/test_app/config/environment.rb +0 -0
- data/{test → spec}/test_app/config/initializers/inspect_autoload_paths.rb +0 -0
- data/{test → spec}/test_app/config/webpack/webpack.config.js +0 -0
- data/{test → spec}/test_app/config/webpacker.yml +0 -0
- data/{test → spec}/test_app/config/webpacker_css_extract_ignore_order_warnings.yml +0 -0
- data/{test → spec}/test_app/config/webpacker_defaults_fallback.yml +0 -0
- data/{test → spec}/test_app/config/webpacker_manifest_path.yml +0 -0
- data/{test → spec}/test_app/config/webpacker_nested_entries.yml +0 -0
- data/{test → spec}/test_app/config/webpacker_no_precompile.yml +0 -0
- data/{test → spec}/test_app/config/webpacker_other_location.yml +0 -0
- data/{test → spec}/test_app/config/webpacker_public_root.yml +0 -0
- data/{test → spec}/test_app/config.ru +0 -0
- data/{test → spec}/test_app/package.json +0 -0
- data/{test → spec}/test_app/public/packs/manifest.json +8 -0
- data/{test → spec}/test_app/some.config.js +0 -0
- data/{test → spec}/test_app/yarn.lock +0 -0
- data/spec/version_checker_spec.rb +950 -0
- data/{test/webpack_runner_test.rb → spec/webpack_runner_spec.rb} +12 -15
- data/spec/webpacker_spec.rb +39 -0
- data/yarn.lock +846 -844
- metadata +102 -187
- data/.github/ISSUE_TEMPLATE/feature-request.md +0 -18
- data/lib/tasks/yarn.rake +0 -44
- data/test/command_test.rb +0 -109
- data/test/compiler_strategy_test.rb +0 -27
- data/test/compiler_test.rb +0 -60
- data/test/configuration_test.rb +0 -186
- data/test/dev_server_test.rb +0 -47
- data/test/digest_strategy_test.rb +0 -33
- data/test/env_test.rb +0 -23
- data/test/helper_test.rb +0 -248
- data/test/manifest_test.rb +0 -89
- data/test/mtime_strategy_test.rb +0 -42
- data/test/rake_tasks_test.rb +0 -37
- data/test/test_helper.rb +0 -33
- data/test/version_checker_test.rb +0 -826
- data/test/webpacker_test.rb +0 -49
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 17c0e222ab613e6f12721d7bdb999428753be2ad5543908699ee9c6a935e925b
|
4
|
+
data.tar.gz: b308833c1dece4246d9d427f794abb37bcfd7be30ff11c1471fa70ae3c549ccb
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 28136e6a11fd60abd2d5a83554e13d3405a24ea1c7bda76b3c7d689fef6dc4f98352d6a963f26b9cc888cc0c870e840bec662f5cbdfbc89f7e21938c366d4067
|
7
|
+
data.tar.gz: e5aa229a81dfc4435d4219891f4e8e28560797d365e0ee13584f53743b6cb7c5b8f473690fce75b58d3d47a301ad7862ff8fca1397eacedfb75c450acf8faaaa
|
@@ -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
|
-
|
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
|
-
|
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:
|
data/.github/workflows/ruby.yml
CHANGED
@@ -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
|
-
|
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
|
-
/
|
5
|
-
/
|
4
|
+
/spec/mounted_app/test/dummy/log
|
5
|
+
/spec/test_app/log
|
6
6
|
node_modules
|
7
7
|
.byebug_history
|
8
|
-
/
|
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,22 @@ 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
|
-
## [
|
11
|
+
## [6.5.6] - February 11, 2023
|
12
|
+
### Fixed
|
13
|
+
- Fixed failing to update `bin/setup` file due to different formats of the file in different versions of Rails. [PR229](https://github.com/shakacode/shakapacker/pull/229) by [ahangarha](https://github.com/ahangarha)
|
14
|
+
|
15
|
+
- Upgrade several JS dependencies to fix security issues. [PR 243](https://github.com/shakacode/shakapacker/pull/243) by [ahangarha](https://github.com/ahangarha).
|
16
|
+
|
17
|
+
- 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).
|
18
|
+
|
19
|
+
- 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).
|
20
|
+
|
21
|
+
## [6.5.6] - January 15, 2023
|
22
|
+
### Fixed
|
23
|
+
- Remove duplicate yarn installs. [PR 238](https://github.com/shakacode/shakapacker/pull/238) by [justin808](https://github/justin808).
|
24
|
+
- Remove unneeded code related to CSP config for generator. [PR 223](https://github.com/shakacode/shakapacker/pull/223) by [ahangarha](https://github/ahangarha).
|
25
|
+
|
26
|
+
## [v6.5.5] - December 28, 2022
|
12
27
|
|
13
28
|
### Improved
|
14
29
|
- 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 +208,8 @@ Note: [Rubygem is 6.3.0.pre.rc.1](https://rubygems.org/gems/shakapacker/versions
|
|
193
208
|
## v5.4.3 and prior changes from rails/webpacker
|
194
209
|
See [CHANGELOG.md in rails/webpacker (up to v5.4.3)](https://github.com/rails/webpacker/blob/master/CHANGELOG.md)
|
195
210
|
|
196
|
-
[Unreleased]: https://github.com/shakacode/shakapacker/compare/v6.5.
|
211
|
+
[Unreleased]: https://github.com/shakacode/shakapacker/compare/v6.5.6...master
|
212
|
+
[v6.5.6]: https://github.com/shakacode/shakapacker/compare/v6.5.5...v6.5.6
|
197
213
|
[v6.5.5]: https://github.com/shakacode/shakapacker/compare/v6.5.4...v6.5.5
|
198
214
|
[v6.5.4]: https://github.com/shakacode/shakapacker/compare/v6.5.3...v6.5.4
|
199
215
|
[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
|
-
|
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.
|
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
|
-
|
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
|
-
|
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
|
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:**
|
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
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
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/gemfiles/Gemfile-rails-edge
CHANGED
data/lib/install/template.rb
CHANGED
@@ -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
|
-
|
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!
|
53
|
+
system!("bin/yarn")
|
45
54
|
RUBY
|
46
|
-
end
|
47
55
|
|
48
|
-
if
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
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
|
-
|
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
|
data/lib/webpacker/helper.rb
CHANGED
@@ -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
|
-
|
184
|
-
|
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
|
-
|
189
|
-
|
190
|
-
|
191
|
-
|
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: [],
|
data/lib/webpacker/version.rb
CHANGED
@@ -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
|
+
});
|
@@ -0,0 +1,64 @@
|
|
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 esbuildConfig = require("../esbuild");
|
10
|
+
|
11
|
+
jest.mock("../../config", () => {
|
12
|
+
const original = jest.requireActual("../../config");
|
13
|
+
return {
|
14
|
+
...original,
|
15
|
+
webpack_loader: "esbuild",
|
16
|
+
additional_paths: [...original.additional_paths, "node_modules/included"],
|
17
|
+
};
|
18
|
+
});
|
19
|
+
|
20
|
+
const createWebpackConfig = (file, use) => {
|
21
|
+
return {
|
22
|
+
entry: { file },
|
23
|
+
module: {
|
24
|
+
rules: [
|
25
|
+
{
|
26
|
+
...esbuildConfig,
|
27
|
+
use,
|
28
|
+
},
|
29
|
+
],
|
30
|
+
},
|
31
|
+
output: {
|
32
|
+
path: "/",
|
33
|
+
filename: "scripts-bundled.js",
|
34
|
+
},
|
35
|
+
};
|
36
|
+
};
|
37
|
+
|
38
|
+
describe("swc", () => {
|
39
|
+
test("process source path", async () => {
|
40
|
+
const normalPath = `${app_javascript}/a.js`;
|
41
|
+
const [tracked, loader] = createTrackLoader();
|
42
|
+
const compiler = createTestCompiler(
|
43
|
+
createWebpackConfig(normalPath, loader)
|
44
|
+
);
|
45
|
+
await compiler.run();
|
46
|
+
expect(tracked[normalPath]).toBeTruthy();
|
47
|
+
});
|
48
|
+
|
49
|
+
test("exclude node_modules", async () => {
|
50
|
+
const ignored = `${node_modules}/a.js`;
|
51
|
+
const [tracked, loader] = createTrackLoader();
|
52
|
+
const compiler = createTestCompiler(createWebpackConfig(ignored, loader));
|
53
|
+
await compiler.run();
|
54
|
+
expect(tracked[ignored]).toBeUndefined();
|
55
|
+
});
|
56
|
+
|
57
|
+
test("explicitly included node_modules should be transpiled", async () => {
|
58
|
+
const included = `${node_modules_included}/a.js`;
|
59
|
+
const [tracked, loader] = createTrackLoader();
|
60
|
+
const compiler = createTestCompiler(createWebpackConfig(included, loader));
|
61
|
+
await compiler.run();
|
62
|
+
expect(tracked[included]).toBeTruthy();
|
63
|
+
});
|
64
|
+
});
|
@@ -4,8 +4,4 @@ describe('index', () => {
|
|
4
4
|
test('rule tests are regexes', () => {
|
5
5
|
rules.forEach(rule => expect(rule.test instanceof RegExp).toBe(true))
|
6
6
|
})
|
7
|
-
|
8
|
-
test('rule excludes are regexes', () => {
|
9
|
-
rules.forEach(rule => expect(rule.exclude instanceof RegExp).toBe(true))
|
10
|
-
})
|
11
7
|
})
|