shakapacker 7.1.0 → 7.2.0.rc.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/workflows/generator.yml +3 -0
- data/.github/workflows/ruby-backward-compatibility.yml +6 -0
- data/.github/workflows/ruby.yml +7 -0
- data/CHANGELOG.md +12 -6
- data/README.md +29 -3
- data/docs/v6_upgrade.md +1 -1
- data/lib/install/template.rb +56 -16
- data/lib/shakapacker/compiler.rb +5 -3
- data/lib/shakapacker/configuration.rb +8 -0
- data/lib/shakapacker/dev_server_runner.rb +11 -5
- data/lib/shakapacker/runner.rb +19 -1
- data/lib/shakapacker/utils/misc.rb +12 -0
- data/lib/shakapacker/version.rb +1 -1
- data/lib/shakapacker/webpack_runner.rb +12 -5
- data/lib/tasks/shakapacker/binstubs.rake +1 -1
- data/lib/tasks/shakapacker/check_manager.rake +27 -0
- data/lib/tasks/shakapacker/check_yarn.rake +2 -1
- data/lib/tasks/shakapacker/info.rake +20 -3
- data/lib/tasks/shakapacker/install.rake +1 -1
- data/lib/tasks/shakapacker/verify_install.rake +1 -1
- data/lib/tasks/shakapacker.rake +2 -2
- data/lib/tasks/webpacker/check_yarn.rake +1 -1
- data/package.json +2 -2
- data/shakapacker.gemspec +1 -0
- data/spec/backward_compatibility_specs/dev_server_runner_spec.rb +90 -30
- data/spec/backward_compatibility_specs/engine_rake_tasks_spec.rb +29 -7
- data/spec/backward_compatibility_specs/webpack_runner_spec.rb +44 -10
- data/spec/generator_specs/e2e_template/template.rb +31 -10
- data/spec/generator_specs/fake-bin/bun +10 -0
- data/spec/generator_specs/fake-bin/npm +10 -0
- data/spec/generator_specs/fake-bin/pnpm +10 -0
- data/spec/generator_specs/fake-bin/yarn +10 -0
- data/spec/generator_specs/generator_spec.rb +167 -17
- data/spec/mounted_app/package.json +1 -0
- data/spec/shakapacker/compiler_spec.rb +9 -5
- data/spec/shakapacker/configuration_spec.rb +48 -0
- data/spec/shakapacker/dev_server_runner_spec.rb +88 -29
- data/spec/shakapacker/engine_rake_tasks_spec.rb +27 -6
- data/spec/shakapacker/rake_tasks_spec.rb +6 -5
- data/spec/shakapacker/spec_helper_initializer.rb +18 -0
- data/spec/shakapacker/webpack_runner_spec.rb +44 -10
- data/spec/spec_helper.rb +2 -0
- data/spec/support/package_json_helpers.rb +16 -0
- metadata +26 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d7c6cb64c439d97ec52580010225f4b2204ea652e281926da18b21be6c7ef545
|
4
|
+
data.tar.gz: 33adeb8d524cd2c08206bc1b06c3183cd44f469c7c44b453466ea149baceb30d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 22c9e5716abf6528ab34f652a6b145cb97897769b7c9f4da09f63b9090ce3a2faea507db94cc6fcd87cdf5be8bc60be0881ffd2f9f1f7a5d218d37d759021ffc
|
7
|
+
data.tar.gz: c3a299a84e15d15216d9e6e8c83513b6a9d0ca805587b80779e7e6b8bafd0e8f7090686a6fd82da1eecd829d25a68bf8df25ebf7bec1f82213918edb83953f92
|
@@ -10,6 +10,7 @@ jobs:
|
|
10
10
|
matrix:
|
11
11
|
os: [ubuntu-latest]
|
12
12
|
ruby: ['2.6', '2.7', '3.0']
|
13
|
+
use_package_json_gem: ['true', 'false']
|
13
14
|
gemfile:
|
14
15
|
- gemfiles/Gemfile-rails.6.0.x
|
15
16
|
- gemfiles/Gemfile-rails.6.1.x
|
@@ -37,3 +38,5 @@ jobs:
|
|
37
38
|
- name: Install dependencies
|
38
39
|
run: bundle install
|
39
40
|
- run: bundle exec rake run_spec:generator
|
41
|
+
env:
|
42
|
+
SHAKAPACKER_USE_PACKAGE_JSON_GEM: ${{ matrix.use_package_json_gem }}
|
@@ -39,3 +39,9 @@ jobs:
|
|
39
39
|
|
40
40
|
- name: Ruby specs - Backward compatibility
|
41
41
|
run: bundle exec rake run_spec:gem_bc
|
42
|
+
env:
|
43
|
+
SHAKAPACKER_USE_PACKAGE_JSON_GEM: "false"
|
44
|
+
- name: Ruby specs - Backward compatibility
|
45
|
+
run: bundle exec rake run_spec:gem_bc
|
46
|
+
env:
|
47
|
+
SHAKAPACKER_USE_PACKAGE_JSON_GEM: "true"
|
data/.github/workflows/ruby.yml
CHANGED
data/CHANGELOG.md
CHANGED
@@ -5,20 +5,25 @@
|
|
5
5
|
|
6
6
|
## Versions
|
7
7
|
## [Unreleased]
|
8
|
-
Changes since last non-beta release.
|
8
|
+
Changes since the last non-beta release.
|
9
9
|
|
10
10
|
_Please add entries here for your pull requests that are not yet released._
|
11
11
|
|
12
12
|
### Added
|
13
|
-
-
|
13
|
+
- Experimental support for other JS package managers using `package_json` gem [PR 349](https://github.com/shakacode/shakapacker/pull/349) by [G-Rath](https://github.com/g-rath).
|
14
|
+
|
15
|
+
## [v7.1.0] - September 30, 2023
|
16
|
+
|
17
|
+
### Added
|
18
|
+
- Support passing custom webpack config directly to `generateWebpackConfig` for merging [PR 343](https://github.com/shakacode/shakapacker/pull/343) by [G-Rath](https://github.com/g-rath).
|
14
19
|
|
15
20
|
### Fixed
|
16
|
-
- Use `NODE_OPTIONS` to enable Node-specific debugging flags [PR 350](https://github.com/shakacode/shakapacker/pull/350)
|
17
|
-
- Add the
|
21
|
+
- Use `NODE_OPTIONS` to enable Node-specific debugging flags [PR 350](https://github.com/shakacode/shakapacker/pull/350).
|
22
|
+
- Add the boilerplate `application.js` into `packs/` [PR 363](https://github.com/shakacode/shakapacker/pull/363).
|
18
23
|
|
19
24
|
## [v7.0.3] - July 7, 2023
|
20
25
|
### Fixed
|
21
|
-
- Fixed commands execution for projects with space in absolute path [PR 322](https://github.com/shakacode/shakapacker/pull/322) by [kukicola](https://github.com/kukicola).
|
26
|
+
- Fixed commands execution for projects with space in the absolute path [PR 322](https://github.com/shakacode/shakapacker/pull/322) by [kukicola](https://github.com/kukicola).
|
22
27
|
|
23
28
|
## [v7.0.2] - July 3, 2023
|
24
29
|
### Fixed
|
@@ -274,7 +279,8 @@ Note: [Rubygem is 6.3.0.pre.rc.1](https://rubygems.org/gems/shakapacker/versions
|
|
274
279
|
## v5.4.3 and prior changes from rails/webpacker
|
275
280
|
See [CHANGELOG.md in rails/webpacker (up to v5.4.3)](https://github.com/rails/webpacker/blob/master/CHANGELOG.md)
|
276
281
|
|
277
|
-
[Unreleased]: https://github.com/shakacode/shakapacker/compare/v7.0
|
282
|
+
[Unreleased]: https://github.com/shakacode/shakapacker/compare/v7.1.0...master
|
283
|
+
[v7.1.0]: https://github.com/shakacode/shakapacker/compare/v7.0.3...v7.1.0
|
278
284
|
[v7.0.3]: https://github.com/shakacode/shakapacker/compare/v7.0.2...v7.0.3
|
279
285
|
[v7.0.2]: https://github.com/shakacode/shakapacker/compare/v7.0.1...v7.0.2
|
280
286
|
[v7.0.1]: https://github.com/shakacode/shakapacker/compare/v7.0.0...v7.0.1
|
data/README.md
CHANGED
@@ -51,6 +51,7 @@ Read the [full review here](https://clutch.co/profile/shakacode#reviews?sort_by=
|
|
51
51
|
- [Optional support](#optional-support)
|
52
52
|
- [Installation](#installation)
|
53
53
|
- [Rails v6+](#rails-v6)
|
54
|
+
- [Using alternative package managers](#using-alternative-package-managers)
|
54
55
|
- [Note for Yarn v2 usage](#note-for-yarn-v2-usage)
|
55
56
|
- [Concepts](#concepts)
|
56
57
|
- [Usage](#usage)
|
@@ -163,9 +164,21 @@ yarn add @babel/core @babel/plugin-transform-runtime @babel/preset-env @babel/ru
|
|
163
164
|
Previously, these "webpack" and "babel" packages were direct dependencies for `shakapacker`. By
|
164
165
|
making these peer dependencies, you have control over the versions used in your webpack and babel configs.
|
165
166
|
|
167
|
+
### Using alternative package managers
|
168
|
+
|
169
|
+
There is experimental support for using package managers besides Yarn classic for managing JavaScript dependencies using the [`package_json`](https://github.com/G-Rath/package_json) gem.
|
170
|
+
|
171
|
+
This can be enabled by setting the environment variable `SHAKAPACKER_USE_PACKAGE_JSON_GEM` to `true`; Shakapacker will then use the `package_json` gem which in turn will look for the [`packageManager`](https://nodejs.org/api/packages.html#packagemanager) property in the `package.json` or otherwise the `PACKAGE_JSON_FALLBACK_MANAGER` environment variable to determine which manager to use, defaulting to `npm` if neither are found.
|
172
|
+
|
173
|
+
See [here](https://github.com/G-Rath/package_json#specifying-a-package-manager) for a list of the supported package managers and more information; note that `package_json` does not handle ensuring the manager is installed.
|
174
|
+
|
175
|
+
> **Note**
|
176
|
+
>
|
177
|
+
> The rest of the documentation assumes that `package_json` is not being used, and so always references `yarn` - you should instead use the package manager of your choice for these commands.
|
178
|
+
|
166
179
|
### Note for Yarn v2 usage
|
167
180
|
|
168
|
-
If you are using Yarn v2 (berry), please note that PnP modules are not supported
|
181
|
+
If you are using Yarn v2 (berry), please note that PnP modules are not supported unless you're using `SHAKAPACKER_USE_PACKAGE_JSON_GEM`.
|
169
182
|
|
170
183
|
To use Shakapacker with Yarn v2, make sure you set `nodeLinker: node-modules` in your `.yarnrc.yml` file as per the [Yarn docs](https://yarnpkg.com/getting-started/migration#step-by-step) to opt out of Plug'n'Play behavior.
|
171
184
|
|
@@ -272,7 +285,11 @@ Note, the default of "defer" for the `javascript_pack_tag`. You can override tha
|
|
272
285
|
<%= javascript_pack_tag 'calendar' %>
|
273
286
|
<%= javascript_pack_tag 'map' %>
|
274
287
|
```
|
275
|
-
|
288
|
+
|
289
|
+
While this also generally applies to `stylesheet_pack_tag`,
|
290
|
+
you may use multiple calls to stylesheet_pack_tag if,
|
291
|
+
say,
|
292
|
+
you require multiple `<style>` tags for different output media:
|
276
293
|
|
277
294
|
``` erb
|
278
295
|
<%= stylesheet_pack_tag 'application', media: 'screen' %>
|
@@ -417,7 +434,16 @@ In production or CI environments, the `digest` strategy is more suitable, unless
|
|
417
434
|
|
418
435
|
You can control what strategy is used by the `compiler_strategy` option in `shakapacker.yml` config file. By default `mtime` strategy is used in development environment, `digest` is used elsewhere.
|
419
436
|
|
420
|
-
**Note:**
|
437
|
+
**Note:**
|
438
|
+
If you are not using the `shakapacker-dev-server`,
|
439
|
+
your packs will be served by the Rails public file server.
|
440
|
+
If you've enabled caching
|
441
|
+
(Rails application `config.action_controller.perform_caching` setting),
|
442
|
+
your changes will likely not be picked up due to `Cache-Control` header being set
|
443
|
+
and
|
444
|
+
assets being cached in the browser memory.
|
445
|
+
For more details see
|
446
|
+
[issue 88: Caching issues in Development since migrating to Shakapacker](https://github.com/shakacode/shakapacker/issues/88).
|
421
447
|
|
422
448
|
If you want to use live code reloading, or you have enough JavaScript that on-demand compilation is too slow, you'll need to run `./bin/shakapacker-dev-server`. This process will watch for changes in the relevant files, defined by `shakapacker.yml` configuration settings for `source_path`, `source_entry_path`, and `additional_paths`, and it will then automatically reload the browser to match. This feature is also known as [Hot Module Replacement](https://webpack.js.org/concepts/hot-module-replacement/).
|
423
449
|
|
data/docs/v6_upgrade.md
CHANGED
@@ -101,7 +101,7 @@ _If you're on webpacker v5, follow [how to upgrade to webpacker v6.0.0.rc.6 from
|
|
101
101
|
|
102
102
|
1. Update `webpack-dev-server` to the current version, greater than 4.2, updating `package.json`.
|
103
103
|
|
104
|
-
1. Update API usage of the view helpers by changing `javascript_packs_with_chunks_tag` and `stylesheet_packs_with_chunks_tag` to `javascript_pack_tag` and `stylesheet_pack_tag`. Ensure that your layouts and views will only have **at most one call** to `javascript_pack_tag` and **at most one call** to `stylesheet_pack_tag`. You can now pass multiple bundles to these view helper methods. If you fail to changes this, you may experience performance issues, and other bugs related to multiple copies of React, like [issue 2932](https://github.com/rails/webpacker/issues/2932). If you expose jquery globally with `expose-loader
|
104
|
+
1. Update API usage of the view helpers by changing `javascript_packs_with_chunks_tag` and `stylesheet_packs_with_chunks_tag` to `javascript_pack_tag` and `stylesheet_pack_tag`. Ensure that your layouts and views will only have **at most one call** to `javascript_pack_tag` and **at most one call** to `stylesheet_pack_tag`. You can now pass multiple bundles to these view helper methods. If you fail to changes this, you may experience performance issues, and other bugs related to multiple copies of React, like [issue 2932](https://github.com/rails/webpacker/issues/2932). If you expose jquery globally with `expose-loader` by using `import $ from "expose-loader?exposes=$,jQuery!jquery"` in your `app/javascript/application.js`, pass the option `defer: false` to your `javascript_pack_tag`.
|
105
105
|
|
106
106
|
1. If you are using any integrations like `css`, `postcss`, `React` or `TypeScript`. Please see https://github.com/shakacode/shakapacker#integrations section on how they work in v6.
|
107
107
|
|
data/lib/install/template.rb
CHANGED
@@ -1,3 +1,4 @@
|
|
1
|
+
require "shakapacker/utils/misc"
|
1
2
|
require "shakapacker/utils/version_syntax_converter"
|
2
3
|
|
3
4
|
# Install Shakapacker
|
@@ -41,12 +42,28 @@ else
|
|
41
42
|
say %( Add <%= javascript_pack_tag "application" %> within the <head> tag in your custom layout.)
|
42
43
|
end
|
43
44
|
|
45
|
+
def package_json
|
46
|
+
if @package_json.nil?
|
47
|
+
Shakapacker::Utils::Misc.require_package_json_gem
|
48
|
+
|
49
|
+
@package_json = PackageJson.read
|
50
|
+
end
|
51
|
+
|
52
|
+
@package_json
|
53
|
+
end
|
54
|
+
|
44
55
|
# Ensure there is `system!("bin/yarn")` command in `./bin/setup` file
|
45
56
|
if (setup_path = Rails.root.join("bin/setup")).exist?
|
46
|
-
|
57
|
+
def native_install_command
|
58
|
+
return "bin/yarn" unless Shakapacker::Utils::Misc.use_package_json_gem
|
59
|
+
|
60
|
+
package_json.manager.native_install_command.join(" ")
|
61
|
+
end
|
62
|
+
|
63
|
+
say "Run #{native_install_command} during bin/setup"
|
47
64
|
|
48
65
|
if File.read(setup_path).match? Regexp.escape(" # system('bin/yarn')\n")
|
49
|
-
gsub_file(setup_path, "# system('bin/yarn')", "system!('
|
66
|
+
gsub_file(setup_path, "# system('bin/yarn')", "system!('#{native_install_command}')")
|
50
67
|
else
|
51
68
|
# Due to the inconsistency of quotation usage in Rails 7 compared to
|
52
69
|
# earlier versions, we check both single and double quotations here.
|
@@ -55,30 +72,58 @@ if (setup_path = Rails.root.join("bin/setup")).exist?
|
|
55
72
|
string_to_add = <<-RUBY
|
56
73
|
|
57
74
|
# Install JavaScript dependencies
|
58
|
-
system!("
|
59
|
-
RUBY
|
75
|
+
system!("#{native_install_command}")
|
76
|
+
RUBY
|
60
77
|
|
61
78
|
if File.read(setup_path).match? pattern
|
62
79
|
insert_into_file(setup_path, string_to_add, after: pattern)
|
63
80
|
else
|
64
81
|
say <<~MSG, :red
|
65
82
|
It seems your `bin/setup` file doesn't have the expected content.
|
66
|
-
Please review the file and manually add `system!("
|
83
|
+
Please review the file and manually add `system!("#{native_install_command}")` before any
|
67
84
|
other command that requires JavaScript dependencies being already installed.
|
68
85
|
MSG
|
69
86
|
end
|
70
87
|
end
|
71
88
|
end
|
72
89
|
|
73
|
-
|
90
|
+
def add_dependencies(dependencies, type)
|
91
|
+
return package_json.manager.add!(dependencies, type: type) if Shakapacker::Utils::Misc.use_package_json_gem
|
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
|
96
|
+
rescue PackageJson::Error
|
97
|
+
say "Shakapacker installation failed 😭 See above for details.", :red
|
98
|
+
exit 1
|
99
|
+
end
|
100
|
+
|
101
|
+
def fetch_peer_dependencies
|
102
|
+
if Shakapacker::Utils::Misc.use_package_json_gem
|
103
|
+
return PackageJson.read("#{__dir__}/../../").fetch("peerDependencies")
|
104
|
+
end
|
105
|
+
|
106
|
+
package_json = File.read("#{__dir__}/../../package.json")
|
107
|
+
JSON.parse(package_json)["peerDependencies"]
|
108
|
+
end
|
74
109
|
|
75
110
|
Dir.chdir(Rails.root) do
|
76
111
|
npm_version = Shakapacker::Utils::VersionSyntaxConverter.new.rubygem_to_npm(Shakapacker::VERSION)
|
77
112
|
say "Installing shakapacker@#{npm_version}"
|
78
|
-
|
113
|
+
add_dependencies(["shakapacker@#{npm_version}"], :production)
|
114
|
+
|
115
|
+
if Shakapacker::Utils::Misc.use_package_json_gem
|
116
|
+
package_json.merge! do |pj|
|
117
|
+
{
|
118
|
+
"dependencies" => pj["dependencies"].merge({
|
119
|
+
# TODO: workaround for test suite - long-run need to actually account for diff pkg manager behaviour
|
120
|
+
"shakapacker" => pj["dependencies"]["shakapacker"].delete_prefix("^")
|
121
|
+
})
|
122
|
+
}
|
123
|
+
end
|
124
|
+
end
|
79
125
|
|
80
|
-
|
81
|
-
peers = JSON.parse(package_json)["peerDependencies"]
|
126
|
+
peers = fetch_peer_dependencies
|
82
127
|
dev_dependency_packages = ["webpack-dev-server"]
|
83
128
|
|
84
129
|
dependencies_to_add = []
|
@@ -96,13 +141,8 @@ Dir.chdir(Rails.root) do
|
|
96
141
|
end
|
97
142
|
|
98
143
|
say "Adding shakapacker peerDependencies"
|
99
|
-
|
144
|
+
add_dependencies(dependencies_to_add, :production)
|
100
145
|
|
101
146
|
say "Installing webpack-dev-server for live reloading as a development dependency"
|
102
|
-
|
103
|
-
end
|
104
|
-
|
105
|
-
unless results.all?
|
106
|
-
say "Shakapacker installation failed 😭 See above for details.", :red
|
107
|
-
exit 1
|
147
|
+
add_dependencies(dev_dependencies_to_add, :dev)
|
108
148
|
end
|
data/lib/shakapacker/compiler.rb
CHANGED
@@ -106,9 +106,11 @@ class Shakapacker::Compiler
|
|
106
106
|
|
107
107
|
Shakapacker.set_shakapacker_env_variables_for_backward_compatibility
|
108
108
|
|
109
|
-
env.merge(
|
110
|
-
|
111
|
-
|
109
|
+
env.merge(
|
110
|
+
"SHAKAPACKER_ASSET_HOST" => instance.config.asset_host,
|
111
|
+
"SHAKAPACKER_RELATIVE_URL_ROOT" => instance.config.relative_url_root,
|
112
|
+
"SHAKAPACKER_CONFIG" => instance.config_path.to_s
|
113
|
+
)
|
112
114
|
end
|
113
115
|
|
114
116
|
def bin_shakapacker_path
|
@@ -116,6 +116,14 @@ class Shakapacker::Configuration
|
|
116
116
|
data.fetch(key, defaults[:shakapacker_precompile])
|
117
117
|
end
|
118
118
|
|
119
|
+
def asset_host
|
120
|
+
ENV.fetch("SHAKAPACKER_ASSET_HOST", ActionController::Base.helpers.compute_asset_host)
|
121
|
+
end
|
122
|
+
|
123
|
+
def relative_url_root
|
124
|
+
ENV.fetch("SHAKAPACKER_RELATIVE_URL_ROOT", ActionController::Base.relative_url_root)
|
125
|
+
end
|
126
|
+
|
119
127
|
private
|
120
128
|
def data
|
121
129
|
@data ||= load
|
@@ -68,11 +68,7 @@ module Shakapacker
|
|
68
68
|
env["WEBPACK_SERVE"] = "true"
|
69
69
|
env["NODE_OPTIONS"] = ENV["NODE_OPTIONS"] || ""
|
70
70
|
|
71
|
-
cmd =
|
72
|
-
["#{@node_modules_bin_path}/webpack", "serve"]
|
73
|
-
else
|
74
|
-
["yarn", "webpack", "serve"]
|
75
|
-
end
|
71
|
+
cmd = build_cmd
|
76
72
|
|
77
73
|
if @argv.include?("--debug-webpacker")
|
78
74
|
Shakapacker.puts_deprecation_message(
|
@@ -98,6 +94,16 @@ module Shakapacker
|
|
98
94
|
end
|
99
95
|
end
|
100
96
|
|
97
|
+
def build_cmd
|
98
|
+
if Shakapacker::Utils::Misc.use_package_json_gem
|
99
|
+
return package_json.manager.native_exec_command("webpack", ["serve"])
|
100
|
+
end
|
101
|
+
|
102
|
+
return ["#{@node_modules_bin_path}/webpack", "serve"] if node_modules_bin_exist?
|
103
|
+
|
104
|
+
["yarn", "webpack", "serve"]
|
105
|
+
end
|
106
|
+
|
101
107
|
def node_modules_bin_exist?
|
102
108
|
File.exist?("#{@node_modules_bin_path}/webpack-dev-server")
|
103
109
|
end
|
data/lib/shakapacker/runner.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
require "shakapacker/utils/misc"
|
2
|
+
|
1
3
|
module Shakapacker
|
2
4
|
class Runner
|
3
5
|
def self.run(argv)
|
@@ -14,7 +16,7 @@ module Shakapacker
|
|
14
16
|
|
15
17
|
Shakapacker.set_shakapacker_env_variables_for_backward_compatibility
|
16
18
|
|
17
|
-
@node_modules_bin_path =
|
19
|
+
@node_modules_bin_path = fetch_node_modules_bin_path
|
18
20
|
@shakapacker_config = ENV["SHAKAPACKER_CONFIG"] || File.join(@app_path, "config/shakapacker.yml")
|
19
21
|
|
20
22
|
@shakapacker_config = Shakapacker.get_config_file_path_with_backward_compatibility(@shakapacker_config)
|
@@ -24,5 +26,21 @@ module Shakapacker
|
|
24
26
|
exit!
|
25
27
|
end
|
26
28
|
end
|
29
|
+
|
30
|
+
def fetch_node_modules_bin_path
|
31
|
+
return nil if Shakapacker::Utils::Misc.use_package_json_gem
|
32
|
+
|
33
|
+
ENV["SHAKAPACKER_NODE_MODULES_BIN_PATH"] || `yarn bin`.chomp
|
34
|
+
end
|
35
|
+
|
36
|
+
def package_json
|
37
|
+
if @package_json.nil?
|
38
|
+
Shakapacker::Utils::Misc.require_package_json_gem
|
39
|
+
|
40
|
+
@package_json = PackageJson.read(@app_path)
|
41
|
+
end
|
42
|
+
|
43
|
+
@package_json
|
44
|
+
end
|
27
45
|
end
|
28
46
|
end
|
@@ -8,6 +8,18 @@ module Shakapacker
|
|
8
8
|
class Misc
|
9
9
|
extend FileUtils
|
10
10
|
|
11
|
+
def self.use_package_json_gem
|
12
|
+
ENV.fetch("SHAKAPACKER_USE_PACKAGE_JSON_GEM", "false").casecmp("true").zero?
|
13
|
+
end
|
14
|
+
|
15
|
+
def self.require_package_json_gem
|
16
|
+
unless use_package_json_gem
|
17
|
+
raise "PackageJson should not be used unless SHAKAPACKER_USE_PACKAGE_JSON_GEM is true"
|
18
|
+
end
|
19
|
+
|
20
|
+
require "package_json"
|
21
|
+
end
|
22
|
+
|
11
23
|
def self.uncommitted_changes?(message_handler)
|
12
24
|
return false if ENV["COVERAGE"] == "true"
|
13
25
|
|
data/lib/shakapacker/version.rb
CHANGED
@@ -21,11 +21,7 @@ module Shakapacker
|
|
21
21
|
env["SHAKAPACKER_CONFIG"] = @shakapacker_config
|
22
22
|
env["NODE_OPTIONS"] = ENV["NODE_OPTIONS"] || ""
|
23
23
|
|
24
|
-
cmd =
|
25
|
-
["#{@node_modules_bin_path}/webpack"]
|
26
|
-
else
|
27
|
-
["yarn", "webpack"]
|
28
|
-
end
|
24
|
+
cmd = build_cmd
|
29
25
|
|
30
26
|
if @argv.include?("--debug-webpacker")
|
31
27
|
Shakapacker.puts_deprecation_message(
|
@@ -61,6 +57,17 @@ module Shakapacker
|
|
61
57
|
end
|
62
58
|
|
63
59
|
private
|
60
|
+
|
61
|
+
def build_cmd
|
62
|
+
if Shakapacker::Utils::Misc.use_package_json_gem
|
63
|
+
return package_json.manager.native_exec_command("webpack")
|
64
|
+
end
|
65
|
+
|
66
|
+
return ["#{@node_modules_bin_path}/webpack"] if node_modules_bin_exist?
|
67
|
+
|
68
|
+
["yarn", "webpack"]
|
69
|
+
end
|
70
|
+
|
64
71
|
def node_modules_bin_exist?
|
65
72
|
File.exist?("#{@node_modules_bin_path}/webpack")
|
66
73
|
end
|
@@ -3,7 +3,7 @@ bin_path = ENV["BUNDLE_BIN"] || Rails.root.join("bin")
|
|
3
3
|
|
4
4
|
namespace :shakapacker do
|
5
5
|
desc "Installs Shakapacker binstubs in this application"
|
6
|
-
task binstubs: [:check_node, :
|
6
|
+
task binstubs: [:check_node, :check_manager] do |task|
|
7
7
|
prefix = task.name.split(/#|shakapacker:binstubs/).first
|
8
8
|
|
9
9
|
if Rails::VERSION::MAJOR >= 5
|
@@ -0,0 +1,27 @@
|
|
1
|
+
require "shakapacker/utils/misc"
|
2
|
+
|
3
|
+
namespace :shakapacker do
|
4
|
+
desc "Verifies if the expected JS package manager is installed"
|
5
|
+
task :check_manager do |task|
|
6
|
+
unless Shakapacker::Utils::Misc.use_package_json_gem
|
7
|
+
prefix = task.name.split(/#|shakapacker:/).first
|
8
|
+
Rake::Task["#{prefix}shakapacker:check_manager"].invoke
|
9
|
+
next
|
10
|
+
end
|
11
|
+
|
12
|
+
require "package_json"
|
13
|
+
|
14
|
+
package_json = PackageJson.read
|
15
|
+
pm = package_json.manager.binary
|
16
|
+
|
17
|
+
begin
|
18
|
+
version = package_json.manager.version
|
19
|
+
|
20
|
+
$stdout.puts "using #{pm}@#{version} to manage dependencies and scripts in package.json"
|
21
|
+
rescue PackageJson::Error
|
22
|
+
$stderr.puts "#{pm} not installed - please ensure it is installed before trying again"
|
23
|
+
$stderr.puts "Exiting!"
|
24
|
+
exit!
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
@@ -1,7 +1,8 @@
|
|
1
|
-
require "semantic_range"
|
2
1
|
namespace :shakapacker do
|
3
2
|
desc "Verifies if Yarn is installed"
|
4
3
|
task :check_yarn do
|
4
|
+
require "semantic_range"
|
5
|
+
|
5
6
|
begin
|
6
7
|
which_command = Gem.win_platform? ? "where" : "which"
|
7
8
|
raise Errno::ENOENT if `#{which_command} yarn`.strip.empty?
|
@@ -1,4 +1,5 @@
|
|
1
1
|
require "shakapacker/version"
|
2
|
+
require "shakapacker/utils/misc"
|
2
3
|
|
3
4
|
namespace :shakapacker do
|
4
5
|
desc "Provide information on Shakapacker's environment"
|
@@ -8,14 +9,30 @@ namespace :shakapacker do
|
|
8
9
|
$stdout.puts "Rails: #{Rails.version}"
|
9
10
|
$stdout.puts "Shakapacker: #{Shakapacker::VERSION}"
|
10
11
|
$stdout.puts "Node: #{`node --version`}"
|
11
|
-
|
12
|
+
if Shakapacker::Utils::Misc.use_package_json_gem
|
13
|
+
require "package_json"
|
14
|
+
|
15
|
+
pj_manager = PackageJson.read.manager
|
16
|
+
|
17
|
+
$stdout.puts "#{pj_manager.binary}: #{pj_manager.version}"
|
18
|
+
else
|
19
|
+
$stdout.puts "Yarn: #{`yarn --version`}"
|
20
|
+
end
|
21
|
+
|
22
|
+
if Shakapacker::Utils::Misc.use_package_json_gem
|
23
|
+
node_package_version = Shakapacker::VersionChecker.build.node_package_version.raw
|
24
|
+
else
|
25
|
+
node_package_version = `npm list shakapacker version`
|
26
|
+
end
|
12
27
|
|
13
28
|
$stdout.puts "\n"
|
14
|
-
$stdout.puts "shakapacker:
|
29
|
+
$stdout.puts "shakapacker: #{node_package_version}"
|
15
30
|
|
16
31
|
$stdout.puts "Is bin/shakapacker present?: #{File.exist? 'bin/shakapacker'}"
|
17
32
|
$stdout.puts "Is bin/shakapacker-dev-server present?: #{File.exist? 'bin/shakapacker-dev-server'}"
|
18
|
-
|
33
|
+
unless Shakapacker::Utils::Misc.use_package_json_gem
|
34
|
+
$stdout.puts "Is bin/yarn present?: #{File.exist? 'bin/yarn'}"
|
35
|
+
end
|
19
36
|
end
|
20
37
|
end
|
21
38
|
end
|
@@ -3,7 +3,7 @@ bin_path = ENV["BUNDLE_BIN"] || Rails.root.join("bin")
|
|
3
3
|
|
4
4
|
namespace :shakapacker do
|
5
5
|
desc "Install Shakapacker in this application"
|
6
|
-
task install: [:check_node
|
6
|
+
task install: [:check_node] do |task|
|
7
7
|
Shakapacker::Configuration.installing = true
|
8
8
|
|
9
9
|
prefix = task.name.split(/#|shakapacker:install/).first
|
data/lib/tasks/shakapacker.rake
CHANGED
@@ -1,11 +1,11 @@
|
|
1
1
|
tasks = {
|
2
2
|
"shakapacker:info" => "Provides information on Shakapacker's environment",
|
3
|
-
"shakapacker:install" => "Installs and setup webpack
|
3
|
+
"shakapacker:install" => "Installs and setup webpack",
|
4
4
|
"shakapacker:compile" => "Compiles webpack bundles based on environment",
|
5
5
|
"shakapacker:clean" => "Remove old compiled bundles",
|
6
6
|
"shakapacker:clobber" => "Removes the webpack compiled output directory",
|
7
7
|
"shakapacker:check_node" => "Verifies if Node.js is installed",
|
8
|
-
"shakapacker:
|
8
|
+
"shakapacker:check_manager" => "Verifies if the expected JS package manager is available",
|
9
9
|
"shakapacker:check_binstubs" => "Verifies that bin/shakapacker is present",
|
10
10
|
"shakapacker:binstubs" => "Installs Shakapacker binstubs in this application",
|
11
11
|
"shakapacker:verify_install" => "Verifies if Shakapacker is installed",
|
data/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "shakapacker",
|
3
|
-
"version": "7.
|
3
|
+
"version": "7.2.0-rc.0",
|
4
4
|
"description": "Use webpack to manage app-like JavaScript modules in Rails",
|
5
5
|
"main": "package/index.js",
|
6
6
|
"types": "package/index.d.ts",
|
@@ -10,7 +10,7 @@
|
|
10
10
|
],
|
11
11
|
"engines": {
|
12
12
|
"node": "^12.13.0 || ^14 || >=16",
|
13
|
-
"yarn": ">=1 <
|
13
|
+
"yarn": ">=1 <5"
|
14
14
|
},
|
15
15
|
"peerDependencies": {
|
16
16
|
"@types/babel__core": "^7.0.0",
|
data/shakapacker.gemspec
CHANGED
@@ -18,6 +18,7 @@ Gem::Specification.new do |s|
|
|
18
18
|
s.required_ruby_version = ">= 2.6.0"
|
19
19
|
|
20
20
|
s.add_dependency "activesupport", ">= 5.2"
|
21
|
+
s.add_dependency "package_json"
|
21
22
|
s.add_dependency "railties", ">= 5.2"
|
22
23
|
s.add_dependency "rack-proxy", ">= 0.6.1"
|
23
24
|
s.add_dependency "semantic_range", ">= 2.3.0"
|