Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make "webpacker:yarn_install" task env aware #1331

Merged
merged 4 commits into from
Dec 3, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/tasks/webpacker/yarn_install.rake
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
namespace :webpacker do
desc "Support for older Rails versions. Install all JavaScript dependencies as specified via Yarn"
task :yarn_install do
system "yarn install --no-progress --frozen-lockfile --production"
system "yarn install --no-progress"
end
end
34 changes: 34 additions & 0 deletions test/rake_tasks_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,42 @@ def test_rake_task_webpacker_check_binstubs
refute_includes output, "webpack binstubs not found."
end

def test_rake_webpacker_yarn_install_in_non_production_environments
assert_includes test_app_dev_dependencies, "right-pad"

Webpacker.with_node_env("test") do
Dir.chdir(test_app_path) do
`bundle exec rake webpacker:yarn_install`
end
end

assert_includes installed_node_module_names, "right-pad",
"Expected dev dependencies to be installed"
end

def test_rake_webpacker_yarn_install_in_production_environment
Webpacker.with_node_env("production") do
Dir.chdir(test_app_path) do
`bundle exec rake webpacker:yarn_install`
end
end

refute_includes installed_node_module_names, "right-pad",
"Expected only production dependencies to be installed"
end

private
def test_app_path
File.expand_path("test_app", __dir__)
end

def test_app_dev_dependencies
package_json = File.expand_path("package.json", test_app_path)
JSON.parse(File.read(package_json))["devDependencies"]
end

def installed_node_module_names
node_modules_path = File.expand_path("node_modules", test_app_path)
Dir.chdir(node_modules_path) { Dir.glob("*") }
end
end
13 changes: 13 additions & 0 deletions test/test_app/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"name": "test_app",
"version": "1.0.0",
"main": "index.js",
"license": "MIT",
"private": true,
"dependencies": {
"left-pad": "^1.2.0"
},
"devDependencies": {
"right-pad": "^1.0.1"
}
}
11 changes: 11 additions & 0 deletions test/test_app/yarn.lock
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY.
# yarn lockfile v1


left-pad@^1.2.0:
version "1.2.0"
resolved "https://registry.yarnpkg.com/left-pad/-/left-pad-1.2.0.tgz#d30a73c6b8201d8f7d8e7956ba9616087a68e0ee"

right-pad@^1.0.1:
version "1.0.1"
resolved "https://registry.yarnpkg.com/right-pad/-/right-pad-1.0.1.tgz#8ca08c2cbb5b55e74dafa96bf7fd1a27d568c8d0"