shakapacker 7.3.0.beta.1 → 8.0.0.rc.2
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
@@ -17,41 +17,19 @@ module Shakapacker
|
|
17
17
|
|
18
18
|
def raise_if_gem_and_node_package_versions_differ
|
19
19
|
# Skip check if package is not in package.json or listed from relative path, git repo or github URL
|
20
|
-
|
20
|
+
# or if consistent version checking is not enabled
|
21
|
+
return if node_package_version.skip_processing? || !Shakapacker.config.ensure_consistent_versioning?
|
21
22
|
|
22
23
|
node_major_minor_patch = node_package_version.major_minor_patch
|
23
24
|
gem_major_minor_patch = gem_major_minor_patch_version
|
24
|
-
versions_match = node_major_minor_patch[0] == gem_major_minor_patch[0] &&
|
25
|
-
node_major_minor_patch[1] == gem_major_minor_patch[1] &&
|
26
|
-
node_major_minor_patch[2] == gem_major_minor_patch[2]
|
27
25
|
|
28
|
-
|
26
|
+
raise_differing_versions_warning unless (
|
27
|
+
node_major_minor_patch[0] == gem_major_minor_patch[0] &&
|
28
|
+
node_major_minor_patch[1] == gem_major_minor_patch[1] &&
|
29
|
+
node_major_minor_patch[2] == gem_major_minor_patch[2]
|
30
|
+
)
|
29
31
|
|
30
|
-
if
|
31
|
-
check_failed = if uses_wildcard
|
32
|
-
"Semver wildcard without a lockfile detected"
|
33
|
-
else
|
34
|
-
"Version mismatch detected"
|
35
|
-
end
|
36
|
-
|
37
|
-
warn <<-MSG.strip_heredoc
|
38
|
-
Shakapacker::VersionChecker - #{check_failed}
|
39
|
-
|
40
|
-
You are currently not checking for consistent versions of shakapacker gem and npm package. A version mismatch or usage of semantic versioning wildcard (~ or ^) without a lockfile has been detected.
|
41
|
-
|
42
|
-
Version mismatch can lead to incorrect behavior and bugs. You should ensure that both the gem and npm package dependencies are locked to the same version.
|
43
|
-
|
44
|
-
You can enable the version check by setting `ensure_consistent_versioning: true` in your `shakapacker.yml` file.
|
45
|
-
|
46
|
-
Checking for gem and npm package versions mismatch or wildcard will be enabled by default in the next major version of shakapacker.
|
47
|
-
MSG
|
48
|
-
|
49
|
-
return
|
50
|
-
end
|
51
|
-
|
52
|
-
raise_differing_versions_warning unless versions_match
|
53
|
-
|
54
|
-
raise_node_semver_version_warning if uses_wildcard
|
32
|
+
raise_node_semver_version_warning if node_package_version.semver_wildcard?
|
55
33
|
end
|
56
34
|
|
57
35
|
private
|
@@ -87,6 +65,7 @@ module Shakapacker
|
|
87
65
|
[match[1], match[2], match[3]]
|
88
66
|
end
|
89
67
|
|
68
|
+
# TODO: this might as well use package_json
|
90
69
|
class NodePackageVersion
|
91
70
|
attr_reader :package_json
|
92
71
|
|
@@ -23,16 +23,7 @@ module Shakapacker
|
|
23
23
|
|
24
24
|
cmd = build_cmd
|
25
25
|
|
26
|
-
if @argv.
|
27
|
-
Shakapacker.puts_deprecation_message(
|
28
|
-
Shakapacker.short_deprecation_message(
|
29
|
-
"--debug-webpacker",
|
30
|
-
"--debug-shakapacker"
|
31
|
-
)
|
32
|
-
)
|
33
|
-
end
|
34
|
-
|
35
|
-
if @argv.delete("--debug-shakapacker") || @argv.delete("--debug-webpacker")
|
26
|
+
if @argv.delete("--debug-shakapacker")
|
36
27
|
env["NODE_OPTIONS"] = "#{env["NODE_OPTIONS"]} --inspect-brk"
|
37
28
|
end
|
38
29
|
|
@@ -59,17 +50,7 @@ module Shakapacker
|
|
59
50
|
private
|
60
51
|
|
61
52
|
def build_cmd
|
62
|
-
|
63
|
-
return package_json.manager.native_exec_command("webpack")
|
64
|
-
end
|
65
|
-
|
66
|
-
return ["#{@node_modules_bin_path}/webpack"] if node_modules_bin_exist?
|
67
|
-
|
68
|
-
["yarn", "webpack"]
|
69
|
-
end
|
70
|
-
|
71
|
-
def node_modules_bin_exist?
|
72
|
-
File.exist?("#{@node_modules_bin_path}/webpack")
|
53
|
+
package_json.manager.native_exec_command("webpack")
|
73
54
|
end
|
74
55
|
end
|
75
56
|
end
|
data/lib/shakapacker.rb
CHANGED
@@ -1,34 +1,20 @@
|
|
1
1
|
namespace :shakapacker do
|
2
2
|
desc "Verifies that bin/shakapacker is present"
|
3
3
|
task :check_binstubs do
|
4
|
-
verify_file_existence("bin/shakapacker"
|
5
|
-
verify_file_existence("bin/shakapacker-dev-server"
|
4
|
+
verify_file_existence("bin/shakapacker")
|
5
|
+
verify_file_existence("bin/shakapacker-dev-server")
|
6
6
|
end
|
7
7
|
end
|
8
8
|
|
9
|
-
def
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
alternative_file,
|
20
|
-
main_file
|
21
|
-
)
|
22
|
-
)
|
23
|
-
else
|
24
|
-
puts <<~MSG
|
25
|
-
Couldn't find shakapacker binstubs!
|
26
|
-
Possible solutions:
|
27
|
-
- Ensure you have run `rails shakapacker:install`.
|
28
|
-
- Run `rails shakapacker:binstubs` if you have already installed shakapacker.
|
29
|
-
- Ensure the `bin` directory, `bin/shakapacker`, and `bin/shakapacker-dev-server` are not included in .gitignore.
|
30
|
-
MSG
|
31
|
-
exit!
|
32
|
-
end
|
9
|
+
def verify_file_existence(binstub_file)
|
10
|
+
unless File.exist?(Rails.root.join(binstub_file))
|
11
|
+
puts <<~MSG
|
12
|
+
Couldn't find shakapacker binstubs!
|
13
|
+
Possible solutions:
|
14
|
+
- Ensure you have run `rails shakapacker:install`.
|
15
|
+
- Run `rails shakapacker:binstubs` if you have already installed shakapacker.
|
16
|
+
- Ensure the `bin` directory, `bin/shakapacker`, and `bin/shakapacker-dev-server` are not included in .gitignore.
|
17
|
+
MSG
|
18
|
+
exit!
|
33
19
|
end
|
34
20
|
end
|
@@ -1,15 +1,10 @@
|
|
1
1
|
require "shakapacker/utils/misc"
|
2
|
+
require "shakapacker/utils/manager"
|
2
3
|
|
3
4
|
namespace :shakapacker do
|
4
5
|
desc "Verifies if the expected JS package manager is installed"
|
5
|
-
task :check_manager do
|
6
|
-
|
7
|
-
prefix = task.name.split(/#|shakapacker:/).first
|
8
|
-
Rake::Task["#{prefix}shakapacker:check_manager"].invoke
|
9
|
-
next
|
10
|
-
end
|
11
|
-
|
12
|
-
require "package_json"
|
6
|
+
task :check_manager do
|
7
|
+
Shakapacker::Utils::Manager.error_unless_package_manager_is_obvious!
|
13
8
|
|
14
9
|
package_json = PackageJson.read
|
15
10
|
pm = package_json.manager.binary
|
@@ -1,5 +1,6 @@
|
|
1
1
|
require "shakapacker/version"
|
2
2
|
require "shakapacker/utils/misc"
|
3
|
+
require "shakapacker/utils/manager"
|
3
4
|
|
4
5
|
namespace :shakapacker do
|
5
6
|
desc "Provide information on Shakapacker's environment"
|
@@ -9,30 +10,20 @@ namespace :shakapacker do
|
|
9
10
|
$stdout.puts "Rails: #{Rails.version}"
|
10
11
|
$stdout.puts "Shakapacker: #{Shakapacker::VERSION}"
|
11
12
|
$stdout.puts "Node: #{`node --version`}"
|
12
|
-
if Shakapacker::Utils::Misc.use_package_json_gem
|
13
|
-
require "package_json"
|
14
13
|
|
15
|
-
|
14
|
+
Shakapacker::Utils::Manager.error_unless_package_manager_is_obvious!
|
16
15
|
|
17
|
-
|
18
|
-
else
|
19
|
-
$stdout.puts "Yarn: #{`yarn --version`}"
|
20
|
-
end
|
16
|
+
pj_manager = PackageJson.read.manager
|
21
17
|
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
node_package_version = `npm list shakapacker version`
|
26
|
-
end
|
18
|
+
$stdout.puts "#{pj_manager.binary}: #{pj_manager.version}"
|
19
|
+
|
20
|
+
node_package_version = Shakapacker::VersionChecker.build.node_package_version.raw
|
27
21
|
|
28
22
|
$stdout.puts "\n"
|
29
23
|
$stdout.puts "shakapacker: #{node_package_version}"
|
30
24
|
|
31
25
|
$stdout.puts "Is bin/shakapacker present?: #{File.exist? 'bin/shakapacker'}"
|
32
26
|
$stdout.puts "Is bin/shakapacker-dev-server present?: #{File.exist? 'bin/shakapacker-dev-server'}"
|
33
|
-
unless Shakapacker::Utils::Misc.use_package_json_gem
|
34
|
-
$stdout.puts "Is bin/yarn present?: #{File.exist? 'bin/yarn'}"
|
35
|
-
end
|
36
27
|
end
|
37
28
|
end
|
38
29
|
end
|
data/package/babel/preset.js
CHANGED
@@ -1,11 +1,11 @@
|
|
1
|
-
const { moduleExists } = require(
|
1
|
+
const { moduleExists } = require("shakapacker")
|
2
2
|
|
3
3
|
module.exports = function config(api) {
|
4
|
-
const validEnv = [
|
4
|
+
const validEnv = ["development", "test", "production"]
|
5
5
|
const currentEnv = api.env()
|
6
|
-
const isDevelopmentEnv = api.env(
|
7
|
-
const isProductionEnv = api.env(
|
8
|
-
const isTestEnv = api.env(
|
6
|
+
const isDevelopmentEnv = api.env("development")
|
7
|
+
const isProductionEnv = api.env("production")
|
8
|
+
const isTestEnv = api.env("test")
|
9
9
|
|
10
10
|
if (!validEnv.includes(currentEnv)) {
|
11
11
|
throw new Error(
|
@@ -17,21 +17,21 @@ module.exports = function config(api) {
|
|
17
17
|
|
18
18
|
return {
|
19
19
|
presets: [
|
20
|
-
isTestEnv && [
|
20
|
+
isTestEnv && ["@babel/preset-env", { targets: { node: "current" } }],
|
21
21
|
(isProductionEnv || isDevelopmentEnv) && [
|
22
|
-
|
22
|
+
"@babel/preset-env",
|
23
23
|
{
|
24
|
-
useBuiltIns:
|
25
|
-
corejs:
|
26
|
-
modules:
|
24
|
+
useBuiltIns: "entry",
|
25
|
+
corejs: "3.8",
|
26
|
+
modules: "auto",
|
27
27
|
bugfixes: true,
|
28
|
-
exclude: [
|
28
|
+
exclude: ["transform-typeof-symbol"]
|
29
29
|
}
|
30
30
|
],
|
31
|
-
moduleExists(
|
31
|
+
moduleExists("@babel/preset-typescript") && "@babel/preset-typescript"
|
32
32
|
].filter(Boolean),
|
33
|
-
plugins: [
|
34
|
-
|
35
|
-
|
33
|
+
plugins: [["@babel/plugin-transform-runtime", { helpers: false }]].filter(
|
34
|
+
Boolean
|
35
|
+
)
|
36
36
|
}
|
37
37
|
}
|
data/package/config.js
CHANGED
@@ -1,19 +1,16 @@
|
|
1
|
-
const { resolve } = require(
|
2
|
-
const { load } = require(
|
3
|
-
const { existsSync, readFileSync } = require(
|
1
|
+
const { resolve } = require("path")
|
2
|
+
const { load } = require("js-yaml")
|
3
|
+
const { existsSync, readFileSync } = require("fs")
|
4
4
|
|
5
|
-
const { merge } = require(
|
6
|
-
const {
|
7
|
-
|
8
|
-
|
9
|
-
} = require('./utils/helpers')
|
10
|
-
const { railsEnv } = require('./env')
|
11
|
-
const configPath = require('./utils/configPath')
|
5
|
+
const { merge } = require("webpack-merge")
|
6
|
+
const { ensureTrailingSlash } = require("./utils/helpers")
|
7
|
+
const { railsEnv } = require("./env")
|
8
|
+
const configPath = require("./utils/configPath")
|
12
9
|
|
13
|
-
const defaultConfigPath = require(
|
10
|
+
const defaultConfigPath = require("./utils/defaultConfigPath")
|
14
11
|
|
15
12
|
const getDefaultConfig = () => {
|
16
|
-
const defaultConfig = load(readFileSync(defaultConfigPath),
|
13
|
+
const defaultConfig = load(readFileSync(defaultConfigPath), "utf8")
|
17
14
|
return defaultConfig[railsEnv] || defaultConfig.production
|
18
15
|
}
|
19
16
|
|
@@ -21,12 +18,14 @@ const defaults = getDefaultConfig()
|
|
21
18
|
let config
|
22
19
|
|
23
20
|
if (existsSync(configPath)) {
|
24
|
-
const appYmlObject = load(readFileSync(configPath),
|
21
|
+
const appYmlObject = load(readFileSync(configPath), "utf8")
|
25
22
|
const envAppConfig = appYmlObject[railsEnv]
|
26
23
|
|
27
24
|
if (!envAppConfig) {
|
28
25
|
/* eslint no-console:0 */
|
29
|
-
console.warn(
|
26
|
+
console.warn(
|
27
|
+
`Warning: ${railsEnv} key not found in the configuration file. Using production configuration as a fallback.`
|
28
|
+
)
|
30
29
|
}
|
31
30
|
|
32
31
|
config = merge(defaults, envAppConfig || {})
|
@@ -39,8 +38,7 @@ config.outputPath = resolve(config.public_root_path, config.public_output_path)
|
|
39
38
|
// Ensure that the publicPath includes our asset host so dynamic imports
|
40
39
|
// (code-splitting chunks and static assets) load from the CDN instead of a relative path.
|
41
40
|
const getPublicPath = () => {
|
42
|
-
|
43
|
-
const rootUrl = ensureTrailingSlash(process.env.SHAKAPACKER_ASSET_HOST || '/')
|
41
|
+
const rootUrl = ensureTrailingSlash(process.env.SHAKAPACKER_ASSET_HOST || "/")
|
44
42
|
return `${rootUrl}${config.public_output_path}/`
|
45
43
|
}
|
46
44
|
|
@@ -50,9 +48,7 @@ config.publicPathWithoutCDN = `/${config.public_output_path}/`
|
|
50
48
|
if (config.manifest_path) {
|
51
49
|
config.manifestPath = resolve(config.manifest_path)
|
52
50
|
} else {
|
53
|
-
config.manifestPath = resolve(config.outputPath,
|
51
|
+
config.manifestPath = resolve(config.outputPath, "manifest.json")
|
54
52
|
}
|
55
53
|
|
56
|
-
config.includePaths = [config.source_path, ...config.additional_paths]
|
57
|
-
|
58
54
|
module.exports = config
|
data/package/dev_server.js
CHANGED
@@ -1,6 +1,6 @@
|
|
1
|
-
// These are the raw
|
2
|
-
const { isBoolean } = require(
|
3
|
-
const config = require(
|
1
|
+
// These are the raw shakapacker dev server config settings from the YML file with ENV overrides applied.
|
2
|
+
const { isBoolean } = require("./utils/helpers")
|
3
|
+
const config = require("./config")
|
4
4
|
|
5
5
|
const envFetch = (key) => {
|
6
6
|
const value = process.env[key]
|
@@ -10,7 +10,7 @@ const envFetch = (key) => {
|
|
10
10
|
const devServerConfig = config.dev_server
|
11
11
|
|
12
12
|
if (devServerConfig) {
|
13
|
-
const envPrefix = config.dev_server.env_prefix ||
|
13
|
+
const envPrefix = config.dev_server.env_prefix || "SHAKAPACKER_DEV_SERVER"
|
14
14
|
|
15
15
|
Object.keys(devServerConfig).forEach((key) => {
|
16
16
|
const envValue = envFetch(`${envPrefix}_${key.toUpperCase()}`)
|
data/package/env.js
CHANGED
@@ -1,40 +1,42 @@
|
|
1
|
-
const { load } = require(
|
2
|
-
const { readFileSync } = require(
|
3
|
-
const defaultConfigPath = require(
|
1
|
+
const { load } = require("js-yaml")
|
2
|
+
const { readFileSync } = require("fs")
|
3
|
+
const defaultConfigPath = require("./utils/defaultConfigPath")
|
4
4
|
|
5
|
-
const NODE_ENVIRONMENTS = [
|
6
|
-
const DEFAULT =
|
7
|
-
const configPath = require(
|
5
|
+
const NODE_ENVIRONMENTS = ["development", "production", "test"]
|
6
|
+
const DEFAULT = "production"
|
7
|
+
const configPath = require("./utils/configPath")
|
8
8
|
|
9
9
|
const railsEnv = process.env.RAILS_ENV
|
10
10
|
const rawNodeEnv = process.env.NODE_ENV
|
11
|
-
const nodeEnv
|
12
|
-
|
13
|
-
const isProduction = nodeEnv ===
|
14
|
-
const isDevelopment = nodeEnv ===
|
11
|
+
const nodeEnv =
|
12
|
+
rawNodeEnv && NODE_ENVIRONMENTS.includes(rawNodeEnv) ? rawNodeEnv : DEFAULT
|
13
|
+
const isProduction = nodeEnv === "production"
|
14
|
+
const isDevelopment = nodeEnv === "development"
|
15
15
|
|
16
16
|
let config
|
17
17
|
try {
|
18
|
-
config = load(readFileSync(configPath),
|
18
|
+
config = load(readFileSync(configPath), "utf8")
|
19
19
|
} catch (error) {
|
20
|
-
if (error.code ===
|
20
|
+
if (error.code === "ENOENT") {
|
21
21
|
// File not found, use default configuration
|
22
|
-
config = load(readFileSync(defaultConfigPath),
|
22
|
+
config = load(readFileSync(defaultConfigPath), "utf8")
|
23
23
|
} else {
|
24
24
|
throw error
|
25
25
|
}
|
26
26
|
}
|
27
27
|
|
28
|
-
const availableEnvironments = Object.keys(config).join(
|
29
|
-
const regex = new RegExp(`^(${availableEnvironments})$`,
|
28
|
+
const availableEnvironments = Object.keys(config).join("|")
|
29
|
+
const regex = new RegExp(`^(${availableEnvironments})$`, "g")
|
30
30
|
|
31
|
-
const runningWebpackDevServer = process.env.WEBPACK_SERVE ===
|
31
|
+
const runningWebpackDevServer = process.env.WEBPACK_SERVE === "true"
|
32
32
|
|
33
33
|
const validatedRailsEnv = railsEnv && railsEnv.match(regex) ? railsEnv : DEFAULT
|
34
34
|
|
35
35
|
if (railsEnv && validatedRailsEnv !== railsEnv) {
|
36
36
|
/* eslint no-console:0 */
|
37
|
-
console.warn(
|
37
|
+
console.warn(
|
38
|
+
`Warning: '${railsEnv}' environment not found in the configuration. Using '${DEFAULT}' configuration as a fallback.`
|
39
|
+
)
|
38
40
|
}
|
39
41
|
|
40
42
|
module.exports = {
|
@@ -1,28 +1,45 @@
|
|
1
1
|
/* eslint global-require: 0 */
|
2
2
|
/* eslint import/no-dynamic-require: 0 */
|
3
3
|
|
4
|
-
const {
|
5
|
-
const
|
6
|
-
const
|
7
|
-
const WebpackAssetsManifest = require(
|
8
|
-
const webpack = require(
|
9
|
-
const rules = require(
|
10
|
-
const config = require(
|
11
|
-
const { isProduction } = require(
|
12
|
-
const { moduleExists } = require(
|
4
|
+
const { existsSync, readdirSync } = require("fs")
|
5
|
+
const { basename, dirname, join, relative, resolve } = require("path")
|
6
|
+
const extname = require("path-complete-extname")
|
7
|
+
const WebpackAssetsManifest = require("webpack-assets-manifest")
|
8
|
+
const webpack = require("webpack")
|
9
|
+
const rules = require("../rules")
|
10
|
+
const config = require("../config")
|
11
|
+
const { isProduction } = require("../env")
|
12
|
+
const { moduleExists } = require("../utils/helpers")
|
13
|
+
|
14
|
+
const getFilesInDirectory = (dir, includeNested) => {
|
15
|
+
if (!existsSync(dir)) {
|
16
|
+
return []
|
17
|
+
}
|
18
|
+
|
19
|
+
return readdirSync(dir, { withFileTypes: true }).flatMap((dirent) => {
|
20
|
+
const filePath = join(dir, dirent.name)
|
21
|
+
|
22
|
+
if (dirent.isDirectory() && includeNested) {
|
23
|
+
return getFilesInDirectory(filePath, includeNested)
|
24
|
+
}
|
25
|
+
if (dirent.isFile()) {
|
26
|
+
return filePath
|
27
|
+
}
|
28
|
+
return []
|
29
|
+
})
|
30
|
+
}
|
13
31
|
|
14
32
|
const getEntryObject = () => {
|
15
33
|
const entries = {}
|
16
34
|
const rootPath = join(config.source_path, config.source_entry_path)
|
17
|
-
if (config.source_entry_path ===
|
35
|
+
if (config.source_entry_path === "/" && config.nested_entries) {
|
18
36
|
throw new Error(
|
19
37
|
"Your shakapacker config specified using a source_entry_path of '/' with 'nested_entries' == " +
|
20
|
-
|
38
|
+
"'true'. Doing this would result in packs for every one of your source files"
|
21
39
|
)
|
22
40
|
}
|
23
|
-
const nesting = config.nested_entries ? '**/' : ''
|
24
41
|
|
25
|
-
|
42
|
+
getFilesInDirectory(rootPath, config.nested_entries).forEach((path) => {
|
26
43
|
const namespace = relative(join(rootPath), dirname(path))
|
27
44
|
const name = join(namespace, basename(path, extname(path)))
|
28
45
|
let assetPaths = resolve(path)
|
@@ -50,7 +67,7 @@ const getModulePaths = () => {
|
|
50
67
|
if (config.additional_paths) {
|
51
68
|
config.additional_paths.forEach((path) => result.push(resolve(path)))
|
52
69
|
}
|
53
|
-
result.push(
|
70
|
+
result.push("node_modules")
|
54
71
|
|
55
72
|
return result
|
56
73
|
}
|
@@ -67,9 +84,9 @@ const getPlugins = () => {
|
|
67
84
|
})
|
68
85
|
]
|
69
86
|
|
70
|
-
if (moduleExists(
|
71
|
-
const hash = isProduction || config.useContentHash ?
|
72
|
-
const MiniCssExtractPlugin = require(
|
87
|
+
if (moduleExists("css-loader") && moduleExists("mini-css-extract-plugin")) {
|
88
|
+
const hash = isProduction || config.useContentHash ? "-[contenthash:8]" : ""
|
89
|
+
const MiniCssExtractPlugin = require("mini-css-extract-plugin")
|
73
90
|
plugins.push(
|
74
91
|
new MiniCssExtractPlugin({
|
75
92
|
filename: `css/[name]${hash}.css`,
|
@@ -87,35 +104,35 @@ const getPlugins = () => {
|
|
87
104
|
|
88
105
|
// Don't use contentHash except for production for performance
|
89
106
|
// https://webpack.js.org/guides/build-performance/#avoid-production-specific-tooling
|
90
|
-
const hash = isProduction || config.useContentHash ?
|
107
|
+
const hash = isProduction || config.useContentHash ? "-[contenthash]" : ""
|
91
108
|
|
92
109
|
module.exports = {
|
93
|
-
mode:
|
110
|
+
mode: "production",
|
94
111
|
output: {
|
95
112
|
filename: `js/[name]${hash}.js`,
|
96
113
|
chunkFilename: `js/[name]${hash}.chunk.js`,
|
97
114
|
|
98
115
|
// https://webpack.js.org/configuration/output/#outputhotupdatechunkfilename
|
99
|
-
hotUpdateChunkFilename:
|
116
|
+
hotUpdateChunkFilename: "js/[id].[fullhash].hot-update.js",
|
100
117
|
path: config.outputPath,
|
101
118
|
publicPath: config.publicPath
|
102
119
|
},
|
103
120
|
entry: getEntryObject(),
|
104
121
|
resolve: {
|
105
|
-
extensions: [
|
122
|
+
extensions: [".js", ".jsx", ".mjs", ".ts", ".tsx", ".coffee"],
|
106
123
|
modules: getModulePaths()
|
107
124
|
},
|
108
125
|
|
109
126
|
plugins: getPlugins(),
|
110
127
|
|
111
128
|
resolveLoader: {
|
112
|
-
modules: [
|
129
|
+
modules: ["node_modules"]
|
113
130
|
},
|
114
131
|
|
115
132
|
optimization: {
|
116
|
-
splitChunks: { chunks:
|
133
|
+
splitChunks: { chunks: "all" },
|
117
134
|
|
118
|
-
runtimeChunk:
|
135
|
+
runtimeChunk: "single"
|
119
136
|
},
|
120
137
|
|
121
138
|
module: {
|
@@ -1,12 +1,12 @@
|
|
1
|
-
const { merge } = require(
|
1
|
+
const { merge } = require("webpack-merge")
|
2
2
|
|
3
|
-
const baseConfig = require(
|
4
|
-
const webpackDevServerConfig
|
5
|
-
const { runningWebpackDevServer } = require(
|
3
|
+
const baseConfig = require("./base")
|
4
|
+
const webpackDevServerConfig = require("../webpackDevServerConfig")
|
5
|
+
const { runningWebpackDevServer } = require("../env")
|
6
6
|
|
7
7
|
const devConfig = {
|
8
|
-
mode:
|
9
|
-
devtool:
|
8
|
+
mode: "development",
|
9
|
+
devtool: "cheap-module-source-map",
|
10
10
|
...(runningWebpackDevServer && { devServer: webpackDevServerConfig() })
|
11
11
|
}
|
12
12
|
|
@@ -1,29 +1,29 @@
|
|
1
1
|
/* eslint global-require: 0 */
|
2
2
|
/* eslint import/no-dynamic-require: 0 */
|
3
3
|
|
4
|
-
const { merge } = require(
|
5
|
-
const CompressionPlugin = require(
|
6
|
-
const TerserPlugin = require(
|
7
|
-
const baseConfig = require(
|
8
|
-
const { moduleExists } = require(
|
9
|
-
const config = require(
|
4
|
+
const { merge } = require("webpack-merge")
|
5
|
+
const CompressionPlugin = require("compression-webpack-plugin")
|
6
|
+
const TerserPlugin = require("terser-webpack-plugin")
|
7
|
+
const baseConfig = require("./base")
|
8
|
+
const { moduleExists } = require("../utils/helpers")
|
9
|
+
const config = require("../config")
|
10
10
|
|
11
11
|
const getPlugins = () => {
|
12
12
|
const plugins = []
|
13
13
|
|
14
14
|
plugins.push(
|
15
15
|
new CompressionPlugin({
|
16
|
-
filename:
|
17
|
-
algorithm:
|
16
|
+
filename: "[path][base].gz[query]",
|
17
|
+
algorithm: "gzip",
|
18
18
|
test: /\.(js|css|html|json|ico|svg|eot|otf|ttf|map)$/
|
19
19
|
})
|
20
20
|
)
|
21
21
|
|
22
|
-
if (
|
22
|
+
if ("brotli" in process.versions) {
|
23
23
|
plugins.push(
|
24
24
|
new CompressionPlugin({
|
25
|
-
filename:
|
26
|
-
algorithm:
|
25
|
+
filename: "[path][base].br[query]",
|
26
|
+
algorithm: "brotliCompress",
|
27
27
|
test: /\.(js|css|html|json|ico|svg|eot|otf|ttf|map)$/
|
28
28
|
})
|
29
29
|
)
|
@@ -34,10 +34,10 @@ const getPlugins = () => {
|
|
34
34
|
|
35
35
|
const tryCssMinimizer = () => {
|
36
36
|
if (
|
37
|
-
moduleExists(
|
38
|
-
moduleExists(
|
37
|
+
moduleExists("css-loader") &&
|
38
|
+
moduleExists("css-minimizer-webpack-plugin")
|
39
39
|
) {
|
40
|
-
const CssMinimizerPlugin = require(
|
40
|
+
const CssMinimizerPlugin = require("css-minimizer-webpack-plugin")
|
41
41
|
return new CssMinimizerPlugin()
|
42
42
|
}
|
43
43
|
|
@@ -45,8 +45,8 @@ const tryCssMinimizer = () => {
|
|
45
45
|
}
|
46
46
|
|
47
47
|
const productionConfig = {
|
48
|
-
devtool:
|
49
|
-
stats:
|
48
|
+
devtool: "source-map",
|
49
|
+
stats: "normal",
|
50
50
|
bail: true,
|
51
51
|
plugins: getPlugins(),
|
52
52
|
optimization: {
|