Skip to content

Commit

Permalink
Generate empty yarn.lock using Yarn on Heroku
Browse files Browse the repository at this point in the history
Closes [#538].

Generate an empty `yarn.lock` so that Heroku understands that the
application's deployment target requires `yarn`.

[#538]: #538
  • Loading branch information
seanpdoyle committed Jul 14, 2017
1 parent 1089254 commit 5ed3bc7
Show file tree
Hide file tree
Showing 7 changed files with 80 additions and 0 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
master
------

* Generate an empty `yarn.lock` so that Heroku understands that the
application's deployment target requires `yarn`. Closes [#538]. [#540]

[#538]: https://github.com/thoughtbot/ember-cli-rails/issues/538
[#540]: https://github.com/thoughtbot/ember-cli-rails/pull/540

0.9.0
-----

Expand Down
1 change: 1 addition & 0 deletions ember-cli-rails.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,5 @@ Gem::Specification.new do |spec|
spec.add_dependency "railties", ">= 3.2"
spec.add_dependency "cocaine", "~> 0.5.8"
spec.add_dependency "html_page", "~> 0.1.0"
spec.add_development_dependency "generator_spec", "~> 0.9.0"
end
4 changes: 4 additions & 0 deletions lib/ember_cli/app.rb
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,10 @@ def mountable?
deploy.mountable?
end

def yarn_enabled?
options.fetch(:yarn, false)
end

def to_rack
deploy.to_rack
end
Expand Down
6 changes: 6 additions & 0 deletions lib/generators/ember/heroku/heroku_generator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,12 @@ def copy_setup_heroku_file
run "chmod a+x bin/heroku_install"
end

def identify_as_yarn_project
if EmberCli.apps.values.any?(&:yarn_enabled?)
template "yarn.lock.erb", "yarn.lock"
end
end

def inject_12factor_gem
gem "rails_12factor", group: [:staging, :production]
end
Expand Down
1 change: 1 addition & 0 deletions lib/generators/ember/heroku/templates/yarn.lock.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@

40 changes: 40 additions & 0 deletions spec/generators/ember/heroku/heroku_generator_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
require "rails/generators"
require "generator_spec"
require "generators/ember/heroku/heroku_generator"

describe EmberCli::HerokuGenerator, type: :generator do
destination Rails.root.join("tmp", "generator_test_output")

before :all do
prepare_destination
FileUtils.touch(destination_root.join("Gemfile"))
end

context "without yarn enabled" do
it "does not generate a root-level yarn.lock" do
EmberCli.configure do |c|
c.app "my-app", yarn: false
end

run_generator

expect(destination_root).to have_structure {
no_file "yarn.lock"
}
end
end

context "with yarn enabled" do
it "generates a root-level yarn.lock" do
EmberCli.configure do |c|
c.app "my-app", yarn: true
end

run_generator

expect(destination_root).to have_structure {
file "yarn.lock"
}
end
end
end
22 changes: 22 additions & 0 deletions spec/lib/ember_cli/app_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,28 @@
end
end

describe "yarn_enabled?" do
context "when configured with yarn: true" do
it "returns true" do
app = EmberCli::App.new("with-yarn", yarn: true)

yarn_enabled = app.yarn_enabled?

expect(yarn_enabled).to be true
end
end

context "when configured with yarn: false" do
it "returns false" do
app = EmberCli::App.new("without-yarn", yarn: false)

yarn_enabled = app.yarn_enabled?

expect(yarn_enabled).to be false
end
end
end

describe "#compile" do
it "exits with exit status of 0" do
passed = EmberCli["my-app"].compile
Expand Down

0 comments on commit 5ed3bc7

Please sign in to comment.