shakapacker 7.3.0.beta.1 → 8.0.0.rc.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- 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 +6 -1
- data/.github/workflows/generator.yml +14 -18
- data/.github/workflows/node.yml +56 -0
- data/.github/workflows/ruby.yml +29 -17
- data/.node-version +1 -1
- data/.rubocop.yml +1 -0
- data/CHANGELOG.md +56 -5
- data/README.md +101 -48
- data/Rakefile +1 -7
- data/docs/customizing_babel_config.md +2 -2
- data/docs/deployment.md +13 -6
- data/docs/react.md +7 -13
- data/docs/troubleshooting.md +4 -4
- data/docs/using_esbuild_loader.md +1 -1
- data/docs/using_swc_loader.md +1 -1
- data/docs/v6_upgrade.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 +6 -21
- 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/helper.rb +3 -3
- 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 -19
- 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 -2
- 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 +14 -7
- data/package/rules/index.js +11 -11
- data/package/rules/jscommon.js +8 -5
- data/package/rules/less.js +10 -9
- data/package/rules/raw.js +1 -1
- data/package/rules/sass.js +4 -4
- data/package/rules/stylus.js +12 -7
- 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 +12 -18
- 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/fixtures/github_url_package-lock.v1.json +1 -1
- data/spec/fixtures/github_url_package-lock.v2.json +2 -2
- data/spec/fixtures/github_url_package.json +1 -1
- data/spec/fixtures/github_url_pnpm-lock.v7.yaml +1 -1
- data/spec/fixtures/github_url_pnpm-lock.v8.yaml +1 -1
- data/spec/fixtures/github_url_yarn.v1.lock +1 -1
- data/spec/fixtures/github_url_yarn.v2.lock +2 -2
- 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/helper_spec.rb +3 -3
- 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 +5 -5
- 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 +50 -100
- data/.github/workflows/jest.yml +0 -33
- data/.github/workflows/js-lint.yml +0 -33
- data/.github/workflows/rubocop.yml +0 -28
- data/.github/workflows/ruby-backward-compatibility.yml +0 -51
- 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 -79
- 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/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,13 +82,13 @@ 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
|
|
|
89
89
|
if status.success?
|
|
90
90
|
logger.info "Compiled all packs in #{config.public_output_path}"
|
|
91
|
-
logger.
|
|
91
|
+
logger.warn "#{stderr}" unless stderr.empty?
|
|
92
92
|
|
|
93
93
|
if config.webpack_compile_output?
|
|
94
94
|
logger.info stdout
|
|
@@ -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
|
|
@@ -1,87 +1,9 @@
|
|
|
1
1
|
require "thor"
|
|
2
2
|
|
|
3
3
|
module Shakapacker
|
|
4
|
-
DEPRECATION_GUIDE_URL = "https://github.com/shakacode/shakapacker/blob/master/docs/v7_upgrade.md"
|
|
5
|
-
DEPRECATION_MESSAGE = <<~MSG
|
|
6
|
-
DEPRECATION NOTICE:
|
|
7
|
-
|
|
8
|
-
Using webpacker spelling is deprecated in Shakapacker.
|
|
9
|
-
Update your project with the new spelling.
|
|
10
|
-
|
|
11
|
-
For more information about this process, check:
|
|
12
|
-
#{DEPRECATION_GUIDE_URL}
|
|
13
|
-
MSG
|
|
14
4
|
SHELL = Thor::Shell::Color.new
|
|
15
5
|
|
|
16
|
-
def get_config_file_path_with_backward_compatibility(config_path)
|
|
17
|
-
if config_path.to_s.end_with?("shakapacker.yml") && !File.exist?(config_path)
|
|
18
|
-
webpacker_config_path = if config_path.class == Pathname
|
|
19
|
-
Pathname.new(config_path.to_s.gsub("shakapacker.yml", "webpacker.yml"))
|
|
20
|
-
else
|
|
21
|
-
config_path.gsub("shakapacker.yml", "webpacker.yml")
|
|
22
|
-
end
|
|
23
|
-
|
|
24
|
-
if File.exist?(webpacker_config_path)
|
|
25
|
-
puts_deprecation_message(
|
|
26
|
-
short_deprecation_message(
|
|
27
|
-
"config/webpacker.yml",
|
|
28
|
-
"config/shakapacker.yml"
|
|
29
|
-
)
|
|
30
|
-
)
|
|
31
|
-
return webpacker_config_path
|
|
32
|
-
end
|
|
33
|
-
end
|
|
34
|
-
|
|
35
|
-
config_path
|
|
36
|
-
end
|
|
37
|
-
|
|
38
|
-
def set_shakapacker_env_variables_for_backward_compatibility
|
|
39
|
-
webpacker_env_variables = ENV.select { |key| key.start_with?("WEBPACKER_") }
|
|
40
|
-
|
|
41
|
-
deprecation_message_body = ""
|
|
42
|
-
|
|
43
|
-
webpacker_env_variables.each do |webpacker_key, _|
|
|
44
|
-
shakapacker_key = webpacker_key.gsub("WEBPACKER_", "SHAKAPACKER_")
|
|
45
|
-
next if ENV.key?(shakapacker_key)
|
|
46
|
-
|
|
47
|
-
deprecation_message_body += <<~MSG
|
|
48
|
-
Use `#{shakapacker_key}` instead of the deprecated `#{webpacker_key}`.
|
|
49
|
-
MSG
|
|
50
|
-
|
|
51
|
-
ENV[shakapacker_key] = ENV[webpacker_key]
|
|
52
|
-
end
|
|
53
|
-
|
|
54
|
-
if deprecation_message_body.present?
|
|
55
|
-
Shakapacker.puts_deprecation_message(
|
|
56
|
-
<<~MSG
|
|
57
|
-
DEPRECATION NOTICE:
|
|
58
|
-
|
|
59
|
-
#{deprecation_message_body}
|
|
60
|
-
Read more: #{Shakapacker::DEPRECATION_GUIDE_URL}
|
|
61
|
-
MSG
|
|
62
|
-
)
|
|
63
|
-
end
|
|
64
|
-
end
|
|
65
|
-
|
|
66
|
-
def short_deprecation_message(old_usage, new_usage)
|
|
67
|
-
<<~MSG
|
|
68
|
-
DEPRECATION NOTICE:
|
|
69
|
-
|
|
70
|
-
Consider using `#{new_usage}` instead of the deprecated `#{old_usage}`.
|
|
71
|
-
Read more: #{DEPRECATION_GUIDE_URL}
|
|
72
|
-
MSG
|
|
73
|
-
end
|
|
74
|
-
|
|
75
6
|
def puts_deprecation_message(message)
|
|
76
7
|
SHELL.say "\n#{message}\n", :yellow
|
|
77
8
|
end
|
|
78
|
-
|
|
79
|
-
def puts_rake_deprecation_message(webpacker_task_name)
|
|
80
|
-
Shakapacker.puts_deprecation_message(
|
|
81
|
-
Shakapacker.short_deprecation_message(
|
|
82
|
-
"rake #{webpacker_task_name}",
|
|
83
|
-
"rake #{webpacker_task_name.gsub("webpacker", "shakapacker")}"
|
|
84
|
-
)
|
|
85
|
-
)
|
|
86
|
-
end
|
|
87
9
|
end
|
|
@@ -30,21 +30,6 @@ class Shakapacker::DevServer
|
|
|
30
30
|
fetch(:port)
|
|
31
31
|
end
|
|
32
32
|
|
|
33
|
-
def https?
|
|
34
|
-
value = fetch(:https)
|
|
35
|
-
|
|
36
|
-
unless value.nil?
|
|
37
|
-
puts "WARNING: `https: true` has been deprecated in favor of `server: 'https'`"
|
|
38
|
-
end
|
|
39
|
-
|
|
40
|
-
case value
|
|
41
|
-
when true, "true", Hash
|
|
42
|
-
true
|
|
43
|
-
else
|
|
44
|
-
false
|
|
45
|
-
end
|
|
46
|
-
end
|
|
47
|
-
|
|
48
33
|
def server
|
|
49
34
|
server_value = fetch(:server)
|
|
50
35
|
server_type = server_value.is_a?(Hash) ? server_value[:type] : server_value
|
|
@@ -65,7 +50,7 @@ class Shakapacker::DevServer
|
|
|
65
50
|
end
|
|
66
51
|
|
|
67
52
|
def protocol
|
|
68
|
-
return "https" if server == "https"
|
|
53
|
+
return "https" if server == "https"
|
|
69
54
|
|
|
70
55
|
"http"
|
|
71
56
|
end
|
|
@@ -70,16 +70,7 @@ module Shakapacker
|
|
|
70
70
|
|
|
71
71
|
cmd = build_cmd
|
|
72
72
|
|
|
73
|
-
if @argv.
|
|
74
|
-
Shakapacker.puts_deprecation_message(
|
|
75
|
-
Shakapacker.short_deprecation_message(
|
|
76
|
-
"--debug-webpacker",
|
|
77
|
-
"--debug-shakapacker"
|
|
78
|
-
)
|
|
79
|
-
)
|
|
80
|
-
end
|
|
81
|
-
|
|
82
|
-
if @argv.delete("--debug-shakapacker") || @argv.delete("--debug-webpacker")
|
|
73
|
+
if @argv.delete("--debug-shakapacker")
|
|
83
74
|
env["NODE_OPTIONS"] = "#{env["NODE_OPTIONS"]} --inspect-brk --trace-warnings"
|
|
84
75
|
end
|
|
85
76
|
|
|
@@ -98,17 +89,7 @@ module Shakapacker
|
|
|
98
89
|
end
|
|
99
90
|
|
|
100
91
|
def build_cmd
|
|
101
|
-
|
|
102
|
-
return package_json.manager.native_exec_command("webpack", ["serve"])
|
|
103
|
-
end
|
|
104
|
-
|
|
105
|
-
return ["#{@node_modules_bin_path}/webpack", "serve"] if node_modules_bin_exist?
|
|
106
|
-
|
|
107
|
-
["yarn", "webpack", "serve"]
|
|
108
|
-
end
|
|
109
|
-
|
|
110
|
-
def node_modules_bin_exist?
|
|
111
|
-
File.exist?("#{@node_modules_bin_path}/webpack-dev-server")
|
|
92
|
+
package_json.manager.native_exec_command("webpack", ["serve"])
|
|
112
93
|
end
|
|
113
94
|
end
|
|
114
95
|
end
|
data/lib/shakapacker/env.rb
CHANGED
|
@@ -20,7 +20,7 @@ class Shakapacker::Env
|
|
|
20
20
|
end
|
|
21
21
|
|
|
22
22
|
def fallback_env_warning
|
|
23
|
-
logger.info "RAILS_ENV=#{Rails.env} environment is not defined in
|
|
23
|
+
logger.info "RAILS_ENV=#{Rails.env} environment is not defined in #{config_path}, falling back to #{Shakapacker::DEFAULT_ENV} environment"
|
|
24
24
|
end
|
|
25
25
|
|
|
26
26
|
def available_environments
|
data/lib/shakapacker/helper.rb
CHANGED
|
@@ -98,7 +98,7 @@ module Shakapacker::Helper
|
|
|
98
98
|
def javascript_pack_tag(*names, defer: true, **options)
|
|
99
99
|
if @javascript_pack_tag_loaded
|
|
100
100
|
raise "To prevent duplicated chunks on the page, you should call javascript_pack_tag only once on the page. " \
|
|
101
|
-
"Please refer to https://github.com/shakacode/shakapacker/blob/
|
|
101
|
+
"Please refer to https://github.com/shakacode/shakapacker/blob/main/README.md#view-helpers-javascript_pack_tag-and-stylesheet_pack_tag for the usage guide"
|
|
102
102
|
end
|
|
103
103
|
|
|
104
104
|
append_javascript_pack_tag(*names, defer: defer)
|
|
@@ -169,7 +169,7 @@ module Shakapacker::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/
|
|
172
|
+
"Please refer to https://github.com/shakacode/shakapacker/blob/main/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 ||= []
|
|
@@ -196,7 +196,7 @@ module Shakapacker::Helper
|
|
|
196
196
|
def update_javascript_pack_tag_queue(defer:)
|
|
197
197
|
if @javascript_pack_tag_loaded
|
|
198
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/
|
|
199
|
+
"Please refer to https://github.com/shakacode/shakapacker/blob/main/README.md#view-helper-append_javascript_pack_tag-prepend_javascript_pack_tag-and-append_stylesheet_pack_tag for the usage guide"
|
|
200
200
|
end
|
|
201
201
|
|
|
202
202
|
yield(defer ? :deferred : :non_deferred)
|
data/lib/shakapacker/instance.rb
CHANGED
|
@@ -7,9 +7,7 @@ class Shakapacker::Instance
|
|
|
7
7
|
|
|
8
8
|
def initialize(root_path: Rails.root, config_path: Rails.root.join("config/shakapacker.yml"))
|
|
9
9
|
@root_path = root_path
|
|
10
|
-
|
|
11
|
-
# For backward compatibility
|
|
12
|
-
@config_path = Shakapacker.get_config_file_path_with_backward_compatibility(config_path)
|
|
10
|
+
@config_path = Pathname.new(ENV["SHAKAPACKER_CONFIG"] || config_path)
|
|
13
11
|
end
|
|
14
12
|
|
|
15
13
|
def env
|
data/lib/shakapacker/manifest.rb
CHANGED
|
@@ -105,7 +105,7 @@ class Shakapacker::Manifest
|
|
|
105
105
|
def missing_file_from_manifest_error(bundle_name)
|
|
106
106
|
<<-MSG
|
|
107
107
|
Shakapacker can't find #{bundle_name} in #{config.manifest_path}. Possible causes:
|
|
108
|
-
1. You forgot to install
|
|
108
|
+
1. You forgot to install javascript packages or are running an incompatible javascript runtime version
|
|
109
109
|
2. Your app has code with a non-standard extension (like a `.jsx` file) but the extension is not in the `extensions` config in `config/shakapacker.yml`
|
|
110
110
|
3. You have set compile: false (see `config/shakapacker.yml`) for this environment
|
|
111
111
|
(unless you are using the `bin/shakapacker -w` or the `bin/shakapacker-dev-server`, in which case maybe you aren't running the dev server in the background?)
|
data/lib/shakapacker/railtie.rb
CHANGED
|
@@ -3,6 +3,7 @@ require "rails/railtie"
|
|
|
3
3
|
require "shakapacker/helper"
|
|
4
4
|
require "shakapacker/dev_server_proxy"
|
|
5
5
|
require "shakapacker/version_checker"
|
|
6
|
+
require "shakapacker/utils/manager"
|
|
6
7
|
|
|
7
8
|
class Shakapacker::Engine < ::Rails::Engine
|
|
8
9
|
# Allows Shakapacker config values to be set via Rails env config files
|
|
@@ -14,6 +15,12 @@ class Shakapacker::Engine < ::Rails::Engine
|
|
|
14
15
|
end
|
|
15
16
|
end
|
|
16
17
|
|
|
18
|
+
initializer "shakapacker.manager_checker" do
|
|
19
|
+
if File.exist?(Shakapacker::VersionChecker::NodePackageVersion.package_json_path)
|
|
20
|
+
Shakapacker::Utils::Manager.error_unless_package_manager_is_obvious!
|
|
21
|
+
end
|
|
22
|
+
end
|
|
23
|
+
|
|
17
24
|
initializer "shakapacker.proxy" do |app|
|
|
18
25
|
if (Shakapacker.config.dev_server.present? rescue nil)
|
|
19
26
|
app.middleware.insert_before 0,
|
data/lib/shakapacker/runner.rb
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
require "shakapacker/utils/misc"
|
|
2
|
+
require "shakapacker/utils/manager"
|
|
3
|
+
require "package_json"
|
|
2
4
|
|
|
3
5
|
module Shakapacker
|
|
4
6
|
class Runner
|
|
@@ -13,34 +15,18 @@ module Shakapacker
|
|
|
13
15
|
|
|
14
16
|
@app_path = File.expand_path(".", Dir.pwd)
|
|
15
17
|
@webpack_config = File.join(@app_path, "config/webpack/webpack.config.js")
|
|
16
|
-
|
|
17
|
-
Shakapacker.set_shakapacker_env_variables_for_backward_compatibility
|
|
18
|
-
|
|
19
|
-
@node_modules_bin_path = fetch_node_modules_bin_path
|
|
20
18
|
@shakapacker_config = ENV["SHAKAPACKER_CONFIG"] || File.join(@app_path, "config/shakapacker.yml")
|
|
21
19
|
|
|
22
|
-
@shakapacker_config = Shakapacker.get_config_file_path_with_backward_compatibility(@shakapacker_config)
|
|
23
|
-
|
|
24
20
|
unless File.exist?(@webpack_config)
|
|
25
21
|
$stderr.puts "webpack config #{@webpack_config} not found, please run 'bundle exec rails shakapacker:install' to install Shakapacker with default configs or add the missing config file for your custom environment."
|
|
26
22
|
exit!
|
|
27
23
|
end
|
|
28
|
-
end
|
|
29
24
|
|
|
30
|
-
|
|
31
|
-
return nil if Shakapacker::Utils::Misc.use_package_json_gem
|
|
32
|
-
|
|
33
|
-
ENV["SHAKAPACKER_NODE_MODULES_BIN_PATH"] || `yarn bin`.chomp
|
|
25
|
+
Shakapacker::Utils::Manager.error_unless_package_manager_is_obvious!
|
|
34
26
|
end
|
|
35
27
|
|
|
36
28
|
def package_json
|
|
37
|
-
|
|
38
|
-
Shakapacker::Utils::Misc.require_package_json_gem
|
|
39
|
-
|
|
40
|
-
@package_json = PackageJson.read(@app_path)
|
|
41
|
-
end
|
|
42
|
-
|
|
43
|
-
@package_json
|
|
29
|
+
@package_json ||= PackageJson.read(@app_path)
|
|
44
30
|
end
|
|
45
31
|
end
|
|
46
32
|
end
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require "package_json"
|
|
4
|
+
|
|
5
|
+
module Shakapacker
|
|
6
|
+
module Utils
|
|
7
|
+
class Manager
|
|
8
|
+
class Error < StandardError; end
|
|
9
|
+
|
|
10
|
+
MANAGER_LOCKS = {
|
|
11
|
+
"bun" => "bun.lockb",
|
|
12
|
+
"npm" => "package-lock.json",
|
|
13
|
+
"pnpm" => "pnpm-lock.yaml",
|
|
14
|
+
"yarn" => "yarn.lock"
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
# Emits a warning if it's not obvious what package manager to use
|
|
18
|
+
def self.error_unless_package_manager_is_obvious!
|
|
19
|
+
return unless PackageJson.read.fetch("packageManager", nil).nil?
|
|
20
|
+
|
|
21
|
+
guessed_binary = guess_binary
|
|
22
|
+
|
|
23
|
+
return if guessed_binary == "npm"
|
|
24
|
+
|
|
25
|
+
raise Error, <<~MSG
|
|
26
|
+
You don't have "packageManager" set in your package.json
|
|
27
|
+
meaning that Shakapacker will use npm but you've got a #{MANAGER_LOCKS[guessed_binary]}
|
|
28
|
+
file meaning you probably want to be using #{guessed_binary} instead.
|
|
29
|
+
|
|
30
|
+
To make this happen, set "packageManager" in your package.json to #{guessed_binary}@#{guess_version}
|
|
31
|
+
MSG
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
# Guesses the binary of the package manager to use based on what lockfiles exist
|
|
35
|
+
#
|
|
36
|
+
# @return [String]
|
|
37
|
+
def self.guess_binary
|
|
38
|
+
MANAGER_LOCKS.find { |_, lock| File.exist?(lock) }&.first || "npm"
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
# Guesses the version of the package manager to use by calling `<manager> --version`
|
|
42
|
+
#
|
|
43
|
+
# @return [String]
|
|
44
|
+
def self.guess_version
|
|
45
|
+
require "open3"
|
|
46
|
+
|
|
47
|
+
command = "#{guess_binary} --version"
|
|
48
|
+
stdout, stderr, status = Open3.capture3(command)
|
|
49
|
+
|
|
50
|
+
unless status.success?
|
|
51
|
+
raise Error, "#{command} failed with exit code #{status.exitstatus}: #{stderr}"
|
|
52
|
+
end
|
|
53
|
+
|
|
54
|
+
stdout.chomp
|
|
55
|
+
end
|
|
56
|
+
end
|
|
57
|
+
end
|
|
58
|
+
end
|
|
@@ -8,18 +8,6 @@ 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
|
-
|
|
23
11
|
def self.uncommitted_changes?(message_handler)
|
|
24
12
|
return false if ENV["COVERAGE"] == "true"
|
|
25
13
|
|
data/lib/shakapacker/version.rb
CHANGED