shakapacker 7.3.0.beta.1 → 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 +6 -1
- data/.github/workflows/generator.yml +14 -18
- data/.github/workflows/node.yml +56 -0
- data/.github/workflows/ruby.yml +29 -17
- data/.node-version +1 -1
- data/.rubocop.yml +1 -0
- data/CHANGELOG.md +56 -5
- data/README.md +101 -48
- data/Rakefile +1 -7
- data/docs/customizing_babel_config.md +2 -2
- data/docs/deployment.md +13 -6
- data/docs/react.md +7 -13
- data/docs/troubleshooting.md +4 -4
- data/docs/using_esbuild_loader.md +1 -1
- data/docs/using_swc_loader.md +1 -1
- data/docs/v6_upgrade.md +1 -1
- data/docs/v8_upgrade.md +148 -0
- data/gemfiles/Gemfile-rails.7.1.x +12 -0
- data/jest.config.js +4 -0
- data/lib/install/config/shakapacker.yml +2 -2
- data/lib/install/template.rb +36 -30
- data/lib/shakapacker/base_strategy.rb +2 -1
- data/lib/shakapacker/compiler.rb +6 -21
- data/lib/shakapacker/configuration.rb +2 -46
- data/lib/shakapacker/deprecation_helper.rb +0 -78
- data/lib/shakapacker/dev_server.rb +1 -16
- data/lib/shakapacker/dev_server_runner.rb +2 -21
- data/lib/shakapacker/env.rb +1 -1
- data/lib/shakapacker/helper.rb +3 -3
- data/lib/shakapacker/instance.rb +1 -3
- data/lib/shakapacker/manifest.rb +1 -1
- data/lib/shakapacker/railtie.rb +7 -0
- data/lib/shakapacker/runner.rb +4 -18
- data/lib/shakapacker/utils/manager.rb +58 -0
- data/lib/shakapacker/utils/misc.rb +0 -12
- data/lib/shakapacker/version.rb +1 -1
- data/lib/shakapacker/version_checker.rb +9 -30
- data/lib/shakapacker/webpack_runner.rb +2 -21
- data/lib/shakapacker.rb +0 -2
- data/lib/tasks/shakapacker/check_binstubs.rake +12 -26
- data/lib/tasks/shakapacker/check_manager.rake +3 -8
- data/lib/tasks/shakapacker/info.rake +6 -15
- data/package/babel/preset.js +15 -15
- data/package/config.js +15 -19
- data/package/dev_server.js +4 -4
- data/package/env.js +19 -17
- data/package/environments/base.js +41 -24
- data/package/environments/development.js +6 -6
- data/package/environments/production.js +16 -16
- data/package/environments/test.js +1 -1
- data/package/esbuild/index.js +6 -6
- data/package/index.d.ts +0 -2
- data/package/index.js +17 -46
- data/package/rules/babel.js +6 -8
- data/package/rules/coffee.js +2 -2
- data/package/rules/css.js +1 -1
- data/package/rules/erb.js +4 -4
- data/package/rules/esbuild.js +5 -7
- data/package/rules/file.js +14 -7
- data/package/rules/index.js +11 -11
- data/package/rules/jscommon.js +8 -5
- data/package/rules/less.js +10 -9
- data/package/rules/raw.js +1 -1
- data/package/rules/sass.js +4 -4
- data/package/rules/stylus.js +12 -7
- data/package/rules/swc.js +5 -7
- data/package/swc/index.js +10 -10
- data/package/utils/configPath.js +3 -18
- data/package/utils/defaultConfigPath.js +1 -1
- data/package/utils/{get_style_rule.js → getStyleRule.js} +6 -6
- data/package/utils/helpers.js +2 -43
- data/package/utils/inliningCss.js +4 -3
- data/package/utils/snakeToCamelCase.js +5 -0
- data/package/webpackDevServerConfig.js +28 -25
- data/package.json +12 -18
- data/prettier.config.js +4 -0
- data/shakapacker.gemspec +1 -1
- data/spec/dummy/app/javascript/packs/application.js +1 -1
- data/spec/dummy/config/application.rb +3 -0
- data/spec/dummy/config/initializers/react_on_rails.rb +2 -2
- data/spec/dummy/config/shakapacker.yml +3 -4
- data/spec/dummy/config/webpack/commonWebpackConfig.js +0 -1
- data/spec/dummy/config/webpack/webpack.config.js +1 -1
- data/spec/dummy/package.json +2 -1
- data/spec/dummy/yarn.lock +2 -3
- data/spec/fixtures/github_url_package-lock.v1.json +1 -1
- data/spec/fixtures/github_url_package-lock.v2.json +2 -2
- data/spec/fixtures/github_url_package.json +1 -1
- data/spec/fixtures/github_url_pnpm-lock.v7.yaml +1 -1
- data/spec/fixtures/github_url_pnpm-lock.v8.yaml +1 -1
- data/spec/fixtures/github_url_yarn.v1.lock +1 -1
- data/spec/fixtures/github_url_yarn.v2.lock +2 -2
- data/spec/generator_specs/e2e_template/template.rb +15 -28
- data/spec/generator_specs/generator_spec.rb +6 -136
- data/spec/mounted_app/test/dummy/config/webpacker.yml +0 -1
- data/spec/shakapacker/compiler_spec.rb +1 -3
- data/spec/shakapacker/configuration_spec.rb +4 -56
- data/spec/shakapacker/dev_server_runner_spec.rb +19 -102
- data/spec/shakapacker/dev_server_spec.rb +1 -16
- data/spec/shakapacker/engine_rake_tasks_spec.rb +1 -16
- data/spec/shakapacker/helper_spec.rb +3 -3
- data/spec/shakapacker/instance_spec.rb +1 -3
- data/spec/shakapacker/rake_tasks_spec.rb +2 -14
- data/spec/shakapacker/shakapacker_spec.rb +0 -1
- data/spec/shakapacker/test_app/config/shakapacker_css_extract_ignore_order_warnings.yml +0 -1
- data/spec/shakapacker/test_app/config/shakapacker_manifest_path.yml +0 -1
- data/spec/shakapacker/test_app/config/shakapacker_nested_entries.yml +0 -1
- data/spec/shakapacker/test_app/config/shakapacker_other_location.yml +0 -1
- data/spec/shakapacker/test_app/package.json +2 -1
- data/spec/shakapacker/utils_manager_spec.rb +125 -0
- data/spec/shakapacker/version_checker_spec.rb +5 -5
- data/spec/shakapacker/webpack_runner_spec.rb +19 -28
- data/spec/support/package_json_helpers.rb +7 -4
- data/test/helpers.js +67 -0
- data/test/package/config.test.js +50 -0
- data/test/package/dev_server.test.js +44 -0
- data/test/package/development.test.js +43 -0
- data/test/package/env.test.js +57 -0
- data/test/package/environments/base.test.js +105 -0
- data/test/package/environments/development.test.js +50 -0
- data/test/package/environments/production.test.js +106 -0
- data/test/package/index.test.js +45 -0
- data/test/package/production.test.js +32 -0
- data/test/package/rules/babel.test.js +58 -0
- data/test/package/rules/esbuild.test.js +59 -0
- data/test/package/rules/file.test.js +81 -0
- data/test/package/rules/index.test.js +7 -0
- data/test/package/rules/raw.test.js +12 -0
- data/test/package/rules/swc.test.js +59 -0
- data/test/package/staging.test.js +31 -0
- data/test/package/test.test.js +28 -0
- data/yarn.lock +1278 -421
- metadata +50 -100
- data/.github/workflows/jest.yml +0 -33
- data/.github/workflows/js-lint.yml +0 -33
- data/.github/workflows/rubocop.yml +0 -28
- data/.github/workflows/ruby-backward-compatibility.yml +0 -51
- data/lib/install/package.json +0 -15
- data/lib/tasks/shakapacker/check_yarn.rake +0 -34
- data/lib/tasks/shakapacker/yarn_install.rake +0 -24
- data/lib/tasks/webpacker/binstubs.rake +0 -9
- data/lib/tasks/webpacker/check_binstubs.rake +0 -9
- data/lib/tasks/webpacker/check_node.rake +0 -9
- data/lib/tasks/webpacker/check_yarn.rake +0 -9
- data/lib/tasks/webpacker/clean.rake +0 -9
- data/lib/tasks/webpacker/clobber.rake +0 -11
- data/lib/tasks/webpacker/compile.rake +0 -9
- data/lib/tasks/webpacker/info.rake +0 -9
- data/lib/tasks/webpacker/install.rake +0 -9
- data/lib/tasks/webpacker/verify_config.rake +0 -9
- data/lib/tasks/webpacker/verify_install.rake +0 -9
- data/lib/tasks/webpacker/yarn_install.rake +0 -9
- data/lib/tasks/webpacker.rake +0 -20
- data/lib/webpacker/dev_server_runner.rb +0 -9
- data/lib/webpacker/webpack_runner.rb +0 -9
- data/lib/webpacker.rb +0 -4
- data/package/__tests__/config-bc.js +0 -27
- data/package/__tests__/config.js +0 -46
- data/package/__tests__/dev_server-bc.js +0 -46
- data/package/__tests__/dev_server.js +0 -46
- data/package/__tests__/development-bc.js +0 -66
- data/package/__tests__/development.js +0 -66
- data/package/__tests__/env-bc.js +0 -59
- data/package/__tests__/env.js +0 -59
- data/package/__tests__/index-bc.js +0 -22
- data/package/__tests__/index.js +0 -46
- data/package/__tests__/production-bc.js +0 -51
- data/package/__tests__/production.js +0 -51
- data/package/__tests__/staging-bc.js +0 -53
- data/package/__tests__/staging.js +0 -53
- data/package/__tests__/test-bc.js +0 -43
- data/package/__tests__/test.js +0 -43
- data/package/environments/__tests__/base-bc.js +0 -107
- data/package/environments/__tests__/base.js +0 -107
- data/package/environments/__tests__/development.js +0 -53
- data/package/environments/__tests__/production.js +0 -92
- data/package/rules/__tests__/__utils__/webpack.js +0 -50
- data/package/rules/__tests__/babel.js +0 -63
- data/package/rules/__tests__/esbuild.js +0 -64
- data/package/rules/__tests__/file.js +0 -79
- data/package/rules/__tests__/index.js +0 -7
- data/package/rules/__tests__/raw.js +0 -18
- data/package/rules/__tests__/swc.js +0 -63
- data/package/utils/snakeToCamelCase +0 -7
- data/spec/backward_compatibility_specs/command_spec.rb +0 -116
- data/spec/backward_compatibility_specs/compiler_spec.rb +0 -59
- data/spec/backward_compatibility_specs/compiler_strategy_spec.rb +0 -24
- data/spec/backward_compatibility_specs/configuration_spec.rb +0 -294
- data/spec/backward_compatibility_specs/dev_server_runner_spec.rb +0 -206
- data/spec/backward_compatibility_specs/dev_server_spec.rb +0 -47
- data/spec/backward_compatibility_specs/digest_strategy_spec.rb +0 -38
- data/spec/backward_compatibility_specs/engine_rake_tasks_spec.rb +0 -67
- data/spec/backward_compatibility_specs/env_spec.rb +0 -23
- data/spec/backward_compatibility_specs/helper_spec.rb +0 -243
- data/spec/backward_compatibility_specs/instance_spec.rb +0 -31
- data/spec/backward_compatibility_specs/manifest_spec.rb +0 -100
- data/spec/backward_compatibility_specs/mtime_strategy_spec.rb +0 -55
- data/spec/backward_compatibility_specs/rake_tasks_spec.rb +0 -41
- data/spec/backward_compatibility_specs/spec_helper_initializer.rb +0 -24
- data/spec/backward_compatibility_specs/webpack_runner_spec.rb +0 -86
- data/spec/backward_compatibility_specs/webpacker_spec.rb +0 -41
- data/spec/backward_compatibility_specs/webpacker_test_app/.gitignore +0 -2
- data/spec/backward_compatibility_specs/webpacker_test_app/Rakefile +0 -3
- data/spec/backward_compatibility_specs/webpacker_test_app/app/packs/entrypoints/application.js +0 -10
- data/spec/backward_compatibility_specs/webpacker_test_app/app/packs/entrypoints/generated/something.js +0 -2
- data/spec/backward_compatibility_specs/webpacker_test_app/app/packs/entrypoints/multi_entry.css +0 -4
- data/spec/backward_compatibility_specs/webpacker_test_app/app/packs/entrypoints/multi_entry.js +0 -4
- data/spec/backward_compatibility_specs/webpacker_test_app/bin/webpacker +0 -13
- data/spec/backward_compatibility_specs/webpacker_test_app/bin/webpacker-dev-server +0 -13
- data/spec/backward_compatibility_specs/webpacker_test_app/config/application.rb +0 -11
- data/spec/backward_compatibility_specs/webpacker_test_app/config/environment.rb +0 -4
- data/spec/backward_compatibility_specs/webpacker_test_app/config/initializers/inspect_autoload_paths.rb +0 -1
- data/spec/backward_compatibility_specs/webpacker_test_app/config/webpack/webpack.config.js +0 -0
- data/spec/backward_compatibility_specs/webpacker_test_app/config/webpacker.yml +0 -83
- data/spec/backward_compatibility_specs/webpacker_test_app/config/webpacker_css_extract_ignore_order_warnings.yml +0 -84
- data/spec/backward_compatibility_specs/webpacker_test_app/config/webpacker_defaults_fallback.yml +0 -11
- data/spec/backward_compatibility_specs/webpacker_test_app/config/webpacker_manifest_path.yml +0 -80
- data/spec/backward_compatibility_specs/webpacker_test_app/config/webpacker_nested_entries.yml +0 -83
- data/spec/backward_compatibility_specs/webpacker_test_app/config/webpacker_no_precompile.yml +0 -7
- data/spec/backward_compatibility_specs/webpacker_test_app/config/webpacker_other_location.yml +0 -85
- data/spec/backward_compatibility_specs/webpacker_test_app/config/webpacker_public_root.yml +0 -18
- data/spec/backward_compatibility_specs/webpacker_test_app/config.ru +0 -5
- data/spec/backward_compatibility_specs/webpacker_test_app/package.json +0 -13
- data/spec/backward_compatibility_specs/webpacker_test_app/public/packs/manifest.json +0 -58
- data/spec/backward_compatibility_specs/webpacker_test_app/some.config.js +0 -0
- data/spec/backward_compatibility_specs/webpacker_test_app/tmp/shakapacker/last-compilation-digest-production +0 -1
- data/spec/backward_compatibility_specs/webpacker_test_app/yarn.lock +0 -11
@@ -1,100 +0,0 @@
|
|
1
|
-
require_relative "spec_helper_initializer"
|
2
|
-
|
3
|
-
describe "Webpacker::Manifest" do
|
4
|
-
let(:manifest_path) { File.expand_path File.join(File.dirname(__FILE__), "webpacker_test_app/public/packs", "manifest.json").to_s }
|
5
|
-
|
6
|
-
it "#lookup! raises an exception for a non-existing asset file" do
|
7
|
-
asset_file = "calendar.js"
|
8
|
-
expected_error_message = "Shakapacker can't find #{asset_file} in #{manifest_path}"
|
9
|
-
|
10
|
-
allow(Webpacker.config).to receive(:compile?).and_return(false)
|
11
|
-
|
12
|
-
expect {
|
13
|
-
Webpacker.manifest.lookup!(asset_file)
|
14
|
-
}.to raise_error(Webpacker::Manifest::MissingEntryError, /#{expected_error_message}/)
|
15
|
-
end
|
16
|
-
|
17
|
-
it "#lookup! raises an exception for a non-existing asset file with type and without an extension" do
|
18
|
-
asset_file = "calendar"
|
19
|
-
expected_error_message = "Shakapacker can't find #{asset_file}.js in #{manifest_path}"
|
20
|
-
|
21
|
-
allow(Webpacker.config).to receive(:compile?).and_return(false)
|
22
|
-
|
23
|
-
expect {
|
24
|
-
Webpacker.manifest.lookup!(asset_file, type: :javascript)
|
25
|
-
}.to raise_error(Webpacker::Manifest::MissingEntryError, /#{expected_error_message}/)
|
26
|
-
end
|
27
|
-
|
28
|
-
it "#lookup! returns the path to the bundled bootstrap.js" do
|
29
|
-
actual = Webpacker.manifest.lookup!("bootstrap.js")
|
30
|
-
expected = "/packs/bootstrap-300631c4f0e0f9c865bc.js"
|
31
|
-
|
32
|
-
expect(actual).to eq expected
|
33
|
-
end
|
34
|
-
|
35
|
-
it "#lookup_pack_with_chunks! returns an array of paths to the bundled bootstrap of type javascript" do
|
36
|
-
actual = Webpacker.manifest.lookup_pack_with_chunks!("bootstrap", type: :javascript)
|
37
|
-
expected = ["/packs/bootstrap-300631c4f0e0f9c865bc.js"]
|
38
|
-
|
39
|
-
expect(actual).to eq expected
|
40
|
-
end
|
41
|
-
|
42
|
-
it "#lookup_with_chunks! returns an array of paths to the bundled bootstrap.js of type javascript" do
|
43
|
-
actual = Webpacker.manifest.lookup_pack_with_chunks!("bootstrap.js", type: :javascript)
|
44
|
-
expected = ["/packs/bootstrap-300631c4f0e0f9c865bc.js"]
|
45
|
-
|
46
|
-
expect(actual).to eq expected
|
47
|
-
end
|
48
|
-
|
49
|
-
it "#lookup_with_chunks! returns an array of paths to the bundled 'print/application' without an extension and in a sub-directory" do
|
50
|
-
actual = Webpacker.manifest.lookup_pack_with_chunks!("print/application", type: :css)
|
51
|
-
expected = ["/packs/print/application-983b6c164a47f7ed49cd.css"]
|
52
|
-
|
53
|
-
expect(actual).to eq expected
|
54
|
-
end
|
55
|
-
|
56
|
-
it "#lookup_with_chunks! returns an array of paths to the bundled 'print/application.css' in a sub-directory" do
|
57
|
-
actual = Webpacker.manifest.lookup_pack_with_chunks!("print/application.css", type: :css)
|
58
|
-
expected = ["/packs/print/application-983b6c164a47f7ed49cd.css"]
|
59
|
-
|
60
|
-
expect(actual).to eq expected
|
61
|
-
end
|
62
|
-
|
63
|
-
it "#lookup returns nil for non-existing asset files" do
|
64
|
-
expect(Webpacker.manifest.lookup("foo.js")).to be nil
|
65
|
-
end
|
66
|
-
|
67
|
-
it "#lookup_pack_with_chunks returns nil for non-existing asset files" do
|
68
|
-
expect(Webpacker.manifest.lookup_pack_with_chunks("foo.js")).to be nil
|
69
|
-
end
|
70
|
-
|
71
|
-
it "#lookup returns the path for bootstrap.js" do
|
72
|
-
actual = Webpacker.manifest.lookup("bootstrap.js")
|
73
|
-
expected = "/packs/bootstrap-300631c4f0e0f9c865bc.js"
|
74
|
-
|
75
|
-
expect(actual).to eq expected
|
76
|
-
end
|
77
|
-
|
78
|
-
it "#lookup_pack_with_chunks! raises an exception for non-existing asset files" do
|
79
|
-
asset_file = "calendar"
|
80
|
-
|
81
|
-
expected_error_message = "Shakapacker can't find #{asset_file}.js in #{manifest_path}"
|
82
|
-
|
83
|
-
allow(Webpacker.config).to receive(:compile?).and_return(false)
|
84
|
-
|
85
|
-
expect {
|
86
|
-
Webpacker.manifest.lookup_pack_with_chunks!(asset_file, type: :javascript)
|
87
|
-
}.to raise_error(Shakapacker::Manifest::MissingEntryError, /#{expected_error_message}/)
|
88
|
-
end
|
89
|
-
|
90
|
-
it "#lookup_pack_with_chunks! returns an array of paths to bundled js files with 'application' in their name" do
|
91
|
-
actual_application_entrypoints = Webpacker.manifest.lookup_pack_with_chunks!("application", type: :javascript)
|
92
|
-
expected_application_entrypoints = [
|
93
|
-
"/packs/vendors~application~bootstrap-c20632e7baf2c81200d3.chunk.js",
|
94
|
-
"/packs/vendors~application-e55f2aae30c07fb6d82a.chunk.js",
|
95
|
-
"/packs/application-k344a6d59eef8632c9d1.js"
|
96
|
-
]
|
97
|
-
|
98
|
-
expect(actual_application_entrypoints).to eq expected_application_entrypoints
|
99
|
-
end
|
100
|
-
end
|
@@ -1,55 +0,0 @@
|
|
1
|
-
require_relative "spec_helper_initializer"
|
2
|
-
|
3
|
-
describe "Webpacker::MtimeStrategy" do
|
4
|
-
let(:mtime_strategy) { Webpacker::MtimeStrategy.new }
|
5
|
-
let(:manifest_timestamp) { Time.parse("2021-01-01 12:34:56 UTC") }
|
6
|
-
|
7
|
-
describe "#fresh?" do
|
8
|
-
it "returns false when the manifest is missing" do
|
9
|
-
latest_timestamp = manifest_timestamp + 3600
|
10
|
-
|
11
|
-
with_stubs(latest_timestamp: latest_timestamp.to_i, manifest_exists: false) do
|
12
|
-
expect(mtime_strategy.fresh?).to be false
|
13
|
-
end
|
14
|
-
end
|
15
|
-
|
16
|
-
it "returns false when the manifest is older" do
|
17
|
-
latest_timestamp = manifest_timestamp + 3600
|
18
|
-
|
19
|
-
with_stubs(latest_timestamp: latest_timestamp.to_i) do
|
20
|
-
expect(mtime_strategy.fresh?).to be false
|
21
|
-
end
|
22
|
-
end
|
23
|
-
|
24
|
-
it "returns true when the manifest is new" do
|
25
|
-
latest_timestamp = manifest_timestamp - 3600
|
26
|
-
|
27
|
-
with_stubs(latest_timestamp: latest_timestamp.to_i) do
|
28
|
-
expect(mtime_strategy.fresh?).to be true
|
29
|
-
end
|
30
|
-
end
|
31
|
-
end
|
32
|
-
|
33
|
-
describe "#stale?" do
|
34
|
-
it "returns false when #fresh? is true" do
|
35
|
-
expect(mtime_strategy).to receive(:fresh?).and_return(true)
|
36
|
-
|
37
|
-
expect(mtime_strategy.stale?).to be false
|
38
|
-
end
|
39
|
-
|
40
|
-
it "returns true when #fresh? is false" do
|
41
|
-
expect(mtime_strategy).to receive(:fresh?).and_return(false)
|
42
|
-
|
43
|
-
expect(mtime_strategy.stale?).to be true
|
44
|
-
end
|
45
|
-
end
|
46
|
-
|
47
|
-
private
|
48
|
-
|
49
|
-
def with_stubs(latest_timestamp:, manifest_exists: true)
|
50
|
-
allow(mtime_strategy).to receive(:latest_modified_timestamp).and_return(latest_timestamp)
|
51
|
-
allow(FileTest).to receive(:exist?).and_return(manifest_exists)
|
52
|
-
allow(File).to receive(:mtime).and_return(manifest_timestamp)
|
53
|
-
yield
|
54
|
-
end
|
55
|
-
end
|
@@ -1,41 +0,0 @@
|
|
1
|
-
require_relative "spec_helper_initializer"
|
2
|
-
|
3
|
-
describe "RakeTasks" do
|
4
|
-
TEST_APP_PATH = File.expand_path("webpacker_test_app", __dir__)
|
5
|
-
|
6
|
-
it "`rake -T` lists Webpacker tasks" do
|
7
|
-
output = Dir.chdir(TEST_APP_PATH) { `rake -T` }
|
8
|
-
|
9
|
-
expect(output).to match /webpacker .+DEPRECATED/
|
10
|
-
expect(output).to match /webpacker:check_binstubs.+DEPRECATED/
|
11
|
-
expect(output).to match /webpacker:check_node.+DEPRECATED/
|
12
|
-
expect(output).to match /webpacker:check_yarn.+DEPRECATED/
|
13
|
-
expect(output).to match /webpacker:clean.+DEPRECATED/
|
14
|
-
expect(output).to match /webpacker:clobber.+DEPRECATED/
|
15
|
-
expect(output).to match /webpacker:compile.+DEPRECATED/
|
16
|
-
expect(output).to match /webpacker:install.+DEPRECATED/
|
17
|
-
expect(output).to match /webpacker:verify_install.+DEPRECATED/
|
18
|
-
end
|
19
|
-
|
20
|
-
it "`webpacker:check_binstubs` doesn't get 'webpack binstub not found' error" do
|
21
|
-
output = Dir.chdir(TEST_APP_PATH) { `rake webpacker:check_binstubs 2>&1` }
|
22
|
-
|
23
|
-
expect(output).to_not include "webpack binstub not found."
|
24
|
-
expect(output).to include "DEPRECATION"
|
25
|
-
end
|
26
|
-
|
27
|
-
it "`webpacker:check_node` doesn't get 'webpacker requires Node.js' error" do
|
28
|
-
output = Dir.chdir(TEST_APP_PATH) { `rake webpacker:check_node 2>&1` }
|
29
|
-
|
30
|
-
expect(output).to_not include "Shakapacker requires Node.js"
|
31
|
-
expect(output).to include "DEPRECATION"
|
32
|
-
end
|
33
|
-
|
34
|
-
it "`webpacker:check_yarn` doesn't get error related to yarn" do
|
35
|
-
output = Dir.chdir(TEST_APP_PATH) { `rake webpacker:check_yarn 2>&1` }
|
36
|
-
|
37
|
-
expect(output).to_not include "Yarn not installed"
|
38
|
-
expect(output).to_not include "Shakapacker requires Yarn"
|
39
|
-
expect(output).to include "DEPRECATION"
|
40
|
-
end
|
41
|
-
end
|
@@ -1,24 +0,0 @@
|
|
1
|
-
require_relative "webpacker_test_app/config/environment"
|
2
|
-
|
3
|
-
Rails.env = "production"
|
4
|
-
|
5
|
-
Webpacker.instance = ::Webpacker::Instance.new
|
6
|
-
|
7
|
-
def reloaded_config
|
8
|
-
Webpacker.instance.instance_variable_set(:@env, nil)
|
9
|
-
Webpacker.instance.instance_variable_set(:@config, nil)
|
10
|
-
Webpacker.instance.instance_variable_set(:@dev_server, nil)
|
11
|
-
Webpacker.env
|
12
|
-
Webpacker.config
|
13
|
-
Webpacker.dev_server
|
14
|
-
end
|
15
|
-
|
16
|
-
def with_rails_env(env)
|
17
|
-
original = Rails.env
|
18
|
-
Rails.env = ActiveSupport::StringInquirer.new(env)
|
19
|
-
reloaded_config
|
20
|
-
yield
|
21
|
-
ensure
|
22
|
-
Rails.env = ActiveSupport::StringInquirer.new(original)
|
23
|
-
reloaded_config
|
24
|
-
end
|
@@ -1,86 +0,0 @@
|
|
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
|
-
let(:test_app_path) { File.expand_path("./webpacker_test_app", __dir__) }
|
17
|
-
|
18
|
-
NODE_PACKAGE_MANAGERS.each do |fallback_manager|
|
19
|
-
context "when using package_json with #{fallback_manager} as the manager" do
|
20
|
-
with_use_package_json_gem(enabled: true, fallback_manager: fallback_manager)
|
21
|
-
|
22
|
-
let(:package_json) { PackageJson.read(test_app_path) }
|
23
|
-
|
24
|
-
require "package_json"
|
25
|
-
|
26
|
-
it "uses the expected package manager", unless: fallback_manager == "yarn_classic" do
|
27
|
-
cmd = package_json.manager.native_exec_command("webpack", ["--config", "#{test_app_path}/config/webpack/webpack.config.js"])
|
28
|
-
|
29
|
-
manager_name = fallback_manager.split("_")[0]
|
30
|
-
|
31
|
-
expect(cmd).to start_with(manager_name)
|
32
|
-
end
|
33
|
-
|
34
|
-
it "runs the command using the manager" do
|
35
|
-
cmd = package_json.manager.native_exec_command("webpack", ["--config", "#{test_app_path}/config/webpack/webpack.config.js"])
|
36
|
-
|
37
|
-
verify_command(cmd)
|
38
|
-
end
|
39
|
-
|
40
|
-
it "passes on arguments" do
|
41
|
-
cmd = package_json.manager.native_exec_command("webpack", ["--config", "#{test_app_path}/config/webpack/webpack.config.js", "--watch"])
|
42
|
-
|
43
|
-
verify_command(cmd, argv: (["--watch"]))
|
44
|
-
end
|
45
|
-
end
|
46
|
-
end
|
47
|
-
|
48
|
-
context "when not using package_json" do
|
49
|
-
with_use_package_json_gem(enabled: false)
|
50
|
-
|
51
|
-
it "supports running via node_modules" do
|
52
|
-
cmd = ["#{test_app_path}/node_modules/.bin/webpack", "--config", "#{test_app_path}/config/webpack/webpack.config.js"]
|
53
|
-
|
54
|
-
verify_command(cmd, use_node_modules: true)
|
55
|
-
end
|
56
|
-
|
57
|
-
it "supports running via yarn" do
|
58
|
-
cmd = ["yarn", "webpack", "--config", "#{test_app_path}/config/webpack/webpack.config.js"]
|
59
|
-
|
60
|
-
verify_command(cmd, use_node_modules: false)
|
61
|
-
end
|
62
|
-
|
63
|
-
it "passes on arguments" do
|
64
|
-
cmd = ["#{test_app_path}/node_modules/.bin/webpack", "--config", "#{test_app_path}/config/webpack/webpack.config.js", "--watch"]
|
65
|
-
|
66
|
-
verify_command(cmd, argv: ["--watch"])
|
67
|
-
end
|
68
|
-
end
|
69
|
-
|
70
|
-
private
|
71
|
-
|
72
|
-
def verify_command(cmd, use_node_modules: true, argv: [])
|
73
|
-
Dir.chdir(test_app_path) do
|
74
|
-
klass = Webpacker::WebpackRunner
|
75
|
-
instance = klass.new(argv)
|
76
|
-
|
77
|
-
allow(klass).to receive(:new).and_return(instance)
|
78
|
-
allow(instance).to receive(:node_modules_bin_exist?).and_return(use_node_modules)
|
79
|
-
allow(Kernel).to receive(:exec)
|
80
|
-
|
81
|
-
klass.run(argv)
|
82
|
-
|
83
|
-
expect(Kernel).to have_received(:exec).with(Webpacker::Compiler.env, *cmd)
|
84
|
-
end
|
85
|
-
end
|
86
|
-
end
|
@@ -1,41 +0,0 @@
|
|
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
|
data/spec/backward_compatibility_specs/webpacker_test_app/app/packs/entrypoints/application.js
DELETED
@@ -1,10 +0,0 @@
|
|
1
|
-
/* eslint no-console:0 */
|
2
|
-
// This file is automatically compiled by Webpack, along with any other files
|
3
|
-
// present in this directory. You're encouraged to place your actual application logic in
|
4
|
-
// a relevant structure within app/packs and only use these pack files to reference
|
5
|
-
// that code so it'll be compiled.
|
6
|
-
//
|
7
|
-
// To reference this file, add <%= javascript_pack_tag 'application' %> to the appropriate
|
8
|
-
// layout file, like app/views/layouts/application.html.erb
|
9
|
-
|
10
|
-
console.log('Hello World from shakapacker')
|
@@ -1,13 +0,0 @@
|
|
1
|
-
#!/usr/bin/env ruby
|
2
|
-
|
3
|
-
ENV["RAILS_ENV"] ||= "development"
|
4
|
-
ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../Gemfile", __FILE__)
|
5
|
-
|
6
|
-
require "bundler/setup"
|
7
|
-
require "webpacker"
|
8
|
-
require "webpacker/webpack_runner"
|
9
|
-
|
10
|
-
APP_ROOT = File.expand_path("..", __dir__)
|
11
|
-
Dir.chdir(APP_ROOT) do
|
12
|
-
Webpacker::WebpackRunner.run(ARGV)
|
13
|
-
end
|
@@ -1,13 +0,0 @@
|
|
1
|
-
#!/usr/bin/env ruby
|
2
|
-
|
3
|
-
ENV["RAILS_ENV"] ||= "development"
|
4
|
-
ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../Gemfile", __FILE__)
|
5
|
-
|
6
|
-
require "bundler/setup"
|
7
|
-
require "webpacker"
|
8
|
-
require "webpacker/dev_server_runner"
|
9
|
-
|
10
|
-
APP_ROOT = File.expand_path("..", __dir__)
|
11
|
-
Dir.chdir(APP_ROOT) do
|
12
|
-
Webpacker::DevServerRunner.run(ARGV)
|
13
|
-
end
|
@@ -1,11 +0,0 @@
|
|
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
|
@@ -1 +0,0 @@
|
|
1
|
-
$test_app_autoload_paths_in_initializer = ActiveSupport::Dependencies.autoload_paths
|
File without changes
|
@@ -1,83 +0,0 @@
|
|
1
|
-
# Note: You must restart bin/shakapacker-dev-server for changes to take effect
|
2
|
-
|
3
|
-
default: &default
|
4
|
-
source_path: app/packs
|
5
|
-
source_entry_path: entrypoints
|
6
|
-
nested_entries: false
|
7
|
-
public_root_path: public
|
8
|
-
public_output_path: packs
|
9
|
-
cache_path: tmp/webpacker
|
10
|
-
webpack_compile_output: false
|
11
|
-
webpack_loader: babel
|
12
|
-
|
13
|
-
# Location for manifest.json, defaults to {public_output_path}/manifest.json if unset
|
14
|
-
# manifest_path: public/packs/manifest.json
|
15
|
-
|
16
|
-
# Additional paths webpack should look up modules
|
17
|
-
# ['app/assets', 'engine/foo/app/assets']
|
18
|
-
additional_paths:
|
19
|
-
- app/assets
|
20
|
-
- /etc/yarn
|
21
|
-
- some.config.js
|
22
|
-
- app/elm
|
23
|
-
|
24
|
-
# Reload manifest.json on all requests so we reload latest compiled packs
|
25
|
-
cache_manifest: false
|
26
|
-
|
27
|
-
static_assets_extensions:
|
28
|
-
- .jpg
|
29
|
-
- .jpeg
|
30
|
-
- .png
|
31
|
-
- .gif
|
32
|
-
- .tiff
|
33
|
-
- .ico
|
34
|
-
- .svg
|
35
|
-
|
36
|
-
extensions:
|
37
|
-
- .mjs
|
38
|
-
- .js
|
39
|
-
|
40
|
-
development:
|
41
|
-
<<: *default
|
42
|
-
compile: true
|
43
|
-
ensure_consistent_versioning: true
|
44
|
-
|
45
|
-
# Reference: https://webpack.js.org/configuration/dev-server/
|
46
|
-
dev_server:
|
47
|
-
https: false
|
48
|
-
host: localhost
|
49
|
-
port: 3035
|
50
|
-
public: localhost:3035
|
51
|
-
hmr: true
|
52
|
-
overlay: true
|
53
|
-
disable_host_check: true
|
54
|
-
use_local_ip: false
|
55
|
-
pretty: false
|
56
|
-
|
57
|
-
test:
|
58
|
-
<<: *default
|
59
|
-
compile: true
|
60
|
-
|
61
|
-
# Compile test packs to a separate directory
|
62
|
-
public_output_path: packs-test
|
63
|
-
|
64
|
-
production:
|
65
|
-
<<: *default
|
66
|
-
|
67
|
-
# Production depends on precompilation of packs prior to booting for performance.
|
68
|
-
compile: false
|
69
|
-
|
70
|
-
# Cache manifest.json for performance
|
71
|
-
cache_manifest: true
|
72
|
-
|
73
|
-
staging:
|
74
|
-
<<: *default
|
75
|
-
|
76
|
-
# Production depends on precompilation of packs prior to booting for performance.
|
77
|
-
compile: false
|
78
|
-
|
79
|
-
# Cache manifest.json for performance
|
80
|
-
cache_manifest: true
|
81
|
-
|
82
|
-
# Compile staging packs to a separate directory
|
83
|
-
public_output_path: packs-staging
|
@@ -1,84 +0,0 @@
|
|
1
|
-
# Note: You must restart bin/shakapacker-dev-server for changes to take effect
|
2
|
-
|
3
|
-
default: &default
|
4
|
-
source_path: app/packs
|
5
|
-
source_entry_path: entrypoints
|
6
|
-
nested_entries: true
|
7
|
-
public_root_path: public
|
8
|
-
public_output_path: packs
|
9
|
-
cache_path: tmp/webpacker
|
10
|
-
webpack_compile_output: false
|
11
|
-
webpack_loader: babel
|
12
|
-
css_extract_ignore_order_warnings: true
|
13
|
-
|
14
|
-
# Location for manifest.json, defaults to {public_output_path}/manifest.json if unset
|
15
|
-
# manifest_path: public/packs/manifest.json
|
16
|
-
|
17
|
-
# Additional paths webpack should look up modules
|
18
|
-
# ['app/assets', 'engine/foo/app/assets']
|
19
|
-
additional_paths:
|
20
|
-
- app/assets
|
21
|
-
- /etc/yarn
|
22
|
-
- some.config.js
|
23
|
-
- app/elm
|
24
|
-
|
25
|
-
# Reload manifest.json on all requests so we reload latest compiled packs
|
26
|
-
cache_manifest: false
|
27
|
-
|
28
|
-
static_assets_extensions:
|
29
|
-
- .jpg
|
30
|
-
- .jpeg
|
31
|
-
- .png
|
32
|
-
- .gif
|
33
|
-
- .tiff
|
34
|
-
- .ico
|
35
|
-
- .svg
|
36
|
-
|
37
|
-
extensions:
|
38
|
-
- .mjs
|
39
|
-
- .js
|
40
|
-
|
41
|
-
development:
|
42
|
-
<<: *default
|
43
|
-
compile: true
|
44
|
-
ensure_consistent_versioning: true
|
45
|
-
|
46
|
-
# Reference: https://webpack.js.org/configuration/dev-server/
|
47
|
-
dev_server:
|
48
|
-
https: false
|
49
|
-
host: localhost
|
50
|
-
port: 3035
|
51
|
-
public: localhost:3035
|
52
|
-
hmr: false
|
53
|
-
overlay: true
|
54
|
-
disable_host_check: true
|
55
|
-
use_local_ip: false
|
56
|
-
pretty: false
|
57
|
-
|
58
|
-
test:
|
59
|
-
<<: *default
|
60
|
-
compile: true
|
61
|
-
|
62
|
-
# Compile test packs to a separate directory
|
63
|
-
public_output_path: packs-test
|
64
|
-
|
65
|
-
production:
|
66
|
-
<<: *default
|
67
|
-
|
68
|
-
# Production depends on precompilation of packs prior to booting for performance.
|
69
|
-
compile: false
|
70
|
-
|
71
|
-
# Cache manifest.json for performance
|
72
|
-
cache_manifest: true
|
73
|
-
|
74
|
-
staging:
|
75
|
-
<<: *default
|
76
|
-
|
77
|
-
# Production depends on precompilation of packs prior to booting for performance.
|
78
|
-
compile: false
|
79
|
-
|
80
|
-
# Cache manifest.json for performance
|
81
|
-
cache_manifest: true
|
82
|
-
|
83
|
-
# Compile staging packs to a separate directory
|
84
|
-
public_output_path: packs-staging
|