Skip to content

Commit

Permalink
Improve Error Messaging when Yarn is missing
Browse files Browse the repository at this point in the history
Prior to this commit, the `yarn` command being inaccessible resulted in
confusing failures messages.

When an application depends on `yarn` (by being configured with
`yarn: true`) and the `yarn` command is not acccessible, an
`EmberCli::DependencyError` will be raised.
  • Loading branch information
drcapulet authored and seanpdoyle committed Apr 27, 2018
1 parent d5b19df commit 6515144
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 7 deletions.
11 changes: 10 additions & 1 deletion lib/ember_cli/path_set.rb
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,16 @@ def npm

def yarn
if yarn?
@yarn ||= path_for_executable("yarn")
@yarn ||= path_for_executable("yarn").tap do |yarn|
unless File.executable?(yarn.to_s)
fail DependencyError.new(<<-MSG.strip_heredoc)
EmberCLI has been configured to install NodeJS dependencies with Yarn, but the Yarn executable is unavailable.
Install it by following the instructions at https://yarnpkg.com/lang/en/docs/install/
MSG
end
end
end
end

Expand Down
2 changes: 1 addition & 1 deletion lib/ember_cli/shell.rb
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ def install
clean_ember_dependencies!
end

if paths.yarn.present? && Pathname.new(paths.yarn).executable?
if paths.yarn
run! "#{paths.yarn} install"
else
run! "#{paths.npm} prune && #{paths.npm} install"
Expand Down
22 changes: 17 additions & 5 deletions spec/lib/ember_cli/path_set_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -212,13 +212,25 @@
end

context "when the executable isn't installed on the system" do
it "returns nil" do
stub_which(yarn: nil)
path_set = build_path_set
context "and yarn is requested" do
it "raises a DependencyError" do
stub_which(yarn: nil)
app = build_app(options: { yarn: true })
path_set = build_path_set(app: app)

yarn = path_set.yarn
expect { path_set.yarn }.to raise_error(EmberCli::DependencyError)
end
end

context "and yarn is not requested" do
it "returns nil" do
stub_which(yarn: nil)
path_set = build_path_set

yarn = path_set.yarn

expect(yarn).to be_nil
expect(yarn).to be_nil
end
end
end
end
Expand Down

0 comments on commit 6515144

Please sign in to comment.