Can an addon blacklist itself?

Ember CLI has an API that lets host apps blacklist addons. I’m wondering if Addons have the ability to do this themselves, in certain environments?

The motivation for this is say I’m writing an addon used for testing purposes. I want my addon to run in dev and test, but I never want it to affect the production build. I could be diligent about all the code I write in index.js hooks and ensure nothing happens, but the “safest” way seems to be to blacklist it in the production environment altogether.

The host app can do this but it would be nice if the addon itself could be responsible for excluding itself in prod. Is it possible?

2 Likes

There is an addon.isEnabled hook (TIL). I personally haven’t tried it, but stepping through the ember-cli source it might be useful for this.

https://github.com/ember-cli/ember-cli/blob/master/lib/models/addon.js#L1482

https://github.com/ember-cli/ember-cli/blob/f194d52232739dd3d6a4184b3cab8ceac791476f/lib/broccoli/ember-app.js#L536

https://github.com/ember-cli/ember-cli/blob/f194d52232739dd3d6a4184b3cab8ceac791476f/lib/broccoli/ember-app.js#L595-L601

2 Likes

Ya, generally isEnabled hook is the right thing for this.