Skip to content

Commit 34ff6dd

Browse files
committed
Make bower an optional dependency
Closes [#531]. According to `bower` warning messages, the project is semi-deprecated: ``` While Bower is maintained, we recommend Yarn and Webpack for *new* front-end projects! Yarn's advantage is security and reliability, and Webpack's is support for both CommonJS and AMD projects. Currently there's no migration path but we hope you'll help us figure out one. ``` As such, the build process will skip `bower install` and won't require a `bower` if the application's `bower.json` file is missing. [#531]: #531
1 parent 2707c08 commit 34ff6dd

File tree

5 files changed

+64
-18
lines changed

5 files changed

+64
-18
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
master
22
------
33

4+
* Don't require `bower` installation if `bower.json` is missing [#532]
5+
6+
[#532]: https://github.com/thoughtbot/ember-cli-rails/pull/532
7+
48
0.8.5
59
-----
610

README.md

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -270,7 +270,8 @@ To configure your EmberCLI-Rails applications for Heroku:
270270
1. Execute `rails generate ember:heroku`.
271271
1. Commit the newly generated files.
272272
1. [Add the NodeJS buildpack][buildpack] and configure NPM to include the
273-
`bower` dependency's executable file.
273+
`bower` dependency's executable file (if your build process requires
274+
`bower`).
274275

275276
```sh
276277
$ heroku buildpacks:clear
@@ -328,11 +329,16 @@ contains the directory or directories that contain the `bower` and `npm`
328329
executables.
329330

330331
#### For faster deployments
331-
Place the following in your deploy/<environment>.rb
332+
333+
Place the following in your `deploy/<environment>.rb`
334+
332335
```ruby
333336
set :linked_dirs, %w{<ember-app-name>/node_modules <ember-app-name>/bower_components}
334337
```
335-
to avoid rebuilding all the node modules and bower components with every deploy. Replace `<ember-app-name>` with the name of your ember app (default is `frontend`).
338+
339+
to avoid rebuilding all the node modules and bower components with every deploy.
340+
Replace `<ember-app-name>` with the name of your ember app (default is
341+
`frontend`).
336342

337343
## Override
338344

lib/ember_cli/path_set.rb

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,10 @@ def gemfile
3535
@gemfile ||= root.join("Gemfile")
3636
end
3737

38+
def bower_json
39+
ember_cli_root.join("bower.json")
40+
end
41+
3842
def ember
3943
@ember ||= begin
4044
root.join("node_modules", "ember-cli", "bin", "ember").tap do |path|
@@ -64,7 +68,7 @@ def build_error_file
6468
def bower
6569
@bower ||= begin
6670
path_for_executable("bower").tap do |bower_path|
67-
if bower_path.blank? || !bower_path.executable?
71+
if bower_json.exist? && (bower_path.blank? || !bower_path.executable?)
6872
fail DependencyError.new <<-MSG.strip_heredoc
6973
Bower is required by EmberCLI
7074

lib/ember_cli/shell.rb

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,13 +41,15 @@ def install
4141
clean_ember_dependencies!
4242
end
4343

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

50-
run! "[ -f bower.json ] && #{paths.bower} prune && #{paths.bower} install"
50+
if paths.bower_json.exist?
51+
run! "#{paths.bower} prune && #{paths.bower} install"
52+
end
5153
end
5254

5355
def test

spec/lib/ember_cli/path_set_spec.rb

Lines changed: 42 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -119,14 +119,38 @@
119119
end
120120

121121
context "when it is missing from the $PATH" do
122-
it "raises a helpful exception" do
123-
stub_which(bower: nil)
122+
context "bower.json exists" do
123+
it "raises a helpful exception" do
124+
create_file(ember_cli_root.join("bower.json"))
125+
stub_which(bower: nil)
126+
path_set = build_path_set
127+
128+
expect { path_set.bower }.
129+
to raise_error(EmberCli::DependencyError, /bower is required/i)
130+
end
131+
132+
context "bower.json is missing" do
133+
it "returns nil" do
134+
stub_which(bower: nil)
135+
path_set = build_path_set
136+
137+
bower = path_set.bower
138+
139+
expect(bower).to be_nil
140+
end
141+
end
142+
end
143+
end
144+
end
124145

125-
path_set = build_path_set
146+
describe "#bower_json" do
147+
it "is a child of #root" do
148+
app = build_app(name: "foo")
149+
path_set = build_path_set(app: app)
126150

127-
expect { path_set.bower }.
128-
to raise_error(EmberCli::DependencyError, /bower is required/i)
129-
end
151+
bower_json = path_set.bower_json
152+
153+
expect(bower_json).to eq ember_cli_root.join("bower.json")
130154
end
131155
end
132156

@@ -164,12 +188,6 @@
164188
end
165189

166190
describe "#yarn" do
167-
it "is not enabled by default" do
168-
path_set = build_path_set
169-
170-
expect(path_set.yarn).to be nil
171-
end
172-
173191
it "can be overridden" do
174192
fake_yarn = create_executable(ember_cli_root.join("yarn"))
175193
app = build_app(options: { yarn_path: fake_yarn.to_s })
@@ -185,11 +203,23 @@
185203
stub_which(yarn: fake_yarn.to_s)
186204
app = build_app(options: { yarn: true })
187205
path_set = build_path_set(app: app)
206+
create_executable(fake_yarn)
188207

189208
yarn = path_set.yarn
190209

191210
expect(yarn).to eq(fake_yarn).and(be_executable)
192211
end
212+
213+
context "when the executable isn't installed on the system" do
214+
it "returns nil" do
215+
stub_which(yarn: nil)
216+
path_set = build_path_set
217+
218+
yarn = path_set.yarn
219+
220+
expect(yarn).to be_nil
221+
end
222+
end
193223
end
194224

195225
describe "#node_modules" do

0 commit comments

Comments
 (0)