shakapacker 6.6.0 → 7.0.0.rc.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/workflows/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
@@ -0,0 +1,56 @@
|
|
1
|
+
require_relative "spec_helper_initializer"
|
2
|
+
# Requiring from webpacker directory to ensure old ./bin/webpacker-dev-server works fine
|
3
|
+
require "webpacker/webpack_runner"
|
4
|
+
|
5
|
+
describe "WebpackRunner" do
|
6
|
+
before :all do
|
7
|
+
@original_node_env, ENV["NODE_ENV"] = ENV["NODE_ENV"], "development"
|
8
|
+
@original_rails_env, ENV["RAILS_ENV"] = ENV["RAILS_ENV"], "development"
|
9
|
+
end
|
10
|
+
|
11
|
+
after :all do
|
12
|
+
ENV["NODE_ENV"] = @original_node_env
|
13
|
+
ENV["RAILS_ENV"] = @original_rails_env
|
14
|
+
end
|
15
|
+
|
16
|
+
it "runs cmd via node_modules" do
|
17
|
+
cmd = ["#{test_app_path}/node_modules/.bin/webpack", "--config", "#{test_app_path}/config/webpack/webpack.config.js"]
|
18
|
+
|
19
|
+
verify_command(cmd, use_node_modules: true)
|
20
|
+
end
|
21
|
+
|
22
|
+
it "runs cmd via yarn" do
|
23
|
+
cmd = ["yarn", "webpack", "--config", "#{test_app_path}/config/webpack/webpack.config.js"]
|
24
|
+
|
25
|
+
verify_command(cmd, use_node_modules: false)
|
26
|
+
end
|
27
|
+
|
28
|
+
it "runs cmd argv" do
|
29
|
+
cmd = ["#{test_app_path}/node_modules/.bin/webpack", "--config", "#{test_app_path}/config/webpack/webpack.config.js", "--watch"]
|
30
|
+
|
31
|
+
verify_command(cmd, argv: ["--watch"])
|
32
|
+
end
|
33
|
+
|
34
|
+
private
|
35
|
+
def test_app_path
|
36
|
+
File.expand_path("webpacker_test_app", __dir__)
|
37
|
+
end
|
38
|
+
|
39
|
+
def verify_command(cmd, use_node_modules: true, argv: [])
|
40
|
+
cwd = Dir.pwd
|
41
|
+
Dir.chdir(test_app_path)
|
42
|
+
|
43
|
+
klass = Webpacker::WebpackRunner
|
44
|
+
instance = klass.new(argv)
|
45
|
+
|
46
|
+
allow(klass).to receive(:new).and_return(instance)
|
47
|
+
allow(instance).to receive(:node_modules_bin_exist?).and_return(use_node_modules)
|
48
|
+
allow(Kernel).to receive(:exec)
|
49
|
+
|
50
|
+
klass.run(argv)
|
51
|
+
|
52
|
+
expect(Kernel).to have_received(:exec).with(Webpacker::Compiler.env, *cmd)
|
53
|
+
ensure
|
54
|
+
Dir.chdir(cwd)
|
55
|
+
end
|
56
|
+
end
|
@@ -0,0 +1,41 @@
|
|
1
|
+
require_relative "spec_helper_initializer"
|
2
|
+
|
3
|
+
describe "webpacker" do
|
4
|
+
describe "#inline_css?" do
|
5
|
+
let(:dev_server) { instance_double("Webpacker::DevServer") }
|
6
|
+
|
7
|
+
before :each do
|
8
|
+
allow(dev_server).to receive(:host).and_return("localhost")
|
9
|
+
allow(dev_server).to receive(:port).and_return("3035")
|
10
|
+
allow(dev_server).to receive(:pretty?).and_return(false)
|
11
|
+
allow(dev_server).to receive(:https?).and_return(true)
|
12
|
+
allow(dev_server).to receive(:running?).and_return(true)
|
13
|
+
end
|
14
|
+
|
15
|
+
it "returns nil with disabled dev_server" do
|
16
|
+
expect(Webpacker.inlining_css?).to be nil
|
17
|
+
end
|
18
|
+
|
19
|
+
it "returns true with enabled hmr" do
|
20
|
+
allow(dev_server).to receive(:hmr?).and_return(true)
|
21
|
+
allow(dev_server).to receive(:inline_css?).and_return(true)
|
22
|
+
|
23
|
+
allow(Webpacker.instance).to receive(:dev_server).and_return(dev_server)
|
24
|
+
|
25
|
+
expect(Webpacker.inlining_css?).to be true
|
26
|
+
end
|
27
|
+
|
28
|
+
it "returns false with enabled hmr and explicitly setting inline_css to false" do
|
29
|
+
allow(dev_server).to receive(:hmr?).and_return(true)
|
30
|
+
allow(dev_server).to receive(:inline_css?).and_return(false)
|
31
|
+
|
32
|
+
allow(Webpacker.instance).to receive(:dev_server).and_return(dev_server)
|
33
|
+
|
34
|
+
expect(Webpacker.inlining_css?).to be false
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
it "has app_autoload_paths cleanup" do
|
39
|
+
expect($test_app_autoload_paths_in_initializer).to eq []
|
40
|
+
end
|
41
|
+
end
|
File without changes
|
@@ -0,0 +1,11 @@
|
|
1
|
+
require "action_controller/railtie"
|
2
|
+
require "action_view/railtie"
|
3
|
+
require "shakapacker"
|
4
|
+
|
5
|
+
module WebpackerTestApp
|
6
|
+
class Application < ::Rails::Application
|
7
|
+
config.secret_key_base = "abcdef"
|
8
|
+
config.eager_load = true
|
9
|
+
config.active_support.test_order = :sorted
|
10
|
+
end
|
11
|
+
end
|
@@ -0,0 +1 @@
|
|
1
|
+
$test_app_autoload_paths_in_initializer = ActiveSupport::Dependencies.autoload_paths
|
File without changes
|
@@ -0,0 +1,58 @@
|
|
1
|
+
{
|
2
|
+
"bootstrap.css": "/packs/bootstrap-c38deda30895059837cf.css",
|
3
|
+
"application.css": "/packs/application-dd6b1cd38bfa093df600.css",
|
4
|
+
"bootstrap.js": "/packs/bootstrap-300631c4f0e0f9c865bc.js",
|
5
|
+
"main.js": "/packs/main-e323a53c7f30f5d53cbb.js",
|
6
|
+
"application.js": "/packs/application-k344a6d59eef8632c9d1.js",
|
7
|
+
"application.png": "/packs/application-k344a6d59eef8632c9d1.png",
|
8
|
+
"fonts/fa-regular-400.woff2": "/packs/fonts/fa-regular-400-944fb546bd7018b07190a32244f67dc9.woff2",
|
9
|
+
"static/image.jpg": "/packs/static/image-c38deda30895059837cf.jpg",
|
10
|
+
"static/image-2x.jpg": "/packs/static/image-2x-7cca48e6cae66ec07b8e.jpg",
|
11
|
+
"static/nested/image.jpg": "/packs/static/nested/image-c38deda30895059837cf.jpg",
|
12
|
+
"static/mb-icon.png": "/packs/static/mb-icon-c38deda30895059837cf.png",
|
13
|
+
"static/nested/mb-icon.png": "/packs/static/nested/mb-icon-c38deda30895059837cf.png",
|
14
|
+
"entrypoints": {
|
15
|
+
"application": {
|
16
|
+
"assets": {
|
17
|
+
"js": [
|
18
|
+
"/packs/vendors~application~bootstrap-c20632e7baf2c81200d3.chunk.js",
|
19
|
+
"/packs/vendors~application-e55f2aae30c07fb6d82a.chunk.js",
|
20
|
+
"/packs/application-k344a6d59eef8632c9d1.js"
|
21
|
+
],
|
22
|
+
"css": [
|
23
|
+
"/packs/1-c20632e7baf2c81200d3.chunk.css",
|
24
|
+
"/packs/application-k344a6d59eef8632c9d1.chunk.css"
|
25
|
+
]
|
26
|
+
}
|
27
|
+
},
|
28
|
+
"bootstrap": {
|
29
|
+
"assets": {
|
30
|
+
"js": [
|
31
|
+
"/packs/bootstrap-300631c4f0e0f9c865bc.js"
|
32
|
+
]
|
33
|
+
}
|
34
|
+
},
|
35
|
+
"main": {
|
36
|
+
"assets": {
|
37
|
+
"js": [
|
38
|
+
"/packs/main-e323a53c7f30f5d53cbb.js"
|
39
|
+
]
|
40
|
+
}
|
41
|
+
},
|
42
|
+
"hello_stimulus": {
|
43
|
+
"assets": {
|
44
|
+
"css": [
|
45
|
+
"/packs/1-c20632e7baf2c81200d3.chunk.css",
|
46
|
+
"/packs/hello_stimulus-k344a6d59eef8632c9d1.chunk.css"
|
47
|
+
]
|
48
|
+
}
|
49
|
+
},
|
50
|
+
"print/application": {
|
51
|
+
"assets": {
|
52
|
+
"css": [
|
53
|
+
"/packs/print/application-983b6c164a47f7ed49cd.css"
|
54
|
+
]
|
55
|
+
}
|
56
|
+
}
|
57
|
+
}
|
58
|
+
}
|
File without changes
|
@@ -0,0 +1 @@
|
|
1
|
+
70edce1bd3ecd60639ea9e56a3cd098a3641ca07
|
@@ -0,0 +1,11 @@
|
|
1
|
+
# THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY.
|
2
|
+
# yarn lockfile v1
|
3
|
+
|
4
|
+
|
5
|
+
left-pad@^1.2.0:
|
6
|
+
version "1.2.0"
|
7
|
+
resolved "https://registry.yarnpkg.com/left-pad/-/left-pad-1.2.0.tgz#d30a73c6b8201d8f7d8e7956ba9616087a68e0ee"
|
8
|
+
|
9
|
+
right-pad@^1.0.1:
|
10
|
+
version "1.0.1"
|
11
|
+
resolved "https://registry.yarnpkg.com/right-pad/-/right-pad-1.0.1.tgz#8ca08c2cbb5b55e74dafa96bf7fd1a27d568c8d0"
|
data/spec/command_spec.rb
CHANGED
@@ -1,27 +1,29 @@
|
|
1
|
+
require_relative "spec_helper_initializer"
|
2
|
+
|
1
3
|
describe "Command" do
|
2
4
|
before do
|
3
|
-
allow(
|
5
|
+
allow(Shakapacker.logger).to receive(:info)
|
4
6
|
end
|
5
7
|
|
6
8
|
describe "#compile" do
|
7
9
|
it "returns success status when stale" do
|
8
|
-
expect(
|
9
|
-
expect(
|
10
|
+
expect(Shakapacker.compiler).to receive(:stale?).and_return(true)
|
11
|
+
expect(Shakapacker.compiler).to receive(:run_webpack).and_return(true)
|
10
12
|
|
11
|
-
expect(
|
13
|
+
expect(Shakapacker.commands.compile).to be true
|
12
14
|
end
|
13
15
|
|
14
16
|
it "returns success status when fresh" do
|
15
|
-
expect(
|
17
|
+
expect(Shakapacker.compiler).to receive(:stale?).and_return(false)
|
16
18
|
|
17
|
-
expect(
|
19
|
+
expect(Shakapacker.commands.compile).to be true
|
18
20
|
end
|
19
21
|
|
20
22
|
it "returns failure status when stale" do
|
21
|
-
expect(
|
22
|
-
expect(
|
23
|
+
expect(Shakapacker.compiler).to receive(:stale?).and_return(true)
|
24
|
+
expect(Shakapacker.compiler).to receive(:run_webpack).and_return(false)
|
23
25
|
|
24
|
-
expect(
|
26
|
+
expect(Shakapacker.commands.compile).to be false
|
25
27
|
end
|
26
28
|
end
|
27
29
|
|
@@ -30,7 +32,7 @@ describe "Command" do
|
|
30
32
|
let(:prev_files) do
|
31
33
|
# Test assets to be kept and deleted, path and mtime
|
32
34
|
{
|
33
|
-
# recent versions to be kept with
|
35
|
+
# recent versions to be kept with Shakapacker.commands.clean(count = 2)
|
34
36
|
"js/application-deadbeef.js" => now - 4000,
|
35
37
|
"js/common-deadbeee.js" => now - 4002,
|
36
38
|
"css/common-deadbeed.css" => now - 4004,
|
@@ -39,12 +41,12 @@ describe "Command" do
|
|
39
41
|
"js/common-1eadbeee.js" => now - 8002,
|
40
42
|
"css/common-1eadbeed.css" => now - 8004,
|
41
43
|
"media/images/logo-1eadbeeb.css" => now - 8006,
|
42
|
-
# new files to be kept with
|
44
|
+
# new files to be kept with Shakapacker.commands.clean(age = 3600)
|
43
45
|
"js/brandnew-0001.js" => now,
|
44
46
|
"js/brandnew-0002.js" => now - 10,
|
45
47
|
"js/brandnew-0003.js" => now - 20,
|
46
48
|
"js/brandnew-0004.js" => now - 40,
|
47
|
-
}.transform_keys { |path| "#{
|
49
|
+
}.transform_keys { |path| "#{Shakapacker.config.public_output_path}/#{path}" }
|
48
50
|
end
|
49
51
|
|
50
52
|
let(:expired_files) do
|
@@ -54,7 +56,7 @@ describe "Command" do
|
|
54
56
|
"js/common-0eadbeee.js" => now - 9002,
|
55
57
|
"css/common-0eadbeed.css" => now - 9004,
|
56
58
|
"js/brandnew-0005.js" => now - 3640,
|
57
|
-
}.transform_keys { |path| "#{
|
59
|
+
}.transform_keys { |path| "#{Shakapacker.config.public_output_path}/#{path}" }
|
58
60
|
end
|
59
61
|
|
60
62
|
let(:all_files) { prev_files.merge(expired_files) }
|
@@ -66,7 +68,7 @@ describe "Command" do
|
|
66
68
|
before :context do
|
67
69
|
@dir_glob_stub = Proc.new { |arg|
|
68
70
|
case arg
|
69
|
-
when "#{
|
71
|
+
when "#{Shakapacker.config.public_output_path}/**/*"
|
70
72
|
all_files.keys
|
71
73
|
else
|
72
74
|
[]
|
@@ -76,7 +78,7 @@ describe "Command" do
|
|
76
78
|
|
77
79
|
it "works with nested hashes and without any compiled files" do
|
78
80
|
allow(File).to receive(:delete).and_return(true)
|
79
|
-
expect(
|
81
|
+
expect(Shakapacker.commands.clean).to be true
|
80
82
|
end
|
81
83
|
|
82
84
|
it "deletes only and only expired versioned files if no parameter passed" do
|
@@ -85,7 +87,7 @@ describe "Command" do
|
|
85
87
|
end
|
86
88
|
|
87
89
|
with_time_dir_and_files_stub do
|
88
|
-
expect(
|
90
|
+
expect(Shakapacker.commands.clean).to be true
|
89
91
|
|
90
92
|
# Verify that only and only expired files are deleted
|
91
93
|
all_files.keys.each do |longpath|
|
data/spec/compiler_spec.rb
CHANGED
@@ -1,32 +1,34 @@
|
|
1
|
-
|
1
|
+
require_relative "spec_helper_initializer"
|
2
|
+
|
3
|
+
describe "Shakapacker::Compiler" do
|
2
4
|
it "accepts custom environment variables" do
|
3
|
-
expect(
|
5
|
+
expect(Shakapacker.compiler.send(:webpack_env)["FOO"]).to be nil
|
4
6
|
|
5
|
-
|
6
|
-
expect(
|
7
|
+
Shakapacker.compiler.env["FOO"] = "BAR"
|
8
|
+
expect(Shakapacker.compiler.send(:webpack_env)["FOO"]).to eq "BAR"
|
7
9
|
ensure
|
8
|
-
|
10
|
+
Shakapacker.compiler.env = {}
|
9
11
|
end
|
10
12
|
|
11
13
|
it "returns true when fresh" do
|
12
14
|
mocked_strategy = double("Strategy")
|
13
15
|
expect(mocked_strategy).to receive(:stale?).and_return(false)
|
14
16
|
|
15
|
-
expect(
|
17
|
+
expect(Shakapacker.compiler).to receive(:strategy).and_return(mocked_strategy)
|
16
18
|
|
17
|
-
expect(
|
19
|
+
expect(Shakapacker.compiler.compile).to be true
|
18
20
|
end
|
19
21
|
|
20
22
|
it "returns true and calls after_compile_hook on successful compile" do
|
21
23
|
mocked_strategy = spy("Strategy")
|
22
24
|
expect(mocked_strategy).to receive(:stale?).and_return(true)
|
23
25
|
|
24
|
-
allow(
|
26
|
+
allow(Shakapacker.compiler).to receive(:strategy).and_return(mocked_strategy)
|
25
27
|
|
26
28
|
status = OpenStruct.new(success?: true)
|
27
29
|
allow(Open3).to receive(:capture3).and_return([:sterr, :stdout, status])
|
28
30
|
|
29
|
-
expect(
|
31
|
+
expect(Shakapacker.compiler.compile).to be true
|
30
32
|
expect(mocked_strategy).to have_received(:after_compile_hook)
|
31
33
|
end
|
32
34
|
|
@@ -35,23 +37,23 @@ describe "Webpacker::Compiler" do
|
|
35
37
|
allow(mocked_strategy).to receive(:stale?).and_return(true)
|
36
38
|
allow(mocked_strategy).to receive(:after_compile_hook)
|
37
39
|
|
38
|
-
allow(
|
40
|
+
allow(Shakapacker.compiler).to receive(:strategy).and_return(mocked_strategy)
|
39
41
|
|
40
42
|
status = OpenStruct.new(success?: false)
|
41
43
|
allow(Open3).to receive(:capture3).and_return([:sterr, :stdout, status])
|
42
44
|
|
43
|
-
expect(
|
45
|
+
expect(Shakapacker.compiler.compile).to be false
|
44
46
|
expect(mocked_strategy).to have_received(:after_compile_hook)
|
45
47
|
end
|
46
48
|
|
47
49
|
it "accepts external env variables" do
|
48
|
-
expect(
|
49
|
-
expect(
|
50
|
+
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
|
50
52
|
|
51
|
-
ENV["
|
52
|
-
ENV["
|
53
|
+
ENV["SHAKAPACKER_ASSET_HOST"] = "foo.bar"
|
54
|
+
ENV["SHAKAPACKER_RELATIVE_URL_ROOT"] = "/baz"
|
53
55
|
|
54
|
-
expect(
|
55
|
-
expect(
|
56
|
+
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"
|
56
58
|
end
|
57
59
|
end
|
@@ -1,20 +1,22 @@
|
|
1
|
-
|
1
|
+
require_relative "spec_helper_initializer"
|
2
|
+
|
3
|
+
describe "Shakapacker::CompilerStrategy" do
|
2
4
|
describe "#from_config" do
|
3
5
|
it "returns and instance of MtimeStrategy when compiler_strategy is set to mtime" do
|
4
|
-
allow(
|
5
|
-
expect(
|
6
|
+
allow(Shakapacker.config).to receive(:compiler_strategy).and_return("mtime")
|
7
|
+
expect(Shakapacker::CompilerStrategy.from_config).to be_an_instance_of(Shakapacker::MtimeStrategy)
|
6
8
|
end
|
7
9
|
|
8
10
|
it "returns and instance of DigestStrategy when compiler_strategy is set to digest" do
|
9
|
-
allow(
|
10
|
-
expect(
|
11
|
+
allow(Shakapacker.config).to receive(:compiler_strategy).and_return("digest")
|
12
|
+
expect(Shakapacker::CompilerStrategy.from_config).to be_an_instance_of(Shakapacker::DigestStrategy)
|
11
13
|
end
|
12
14
|
|
13
15
|
it "raise exception for unknown compiler_strategy in the config file" do
|
14
16
|
expected_error_message = "Unknown strategy 'other'. Available options are 'mtime' and 'digest'."
|
15
|
-
allow(
|
17
|
+
allow(Shakapacker.config).to receive(:compiler_strategy).and_return("other")
|
16
18
|
|
17
|
-
expect {
|
19
|
+
expect { Shakapacker::CompilerStrategy.from_config }.to raise_error(expected_error_message)
|
18
20
|
end
|
19
21
|
end
|
20
22
|
end
|