-
Notifications
You must be signed in to change notification settings - Fork 204
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add locking feature to prevent stale code #25
Changes from all commits
964ae7d
38abcaf
ad1b21d
605dbd7
0ff1dfe
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -58,18 +58,13 @@ EmberCLI.configure do |c| | |
end | ||
``` | ||
|
||
Once you've updated your initializer to taste, you need to tell EmberCLI that | ||
you want the meta tag to be served in your javascript. Open up your | ||
`Brocfile.js` inside your EmberCLI app and add `{storeConfigInMeta: false}`. | ||
Once you've updated your initializer to taste, you need to install the | ||
[ember-cli-rails-addon](https://github.com/rondale-sc/ember-cli-rails-addon). | ||
|
||
It should look something like this (if you've left it unchanged): | ||
For each of your EmberCLI applications install the addon with: | ||
|
||
```javascript | ||
var EmberApp = require('ember-cli/lib/broccoli/ember-app'); | ||
|
||
var app = new EmberApp({storeConfigInMeta: false}); | ||
|
||
// etc... | ||
```sh | ||
npm install --save-dev [email protected] | ||
``` | ||
|
||
And that's it! | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,9 @@ | ||
require "timeout" | ||
|
||
module EmberCLI | ||
class App | ||
ADDON_VERSION = "0.0.3" | ||
|
||
attr_reader :name, :options, :pid | ||
|
||
def initialize(name, options={}) | ||
|
@@ -32,20 +36,76 @@ def exposed_css_assets | |
%W[#{name}/vendor #{name}/#{ember_app_name}] | ||
end | ||
|
||
def wait | ||
Timeout.timeout(build_timeout) do | ||
sleep 0.1 while lockfile.exist? | ||
end | ||
rescue Timeout::Error | ||
suggested_timeout = build_timeout + 5 | ||
|
||
warn <<-MSG.strip_heredoc | ||
============================= WARNING! ============================= | ||
|
||
Seems like Ember #{name} application takes more than #{build_timeout} | ||
seconds to compile. | ||
|
||
To prevent race conditions consider adjusting build timeout | ||
configuration in your ember initializer: | ||
|
||
EmberCLI.configure do |config| | ||
config.build_timeout = #{suggested_timeout} # in seconds | ||
end | ||
|
||
Alternatively, you can set build timeout per application like this: | ||
|
||
EmberCLI.configure do |config| | ||
config.app :#{name}, build_timeout: #{suggested_timeout} | ||
end | ||
|
||
============================= WARNING! ============================= | ||
MSG | ||
end | ||
|
||
private | ||
|
||
delegate :ember_path, to: :configuration | ||
delegate :tee_path, to: :configuration | ||
delegate :configuration, to: :EmberCLI | ||
|
||
def build_timeout | ||
options.fetch(:build_timeout){ configuration.build_timeout } | ||
end | ||
|
||
def lockfile | ||
app_path.join("tmp", "build.lock") | ||
end | ||
|
||
def prepare | ||
@prepared ||= begin | ||
check_addon! | ||
FileUtils.touch lockfile | ||
symlink_to_assets_root | ||
add_assets_to_precompile_list | ||
true | ||
end | ||
end | ||
|
||
def check_addon! | ||
dependencies = package_json.fetch("devDependencies", {}) | ||
|
||
unless dependencies["ember-cli-rails-addon"] == ADDON_VERSION | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We also need to check for EmberCLI version. It must be greater than 1.3.0 in order to have the preBuild hook that the addon needs. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I am unsure that you should care too much about this here. You can make the addon check the required version |
||
fail <<-MSG.strip_heredoc | ||
EmberCLI Rails requires your Ember app to have an addon. | ||
|
||
Please run: | ||
|
||
$ npm install --save-dev ember-cli-rails-addon@#{ADDON_VERSION}` | ||
|
||
in you Ember application root: #{app_path} | ||
MSG | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. These heredocs are great! |
||
end | ||
end | ||
|
||
def symlink_to_assets_root | ||
symlink_path = dist_path.join("assets") | ||
assets_path.join(name).make_symlink symlink_path unless symlink_path.exist? | ||
|
@@ -65,9 +125,7 @@ def log_pipe | |
end | ||
|
||
def ember_app_name | ||
@ember_app_name ||= options.fetch(:name) do | ||
JSON.parse(app_path.join("package.json").read).fetch("name") | ||
end | ||
@ember_app_name ||= options.fetch(:name){ package_json.fetch(:name) } | ||
end | ||
|
||
def app_path | ||
|
@@ -92,5 +150,9 @@ def assets_path | |
def environment | ||
Helpers.non_production?? "development" : "production" | ||
end | ||
|
||
def package_json | ||
@package_json ||= JSON.parse(app_path.join("package.json").read).with_indifferent_access | ||
end | ||
end | ||
end |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
module EmberCLI | ||
class Middleware | ||
def initialize(app) | ||
@app = app | ||
end | ||
|
||
def call(env) | ||
enable_ember_cli | ||
EmberCLI.wait! | ||
|
||
@app.call(env) | ||
end | ||
|
||
private | ||
|
||
def enable_ember_cli | ||
@enabled ||= begin | ||
if Rails.env.development? | ||
EmberCLI.run! | ||
else | ||
EmberCLI.compile! | ||
end | ||
|
||
true | ||
end | ||
end | ||
end | ||
end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we want to lock to the specific version in the README (just requires work to keep updated when otherwise this project doesn't necessarily need to change).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the concern is that if we make changes to ember-cli-rails-addon it shouldn't break existing installations of ember-cli-rails (the gem).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The addon is not paired with a specific version of ember-cli-rails, so I am not sure how you could break things. Either way is totally good with me, was just an observation.