Skip to content
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

Use latest visit API #71

Merged
merged 3 commits into from
Oct 16, 2015
Merged

Conversation

chancancode
Copy link
Contributor

Update fastboot server for emberjs/ember.js#12394

Require coordination from ember-fastboot/fastboot#2

  • Take advantage of the new API
  • FastFail™
  • Don't mutate autoBoot
  • Remove FastBoot global
  • Better integration with Ember CLI
  • Move most of the work out of initializers
  • Test that it works
  • Write tests

Open question:

  • What are the rules regarding passing complex objects across the sandbox boundary? It would not be hard to avoid that if we have to.

cc @tomdale @stefanpenner

autoRun: false,
storeConfigInMeta: false,
EmberENV: {
FEATURES: { 'ember-application-visit': true }
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I initially avoided doing this because feature flags were not being merged. Which meant that if you had a feature flag set in the consuming apps config/environment.js it would completely ignore any features added from an addon's config hook.

This may be fixed now with current ember-cli, but I'd love it if you could confirm. The easiest way to test would be to make a throw away app, set some features in it, run ember fastboot and confirm that the values are merged propertly in the resulting files...

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, from what I read, the whole thing is deep merged with lodash. I will confirm!

'initializers/server/*',
'instance-initializers/server/*'
]
});
}
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@rwjblue @stefanpenner how does that look? with this I could complete remove the FastBoot global we inject into the sandbox.

By the way, if this works out for us, we might want to move it into the preprocessTree hook so that apps and other addons can use the same pattern

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 - This looks great to me!


I don't see a way to completely generalize this, but we can chat about that further in a separate issue...

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wouldn't it just work if we move this code to preprocessTreeFor? Any initializers in with a browser/... prefix will be stripped for server builds and vice versa. Maybe I am understanding it incorrectly – does preprocessTreeFor not get the fully merged app tree with user code and addon code all merged together?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@chancancode - Ya, we could come up with something that could work (I misread initially as postprocessTree not preprocessTree). I'm happy to come up with a specific layout/plan to make it a standard thing.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll leave that for another time, probably until someone asks for it :P (if you are reading this, you might just want to PR it 😉)

@chancancode
Copy link
Contributor Author

Got the existing tests passing today with some minor fixes! I'll clean it up tomorrow!

included: function(app) {
app.options.autoRun = false;
app.options.storeConfigInMeta = false;
},
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@rwjblue turns out removing this is not as easy as I thought – contrary to the documentation (see "Uses"), these options can't actually be set through the config hook :( (It makes sense, mutating these build options at a random time during build probably has the same problem as setting autoboot during boot 😉)

@stefanpenner can you c/d? If that's true I can (eventually) send a doc PR

@chancancode chancancode force-pushed the new-visit-api branch 4 times, most recently from aed139c to ba48f6d Compare October 14, 2015 09:06
Most of the heavy lifting (runtime stuff) has been moved to
`ember-fastboot-server`. This addon is currently now only responsbile for
building this right app bundle for the fastboot server to consume.

The main integration point between the fastboot server and the app
bundle is the injected `~fastboot/app-factory` module. This allows the
server to create an `Application` instance (not to be confused with an
`ApplicationInstance` instance ...:trollface:) without having to
discover the app name and the app config.

This commit also introduced a convention within the addon: all
(instance) initializers within the `browser` directory will be excluded
from the fastboot app bundle; conversely, the (instance) initializers
contained within the `server` bundle will be removed from the regular
build.
@chancancode chancancode force-pushed the new-visit-api branch 2 times, most recently from 3fa9f78 to e2a8953 Compare October 14, 2015 10:18
chancancode added a commit to chancancode/ember-fastboot-server that referenced this pull request Oct 14, 2015
This commit has an implicit cross-dependency on ember-fastboot/ember-cli-fastboot#71.

This commit takes advantage of the new visit API in Ember and moves
most of the heavy-lifting (runtime stuff) into the server.
@chancancode chancancode changed the title [WIP] Use latest visit API Use latest visit API Oct 14, 2015
We are producing different content for the server vs browser app bundle
(e.g. the server one has `autoRun` and `autoboot` disabled), so we need
to serve the browser version with `--serve-assets`, otherwise the app
won't boot in the browser.

The `--assets-path` is somewhat of a quick fix. We should probably run
the build process twice and store them in the same location but with a
different suffix, like `dummy.fastboot.js` and `index.fastboot.html`.
@chancancode
Copy link
Contributor Author

Tests are green, fixed all the problems, backfilled the commit messages, did some smoke tests 😬

@tomdale @rwjblue final review?

If this looks okay to you, we should probably first merge ember-fastboot/fastboot#2, release 0.1.0, then update the last commit to use the released version before merging.

@@ -36,7 +37,10 @@ module.exports = function runServer(callback, options) {
args.push(commandOptions);

return new RSVP.Promise(function(resolve, reject) {
runCommand.apply(null, args)
runCommand.call(null, emberCommand, 'build') // build 'dist'
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So this reflects a real-world problem: you need to now run ember build (probably ember build -prod) before you run ember fastboot --serve-assets, because we need to serve the browser builds from dist. (See the commit message for details)

Unfortunately, it is not easy to refactor the set up to produce both builds in a single command (it relies on a global ENV variable, among other things).

So I just added a new assets-path option for now, but we should revisit this in the future.

@tomdale
Copy link
Contributor

tomdale commented Oct 16, 2015

Released 0.1.0 of ember-fastboot-server, I will merge this and update the dependency.

tomdale added a commit that referenced this pull request Oct 16, 2015
@tomdale tomdale merged commit 9573c31 into ember-fastboot:master Oct 16, 2015
arjansingh pushed a commit to arjansingh/ember-cli-fastboot that referenced this pull request Oct 29, 2016
Only access instance.getURL if the instance has booted
xg-wang pushed a commit to xg-wang/ember-cli-fastboot that referenced this pull request Nov 16, 2020
…mocha-5.0.0

Update mocha to the latest version 🚀
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants