Skip to content

Commit 6eceea8

Browse files
botandrose-machineseanpdoyle
authored andcommitted
Enhance rake ember:install to fully reinstall if necessary.
Closes [#394]. EmberCLI ships with [`ember-cli-dependency-checker`][addon], which exposes the `ember version` command. `ember version` is akin to `bundle check`. This commit enhances the `ember:install` Rake task to cleanup frontend dependencies before installing if `ember version` returns a non-zero exit status. This (in conjunction with [`npm shrinkwrap`][shrinkwrap]) helps to ensure that every machine has the same dependencies installed. [#394]: #394 [addon]: https://github.com/quaertym/ember-cli-dependency-checker [shrinkwrap]: https://github.com/quaertym/ember-cli-dependency-checker#deployment-with-shrinkwrap
1 parent 7e901b3 commit 6eceea8

File tree

5 files changed

+69
-9
lines changed

5 files changed

+69
-9
lines changed

CHANGELOG.md

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

4+
* Enhance `rake ember:install` to fully reinstall if necessary. [#396]
45
* `EmberCli::Deploy::File` serves assets with Rails' `static_cache_control`
56
value. [#403]
67

8+
[#396]: https://github.com/thoughtbot/ember-cli-rails/pull/396
79
[#403]: https://github.com/thoughtbot/ember-cli-rails/pull/403
810

911
0.7.1

lib/ember_cli/path_set.rb

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,10 +78,18 @@ def bower
7878
end
7979
end
8080

81+
def bower_components
82+
@bower_components ||= root.join("bower_components")
83+
end
84+
8185
def npm
8286
@npm ||= app_options.fetch(:npm_path) { which("npm") }
8387
end
8488

89+
def node_modules
90+
@node_modules ||= root.join("node_modules")
91+
end
92+
8593
def tee
8694
@tee ||= app_options.fetch(:tee_path) { which("tee") }
8795
end

lib/ember_cli/runner.rb

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,19 +9,25 @@ def initialize(env: {}, out:, err:, options: {})
99
@options = options
1010
end
1111

12-
def run!(command)
12+
def run(command)
1313
output, status = Open3.capture2e(@env, command, @options)
1414

1515
@out.write(output)
1616

17+
[output, status]
18+
end
19+
20+
def run!(command)
21+
output, status = run(command)
22+
1723
unless status.success?
1824
@err.write <<-MSG.strip_heredoc
1925
ERROR: Failed command: `#{command}`
2026
OUTPUT:
2127
#{output}
2228
MSG
2329

24-
exit 1
30+
exit status.exitstatus
2531
end
2632

2733
true

lib/ember_cli/shell.rb

Lines changed: 30 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ def initialize(paths:, env: {}, options: {})
1414
end
1515

1616
def compile
17-
exec ember.build
17+
run! ember.build
1818
end
1919

2020
def build_and_watch
@@ -34,22 +34,45 @@ def stop
3434

3535
def install
3636
if paths.gemfile.exist?
37-
exec "#{paths.bundler} install"
37+
run! "#{paths.bundler} install"
3838
end
3939

40-
exec "#{paths.npm} prune && #{paths.npm} install"
41-
exec "#{paths.bower} prune && #{paths.bower} install"
40+
if invalid_ember_dependencies?
41+
clean_ember_dependencies!
42+
end
43+
44+
run! "#{paths.npm} prune && #{paths.npm} install"
45+
run! "#{paths.bower} prune && #{paths.bower} install"
4246
end
4347

4448
def test
45-
exec ember.test
49+
run! ember.test
4650
end
4751

4852
private
4953

5054
attr_accessor :pid
5155
attr_reader :ember, :env, :options, :paths
5256

57+
delegate :run, :run!, to: :runner
58+
59+
def invalid_ember_dependencies?
60+
!run("#{paths.ember} version")
61+
rescue DependencyError
62+
false
63+
end
64+
65+
def clean_ember_dependencies!
66+
ember_dependency_directories.select(&:exist?).each(&:rmtree)
67+
end
68+
69+
def ember_dependency_directories
70+
[
71+
paths.node_modules,
72+
paths.bower_components,
73+
]
74+
end
75+
5376
def spawn(command)
5477
Kernel.spawn(
5578
env,
@@ -59,13 +82,13 @@ def spawn(command)
5982
) || exit(1)
6083
end
6184

62-
def exec(command)
85+
def runner
6386
Runner.new(
6487
options: { chdir: paths.root.to_s },
6588
out: paths.log,
6689
err: $stderr,
6790
env: env,
68-
).run!(command)
91+
)
6992
end
7093

7194
def running?

spec/lib/ember_cli/path_set_spec.rb

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,17 @@
127127
end
128128
end
129129

130+
describe "#bower_components" do
131+
it "is a child of #root" do
132+
app = build_app(name: "foo")
133+
134+
path_set = build_path_set(app: app)
135+
136+
expect(path_set.bower_components).
137+
to eq rails_root.join("foo", "bower_components")
138+
end
139+
end
140+
130141
describe "#npm" do
131142
it "can be overridden" do
132143
app = build_app(options: { npm_path: "npm-path" })
@@ -145,6 +156,16 @@
145156
end
146157
end
147158

159+
describe "#node_modules" do
160+
it "is a child of #root" do
161+
app = build_app(name: "foo")
162+
163+
path_set = build_path_set(app: app)
164+
165+
expect(path_set.node_modules).to eq rails_root.join("foo", "node_modules")
166+
end
167+
end
168+
148169
describe "#tee" do
149170
it "can be overridden" do
150171
app = build_app(options: { tee_path: "tee-path" })

0 commit comments

Comments
 (0)