shakapacker 8.0.0 → 8.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/workflows/dummy.yml +1 -1
- data/.github/workflows/generator.yml +5 -1
- data/.github/workflows/node.yml +1 -1
- data/.github/workflows/ruby.yml +8 -2
- data/.gitignore +0 -1
- data/.node-version +1 -1
- data/CHANGELOG.md +21 -12
- data/Gemfile.lock +257 -0
- data/README.md +11 -12
- data/docs/customizing_babel_config.md +32 -4
- data/docs/react.md +3 -2
- data/docs/troubleshooting.md +1 -1
- data/docs/v8_upgrade.md +2 -2
- data/lib/shakapacker/version.rb +1 -1
- data/package.json +2 -2
- data/shakapacker.gemspec +5 -2
- metadata +5 -235
- data/lib/install/bin/yarn +0 -18
- data/rakelib/release.rake +0 -65
- data/spec/dummy/.browserslistrc +0 -1
- data/spec/dummy/.gitignore +0 -20
- data/spec/dummy/.prettierrc.yaml +0 -4
- data/spec/dummy/Gemfile +0 -61
- data/spec/dummy/Procfile.dev +0 -5
- data/spec/dummy/Procfile.dev-static +0 -9
- data/spec/dummy/README.md +0 -1
- data/spec/dummy/Rakefile +0 -6
- data/spec/dummy/app/assets/config/manifest.js +0 -2
- data/spec/dummy/app/assets/images/.keep +0 -0
- data/spec/dummy/app/assets/stylesheets/application.css +0 -15
- data/spec/dummy/app/channels/application_cable/channel.rb +0 -4
- data/spec/dummy/app/channels/application_cable/connection.rb +0 -4
- data/spec/dummy/app/controllers/application_controller.rb +0 -2
- data/spec/dummy/app/controllers/concerns/.keep +0 -0
- data/spec/dummy/app/controllers/hello_world_controller.rb +0 -9
- data/spec/dummy/app/helpers/application_helper.rb +0 -2
- data/spec/dummy/app/javascript/Globals.d.ts +0 -3
- data/spec/dummy/app/javascript/bundles/HelloWorld/components/HelloWorld.module.css +0 -25
- data/spec/dummy/app/javascript/bundles/HelloWorld/components/HelloWorld.tsx +0 -47
- data/spec/dummy/app/javascript/bundles/HelloWorld/components/HelloWorldServer.tsx +0 -5
- data/spec/dummy/app/javascript/bundles/HelloWorld/components/logo.svg +0 -7
- data/spec/dummy/app/javascript/packs/application.js +0 -17
- data/spec/dummy/app/javascript/packs/hello-world-bundle.ts +0 -8
- data/spec/dummy/app/javascript/packs/server-bundle.ts +0 -8
- data/spec/dummy/app/jobs/application_job.rb +0 -7
- data/spec/dummy/app/mailers/application_mailer.rb +0 -4
- data/spec/dummy/app/models/application_record.rb +0 -3
- data/spec/dummy/app/models/concerns/.keep +0 -0
- data/spec/dummy/app/views/hello_world/index.html.erb +0 -2
- data/spec/dummy/app/views/layouts/application.html.erb +0 -14
- data/spec/dummy/app/views/layouts/hello_world.html.erb +0 -13
- data/spec/dummy/app/views/layouts/mailer.html.erb +0 -13
- data/spec/dummy/app/views/layouts/mailer.text.erb +0 -1
- data/spec/dummy/babel.config.js +0 -30
- data/spec/dummy/bin/bundle +0 -114
- data/spec/dummy/bin/dev +0 -30
- data/spec/dummy/bin/dev-static +0 -30
- data/spec/dummy/bin/rails +0 -9
- data/spec/dummy/bin/rake +0 -9
- data/spec/dummy/bin/setup +0 -33
- data/spec/dummy/bin/shakapacker +0 -13
- data/spec/dummy/bin/shakapacker-dev-server +0 -13
- data/spec/dummy/bin/spring +0 -17
- data/spec/dummy/bin/yarn +0 -18
- data/spec/dummy/config/application.rb +0 -35
- data/spec/dummy/config/boot.rb +0 -4
- data/spec/dummy/config/cable.yml +0 -10
- data/spec/dummy/config/credentials.yml.enc +0 -1
- data/spec/dummy/config/database.yml +0 -25
- data/spec/dummy/config/environment.rb +0 -5
- data/spec/dummy/config/environments/development.rb +0 -54
- data/spec/dummy/config/environments/production.rb +0 -106
- data/spec/dummy/config/environments/test.rb +0 -49
- data/spec/dummy/config/initializers/application_controller_renderer.rb +0 -8
- data/spec/dummy/config/initializers/backtrace_silencers.rb +0 -7
- data/spec/dummy/config/initializers/content_security_policy.rb +0 -28
- data/spec/dummy/config/initializers/cookies_serializer.rb +0 -5
- data/spec/dummy/config/initializers/filter_parameter_logging.rb +0 -4
- data/spec/dummy/config/initializers/inflections.rb +0 -16
- data/spec/dummy/config/initializers/mime_types.rb +0 -4
- data/spec/dummy/config/initializers/react_on_rails.rb +0 -58
- data/spec/dummy/config/initializers/wrap_parameters.rb +0 -14
- data/spec/dummy/config/locales/en.yml +0 -33
- data/spec/dummy/config/puma.rb +0 -38
- data/spec/dummy/config/routes.rb +0 -6
- data/spec/dummy/config/shakapacker.yml +0 -61
- data/spec/dummy/config/spring.rb +0 -6
- data/spec/dummy/config/storage.yml +0 -34
- data/spec/dummy/config/webpack/ServerClientOrBoth.js +0 -34
- data/spec/dummy/config/webpack/clientWebpackConfig.js +0 -15
- data/spec/dummy/config/webpack/commonWebpackConfig.js +0 -17
- data/spec/dummy/config/webpack/development.js +0 -32
- data/spec/dummy/config/webpack/production.js +0 -9
- data/spec/dummy/config/webpack/serverWebpackConfig.js +0 -116
- data/spec/dummy/config/webpack/test.js +0 -7
- data/spec/dummy/config/webpack/webpack.config.js +0 -24
- data/spec/dummy/config.ru +0 -5
- data/spec/dummy/db/seeds.rb +0 -7
- data/spec/dummy/lib/assets/.keep +0 -0
- data/spec/dummy/lib/tasks/.keep +0 -0
- data/spec/dummy/package.json +0 -44
- data/spec/dummy/postcss.config.js +0 -12
- data/spec/dummy/public/404.html +0 -67
- data/spec/dummy/public/422.html +0 -67
- data/spec/dummy/public/500.html +0 -66
- data/spec/dummy/public/apple-touch-icon-precomposed.png +0 -0
- data/spec/dummy/public/apple-touch-icon.png +0 -0
- data/spec/dummy/public/favicon.ico +0 -0
- data/spec/dummy/public/robots.txt +0 -1
- data/spec/dummy/spec/rails_helper.rb +0 -118
- data/spec/dummy/spec/spec_helper.rb +0 -96
- data/spec/dummy/spec/system/hello_world_spec.rb +0 -19
- data/spec/dummy/tsconfig.json +0 -21
- data/spec/dummy/vendor/.keep +0 -0
- data/spec/dummy/yarn.lock +0 -4696
- data/spec/fixtures/beta_package-lock.v1.json +0 -119
- data/spec/fixtures/beta_package-lock.v2.json +0 -6777
- data/spec/fixtures/beta_package.json +0 -13
- data/spec/fixtures/beta_pnpm-lock.v7.yaml +0 -116
- data/spec/fixtures/beta_pnpm-lock.v8.yaml +0 -2537
- data/spec/fixtures/beta_pnpm-lock.v9.yaml +0 -2885
- data/spec/fixtures/beta_yarn.v1.lock +0 -106
- data/spec/fixtures/beta_yarn.v2.lock +0 -164
- data/spec/fixtures/git_url_package-lock.v1.json +0 -118
- data/spec/fixtures/git_url_package-lock.v2.json +0 -10263
- data/spec/fixtures/git_url_package.json +0 -13
- data/spec/fixtures/git_url_pnpm-lock.v7.yaml +0 -126
- data/spec/fixtures/git_url_pnpm-lock.v8.yaml +0 -3728
- data/spec/fixtures/git_url_pnpm-lock.v9.yaml +0 -4544
- data/spec/fixtures/git_url_yarn.v1.lock +0 -106
- data/spec/fixtures/git_url_yarn.v2.lock +0 -165
- data/spec/fixtures/github_url_package-lock.v1.json +0 -118
- data/spec/fixtures/github_url_package-lock.v2.json +0 -10263
- data/spec/fixtures/github_url_package.json +0 -13
- data/spec/fixtures/github_url_pnpm-lock.v7.yaml +0 -126
- data/spec/fixtures/github_url_pnpm-lock.v8.yaml +0 -3728
- data/spec/fixtures/github_url_pnpm-lock.v9.yaml +0 -4544
- data/spec/fixtures/github_url_yarn.v1.lock +0 -105
- data/spec/fixtures/github_url_yarn.v2.lock +0 -165
- data/spec/fixtures/relative_path_package-lock.v1.json +0 -3468
- data/spec/fixtures/relative_path_package-lock.v2.json +0 -105
- data/spec/fixtures/relative_path_package.json +0 -13
- data/spec/fixtures/relative_path_pnpm-lock.v7.yaml +0 -18
- data/spec/fixtures/relative_path_pnpm-lock.v8.yaml +0 -22
- data/spec/fixtures/relative_path_pnpm-lock.v9.yaml +0 -28
- data/spec/fixtures/relative_path_yarn.v1.lock +0 -104
- data/spec/fixtures/relative_path_yarn.v2.lock +0 -165
- data/spec/fixtures/semver_caret_package-lock.v1.json +0 -119
- data/spec/fixtures/semver_caret_package-lock.v2.json +0 -10264
- data/spec/fixtures/semver_caret_package.json +0 -13
- data/spec/fixtures/semver_caret_pnpm-lock.v7.yaml +0 -117
- data/spec/fixtures/semver_caret_pnpm-lock.v8.yaml +0 -2558
- data/spec/fixtures/semver_caret_pnpm-lock.v9.yaml +0 -4285
- data/spec/fixtures/semver_caret_yarn.v1.lock +0 -106
- data/spec/fixtures/semver_caret_yarn.v2.lock +0 -165
- data/spec/fixtures/semver_exact_package-lock.v1.json +0 -119
- data/spec/fixtures/semver_exact_package-lock.v2.json +0 -6819
- data/spec/fixtures/semver_exact_package.json +0 -13
- data/spec/fixtures/semver_exact_pnpm-lock.v7.yaml +0 -117
- data/spec/fixtures/semver_exact_pnpm-lock.v8.yaml +0 -2558
- data/spec/fixtures/semver_exact_pnpm-lock.v9.yaml +0 -2908
- data/spec/fixtures/semver_exact_yarn.v1.lock +0 -106
- data/spec/fixtures/semver_exact_yarn.v2.lock +0 -165
- data/spec/fixtures/semver_tilde_package-lock.v1.json +0 -119
- data/spec/fixtures/semver_tilde_package-lock.v2.json +0 -6777
- data/spec/fixtures/semver_tilde_package.json +0 -13
- data/spec/fixtures/semver_tilde_pnpm-lock.v7.yaml +0 -116
- data/spec/fixtures/semver_tilde_pnpm-lock.v8.yaml +0 -2558
- data/spec/fixtures/semver_tilde_pnpm-lock.v9.yaml +0 -2885
- data/spec/fixtures/semver_tilde_yarn.v1.lock +0 -106
- data/spec/fixtures/semver_tilde_yarn.v2.lock +0 -164
- data/spec/fixtures/without_package-lock.v1.json +0 -19
- data/spec/fixtures/without_package-lock.v2.json +0 -47
- data/spec/fixtures/without_package.json +0 -13
- data/spec/fixtures/without_pnpm-lock.v7.yaml +0 -23
- data/spec/fixtures/without_pnpm-lock.v8.yaml +0 -27
- data/spec/fixtures/without_pnpm-lock.v9.yaml +0 -34
- data/spec/fixtures/without_yarn.v1.lock +0 -13
- data/spec/fixtures/without_yarn.v2.lock +0 -29
- data/spec/generator_specs/e2e_template/files/app/controllers/home_controller.rb +0 -4
- data/spec/generator_specs/e2e_template/files/app/javascript/components/App.js +0 -12
- data/spec/generator_specs/e2e_template/files/app/javascript/packs/application.js +0 -10
- data/spec/generator_specs/e2e_template/files/app/views/home/index.html.erb +0 -2
- data/spec/generator_specs/e2e_template/files/app/views/layouts/application.html.erb +0 -17
- data/spec/generator_specs/e2e_template/files/config/routes.rb +0 -3
- data/spec/generator_specs/e2e_template/files/spec/system/test_react_component_renders_spec.rb +0 -13
- data/spec/generator_specs/e2e_template/template.rb +0 -29
- data/spec/generator_specs/fake-bin/bun +0 -10
- data/spec/generator_specs/fake-bin/npm +0 -10
- data/spec/generator_specs/fake-bin/pnpm +0 -10
- data/spec/generator_specs/fake-bin/yarn +0 -10
- data/spec/generator_specs/generator_spec.rb +0 -193
- data/spec/mounted_app/Rakefile +0 -4
- data/spec/mounted_app/package.json +0 -1
- data/spec/mounted_app/test/dummy/Rakefile +0 -3
- data/spec/mounted_app/test/dummy/bin/rails +0 -3
- data/spec/mounted_app/test/dummy/bin/rake +0 -3
- data/spec/mounted_app/test/dummy/config/application.rb +0 -10
- data/spec/mounted_app/test/dummy/config/environment.rb +0 -3
- data/spec/mounted_app/test/dummy/config/webpacker.yml +0 -81
- data/spec/mounted_app/test/dummy/config.ru +0 -5
- data/spec/mounted_app/test/dummy/package.json +0 -7
- data/spec/shakapacker/command_spec.rb +0 -134
- data/spec/shakapacker/compiler_spec.rb +0 -57
- data/spec/shakapacker/compiler_strategy_spec.rb +0 -24
- data/spec/shakapacker/configuration_spec.rb +0 -377
- data/spec/shakapacker/dev_server_runner_spec.rb +0 -136
- data/spec/shakapacker/dev_server_spec.rb +0 -118
- data/spec/shakapacker/digest_strategy_spec.rb +0 -59
- data/spec/shakapacker/engine_rake_tasks_spec.rb +0 -50
- data/spec/shakapacker/env_spec.rb +0 -23
- data/spec/shakapacker/helper_spec.rb +0 -243
- data/spec/shakapacker/instance_spec.rb +0 -29
- data/spec/shakapacker/manifest_spec.rb +0 -100
- data/spec/shakapacker/mtime_strategy_spec.rb +0 -55
- data/spec/shakapacker/rake_tasks_spec.rb +0 -85
- data/spec/shakapacker/shakapacker_spec.rb +0 -40
- data/spec/shakapacker/spec_helper_initializer.rb +0 -24
- data/spec/shakapacker/test_app/.gitignore +0 -2
- data/spec/shakapacker/test_app/Rakefile +0 -3
- data/spec/shakapacker/test_app/app/javascript/entrypoints/application.js +0 -10
- data/spec/shakapacker/test_app/app/javascript/entrypoints/generated/something.js +0 -2
- data/spec/shakapacker/test_app/app/javascript/entrypoints/multi_entry.css +0 -4
- data/spec/shakapacker/test_app/app/javascript/entrypoints/multi_entry.js +0 -4
- data/spec/shakapacker/test_app/bin/shakapacker +0 -14
- data/spec/shakapacker/test_app/bin/shakapacker-dev-server +0 -14
- data/spec/shakapacker/test_app/config/application.rb +0 -11
- data/spec/shakapacker/test_app/config/environment.rb +0 -4
- data/spec/shakapacker/test_app/config/initializers/inspect_autoload_paths.rb +0 -1
- data/spec/shakapacker/test_app/config/shakapacker.yml +0 -82
- data/spec/shakapacker/test_app/config/shakapacker_css_extract_ignore_order_warnings.yml +0 -83
- data/spec/shakapacker/test_app/config/shakapacker_defaults_fallback.yml +0 -11
- data/spec/shakapacker/test_app/config/shakapacker_manifest_path.yml +0 -79
- data/spec/shakapacker/test_app/config/shakapacker_nested_entries.yml +0 -82
- data/spec/shakapacker/test_app/config/shakapacker_no_precompile.yml +0 -7
- data/spec/shakapacker/test_app/config/shakapacker_other_location.yml +0 -84
- data/spec/shakapacker/test_app/config/shakapacker_public_root.yml +0 -18
- data/spec/shakapacker/test_app/config/webpack/webpack.config.js +0 -0
- data/spec/shakapacker/test_app/config.ru +0 -5
- data/spec/shakapacker/test_app/package.json +0 -14
- data/spec/shakapacker/test_app/public/packs/manifest.json +0 -58
- data/spec/shakapacker/test_app/some.config.js +0 -0
- data/spec/shakapacker/test_app/yarn.lock +0 -11
- data/spec/shakapacker/utils_manager_spec.rb +0 -125
- data/spec/shakapacker/version_checker_spec.rb +0 -1469
- data/spec/shakapacker/webpack_runner_spec.rb +0 -76
- data/spec/spec_helper.rb +0 -100
- data/spec/support/package_json_helpers.rb +0 -19
@@ -1,193 +0,0 @@
|
|
1
|
-
require "pathname"
|
2
|
-
require "rake"
|
3
|
-
require "json"
|
4
|
-
require "shakapacker/utils/misc"
|
5
|
-
require "shakapacker/utils/version_syntax_converter"
|
6
|
-
require "package_json"
|
7
|
-
|
8
|
-
GEM_ROOT = Pathname.new(File.expand_path("../../..", __FILE__))
|
9
|
-
SPEC_PATH = Pathname.new(File.expand_path("../", __FILE__))
|
10
|
-
BASE_RAILS_APP_PATH = SPEC_PATH.join("base-rails-app")
|
11
|
-
TEMP_RAILS_APP_PATH = SPEC_PATH.join("temp-rails-app")
|
12
|
-
|
13
|
-
describe "Generator" do
|
14
|
-
before :all do
|
15
|
-
# Don't use --skip-git because we want .gitignore file to exist in the project
|
16
|
-
sh_in_dir({}, SPEC_PATH, %(
|
17
|
-
rails new base-rails-app --skip-javascript --skip-bundle --skip-spring
|
18
|
-
rm -rf base-rails-app/.git
|
19
|
-
))
|
20
|
-
|
21
|
-
Bundler.with_unbundled_env do
|
22
|
-
sh_in_dir({}, BASE_RAILS_APP_PATH, %(
|
23
|
-
gem update bundler
|
24
|
-
bundle add shakapacker --path "#{GEM_ROOT}"
|
25
|
-
))
|
26
|
-
end
|
27
|
-
end
|
28
|
-
|
29
|
-
after :all do
|
30
|
-
Dir.chdir(SPEC_PATH)
|
31
|
-
FileUtils.rm_rf(BASE_RAILS_APP_PATH)
|
32
|
-
end
|
33
|
-
|
34
|
-
describe "shakapacker:install" do
|
35
|
-
# TODO: ideally "yarn_berry" should be here too, but it requires more complex setup
|
36
|
-
NODE_PACKAGE_MANAGERS.reject { |fm| fm == "yarn_berry" }.each do |fallback_manager|
|
37
|
-
context "when using package_json with #{fallback_manager} as the manager" do
|
38
|
-
before :all do
|
39
|
-
sh_opts = { fallback_manager: fallback_manager }
|
40
|
-
|
41
|
-
sh_in_dir(sh_opts, SPEC_PATH, "cp -r '#{BASE_RAILS_APP_PATH}' '#{TEMP_RAILS_APP_PATH}'")
|
42
|
-
|
43
|
-
Bundler.with_unbundled_env do
|
44
|
-
sh_in_dir(sh_opts, TEMP_RAILS_APP_PATH, "FORCE=true bundle exec rails shakapacker:install")
|
45
|
-
end
|
46
|
-
end
|
47
|
-
|
48
|
-
after :all do
|
49
|
-
Dir.chdir(SPEC_PATH)
|
50
|
-
FileUtils.rm_rf(TEMP_RAILS_APP_PATH)
|
51
|
-
end
|
52
|
-
|
53
|
-
it "creates `config/shakapacker.yml`" do
|
54
|
-
config_file_relative_path = "config/shakapacker.yml"
|
55
|
-
actual_content = read(path_in_the_app(config_file_relative_path))
|
56
|
-
expected_content = read(path_in_the_gem(config_file_relative_path))
|
57
|
-
|
58
|
-
expect(actual_content).to eq expected_content
|
59
|
-
end
|
60
|
-
|
61
|
-
it "ensures the 'packageManager' field is set" do
|
62
|
-
package_json = PackageJson.read(path_in_the_app)
|
63
|
-
|
64
|
-
manager_name = fallback_manager.split("_")[0]
|
65
|
-
|
66
|
-
expect(package_json.fetch("packageManager", "")).to match(/#{manager_name}@\d+\.\d+\.\d+/)
|
67
|
-
end
|
68
|
-
|
69
|
-
it "creates webpack config directory and its files" do
|
70
|
-
expected_files = [
|
71
|
-
"webpack.config.js"
|
72
|
-
]
|
73
|
-
|
74
|
-
Dir.chdir(path_in_the_app("config/webpack")) do
|
75
|
-
existing_files_in_config_webpack_dir = Dir.glob("*")
|
76
|
-
expect(existing_files_in_config_webpack_dir).to eq expected_files
|
77
|
-
end
|
78
|
-
end
|
79
|
-
|
80
|
-
it "adds binstubs" do
|
81
|
-
expected_binstubs = []
|
82
|
-
Dir.chdir(File.join(GEM_ROOT, "lib/install/bin")) do
|
83
|
-
expected_binstubs = Dir.glob("bin/*")
|
84
|
-
end
|
85
|
-
|
86
|
-
Dir.chdir(File.join(TEMP_RAILS_APP_PATH, "bin")) do
|
87
|
-
actual_binstubs = Dir.glob("*")
|
88
|
-
expect(actual_binstubs).to include(*expected_binstubs)
|
89
|
-
end
|
90
|
-
end
|
91
|
-
|
92
|
-
it "modifies .gitignore" do
|
93
|
-
actual_content = read(path_in_the_app(".gitignore"))
|
94
|
-
|
95
|
-
expect(actual_content).to match ".yarn-integrity"
|
96
|
-
end
|
97
|
-
|
98
|
-
it 'adds <%= javascript_pack_tag "application" %>' do
|
99
|
-
actual_content = read(path_in_the_app("app/views/layouts/application.html.erb"))
|
100
|
-
|
101
|
-
expect(actual_content).to match '<%= javascript_pack_tag "application" %>'
|
102
|
-
end
|
103
|
-
|
104
|
-
it "updates `bin/setup`" do
|
105
|
-
package_json = PackageJson.read(path_in_the_app)
|
106
|
-
cmd = package_json.manager.native_install_command.join(" ")
|
107
|
-
|
108
|
-
setup_file_content = read(path_in_the_app("bin/setup"))
|
109
|
-
|
110
|
-
expect(setup_file_content).to match %r(^\s*system!\(['"]#{cmd}['"]\))
|
111
|
-
end
|
112
|
-
|
113
|
-
it "adds relevant shakapacker version in package.json depending on gem version" do
|
114
|
-
npm_version = Shakapacker::Utils::VersionSyntaxConverter.new.rubygem_to_npm(Shakapacker::VERSION)
|
115
|
-
|
116
|
-
package_json = PackageJson.read(path_in_the_app)
|
117
|
-
actual_version = package_json.fetch("dependencies", {})["shakapacker"]
|
118
|
-
|
119
|
-
expect(actual_version).to eq(npm_version)
|
120
|
-
end
|
121
|
-
|
122
|
-
it "adds Shakapacker peer dependencies to package.json" do
|
123
|
-
package_json = PackageJson.read(path_in_the_app)
|
124
|
-
actual_dependencies = package_json.fetch("dependencies", {}).keys
|
125
|
-
|
126
|
-
expected_dependencies = %w(
|
127
|
-
@babel/core
|
128
|
-
@babel/plugin-transform-runtime
|
129
|
-
@babel/preset-env
|
130
|
-
@babel/runtime
|
131
|
-
babel-loader
|
132
|
-
compression-webpack-plugin
|
133
|
-
terser-webpack-plugin
|
134
|
-
webpack
|
135
|
-
webpack-assets-manifest
|
136
|
-
webpack-cli
|
137
|
-
webpack-merge
|
138
|
-
)
|
139
|
-
|
140
|
-
expect(actual_dependencies).to include(*expected_dependencies)
|
141
|
-
end
|
142
|
-
|
143
|
-
it "adds Shakapacker peer dev dependencies to package.json" do
|
144
|
-
package_json = PackageJson.read(path_in_the_app)
|
145
|
-
actual_dev_dependencies = package_json.fetch("devDependencies", {}).keys
|
146
|
-
|
147
|
-
expected_dev_dependencies = %w(
|
148
|
-
webpack-dev-server
|
149
|
-
)
|
150
|
-
|
151
|
-
expect(actual_dev_dependencies).to include(*expected_dev_dependencies)
|
152
|
-
end
|
153
|
-
|
154
|
-
context "with a basic react app setup" do
|
155
|
-
it "passes the test for rendering react component on the page" do
|
156
|
-
sh_opts = { fallback_manager: fallback_manager }
|
157
|
-
|
158
|
-
Bundler.with_unbundled_env do
|
159
|
-
sh_in_dir(sh_opts, TEMP_RAILS_APP_PATH, "./bin/rails app:template LOCATION=../e2e_template/template.rb")
|
160
|
-
expect(sh_in_dir(sh_opts, TEMP_RAILS_APP_PATH, "bundle exec rspec")).to be_truthy
|
161
|
-
end
|
162
|
-
end
|
163
|
-
end
|
164
|
-
end
|
165
|
-
end
|
166
|
-
end
|
167
|
-
|
168
|
-
private
|
169
|
-
|
170
|
-
def path_in_the_app(relative_path = nil)
|
171
|
-
Pathname.new(File.join([TEMP_RAILS_APP_PATH, relative_path].compact))
|
172
|
-
end
|
173
|
-
|
174
|
-
def path_in_the_gem(relative_path = nil)
|
175
|
-
Pathname.new(File.join([GEM_ROOT, "lib/install" , relative_path].compact))
|
176
|
-
end
|
177
|
-
|
178
|
-
def read(path)
|
179
|
-
File.read(path)
|
180
|
-
end
|
181
|
-
|
182
|
-
def sort_out_package_json(opts)
|
183
|
-
ENV["PATH"] = "#{SPEC_PATH}/fake-bin:#{ENV["PATH"]}"
|
184
|
-
|
185
|
-
ENV["SHAKAPACKER_EXPECTED_PACKAGE_MANGER"] = opts[:fallback_manager]
|
186
|
-
ENV["PACKAGE_JSON_FALLBACK_MANAGER"] = opts[:fallback_manager]
|
187
|
-
end
|
188
|
-
|
189
|
-
def sh_in_dir(opts, dir, *shell_commands)
|
190
|
-
sort_out_package_json(opts)
|
191
|
-
Shakapacker::Utils::Misc.sh_in_dir(dir, *shell_commands)
|
192
|
-
end
|
193
|
-
end
|
data/spec/mounted_app/Rakefile
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
{}
|
@@ -1,81 +0,0 @@
|
|
1
|
-
# Note: You must restart bin/shakapacker-dev-server for changes to take effect
|
2
|
-
|
3
|
-
default: &default
|
4
|
-
source_path: app/javascript
|
5
|
-
source_entry_path: entrypoints
|
6
|
-
public_output_path: packs
|
7
|
-
cache_path: tmp/shakapacker
|
8
|
-
webpack_loader: babel
|
9
|
-
|
10
|
-
# Additional paths webpack should look up modules
|
11
|
-
# ['app/assets', 'engine/foo/app/assets']
|
12
|
-
additional_paths:
|
13
|
-
- app/assets
|
14
|
-
- /etc/yarn
|
15
|
-
|
16
|
-
# Reload manifest.json on all requests so we reload latest compiled packs
|
17
|
-
cache_manifest: false
|
18
|
-
|
19
|
-
extensions:
|
20
|
-
- .js
|
21
|
-
- .sass
|
22
|
-
- .scss
|
23
|
-
- .css
|
24
|
-
- .module.sass
|
25
|
-
- .module.scss
|
26
|
-
- .module.css
|
27
|
-
- .png
|
28
|
-
- .svg
|
29
|
-
- .gif
|
30
|
-
- .jpeg
|
31
|
-
- .jpg
|
32
|
-
|
33
|
-
development:
|
34
|
-
<<: *default
|
35
|
-
compile: true
|
36
|
-
|
37
|
-
# Reference: https://webpack.js.org/configuration/dev-server/
|
38
|
-
dev_server:
|
39
|
-
host: localhost
|
40
|
-
port: 3035
|
41
|
-
public: localhost:3035
|
42
|
-
hmr: false
|
43
|
-
# If HMR is on, CSS will by inlined by delivering it as part of the script payload via style-loader. Be sure
|
44
|
-
# that you add style-loader to your project dependencies.
|
45
|
-
#
|
46
|
-
# If you want to instead deliver CSS via <link> with the mini-extract-css-plugin, set inline_css to false.
|
47
|
-
# In that case, style-loader is not needed as a dependency.
|
48
|
-
#
|
49
|
-
# mini-extract-css-plugin is a required dependency in both cases.
|
50
|
-
inline_css: true
|
51
|
-
overlay: true
|
52
|
-
disable_host_check: true
|
53
|
-
use_local_ip: false
|
54
|
-
|
55
|
-
test:
|
56
|
-
<<: *default
|
57
|
-
compile: true
|
58
|
-
|
59
|
-
# Compile test packs to a separate directory
|
60
|
-
public_output_path: packs-test
|
61
|
-
|
62
|
-
production:
|
63
|
-
<<: *default
|
64
|
-
|
65
|
-
# Production depends on precompilation of packs prior to booting for performance.
|
66
|
-
compile: false
|
67
|
-
|
68
|
-
# Cache manifest.json for performance
|
69
|
-
cache_manifest: true
|
70
|
-
|
71
|
-
staging:
|
72
|
-
<<: *default
|
73
|
-
|
74
|
-
# Production depends on precompilation of packs prior to booting for performance.
|
75
|
-
compile: false
|
76
|
-
|
77
|
-
# Cache manifest.json for performance
|
78
|
-
cache_manifest: true
|
79
|
-
|
80
|
-
# Compile staging packs to a separate directory
|
81
|
-
public_output_path: packs-staging
|
@@ -1,134 +0,0 @@
|
|
1
|
-
require_relative "spec_helper_initializer"
|
2
|
-
|
3
|
-
describe "Command" do
|
4
|
-
before do
|
5
|
-
allow(Shakapacker.logger).to receive(:info)
|
6
|
-
end
|
7
|
-
|
8
|
-
describe "#compile" do
|
9
|
-
it "returns success status when stale" do
|
10
|
-
expect(Shakapacker.compiler).to receive(:stale?).and_return(true)
|
11
|
-
expect(Shakapacker.compiler).to receive(:run_webpack).and_return(true)
|
12
|
-
|
13
|
-
expect(Shakapacker.commands.compile).to be true
|
14
|
-
end
|
15
|
-
|
16
|
-
it "returns success status when fresh" do
|
17
|
-
expect(Shakapacker.compiler).to receive(:stale?).and_return(false)
|
18
|
-
|
19
|
-
expect(Shakapacker.commands.compile).to be true
|
20
|
-
end
|
21
|
-
|
22
|
-
it "returns failure status when stale" do
|
23
|
-
expect(Shakapacker.compiler).to receive(:stale?).and_return(true)
|
24
|
-
expect(Shakapacker.compiler).to receive(:run_webpack).and_return(false)
|
25
|
-
|
26
|
-
expect(Shakapacker.commands.compile).to be false
|
27
|
-
end
|
28
|
-
end
|
29
|
-
|
30
|
-
describe "#clean" do
|
31
|
-
let(:now) { Time.parse("2021-01-01 12:34:56 UTC") }
|
32
|
-
let(:prev_files) do
|
33
|
-
# Test assets to be kept and deleted, path and mtime
|
34
|
-
{
|
35
|
-
# recent versions to be kept with Shakapacker.commands.clean(count = 2)
|
36
|
-
"js/application-deadbeef.js" => now - 4000,
|
37
|
-
"js/common-deadbeee.js" => now - 4002,
|
38
|
-
"css/common-deadbeed.css" => now - 4004,
|
39
|
-
"media/images/logo-deadbeeb.css" => now - 4006,
|
40
|
-
"js/application-1eadbeef.js" => now - 8000,
|
41
|
-
"js/common-1eadbeee.js" => now - 8002,
|
42
|
-
"css/common-1eadbeed.css" => now - 8004,
|
43
|
-
"media/images/logo-1eadbeeb.css" => now - 8006,
|
44
|
-
# new files to be kept with Shakapacker.commands.clean(age = 3600)
|
45
|
-
"js/brandnew-0001.js" => now,
|
46
|
-
"js/brandnew-0002.js" => now - 10,
|
47
|
-
"js/brandnew-0003.js" => now - 20,
|
48
|
-
"js/brandnew-0004.js" => now - 40,
|
49
|
-
|
50
|
-
# Compressed and map files
|
51
|
-
"js/application-deadbeef.js.br" => now - 4000,
|
52
|
-
"js/application-deadbeef.js.gz" => now - 4000,
|
53
|
-
"js/application-deadbeef.js.map" => now - 4000,
|
54
|
-
"js/application-deadbeef.js.map.br" => now - 4000,
|
55
|
-
"js/application-deadbeef.js.map.gz" => now - 4000,
|
56
|
-
"js/application-1eadbeef.js.br" => now - 4000,
|
57
|
-
"js/application-1eadbeef.js.gz" => now - 4000,
|
58
|
-
"js/application-1eadbeef.js.map" => now - 4000,
|
59
|
-
"js/application-1eadbeef.js.map.br" => now - 4000,
|
60
|
-
"js/application-1eadbeef.js.map.gz" => now - 4000,
|
61
|
-
}.transform_keys { |path| "#{Shakapacker.config.public_output_path}/#{path}" }
|
62
|
-
end
|
63
|
-
|
64
|
-
let(:expired_files) do
|
65
|
-
{
|
66
|
-
# old files that are outside count = 2 or age = 3600 and to be deleted
|
67
|
-
"js/application-0eadbeef.js" => now - 9000,
|
68
|
-
"js/common-0eadbeee.js" => now - 9002,
|
69
|
-
"css/common-0eadbeed.css" => now - 9004,
|
70
|
-
"js/brandnew-0005.js" => now - 3640,
|
71
|
-
# Compressed and map files
|
72
|
-
"js/application-0eadbeef.js.br" => now - 9000,
|
73
|
-
"js/application-0eadbeef.js.gz" => now - 9000,
|
74
|
-
"js/application-0eadbeef.js.map" => now - 9000,
|
75
|
-
"js/application-0eadbeef.js.map.br" => now - 9000,
|
76
|
-
"js/application-0eadbeef.js.map.gz" => now - 9000,
|
77
|
-
}.transform_keys { |path| "#{Shakapacker.config.public_output_path}/#{path}" }
|
78
|
-
end
|
79
|
-
|
80
|
-
let(:all_files) { prev_files.merge(expired_files) }
|
81
|
-
|
82
|
-
let(:file_delete_mock) { double("File Delete") }
|
83
|
-
let(:file_mtime_stub) { Proc.new { |longpath| all_files[longpath] } }
|
84
|
-
let(:file_delete_stub) { Proc.new { |longpath| file_delete_mock.delete(longpath) } }
|
85
|
-
|
86
|
-
before :context do
|
87
|
-
@dir_glob_stub = Proc.new { |arg|
|
88
|
-
case arg
|
89
|
-
when "#{Shakapacker.config.public_output_path}/**/*"
|
90
|
-
all_files.keys
|
91
|
-
else
|
92
|
-
[]
|
93
|
-
end
|
94
|
-
}
|
95
|
-
end
|
96
|
-
|
97
|
-
it "works with nested hashes and without any compiled files" do
|
98
|
-
allow(File).to receive(:delete).and_return(true)
|
99
|
-
expect(Shakapacker.commands.clean).to be true
|
100
|
-
end
|
101
|
-
|
102
|
-
it "deletes only and only expired versioned files if no parameter passed" do
|
103
|
-
all_files.keys.each do |longpath|
|
104
|
-
allow(file_delete_mock).to receive(:delete).with(longpath)
|
105
|
-
end
|
106
|
-
|
107
|
-
with_time_dir_and_files_stub do
|
108
|
-
expect(Shakapacker.commands.clean).to be true
|
109
|
-
|
110
|
-
# Verify that only and only expired files are deleted
|
111
|
-
all_files.keys.each do |longpath|
|
112
|
-
if expired_files.has_key? longpath
|
113
|
-
expect(file_delete_mock).to have_received(:delete).with(longpath)
|
114
|
-
else
|
115
|
-
expect(file_delete_mock).to_not have_received(:delete).with(longpath)
|
116
|
-
end
|
117
|
-
end
|
118
|
-
end
|
119
|
-
end
|
120
|
-
|
121
|
-
private
|
122
|
-
|
123
|
-
def with_time_dir_and_files_stub(&proc)
|
124
|
-
allow(Time).to receive(:now).and_return(now)
|
125
|
-
allow(Dir).to receive(:glob) { |arg| @dir_glob_stub.call(arg) }
|
126
|
-
allow(File).to receive(:directory?).and_return(false)
|
127
|
-
allow(File).to receive(:file?).and_return(true)
|
128
|
-
allow(File).to receive(:mtime) { |arg| file_mtime_stub.call(arg) }
|
129
|
-
allow(File).to receive(:delete) { |arg| file_delete_stub.call(arg) }
|
130
|
-
|
131
|
-
yield proc
|
132
|
-
end
|
133
|
-
end
|
134
|
-
end
|
@@ -1,57 +0,0 @@
|
|
1
|
-
require_relative "spec_helper_initializer"
|
2
|
-
require "ostruct"
|
3
|
-
|
4
|
-
describe "Shakapacker::Compiler" do
|
5
|
-
it "accepts custom environment variables" do
|
6
|
-
expect(Shakapacker.compiler.send(:webpack_env)["FOO"]).to be nil
|
7
|
-
|
8
|
-
Shakapacker.compiler.env["FOO"] = "BAR"
|
9
|
-
expect(Shakapacker.compiler.send(:webpack_env)["FOO"]).to eq "BAR"
|
10
|
-
ensure
|
11
|
-
Shakapacker.compiler.env = {}
|
12
|
-
end
|
13
|
-
|
14
|
-
it "returns true when fresh" do
|
15
|
-
mocked_strategy = double("Strategy")
|
16
|
-
expect(mocked_strategy).to receive(:stale?).and_return(false)
|
17
|
-
|
18
|
-
expect(Shakapacker.compiler).to receive(:strategy).and_return(mocked_strategy)
|
19
|
-
|
20
|
-
expect(Shakapacker.compiler.compile).to be true
|
21
|
-
end
|
22
|
-
|
23
|
-
it "returns true and calls after_compile_hook on successful compile" do
|
24
|
-
mocked_strategy = spy("Strategy")
|
25
|
-
expect(mocked_strategy).to receive(:stale?).and_return(true)
|
26
|
-
|
27
|
-
allow(Shakapacker.compiler).to receive(:strategy).and_return(mocked_strategy)
|
28
|
-
|
29
|
-
status = OpenStruct.new(success?: true)
|
30
|
-
allow(Open3).to receive(:capture3).and_return([:stderr, :stdout, status])
|
31
|
-
|
32
|
-
expect(Shakapacker.compiler.compile).to be true
|
33
|
-
expect(mocked_strategy).to have_received(:after_compile_hook)
|
34
|
-
end
|
35
|
-
|
36
|
-
it "returns false and calls after_compile_hook on failed compile" do
|
37
|
-
mocked_strategy = spy("Strategy")
|
38
|
-
allow(mocked_strategy).to receive(:stale?).and_return(true)
|
39
|
-
allow(mocked_strategy).to receive(:after_compile_hook)
|
40
|
-
|
41
|
-
allow(Shakapacker.compiler).to receive(:strategy).and_return(mocked_strategy)
|
42
|
-
|
43
|
-
status = OpenStruct.new(success?: false)
|
44
|
-
allow(Open3).to receive(:capture3).and_return([:stderr, :stdout, status])
|
45
|
-
|
46
|
-
expect(Shakapacker.compiler.compile).to be false
|
47
|
-
expect(mocked_strategy).to have_received(:after_compile_hook)
|
48
|
-
end
|
49
|
-
|
50
|
-
it "accepts external env variables" do
|
51
|
-
expect(Shakapacker.compiler.send(:webpack_env)["SHAKAPACKER_ASSET_HOST"]).to be nil
|
52
|
-
|
53
|
-
allow(ENV).to receive(:fetch).with("SHAKAPACKER_ASSET_HOST", nil).and_return("foo.bar")
|
54
|
-
|
55
|
-
expect(Shakapacker.compiler.send(:webpack_env)["SHAKAPACKER_ASSET_HOST"]).to eq "foo.bar"
|
56
|
-
end
|
57
|
-
end
|
@@ -1,24 +0,0 @@
|
|
1
|
-
require_relative "spec_helper_initializer"
|
2
|
-
|
3
|
-
describe "Shakapacker::CompilerStrategy" do
|
4
|
-
describe "#from_config" do
|
5
|
-
it "returns an instance of MtimeStrategy when compiler_strategy is set to mtime" do
|
6
|
-
allow(Shakapacker.config).to receive(:compiler_strategy).and_return("mtime")
|
7
|
-
|
8
|
-
expect(Shakapacker::CompilerStrategy.from_config).to be_an_instance_of(Shakapacker::MtimeStrategy)
|
9
|
-
end
|
10
|
-
|
11
|
-
it "returns an instance of DigestStrategy when compiler_strategy is set to digest" do
|
12
|
-
allow(Shakapacker.config).to receive(:compiler_strategy).and_return("digest")
|
13
|
-
|
14
|
-
expect(Shakapacker::CompilerStrategy.from_config).to be_an_instance_of(Shakapacker::DigestStrategy)
|
15
|
-
end
|
16
|
-
|
17
|
-
it "raise an exception for unknown compiler_strategy in the config file" do
|
18
|
-
expected_error_message = "Unknown strategy 'other'. Available options are 'mtime' and 'digest'."
|
19
|
-
allow(Shakapacker.config).to receive(:compiler_strategy).and_return("other")
|
20
|
-
|
21
|
-
expect { Shakapacker::CompilerStrategy.from_config }.to raise_error(expected_error_message)
|
22
|
-
end
|
23
|
-
end
|
24
|
-
end
|