Skip to content
This repository has been archived by the owner on Dec 5, 2017. It is now read-only.

Use Ember CLI's ENV import #21

Closed
marcemira opened this issue Sep 23, 2014 · 3 comments
Closed

Use Ember CLI's ENV import #21

marcemira opened this issue Sep 23, 2014 · 3 comments
Assignees

Comments

@marcemira
Copy link

Use new ENV import on every module should do it.

@marcoow
Copy link
Member

marcoow commented Sep 29, 2014

This should definitely be done soon as using window.ENV was never really so great in Ember CLI (yet Ember Simple Auth itself still has to support to in order for the browserified and the plain AMD distributions to work). I'm not really sure how to best approach this yet though. torii uses a solution where they modify the library's source in the treeFor method to replace window.env with require("'+this.app.name+'/config/environment") but that won't work for Ember Simple Auth as Ember Simple Auth ads the bower library to the app's bower.json in a generator and never generates the tree for it itself.

A different solution would be to have a special initializer for the Ember CLI Addon that doesn't load the configuration from window.ENV but imports it via import ENV from '<appName>/config/environment';. However, I'm not sure how <appName> would be resolved here or whether it's actually necessary. That initializer could probably also be modified similar to tori's solution as described above. Also this solution means quite some duplication as currently the initializer in the addon is just

import initializer from 'simple-auth/initializer';

export default initializer;

whereas with the solution as described above it would have to duplicate the code that's in the library's initializer:

import setup from './setup';
import ENV from '<appName>/config/environment';`

export default {
  name:       'simple-auth',
  initialize: function(container, application) {
    Configuration.load(container, ENV['simple-auth'] || {});
    setup(container, application);
  }
};

Would be great to get some input here from the Ember CLI team (ping @rwjblue, @stefanpenner).

@rwjblue
Copy link

rwjblue commented Sep 29, 2014

If you return an initializer in the app tree, you do not need to know the application name:

import ENV from '../config/environment';`

To avoid internals knowledge you could update your setup function to accept the optional config as a third argument.

@marcoow
Copy link
Member

marcoow commented Sep 29, 2014

@rwjblue: thanks, wasn't aware of that!

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants