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 [tricknotes#538].
Related to [tricknotes#297].

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

[tricknotes#538]: tricknotes#538
[tricknotes#297]: tricknotes#297
  • Loading branch information
seanpdoyle committed Jul 28, 2017
1 parent c11588e commit ca36543
Show file tree
Hide file tree
Showing 10 changed files with 107 additions and 6 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
11 changes: 8 additions & 3 deletions lib/ember_cli.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,19 @@ def app(name)
fail KeyError, "#{name.inspect} app is not defined"
end
end
alias_method :[], :app

def apps
configuration.apps
end

def build(name)
app(name).build
end

alias_method :[], :app
def any?(*arguments, &block)
apps.values.any?(*arguments, &block)
end

def skip?
ENV["SKIP_EMBER"].present?
Expand All @@ -53,8 +60,6 @@ def env
@env ||= Helpers.current_environment
end

delegate :apps, to: :configuration

private

def cleanup!
Expand Down
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
5 changes: 2 additions & 3 deletions lib/generators/ember/heroku/USAGE
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,8 @@ Description:
Once the generator is complete, execute the following:

$ heroku buildpacks:clear
$ heroku buildpacks:add --index 1 https://github.com/heroku/heroku-buildpack-nodejs
$ heroku buildpacks:add --index 2 https://github.com/heroku/heroku-buildpack-ruby
$ heroku config:set NPM_CONFIG_PRODUCTION=false
$ heroku buildpacks:add --index 1 heroku/nodejs
$ heroku buildpacks:add --index 2 heroku/ruby
$ heroku config:unset SKIP_EMBER

Example:
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.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 @@

43 changes: 43 additions & 0 deletions spec/generators/ember/heroku/heroku_generator_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
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")

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

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 { |c| c.app "my-app", yarn: true }
setup_destination

run_generator

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

def setup_destination
prepare_destination

create_empty_gemfile_for_bundler
end

def create_empty_gemfile_for_bundler
FileUtils.touch(destination_root.join("Gemfile"))
end
end
14 changes: 14 additions & 0 deletions spec/lib/ember-cli-rails_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
describe EmberCli do
describe ".any?" do
it "delegates to the collection of applications" do
allow(EmberCli).to receive(:apps).and_return(
with_foo: { foo: true },
witout_foo: { foo: false },
)

any_with_foo = EmberCli.any? { |options| options.fetch(:foo) }

expect(any_with_foo).to be true
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 ca36543

Please sign in to comment.