vendredi 26 mai 2017

Why does an ember addon using a bower dependency needs to override normalizeEntityName?

You are developing an ember add-on that internally needs a bower package. When you install this add-on in an ember project, you need the bower package to be added to the project's bower dependencies so that your add-on can run.

Ok - easy enough, we just need a default blueprint and a call to afterInstall

module.exports = {
  normalizeEntityName: function() {}, // no-op since we're just adding dependencies

  afterInstall: function() {
    return this.addBowerPackageToProject('a-bower-package');
  }
};

Why is the override to normalizeEntityName necessary? At first I had missed adding this to my blueprint, and spent an ungodly amount of time trying to pinpoint why it was not installing the bower dependency as I was expecting.

I haven't seen a satisfactory answer anywhere, the ember-cli guide explanation doesn't address this and the closest resource I have found was this article, where all it says about the subject is this:

The hero we all need, even if the reason we deserve it can be a bit opaque, normalizeEntityName needs to be overridden as a noop inside of the default blueprint in order for ember g your-addon-name to even work. Just set this as the first property of your exported object, and forget all about it (but never forget it in the future 😀):

So... why do we need it?




Aucun commentaire:

Enregistrer un commentaire