shakapacker 6.6.0 → 7.0.0.rc.0
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/.github/workflows/ruby-backward-compatibility.yml +43 -0
- data/CHANGELOG.md +50 -4
- data/CONTRIBUTING.md +4 -4
- data/Gemfile.development_dependencies +1 -1
- data/README.md +113 -88
- data/Rakefile +5 -0
- data/config/shakapacker.yml +1 -0
- data/docs/deployment.md +12 -10
- data/docs/developing_webpacker.md +5 -5
- data/docs/react.md +10 -6
- data/docs/style_loader_vs_mini_css.md +2 -2
- data/docs/troubleshooting.md +22 -18
- data/docs/using_esbuild_loader.md +5 -3
- data/docs/using_swc_loader.md +2 -2
- data/docs/v6_upgrade.md +2 -2
- data/docs/v7_upgrade.md +56 -0
- data/lib/install/bin/shakapacker +13 -0
- data/lib/install/bin/shakapacker-dev-server +13 -0
- data/lib/install/config/{webpacker.yml → shakapacker.yml} +13 -8
- data/lib/install/template.rb +7 -7
- data/lib/{webpacker → shakapacker}/base_strategy.rb +2 -2
- data/lib/{webpacker → shakapacker}/commands.rb +4 -4
- data/lib/{webpacker → shakapacker}/compiler.rb +43 -15
- data/lib/{webpacker → shakapacker}/compiler_strategy.rb +6 -6
- data/lib/{webpacker → shakapacker}/configuration.rb +52 -21
- data/lib/shakapacker/deprecation_helper.rb +88 -0
- data/lib/{webpacker → shakapacker}/dev_server.rb +27 -4
- data/lib/{webpacker → shakapacker}/dev_server_proxy.rb +4 -4
- data/lib/shakapacker/dev_server_runner.rb +104 -0
- data/lib/{webpacker → shakapacker}/digest_strategy.rb +6 -6
- data/lib/{webpacker → shakapacker}/env.rb +8 -8
- data/lib/{webpacker → shakapacker}/helper.rb +20 -20
- data/lib/{webpacker → shakapacker}/instance.rb +13 -10
- data/lib/{webpacker → shakapacker}/manifest.rb +14 -14
- data/lib/{webpacker → shakapacker}/mtime_strategy.rb +5 -5
- data/lib/shakapacker/railtie.rb +70 -0
- data/lib/shakapacker/runner.rb +28 -0
- data/lib/shakapacker/utils/version_syntax_converter.rb +2 -2
- data/lib/{webpacker → shakapacker}/version.rb +2 -2
- data/lib/{webpacker → shakapacker}/version_checker.rb +8 -8
- data/lib/shakapacker/webpack_runner.rb +67 -0
- data/lib/shakapacker.rb +51 -1
- data/lib/tasks/shakapacker/binstubs.rake +15 -0
- data/lib/tasks/shakapacker/check_binstubs.rake +25 -0
- data/lib/tasks/shakapacker/check_node.rake +31 -0
- data/lib/tasks/shakapacker/check_yarn.rake +33 -0
- data/lib/tasks/shakapacker/clean.rake +23 -0
- data/lib/tasks/shakapacker/clobber.rake +18 -0
- data/lib/tasks/shakapacker/compile.rake +31 -0
- data/lib/tasks/shakapacker/info.rake +21 -0
- data/lib/tasks/shakapacker/install.rake +17 -0
- data/lib/tasks/shakapacker/verify_config.rake +12 -0
- data/lib/tasks/shakapacker/verify_install.rake +4 -0
- data/lib/tasks/shakapacker/yarn_install.rake +24 -0
- data/lib/tasks/shakapacker.rake +18 -0
- data/lib/tasks/webpacker/binstubs.rake +5 -11
- data/lib/tasks/webpacker/check_binstubs.rake +6 -9
- data/lib/tasks/webpacker/check_node.rake +5 -27
- data/lib/tasks/webpacker/check_yarn.rake +5 -29
- data/lib/tasks/webpacker/clean.rake +5 -19
- data/lib/tasks/webpacker/clobber.rake +6 -13
- data/lib/tasks/webpacker/compile.rake +5 -33
- data/lib/tasks/webpacker/info.rake +5 -17
- data/lib/tasks/webpacker/install.rake +5 -13
- data/lib/tasks/webpacker/verify_config.rake +6 -11
- data/lib/tasks/webpacker/verify_install.rake +7 -2
- data/lib/tasks/webpacker/yarn_install.rake +5 -20
- data/lib/tasks/webpacker.rake +15 -13
- data/lib/webpacker/dev_server_runner.rb +9 -96
- data/lib/webpacker/webpack_runner.rb +9 -58
- data/lib/webpacker.rb +3 -47
- data/package/__tests__/config-bc.js +27 -0
- data/package/__tests__/config.js +6 -5
- data/package/__tests__/dev_server-bc.js +46 -0
- data/package/__tests__/dev_server.js +9 -8
- data/package/__tests__/development-bc.js +66 -0
- data/package/__tests__/development.js +36 -5
- data/package/__tests__/env-bc.js +59 -0
- data/package/__tests__/env.js +3 -2
- data/package/__tests__/index.js +13 -0
- data/package/__tests__/production-bc.js +51 -0
- data/package/__tests__/production.js +25 -3
- data/package/__tests__/staging-bc.js +53 -0
- data/package/__tests__/staging.js +27 -4
- data/package/__tests__/test-bc.js +43 -0
- data/package/__tests__/test.js +22 -4
- data/package/babel/preset.js +1 -4
- data/package/config.js +25 -7
- data/package/dev_server.js +7 -4
- data/package/env.js +22 -3
- data/package/environments/__tests__/base-bc.js +107 -0
- data/package/environments/__tests__/base.js +13 -13
- data/package/environments/base.js +1 -1
- data/package/environments/development.js +4 -46
- data/package/environments/production.js +1 -1
- data/package/index.js +11 -4
- data/package/rules/__tests__/__utils__/webpack.js +1 -1
- data/package/rules/__tests__/file.js +27 -0
- data/package/rules/__tests__/swc.js +1 -2
- data/package/rules/file.js +2 -2
- data/package/utils/configPath.js +19 -0
- data/package/utils/defaultConfigPath.js +2 -0
- data/package/utils/get_style_rule.js +5 -2
- data/package/utils/helpers.js +24 -1
- data/package/utils/inliningCss.js +7 -0
- data/package/utils/snakeToCamelCase +7 -0
- data/package/webpackDevServerConfig.js +68 -0
- data/package.json +2 -2
- data/{webpacker.gemspec → shakapacker.gemspec} +3 -3
- data/spec/backward_compatibility_specs/command_spec_bc.rb +116 -0
- data/spec/backward_compatibility_specs/compiler_spec_bc.rb +59 -0
- data/spec/backward_compatibility_specs/compiler_strategy_spec_bc.rb +22 -0
- data/spec/backward_compatibility_specs/configuration_spec_bc.rb +286 -0
- data/spec/backward_compatibility_specs/dev_server_runner_spec_bc.rb +79 -0
- data/spec/backward_compatibility_specs/dev_server_spec_bc.rb +47 -0
- data/spec/backward_compatibility_specs/digest_strategy_spec_bc.rb +35 -0
- data/spec/backward_compatibility_specs/engine_rake_tasks_spec_bc.rb +44 -0
- data/spec/backward_compatibility_specs/env_spec_bc.rb +23 -0
- data/spec/backward_compatibility_specs/helper_spec_bc.rb +243 -0
- data/spec/backward_compatibility_specs/instance_spec_bc.rb +31 -0
- data/spec/backward_compatibility_specs/manifest_spec_bc.rb +100 -0
- data/spec/backward_compatibility_specs/mtime_strategy_spec_bc.rb +55 -0
- data/spec/backward_compatibility_specs/rake_tasks_spec_bc.rb +37 -0
- data/spec/backward_compatibility_specs/spec_helper_initializer.rb +24 -0
- data/spec/backward_compatibility_specs/webpack_runner_spec_bc.rb +56 -0
- data/spec/backward_compatibility_specs/webpacker_spec_bc.rb +41 -0
- data/spec/backward_compatibility_specs/webpacker_test_app/.gitignore +2 -0
- data/spec/backward_compatibility_specs/webpacker_test_app/Rakefile +3 -0
- data/spec/{test_app → backward_compatibility_specs/webpacker_test_app}/app/packs/entrypoints/application.js +1 -1
- data/{lib/install → spec/backward_compatibility_specs/webpacker_test_app}/bin/webpacker +0 -0
- data/spec/backward_compatibility_specs/webpacker_test_app/config/application.rb +11 -0
- data/spec/backward_compatibility_specs/webpacker_test_app/config/environment.rb +4 -0
- data/spec/backward_compatibility_specs/webpacker_test_app/config/initializers/inspect_autoload_paths.rb +1 -0
- data/spec/backward_compatibility_specs/webpacker_test_app/config/webpack/webpack.config.js +0 -0
- data/spec/{test_app → backward_compatibility_specs/webpacker_test_app}/config/webpacker.yml +1 -1
- data/spec/{test_app → backward_compatibility_specs/webpacker_test_app}/config/webpacker_css_extract_ignore_order_warnings.yml +1 -1
- data/spec/{test_app → backward_compatibility_specs/webpacker_test_app}/config/webpacker_defaults_fallback.yml +1 -1
- data/spec/backward_compatibility_specs/webpacker_test_app/config/webpacker_no_precompile.yml +7 -0
- data/spec/{test_app → backward_compatibility_specs/webpacker_test_app}/config/webpacker_other_location.yml +1 -1
- data/spec/{test_app → backward_compatibility_specs/webpacker_test_app}/config/webpacker_public_root.yml +1 -1
- data/spec/backward_compatibility_specs/webpacker_test_app/config.ru +5 -0
- data/spec/backward_compatibility_specs/webpacker_test_app/package.json +13 -0
- data/spec/backward_compatibility_specs/webpacker_test_app/public/packs/manifest.json +58 -0
- 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 +1 -0
- data/spec/backward_compatibility_specs/webpacker_test_app/yarn.lock +11 -0
- data/spec/command_spec.rb +18 -16
- data/spec/compiler_spec.rb +19 -17
- data/spec/compiler_strategy_spec.rb +9 -7
- data/spec/configuration_spec.rb +108 -66
- data/spec/dev_server_runner_spec.rb +9 -8
- data/spec/dev_server_spec.rb +97 -9
- data/spec/digest_strategy_spec.rb +4 -2
- data/spec/engine_rake_tasks_spec.rb +12 -16
- data/spec/env_spec.rb +7 -5
- data/spec/helper_spec.rb +4 -2
- data/spec/instance_spec.rb +31 -0
- data/spec/manifest_spec.rb +21 -19
- data/spec/mounted_app/test/dummy/config/application.rb +1 -1
- data/spec/mounted_app/test/dummy/config/webpacker.yml +3 -3
- data/spec/mtime_strategy_spec.rb +4 -2
- data/spec/rake_tasks_spec.rb +20 -18
- data/spec/spec_helper.rb +0 -25
- data/spec/spec_helper_initializer.rb +24 -0
- data/spec/test_app/.gitignore +2 -0
- data/spec/test_app/app/javascript/entrypoints/application.js +10 -0
- data/spec/test_app/app/javascript/entrypoints/generated/something.js +2 -0
- data/spec/test_app/app/javascript/entrypoints/multi_entry.css +4 -0
- data/spec/test_app/app/javascript/entrypoints/multi_entry.js +4 -0
- data/spec/test_app/bin/{webpacker-dev-server → shakapacker} +3 -3
- data/spec/test_app/bin/{webpacker → shakapacker-dev-server} +3 -3
- data/spec/test_app/config/application.rb +1 -1
- data/spec/test_app/config/shakapacker.yml +82 -0
- data/spec/test_app/config/shakapacker_css_extract_ignore_order_warnings.yml +84 -0
- data/spec/test_app/config/shakapacker_defaults_fallback.yml +11 -0
- data/spec/test_app/config/shakapacker_manifest_path.yml +80 -0
- data/spec/test_app/config/shakapacker_nested_entries.yml +83 -0
- data/spec/test_app/config/shakapacker_no_precompile.yml +7 -0
- data/spec/test_app/config/shakapacker_other_location.yml +85 -0
- data/spec/test_app/config/shakapacker_public_root.yml +18 -0
- data/spec/version_checker_spec.rb +16 -15
- data/spec/webpack_runner_spec.rb +4 -3
- data/spec/webpacker_spec.rb +9 -29
- metadata +119 -44
- data/config/webpacker.yml +0 -1
- data/lib/webpacker/railtie.rb +0 -70
- data/lib/webpacker/runner.rb +0 -23
- data/package/configPath.js +0 -3
- data/package/inliningCss.js +0 -7
- data/spec/test_app/config/webpacker_no_precompile.yml +0 -7
- /data/spec/{test_app → backward_compatibility_specs/webpacker_test_app}/app/packs/entrypoints/generated/something.js +0 -0
- /data/spec/{test_app → backward_compatibility_specs/webpacker_test_app}/app/packs/entrypoints/multi_entry.css +0 -0
- /data/spec/{test_app → backward_compatibility_specs/webpacker_test_app}/app/packs/entrypoints/multi_entry.js +0 -0
- /data/{lib/install → spec/backward_compatibility_specs/webpacker_test_app}/bin/webpacker-dev-server +0 -0
- /data/spec/{test_app → backward_compatibility_specs/webpacker_test_app}/config/webpacker_manifest_path.yml +0 -0
- /data/spec/{test_app → backward_compatibility_specs/webpacker_test_app}/config/webpacker_nested_entries.yml +0 -0
|
@@ -2,7 +2,7 @@ require "yaml"
|
|
|
2
2
|
require "active_support/core_ext/hash/keys"
|
|
3
3
|
require "active_support/core_ext/hash/indifferent_access"
|
|
4
4
|
|
|
5
|
-
class
|
|
5
|
+
class Shakapacker::Configuration
|
|
6
6
|
class << self
|
|
7
7
|
attr_accessor :installing
|
|
8
8
|
end
|
|
@@ -11,8 +11,11 @@ class Webpacker::Configuration
|
|
|
11
11
|
|
|
12
12
|
def initialize(root_path:, config_path:, env:)
|
|
13
13
|
@root_path = root_path
|
|
14
|
-
@config_path = config_path
|
|
15
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)
|
|
16
19
|
end
|
|
17
20
|
|
|
18
21
|
def dev_server
|
|
@@ -31,13 +34,24 @@ class Webpacker::Configuration
|
|
|
31
34
|
fetch(:ensure_consistent_versioning)
|
|
32
35
|
end
|
|
33
36
|
|
|
34
|
-
def
|
|
37
|
+
def shakapacker_precompile?
|
|
35
38
|
# ENV of false takes precedence
|
|
36
|
-
return false if %w(no false n f).include?(ENV["
|
|
37
|
-
return true if %w(yes true y t).include?(ENV["
|
|
39
|
+
return false if %w(no false n f).include?(ENV["SHAKAPACKER_PRECOMPILE"])
|
|
40
|
+
return true if %w(yes true y t).include?(ENV["SHAKAPACKER_PRECOMPILE"])
|
|
38
41
|
|
|
39
42
|
return false unless config_path.exist?
|
|
40
|
-
fetch(:
|
|
43
|
+
fetch(:shakapacker_precompile)
|
|
44
|
+
end
|
|
45
|
+
|
|
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?
|
|
41
55
|
end
|
|
42
56
|
|
|
43
57
|
def source_path
|
|
@@ -49,7 +63,7 @@ class Webpacker::Configuration
|
|
|
49
63
|
end
|
|
50
64
|
|
|
51
65
|
def source_entry_path
|
|
52
|
-
source_path.join(fetch(:source_entry_path))
|
|
66
|
+
source_path.join(relative_path(fetch(:source_entry_path)))
|
|
53
67
|
end
|
|
54
68
|
|
|
55
69
|
def manifest_path
|
|
@@ -80,14 +94,6 @@ class Webpacker::Configuration
|
|
|
80
94
|
root_path.join(fetch(:cache_path))
|
|
81
95
|
end
|
|
82
96
|
|
|
83
|
-
def check_yarn_integrity=(value)
|
|
84
|
-
warn <<~EOS
|
|
85
|
-
Webpacker::Configuration#check_yarn_integrity=(value) is obsolete. The integrity
|
|
86
|
-
check has been removed from Webpacker (https://github.com/rails/webpacker/pull/2518)
|
|
87
|
-
so changing this setting will have no effect.
|
|
88
|
-
EOS
|
|
89
|
-
end
|
|
90
|
-
|
|
91
97
|
def webpack_compile_output?
|
|
92
98
|
fetch(:webpack_compile_output)
|
|
93
99
|
end
|
|
@@ -97,7 +103,17 @@ class Webpacker::Configuration
|
|
|
97
103
|
end
|
|
98
104
|
|
|
99
105
|
def fetch(key)
|
|
100
|
-
data.fetch(key, defaults[key])
|
|
106
|
+
return data.fetch(key, defaults[key]) unless key == :webpacker_precompile
|
|
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])
|
|
101
117
|
end
|
|
102
118
|
|
|
103
119
|
private
|
|
@@ -111,13 +127,22 @@ class Webpacker::Configuration
|
|
|
111
127
|
rescue ArgumentError
|
|
112
128
|
YAML.load_file(config_path.to_s)
|
|
113
129
|
end
|
|
114
|
-
config[env].deep_symbolize_keys
|
|
130
|
+
symbolized_config = config[env].deep_symbolize_keys
|
|
131
|
+
|
|
132
|
+
# For backward compatibility
|
|
133
|
+
if symbolized_config.key?(:shakapacker_precompile) && !symbolized_config.key?(:webpacker_precompile)
|
|
134
|
+
symbolized_config[:webpacker_precompile] = symbolized_config[:shakapacker_precompile]
|
|
135
|
+
elsif !symbolized_config.key?(:shakapacker_precompile) && symbolized_config.key?(:webpacker_precompile)
|
|
136
|
+
symbolized_config[:shakapacker_precompile] = symbolized_config[:webpacker_precompile]
|
|
137
|
+
end
|
|
138
|
+
|
|
139
|
+
return symbolized_config
|
|
115
140
|
rescue Errno::ENOENT => e
|
|
116
141
|
if self.class.installing
|
|
117
142
|
{}
|
|
118
143
|
else
|
|
119
|
-
raise "
|
|
120
|
-
"Please run rails
|
|
144
|
+
raise "Shakapacker configuration file not found #{config_path}. " \
|
|
145
|
+
"Please run rails shakapacker:install " \
|
|
121
146
|
"Error: #{e.message}"
|
|
122
147
|
end
|
|
123
148
|
rescue Psych::SyntaxError => e
|
|
@@ -128,13 +153,19 @@ class Webpacker::Configuration
|
|
|
128
153
|
|
|
129
154
|
def defaults
|
|
130
155
|
@defaults ||= begin
|
|
131
|
-
path = File.expand_path("../../install/config/
|
|
156
|
+
path = File.expand_path("../../install/config/shakapacker.yml", __FILE__)
|
|
132
157
|
config = begin
|
|
133
158
|
YAML.load_file(path, aliases: true)
|
|
134
159
|
rescue ArgumentError
|
|
135
160
|
YAML.load_file(path)
|
|
136
161
|
end
|
|
137
|
-
HashWithIndifferentAccess.new(config[env] || config[
|
|
162
|
+
HashWithIndifferentAccess.new(config[env] || config[Shakapacker::DEFAULT_ENV])
|
|
138
163
|
end
|
|
139
164
|
end
|
|
165
|
+
|
|
166
|
+
def relative_path(path)
|
|
167
|
+
return ".#{path}" if path.start_with?("/")
|
|
168
|
+
|
|
169
|
+
path
|
|
170
|
+
end
|
|
140
171
|
end
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
module Shakapacker
|
|
2
|
+
DEPRECATION_GUIDE_URL = "https://github.com/shakacode/shakapacker/docs/v7_upgrade.md"
|
|
3
|
+
DEPRECATION_MESSAGE = <<~MSG
|
|
4
|
+
DEPRECATION NOTICE:
|
|
5
|
+
|
|
6
|
+
Using webpacker spelling is deprecated in Shakapacker.
|
|
7
|
+
Update your project with the new spelling.
|
|
8
|
+
|
|
9
|
+
For more information about this process, check:
|
|
10
|
+
#{DEPRECATION_GUIDE_URL}
|
|
11
|
+
MSG
|
|
12
|
+
|
|
13
|
+
def get_config_file_path_with_backward_compatibility(config_path)
|
|
14
|
+
if config_path.to_s.end_with?("shakapacker.yml") && !File.exist?(config_path)
|
|
15
|
+
webpacker_config_path = if config_path.class == Pathname
|
|
16
|
+
Pathname.new(config_path.to_s.gsub("shakapacker.yml", "webpacker.yml"))
|
|
17
|
+
else
|
|
18
|
+
config_path.gsub("shakapacker.yml", "webpacker.yml")
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
if File.exist?(webpacker_config_path)
|
|
22
|
+
puts_deprecation_message(
|
|
23
|
+
short_deprecation_message(
|
|
24
|
+
"config/webpacker.yml",
|
|
25
|
+
"config/shakapacker.yml"
|
|
26
|
+
)
|
|
27
|
+
)
|
|
28
|
+
return webpacker_config_path
|
|
29
|
+
end
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
config_path
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
def set_shakapacker_env_variables_for_backward_compatibility
|
|
36
|
+
webpacker_env_variables = ENV.select { |key| key.start_with?("WEBPACKER_") }
|
|
37
|
+
|
|
38
|
+
deprecation_message_body = ""
|
|
39
|
+
|
|
40
|
+
webpacker_env_variables.each do |webpacker_key, _|
|
|
41
|
+
shakapacker_key = webpacker_key.gsub("WEBPACKER_", "SHAKAPACKER_")
|
|
42
|
+
next if ENV.key?(shakapacker_key)
|
|
43
|
+
|
|
44
|
+
deprecation_message_body += <<~MSG
|
|
45
|
+
Use `#{shakapacker_key}` instead of the deprecated `#{webpacker_key}`.
|
|
46
|
+
MSG
|
|
47
|
+
|
|
48
|
+
ENV[shakapacker_key] = ENV[webpacker_key]
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
if deprecation_message_body.present?
|
|
52
|
+
Shakapacker.puts_deprecation_message(
|
|
53
|
+
<<~MSG
|
|
54
|
+
DEPRECATION NOTICE:
|
|
55
|
+
|
|
56
|
+
#{deprecation_message_body}
|
|
57
|
+
Read more: #{Shakapacker::DEPRECATION_GUIDE_URL}
|
|
58
|
+
MSG
|
|
59
|
+
)
|
|
60
|
+
end
|
|
61
|
+
end
|
|
62
|
+
|
|
63
|
+
def short_deprecation_message(old_usage, new_usage)
|
|
64
|
+
<<~MSG
|
|
65
|
+
DEPRECATION NOTICE:
|
|
66
|
+
|
|
67
|
+
Consider using `#{new_usage}` instead of the deprecated `#{old_usage}`.
|
|
68
|
+
Read more: #{DEPRECATION_GUIDE_URL}
|
|
69
|
+
MSG
|
|
70
|
+
end
|
|
71
|
+
|
|
72
|
+
def puts_deprecation_message(message)
|
|
73
|
+
puts <<~MSG
|
|
74
|
+
\e[33m
|
|
75
|
+
#{message}
|
|
76
|
+
\e[0m
|
|
77
|
+
MSG
|
|
78
|
+
end
|
|
79
|
+
|
|
80
|
+
def puts_rake_deprecation_message(webpacker_task_name)
|
|
81
|
+
Shakapacker.puts_deprecation_message(
|
|
82
|
+
Shakapacker.short_deprecation_message(
|
|
83
|
+
"rake #{webpacker_task_name}",
|
|
84
|
+
"rake #{webpacker_task_name.gsub("webpacker", "shakapacker")}"
|
|
85
|
+
)
|
|
86
|
+
)
|
|
87
|
+
end
|
|
88
|
+
end
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
class
|
|
2
|
-
DEFAULT_ENV_PREFIX = "
|
|
1
|
+
class Shakapacker::DevServer
|
|
2
|
+
DEFAULT_ENV_PREFIX = "SHAKAPACKER_DEV_SERVER".freeze
|
|
3
3
|
|
|
4
4
|
# Configure dev server connection timeout (in seconds), default: 0.1
|
|
5
|
-
#
|
|
5
|
+
# Shakapacker.dev_server.connect_timeout = 1
|
|
6
6
|
cattr_accessor(:connect_timeout) { 0.1 }
|
|
7
7
|
|
|
8
8
|
attr_reader :config
|
|
@@ -39,8 +39,29 @@ class Webpacker::DevServer
|
|
|
39
39
|
end
|
|
40
40
|
end
|
|
41
41
|
|
|
42
|
+
def server
|
|
43
|
+
server_value = fetch(:server)
|
|
44
|
+
server_type = server_value.is_a?(Hash) ? server_value[:type] : server_value
|
|
45
|
+
|
|
46
|
+
return server_type if ["http", "https"].include?(server_type)
|
|
47
|
+
|
|
48
|
+
return "http" if server_type.nil?
|
|
49
|
+
|
|
50
|
+
puts <<~MSG
|
|
51
|
+
WARNING:
|
|
52
|
+
`server: #{server_type}` is not a valid configuration in Shakapacker.
|
|
53
|
+
Falling back to default `server: http`.
|
|
54
|
+
MSG
|
|
55
|
+
|
|
56
|
+
"http"
|
|
57
|
+
rescue KeyError
|
|
58
|
+
"http"
|
|
59
|
+
end
|
|
60
|
+
|
|
42
61
|
def protocol
|
|
43
|
-
https
|
|
62
|
+
return "https" if server == "https" || https? == true
|
|
63
|
+
|
|
64
|
+
"http"
|
|
44
65
|
end
|
|
45
66
|
|
|
46
67
|
def host_with_port
|
|
@@ -73,6 +94,8 @@ class Webpacker::DevServer
|
|
|
73
94
|
return nil unless config.dev_server.present?
|
|
74
95
|
|
|
75
96
|
ENV["#{env_prefix}_#{key.upcase}"] || config.dev_server.fetch(key, defaults[key])
|
|
97
|
+
rescue
|
|
98
|
+
nil
|
|
76
99
|
end
|
|
77
100
|
|
|
78
101
|
def defaults
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
require "rack/proxy"
|
|
2
2
|
|
|
3
|
-
class
|
|
4
|
-
delegate :config, :dev_server, to: :@
|
|
3
|
+
class Shakapacker::DevServerProxy < Rack::Proxy
|
|
4
|
+
delegate :config, :dev_server, to: :@instance
|
|
5
5
|
|
|
6
6
|
def initialize(app = nil, opts = {})
|
|
7
|
-
@
|
|
7
|
+
@instance = opts.delete(:shakapacker) || Shakapacker.instance
|
|
8
8
|
opts[:streaming] = false if Rails.env.test? && !opts.key?(:streaming)
|
|
9
9
|
super
|
|
10
10
|
end
|
|
@@ -15,7 +15,7 @@ class Webpacker::DevServerProxy < Rack::Proxy
|
|
|
15
15
|
env["HTTP_X_FORWARDED_SERVER"] = dev_server.host_with_port
|
|
16
16
|
env["HTTP_PORT"] = env["HTTP_X_FORWARDED_PORT"] = dev_server.port.to_s
|
|
17
17
|
env["HTTP_X_FORWARDED_PROTO"] = env["HTTP_X_FORWARDED_SCHEME"] = dev_server.protocol
|
|
18
|
-
unless dev_server.https
|
|
18
|
+
unless dev_server.protocol == "https"
|
|
19
19
|
env["HTTPS"] = env["HTTP_X_FORWARDED_SSL"] = "off"
|
|
20
20
|
end
|
|
21
21
|
env["SCRIPT_NAME"] = ""
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
require "shellwords"
|
|
2
|
+
require "socket"
|
|
3
|
+
require "shakapacker/configuration"
|
|
4
|
+
require "shakapacker/dev_server"
|
|
5
|
+
require "shakapacker/runner"
|
|
6
|
+
|
|
7
|
+
module Shakapacker
|
|
8
|
+
class DevServerRunner < Shakapacker::Runner
|
|
9
|
+
def run
|
|
10
|
+
load_config
|
|
11
|
+
detect_unsupported_switches!
|
|
12
|
+
detect_port!
|
|
13
|
+
execute_cmd
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
private
|
|
17
|
+
|
|
18
|
+
def load_config
|
|
19
|
+
app_root = Pathname.new(@app_path)
|
|
20
|
+
|
|
21
|
+
@config = Configuration.new(
|
|
22
|
+
root_path: app_root,
|
|
23
|
+
config_path: Pathname.new(@shakapacker_config),
|
|
24
|
+
env: ENV["RAILS_ENV"]
|
|
25
|
+
)
|
|
26
|
+
|
|
27
|
+
dev_server = DevServer.new(@config)
|
|
28
|
+
|
|
29
|
+
@hostname = dev_server.host
|
|
30
|
+
@port = dev_server.port
|
|
31
|
+
@pretty = dev_server.pretty?
|
|
32
|
+
@https = dev_server.protocol == "https"
|
|
33
|
+
@hot = dev_server.hmr?
|
|
34
|
+
|
|
35
|
+
rescue Errno::ENOENT, NoMethodError
|
|
36
|
+
$stdout.puts "webpack 'dev_server' configuration not found in #{@config.config_path}[#{ENV["RAILS_ENV"]}]."
|
|
37
|
+
$stdout.puts "Please run bundle exec rails shakapacker:install to install Shakapacker"
|
|
38
|
+
exit!
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
UNSUPPORTED_SWITCHES = %w[--host --port]
|
|
42
|
+
private_constant :UNSUPPORTED_SWITCHES
|
|
43
|
+
def detect_unsupported_switches!
|
|
44
|
+
unsupported_switches = UNSUPPORTED_SWITCHES & @argv
|
|
45
|
+
if unsupported_switches.any?
|
|
46
|
+
$stdout.puts "The following CLI switches are not supported by Shakapacker: #{unsupported_switches.join(' ')}. Please edit your command and try again."
|
|
47
|
+
exit!
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
if @argv.include?("--https") && !@https
|
|
51
|
+
$stdout.puts "Please set https: true in shakapacker.yml to use the --https command line flag."
|
|
52
|
+
exit!
|
|
53
|
+
end
|
|
54
|
+
end
|
|
55
|
+
|
|
56
|
+
def detect_port!
|
|
57
|
+
server = TCPServer.new(@hostname, @port)
|
|
58
|
+
server.close
|
|
59
|
+
|
|
60
|
+
rescue Errno::EADDRINUSE
|
|
61
|
+
$stdout.puts "Another program is running on port #{@port}. Set a new port in #{@config.config_path} for dev_server"
|
|
62
|
+
exit!
|
|
63
|
+
end
|
|
64
|
+
|
|
65
|
+
def execute_cmd
|
|
66
|
+
env = Shakapacker::Compiler.env
|
|
67
|
+
env["SHAKAPACKER_CONFIG"] = @shakapacker_config
|
|
68
|
+
env["WEBPACK_SERVE"] = "true"
|
|
69
|
+
|
|
70
|
+
cmd = if node_modules_bin_exist?
|
|
71
|
+
["#{@node_modules_bin_path}/webpack", "serve"]
|
|
72
|
+
else
|
|
73
|
+
["yarn", "webpack", "serve"]
|
|
74
|
+
end
|
|
75
|
+
|
|
76
|
+
if @argv.include?("--debug-webpacker")
|
|
77
|
+
Shakapacker.puts_deprecation_message(
|
|
78
|
+
Shakapacker.short_deprecation_message(
|
|
79
|
+
"--debug-webpacker",
|
|
80
|
+
"--debug-shakapacker"
|
|
81
|
+
)
|
|
82
|
+
)
|
|
83
|
+
end
|
|
84
|
+
|
|
85
|
+
if @argv.delete("--debug-shakapacker") || @argv.delete("--debug-webpacker")
|
|
86
|
+
cmd = [ "node", "--inspect-brk", "--trace-warnings" ] + cmd
|
|
87
|
+
end
|
|
88
|
+
|
|
89
|
+
cmd += ["--config", @webpack_config]
|
|
90
|
+
cmd += ["--progress", "--color"] if @pretty
|
|
91
|
+
|
|
92
|
+
cmd += ["--hot"] if @hot
|
|
93
|
+
cmd += @argv
|
|
94
|
+
|
|
95
|
+
Dir.chdir(@app_path) do
|
|
96
|
+
Kernel.exec env, *cmd
|
|
97
|
+
end
|
|
98
|
+
end
|
|
99
|
+
|
|
100
|
+
def node_modules_bin_exist?
|
|
101
|
+
File.exist?("#{@node_modules_bin_path}/webpack-dev-server")
|
|
102
|
+
end
|
|
103
|
+
end
|
|
104
|
+
end
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
require "digest/sha1"
|
|
2
|
-
require "
|
|
2
|
+
require "shakapacker/base_strategy"
|
|
3
3
|
|
|
4
|
-
module
|
|
4
|
+
module Shakapacker
|
|
5
5
|
class DigestStrategy < BaseStrategy
|
|
6
6
|
# Returns true if all the compiled packs are up to date with the underlying asset files.
|
|
7
7
|
def fresh?
|
|
@@ -31,10 +31,10 @@ module Webpacker
|
|
|
31
31
|
def watched_files_digest
|
|
32
32
|
if Rails.env.development?
|
|
33
33
|
warn <<~MSG.strip
|
|
34
|
-
|
|
34
|
+
Shakapacker::Compiler - Slow setup for development
|
|
35
35
|
Prepare JS assets with either:
|
|
36
|
-
1. Running `bin/
|
|
37
|
-
2. Set `compile` to false in
|
|
36
|
+
1. Running `bin/shakapacker-dev-server`
|
|
37
|
+
2. Set `compile` to false in shakapacker.yml and run `bin/shakapacker -w`
|
|
38
38
|
MSG
|
|
39
39
|
end
|
|
40
40
|
|
|
@@ -53,7 +53,7 @@ module Webpacker
|
|
|
53
53
|
end
|
|
54
54
|
|
|
55
55
|
def compilation_digest_path
|
|
56
|
-
config.cache_path.join("last-compilation-digest-#{
|
|
56
|
+
config.cache_path.join("last-compilation-digest-#{Shakapacker.env}")
|
|
57
57
|
end
|
|
58
58
|
end
|
|
59
59
|
end
|
|
@@ -1,17 +1,17 @@
|
|
|
1
|
-
class
|
|
2
|
-
delegate :config_path, :logger, to: :@
|
|
1
|
+
class Shakapacker::Env
|
|
2
|
+
delegate :config_path, :logger, to: :@instance
|
|
3
3
|
|
|
4
|
-
def self.inquire(
|
|
5
|
-
new(
|
|
4
|
+
def self.inquire(instance)
|
|
5
|
+
new(instance).inquire
|
|
6
6
|
end
|
|
7
7
|
|
|
8
|
-
def initialize(
|
|
9
|
-
@
|
|
8
|
+
def initialize(instance)
|
|
9
|
+
@instance = instance
|
|
10
10
|
end
|
|
11
11
|
|
|
12
12
|
def inquire
|
|
13
13
|
fallback_env_warning if config_path.exist? && !current
|
|
14
|
-
current ||
|
|
14
|
+
current || Shakapacker::DEFAULT_ENV.inquiry
|
|
15
15
|
end
|
|
16
16
|
|
|
17
17
|
private
|
|
@@ -20,7 +20,7 @@ class Webpacker::Env
|
|
|
20
20
|
end
|
|
21
21
|
|
|
22
22
|
def fallback_env_warning
|
|
23
|
-
logger.info "RAILS_ENV=#{Rails.env} environment is not defined in config/
|
|
23
|
+
logger.info "RAILS_ENV=#{Rails.env} environment is not defined in config/shakapacker.yml, falling back to #{Shakapacker::DEFAULT_ENV} environment"
|
|
24
24
|
end
|
|
25
25
|
|
|
26
26
|
def available_environments
|
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
module
|
|
2
|
-
# Returns the current
|
|
3
|
-
# Could be overridden to use multiple
|
|
1
|
+
module Shakapacker::Helper
|
|
2
|
+
# Returns the current Shakapacker instance.
|
|
3
|
+
# Could be overridden to use multiple Shakapacker
|
|
4
4
|
# configurations within the same app (e.g. with engines).
|
|
5
|
-
def
|
|
6
|
-
|
|
5
|
+
def current_shakapacker_instance
|
|
6
|
+
Shakapacker.instance
|
|
7
7
|
end
|
|
8
8
|
|
|
9
|
-
# Computes the relative path for a given
|
|
9
|
+
# Computes the relative path for a given Shakapacker asset.
|
|
10
10
|
# Returns the relative path using manifest.json and passes it to path_to_asset helper.
|
|
11
11
|
# This will use path_to_asset internally, so most of their behaviors will be the same.
|
|
12
12
|
#
|
|
@@ -14,10 +14,10 @@ module Webpacker::Helper
|
|
|
14
14
|
#
|
|
15
15
|
# <%= asset_pack_path 'calendar.css' %> # => "/packs/calendar-1016838bab065ae1e122.css"
|
|
16
16
|
def asset_pack_path(name, **options)
|
|
17
|
-
path_to_asset(
|
|
17
|
+
path_to_asset(current_shakapacker_instance.manifest.lookup!(name), options)
|
|
18
18
|
end
|
|
19
19
|
|
|
20
|
-
# Computes the absolute path for a given
|
|
20
|
+
# Computes the absolute path for a given Shakapacker asset.
|
|
21
21
|
# Returns the absolute path using manifest.json and passes it to url_to_asset helper.
|
|
22
22
|
# This will use url_to_asset internally, so most of their behaviors will be the same.
|
|
23
23
|
#
|
|
@@ -25,17 +25,17 @@ module Webpacker::Helper
|
|
|
25
25
|
#
|
|
26
26
|
# <%= asset_pack_url 'calendar.css' %> # => "http://example.com/packs/calendar-1016838bab065ae1e122.css"
|
|
27
27
|
def asset_pack_url(name, **options)
|
|
28
|
-
url_to_asset(
|
|
28
|
+
url_to_asset(current_shakapacker_instance.manifest.lookup!(name), options)
|
|
29
29
|
end
|
|
30
30
|
|
|
31
|
-
# Computes the relative path for a given
|
|
31
|
+
# Computes the relative path for a given Shakapacker image with the same automated processing as image_pack_tag.
|
|
32
32
|
# Returns the relative path using manifest.json and passes it to path_to_asset helper.
|
|
33
33
|
# This will use path_to_asset internally, so most of their behaviors will be the same.
|
|
34
34
|
def image_pack_path(name, **options)
|
|
35
35
|
resolve_path_to_image(name, **options)
|
|
36
36
|
end
|
|
37
37
|
|
|
38
|
-
# Computes the absolute path for a given
|
|
38
|
+
# Computes the absolute path for a given Shakapacker image with the same automated
|
|
39
39
|
# processing as image_pack_tag. Returns the relative path using manifest.json
|
|
40
40
|
# and passes it to path_to_asset helper. This will use path_to_asset internally,
|
|
41
41
|
# so most of their behaviors will be the same.
|
|
@@ -75,7 +75,7 @@ module Webpacker::Helper
|
|
|
75
75
|
# Creates script tags that reference the js chunks from entrypoints when using split chunks API,
|
|
76
76
|
# as compiled by webpack per the entries list in package/environments/base.js.
|
|
77
77
|
# By default, this list is auto-generated to match everything in
|
|
78
|
-
# app/
|
|
78
|
+
# app/javascript/entrypoints/*.js and all the dependent chunks. In production mode, the digested reference is automatically looked up.
|
|
79
79
|
# See: https://webpack.js.org/plugins/split-chunks-plugin/
|
|
80
80
|
#
|
|
81
81
|
# Example:
|
|
@@ -114,7 +114,7 @@ module Webpacker::Helper
|
|
|
114
114
|
end
|
|
115
115
|
end
|
|
116
116
|
|
|
117
|
-
# Creates a link tag, for preloading, that references a given
|
|
117
|
+
# Creates a link tag, for preloading, that references a given Shakapacker asset.
|
|
118
118
|
# In production mode, the digested reference is automatically looked up.
|
|
119
119
|
# See: https://developer.mozilla.org/en-US/docs/Web/HTML/Preloading_content
|
|
120
120
|
#
|
|
@@ -124,7 +124,7 @@ module Webpacker::Helper
|
|
|
124
124
|
# <link rel="preload" href="/packs/fonts/fa-regular-400-944fb546bd7018b07190a32244f67dc9.woff2" as="font" type="font/woff2" crossorigin="anonymous">
|
|
125
125
|
def preload_pack_asset(name, **options)
|
|
126
126
|
if self.class.method_defined?(:preload_link_tag)
|
|
127
|
-
preload_link_tag(
|
|
127
|
+
preload_link_tag(current_shakapacker_instance.manifest.lookup!(name), options)
|
|
128
128
|
else
|
|
129
129
|
raise "You need Rails >= 5.2 to use this tag."
|
|
130
130
|
end
|
|
@@ -133,7 +133,7 @@ module Webpacker::Helper
|
|
|
133
133
|
# Creates link tags that reference the css chunks from entrypoints when using split chunks API,
|
|
134
134
|
# as compiled by webpack per the entries list in package/environments/base.js.
|
|
135
135
|
# By default, this list is auto-generated to match everything in
|
|
136
|
-
# app/
|
|
136
|
+
# app/javascript/entrypoints/*.js and all the dependent chunks. In production mode, the digested reference is automatically looked up.
|
|
137
137
|
# See: https://webpack.js.org/plugins/split-chunks-plugin/
|
|
138
138
|
#
|
|
139
139
|
# Examples:
|
|
@@ -156,7 +156,7 @@ module Webpacker::Helper
|
|
|
156
156
|
# <%= stylesheet_pack_tag 'calendar' %>
|
|
157
157
|
# <%= stylesheet_pack_tag 'map' %>
|
|
158
158
|
def stylesheet_pack_tag(*names, **options)
|
|
159
|
-
return "" if
|
|
159
|
+
return "" if Shakapacker.inlining_css?
|
|
160
160
|
|
|
161
161
|
requested_packs = sources_from_manifest_entrypoints(names, type: :stylesheet)
|
|
162
162
|
appended_packs = available_sources_from_manifest_entrypoints(@stylesheet_pack_tag_queue || [], type: :stylesheet)
|
|
@@ -213,17 +213,17 @@ module Webpacker::Helper
|
|
|
213
213
|
end
|
|
214
214
|
|
|
215
215
|
def sources_from_manifest_entrypoints(names, type:)
|
|
216
|
-
names.map { |name|
|
|
216
|
+
names.map { |name| current_shakapacker_instance.manifest.lookup_pack_with_chunks!(name.to_s, type: type) }.flatten.uniq
|
|
217
217
|
end
|
|
218
218
|
|
|
219
219
|
def available_sources_from_manifest_entrypoints(names, type:)
|
|
220
|
-
names.map { |name|
|
|
220
|
+
names.map { |name| current_shakapacker_instance.manifest.lookup_pack_with_chunks(name.to_s, type: type) }.flatten.compact.uniq
|
|
221
221
|
end
|
|
222
222
|
|
|
223
223
|
def resolve_path_to_image(name, **options)
|
|
224
224
|
path = name.starts_with?("static/") ? name : "static/#{name}"
|
|
225
|
-
path_to_asset(
|
|
225
|
+
path_to_asset(current_shakapacker_instance.manifest.lookup!(path), options)
|
|
226
226
|
rescue
|
|
227
|
-
path_to_asset(
|
|
227
|
+
path_to_asset(current_shakapacker_instance.manifest.lookup!(name), options)
|
|
228
228
|
end
|
|
229
229
|
end
|
|
@@ -1,20 +1,23 @@
|
|
|
1
1
|
require "pathname"
|
|
2
|
-
|
|
2
|
+
|
|
3
|
+
class Shakapacker::Instance
|
|
3
4
|
cattr_accessor(:logger) { ActiveSupport::TaggedLogging.new(ActiveSupport::Logger.new(STDOUT)) }
|
|
4
5
|
|
|
5
6
|
attr_reader :root_path, :config_path
|
|
6
7
|
|
|
7
|
-
def initialize(root_path: Rails.root, config_path: Rails.root.join("config/
|
|
8
|
+
def initialize(root_path: Rails.root, config_path: Rails.root.join("config/shakapacker.yml"))
|
|
8
9
|
@root_path = root_path
|
|
9
|
-
|
|
10
|
+
|
|
11
|
+
# For backward compatibility
|
|
12
|
+
@config_path = Shakapacker.get_config_file_path_with_backward_compatibility(config_path)
|
|
10
13
|
end
|
|
11
14
|
|
|
12
15
|
def env
|
|
13
|
-
@env ||=
|
|
16
|
+
@env ||= Shakapacker::Env.inquire self
|
|
14
17
|
end
|
|
15
18
|
|
|
16
19
|
def config
|
|
17
|
-
@config ||=
|
|
20
|
+
@config ||= Shakapacker::Configuration.new(
|
|
18
21
|
root_path: root_path,
|
|
19
22
|
config_path: config_path,
|
|
20
23
|
env: env
|
|
@@ -22,23 +25,23 @@ class Webpacker::Instance
|
|
|
22
25
|
end
|
|
23
26
|
|
|
24
27
|
def strategy
|
|
25
|
-
@strategy ||=
|
|
28
|
+
@strategy ||= Shakapacker::CompilerStrategy.from_config
|
|
26
29
|
end
|
|
27
30
|
|
|
28
31
|
def compiler
|
|
29
|
-
@compiler ||=
|
|
32
|
+
@compiler ||= Shakapacker::Compiler.new self
|
|
30
33
|
end
|
|
31
34
|
|
|
32
35
|
def dev_server
|
|
33
|
-
@dev_server ||=
|
|
36
|
+
@dev_server ||= Shakapacker::DevServer.new config
|
|
34
37
|
end
|
|
35
38
|
|
|
36
39
|
def manifest
|
|
37
|
-
@manifest ||=
|
|
40
|
+
@manifest ||= Shakapacker::Manifest.new self
|
|
38
41
|
end
|
|
39
42
|
|
|
40
43
|
def commands
|
|
41
|
-
@commands ||=
|
|
44
|
+
@commands ||= Shakapacker::Commands.new self
|
|
42
45
|
end
|
|
43
46
|
|
|
44
47
|
def inlining_css?
|