shakapacker 7.0.0.rc.0 → 7.0.0.rc.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/PULL_REQUEST_TEMPLATE.md +4 -8
- data/.github/workflows/dummy.yml +21 -0
- data/.github/workflows/generator.yml +37 -0
- data/.github/workflows/jest.yml +2 -2
- data/.github/workflows/js-lint.yml +2 -2
- data/.github/workflows/rubocop.yml +1 -1
- data/.github/workflows/ruby-backward-compatibility.yml +2 -6
- data/.github/workflows/ruby.yml +2 -6
- data/.gitignore +3 -0
- data/CHANGELOG.md +16 -18
- data/CONTRIBUTING.md +76 -20
- data/README.md +3 -1
- data/Rakefile +44 -8
- data/docs/deployment.md +1 -2
- data/lib/install/binstubs.rb +3 -1
- data/lib/install/config/webpack/webpack.config.js +3 -2
- data/lib/install/template.rb +27 -15
- data/lib/shakapacker/deprecation_helper.rb +4 -5
- data/lib/shakapacker/version.rb +1 -1
- data/lib/tasks/shakapacker/check_binstubs.rake +14 -10
- data/lib/tasks/shakapacker/compile.rake +1 -6
- data/package/index.js +16 -0
- data/package/utils/helpers.js +1 -1
- data/package.json +1 -1
- data/spec/dummy/.browserslistrc +1 -0
- data/spec/dummy/.gitignore +20 -0
- data/spec/dummy/.prettierrc.yaml +4 -0
- data/spec/dummy/Gemfile +63 -0
- data/spec/dummy/Procfile.dev +5 -0
- data/spec/dummy/Procfile.dev-static +9 -0
- data/spec/dummy/README.md +1 -0
- data/spec/dummy/Rakefile +6 -0
- data/spec/dummy/app/assets/config/manifest.js +2 -0
- data/spec/dummy/app/assets/stylesheets/application.css +15 -0
- data/spec/dummy/app/channels/application_cable/channel.rb +4 -0
- data/spec/dummy/app/channels/application_cable/connection.rb +4 -0
- data/spec/dummy/app/controllers/application_controller.rb +2 -0
- data/spec/dummy/app/controllers/hello_world_controller.rb +9 -0
- data/spec/dummy/app/helpers/application_helper.rb +2 -0
- data/spec/dummy/app/javascript/Globals.d.ts +3 -0
- data/spec/dummy/app/javascript/bundles/HelloWorld/components/HelloWorld.module.css +25 -0
- data/spec/dummy/app/javascript/bundles/HelloWorld/components/HelloWorld.tsx +47 -0
- data/spec/dummy/app/javascript/bundles/HelloWorld/components/HelloWorldServer.tsx +5 -0
- data/spec/dummy/app/javascript/bundles/HelloWorld/components/logo.svg +7 -0
- data/spec/dummy/app/javascript/packs/application.js +17 -0
- data/spec/dummy/app/javascript/packs/hello-world-bundle.ts +8 -0
- data/spec/dummy/app/javascript/packs/server-bundle.ts +8 -0
- data/spec/dummy/app/jobs/application_job.rb +7 -0
- data/spec/dummy/app/mailers/application_mailer.rb +4 -0
- data/spec/dummy/app/models/application_record.rb +3 -0
- data/spec/dummy/app/models/concerns/.keep +0 -0
- data/spec/dummy/app/views/hello_world/index.html.erb +2 -0
- data/spec/dummy/app/views/layouts/application.html.erb +14 -0
- data/spec/dummy/app/views/layouts/hello_world.html.erb +13 -0
- data/spec/dummy/app/views/layouts/mailer.html.erb +13 -0
- data/spec/dummy/app/views/layouts/mailer.text.erb +1 -0
- data/spec/dummy/babel.config.js +30 -0
- data/spec/dummy/bin/bundle +114 -0
- data/spec/dummy/bin/dev +30 -0
- data/spec/dummy/bin/dev-static +30 -0
- data/spec/dummy/bin/rails +9 -0
- data/spec/dummy/bin/rake +9 -0
- data/spec/dummy/bin/setup +33 -0
- data/spec/dummy/bin/shakapacker +13 -0
- data/spec/dummy/bin/shakapacker-dev-server +13 -0
- data/spec/dummy/bin/spring +17 -0
- data/spec/dummy/bin/yarn +18 -0
- data/spec/dummy/config/application.rb +32 -0
- data/spec/dummy/config/boot.rb +4 -0
- data/spec/dummy/config/cable.yml +10 -0
- data/spec/dummy/config/credentials.yml.enc +1 -0
- data/spec/dummy/config/database.yml +25 -0
- data/spec/dummy/config/environment.rb +5 -0
- data/spec/dummy/config/environments/development.rb +54 -0
- data/spec/dummy/config/environments/production.rb +106 -0
- data/spec/dummy/config/environments/test.rb +49 -0
- data/spec/dummy/config/initializers/application_controller_renderer.rb +8 -0
- data/spec/dummy/config/initializers/backtrace_silencers.rb +7 -0
- data/spec/dummy/config/initializers/content_security_policy.rb +28 -0
- data/spec/dummy/config/initializers/cookies_serializer.rb +5 -0
- data/spec/dummy/config/initializers/filter_parameter_logging.rb +4 -0
- data/spec/dummy/config/initializers/inflections.rb +16 -0
- data/spec/dummy/config/initializers/mime_types.rb +4 -0
- data/spec/dummy/config/initializers/react_on_rails.rb +58 -0
- data/spec/dummy/config/initializers/wrap_parameters.rb +14 -0
- data/spec/dummy/config/locales/en.yml +33 -0
- data/spec/dummy/config/puma.rb +38 -0
- data/spec/dummy/config/routes.rb +6 -0
- data/spec/dummy/config/shakapacker.yml +62 -0
- data/spec/dummy/config/spring.rb +6 -0
- data/spec/dummy/config/storage.yml +34 -0
- data/spec/dummy/config/webpack/ServerClientOrBoth.js +34 -0
- data/spec/dummy/config/webpack/clientWebpackConfig.js +15 -0
- data/spec/dummy/config/webpack/commonWebpackConfig.js +18 -0
- data/spec/dummy/config/webpack/development.js +32 -0
- data/spec/dummy/config/webpack/production.js +9 -0
- data/spec/dummy/config/webpack/serverWebpackConfig.js +116 -0
- data/spec/dummy/config/webpack/test.js +7 -0
- data/spec/dummy/config/webpack/webpack.config.js +24 -0
- data/spec/dummy/config.ru +5 -0
- data/spec/dummy/db/seeds.rb +7 -0
- data/spec/dummy/lib/assets/.keep +0 -0
- data/spec/dummy/lib/tasks/.keep +0 -0
- data/spec/dummy/package.json +44 -0
- data/spec/dummy/postcss.config.js +12 -0
- data/spec/dummy/public/404.html +67 -0
- data/spec/dummy/public/422.html +67 -0
- data/spec/dummy/public/500.html +66 -0
- 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 +1 -0
- data/spec/dummy/spec/rails_helper.rb +118 -0
- data/spec/dummy/spec/spec_helper.rb +96 -0
- data/spec/dummy/spec/system/hello_world_spec.rb +19 -0
- data/spec/dummy/tsconfig.json +21 -0
- data/spec/dummy/vendor/.keep +0 -0
- data/spec/dummy/yarn.lock +4697 -0
- data/spec/generator_specs/e2e_template/files/app/controllers/home_controller.rb +4 -0
- data/spec/generator_specs/e2e_template/files/app/javascript/components/App.js +12 -0
- data/spec/generator_specs/e2e_template/files/app/javascript/packs/application.js +10 -0
- data/spec/generator_specs/e2e_template/files/app/views/home/index.html.erb +2 -0
- data/spec/generator_specs/e2e_template/files/app/views/layouts/application.html.erb +17 -0
- data/spec/generator_specs/e2e_template/files/config/routes.rb +3 -0
- data/spec/generator_specs/e2e_template/files/spec/system/test_react_component_renders_spec.rb +13 -0
- data/spec/generator_specs/e2e_template/template.rb +21 -0
- data/spec/generator_specs/generator_spec.rb +169 -0
- data/spec/{configuration_spec.rb → shakapacker/configuration_spec.rb} +10 -10
- data/spec/{dev_server_runner_spec.rb → shakapacker/dev_server_runner_spec.rb} +1 -1
- data/spec/{engine_rake_tasks_spec.rb → shakapacker/engine_rake_tasks_spec.rb} +2 -2
- data/spec/{manifest_spec.rb → shakapacker/manifest_spec.rb} +1 -1
- data/spec/shakapacker/rake_tasks_spec.rb +93 -0
- data/spec/{spec_helper_initializer.rb → shakapacker/spec_helper_initializer.rb} +1 -1
- data/spec/shakapacker/test_app/config/webpack/webpack.config.js +0 -0
- data/spec/shakapacker/test_app/some.config.js +0 -0
- data/spec/{version_checker_spec.rb → shakapacker/version_checker_spec.rb} +9 -9
- data/spec/{webpack_runner_spec.rb → shakapacker/webpack_runner_spec.rb} +1 -1
- metadata +170 -64
- data/gemfiles/Gemfile-rails.5.2.x +0 -9
- data/spec/rake_tasks_spec.rb +0 -34
- /data/docs/{developing_webpacker.md → developing_shakapacker.md} +0 -0
- /data/spec/backward_compatibility_specs/{command_spec_bc.rb → command_spec.rb} +0 -0
- /data/spec/backward_compatibility_specs/{compiler_spec_bc.rb → compiler_spec.rb} +0 -0
- /data/spec/backward_compatibility_specs/{compiler_strategy_spec_bc.rb → compiler_strategy_spec.rb} +0 -0
- /data/spec/backward_compatibility_specs/{configuration_spec_bc.rb → configuration_spec.rb} +0 -0
- /data/spec/backward_compatibility_specs/{dev_server_runner_spec_bc.rb → dev_server_runner_spec.rb} +0 -0
- /data/spec/backward_compatibility_specs/{dev_server_spec_bc.rb → dev_server_spec.rb} +0 -0
- /data/spec/backward_compatibility_specs/{digest_strategy_spec_bc.rb → digest_strategy_spec.rb} +0 -0
- /data/spec/backward_compatibility_specs/{engine_rake_tasks_spec_bc.rb → engine_rake_tasks_spec.rb} +0 -0
- /data/spec/backward_compatibility_specs/{env_spec_bc.rb → env_spec.rb} +0 -0
- /data/spec/backward_compatibility_specs/{helper_spec_bc.rb → helper_spec.rb} +0 -0
- /data/spec/backward_compatibility_specs/{instance_spec_bc.rb → instance_spec.rb} +0 -0
- /data/spec/backward_compatibility_specs/{manifest_spec_bc.rb → manifest_spec.rb} +0 -0
- /data/spec/backward_compatibility_specs/{mtime_strategy_spec_bc.rb → mtime_strategy_spec.rb} +0 -0
- /data/spec/backward_compatibility_specs/{rake_tasks_spec_bc.rb → rake_tasks_spec.rb} +0 -0
- /data/spec/backward_compatibility_specs/{webpack_runner_spec_bc.rb → webpack_runner_spec.rb} +0 -0
- /data/spec/backward_compatibility_specs/{webpacker_spec_bc.rb → webpacker_spec.rb} +0 -0
- /data/spec/{test_app/config/webpack/webpack.config.js → dummy/app/assets/images/.keep} +0 -0
- /data/spec/{test_app/some.config.js → dummy/app/controllers/concerns/.keep} +0 -0
- /data/spec/{command_spec.rb → shakapacker/command_spec.rb} +0 -0
- /data/spec/{compiler_spec.rb → shakapacker/compiler_spec.rb} +0 -0
- /data/spec/{compiler_strategy_spec.rb → shakapacker/compiler_strategy_spec.rb} +0 -0
- /data/spec/{dev_server_spec.rb → shakapacker/dev_server_spec.rb} +0 -0
- /data/spec/{digest_strategy_spec.rb → shakapacker/digest_strategy_spec.rb} +0 -0
- /data/spec/{env_spec.rb → shakapacker/env_spec.rb} +0 -0
- /data/spec/{helper_spec.rb → shakapacker/helper_spec.rb} +0 -0
- /data/spec/{instance_spec.rb → shakapacker/instance_spec.rb} +0 -0
- /data/spec/{mtime_strategy_spec.rb → shakapacker/mtime_strategy_spec.rb} +0 -0
- /data/spec/{webpacker_spec.rb → shakapacker/shakapacker_spec.rb} +0 -0
- /data/spec/{test_app → shakapacker/test_app}/.gitignore +0 -0
- /data/spec/{test_app → shakapacker/test_app}/Rakefile +0 -0
- /data/spec/{test_app → shakapacker/test_app}/app/javascript/entrypoints/application.js +0 -0
- /data/spec/{test_app → shakapacker/test_app}/app/javascript/entrypoints/generated/something.js +0 -0
- /data/spec/{test_app → shakapacker/test_app}/app/javascript/entrypoints/multi_entry.css +0 -0
- /data/spec/{test_app → shakapacker/test_app}/app/javascript/entrypoints/multi_entry.js +0 -0
- /data/spec/{test_app → shakapacker/test_app}/bin/shakapacker +0 -0
- /data/spec/{test_app → shakapacker/test_app}/bin/shakapacker-dev-server +0 -0
- /data/spec/{test_app → shakapacker/test_app}/config/application.rb +0 -0
- /data/spec/{test_app → shakapacker/test_app}/config/environment.rb +0 -0
- /data/spec/{test_app → shakapacker/test_app}/config/initializers/inspect_autoload_paths.rb +0 -0
- /data/spec/{test_app → shakapacker/test_app}/config/shakapacker.yml +0 -0
- /data/spec/{test_app → shakapacker/test_app}/config/shakapacker_css_extract_ignore_order_warnings.yml +0 -0
- /data/spec/{test_app → shakapacker/test_app}/config/shakapacker_defaults_fallback.yml +0 -0
- /data/spec/{test_app → shakapacker/test_app}/config/shakapacker_manifest_path.yml +0 -0
- /data/spec/{test_app → shakapacker/test_app}/config/shakapacker_nested_entries.yml +0 -0
- /data/spec/{test_app → shakapacker/test_app}/config/shakapacker_no_precompile.yml +0 -0
- /data/spec/{test_app → shakapacker/test_app}/config/shakapacker_other_location.yml +0 -0
- /data/spec/{test_app → shakapacker/test_app}/config/shakapacker_public_root.yml +0 -0
- /data/spec/{test_app → shakapacker/test_app}/config.ru +0 -0
- /data/spec/{test_app → shakapacker/test_app}/package.json +0 -0
- /data/spec/{test_app → shakapacker/test_app}/public/packs/manifest.json +0 -0
- /data/spec/{test_app → shakapacker/test_app}/yarn.lock +0 -0
@@ -0,0 +1,17 @@
|
|
1
|
+
<!DOCTYPE html>
|
2
|
+
<html>
|
3
|
+
<head>
|
4
|
+
<title>Sh7InstallTest</title>
|
5
|
+
<meta name="viewport" content="width=device-width,initial-scale=1">
|
6
|
+
<%= csrf_meta_tags %>
|
7
|
+
<%= csp_meta_tag %>
|
8
|
+
|
9
|
+
<%= stylesheet_link_tag "application" %>
|
10
|
+
<%= javascript_pack_tag "application" %>
|
11
|
+
</head>
|
12
|
+
|
13
|
+
<body>
|
14
|
+
<%= yield %>
|
15
|
+
<div id="root"></div>
|
16
|
+
</body>
|
17
|
+
</html>
|
@@ -0,0 +1,21 @@
|
|
1
|
+
# install react
|
2
|
+
system("yarn add react react-dom @babel/preset-react")
|
3
|
+
|
4
|
+
# update webpack presets for react
|
5
|
+
package_json_path = Rails.root.join("./package.json")
|
6
|
+
insert_into_file(
|
7
|
+
package_json_path,
|
8
|
+
%( "@babel/preset-react",\n),
|
9
|
+
after: /"presets": \[\n/
|
10
|
+
)
|
11
|
+
|
12
|
+
# install rspec-rails
|
13
|
+
system("bundle add rspec-rails --group development,test")
|
14
|
+
system("bundle exec rails g rspec:install")
|
15
|
+
|
16
|
+
# copy files
|
17
|
+
directory(
|
18
|
+
Rails.root.join("../e2e_template/files"),
|
19
|
+
Rails.root,
|
20
|
+
force: true
|
21
|
+
)
|
@@ -0,0 +1,169 @@
|
|
1
|
+
require "pathname"
|
2
|
+
require "rake"
|
3
|
+
require "json"
|
4
|
+
require "shakapacker/utils/misc"
|
5
|
+
require "shakapacker/utils/version_syntax_converter"
|
6
|
+
|
7
|
+
GEM_ROOT = Pathname.new(File.expand_path("../../..", __FILE__))
|
8
|
+
SPEC_PATH = Pathname.new(File.expand_path("../", __FILE__))
|
9
|
+
BASE_RAILS_APP_PATH = SPEC_PATH.join("base-rails-app")
|
10
|
+
TEMP_RAILS_APP_PATH = SPEC_PATH.join("temp-rails-app")
|
11
|
+
|
12
|
+
describe "Generator" do
|
13
|
+
before :all do
|
14
|
+
# Don't use --skip-git because we want .gitignore file to exist in the project
|
15
|
+
sh_in_dir(SPEC_PATH, %(
|
16
|
+
rails new base-rails-app --skip-javascript --skip-bundle --skip-spring
|
17
|
+
rm -rf base-rails-app/.git
|
18
|
+
))
|
19
|
+
|
20
|
+
Bundler.with_unbundled_env do
|
21
|
+
sh_in_dir(BASE_RAILS_APP_PATH, %(
|
22
|
+
gem update bundler
|
23
|
+
bundle add shakapacker --path "#{GEM_ROOT}"
|
24
|
+
))
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
after :all do
|
29
|
+
Dir.chdir(SPEC_PATH)
|
30
|
+
FileUtils.rm_rf(BASE_RAILS_APP_PATH)
|
31
|
+
end
|
32
|
+
|
33
|
+
describe "shakapacker:install" do
|
34
|
+
context "in a normal Rails project" do
|
35
|
+
before :all do
|
36
|
+
sh_in_dir(SPEC_PATH, "cp -r #{BASE_RAILS_APP_PATH} #{TEMP_RAILS_APP_PATH}")
|
37
|
+
|
38
|
+
Bundler.with_unbundled_env do
|
39
|
+
sh_in_dir(TEMP_RAILS_APP_PATH, "FORCE=true bundle exec rails shakapacker:install")
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
after :all do
|
44
|
+
Dir.chdir(SPEC_PATH)
|
45
|
+
FileUtils.rm_rf(TEMP_RAILS_APP_PATH)
|
46
|
+
end
|
47
|
+
|
48
|
+
it "creates `config/shakapacker.yml`" do
|
49
|
+
config_file_relative_path = "config/shakapacker.yml"
|
50
|
+
actual_content = read(path_in_the_app(config_file_relative_path))
|
51
|
+
expected_content = read(path_in_the_gem(config_file_relative_path))
|
52
|
+
|
53
|
+
expect(actual_content).to eq expected_content
|
54
|
+
end
|
55
|
+
|
56
|
+
it "replaces package.json with template file" do
|
57
|
+
actual_content = read(path_in_the_app("package.json"))
|
58
|
+
|
59
|
+
expect(actual_content).to match /"name": "app",/
|
60
|
+
end
|
61
|
+
|
62
|
+
it "creates webpack config directory and its files" do
|
63
|
+
expected_files = [
|
64
|
+
"webpack.config.js"
|
65
|
+
]
|
66
|
+
|
67
|
+
Dir.chdir(path_in_the_app("config/webpack")) do
|
68
|
+
exisiting_files_in_config_webpack_dir = Dir.glob("*")
|
69
|
+
expect(exisiting_files_in_config_webpack_dir).to eq expected_files
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
it "adds binstubs" do
|
74
|
+
expected_binstubs = []
|
75
|
+
Dir.chdir(File.join(GEM_ROOT, "lib/install/bin")) do
|
76
|
+
expected_binstubs = Dir.glob("bin/*")
|
77
|
+
end
|
78
|
+
|
79
|
+
Dir.chdir(File.join(TEMP_RAILS_APP_PATH, "bin")) do
|
80
|
+
actual_binstubs = Dir.glob("*")
|
81
|
+
expect(actual_binstubs).to include(*expected_binstubs)
|
82
|
+
end
|
83
|
+
end
|
84
|
+
|
85
|
+
it "modifies .gitignore" do
|
86
|
+
actual_content = read(path_in_the_app(".gitignore"))
|
87
|
+
|
88
|
+
expect(actual_content).to match ".yarn-integrity"
|
89
|
+
end
|
90
|
+
|
91
|
+
it 'adds <%= javascript_pack_tag "application" %>' do
|
92
|
+
actual_content = read(path_in_the_app("app/views/layouts/application.html.erb"))
|
93
|
+
|
94
|
+
expect(actual_content).to match '<%= javascript_pack_tag "application" %>'
|
95
|
+
end
|
96
|
+
|
97
|
+
it "updates `bin/setup" do
|
98
|
+
setup_file_content = read(path_in_the_app("bin/setup"))
|
99
|
+
expect(setup_file_content).to match %r(^\s*system!\(['"]bin/yarn['"]\))
|
100
|
+
end
|
101
|
+
|
102
|
+
it "adds relevant shakapacker version in package.json depending on gem version," do
|
103
|
+
npm_version = Shakapacker::Utils::VersionSyntaxConverter.new.rubygem_to_npm(Shakapacker::VERSION)
|
104
|
+
|
105
|
+
actual_content = read(path_in_the_app("package.json"))
|
106
|
+
|
107
|
+
expect(actual_content).to match /"shakapacker": "#{npm_version}",/
|
108
|
+
end
|
109
|
+
|
110
|
+
it "adds Shakapacker peer dependencies to package.json" do
|
111
|
+
package_json = JSON.parse(File.read(path_in_the_app("package.json")))
|
112
|
+
actual_dependencies = package_json["dependencies"]&.keys
|
113
|
+
|
114
|
+
expected_dependencies = %w(
|
115
|
+
@babel/core
|
116
|
+
@babel/plugin-transform-runtime
|
117
|
+
@babel/preset-env
|
118
|
+
@babel/runtime
|
119
|
+
babel-loader
|
120
|
+
compression-webpack-plugin
|
121
|
+
terser-webpack-plugin
|
122
|
+
webpack
|
123
|
+
webpack-assets-manifest
|
124
|
+
webpack-cli
|
125
|
+
webpack-merge
|
126
|
+
)
|
127
|
+
|
128
|
+
expect(actual_dependencies).to include(*expected_dependencies)
|
129
|
+
end
|
130
|
+
|
131
|
+
it "adds Shakapacker peer dev dependencies to package.json" do
|
132
|
+
package_json = JSON.parse(File.read(path_in_the_app("package.json")))
|
133
|
+
actual_dev_dependencies = package_json["devDependencies"]&.keys
|
134
|
+
|
135
|
+
expected_dev_dependencies = %w(
|
136
|
+
webpack-dev-server
|
137
|
+
)
|
138
|
+
|
139
|
+
expect(actual_dev_dependencies).to include(*expected_dev_dependencies)
|
140
|
+
end
|
141
|
+
|
142
|
+
context "with a basic react app setup" do
|
143
|
+
it "passes the test for rendering react component on the page" do
|
144
|
+
Bundler.with_unbundled_env do
|
145
|
+
sh_in_dir(TEMP_RAILS_APP_PATH, "./bin/rails app:template LOCATION=../e2e_template/template.rb")
|
146
|
+
expect(sh_in_dir(TEMP_RAILS_APP_PATH, "bundle exec rspec")).to be_truthy
|
147
|
+
end
|
148
|
+
end
|
149
|
+
end
|
150
|
+
end
|
151
|
+
end
|
152
|
+
|
153
|
+
private
|
154
|
+
def path_in_the_app(relative_path = nil)
|
155
|
+
Pathname.new(File.join([TEMP_RAILS_APP_PATH, relative_path].compact))
|
156
|
+
end
|
157
|
+
|
158
|
+
def path_in_the_gem(relative_path = nil)
|
159
|
+
Pathname.new(File.join([GEM_ROOT, "lib/install" , relative_path].compact))
|
160
|
+
end
|
161
|
+
|
162
|
+
def read(path)
|
163
|
+
File.read(path)
|
164
|
+
end
|
165
|
+
|
166
|
+
def sh_in_dir(dir, *shell_commands)
|
167
|
+
Shakapacker::Utils::Misc.sh_in_dir(dir, *shell_commands)
|
168
|
+
end
|
169
|
+
end
|
@@ -1,7 +1,7 @@
|
|
1
1
|
require_relative "spec_helper_initializer"
|
2
2
|
|
3
3
|
describe "Shakapacker::Configuration" do
|
4
|
-
ROOT_PATH = Pathname.new(File.expand_path("test_app", __dir__))
|
4
|
+
ROOT_PATH = Pathname.new(File.expand_path("./test_app", __dir__))
|
5
5
|
|
6
6
|
context "with standard shakapacker.yml" do
|
7
7
|
let(:config) do
|
@@ -13,37 +13,37 @@ describe "Shakapacker::Configuration" do
|
|
13
13
|
end
|
14
14
|
|
15
15
|
it "#source_path returns correct path" do
|
16
|
-
source_path = File.expand_path File.join(File.dirname(__FILE__), "test_app/app/javascript").to_s
|
16
|
+
source_path = File.expand_path File.join(File.dirname(__FILE__), "./test_app/app/javascript").to_s
|
17
17
|
expect(config.source_path.to_s).to eq source_path
|
18
18
|
end
|
19
19
|
|
20
20
|
it "#source_entry_path returns correct path" do
|
21
|
-
source_entry_path = File.expand_path File.join(File.dirname(__FILE__), "test_app/app/javascript", "entrypoints").to_s
|
21
|
+
source_entry_path = File.expand_path File.join(File.dirname(__FILE__), "./test_app/app/javascript", "entrypoints").to_s
|
22
22
|
expect(config.source_entry_path.to_s).to eq source_entry_path
|
23
23
|
end
|
24
24
|
|
25
25
|
it "#public_root_path returns correct path" do
|
26
|
-
public_root_path = File.expand_path File.join(File.dirname(__FILE__), "test_app/public").to_s
|
26
|
+
public_root_path = File.expand_path File.join(File.dirname(__FILE__), "./test_app/public").to_s
|
27
27
|
expect(config.public_path.to_s).to eq public_root_path
|
28
28
|
end
|
29
29
|
|
30
30
|
it "#public_output_path returns correct path" do
|
31
|
-
public_output_path = File.expand_path File.join(File.dirname(__FILE__), "test_app/public/packs").to_s
|
31
|
+
public_output_path = File.expand_path File.join(File.dirname(__FILE__), "./test_app/public/packs").to_s
|
32
32
|
expect(config.public_output_path.to_s).to eq public_output_path
|
33
33
|
end
|
34
34
|
|
35
35
|
it "#public_manifest_path returns correct path" do
|
36
|
-
public_manifest_path = File.expand_path File.join(File.dirname(__FILE__), "test_app/public/packs", "manifest.json").to_s
|
36
|
+
public_manifest_path = File.expand_path File.join(File.dirname(__FILE__), "./test_app/public/packs", "manifest.json").to_s
|
37
37
|
expect(config.public_manifest_path.to_s).to eq public_manifest_path
|
38
38
|
end
|
39
39
|
|
40
40
|
it "#manifest_path returns correct path" do
|
41
|
-
manifest_path = File.expand_path File.join(File.dirname(__FILE__), "test_app/public/packs", "manifest.json").to_s
|
41
|
+
manifest_path = File.expand_path File.join(File.dirname(__FILE__), "./test_app/public/packs", "manifest.json").to_s
|
42
42
|
expect(config.manifest_path.to_s).to eq manifest_path
|
43
43
|
end
|
44
44
|
|
45
45
|
it "#cache_path returns correct path" do
|
46
|
-
cache_path = File.expand_path File.join(File.dirname(__FILE__), "test_app/tmp/shakapacker").to_s
|
46
|
+
cache_path = File.expand_path File.join(File.dirname(__FILE__), "./test_app/tmp/shakapacker").to_s
|
47
47
|
expect(config.cache_path.to_s).to eq cache_path
|
48
48
|
end
|
49
49
|
|
@@ -184,7 +184,7 @@ describe "Shakapacker::Configuration" do
|
|
184
184
|
)
|
185
185
|
|
186
186
|
it "#public_output_path returns correct path" do
|
187
|
-
expected_public_output_path = File.expand_path File.join(File.dirname(__FILE__), "public/packs").to_s
|
187
|
+
expected_public_output_path = File.expand_path File.join(File.dirname(__FILE__), "./public/packs").to_s
|
188
188
|
expect(config.public_output_path.to_s).to eq expected_public_output_path
|
189
189
|
end
|
190
190
|
end
|
@@ -197,7 +197,7 @@ describe "Shakapacker::Configuration" do
|
|
197
197
|
)
|
198
198
|
|
199
199
|
it "#manifest_path returns correct expected value" do
|
200
|
-
expected_manifest_path = File.expand_path File.join(File.dirname(__FILE__), "test_app/app/javascript", "manifest.json").to_s
|
200
|
+
expected_manifest_path = File.expand_path File.join(File.dirname(__FILE__), "./test_app/app/javascript", "manifest.json").to_s
|
201
201
|
expect(config.manifest_path.to_s).to eq expected_manifest_path
|
202
202
|
end
|
203
203
|
end
|
@@ -14,7 +14,7 @@ describe "DevServerRunner" do
|
|
14
14
|
ENV["SHAKAPACKER_CONFIG"] = @original_shakapacker_config
|
15
15
|
end
|
16
16
|
|
17
|
-
let(:test_app_path) { File.expand_path("test_app", __dir__) }
|
17
|
+
let(:test_app_path) { File.expand_path("./test_app", __dir__) }
|
18
18
|
|
19
19
|
it "run cmd via node modules" do
|
20
20
|
cmd = ["#{test_app_path}/node_modules/.bin/webpack", "serve", "--config", "#{test_app_path}/config/webpack/webpack.config.js"]
|
@@ -21,7 +21,7 @@ describe "EngineRakeTasks" do
|
|
21
21
|
|
22
22
|
private
|
23
23
|
def mounted_app_path
|
24
|
-
File.expand_path("mounted_app", __dir__)
|
24
|
+
File.expand_path("../mounted_app", __dir__)
|
25
25
|
end
|
26
26
|
|
27
27
|
def current_files_in_bin
|
@@ -29,7 +29,7 @@ describe "EngineRakeTasks" do
|
|
29
29
|
end
|
30
30
|
|
31
31
|
def expected_binstub_paths
|
32
|
-
gem_path = File.expand_path("
|
32
|
+
gem_path = File.expand_path("../..", __dir__)
|
33
33
|
Dir.chdir("#{gem_path}/lib/install/bin") do
|
34
34
|
Dir.glob("*").map { |file| "#{mounted_app_path}/test/dummy/bin/#{file}" }
|
35
35
|
end
|
@@ -1,7 +1,7 @@
|
|
1
1
|
require_relative "spec_helper_initializer"
|
2
2
|
|
3
3
|
describe "Shakapacker::Manifest" do
|
4
|
-
let(:manifest_path) { File.expand_path File.join(File.dirname(__FILE__), "test_app/public/packs", "manifest.json").to_s }
|
4
|
+
let(:manifest_path) { File.expand_path File.join(File.dirname(__FILE__), "./test_app/public/packs", "manifest.json").to_s }
|
5
5
|
|
6
6
|
it "#lookup! throws exception for a non-existing asset file" do
|
7
7
|
asset_file = "calendar.js"
|
@@ -0,0 +1,93 @@
|
|
1
|
+
require_relative "spec_helper_initializer"
|
2
|
+
|
3
|
+
describe "RakeTasks" do
|
4
|
+
TEST_APP_PATH = File.expand_path("./test_app", __dir__)
|
5
|
+
|
6
|
+
it "`rake -T` lists Shakapacker tasks" do
|
7
|
+
output = Dir.chdir(TEST_APP_PATH) { `rake -T` }
|
8
|
+
expect(output).to include "shakapacker"
|
9
|
+
expect(output).to include "shakapacker:check_binstubs"
|
10
|
+
expect(output).to include "shakapacker:check_node"
|
11
|
+
expect(output).to include "shakapacker:check_yarn"
|
12
|
+
expect(output).to include "shakapacker:clean"
|
13
|
+
expect(output).to include "shakapacker:clobber"
|
14
|
+
expect(output).to include "shakapacker:compile"
|
15
|
+
expect(output).to include "shakapacker:install"
|
16
|
+
expect(output).to include "shakapacker:verify_install"
|
17
|
+
end
|
18
|
+
|
19
|
+
it "`shakapacker:check_binstubs` doesn't get 'webpack binstub not found' error" do
|
20
|
+
output = Dir.chdir(TEST_APP_PATH) { `rake shakapacker:check_binstubs 2>&1` }
|
21
|
+
expect(output).to_not include "webpack binstub not found."
|
22
|
+
end
|
23
|
+
|
24
|
+
it "`shakapacker:check_node` doesn't get 'shakapacker requires Node.js' error" do
|
25
|
+
output = Dir.chdir(TEST_APP_PATH) { `rake shakapacker:check_node 2>&1` }
|
26
|
+
expect(output).to_not include "Shakapacker requires Node.js"
|
27
|
+
end
|
28
|
+
|
29
|
+
it "`shakapacker:check_yarn` doesn't get error related to yarn" do
|
30
|
+
output = Dir.chdir(TEST_APP_PATH) { `rake shakapacker:check_yarn 2>&1` }
|
31
|
+
expect(output).to_not include "Yarn not installed"
|
32
|
+
expect(output).to_not include "Shakapacker requires Yarn"
|
33
|
+
end
|
34
|
+
|
35
|
+
describe "`shakapacker:check_binstubs`" do
|
36
|
+
def with_temporary_file(file_name, &block)
|
37
|
+
FileUtils.touch(file_name, verbose: false)
|
38
|
+
yield if block_given?
|
39
|
+
ensure
|
40
|
+
FileUtils.rm_f(file_name, verbose: false)
|
41
|
+
end
|
42
|
+
|
43
|
+
before :all do
|
44
|
+
Dir.chdir(TEST_APP_PATH)
|
45
|
+
end
|
46
|
+
|
47
|
+
context "with existing `./bin/shapapacker` and `./bin/shapapacker-dev-server`" do
|
48
|
+
it "passes" do
|
49
|
+
expect { system("bundle exec rake shakapacker:check_binstubs") }.to output("").to_stdout_from_any_process
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
context "without `./bin/shakapacker`" do
|
54
|
+
before :all do
|
55
|
+
FileUtils.mv("bin/shakapacker", "bin/shakapacker_renamed")
|
56
|
+
end
|
57
|
+
|
58
|
+
after :all do
|
59
|
+
FileUtils.mv("bin/shakapacker_renamed", "bin/shakapacker")
|
60
|
+
end
|
61
|
+
|
62
|
+
it "passes if `./bin/webpacker exist" do
|
63
|
+
with_temporary_file("bin/webpacker") do
|
64
|
+
expect { system("bundle exec rake shakapacker:check_binstubs") }.to output(/DEPRECATION/).to_stdout_from_any_process
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
it "fails otherwise" do
|
69
|
+
expect { system("bundle exec rake shakapacker:check_binstubs") }.to output(/Couldn't find shakapacker binstubs!/).to_stdout_from_any_process
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
context "without `./bin/shakapacker-dev-server`" do
|
74
|
+
before :all do
|
75
|
+
FileUtils.mv("bin/shakapacker-dev-server", "bin/shakapacker-dev-server_renamed")
|
76
|
+
end
|
77
|
+
|
78
|
+
after :all do
|
79
|
+
FileUtils.mv("bin/shakapacker-dev-server_renamed", "bin/shakapacker-dev-server")
|
80
|
+
end
|
81
|
+
|
82
|
+
it "passes if `./bin/webpacker-dev-server exist" do
|
83
|
+
with_temporary_file("bin/webpacker-dev-server") do
|
84
|
+
expect { system("bundle exec rake shakapacker:check_binstubs") }.to output(/DEPRECATION/).to_stdout_from_any_process
|
85
|
+
end
|
86
|
+
end
|
87
|
+
|
88
|
+
it "fails otherwise" do
|
89
|
+
expect { system("bundle exec rake shakapacker:check_binstubs") }.to output(/Couldn't find shakapacker binstubs!/).to_stdout_from_any_process
|
90
|
+
end
|
91
|
+
end
|
92
|
+
end
|
93
|
+
end
|
File without changes
|
File without changes
|
@@ -102,7 +102,7 @@ describe "VersionChecker::NodePackageVersion" do
|
|
102
102
|
context "with no yarn.lock file" do
|
103
103
|
def node_package_version(fixture_version:)
|
104
104
|
Shakapacker::VersionChecker::NodePackageVersion.new(
|
105
|
-
File.expand_path("fixtures/#{fixture_version}_package.json", __dir__),
|
105
|
+
File.expand_path("../fixtures/#{fixture_version}_package.json", __dir__),
|
106
106
|
"file/does/not/exist",
|
107
107
|
"file/does/not/exist"
|
108
108
|
)
|
@@ -272,8 +272,8 @@ describe "VersionChecker::NodePackageVersion" do
|
|
272
272
|
context "with yarn.lock v1" do
|
273
273
|
def node_package_version(fixture_version:)
|
274
274
|
Shakapacker::VersionChecker::NodePackageVersion.new(
|
275
|
-
File.expand_path("fixtures/#{fixture_version}_package.json", __dir__),
|
276
|
-
File.expand_path("fixtures/#{fixture_version}_yarn.v1.lock", __dir__),
|
275
|
+
File.expand_path("../fixtures/#{fixture_version}_package.json", __dir__),
|
276
|
+
File.expand_path("../fixtures/#{fixture_version}_yarn.v1.lock", __dir__),
|
277
277
|
"file/does/not/exist"
|
278
278
|
)
|
279
279
|
end
|
@@ -442,8 +442,8 @@ describe "VersionChecker::NodePackageVersion" do
|
|
442
442
|
context "with yarn.lock v2" do
|
443
443
|
def node_package_version(fixture_version:)
|
444
444
|
Shakapacker::VersionChecker::NodePackageVersion.new(
|
445
|
-
File.expand_path("fixtures/#{fixture_version}_package.json", __dir__),
|
446
|
-
File.expand_path("fixtures/#{fixture_version}_yarn.v2.lock", __dir__),
|
445
|
+
File.expand_path("../fixtures/#{fixture_version}_package.json", __dir__),
|
446
|
+
File.expand_path("../fixtures/#{fixture_version}_yarn.v2.lock", __dir__),
|
447
447
|
"file/does/not/exist"
|
448
448
|
)
|
449
449
|
end
|
@@ -612,9 +612,9 @@ describe "VersionChecker::NodePackageVersion" do
|
|
612
612
|
context "with package-lock.json v1" do
|
613
613
|
def node_package_version(fixture_version:)
|
614
614
|
Shakapacker::VersionChecker::NodePackageVersion.new(
|
615
|
-
File.expand_path("fixtures/#{fixture_version}_package.json", __dir__),
|
615
|
+
File.expand_path("../fixtures/#{fixture_version}_package.json", __dir__),
|
616
616
|
"file/does/not/exist",
|
617
|
-
File.expand_path("fixtures/#{fixture_version}_package-lock.v1.json", __dir__),
|
617
|
+
File.expand_path("../fixtures/#{fixture_version}_package-lock.v1.json", __dir__),
|
618
618
|
)
|
619
619
|
end
|
620
620
|
|
@@ -782,9 +782,9 @@ describe "VersionChecker::NodePackageVersion" do
|
|
782
782
|
context "with package-lock.json v2" do
|
783
783
|
def node_package_version(fixture_version:)
|
784
784
|
Shakapacker::VersionChecker::NodePackageVersion.new(
|
785
|
-
File.expand_path("fixtures/#{fixture_version}_package.json", __dir__),
|
785
|
+
File.expand_path("../fixtures/#{fixture_version}_package.json", __dir__),
|
786
786
|
"file/does/not/exist",
|
787
|
-
File.expand_path("fixtures/#{fixture_version}_package-lock.v2.json", __dir__),
|
787
|
+
File.expand_path("../fixtures/#{fixture_version}_package-lock.v2.json", __dir__),
|
788
788
|
)
|
789
789
|
end
|
790
790
|
|