Search code examples
ember.jsember-cli

Ember app use addon installed as transitive dependency


Can an Ember app use an addon that is installed as a transitive dependency? I have a local Ember addon that lists ember-angle-bracket-invocation-polyfill as a dependency in package.json. When I install the addon into an Ember app using ember install path/to/addon, I'm unable to use ember-angle-bracket-invocation-polyfill. Any help is appreciated!


Solution

  • An addon could add dependencies as part of it's installation process. This is usually done in the default blueprint. The default blueprint is a blueprint having the exact same name as the addon. It's automatically run after addon installation by ember-cli. This is the main reason why addons should be installed by ember install <addon-name> and not only by adding it as a dependency using npm or yarn.

    Ember-cli provides different methods to add a dependency depending on it's type. As ember-angle-bracket-invocation-polyfill is an ember addon, addAddonsToProject() should be used for your case. It expects an object having a array with addon names under packages key.

    For your example the blueprint would look like:

    // blueprints/your-addon-name/index.js
    module.exports = {
      normalizeEntityName() {}, // no-op since we're just adding dependencies
    
      afterInstall() {
        // Add addons to package.json and run defaultBlueprint
        return this.addAddonsToProject({
          // a packages array defines the addons to install
          packages: [
            // name is the addon name, and target (optional) is the version
            {name: 'ember-angle-bracket-invocation-polyfill'}
          ]
        });
      }
    };
    

    More information Working with dependencies chapter of ember-cli docs.