Skip to content

Commit 7fc1b3e

Browse files
drewtempelmeyerseanpdoyle
authored andcommitted
Add support for yarn
#496 [yarn](https://github.com/yarnpkg/yarn) has significantly reduced the time it takes to install npm packages. Given the benefits of yarn, I've added opt-in support for using `yarn install` instead of `npm install`. Enabling yarn can be done by either: * Specifying the `yarn` option: ```ruby EmberCli.configure do |c| c.app :frontend, yarn: true end ``` * Specifying the `yarn_path`: ```ruby EmberCli.configure do |c| c.app :frontend, yarn_path: "/home/app/bin/yarn" end ```
1 parent 9119085 commit 7fc1b3e

File tree

5 files changed

+57
-2
lines changed

5 files changed

+57
-2
lines changed

CHANGELOG.md

+4
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
master
22
------
33

4+
* Add support for integrating with `yarn`. [#496]
5+
6+
[#496]: https://github.com/thoughtbot/ember-cli-rails/pull/496
7+
48
0.8.2.
59
------
610

README.md

+2
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,8 @@ c.app :frontend, path: "~/projects/my-ember-app"
7979

8080
- `silent` - this provides `--silent` option for Ember CLI commands to control verbosity of their output.
8181

82+
- `yarn` - enables the [yarn](https://github.com/yarnpkg/yarn) package manager when installing dependencies
83+
8284
```ruby
8385
EmberCli.configure do |c|
8486
c.app :adminpanel # path defaults to `Rails.root.join("adminpanel")`

lib/ember_cli/path_set.rb

+19-1
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ def ember
4545
Install it:
4646
4747
$ cd #{root}
48-
$ npm install
48+
$ #{package_manager} install
4949
MSG
5050
end
5151
end
@@ -86,6 +86,12 @@ def npm
8686
@npm ||= app_options.fetch(:npm_path) { which("npm") }
8787
end
8888

89+
def yarn
90+
if yarn?
91+
@yarn ||= app_options.fetch(:yarn_path) { which("yarn") }
92+
end
93+
end
94+
8995
def node_modules
9096
@node_modules ||= root.join("node_modules")
9197
end
@@ -102,6 +108,18 @@ def bundler
102108

103109
attr_reader :app, :ember_cli_root, :environment, :rails_root
104110

111+
def package_manager
112+
if yarn?
113+
"yarn"
114+
else
115+
"npm"
116+
end
117+
end
118+
119+
def yarn?
120+
app_options[:yarn] || app_options[:yarn_path]
121+
end
122+
105123
def app_name
106124
app.name
107125
end

lib/ember_cli/shell.rb

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

44-
run! "#{paths.npm} prune && #{paths.npm} install"
44+
if paths.yarn
45+
run! "#{paths.yarn} install"
46+
else
47+
run! "#{paths.npm} prune && #{paths.npm} install"
48+
end
49+
4550
run! "#{paths.bower} prune && #{paths.bower} install"
4651
end
4752

spec/lib/ember_cli/path_set_spec.rb

+26
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,32 @@
156156
end
157157
end
158158

159+
describe "#yarn" do
160+
it "is not enabled by default" do
161+
path_set = build_path_set
162+
163+
expect(path_set.yarn).to be nil
164+
end
165+
166+
it "can be overridden" do
167+
app = build_app(options: { yarn_path: "yarn-path" })
168+
169+
path_set = build_path_set(app: app)
170+
171+
expect(path_set.yarn).to eq "yarn-path"
172+
end
173+
174+
it "can be inferred from the $PATH" do
175+
stub_which(yarn: "yarn-path")
176+
177+
app = build_app(options: { yarn: true })
178+
179+
path_set = build_path_set(app: app)
180+
181+
expect(path_set.yarn).to eq "yarn-path"
182+
end
183+
end
184+
159185
describe "#node_modules" do
160186
it "is a child of #root" do
161187
app = build_app(name: "foo")

0 commit comments

Comments
 (0)