Skip to content

Comments

Expose API for fastboot addons to update fastboot manifest.#374

Merged
rwjblue merged 1 commit intoember-fastboot:masterfrom
kratiahuja:add-fastboot-assets-api
Apr 21, 2017
Merged

Expose API for fastboot addons to update fastboot manifest.#374
rwjblue merged 1 commit intoember-fastboot:masterfrom
kratiahuja:add-fastboot-assets-api

Conversation

@kratiahuja
Copy link
Contributor

@kratiahuja kratiahuja commented Apr 15, 2017

Motivation

Currently, FastBoot runs two ember builds to fork and build fastboot assets. When it runs the fastboot build it sets an environment variable process.env.EMBER_CLI_FASTBOOT to be true. At present a lot of addons are relying on this environment variable to append libraries into the fastboot assets (example ember-network).

Moreover another usecase is to allow addons like ember-engines to write and load additional assets in the FastBoot sandbox.

With #360, this environment variable will no longer be exposed or valid. Therefore, we want to expose an API from ember-cli-fastboot to allow other fastboot compatible addons to be able to provide paths under dist from where additional vendor or app specific assets should be loaded in sandbox. With addons being able to leverage this API when the build issue is resolved they will automatically become backward compatible.

How does it work

In order for an addon to load additional assets in the sandbox (in any order), they need to either update vendorFiles or appFiles key in the fastboot manifest. Therefore, they will define updateFastBootManifest hook in their index.js which takes in the manifest as input, updates the manifest and returns it back:

   updateFastBootManifest: function(manifest) {
      manifest.vendorFiles.unshift(<add some path>);
      manifest.appFiles.push(<add some path>);
     
     return manifest;
  }

An addon can decide to update the manifest enteries however they like. If the manifest key is not returned, the build will fail with an error message as : <addon name> did not return the updated manifest from updateFastBootManifest hook.

Example: See ember-fastboot-build-example addon for a simple example of how to load assets

TODO

  • Update README with instructions and example of how to use the new API
  • Update fastboot website with new API

cc: @rwjblue @tomdale @danmcclain @ryanone @tsubomii @arjansingh @simonihmig

@kratiahuja
Copy link
Contributor Author

Travis is failing due to unrelated ember-data issue

@kratiahuja
Copy link
Contributor Author

kratiahuja commented Apr 21, 2017

@rwjblue and I discussed over slack. We should also handle usecase where you may want to prepend to vendorFiles or appFiles and other such usecases.

updateFastBootManifest(manifest) {..}

you get manifest as input (which maybe an updated version from prev addon) and you update and return and at the end we write it back

Going to update this PR.

@kratiahuja
Copy link
Contributor Author

kratiahuja commented Apr 21, 2017

@rwjblue @simonihmig updated PR and description with the discussed changes. Also tested it with multiple addons to make sure ordering is maintained as well.

Please let me know your feedback.

@rwjblue rwjblue merged commit 42dee47 into ember-fastboot:master Apr 21, 2017
@kratiahuja
Copy link
Contributor Author

@rwjblue thank you! :)

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.

3 participants