Skip to content

Commit 6515144

Browse files
drcapuletseanpdoyle
authored andcommitted
Improve Error Messaging when Yarn is missing
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.
1 parent d5b19df commit 6515144

File tree

3 files changed

+28
-7
lines changed

3 files changed

+28
-7
lines changed

lib/ember_cli/path_set.rb

+10-1
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,16 @@ def npm
9292

9393
def yarn
9494
if yarn?
95-
@yarn ||= path_for_executable("yarn")
95+
@yarn ||= path_for_executable("yarn").tap do |yarn|
96+
unless File.executable?(yarn.to_s)
97+
fail DependencyError.new(<<-MSG.strip_heredoc)
98+
EmberCLI has been configured to install NodeJS dependencies with Yarn, but the Yarn executable is unavailable.
99+
100+
Install it by following the instructions at https://yarnpkg.com/lang/en/docs/install/
101+
102+
MSG
103+
end
104+
end
96105
end
97106
end
98107

lib/ember_cli/shell.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ def install
4141
clean_ember_dependencies!
4242
end
4343

44-
if paths.yarn.present? && Pathname.new(paths.yarn).executable?
44+
if paths.yarn
4545
run! "#{paths.yarn} install"
4646
else
4747
run! "#{paths.npm} prune && #{paths.npm} install"

spec/lib/ember_cli/path_set_spec.rb

+17-5
Original file line numberDiff line numberDiff line change
@@ -212,13 +212,25 @@
212212
end
213213

214214
context "when the executable isn't installed on the system" do
215-
it "returns nil" do
216-
stub_which(yarn: nil)
217-
path_set = build_path_set
215+
context "and yarn is requested" do
216+
it "raises a DependencyError" do
217+
stub_which(yarn: nil)
218+
app = build_app(options: { yarn: true })
219+
path_set = build_path_set(app: app)
218220

219-
yarn = path_set.yarn
221+
expect { path_set.yarn }.to raise_error(EmberCli::DependencyError)
222+
end
223+
end
224+
225+
context "and yarn is not requested" do
226+
it "returns nil" do
227+
stub_which(yarn: nil)
228+
path_set = build_path_set
229+
230+
yarn = path_set.yarn
220231

221-
expect(yarn).to be_nil
232+
expect(yarn).to be_nil
233+
end
222234
end
223235
end
224236
end

0 commit comments

Comments
 (0)