shakapacker 7.2.3 → 8.0.0.pre.rc.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.eslintignore +1 -1
- data/.eslintrc.js +29 -8
- data/.github/PULL_REQUEST_TEMPLATE.md +10 -3
- data/.github/workflows/dummy.yml +5 -1
- data/.github/workflows/generator.yml +13 -18
- data/.github/workflows/node.yml +56 -0
- data/.github/workflows/ruby.yml +28 -17
- data/.rubocop.yml +1 -0
- data/CHANGELOG.md +52 -1
- data/README.md +88 -50
- data/Rakefile +1 -7
- data/docs/customizing_babel_config.md +2 -2
- data/docs/deployment.md +13 -6
- data/docs/react.md +6 -12
- data/docs/troubleshooting.md +4 -4
- data/docs/using_esbuild_loader.md +1 -1
- data/docs/using_swc_loader.md +1 -1
- data/docs/v8_upgrade.md +148 -0
- data/gemfiles/Gemfile-rails.7.1.x +12 -0
- data/jest.config.js +4 -0
- data/lib/install/config/shakapacker.yml +2 -2
- data/lib/install/template.rb +36 -30
- data/lib/shakapacker/base_strategy.rb +2 -1
- data/lib/shakapacker/compiler.rb +5 -20
- data/lib/shakapacker/configuration.rb +2 -46
- data/lib/shakapacker/deprecation_helper.rb +0 -78
- data/lib/shakapacker/dev_server.rb +1 -16
- data/lib/shakapacker/dev_server_runner.rb +2 -21
- data/lib/shakapacker/env.rb +1 -1
- data/lib/shakapacker/instance.rb +1 -3
- data/lib/shakapacker/manifest.rb +1 -1
- data/lib/shakapacker/railtie.rb +7 -0
- data/lib/shakapacker/runner.rb +4 -18
- data/lib/shakapacker/utils/manager.rb +58 -0
- data/lib/shakapacker/utils/misc.rb +0 -12
- data/lib/shakapacker/version.rb +1 -1
- data/lib/shakapacker/version_checker.rb +9 -30
- data/lib/shakapacker/webpack_runner.rb +2 -21
- data/lib/shakapacker.rb +0 -2
- data/lib/tasks/shakapacker/check_binstubs.rake +12 -26
- data/lib/tasks/shakapacker/check_manager.rake +3 -8
- data/lib/tasks/shakapacker/info.rake +6 -15
- data/package/babel/preset.js +15 -15
- data/package/config.js +15 -17
- data/package/dev_server.js +4 -4
- data/package/env.js +19 -17
- data/package/environments/base.js +41 -24
- data/package/environments/development.js +6 -6
- data/package/environments/production.js +16 -16
- data/package/environments/test.js +1 -1
- data/package/esbuild/index.js +6 -6
- data/package/index.d.ts +0 -1
- data/package/index.js +17 -46
- data/package/rules/babel.js +6 -8
- data/package/rules/coffee.js +2 -2
- data/package/rules/css.js +1 -1
- data/package/rules/erb.js +4 -4
- data/package/rules/esbuild.js +5 -7
- data/package/rules/file.js +17 -7
- data/package/rules/index.js +11 -11
- data/package/rules/jscommon.js +5 -5
- data/package/rules/less.js +6 -6
- data/package/rules/raw.js +1 -1
- data/package/rules/sass.js +4 -4
- data/package/rules/stylus.js +6 -6
- data/package/rules/swc.js +5 -7
- data/package/swc/index.js +10 -10
- data/package/utils/configPath.js +3 -18
- data/package/utils/defaultConfigPath.js +1 -1
- data/package/utils/{get_style_rule.js → getStyleRule.js} +6 -6
- data/package/utils/helpers.js +2 -43
- data/package/utils/inliningCss.js +4 -3
- data/package/utils/snakeToCamelCase.js +5 -0
- data/package/webpackDevServerConfig.js +28 -25
- data/package.json +11 -17
- data/prettier.config.js +4 -0
- data/shakapacker.gemspec +1 -1
- data/spec/dummy/app/javascript/packs/application.js +1 -1
- data/spec/dummy/config/application.rb +3 -0
- data/spec/dummy/config/initializers/react_on_rails.rb +2 -2
- data/spec/dummy/config/shakapacker.yml +3 -4
- data/spec/dummy/config/webpack/commonWebpackConfig.js +0 -1
- data/spec/dummy/config/webpack/webpack.config.js +1 -1
- data/spec/dummy/package.json +2 -1
- data/spec/dummy/yarn.lock +2 -3
- data/spec/generator_specs/e2e_template/template.rb +15 -28
- data/spec/generator_specs/generator_spec.rb +6 -136
- data/spec/mounted_app/test/dummy/config/webpacker.yml +0 -1
- data/spec/shakapacker/compiler_spec.rb +1 -3
- data/spec/shakapacker/configuration_spec.rb +4 -56
- data/spec/shakapacker/dev_server_runner_spec.rb +19 -102
- data/spec/shakapacker/dev_server_spec.rb +1 -16
- data/spec/shakapacker/engine_rake_tasks_spec.rb +1 -16
- data/spec/shakapacker/instance_spec.rb +1 -3
- data/spec/shakapacker/rake_tasks_spec.rb +2 -14
- data/spec/shakapacker/shakapacker_spec.rb +0 -1
- data/spec/shakapacker/test_app/config/shakapacker_css_extract_ignore_order_warnings.yml +0 -1
- data/spec/shakapacker/test_app/config/shakapacker_manifest_path.yml +0 -1
- data/spec/shakapacker/test_app/config/shakapacker_nested_entries.yml +0 -1
- data/spec/shakapacker/test_app/config/shakapacker_other_location.yml +0 -1
- data/spec/shakapacker/test_app/package.json +2 -1
- data/spec/shakapacker/utils_manager_spec.rb +125 -0
- data/spec/shakapacker/version_checker_spec.rb +4 -4
- data/spec/shakapacker/webpack_runner_spec.rb +19 -28
- data/spec/support/package_json_helpers.rb +7 -4
- data/test/helpers.js +67 -0
- data/test/package/config.test.js +50 -0
- data/test/package/dev_server.test.js +44 -0
- data/test/package/development.test.js +43 -0
- data/test/package/env.test.js +57 -0
- data/test/package/environments/base.test.js +105 -0
- data/test/package/environments/development.test.js +50 -0
- data/test/package/environments/production.test.js +106 -0
- data/test/package/index.test.js +45 -0
- data/test/package/production.test.js +32 -0
- data/test/package/rules/babel.test.js +58 -0
- data/test/package/rules/esbuild.test.js +59 -0
- data/test/package/rules/file.test.js +81 -0
- data/test/package/rules/index.test.js +7 -0
- data/test/package/rules/raw.test.js +12 -0
- data/test/package/rules/swc.test.js +59 -0
- data/test/package/staging.test.js +31 -0
- data/test/package/test.test.js +28 -0
- data/yarn.lock +1278 -421
- metadata +52 -102
- data/.github/workflows/jest.yml +0 -34
- data/.github/workflows/js-lint.yml +0 -34
- data/.github/workflows/rubocop.yml +0 -29
- data/.github/workflows/ruby-backward-compatibility.yml +0 -52
- data/lib/install/package.json +0 -15
- data/lib/tasks/shakapacker/check_yarn.rake +0 -34
- data/lib/tasks/shakapacker/yarn_install.rake +0 -24
- data/lib/tasks/webpacker/binstubs.rake +0 -9
- data/lib/tasks/webpacker/check_binstubs.rake +0 -9
- data/lib/tasks/webpacker/check_node.rake +0 -9
- data/lib/tasks/webpacker/check_yarn.rake +0 -9
- data/lib/tasks/webpacker/clean.rake +0 -9
- data/lib/tasks/webpacker/clobber.rake +0 -11
- data/lib/tasks/webpacker/compile.rake +0 -9
- data/lib/tasks/webpacker/info.rake +0 -9
- data/lib/tasks/webpacker/install.rake +0 -9
- data/lib/tasks/webpacker/verify_config.rake +0 -9
- data/lib/tasks/webpacker/verify_install.rake +0 -9
- data/lib/tasks/webpacker/yarn_install.rake +0 -9
- data/lib/tasks/webpacker.rake +0 -20
- data/lib/webpacker/dev_server_runner.rb +0 -9
- data/lib/webpacker/webpack_runner.rb +0 -9
- data/lib/webpacker.rb +0 -4
- data/package/__tests__/config-bc.js +0 -27
- data/package/__tests__/config.js +0 -46
- data/package/__tests__/dev_server-bc.js +0 -46
- data/package/__tests__/dev_server.js +0 -46
- data/package/__tests__/development-bc.js +0 -66
- data/package/__tests__/development.js +0 -66
- data/package/__tests__/env-bc.js +0 -59
- data/package/__tests__/env.js +0 -59
- data/package/__tests__/index-bc.js +0 -22
- data/package/__tests__/index.js +0 -46
- data/package/__tests__/production-bc.js +0 -51
- data/package/__tests__/production.js +0 -51
- data/package/__tests__/staging-bc.js +0 -53
- data/package/__tests__/staging.js +0 -53
- data/package/__tests__/test-bc.js +0 -43
- data/package/__tests__/test.js +0 -43
- data/package/environments/__tests__/base-bc.js +0 -107
- data/package/environments/__tests__/base.js +0 -107
- data/package/environments/__tests__/development.js +0 -53
- data/package/environments/__tests__/production.js +0 -92
- data/package/rules/__tests__/__utils__/webpack.js +0 -50
- data/package/rules/__tests__/babel.js +0 -63
- data/package/rules/__tests__/esbuild.js +0 -64
- data/package/rules/__tests__/file.js +0 -62
- data/package/rules/__tests__/index.js +0 -7
- data/package/rules/__tests__/raw.js +0 -18
- data/package/rules/__tests__/swc.js +0 -63
- data/package/utils/snakeToCamelCase +0 -7
- data/spec/backward_compatibility_specs/command_spec.rb +0 -116
- data/spec/backward_compatibility_specs/compiler_spec.rb +0 -59
- data/spec/backward_compatibility_specs/compiler_strategy_spec.rb +0 -24
- data/spec/backward_compatibility_specs/configuration_spec.rb +0 -294
- data/spec/backward_compatibility_specs/dev_server_runner_spec.rb +0 -206
- data/spec/backward_compatibility_specs/dev_server_spec.rb +0 -47
- data/spec/backward_compatibility_specs/digest_strategy_spec.rb +0 -38
- data/spec/backward_compatibility_specs/engine_rake_tasks_spec.rb +0 -67
- data/spec/backward_compatibility_specs/env_spec.rb +0 -23
- data/spec/backward_compatibility_specs/helper_spec.rb +0 -243
- data/spec/backward_compatibility_specs/instance_spec.rb +0 -31
- data/spec/backward_compatibility_specs/manifest_spec.rb +0 -100
- data/spec/backward_compatibility_specs/mtime_strategy_spec.rb +0 -55
- data/spec/backward_compatibility_specs/rake_tasks_spec.rb +0 -41
- data/spec/backward_compatibility_specs/spec_helper_initializer.rb +0 -24
- data/spec/backward_compatibility_specs/webpack_runner_spec.rb +0 -86
- data/spec/backward_compatibility_specs/webpacker_spec.rb +0 -41
- data/spec/backward_compatibility_specs/webpacker_test_app/.gitignore +0 -2
- data/spec/backward_compatibility_specs/webpacker_test_app/Rakefile +0 -3
- data/spec/backward_compatibility_specs/webpacker_test_app/app/packs/entrypoints/application.js +0 -10
- data/spec/backward_compatibility_specs/webpacker_test_app/app/packs/entrypoints/generated/something.js +0 -2
- data/spec/backward_compatibility_specs/webpacker_test_app/app/packs/entrypoints/multi_entry.css +0 -4
- data/spec/backward_compatibility_specs/webpacker_test_app/app/packs/entrypoints/multi_entry.js +0 -4
- data/spec/backward_compatibility_specs/webpacker_test_app/bin/webpacker +0 -13
- data/spec/backward_compatibility_specs/webpacker_test_app/bin/webpacker-dev-server +0 -13
- data/spec/backward_compatibility_specs/webpacker_test_app/config/application.rb +0 -11
- data/spec/backward_compatibility_specs/webpacker_test_app/config/environment.rb +0 -4
- data/spec/backward_compatibility_specs/webpacker_test_app/config/initializers/inspect_autoload_paths.rb +0 -1
- data/spec/backward_compatibility_specs/webpacker_test_app/config/webpack/webpack.config.js +0 -0
- data/spec/backward_compatibility_specs/webpacker_test_app/config/webpacker.yml +0 -83
- data/spec/backward_compatibility_specs/webpacker_test_app/config/webpacker_css_extract_ignore_order_warnings.yml +0 -84
- data/spec/backward_compatibility_specs/webpacker_test_app/config/webpacker_defaults_fallback.yml +0 -11
- data/spec/backward_compatibility_specs/webpacker_test_app/config/webpacker_manifest_path.yml +0 -80
- data/spec/backward_compatibility_specs/webpacker_test_app/config/webpacker_nested_entries.yml +0 -83
- data/spec/backward_compatibility_specs/webpacker_test_app/config/webpacker_no_precompile.yml +0 -7
- data/spec/backward_compatibility_specs/webpacker_test_app/config/webpacker_other_location.yml +0 -85
- data/spec/backward_compatibility_specs/webpacker_test_app/config/webpacker_public_root.yml +0 -18
- data/spec/backward_compatibility_specs/webpacker_test_app/config.ru +0 -5
- data/spec/backward_compatibility_specs/webpacker_test_app/package.json +0 -13
- data/spec/backward_compatibility_specs/webpacker_test_app/public/packs/manifest.json +0 -58
- data/spec/backward_compatibility_specs/webpacker_test_app/some.config.js +0 -0
- data/spec/backward_compatibility_specs/webpacker_test_app/tmp/shakapacker/last-compilation-digest-production +0 -1
- data/spec/backward_compatibility_specs/webpacker_test_app/yarn.lock +0 -11
@@ -58,10 +58,12 @@ describe "Generator" do
|
|
58
58
|
expect(actual_content).to eq expected_content
|
59
59
|
end
|
60
60
|
|
61
|
-
it "
|
61
|
+
it "ensures the 'packageManager' field is set" do
|
62
62
|
package_json = PackageJson.read(path_in_the_app)
|
63
63
|
|
64
|
-
|
64
|
+
manager_name = fallback_manager.split("_")[0]
|
65
|
+
|
66
|
+
expect(package_json.fetch("packageManager", "")).to match(/#{manager_name}@\d+\.\d+\.\d+/)
|
65
67
|
end
|
66
68
|
|
67
69
|
it "creates webpack config directory and its files" do
|
@@ -161,132 +163,6 @@ describe "Generator" do
|
|
161
163
|
end
|
162
164
|
end
|
163
165
|
end
|
164
|
-
|
165
|
-
context "when not using package_json" do
|
166
|
-
before :all do
|
167
|
-
sh_opts = { fallback_manager: nil }
|
168
|
-
|
169
|
-
sh_in_dir(sh_opts, SPEC_PATH, "cp -r '#{BASE_RAILS_APP_PATH}' '#{TEMP_RAILS_APP_PATH}'")
|
170
|
-
|
171
|
-
Bundler.with_unbundled_env do
|
172
|
-
sh_in_dir(sh_opts, TEMP_RAILS_APP_PATH, "FORCE=true bundle exec rails shakapacker:install")
|
173
|
-
end
|
174
|
-
end
|
175
|
-
|
176
|
-
after :all do
|
177
|
-
Dir.chdir(SPEC_PATH)
|
178
|
-
FileUtils.rm_rf(TEMP_RAILS_APP_PATH)
|
179
|
-
end
|
180
|
-
|
181
|
-
it "creates `config/shakapacker.yml`" do
|
182
|
-
config_file_relative_path = "config/shakapacker.yml"
|
183
|
-
actual_content = read(path_in_the_app(config_file_relative_path))
|
184
|
-
expected_content = read(path_in_the_gem(config_file_relative_path))
|
185
|
-
|
186
|
-
expect(actual_content).to eq expected_content
|
187
|
-
end
|
188
|
-
|
189
|
-
it "replaces package.json with template file" do
|
190
|
-
package_json = PackageJson.read(path_in_the_app)
|
191
|
-
|
192
|
-
expect(package_json.fetch("name", "")).to eq("app")
|
193
|
-
end
|
194
|
-
|
195
|
-
it "creates the webpack config directory and its files" do
|
196
|
-
expected_files = [
|
197
|
-
"webpack.config.js"
|
198
|
-
]
|
199
|
-
|
200
|
-
Dir.chdir(path_in_the_app("config/webpack")) do
|
201
|
-
existing_files_in_config_webpack_dir = Dir.glob("*")
|
202
|
-
expect(existing_files_in_config_webpack_dir).to eq expected_files
|
203
|
-
end
|
204
|
-
end
|
205
|
-
|
206
|
-
it "adds binstubs" do
|
207
|
-
expected_binstubs = []
|
208
|
-
Dir.chdir(File.join(GEM_ROOT, "lib/install/bin")) do
|
209
|
-
expected_binstubs = Dir.glob("bin/*")
|
210
|
-
end
|
211
|
-
|
212
|
-
Dir.chdir(File.join(TEMP_RAILS_APP_PATH, "bin")) do
|
213
|
-
actual_binstubs = Dir.glob("*")
|
214
|
-
|
215
|
-
expect(actual_binstubs).to include(*expected_binstubs)
|
216
|
-
end
|
217
|
-
end
|
218
|
-
|
219
|
-
it "modifies .gitignore" do
|
220
|
-
actual_content = read(path_in_the_app(".gitignore"))
|
221
|
-
|
222
|
-
expect(actual_content).to match ".yarn-integrity"
|
223
|
-
end
|
224
|
-
|
225
|
-
it 'adds <%= javascript_pack_tag "application" %>' do
|
226
|
-
actual_content = read(path_in_the_app("app/views/layouts/application.html.erb"))
|
227
|
-
|
228
|
-
expect(actual_content).to match '<%= javascript_pack_tag "application" %>'
|
229
|
-
end
|
230
|
-
|
231
|
-
it "updates `bin/setup`" do
|
232
|
-
setup_file_content = read(path_in_the_app("bin/setup"))
|
233
|
-
|
234
|
-
expect(setup_file_content).to match %r(^\s*system!\(['"]bin/yarn['"]\))
|
235
|
-
end
|
236
|
-
|
237
|
-
it "uses the shakapacker version in package.json depending on gem version" do
|
238
|
-
npm_version = Shakapacker::Utils::VersionSyntaxConverter.new.rubygem_to_npm(Shakapacker::VERSION)
|
239
|
-
|
240
|
-
package_json = PackageJson.read(path_in_the_app)
|
241
|
-
actual_version = package_json.fetch("dependencies", {})["shakapacker"]
|
242
|
-
|
243
|
-
expect(actual_version).to eq(npm_version)
|
244
|
-
end
|
245
|
-
|
246
|
-
it "adds Shakapacker peer dependencies to package.json" do
|
247
|
-
package_json = PackageJson.read(path_in_the_app)
|
248
|
-
actual_dependencies = package_json.fetch("dependencies", {}).keys
|
249
|
-
|
250
|
-
expected_dependencies = %w(
|
251
|
-
@babel/core
|
252
|
-
@babel/plugin-transform-runtime
|
253
|
-
@babel/preset-env
|
254
|
-
@babel/runtime
|
255
|
-
babel-loader
|
256
|
-
compression-webpack-plugin
|
257
|
-
terser-webpack-plugin
|
258
|
-
webpack
|
259
|
-
webpack-assets-manifest
|
260
|
-
webpack-cli
|
261
|
-
webpack-merge
|
262
|
-
)
|
263
|
-
|
264
|
-
expect(actual_dependencies).to include(*expected_dependencies)
|
265
|
-
end
|
266
|
-
|
267
|
-
it "adds Shakapacker peer dev dependencies to package.json" do
|
268
|
-
package_json = PackageJson.read(path_in_the_app)
|
269
|
-
actual_dev_dependencies = package_json.fetch("devDependencies", {}).keys
|
270
|
-
|
271
|
-
expected_dev_dependencies = %w(
|
272
|
-
webpack-dev-server
|
273
|
-
)
|
274
|
-
|
275
|
-
expect(actual_dev_dependencies).to include(*expected_dev_dependencies)
|
276
|
-
end
|
277
|
-
|
278
|
-
context "with a basic react app setup" do
|
279
|
-
it "passes the test for rendering react component on the page" do
|
280
|
-
sh_opts = { fallback_manager: nil }
|
281
|
-
|
282
|
-
Bundler.with_unbundled_env do
|
283
|
-
sh_in_dir(sh_opts, TEMP_RAILS_APP_PATH, "./bin/rails app:template LOCATION=../e2e_template/template.rb")
|
284
|
-
|
285
|
-
expect(sh_in_dir(sh_opts, TEMP_RAILS_APP_PATH, "bundle exec rspec")).to be_truthy
|
286
|
-
end
|
287
|
-
end
|
288
|
-
end
|
289
|
-
end
|
290
166
|
end
|
291
167
|
|
292
168
|
private
|
@@ -306,14 +182,8 @@ describe "Generator" do
|
|
306
182
|
def sort_out_package_json(opts)
|
307
183
|
ENV["PATH"] = "#{SPEC_PATH}/fake-bin:#{ENV["PATH"]}"
|
308
184
|
|
309
|
-
|
310
|
-
|
311
|
-
ENV["SHAKAPACKER_USE_PACKAGE_JSON_GEM"] = "false"
|
312
|
-
else
|
313
|
-
ENV["SHAKAPACKER_EXPECTED_PACKAGE_MANGER"] = opts[:fallback_manager]
|
314
|
-
ENV["SHAKAPACKER_USE_PACKAGE_JSON_GEM"] = "true"
|
315
|
-
ENV["PACKAGE_JSON_FALLBACK_MANAGER"] = opts[:fallback_manager]
|
316
|
-
end
|
185
|
+
ENV["SHAKAPACKER_EXPECTED_PACKAGE_MANGER"] = opts[:fallback_manager]
|
186
|
+
ENV["PACKAGE_JSON_FALLBACK_MANAGER"] = opts[:fallback_manager]
|
317
187
|
end
|
318
188
|
|
319
189
|
def sh_in_dir(opts, dir, *shell_commands)
|
@@ -1,4 +1,5 @@
|
|
1
1
|
require_relative "spec_helper_initializer"
|
2
|
+
require "ostruct"
|
2
3
|
|
3
4
|
describe "Shakapacker::Compiler" do
|
4
5
|
it "accepts custom environment variables" do
|
@@ -48,12 +49,9 @@ describe "Shakapacker::Compiler" do
|
|
48
49
|
|
49
50
|
it "accepts external env variables" do
|
50
51
|
expect(Shakapacker.compiler.send(:webpack_env)["SHAKAPACKER_ASSET_HOST"]).to be nil
|
51
|
-
expect(Shakapacker.compiler.send(:webpack_env)["SHAKAPACKER_RELATIVE_URL_ROOT"]).to be nil
|
52
52
|
|
53
53
|
allow(ENV).to receive(:fetch).with("SHAKAPACKER_ASSET_HOST", nil).and_return("foo.bar")
|
54
|
-
allow(ENV).to receive(:fetch).with("SHAKAPACKER_RELATIVE_URL_ROOT", nil).and_return("/baz")
|
55
54
|
|
56
55
|
expect(Shakapacker.compiler.send(:webpack_env)["SHAKAPACKER_ASSET_HOST"]).to eq "foo.bar"
|
57
|
-
expect(Shakapacker.compiler.send(:webpack_env)["SHAKAPACKER_RELATIVE_URL_ROOT"]).to eq "/baz"
|
58
56
|
end
|
59
57
|
end
|
@@ -113,8 +113,8 @@ describe "Shakapacker::Configuration" do
|
|
113
113
|
end
|
114
114
|
|
115
115
|
describe "#ensure_consistent_versioning?" do
|
116
|
-
it "returns
|
117
|
-
expect(config.ensure_consistent_versioning?).to be
|
116
|
+
it "returns true in production environment" do
|
117
|
+
expect(config.ensure_consistent_versioning?).to be true
|
118
118
|
end
|
119
119
|
|
120
120
|
it "returns true in development environment" do
|
@@ -123,9 +123,9 @@ describe "Shakapacker::Configuration" do
|
|
123
123
|
end
|
124
124
|
end
|
125
125
|
|
126
|
-
it "returns
|
126
|
+
it "returns true in test environment" do
|
127
127
|
with_rails_env("test") do
|
128
|
-
expect(Shakapacker.config.ensure_consistent_versioning?).to be
|
128
|
+
expect(Shakapacker.config.ensure_consistent_versioning?).to be true
|
129
129
|
end
|
130
130
|
end
|
131
131
|
end
|
@@ -374,56 +374,4 @@ describe "Shakapacker::Configuration" do
|
|
374
374
|
end
|
375
375
|
end
|
376
376
|
|
377
|
-
describe "#relative_url_root" do
|
378
|
-
let(:config) do
|
379
|
-
Shakapacker::Configuration.new(
|
380
|
-
root_path: ROOT_PATH,
|
381
|
-
config_path: Pathname.new(File.expand_path("./test_app/config/shakapacker.yml", __dir__)),
|
382
|
-
env: "production"
|
383
|
-
)
|
384
|
-
end
|
385
|
-
|
386
|
-
context "with SHAKAPACKER_RELATIVE_URL_ROOT set" do
|
387
|
-
before do
|
388
|
-
expect(ENV).to receive(:fetch).with("SHAKAPACKER_RELATIVE_URL_ROOT", nil).and_return("custom_value")
|
389
|
-
end
|
390
|
-
it "shows deprecation message" do
|
391
|
-
expect { config.relative_url_root }.to output(/deprecated/).to_stdout
|
392
|
-
end
|
393
|
-
|
394
|
-
it "returns the value of SHAKAPACKER_RELATIVE_URL_ROOT" do
|
395
|
-
expect(config.relative_url_root).to eq "custom_value"
|
396
|
-
end
|
397
|
-
end
|
398
|
-
|
399
|
-
context "without SHAKAPACKER_RELATIVE_URL_ROOT set" do
|
400
|
-
it "returns relative_url_root in shakapacker.yml if set" do
|
401
|
-
expect(config).to receive(:fetch).with(:relative_url_root).and_return("value-in-config-file")
|
402
|
-
expect(ENV).to receive(:fetch).with("SHAKAPACKER_RELATIVE_URL_ROOT", "value-in-config-file").and_return("value-in-config-file")
|
403
|
-
|
404
|
-
expect(config.relative_url_root).to eq "value-in-config-file"
|
405
|
-
end
|
406
|
-
|
407
|
-
context "without relative_url_root set in the shakapacker.yml" do
|
408
|
-
it "returns ActionController::Base.relative_url_root if SHAKAPACKER_RELATIVE_URL_ROOT is not set" do
|
409
|
-
expect(ActionController::Base).to receive(:relative_url_root).and_return("abcd")
|
410
|
-
expect(ENV).to receive(:fetch).with("SHAKAPACKER_RELATIVE_URL_ROOT", "abcd").and_return("abcd")
|
411
|
-
|
412
|
-
expect(config.relative_url_root).to eq "abcd"
|
413
|
-
end
|
414
|
-
|
415
|
-
context "without ActionController::Base.relative_url_root returing any value" do
|
416
|
-
it "returns an empty string" do
|
417
|
-
expect(ENV).to receive(:fetch).with("SHAKAPACKER_RELATIVE_URL_ROOT", nil).and_return(nil)
|
418
|
-
|
419
|
-
expect(config.relative_url_root).to be nil
|
420
|
-
end
|
421
|
-
|
422
|
-
it "doesn't shows deprecation message" do
|
423
|
-
expect { config.relative_url_root }.to_not output(/deprecated/).to_stdout
|
424
|
-
end
|
425
|
-
end
|
426
|
-
end
|
427
|
-
end
|
428
|
-
end
|
429
377
|
end
|
@@ -2,6 +2,13 @@ require_relative "spec_helper_initializer"
|
|
2
2
|
require "shakapacker/dev_server_runner"
|
3
3
|
|
4
4
|
describe "DevServerRunner" do
|
5
|
+
around do |example|
|
6
|
+
within_temp_directory do
|
7
|
+
FileUtils.cp_r(File.expand_path("./test_app", __dir__), Dir.pwd)
|
8
|
+
Dir.chdir("test_app") { example.run }
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
5
12
|
before do
|
6
13
|
@original_node_env, ENV["NODE_ENV"] = ENV["NODE_ENV"], "development"
|
7
14
|
@original_rails_env, ENV["RAILS_ENV"] = ENV["RAILS_ENV"], "development"
|
@@ -14,15 +21,21 @@ describe "DevServerRunner" do
|
|
14
21
|
ENV["SHAKAPACKER_CONFIG"] = @original_shakapacker_config
|
15
22
|
end
|
16
23
|
|
17
|
-
let(:test_app_path) {
|
24
|
+
let(:test_app_path) { Dir.pwd }
|
18
25
|
|
19
26
|
NODE_PACKAGE_MANAGERS.each do |fallback_manager|
|
20
27
|
context "when using package_json with #{fallback_manager} as the manager" do
|
21
|
-
|
28
|
+
before do
|
29
|
+
manager_name = fallback_manager.split("_")[0]
|
30
|
+
manager_version = "1.2.3"
|
31
|
+
manager_version = "4.5.6" if fallback_manager == "yarn_berry"
|
22
32
|
|
23
|
-
|
33
|
+
PackageJson.read.merge! { { "packageManager" => "#{manager_name}@#{manager_version}" } }
|
24
34
|
|
25
|
-
|
35
|
+
allow(Shakapacker::Utils::Manager).to receive(:error_unless_package_manager_is_obvious!)
|
36
|
+
end
|
37
|
+
|
38
|
+
let(:package_json) { PackageJson.read(test_app_path) }
|
26
39
|
|
27
40
|
it "uses the expected package manager", unless: fallback_manager == "yarn_classic" do
|
28
41
|
cmd = package_json.manager.native_exec_command("webpack", ["serve", "--config", "#{test_app_path}/config/webpack/webpack.config.js"])
|
@@ -104,116 +117,20 @@ describe "DevServerRunner" do
|
|
104
117
|
end
|
105
118
|
end
|
106
119
|
|
107
|
-
context "when not using package_json" do
|
108
|
-
with_use_package_json_gem(enabled: false)
|
109
|
-
|
110
|
-
it "supports running via node modules" do
|
111
|
-
cmd = ["#{test_app_path}/node_modules/.bin/webpack", "serve", "--config", "#{test_app_path}/config/webpack/webpack.config.js"]
|
112
|
-
|
113
|
-
verify_command(cmd, use_node_modules: true)
|
114
|
-
end
|
115
|
-
|
116
|
-
it "supports running via yarn" do
|
117
|
-
cmd = ["yarn", "webpack", "serve", "--config", "#{test_app_path}/config/webpack/webpack.config.js"]
|
118
|
-
|
119
|
-
verify_command(cmd, use_node_modules: false)
|
120
|
-
end
|
121
|
-
|
122
|
-
it "passes on arguments" do
|
123
|
-
cmd = ["#{test_app_path}/node_modules/.bin/webpack", "serve", "--config", "#{test_app_path}/config/webpack/webpack.config.js", "--quiet"]
|
124
|
-
|
125
|
-
verify_command(cmd, argv: (["--quiet"]))
|
126
|
-
end
|
127
|
-
|
128
|
-
it "does not automatically pass the --https flag" do
|
129
|
-
cmd = ["#{test_app_path}/node_modules/.bin/webpack", "serve", "--config", "#{test_app_path}/config/webpack/webpack.config.js"]
|
130
|
-
|
131
|
-
allow(Shakapacker::DevServer).to receive(:new).and_return(
|
132
|
-
double(
|
133
|
-
host: "localhost",
|
134
|
-
port: "3035",
|
135
|
-
pretty?: false,
|
136
|
-
protocol: "https",
|
137
|
-
hmr?: true
|
138
|
-
)
|
139
|
-
)
|
140
|
-
|
141
|
-
verify_command(cmd)
|
142
|
-
end
|
143
|
-
|
144
|
-
it "supports the https flag" do
|
145
|
-
cmd = ["#{test_app_path}/node_modules/.bin/webpack", "serve", "--config", "#{test_app_path}/config/webpack/webpack.config.js", "--https"]
|
146
|
-
|
147
|
-
allow(Shakapacker::DevServer).to receive(:new).and_return(
|
148
|
-
double(
|
149
|
-
host: "localhost",
|
150
|
-
port: "3035",
|
151
|
-
pretty?: false,
|
152
|
-
protocol: "https",
|
153
|
-
hmr?: true
|
154
|
-
)
|
155
|
-
)
|
156
|
-
|
157
|
-
verify_command(cmd, argv: ["--https"])
|
158
|
-
end
|
159
|
-
|
160
|
-
it "supports disabling hot module reloading" do
|
161
|
-
cmd = ["#{test_app_path}/node_modules/.bin/webpack", "serve", "--config", "#{test_app_path}/config/webpack/webpack.config.js", "--no-hot"]
|
162
|
-
|
163
|
-
allow(Shakapacker::DevServer).to receive(:new).and_return(
|
164
|
-
double(
|
165
|
-
host: "localhost",
|
166
|
-
port: "3035",
|
167
|
-
pretty?: false,
|
168
|
-
protocol: "http",
|
169
|
-
hmr?: false
|
170
|
-
)
|
171
|
-
)
|
172
|
-
|
173
|
-
verify_command(cmd)
|
174
|
-
end
|
175
|
-
|
176
|
-
it "supports --hot being 'only'" do
|
177
|
-
cmd = ["#{test_app_path}/node_modules/.bin/webpack", "serve", "--config", "#{test_app_path}/config/webpack/webpack.config.js", "--hot", "only"]
|
178
|
-
|
179
|
-
allow(Shakapacker::DevServer).to receive(:new).and_return(
|
180
|
-
double(
|
181
|
-
host: "localhost",
|
182
|
-
port: "3035",
|
183
|
-
pretty?: false,
|
184
|
-
protocol: "http",
|
185
|
-
hmr?: "only"
|
186
|
-
)
|
187
|
-
)
|
188
|
-
|
189
|
-
verify_command(cmd)
|
190
|
-
end
|
191
|
-
|
192
|
-
it "accepts environment variables" do
|
193
|
-
cmd = ["#{test_app_path}/node_modules/.bin/webpack", "serve", "--config", "#{test_app_path}/config/webpack/webpack.config.js"]
|
194
|
-
env = Shakapacker::Compiler.env.dup
|
195
|
-
|
196
|
-
ENV["SHAKAPACKER_CONFIG"] = env["SHAKAPACKER_CONFIG"] = "#{test_app_path}/config/shakapacker_other_location.yml"
|
197
|
-
env["WEBPACK_SERVE"] = "true"
|
198
|
-
|
199
|
-
verify_command(cmd, env: env)
|
200
|
-
end
|
201
|
-
end
|
202
|
-
|
203
120
|
private
|
204
121
|
|
205
|
-
def verify_command(cmd,
|
122
|
+
def verify_command(cmd, argv: [], env: Shakapacker::Compiler.env)
|
206
123
|
Dir.chdir(test_app_path) do
|
207
124
|
klass = Shakapacker::DevServerRunner
|
208
125
|
instance = klass.new(argv)
|
209
126
|
|
210
127
|
allow(klass).to receive(:new).and_return(instance)
|
211
|
-
allow(instance).to receive(:node_modules_bin_exist?).and_return(use_node_modules)
|
212
128
|
allow(Kernel).to receive(:exec).with(env, *cmd)
|
213
129
|
|
214
130
|
klass.run(argv)
|
215
131
|
|
216
132
|
expect(Kernel).to have_received(:exec).with(env, *cmd)
|
133
|
+
expect(Shakapacker::Utils::Manager).to have_received(:error_unless_package_manager_is_obvious!)
|
217
134
|
end
|
218
135
|
end
|
219
136
|
end
|
@@ -17,12 +17,6 @@ describe "DevServer" do
|
|
17
17
|
end
|
18
18
|
end
|
19
19
|
|
20
|
-
it "doesn't use https in development environment" do
|
21
|
-
with_rails_env("development") do
|
22
|
-
expect(Shakapacker.dev_server.https?).to be false
|
23
|
-
end
|
24
|
-
end
|
25
|
-
|
26
20
|
it "uses http protocol in development environment" do
|
27
21
|
with_rails_env("development") do
|
28
22
|
expect(Shakapacker.dev_server.protocol).to eq "http"
|
@@ -48,7 +42,7 @@ describe "DevServer" do
|
|
48
42
|
context "#protocol in development environment" do
|
49
43
|
let(:dev_server) { Shakapacker.dev_server }
|
50
44
|
|
51
|
-
it "returns `http` by default (with unset `server`
|
45
|
+
it "returns `http` by default (with unset `server`)" do
|
52
46
|
with_rails_env("development") do
|
53
47
|
expect(dev_server.protocol).to eq "http"
|
54
48
|
end
|
@@ -61,15 +55,6 @@ describe "DevServer" do
|
|
61
55
|
expect(dev_server.protocol).to eq "https"
|
62
56
|
end
|
63
57
|
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
|
72
|
-
end
|
73
58
|
end
|
74
59
|
|
75
60
|
context "#server in development environment" do
|
@@ -11,7 +11,7 @@ describe "EngineRakeTasks" do
|
|
11
11
|
|
12
12
|
NODE_PACKAGE_MANAGERS.each do |fallback_manager|
|
13
13
|
context "when using package_json with #{fallback_manager} as the manager" do
|
14
|
-
|
14
|
+
with_package_json_fallback_manager(fallback_manager)
|
15
15
|
|
16
16
|
it "mounts app:shakapacker task successfully" do
|
17
17
|
output = Dir.chdir(mounted_app_path) { `rake -T` }
|
@@ -26,21 +26,6 @@ describe "EngineRakeTasks" do
|
|
26
26
|
end
|
27
27
|
end
|
28
28
|
|
29
|
-
context "when not using package_json" do
|
30
|
-
with_use_package_json_gem(enabled: false)
|
31
|
-
|
32
|
-
it "mounts app:shakapacker task successfully" do
|
33
|
-
output = Dir.chdir(mounted_app_path) { `rake -T` }
|
34
|
-
|
35
|
-
expect(output).to include "app:shakapacker"
|
36
|
-
end
|
37
|
-
|
38
|
-
it "only adds expected files to bin directory when binstubs is run" do
|
39
|
-
Dir.chdir(mounted_app_path) { `bundle exec rake app:shakapacker:binstubs` }
|
40
|
-
expected_binstub_paths.each { |path| expect(File.exist?(path)).to be true }
|
41
|
-
end
|
42
|
-
end
|
43
|
-
|
44
29
|
private
|
45
30
|
def mounted_app_path
|
46
31
|
File.expand_path("../mounted_app", __dir__)
|
@@ -2,13 +2,10 @@ require_relative "spec_helper_initializer"
|
|
2
2
|
|
3
3
|
describe "Shakapacker::Instance" do
|
4
4
|
before :each do
|
5
|
-
ENV.delete("WEBPACKER_CONFIG")
|
6
5
|
ENV.delete("SHAKAPACKER_CONFIG")
|
7
|
-
Shakapacker.instance = Shakapacker::Instance.new
|
8
6
|
end
|
9
7
|
|
10
8
|
after :each do
|
11
|
-
ENV.delete("WEBPACKER_CONFIG")
|
12
9
|
ENV.delete("SHAKAPACKER_CONFIG")
|
13
10
|
Shakapacker.instance = Shakapacker::Instance.new
|
14
11
|
end
|
@@ -22,6 +19,7 @@ describe "Shakapacker::Instance" do
|
|
22
19
|
|
23
20
|
it "uses the SHAKAPACKER_CONFIG env variable for the config file path" do
|
24
21
|
ENV["SHAKAPACKER_CONFIG"] = "/some/random/path.yml"
|
22
|
+
Shakapacker.instance = Shakapacker::Instance.new
|
25
23
|
|
26
24
|
actual_config_path = "/some/random/path.yml"
|
27
25
|
expected_config_path = Shakapacker.config.config_path.to_s
|
@@ -63,13 +63,7 @@ describe "RakeTasks" do
|
|
63
63
|
FileUtils.mv("bin/shakapacker_renamed", "bin/shakapacker")
|
64
64
|
end
|
65
65
|
|
66
|
-
it "
|
67
|
-
with_temporary_file("bin/webpacker") do
|
68
|
-
expect { system("bundle exec rake shakapacker:check_binstubs") }.to output(/DEPRECATION/).to_stdout_from_any_process
|
69
|
-
end
|
70
|
-
end
|
71
|
-
|
72
|
-
it "fails otherwise" do
|
66
|
+
it "fails" do
|
73
67
|
expect { system("bundle exec rake shakapacker:check_binstubs") }.to output(/Couldn't find shakapacker binstubs!/).to_stdout_from_any_process
|
74
68
|
end
|
75
69
|
end
|
@@ -83,13 +77,7 @@ describe "RakeTasks" do
|
|
83
77
|
FileUtils.mv("bin/shakapacker-dev-server_renamed", "bin/shakapacker-dev-server")
|
84
78
|
end
|
85
79
|
|
86
|
-
it "
|
87
|
-
with_temporary_file("bin/webpacker-dev-server") do
|
88
|
-
expect { system("bundle exec rake shakapacker:check_binstubs") }.to output(/DEPRECATION/).to_stdout_from_any_process
|
89
|
-
end
|
90
|
-
end
|
91
|
-
|
92
|
-
it "fails otherwise" do
|
80
|
+
it "fails" do
|
93
81
|
expect { system("bundle exec rake shakapacker:check_binstubs") }.to output(/Couldn't find shakapacker binstubs!/).to_stdout_from_any_process
|
94
82
|
end
|
95
83
|
end
|
@@ -8,7 +8,6 @@ describe "Shakapacker" do
|
|
8
8
|
allow(dev_server).to receive(:host).and_return("localhost")
|
9
9
|
allow(dev_server).to receive(:port).and_return("3035")
|
10
10
|
allow(dev_server).to receive(:pretty?).and_return(false)
|
11
|
-
allow(dev_server).to receive(:https?).and_return(true)
|
12
11
|
allow(dev_server).to receive(:running?).and_return(true)
|
13
12
|
end
|
14
13
|
|