Skip to content

Commit

Permalink
Revert "Revert "Make bower an optional dependency""
Browse files Browse the repository at this point in the history
This reverts commit 0501445.

The changes introduced in `0.8.6` will be re-released as part of a major
version bump to `0.9.x`.
  • Loading branch information
seanpdoyle committed Jun 14, 2017
1 parent f595014 commit a0c6cdf
Show file tree
Hide file tree
Showing 5 changed files with 64 additions and 18 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
master
------

* Don't require `bower` installation if `bower.json` is missing [#532]

[#532]: https://github.com/thoughtbot/ember-cli-rails/pull/532

0.8.7
-----

Expand Down
12 changes: 9 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,8 @@ To configure your EmberCLI-Rails applications for Heroku:
1. Execute `rails generate ember:heroku`.
1. Commit the newly generated files.
1. [Add the NodeJS buildpack][buildpack] and configure NPM to include the
`bower` dependency's executable file.
`bower` dependency's executable file (if your build process requires
`bower`).

```sh
$ heroku buildpacks:clear
Expand Down Expand Up @@ -328,11 +329,16 @@ contains the directory or directories that contain the `bower` and `npm`
executables.

#### For faster deployments
Place the following in your deploy/<environment>.rb

Place the following in your `deploy/<environment>.rb`

```ruby
set :linked_dirs, %w{<ember-app-name>/node_modules <ember-app-name>/bower_components}
```
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`).

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`).

## Override

Expand Down
6 changes: 5 additions & 1 deletion lib/ember_cli/path_set.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,10 @@ def gemfile
@gemfile ||= root.join("Gemfile")
end

def bower_json
ember_cli_root.join("bower.json")
end

def ember
@ember ||= begin
root.join("node_modules", "ember-cli", "bin", "ember").tap do |path|
Expand Down Expand Up @@ -64,7 +68,7 @@ def build_error_file
def bower
@bower ||= begin
path_for_executable("bower").tap do |bower_path|
if bower_path.blank? || !bower_path.executable?
if bower_json.exist? && (bower_path.blank? || !bower_path.executable?)
fail DependencyError.new <<-MSG.strip_heredoc
Bower is required by EmberCLI
Expand Down
6 changes: 4 additions & 2 deletions lib/ember_cli/shell.rb
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,15 @@ def install
clean_ember_dependencies!
end

if paths.yarn
if paths.yarn.present? && Pathname.new(paths.yarn).executable?
run! "#{paths.yarn} install"
else
run! "#{paths.npm} prune && #{paths.npm} install"
end

run! "[ -f bower.json ] && #{paths.bower} prune && #{paths.bower} install"
if paths.bower_json.exist?
run! "#{paths.bower} prune && #{paths.bower} install"
end
end

def test
Expand Down
54 changes: 42 additions & 12 deletions spec/lib/ember_cli/path_set_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -119,14 +119,38 @@
end

context "when it is missing from the $PATH" do
it "raises a helpful exception" do
stub_which(bower: nil)
context "bower.json exists" do
it "raises a helpful exception" do
create_file(ember_cli_root.join("bower.json"))
stub_which(bower: nil)
path_set = build_path_set

expect { path_set.bower }.
to raise_error(EmberCli::DependencyError, /bower is required/i)
end

context "bower.json is missing" do
it "returns nil" do
stub_which(bower: nil)
path_set = build_path_set

bower = path_set.bower

expect(bower).to be_nil
end
end
end
end
end

path_set = build_path_set
describe "#bower_json" do
it "is a child of #root" do
app = build_app(name: "foo")
path_set = build_path_set(app: app)

expect { path_set.bower }.
to raise_error(EmberCli::DependencyError, /bower is required/i)
end
bower_json = path_set.bower_json

expect(bower_json).to eq ember_cli_root.join("bower.json")
end
end

Expand Down Expand Up @@ -164,12 +188,6 @@
end

describe "#yarn" do
it "is not enabled by default" do
path_set = build_path_set

expect(path_set.yarn).to be nil
end

it "can be overridden" do
fake_yarn = create_executable(ember_cli_root.join("yarn"))
app = build_app(options: { yarn_path: fake_yarn.to_s })
Expand All @@ -185,11 +203,23 @@
stub_which(yarn: fake_yarn.to_s)
app = build_app(options: { yarn: true })
path_set = build_path_set(app: app)
create_executable(fake_yarn)

yarn = path_set.yarn

expect(yarn).to eq(fake_yarn).and(be_executable)
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

yarn = path_set.yarn

expect(yarn).to be_nil
end
end
end

describe "#node_modules" do
Expand Down

0 comments on commit a0c6cdf

Please sign in to comment.