shakapacker 7.2.3 → 8.0.0.pre.rc.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.eslintignore +1 -1
- data/.eslintrc.js +29 -8
- data/.github/PULL_REQUEST_TEMPLATE.md +10 -3
- data/.github/workflows/dummy.yml +5 -1
- data/.github/workflows/generator.yml +13 -18
- data/.github/workflows/node.yml +56 -0
- data/.github/workflows/ruby.yml +28 -17
- data/.rubocop.yml +1 -0
- data/CHANGELOG.md +52 -1
- data/README.md +88 -50
- data/Rakefile +1 -7
- data/docs/customizing_babel_config.md +2 -2
- data/docs/deployment.md +13 -6
- data/docs/react.md +6 -12
- data/docs/troubleshooting.md +4 -4
- data/docs/using_esbuild_loader.md +1 -1
- data/docs/using_swc_loader.md +1 -1
- data/docs/v8_upgrade.md +148 -0
- data/gemfiles/Gemfile-rails.7.1.x +12 -0
- data/jest.config.js +4 -0
- data/lib/install/config/shakapacker.yml +2 -2
- data/lib/install/template.rb +36 -30
- data/lib/shakapacker/base_strategy.rb +2 -1
- data/lib/shakapacker/compiler.rb +5 -20
- data/lib/shakapacker/configuration.rb +2 -46
- data/lib/shakapacker/deprecation_helper.rb +0 -78
- data/lib/shakapacker/dev_server.rb +1 -16
- data/lib/shakapacker/dev_server_runner.rb +2 -21
- data/lib/shakapacker/env.rb +1 -1
- data/lib/shakapacker/instance.rb +1 -3
- data/lib/shakapacker/manifest.rb +1 -1
- data/lib/shakapacker/railtie.rb +7 -0
- data/lib/shakapacker/runner.rb +4 -18
- data/lib/shakapacker/utils/manager.rb +58 -0
- data/lib/shakapacker/utils/misc.rb +0 -12
- data/lib/shakapacker/version.rb +1 -1
- data/lib/shakapacker/version_checker.rb +9 -30
- data/lib/shakapacker/webpack_runner.rb +2 -21
- data/lib/shakapacker.rb +0 -2
- data/lib/tasks/shakapacker/check_binstubs.rake +12 -26
- data/lib/tasks/shakapacker/check_manager.rake +3 -8
- data/lib/tasks/shakapacker/info.rake +6 -15
- data/package/babel/preset.js +15 -15
- data/package/config.js +15 -17
- data/package/dev_server.js +4 -4
- data/package/env.js +19 -17
- data/package/environments/base.js +41 -24
- data/package/environments/development.js +6 -6
- data/package/environments/production.js +16 -16
- data/package/environments/test.js +1 -1
- data/package/esbuild/index.js +6 -6
- data/package/index.d.ts +0 -1
- data/package/index.js +17 -46
- data/package/rules/babel.js +6 -8
- data/package/rules/coffee.js +2 -2
- data/package/rules/css.js +1 -1
- data/package/rules/erb.js +4 -4
- data/package/rules/esbuild.js +5 -7
- data/package/rules/file.js +17 -7
- data/package/rules/index.js +11 -11
- data/package/rules/jscommon.js +5 -5
- data/package/rules/less.js +6 -6
- data/package/rules/raw.js +1 -1
- data/package/rules/sass.js +4 -4
- data/package/rules/stylus.js +6 -6
- data/package/rules/swc.js +5 -7
- data/package/swc/index.js +10 -10
- data/package/utils/configPath.js +3 -18
- data/package/utils/defaultConfigPath.js +1 -1
- data/package/utils/{get_style_rule.js → getStyleRule.js} +6 -6
- data/package/utils/helpers.js +2 -43
- data/package/utils/inliningCss.js +4 -3
- data/package/utils/snakeToCamelCase.js +5 -0
- data/package/webpackDevServerConfig.js +28 -25
- data/package.json +11 -17
- data/prettier.config.js +4 -0
- data/shakapacker.gemspec +1 -1
- data/spec/dummy/app/javascript/packs/application.js +1 -1
- data/spec/dummy/config/application.rb +3 -0
- data/spec/dummy/config/initializers/react_on_rails.rb +2 -2
- data/spec/dummy/config/shakapacker.yml +3 -4
- data/spec/dummy/config/webpack/commonWebpackConfig.js +0 -1
- data/spec/dummy/config/webpack/webpack.config.js +1 -1
- data/spec/dummy/package.json +2 -1
- data/spec/dummy/yarn.lock +2 -3
- data/spec/generator_specs/e2e_template/template.rb +15 -28
- data/spec/generator_specs/generator_spec.rb +6 -136
- data/spec/mounted_app/test/dummy/config/webpacker.yml +0 -1
- data/spec/shakapacker/compiler_spec.rb +1 -3
- data/spec/shakapacker/configuration_spec.rb +4 -56
- data/spec/shakapacker/dev_server_runner_spec.rb +19 -102
- data/spec/shakapacker/dev_server_spec.rb +1 -16
- data/spec/shakapacker/engine_rake_tasks_spec.rb +1 -16
- data/spec/shakapacker/instance_spec.rb +1 -3
- data/spec/shakapacker/rake_tasks_spec.rb +2 -14
- data/spec/shakapacker/shakapacker_spec.rb +0 -1
- data/spec/shakapacker/test_app/config/shakapacker_css_extract_ignore_order_warnings.yml +0 -1
- data/spec/shakapacker/test_app/config/shakapacker_manifest_path.yml +0 -1
- data/spec/shakapacker/test_app/config/shakapacker_nested_entries.yml +0 -1
- data/spec/shakapacker/test_app/config/shakapacker_other_location.yml +0 -1
- data/spec/shakapacker/test_app/package.json +2 -1
- data/spec/shakapacker/utils_manager_spec.rb +125 -0
- data/spec/shakapacker/version_checker_spec.rb +4 -4
- data/spec/shakapacker/webpack_runner_spec.rb +19 -28
- data/spec/support/package_json_helpers.rb +7 -4
- data/test/helpers.js +67 -0
- data/test/package/config.test.js +50 -0
- data/test/package/dev_server.test.js +44 -0
- data/test/package/development.test.js +43 -0
- data/test/package/env.test.js +57 -0
- data/test/package/environments/base.test.js +105 -0
- data/test/package/environments/development.test.js +50 -0
- data/test/package/environments/production.test.js +106 -0
- data/test/package/index.test.js +45 -0
- data/test/package/production.test.js +32 -0
- data/test/package/rules/babel.test.js +58 -0
- data/test/package/rules/esbuild.test.js +59 -0
- data/test/package/rules/file.test.js +81 -0
- data/test/package/rules/index.test.js +7 -0
- data/test/package/rules/raw.test.js +12 -0
- data/test/package/rules/swc.test.js +59 -0
- data/test/package/staging.test.js +31 -0
- data/test/package/test.test.js +28 -0
- data/yarn.lock +1278 -421
- metadata +52 -102
- data/.github/workflows/jest.yml +0 -34
- data/.github/workflows/js-lint.yml +0 -34
- data/.github/workflows/rubocop.yml +0 -29
- data/.github/workflows/ruby-backward-compatibility.yml +0 -52
- data/lib/install/package.json +0 -15
- data/lib/tasks/shakapacker/check_yarn.rake +0 -34
- data/lib/tasks/shakapacker/yarn_install.rake +0 -24
- data/lib/tasks/webpacker/binstubs.rake +0 -9
- data/lib/tasks/webpacker/check_binstubs.rake +0 -9
- data/lib/tasks/webpacker/check_node.rake +0 -9
- data/lib/tasks/webpacker/check_yarn.rake +0 -9
- data/lib/tasks/webpacker/clean.rake +0 -9
- data/lib/tasks/webpacker/clobber.rake +0 -11
- data/lib/tasks/webpacker/compile.rake +0 -9
- data/lib/tasks/webpacker/info.rake +0 -9
- data/lib/tasks/webpacker/install.rake +0 -9
- data/lib/tasks/webpacker/verify_config.rake +0 -9
- data/lib/tasks/webpacker/verify_install.rake +0 -9
- data/lib/tasks/webpacker/yarn_install.rake +0 -9
- data/lib/tasks/webpacker.rake +0 -20
- data/lib/webpacker/dev_server_runner.rb +0 -9
- data/lib/webpacker/webpack_runner.rb +0 -9
- data/lib/webpacker.rb +0 -4
- data/package/__tests__/config-bc.js +0 -27
- data/package/__tests__/config.js +0 -46
- data/package/__tests__/dev_server-bc.js +0 -46
- data/package/__tests__/dev_server.js +0 -46
- data/package/__tests__/development-bc.js +0 -66
- data/package/__tests__/development.js +0 -66
- data/package/__tests__/env-bc.js +0 -59
- data/package/__tests__/env.js +0 -59
- data/package/__tests__/index-bc.js +0 -22
- data/package/__tests__/index.js +0 -46
- data/package/__tests__/production-bc.js +0 -51
- data/package/__tests__/production.js +0 -51
- data/package/__tests__/staging-bc.js +0 -53
- data/package/__tests__/staging.js +0 -53
- data/package/__tests__/test-bc.js +0 -43
- data/package/__tests__/test.js +0 -43
- data/package/environments/__tests__/base-bc.js +0 -107
- data/package/environments/__tests__/base.js +0 -107
- data/package/environments/__tests__/development.js +0 -53
- data/package/environments/__tests__/production.js +0 -92
- data/package/rules/__tests__/__utils__/webpack.js +0 -50
- data/package/rules/__tests__/babel.js +0 -63
- data/package/rules/__tests__/esbuild.js +0 -64
- data/package/rules/__tests__/file.js +0 -62
- data/package/rules/__tests__/index.js +0 -7
- data/package/rules/__tests__/raw.js +0 -18
- data/package/rules/__tests__/swc.js +0 -63
- data/package/utils/snakeToCamelCase +0 -7
- data/spec/backward_compatibility_specs/command_spec.rb +0 -116
- data/spec/backward_compatibility_specs/compiler_spec.rb +0 -59
- data/spec/backward_compatibility_specs/compiler_strategy_spec.rb +0 -24
- data/spec/backward_compatibility_specs/configuration_spec.rb +0 -294
- data/spec/backward_compatibility_specs/dev_server_runner_spec.rb +0 -206
- data/spec/backward_compatibility_specs/dev_server_spec.rb +0 -47
- data/spec/backward_compatibility_specs/digest_strategy_spec.rb +0 -38
- data/spec/backward_compatibility_specs/engine_rake_tasks_spec.rb +0 -67
- data/spec/backward_compatibility_specs/env_spec.rb +0 -23
- data/spec/backward_compatibility_specs/helper_spec.rb +0 -243
- data/spec/backward_compatibility_specs/instance_spec.rb +0 -31
- data/spec/backward_compatibility_specs/manifest_spec.rb +0 -100
- data/spec/backward_compatibility_specs/mtime_strategy_spec.rb +0 -55
- data/spec/backward_compatibility_specs/rake_tasks_spec.rb +0 -41
- data/spec/backward_compatibility_specs/spec_helper_initializer.rb +0 -24
- data/spec/backward_compatibility_specs/webpack_runner_spec.rb +0 -86
- data/spec/backward_compatibility_specs/webpacker_spec.rb +0 -41
- data/spec/backward_compatibility_specs/webpacker_test_app/.gitignore +0 -2
- data/spec/backward_compatibility_specs/webpacker_test_app/Rakefile +0 -3
- data/spec/backward_compatibility_specs/webpacker_test_app/app/packs/entrypoints/application.js +0 -10
- data/spec/backward_compatibility_specs/webpacker_test_app/app/packs/entrypoints/generated/something.js +0 -2
- data/spec/backward_compatibility_specs/webpacker_test_app/app/packs/entrypoints/multi_entry.css +0 -4
- data/spec/backward_compatibility_specs/webpacker_test_app/app/packs/entrypoints/multi_entry.js +0 -4
- data/spec/backward_compatibility_specs/webpacker_test_app/bin/webpacker +0 -13
- data/spec/backward_compatibility_specs/webpacker_test_app/bin/webpacker-dev-server +0 -13
- data/spec/backward_compatibility_specs/webpacker_test_app/config/application.rb +0 -11
- data/spec/backward_compatibility_specs/webpacker_test_app/config/environment.rb +0 -4
- data/spec/backward_compatibility_specs/webpacker_test_app/config/initializers/inspect_autoload_paths.rb +0 -1
- data/spec/backward_compatibility_specs/webpacker_test_app/config/webpack/webpack.config.js +0 -0
- data/spec/backward_compatibility_specs/webpacker_test_app/config/webpacker.yml +0 -83
- data/spec/backward_compatibility_specs/webpacker_test_app/config/webpacker_css_extract_ignore_order_warnings.yml +0 -84
- data/spec/backward_compatibility_specs/webpacker_test_app/config/webpacker_defaults_fallback.yml +0 -11
- data/spec/backward_compatibility_specs/webpacker_test_app/config/webpacker_manifest_path.yml +0 -80
- data/spec/backward_compatibility_specs/webpacker_test_app/config/webpacker_nested_entries.yml +0 -83
- data/spec/backward_compatibility_specs/webpacker_test_app/config/webpacker_no_precompile.yml +0 -7
- data/spec/backward_compatibility_specs/webpacker_test_app/config/webpacker_other_location.yml +0 -85
- data/spec/backward_compatibility_specs/webpacker_test_app/config/webpacker_public_root.yml +0 -18
- data/spec/backward_compatibility_specs/webpacker_test_app/config.ru +0 -5
- data/spec/backward_compatibility_specs/webpacker_test_app/package.json +0 -13
- data/spec/backward_compatibility_specs/webpacker_test_app/public/packs/manifest.json +0 -58
- data/spec/backward_compatibility_specs/webpacker_test_app/some.config.js +0 -0
- data/spec/backward_compatibility_specs/webpacker_test_app/tmp/shakapacker/last-compilation-digest-production +0 -1
- data/spec/backward_compatibility_specs/webpacker_test_app/yarn.lock +0 -11
data/Rakefile
CHANGED
@@ -14,12 +14,6 @@ namespace :run_spec do
|
|
14
14
|
sh("bundle exec rspec spec/shakapacker/*_spec.rb")
|
15
15
|
end
|
16
16
|
|
17
|
-
desc "Run backward compatibility specs"
|
18
|
-
task :gem_bc do
|
19
|
-
puts "Running Shakapacker gem specs for backward compatibility"
|
20
|
-
sh("bundle exec rspec spec/backward_compatibility_specs/*_spec.rb")
|
21
|
-
end
|
22
|
-
|
23
17
|
desc "Run specs in the dummy app"
|
24
18
|
task :dummy do
|
25
19
|
puts "Running dummy app specs"
|
@@ -41,7 +35,7 @@ namespace :run_spec do
|
|
41
35
|
end
|
42
36
|
|
43
37
|
desc "Run all specs"
|
44
|
-
task all_specs: %i[gem
|
38
|
+
task all_specs: %i[gem dummy generator] do
|
45
39
|
puts "Completed all RSpec tests"
|
46
40
|
end
|
47
41
|
end
|
@@ -20,8 +20,8 @@ This example shows how you can create an object and apply _additional_ presets a
|
|
20
20
|
To use this example file,
|
21
21
|
|
22
22
|
```
|
23
|
-
|
24
|
-
|
23
|
+
npm install react react-dom @babel/preset-react
|
24
|
+
npm install --dev @pmmmwh/react-refresh-webpack-plugin react-refresh
|
25
25
|
```
|
26
26
|
|
27
27
|
```js
|
data/docs/deployment.md
CHANGED
@@ -24,7 +24,7 @@ We're essentially doing the following here:
|
|
24
24
|
* Adding the Heroku NodeJS and Ruby buildpacks for your app. This allows the `npm` or `yarn` executables to properly function when compiling your app - as well as Ruby.
|
25
25
|
* Pushing your code to Heroku and kicking off the deployment
|
26
26
|
|
27
|
-
Your production build process is responsible for
|
27
|
+
Your production build process is responsible for installing your JavaScript dependencies before `rake assets:precompile`. For example, if you are on Heroku, the `heroku/nodejs` buildpack must run **prior** to the `heroku/ruby` buildpack for precompilation to run successfully.
|
28
28
|
|
29
29
|
## Nginx
|
30
30
|
|
@@ -100,18 +100,25 @@ Make sure you have your public output path (default `public/packs`), the shakapa
|
|
100
100
|
append :linked_dirs, "log", "tmp/pids", "tmp/cache", "tmp/sockets", "tmp/shakapacker", "public/packs", ".bundle", "node_modules"
|
101
101
|
```
|
102
102
|
|
103
|
-
If you have `node_modules` added to `:linked_dirs` you'll need to
|
103
|
+
If you have `node_modules` added to `:linked_dirs` you'll need to install your JavaScript dependencies before `deploy:assets:precompile`; you can use `package_json` to do this generically:
|
104
104
|
|
105
105
|
```ruby
|
106
|
-
before "deploy:assets:precompile", "deploy:
|
106
|
+
before "deploy:assets:precompile", "deploy:js_install"
|
107
107
|
namespace :deploy do
|
108
|
-
desc "Run rake
|
109
|
-
task :
|
108
|
+
desc "Run rake js install"
|
109
|
+
task :js_install do
|
110
|
+
require "package_json"
|
111
|
+
|
112
|
+
# this will use the package manager specified via `packageManager`, or otherwise fallback to `npm`
|
113
|
+
native_js_install_command = PackageJson.read.manager.native_install_command(frozen: true).join(" ")
|
114
|
+
|
110
115
|
on roles(:web) do
|
111
116
|
within release_path do
|
112
|
-
execute("cd #{release_path} &&
|
117
|
+
execute("cd #{release_path} && #{native_js_install_command}")
|
113
118
|
end
|
114
119
|
end
|
115
120
|
end
|
116
121
|
end
|
117
122
|
```
|
123
|
+
|
124
|
+
You can also replace the use of `package_json` with the underlying native install command for your preferred package manager.
|
data/docs/react.md
CHANGED
@@ -2,12 +2,6 @@
|
|
2
2
|
|
3
3
|
These steps describe creating a Rails/React app, using Shakapacker as the bundler.
|
4
4
|
|
5
|
-
Before starting, ensure that you have Yarn installed, for example:
|
6
|
-
|
7
|
-
```shell
|
8
|
-
npm i -g yarn
|
9
|
-
```
|
10
|
-
|
11
5
|
## Easy Setup
|
12
6
|
If you'd like easy integration of React with Ruby on Rails, see [React on Rails](https://github.com/shakacode/react_on_rails).
|
13
7
|
|
@@ -24,8 +18,8 @@ Create a new Rails app as per the [installation instructions in the README](http
|
|
24
18
|
Add React, as well as the necessary libraries to enable CSS support in your application:
|
25
19
|
|
26
20
|
```shell
|
27
|
-
|
28
|
-
|
21
|
+
npm install react react-dom @babel/preset-react
|
22
|
+
npm install css-loader style-loader mini-css-extract-plugin css-minimizer-webpack-plugin
|
29
23
|
```
|
30
24
|
|
31
25
|
Update the Babel configuration in the `package.json` file:
|
@@ -52,7 +46,7 @@ In `config/shakapacker.yml` set `hmr` is set to `true`.
|
|
52
46
|
Install the [react-refresh](https://www.npmjs.com/package/react-refresh) package, as well as [@pmmmwh/react-refresh-webpack-plugin](https://www.npmjs.com/package/@pmmmwh/react-refresh-webpack-plugin):
|
53
47
|
|
54
48
|
```shell
|
55
|
-
|
49
|
+
npm install --dev react-refresh @pmmmwh/react-refresh-webpack-plugin
|
56
50
|
```
|
57
51
|
|
58
52
|
Alter `config/webpack/webpack.config.js` like so:
|
@@ -142,8 +136,8 @@ cd myapp
|
|
142
136
|
bundle add shakapacker --strict
|
143
137
|
./bin/bundle install
|
144
138
|
./bin/rails shakapacker:install
|
145
|
-
|
146
|
-
|
139
|
+
npm install react react-dom @babel/preset-react
|
140
|
+
npm install css-loader style-loader mini-css-extract-plugin css-minimizer-webpack-plugin
|
147
141
|
```
|
148
142
|
|
149
143
|
2. Generate a controller
|
@@ -192,7 +186,7 @@ hmr: true
|
|
192
186
|
8. Install the [react-refresh](https://www.npmjs.com/package/react-refresh) package, as well as [@pmmmwh/react-refresh-webpack-plugin](https://www.npmjs.com/package/@pmmmwh/react-refresh-webpack-plugin):
|
193
187
|
|
194
188
|
```shell
|
195
|
-
|
189
|
+
npm install --dev react-refresh @pmmmwh/react-refresh-webpack-plugin
|
196
190
|
```
|
197
191
|
|
198
192
|
9. Alter `config/webpack/webpack.config.js` like so:
|
data/docs/troubleshooting.md
CHANGED
@@ -18,9 +18,9 @@
|
|
18
18
|
4. You can also pass additional options to the command to run the webpack-dev-server and start the webpack-dev-server with the option `--debug-shakapacker`
|
19
19
|
|
20
20
|
## Incorrect peer dependencies
|
21
|
-
|
22
|
-
|
23
|
-
|
21
|
+
Shakapacker uses peer dependencies to make it easier to manage what versions are being used for your app, which is especially
|
22
|
+
useful for patching security vulnerabilities. However, not all package managers will actually enforce these versions - notably,
|
23
|
+
Yarn will omit a warning rather than erroring if you forget to update a peer dependency:
|
24
24
|
|
25
25
|
```
|
26
26
|
warning " > shakapacker@6.1.1" has incorrect peer dependency "compression-webpack-plugin@^9.0.0".
|
@@ -31,7 +31,7 @@ This omission resulted in an error in the browser:
|
|
31
31
|
Failed to load resource: net::ERR_CONTENT_DECODING_FAILED
|
32
32
|
```
|
33
33
|
|
34
|
-
The error was caused by an old version of the peer dependency webpack-compression-plugin
|
34
|
+
The error was caused by an old version of the peer dependency `webpack-compression-plugin`.
|
35
35
|
|
36
36
|
So, be sure to investigate warnings from `yarn install`!
|
37
37
|
|
@@ -24,7 +24,7 @@ To use esbuild as your transpiler today. You need to do two things:
|
|
24
24
|
1. Make sure you've installed `esbuild` and `esbuild-loader` packages.
|
25
25
|
|
26
26
|
```
|
27
|
-
|
27
|
+
npm install esbuild esbuild-loader
|
28
28
|
```
|
29
29
|
|
30
30
|
2. Add or change `shakapacker_loader` value in your default `shakapacker.yml` config to `esbuild`
|
data/docs/using_swc_loader.md
CHANGED
@@ -19,7 +19,7 @@ In order to use SWC as your compiler today. You need to do two things:
|
|
19
19
|
1. Make sure you've installed `@swc/core` and `swc-loader` packages.
|
20
20
|
|
21
21
|
```
|
22
|
-
|
22
|
+
npm install @swc/core swc-loader
|
23
23
|
```
|
24
24
|
|
25
25
|
2. Add or change `webpack_loader` value in your default `shakapacker.yml` config to `swc`
|
data/docs/v8_upgrade.md
ADDED
@@ -0,0 +1,148 @@
|
|
1
|
+
# Upgrading from Shakapacker v7 to v8
|
2
|
+
|
3
|
+
The majority of the breaking changes in v8 were about dropping deprecated
|
4
|
+
functions and features, along with switching to be agnostic about what package
|
5
|
+
manager is used to manage JavaScript dependencies.
|
6
|
+
|
7
|
+
Support for Ruby 2.6 and Node v12 has also been dropped since they're very old
|
8
|
+
at this point.
|
9
|
+
|
10
|
+
## The `packageManager` property in `package.json` is used to determine the package manager
|
11
|
+
|
12
|
+
The biggest functional change in v8, `shakapacker` is now able to work with any
|
13
|
+
of the major JavaScript package managers thanks to the
|
14
|
+
[`package_json`](https://github.com/shakacode/package_json) gem which uses the
|
15
|
+
[`packageManager`](https://nodejs.org/api/packages.html#packagemanager) property
|
16
|
+
in the `package.json`.
|
17
|
+
|
18
|
+
In alignment with the behaviour of Node and `corepack`, in the absence of the
|
19
|
+
`packageManager` property `npm` will be used as the package manager so as part
|
20
|
+
of upgrading you will want to ensure that is set to `yarn@<version>` if you want
|
21
|
+
to continue using Yarn.
|
22
|
+
|
23
|
+
An error will be raised in the presences of a lockfile other than
|
24
|
+
`package-lock.json` if this property is not set with the recommended value to
|
25
|
+
use, but it important the property is set to ensure all tooling uses the right
|
26
|
+
package manager.
|
27
|
+
|
28
|
+
The `check_yarn` rake task has also been renamed to `check_manager` to reflect
|
29
|
+
this change.
|
30
|
+
|
31
|
+
Check out the [installation section](../README.md#installation) of the readme
|
32
|
+
for more details.
|
33
|
+
|
34
|
+
## Usages of `webpacker` must now be `shakapacker`
|
35
|
+
|
36
|
+
The `webpacker` spelling was deprecated in v7 and has now been completely
|
37
|
+
removed in v8 - this includes constants, environment variables, and rake tasks.
|
38
|
+
|
39
|
+
If you are still using references to `webpacker`, see the
|
40
|
+
[v7 Upgrade Guide](../docs/v7_upgrade.md) for how to migrate.
|
41
|
+
|
42
|
+
## JavaScript dependencies are no longer installed automatically as part of `assets:precompile`
|
43
|
+
|
44
|
+
You will now need to ensure your dependencies are installed before compiling
|
45
|
+
assets.
|
46
|
+
|
47
|
+
Some platforms like Heroku will install dependencies automatically but if you're
|
48
|
+
using a tool like `capistrano` to deploy to servers you can enhance the
|
49
|
+
`assets:precompile` command like so:
|
50
|
+
|
51
|
+
```ruby
|
52
|
+
namespace :assets do
|
53
|
+
desc "Ensures that dependencies required to compile assets are installed"
|
54
|
+
task install_dependencies: :environment do
|
55
|
+
# npm v6+
|
56
|
+
raise if File.exist?("package.json") && !(system "npm ci")
|
57
|
+
|
58
|
+
# yarn v1.x (classic)
|
59
|
+
raise if File.exist?("package.json") && !(system "yarn install --immutable")
|
60
|
+
|
61
|
+
# yarn v2+ (berry)
|
62
|
+
raise if File.exist?("package.json") && !(system "yarn install --frozen-lockfile")
|
63
|
+
|
64
|
+
# bun v1+
|
65
|
+
raise if File.exist?("package.json") && !(system "bun install --frozen-lockfile")
|
66
|
+
|
67
|
+
# pnpm v6+
|
68
|
+
raise if File.exist?("package.json") && !(system "pnpm install --frozen-lockfile")
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
72
|
+
Rake::Task["assets:precompile"].enhance ["assets:install_dependencies"]
|
73
|
+
```
|
74
|
+
|
75
|
+
This allows more flexibility than what `shakapacker` could provide - for
|
76
|
+
example, you might only want to do an immutable install if you're in CI.
|
77
|
+
|
78
|
+
## `ensure_consistent_versioning` is now enabled by default
|
79
|
+
|
80
|
+
This has `shakapacker` check that the versions of the installed Ruby gem and
|
81
|
+
JavaScript package are compatible; this should only be impactful for codebases
|
82
|
+
that are not using lockfiles.
|
83
|
+
|
84
|
+
## Usages of `globalMutableWebpackConfig` must be replaced with `generateWebpackConfig()`
|
85
|
+
|
86
|
+
The function will return the same object with less risk:
|
87
|
+
|
88
|
+
```js
|
89
|
+
// before
|
90
|
+
const { globalMutableWebpackConfig, merge } = require('shakapacker');
|
91
|
+
|
92
|
+
const customConfig = {
|
93
|
+
module: {
|
94
|
+
rules: [
|
95
|
+
{
|
96
|
+
test: require.resolve('jquery'),
|
97
|
+
loader: 'expose-loader',
|
98
|
+
options: { exposes: ['$', 'jQuery'] }
|
99
|
+
}
|
100
|
+
]
|
101
|
+
}
|
102
|
+
};
|
103
|
+
|
104
|
+
module.exports = merge(globalMutableWebpackConfig, customConfig);
|
105
|
+
```
|
106
|
+
|
107
|
+
```js
|
108
|
+
// after
|
109
|
+
const { generateWebpackConfig } = require('shakapacker');
|
110
|
+
|
111
|
+
const customConfig = {
|
112
|
+
module: {
|
113
|
+
rules: [
|
114
|
+
{
|
115
|
+
test: require.resolve('jquery'),
|
116
|
+
loader: 'expose-loader',
|
117
|
+
options: { exposes: ['$', 'jQuery'] }
|
118
|
+
}
|
119
|
+
]
|
120
|
+
}
|
121
|
+
};
|
122
|
+
|
123
|
+
// you can also pass your config directly to the generator function to have it merged in!
|
124
|
+
module.exports = merge(generateWebpackConfig(), customConfig);
|
125
|
+
```
|
126
|
+
|
127
|
+
## `additional_paths` are now stripped just like with `source_path`
|
128
|
+
|
129
|
+
This means going forward asset paths should be same regardless of their source:
|
130
|
+
|
131
|
+
```erb
|
132
|
+
<%# before %>
|
133
|
+
<%= image_pack_tag('marketing/images/people_looking_happy.png') %>
|
134
|
+
|
135
|
+
<%# after %>
|
136
|
+
<%= image_pack_tag('image/people_looking_happy.png') %>
|
137
|
+
```
|
138
|
+
|
139
|
+
## Misc. removals
|
140
|
+
|
141
|
+
In addition to the above, v8 has also removed a number of miscellaneous
|
142
|
+
functions that no one is probably using anyway but technically could have been
|
143
|
+
including:
|
144
|
+
|
145
|
+
- `isArray` js utility function (just use `Array.isArray` directly)
|
146
|
+
- `relative_url_root` config getter (it was never used)
|
147
|
+
- `verify_file_existance` method (use `verify_file_existence` instead)
|
148
|
+
- `https` option for `webpack-dev-server` (use `server: 'https'` instead)
|
@@ -0,0 +1,12 @@
|
|
1
|
+
source "https://rubygems.org"
|
2
|
+
|
3
|
+
git_source(:github) { |repo| "https://github.com/#{repo}.git" }
|
4
|
+
|
5
|
+
gemspec path: "../"
|
6
|
+
|
7
|
+
gem "rails", '~>7.1.0'
|
8
|
+
gem "arel", github: "rails/arel"
|
9
|
+
gem "rake", ">= 11.1"
|
10
|
+
gem "rack-proxy", require: false
|
11
|
+
gem "rspec-rails", "~> 6.0.0"
|
12
|
+
gem "byebug"
|
data/jest.config.js
ADDED
@@ -39,8 +39,8 @@ default: &default
|
|
39
39
|
# Select loader to use, available options are 'babel' (default), 'swc' or 'esbuild'
|
40
40
|
webpack_loader: 'babel'
|
41
41
|
|
42
|
-
#
|
43
|
-
ensure_consistent_versioning:
|
42
|
+
# Raises an error if there is a mismatch in the shakapacker gem and npm package being used
|
43
|
+
ensure_consistent_versioning: true
|
44
44
|
|
45
45
|
# Select whether the compiler will use SHA digest ('digest' option) or most most recent modified timestamp ('mtime') to determine freshness
|
46
46
|
compiler_strategy: digest
|
data/lib/install/template.rb
CHANGED
@@ -1,12 +1,14 @@
|
|
1
1
|
require "shakapacker/utils/misc"
|
2
|
+
require "shakapacker/utils/manager"
|
2
3
|
require "shakapacker/utils/version_syntax_converter"
|
4
|
+
require "package_json"
|
3
5
|
|
4
6
|
# Install Shakapacker
|
5
7
|
|
6
8
|
force_option = ENV["FORCE"] ? { force: true } : {}
|
7
9
|
|
8
10
|
copy_file "#{__dir__}/config/shakapacker.yml", "config/shakapacker.yml", force_option
|
9
|
-
|
11
|
+
remove_file "#{__dir__}/package.json" if force_option[:force]
|
10
12
|
|
11
13
|
say "Copying webpack core config"
|
12
14
|
directory "#{__dir__}/config/webpack", "config/webpack", force_option
|
@@ -43,22 +45,37 @@ else
|
|
43
45
|
end
|
44
46
|
|
45
47
|
def package_json
|
46
|
-
|
47
|
-
|
48
|
+
@package_json ||= PackageJson.new
|
49
|
+
end
|
50
|
+
|
51
|
+
# setup the package manager with default values
|
52
|
+
package_json.merge! do |pj|
|
53
|
+
babel = pj.fetch("babel", {})
|
54
|
+
|
55
|
+
babel["presets"] ||= []
|
56
|
+
babel["presets"].push("./node_modules/shakapacker/package/babel/preset.js")
|
48
57
|
|
49
|
-
|
58
|
+
package_manager = pj.fetch("packageManager") do
|
59
|
+
"#{Shakapacker::Utils::Manager.guess_binary}@#{Shakapacker::Utils::Manager.guess_version}"
|
50
60
|
end
|
51
61
|
|
52
|
-
|
62
|
+
{
|
63
|
+
"name" => "app",
|
64
|
+
"private" => true,
|
65
|
+
"version" => "0.1.0",
|
66
|
+
"babel" => babel,
|
67
|
+
"browserslist" => [
|
68
|
+
"defaults"
|
69
|
+
],
|
70
|
+
"packageManager" => package_manager
|
71
|
+
}.merge(pj)
|
53
72
|
end
|
54
73
|
|
74
|
+
Shakapacker::Utils::Manager.error_unless_package_manager_is_obvious!
|
75
|
+
|
55
76
|
# Ensure there is `system!("bin/yarn")` command in `./bin/setup` file
|
56
77
|
if (setup_path = Rails.root.join("bin/setup")).exist?
|
57
|
-
|
58
|
-
return "bin/yarn" unless Shakapacker::Utils::Misc.use_package_json_gem
|
59
|
-
|
60
|
-
package_json.manager.native_install_command.join(" ")
|
61
|
-
end
|
78
|
+
native_install_command = package_json.manager.native_install_command.join(" ")
|
62
79
|
|
63
80
|
say "Run #{native_install_command} during bin/setup"
|
64
81
|
|
@@ -88,23 +105,14 @@ if (setup_path = Rails.root.join("bin/setup")).exist?
|
|
88
105
|
end
|
89
106
|
|
90
107
|
def add_dependencies(dependencies, type)
|
91
|
-
|
92
|
-
|
93
|
-
# TODO: check that run actually errors
|
94
|
-
run("yarn add #{dependencies.join(" ")}") if type == :production
|
95
|
-
run("yarn add --dev #{dependencies.join(" ")}") if type == :dev
|
108
|
+
package_json.manager.add!(dependencies, type: type)
|
96
109
|
rescue PackageJson::Error
|
97
110
|
say "Shakapacker installation failed 😭 See above for details.", :red
|
98
111
|
exit 1
|
99
112
|
end
|
100
113
|
|
101
114
|
def fetch_peer_dependencies
|
102
|
-
|
103
|
-
return PackageJson.read("#{__dir__}/../../").fetch("peerDependencies")
|
104
|
-
end
|
105
|
-
|
106
|
-
package_json = File.read("#{__dir__}/../../package.json")
|
107
|
-
JSON.parse(package_json)["peerDependencies"]
|
115
|
+
PackageJson.read("#{__dir__}/../../").fetch("peerDependencies")
|
108
116
|
end
|
109
117
|
|
110
118
|
Dir.chdir(Rails.root) do
|
@@ -112,15 +120,13 @@ Dir.chdir(Rails.root) do
|
|
112
120
|
say "Installing shakapacker@#{npm_version}"
|
113
121
|
add_dependencies(["shakapacker@#{npm_version}"], :production)
|
114
122
|
|
115
|
-
|
116
|
-
|
117
|
-
{
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
}
|
123
|
-
end
|
123
|
+
package_json.merge! do |pj|
|
124
|
+
{
|
125
|
+
"dependencies" => pj["dependencies"].merge({
|
126
|
+
# TODO: workaround for test suite - long-run need to actually account for diff pkg manager behaviour
|
127
|
+
"shakapacker" => pj["dependencies"]["shakapacker"].delete_prefix("^")
|
128
|
+
})
|
129
|
+
}
|
124
130
|
end
|
125
131
|
|
126
132
|
peers = fetch_peer_dependencies
|
@@ -16,7 +16,8 @@ module Shakapacker
|
|
16
16
|
[
|
17
17
|
*config.additional_paths.map { |path| "#{path}{,/**/*}" },
|
18
18
|
"#{config.source_path}{,/**/*}",
|
19
|
-
"
|
19
|
+
"package.json", "package-lock.json", "yarn.lock",
|
20
|
+
"pnpm-lock.yaml", "bun.lockb",
|
20
21
|
"config/webpack{,/**/*}"
|
21
22
|
].freeze
|
22
23
|
end
|
data/lib/shakapacker/compiler.rb
CHANGED
@@ -72,7 +72,7 @@ class Shakapacker::Compiler
|
|
72
72
|
config.root_path.join("tmp/shakapacker.lock")
|
73
73
|
end
|
74
74
|
|
75
|
-
def
|
75
|
+
def optional_ruby_runner
|
76
76
|
first_line = File.readlines(bin_shakapacker_path).first.chomp
|
77
77
|
/ruby/.match?(first_line) ? RbConfig.ruby : ""
|
78
78
|
end
|
@@ -82,7 +82,7 @@ class Shakapacker::Compiler
|
|
82
82
|
|
83
83
|
stdout, stderr, status = Open3.capture3(
|
84
84
|
webpack_env,
|
85
|
-
"#{
|
85
|
+
"#{optional_ruby_runner} '#{bin_shakapacker_path}'",
|
86
86
|
chdir: File.expand_path(config.root_path)
|
87
87
|
)
|
88
88
|
|
@@ -104,28 +104,13 @@ class Shakapacker::Compiler
|
|
104
104
|
def webpack_env
|
105
105
|
return env unless defined?(ActionController::Base)
|
106
106
|
|
107
|
-
Shakapacker.set_shakapacker_env_variables_for_backward_compatibility
|
108
|
-
|
109
107
|
env.merge(
|
110
|
-
"SHAKAPACKER_ASSET_HOST"
|
111
|
-
"
|
112
|
-
"SHAKAPACKER_CONFIG" => instance.config_path.to_s
|
108
|
+
"SHAKAPACKER_ASSET_HOST" => instance.config.asset_host,
|
109
|
+
"SHAKAPACKER_CONFIG" => instance.config.config_path.to_s
|
113
110
|
)
|
114
111
|
end
|
115
112
|
|
116
113
|
def bin_shakapacker_path
|
117
|
-
|
118
|
-
config.root_path.join("bin/shakapacker")
|
119
|
-
elsif File.exist?(config.root_path.join("bin/webpacker"))
|
120
|
-
Shakapacker.puts_deprecation_message(
|
121
|
-
Shakapacker.short_deprecation_message(
|
122
|
-
"bin/webpacker",
|
123
|
-
"bin/shakapacker"
|
124
|
-
)
|
125
|
-
)
|
126
|
-
config.root_path.join("bin/webpacker")
|
127
|
-
else
|
128
|
-
config.root_path.join("bin/shakapacker")
|
129
|
-
end
|
114
|
+
config.root_path.join("bin/shakapacker")
|
130
115
|
end
|
131
116
|
end
|
@@ -12,10 +12,7 @@ class Shakapacker::Configuration
|
|
12
12
|
def initialize(root_path:, config_path:, env:)
|
13
13
|
@root_path = root_path
|
14
14
|
@env = env
|
15
|
-
|
16
|
-
# For backward compatibility
|
17
|
-
Shakapacker.set_shakapacker_env_variables_for_backward_compatibility
|
18
|
-
@config_path = Pathname.new(ENV["SHAKAPACKER_CONFIG"] || config_path)
|
15
|
+
@config_path = config_path
|
19
16
|
end
|
20
17
|
|
21
18
|
def dev_server
|
@@ -43,17 +40,6 @@ class Shakapacker::Configuration
|
|
43
40
|
fetch(:shakapacker_precompile)
|
44
41
|
end
|
45
42
|
|
46
|
-
def webpacker_precompile?
|
47
|
-
Shakapacker.puts_deprecation_message(
|
48
|
-
Shakapacker.short_deprecation_message(
|
49
|
-
"webpacker_precompile?",
|
50
|
-
"shakapacker_precompile?"
|
51
|
-
)
|
52
|
-
)
|
53
|
-
|
54
|
-
shakapacker_precompile?
|
55
|
-
end
|
56
|
-
|
57
43
|
def source_path
|
58
44
|
root_path.join(fetch(:source_path))
|
59
45
|
end
|
@@ -103,17 +89,7 @@ class Shakapacker::Configuration
|
|
103
89
|
end
|
104
90
|
|
105
91
|
def fetch(key)
|
106
|
-
|
107
|
-
|
108
|
-
# for backward compatibility
|
109
|
-
Shakapacker.puts_deprecation_message(
|
110
|
-
Shakapacker.short_deprecation_message(
|
111
|
-
"webpacker_precompile",
|
112
|
-
"shakapacker_precompile"
|
113
|
-
)
|
114
|
-
)
|
115
|
-
|
116
|
-
data.fetch(key, defaults[:shakapacker_precompile])
|
92
|
+
data.fetch(key, defaults[key])
|
117
93
|
end
|
118
94
|
|
119
95
|
def asset_host
|
@@ -123,19 +99,6 @@ class Shakapacker::Configuration
|
|
123
99
|
)
|
124
100
|
end
|
125
101
|
|
126
|
-
def relative_url_root
|
127
|
-
result = ENV.fetch(
|
128
|
-
"SHAKAPACKER_RELATIVE_URL_ROOT",
|
129
|
-
fetch(:relative_url_root) || ActionController::Base.relative_url_root
|
130
|
-
)
|
131
|
-
|
132
|
-
if result
|
133
|
-
Shakapacker.puts_deprecation_message("The usage of relative_url_root is deprecated in Shakapacker and will be removed in v8.")
|
134
|
-
end
|
135
|
-
|
136
|
-
result
|
137
|
-
end
|
138
|
-
|
139
102
|
private
|
140
103
|
def data
|
141
104
|
@data ||= load
|
@@ -149,13 +112,6 @@ class Shakapacker::Configuration
|
|
149
112
|
end
|
150
113
|
symbolized_config = config[env].deep_symbolize_keys
|
151
114
|
|
152
|
-
# For backward compatibility
|
153
|
-
if symbolized_config.key?(:shakapacker_precompile) && !symbolized_config.key?(:webpacker_precompile)
|
154
|
-
symbolized_config[:webpacker_precompile] = symbolized_config[:shakapacker_precompile]
|
155
|
-
elsif !symbolized_config.key?(:shakapacker_precompile) && symbolized_config.key?(:webpacker_precompile)
|
156
|
-
symbolized_config[:shakapacker_precompile] = symbolized_config[:webpacker_precompile]
|
157
|
-
end
|
158
|
-
|
159
115
|
return symbolized_config
|
160
116
|
rescue Errno::ENOENT => e
|
161
117
|
if self.class.installing
|