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
data/spec/configuration_spec.rb
CHANGED
|
@@ -1,22 +1,24 @@
|
|
|
1
|
-
|
|
1
|
+
require_relative "spec_helper_initializer"
|
|
2
|
+
|
|
3
|
+
describe "Shakapacker::Configuration" do
|
|
2
4
|
ROOT_PATH = Pathname.new(File.expand_path("test_app", __dir__))
|
|
3
5
|
|
|
4
|
-
context "with standard
|
|
6
|
+
context "with standard shakapacker.yml" do
|
|
5
7
|
let(:config) do
|
|
6
|
-
|
|
8
|
+
Shakapacker::Configuration.new(
|
|
7
9
|
root_path: ROOT_PATH,
|
|
8
|
-
config_path: Pathname.new(File.expand_path("./test_app/config/
|
|
10
|
+
config_path: Pathname.new(File.expand_path("./test_app/config/shakapacker.yml", __dir__)),
|
|
9
11
|
env: "production"
|
|
10
12
|
)
|
|
11
13
|
end
|
|
12
14
|
|
|
13
15
|
it "#source_path returns correct path" do
|
|
14
|
-
source_path = File.expand_path File.join(File.dirname(__FILE__), "test_app/app/
|
|
16
|
+
source_path = File.expand_path File.join(File.dirname(__FILE__), "test_app/app/javascript").to_s
|
|
15
17
|
expect(config.source_path.to_s).to eq source_path
|
|
16
18
|
end
|
|
17
19
|
|
|
18
20
|
it "#source_entry_path returns correct path" do
|
|
19
|
-
source_entry_path = File.expand_path File.join(File.dirname(__FILE__), "test_app/app/
|
|
21
|
+
source_entry_path = File.expand_path File.join(File.dirname(__FILE__), "test_app/app/javascript", "entrypoints").to_s
|
|
20
22
|
expect(config.source_entry_path.to_s).to eq source_entry_path
|
|
21
23
|
end
|
|
22
24
|
|
|
@@ -41,7 +43,7 @@ describe "Webpacker::Configuration" do
|
|
|
41
43
|
end
|
|
42
44
|
|
|
43
45
|
it "#cache_path returns correct path" do
|
|
44
|
-
cache_path = File.expand_path File.join(File.dirname(__FILE__), "test_app/tmp/
|
|
46
|
+
cache_path = File.expand_path File.join(File.dirname(__FILE__), "test_app/tmp/shakapacker").to_s
|
|
45
47
|
expect(config.cache_path.to_s).to eq cache_path
|
|
46
48
|
end
|
|
47
49
|
|
|
@@ -56,13 +58,13 @@ describe "Webpacker::Configuration" do
|
|
|
56
58
|
|
|
57
59
|
it "returns false in developemnt environemnt" do
|
|
58
60
|
with_rails_env("development") do
|
|
59
|
-
expect(
|
|
61
|
+
expect(Shakapacker.config.cache_manifest?).to be false
|
|
60
62
|
end
|
|
61
63
|
end
|
|
62
64
|
|
|
63
65
|
it "returns false in test environment" do
|
|
64
66
|
with_rails_env("test") do
|
|
65
|
-
expect(
|
|
67
|
+
expect(Shakapacker.config.cache_manifest?).to be false
|
|
66
68
|
end
|
|
67
69
|
end
|
|
68
70
|
end
|
|
@@ -74,13 +76,13 @@ describe "Webpacker::Configuration" do
|
|
|
74
76
|
|
|
75
77
|
it "returns true in developemnt environemnt" do
|
|
76
78
|
with_rails_env("development") do
|
|
77
|
-
expect(
|
|
79
|
+
expect(Shakapacker.config.compile?).to be true
|
|
78
80
|
end
|
|
79
81
|
end
|
|
80
82
|
|
|
81
83
|
it "returns true in test environemnt" do
|
|
82
84
|
with_rails_env("test") do
|
|
83
|
-
expect(
|
|
85
|
+
expect(Shakapacker.config.compile?).to be true
|
|
84
86
|
end
|
|
85
87
|
end
|
|
86
88
|
end
|
|
@@ -92,13 +94,13 @@ describe "Webpacker::Configuration" do
|
|
|
92
94
|
|
|
93
95
|
it "returns false in development environment" do
|
|
94
96
|
with_rails_env("development") do
|
|
95
|
-
expect(
|
|
97
|
+
expect(Shakapacker.config.nested_entries?).to be false
|
|
96
98
|
end
|
|
97
99
|
end
|
|
98
100
|
|
|
99
101
|
it "returns false in test environment" do
|
|
100
102
|
with_rails_env("test") do
|
|
101
|
-
expect(
|
|
103
|
+
expect(Shakapacker.config.nested_entries?).to be false
|
|
102
104
|
end
|
|
103
105
|
end
|
|
104
106
|
end
|
|
@@ -110,74 +112,74 @@ describe "Webpacker::Configuration" do
|
|
|
110
112
|
|
|
111
113
|
it "returns true in development environment" do
|
|
112
114
|
with_rails_env("development") do
|
|
113
|
-
expect(
|
|
115
|
+
expect(Shakapacker.config.ensure_consistent_versioning?).to be true
|
|
114
116
|
end
|
|
115
117
|
end
|
|
116
118
|
|
|
117
119
|
it "returns false in test environment" do
|
|
118
120
|
with_rails_env("test") do
|
|
119
|
-
expect(
|
|
121
|
+
expect(Shakapacker.config.ensure_consistent_versioning?).to be false
|
|
120
122
|
end
|
|
121
123
|
end
|
|
122
124
|
end
|
|
123
125
|
|
|
124
|
-
describe "#
|
|
126
|
+
describe "#shakapacker_precompile?" do
|
|
125
127
|
before :each do
|
|
126
|
-
ENV["
|
|
128
|
+
ENV["SHAKAPACKER_PRECOMPILE"] = nil
|
|
127
129
|
end
|
|
128
130
|
|
|
129
|
-
subject { config.
|
|
131
|
+
subject { config.shakapacker_precompile? }
|
|
130
132
|
|
|
131
|
-
it "returns true when
|
|
133
|
+
it "returns true when SHAKAPACKER_PRECOMPILE is unset" do
|
|
132
134
|
is_expected.to be true
|
|
133
135
|
end
|
|
134
136
|
|
|
135
|
-
it "returns false when
|
|
136
|
-
ENV["
|
|
137
|
+
it "returns false when SHAKAPACKER_PRECOMPILE sets to no" do
|
|
138
|
+
ENV["SHAKAPACKER_PRECOMPILE"] = "no"
|
|
137
139
|
is_expected.to be false
|
|
138
140
|
end
|
|
139
141
|
|
|
140
|
-
it "returns true when
|
|
141
|
-
ENV["
|
|
142
|
+
it "returns true when SHAKAPACKER_PRECOMPILE sets to yes" do
|
|
143
|
+
ENV["SHAKAPACKER_PRECOMPILE"] = "yes"
|
|
142
144
|
is_expected.to be true
|
|
143
145
|
end
|
|
144
146
|
|
|
145
|
-
it "returns false when
|
|
146
|
-
ENV["
|
|
147
|
+
it "returns false when SHAKAPACKER_PRECOMPILE sets to false" do
|
|
148
|
+
ENV["SHAKAPACKER_PRECOMPILE"] = "false"
|
|
147
149
|
is_expected.to be false
|
|
148
150
|
end
|
|
149
151
|
|
|
150
|
-
it "returns true when
|
|
151
|
-
ENV["
|
|
152
|
+
it "returns true when SHAKAPACKER_PRECOMPILE sets to true" do
|
|
153
|
+
ENV["SHAKAPACKER_PRECOMPILE"] = "true"
|
|
152
154
|
is_expected.to be true
|
|
153
155
|
end
|
|
154
156
|
|
|
155
|
-
it "returns false when
|
|
156
|
-
ENV["
|
|
157
|
+
it "returns false when SHAKAPACKER_PRECOMPILE sets to n" do
|
|
158
|
+
ENV["SHAKAPACKER_PRECOMPILE"] = "n"
|
|
157
159
|
is_expected.to be false
|
|
158
160
|
end
|
|
159
161
|
|
|
160
|
-
it "returns true when
|
|
161
|
-
ENV["
|
|
162
|
+
it "returns true when SHAKAPACKER_PRECOMPILE sets to y" do
|
|
163
|
+
ENV["SHAKAPACKER_PRECOMPILE"] = "y"
|
|
162
164
|
is_expected.to be true
|
|
163
165
|
end
|
|
164
166
|
|
|
165
|
-
it "returns false when
|
|
166
|
-
ENV["
|
|
167
|
+
it "returns false when SHAKAPACKER_PRECOMPILE sets to f" do
|
|
168
|
+
ENV["SHAKAPACKER_PRECOMPILE"] = "f"
|
|
167
169
|
is_expected.to be false
|
|
168
170
|
end
|
|
169
171
|
|
|
170
|
-
it "returns true when
|
|
171
|
-
ENV["
|
|
172
|
+
it "returns true when SHAKAPACKER_PRECOMPILE sets to t" do
|
|
173
|
+
ENV["SHAKAPACKER_PRECOMPILE"] = "t"
|
|
172
174
|
is_expected.to be true
|
|
173
175
|
end
|
|
174
176
|
end
|
|
175
177
|
end
|
|
176
178
|
|
|
177
|
-
context "with
|
|
178
|
-
config =
|
|
179
|
+
context "with shakapacker config file containing public_output_path entry" do
|
|
180
|
+
config = Shakapacker::Configuration.new(
|
|
179
181
|
root_path: ROOT_PATH,
|
|
180
|
-
config_path: Pathname.new(File.expand_path("./test_app/config/
|
|
182
|
+
config_path: Pathname.new(File.expand_path("./test_app/config/shakapacker_public_root.yml", __dir__)),
|
|
181
183
|
env: "production"
|
|
182
184
|
)
|
|
183
185
|
|
|
@@ -187,68 +189,68 @@ describe "Webpacker::Configuration" do
|
|
|
187
189
|
end
|
|
188
190
|
end
|
|
189
191
|
|
|
190
|
-
context "with
|
|
191
|
-
config =
|
|
192
|
+
context "with shakapacker config file containing manifext_path entry" do
|
|
193
|
+
config = Shakapacker::Configuration.new(
|
|
192
194
|
root_path: ROOT_PATH,
|
|
193
|
-
config_path: Pathname.new(File.expand_path("./test_app/config/
|
|
195
|
+
config_path: Pathname.new(File.expand_path("./test_app/config/shakapacker_manifest_path.yml", __dir__)),
|
|
194
196
|
env: "production"
|
|
195
197
|
)
|
|
196
198
|
|
|
197
199
|
it "#manifest_path returns correct expected value" do
|
|
198
|
-
expected_manifest_path = File.expand_path File.join(File.dirname(__FILE__), "test_app/app/
|
|
200
|
+
expected_manifest_path = File.expand_path File.join(File.dirname(__FILE__), "test_app/app/javascript", "manifest.json").to_s
|
|
199
201
|
expect(config.manifest_path.to_s).to eq expected_manifest_path
|
|
200
202
|
end
|
|
201
203
|
end
|
|
202
204
|
|
|
203
|
-
context "with
|
|
204
|
-
describe "#
|
|
205
|
+
context "with shakapacker_precompile entry set to false" do
|
|
206
|
+
describe "#shakapacker_precompile?" do
|
|
205
207
|
before :each do
|
|
206
|
-
ENV["
|
|
208
|
+
ENV["SHAKAPACKER_PRECOMPILE"] = nil
|
|
207
209
|
end
|
|
208
210
|
|
|
209
211
|
let(:config) {
|
|
210
|
-
|
|
212
|
+
Shakapacker::Configuration.new(
|
|
211
213
|
root_path: ROOT_PATH,
|
|
212
|
-
config_path: Pathname.new(File.expand_path("./test_app/config/
|
|
214
|
+
config_path: Pathname.new(File.expand_path("./test_app/config/shakapacker_no_precompile.yml", __dir__)),
|
|
213
215
|
env: "production"
|
|
214
216
|
)
|
|
215
217
|
}
|
|
216
218
|
|
|
217
|
-
subject { config.
|
|
219
|
+
subject { config.shakapacker_precompile? }
|
|
218
220
|
|
|
219
|
-
it "returns false with unset
|
|
221
|
+
it "returns false with unset SHAKAPACKER_PRECOMPILE" do
|
|
220
222
|
expect(subject).to be false
|
|
221
223
|
end
|
|
222
224
|
|
|
223
|
-
it "returns true with
|
|
224
|
-
ENV["
|
|
225
|
+
it "returns true with SHAKAPACKER_PRECOMPILE set to true" do
|
|
226
|
+
ENV["SHAKAPACKER_PRECOMPILE"] = "true"
|
|
225
227
|
expect(subject).to be true
|
|
226
228
|
end
|
|
227
229
|
|
|
228
|
-
it "returns false with
|
|
229
|
-
ENV["
|
|
230
|
+
it "returns false with SHAKAPACKER_PRECOMPILE set to nil" do
|
|
231
|
+
ENV["SHAKAPACKER_PRECOMPILE"] = nil
|
|
230
232
|
expect(subject).to be false
|
|
231
233
|
end
|
|
232
234
|
end
|
|
233
235
|
end
|
|
234
236
|
|
|
235
|
-
context "with
|
|
236
|
-
config =
|
|
237
|
+
context "with shakapacker config file containing invalid path" do
|
|
238
|
+
config = Shakapacker::Configuration.new(
|
|
237
239
|
root_path: ROOT_PATH,
|
|
238
240
|
config_path: Pathname.new(File.expand_path("./test_app/config/invalid_path.yml", __dir__)),
|
|
239
241
|
env: "default"
|
|
240
242
|
)
|
|
241
243
|
|
|
242
|
-
it "#
|
|
243
|
-
expect(config.
|
|
244
|
+
it "#shakapacker_precompile? returns false" do
|
|
245
|
+
expect(config.shakapacker_precompile?).to be false
|
|
244
246
|
end
|
|
245
247
|
end
|
|
246
248
|
|
|
247
|
-
context "with
|
|
249
|
+
context "with shakapacker config file with defaults fallback" do
|
|
248
250
|
let(:config) do
|
|
249
|
-
|
|
251
|
+
Shakapacker::Configuration.new(
|
|
250
252
|
root_path: ROOT_PATH,
|
|
251
|
-
config_path: Pathname.new(File.expand_path("./test_app/config/
|
|
253
|
+
config_path: Pathname.new(File.expand_path("./test_app/config/shakapacker_defaults_fallback.yml", __dir__)),
|
|
252
254
|
env: "default"
|
|
253
255
|
)
|
|
254
256
|
end
|
|
@@ -257,16 +259,16 @@ describe "Webpacker::Configuration" do
|
|
|
257
259
|
expect(config.cache_manifest?).to be false
|
|
258
260
|
end
|
|
259
261
|
|
|
260
|
-
it "#
|
|
261
|
-
expect(config.
|
|
262
|
+
it "#shakapacker_precompile? uses 'default' config from custom file" do
|
|
263
|
+
expect(config.shakapacker_precompile?).to be false
|
|
262
264
|
end
|
|
263
265
|
end
|
|
264
266
|
|
|
265
267
|
context "falls back to bundled production config for custom environments" do
|
|
266
268
|
let(:config) do
|
|
267
|
-
|
|
269
|
+
Shakapacker::Configuration.new(
|
|
268
270
|
root_path: ROOT_PATH,
|
|
269
|
-
config_path: Pathname.new(File.expand_path("./test_app/config/
|
|
271
|
+
config_path: Pathname.new(File.expand_path("./test_app/config/shakapacker_defaults_fallback.yml", __dir__)),
|
|
270
272
|
env: "staging"
|
|
271
273
|
)
|
|
272
274
|
end
|
|
@@ -274,8 +276,48 @@ describe "Webpacker::Configuration" do
|
|
|
274
276
|
it "#cache_manifest? fall back to 'production' config from bundled file" do
|
|
275
277
|
expect(config.cache_manifest?).to be true
|
|
276
278
|
end
|
|
277
|
-
it "#
|
|
278
|
-
expect(config.
|
|
279
|
+
it "#shakapacker_precompile? use 'staging' config from custom file" do
|
|
280
|
+
expect(config.shakapacker_precompile?).to be false
|
|
281
|
+
end
|
|
282
|
+
end
|
|
283
|
+
|
|
284
|
+
context "#source_entry_path" do
|
|
285
|
+
let(:config) do
|
|
286
|
+
Shakapacker::Configuration.new(
|
|
287
|
+
root_path: ROOT_PATH,
|
|
288
|
+
config_path: Pathname.new(File.expand_path("./test_app/config/shakapacker.yml", __dir__)),
|
|
289
|
+
env: "production"
|
|
290
|
+
)
|
|
291
|
+
end
|
|
292
|
+
|
|
293
|
+
it "returns correct path with source_entry_path starting with 'extra_path'" do
|
|
294
|
+
allow(config).to receive(:fetch).with(:source_path).and_return("the_source_path")
|
|
295
|
+
allow(config).to receive(:fetch).with(:source_entry_path).and_return("extra_path")
|
|
296
|
+
|
|
297
|
+
actual = config.source_entry_path.to_s
|
|
298
|
+
expected = "#{config.source_path.to_s}/extra_path"
|
|
299
|
+
|
|
300
|
+
expect(actual).to eq(expected)
|
|
301
|
+
end
|
|
302
|
+
|
|
303
|
+
it "returns correct path with source_entry_path starting with /" do
|
|
304
|
+
allow(config).to receive(:fetch).with(:source_path).and_return("the_source_path")
|
|
305
|
+
allow(config).to receive(:fetch).with(:source_entry_path).and_return("/")
|
|
306
|
+
|
|
307
|
+
actual = config.source_entry_path.to_s
|
|
308
|
+
expected = config.source_path.to_s
|
|
309
|
+
|
|
310
|
+
expect(actual).to eq(expected)
|
|
311
|
+
end
|
|
312
|
+
|
|
313
|
+
it "returns correct path with source_entry_path starting with /extra_path" do
|
|
314
|
+
allow(config).to receive(:fetch).with(:source_path).and_return("the_source_path")
|
|
315
|
+
allow(config).to receive(:fetch).with(:source_entry_path).and_return("/extra_path")
|
|
316
|
+
|
|
317
|
+
actual = config.source_entry_path.to_s
|
|
318
|
+
expected = "#{config.source_path.to_s}/extra_path"
|
|
319
|
+
|
|
320
|
+
expect(actual).to eq(expected)
|
|
279
321
|
end
|
|
280
322
|
end
|
|
281
323
|
end
|
|
@@ -1,16 +1,17 @@
|
|
|
1
|
-
|
|
1
|
+
require_relative "spec_helper_initializer"
|
|
2
|
+
require "shakapacker/dev_server_runner"
|
|
2
3
|
|
|
3
4
|
describe "DevServerRunner" do
|
|
4
5
|
before do
|
|
5
6
|
@original_node_env, ENV["NODE_ENV"] = ENV["NODE_ENV"], "development"
|
|
6
7
|
@original_rails_env, ENV["RAILS_ENV"] = ENV["RAILS_ENV"], "development"
|
|
7
|
-
@
|
|
8
|
+
@original_shakapacker_config = ENV["SHAKAPACKER_CONFIG"]
|
|
8
9
|
end
|
|
9
10
|
|
|
10
11
|
after do
|
|
11
12
|
ENV["NODE_ENV"] = @original_node_env
|
|
12
13
|
ENV["RAILS_ENV"] = @original_rails_env
|
|
13
|
-
ENV["
|
|
14
|
+
ENV["SHAKAPACKER_CONFIG"] = @original_shakapacker_config
|
|
14
15
|
end
|
|
15
16
|
|
|
16
17
|
let(:test_app_path) { File.expand_path("test_app", __dir__) }
|
|
@@ -37,24 +38,24 @@ describe "DevServerRunner" do
|
|
|
37
38
|
allow(dev_server).to receive(:https?).and_return(true)
|
|
38
39
|
allow(dev_server).to receive(:hmr?).and_return(false)
|
|
39
40
|
|
|
40
|
-
allow(
|
|
41
|
+
allow(Shakapacker::DevServer).to receive(:new) do
|
|
41
42
|
verify_command(cmd, argv: (["--https"]))
|
|
42
43
|
end.and_return(dev_server)
|
|
43
44
|
end
|
|
44
45
|
it "accepts environment variables" do
|
|
45
46
|
cmd = ["#{test_app_path}/node_modules/.bin/webpack", "serve", "--config", "#{test_app_path}/config/webpack/webpack.config.js"]
|
|
46
|
-
env =
|
|
47
|
-
ENV["
|
|
47
|
+
env = Shakapacker::Compiler.env.dup
|
|
48
|
+
ENV["SHAKAPACKER_CONFIG"] = env["SHAKAPACKER_CONFIG"] = "#{test_app_path}/config/shakapacker_other_location.yml"
|
|
48
49
|
env["WEBPACK_SERVE"] = "true"
|
|
49
50
|
verify_command(cmd, env: env)
|
|
50
51
|
end
|
|
51
52
|
|
|
52
53
|
private
|
|
53
54
|
|
|
54
|
-
def verify_command(cmd, use_node_modules: true, argv: [], env:
|
|
55
|
+
def verify_command(cmd, use_node_modules: true, argv: [], env: Shakapacker::Compiler.env)
|
|
55
56
|
cwd = Dir.pwd
|
|
56
57
|
Dir.chdir(test_app_path)
|
|
57
|
-
klass =
|
|
58
|
+
klass = Shakapacker::DevServerRunner
|
|
58
59
|
instance = klass.new(argv)
|
|
59
60
|
|
|
60
61
|
allow(klass).to receive(:new).and_return(instance)
|
data/spec/dev_server_spec.rb
CHANGED
|
@@ -1,45 +1,133 @@
|
|
|
1
|
+
require_relative "spec_helper_initializer"
|
|
2
|
+
|
|
1
3
|
describe "DevServer" do
|
|
2
4
|
it "doesn't run by default" do
|
|
3
|
-
expect(
|
|
5
|
+
expect(Shakapacker.dev_server.running?).to be_falsy
|
|
4
6
|
end
|
|
5
7
|
|
|
6
8
|
it "uses localhost as host in development environment" do
|
|
7
9
|
with_rails_env("development") do
|
|
8
|
-
expect(
|
|
10
|
+
expect(Shakapacker.dev_server.host).to eq "localhost"
|
|
9
11
|
end
|
|
10
12
|
end
|
|
11
13
|
|
|
12
14
|
it "uses port 3035 in development environment" do
|
|
13
15
|
with_rails_env("development") do
|
|
14
|
-
expect(
|
|
16
|
+
expect(Shakapacker.dev_server.port).to eq 3035
|
|
15
17
|
end
|
|
16
18
|
end
|
|
17
19
|
|
|
18
20
|
it "doesn't use https in development environment" do
|
|
19
21
|
with_rails_env("development") do
|
|
20
|
-
expect(
|
|
22
|
+
expect(Shakapacker.dev_server.https?).to be false
|
|
21
23
|
end
|
|
22
24
|
end
|
|
23
25
|
|
|
24
26
|
it "uses http protocol in development environment" do
|
|
25
27
|
with_rails_env("development") do
|
|
26
|
-
expect(
|
|
28
|
+
expect(Shakapacker.dev_server.protocol).to eq "http"
|
|
27
29
|
end
|
|
28
30
|
end
|
|
29
31
|
|
|
30
32
|
it "sets host_with_port to localhost:3035 in development environment" do
|
|
31
33
|
with_rails_env("development") do
|
|
32
|
-
expect(
|
|
34
|
+
expect(Shakapacker.dev_server.host_with_port).to eq "localhost:3035"
|
|
33
35
|
end
|
|
34
36
|
end
|
|
35
37
|
|
|
36
38
|
it "doesn't use pretty in development environment" do
|
|
37
39
|
with_rails_env("development") do
|
|
38
|
-
expect(
|
|
40
|
+
expect(Shakapacker.dev_server.pretty?).to be false
|
|
41
|
+
end
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
it "users SHAKAPACKER_DEV_SERVER for DEFAULT_ENV_PREFIX" do
|
|
45
|
+
expect(Shakapacker::DevServer::DEFAULT_ENV_PREFIX).to eq "SHAKAPACKER_DEV_SERVER"
|
|
46
|
+
end
|
|
47
|
+
|
|
48
|
+
context "#protocol in development environment" do
|
|
49
|
+
let(:dev_server) { Shakapacker.dev_server }
|
|
50
|
+
|
|
51
|
+
it "returns `http` by default (with unset `server` and `https`)" do
|
|
52
|
+
with_rails_env("development") do
|
|
53
|
+
expect(dev_server.protocol).to eq "http"
|
|
54
|
+
end
|
|
55
|
+
end
|
|
56
|
+
|
|
57
|
+
it "returns `https` when `server` is set to `https`" do
|
|
58
|
+
expect(dev_server).to receive(:server).and_return("https")
|
|
59
|
+
|
|
60
|
+
with_rails_env("development") do
|
|
61
|
+
expect(dev_server.protocol).to eq "https"
|
|
62
|
+
end
|
|
63
|
+
end
|
|
64
|
+
|
|
65
|
+
it "returns `https` with unset `server` and `https` set to `true`" do
|
|
66
|
+
expect(dev_server).to receive(:server).and_return("http")
|
|
67
|
+
expect(dev_server).to receive(:https?).and_return(true)
|
|
68
|
+
|
|
69
|
+
with_rails_env("development") do
|
|
70
|
+
expect(dev_server.protocol).to eq "https"
|
|
71
|
+
end
|
|
39
72
|
end
|
|
40
73
|
end
|
|
41
74
|
|
|
42
|
-
|
|
43
|
-
|
|
75
|
+
context "#server in development environment" do
|
|
76
|
+
let(:dev_server) { Shakapacker.dev_server }
|
|
77
|
+
|
|
78
|
+
it "returns `http` when unset" do
|
|
79
|
+
expect(dev_server).to receive(:fetch).with(:server).and_return(nil)
|
|
80
|
+
|
|
81
|
+
with_rails_env("development") do
|
|
82
|
+
expect(dev_server.server).to eq "http"
|
|
83
|
+
end
|
|
84
|
+
end
|
|
85
|
+
|
|
86
|
+
it "returns `http` when set to `https`" do
|
|
87
|
+
expect(dev_server).to receive(:fetch).with(:server).and_return("http")
|
|
88
|
+
|
|
89
|
+
with_rails_env("development") do
|
|
90
|
+
expect(dev_server.server).to eq "http"
|
|
91
|
+
end
|
|
92
|
+
end
|
|
93
|
+
|
|
94
|
+
it "returns `http` when set to a hash with `type: http`" do
|
|
95
|
+
expect(dev_server).to receive(:fetch).with(:server).and_return({
|
|
96
|
+
type: "http",
|
|
97
|
+
options: {}
|
|
98
|
+
})
|
|
99
|
+
|
|
100
|
+
with_rails_env("development") do
|
|
101
|
+
expect(dev_server.server).to eq "http"
|
|
102
|
+
end
|
|
103
|
+
end
|
|
104
|
+
|
|
105
|
+
it "returns `https` when set to `https`" do
|
|
106
|
+
expect(dev_server).to receive(:fetch).with(:server).and_return("https")
|
|
107
|
+
|
|
108
|
+
with_rails_env("development") do
|
|
109
|
+
expect(dev_server.server).to eq "https"
|
|
110
|
+
end
|
|
111
|
+
end
|
|
112
|
+
|
|
113
|
+
it "returns `https` when set to a hash with `type: https`" do
|
|
114
|
+
expect(dev_server).to receive(:fetch).with(:server).and_return({
|
|
115
|
+
type: "https",
|
|
116
|
+
options: {}
|
|
117
|
+
})
|
|
118
|
+
|
|
119
|
+
with_rails_env("development") do
|
|
120
|
+
expect(dev_server.server).to eq "https"
|
|
121
|
+
end
|
|
122
|
+
end
|
|
123
|
+
|
|
124
|
+
it "returns `http` when set to any value except `http` and `https`" do
|
|
125
|
+
expect(dev_server).to receive(:fetch).twice.with(:server).and_return("other-than-https")
|
|
126
|
+
|
|
127
|
+
with_rails_env("development") do
|
|
128
|
+
expect(dev_server.server).to eq "http"
|
|
129
|
+
expect { dev_server.server }.to output(/WARNING/).to_stdout
|
|
130
|
+
end
|
|
131
|
+
end
|
|
44
132
|
end
|
|
45
133
|
end
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
require_relative "spec_helper_initializer"
|
|
2
|
+
|
|
1
3
|
describe "DigestStrategy" do
|
|
2
4
|
def remove_compilation_digest_path
|
|
3
5
|
@digest_strategy.send(:compilation_digest_path).tap do |path|
|
|
@@ -6,7 +8,7 @@ describe "DigestStrategy" do
|
|
|
6
8
|
end
|
|
7
9
|
|
|
8
10
|
before :all do
|
|
9
|
-
@digest_strategy =
|
|
11
|
+
@digest_strategy = Shakapacker::DigestStrategy.new
|
|
10
12
|
remove_compilation_digest_path
|
|
11
13
|
end
|
|
12
14
|
|
|
@@ -27,7 +29,7 @@ describe "DigestStrategy" do
|
|
|
27
29
|
|
|
28
30
|
it "generates correct compilation_digest_path" do
|
|
29
31
|
actual_path = @digest_strategy.send(:compilation_digest_path).basename.to_s
|
|
30
|
-
expected_path = "last-compilation-digest-#{
|
|
32
|
+
expected_path = "last-compilation-digest-#{Shakapacker.env}"
|
|
31
33
|
expect(actual_path).to eq expected_path
|
|
32
34
|
end
|
|
33
35
|
end
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
require_relative "spec_helper_initializer"
|
|
2
|
+
|
|
1
3
|
describe "EngineRakeTasks" do
|
|
2
4
|
before :context do
|
|
3
5
|
remove_webpack_binstubs
|
|
@@ -7,19 +9,14 @@ describe "EngineRakeTasks" do
|
|
|
7
9
|
remove_webpack_binstubs
|
|
8
10
|
end
|
|
9
11
|
|
|
10
|
-
it "mounts app:
|
|
12
|
+
it "mounts app:shakapacker task successfully" do
|
|
11
13
|
output = Dir.chdir(mounted_app_path) { `rake -T` }
|
|
12
|
-
expect(output).to include "app:
|
|
14
|
+
expect(output).to include "app:shakapacker"
|
|
13
15
|
end
|
|
14
16
|
|
|
15
17
|
it "binstubs adds only expected files to bin directory" do
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
Dir.chdir(mounted_app_path) { `bundle exec rake app:webpacker:binstubs` }
|
|
19
|
-
webpack_binstub_paths.each { |path| expect(File.exist?(path)).to be true }
|
|
20
|
-
|
|
21
|
-
# and no other files are added
|
|
22
|
-
expect(current_files_in_bin - webpack_binstub_paths).to match_array original_files_in_bin
|
|
18
|
+
Dir.chdir(mounted_app_path) { `bundle exec rake app:shakapacker:binstubs` }
|
|
19
|
+
expected_binstub_paths.each { |path| expect(File.exist?(path)).to be true }
|
|
23
20
|
end
|
|
24
21
|
|
|
25
22
|
private
|
|
@@ -31,16 +28,15 @@ describe "EngineRakeTasks" do
|
|
|
31
28
|
Dir.glob("#{mounted_app_path}/test/dummy/bin/*")
|
|
32
29
|
end
|
|
33
30
|
|
|
34
|
-
def
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
"#{mounted_app_path}/test/dummy/bin
|
|
38
|
-
|
|
39
|
-
]
|
|
31
|
+
def expected_binstub_paths
|
|
32
|
+
gem_path = File.expand_path("..", __dir__)
|
|
33
|
+
Dir.chdir("#{gem_path}/lib/install/bin") do
|
|
34
|
+
Dir.glob("*").map { |file| "#{mounted_app_path}/test/dummy/bin/#{file}" }
|
|
35
|
+
end
|
|
40
36
|
end
|
|
41
37
|
|
|
42
38
|
def remove_webpack_binstubs
|
|
43
|
-
|
|
39
|
+
expected_binstub_paths.each do |path|
|
|
44
40
|
File.delete(path) if File.exist?(path)
|
|
45
41
|
end
|
|
46
42
|
end
|
data/spec/env_spec.rb
CHANGED
|
@@ -1,21 +1,23 @@
|
|
|
1
|
+
require_relative "spec_helper_initializer"
|
|
2
|
+
|
|
1
3
|
RSpec.describe "Env" do
|
|
2
|
-
it "uses the same env for Rails and
|
|
3
|
-
expect(
|
|
4
|
+
it "uses the same env for Rails and Shakapacker" do
|
|
5
|
+
expect(Shakapacker.env).to eq Rails.env
|
|
4
6
|
end
|
|
5
7
|
|
|
6
8
|
it "uses production env without config" do
|
|
7
9
|
with_rails_env("foo") do
|
|
8
|
-
expect(
|
|
10
|
+
expect(Shakapacker.env).to eq "production"
|
|
9
11
|
end
|
|
10
12
|
end
|
|
11
13
|
|
|
12
14
|
it "uses the given env in custom config" do
|
|
13
15
|
with_rails_env("staging") do
|
|
14
|
-
expect(
|
|
16
|
+
expect(Shakapacker.env).to eq "staging"
|
|
15
17
|
end
|
|
16
18
|
end
|
|
17
19
|
|
|
18
20
|
it "uses 'production' as default env" do
|
|
19
|
-
expect(
|
|
21
|
+
expect(Shakapacker::DEFAULT_ENV).to eq "production"
|
|
20
22
|
end
|
|
21
23
|
end
|
data/spec/helper_spec.rb
CHANGED
|
@@ -1,12 +1,14 @@
|
|
|
1
|
+
require_relative "spec_helper_initializer"
|
|
2
|
+
|
|
1
3
|
module ActionView::TestCase::Behavior
|
|
2
4
|
attr_accessor :request
|
|
3
5
|
|
|
4
|
-
describe "
|
|
6
|
+
describe "Shakapacker::Helper" do
|
|
5
7
|
let(:application_stylesheet_chunks) { %w[/packs/1-c20632e7baf2c81200d3.chunk.css /packs/application-k344a6d59eef8632c9d1.chunk.css] }
|
|
6
8
|
let(:hello_stimulus_stylesheet_chunks) { %w[/packs/1-c20632e7baf2c81200d3.chunk.css /packs/hello_stimulus-k344a6d59eef8632c9d1.chunk.css] }
|
|
7
9
|
|
|
8
10
|
before :each do
|
|
9
|
-
extend
|
|
11
|
+
extend Shakapacker::Helper
|
|
10
12
|
extend ActionView::Helpers
|
|
11
13
|
extend ActionView::Helpers::AssetTagHelper
|
|
12
14
|
extend ActionView::TestCase::Behavior
|