diff --git a/lib/index.js b/lib/index.js index 12f0038..3b2e06a 100644 --- a/lib/index.js +++ b/lib/index.js @@ -1,3 +1,19 @@ +// Support old versions of Ember CLI. +function findHost() { + var current = this; + var app; + + // Keep iterating upward until we don't have a grandparent. + // Has to do this grandparent check because at some point we hit the project. + // Stop at lazy engine boundaries. + do { + if (current.lazyLoading === true) { return current; } + app = current.app || app; + } while (current.parent && current.parent.parent && (current = current.parent)); + + return app; +} + module.exports = { name: 'ember-browserify', @@ -12,11 +28,7 @@ module.exports = { newImportApi = true; } - // Stop-gap measure to support another addon - // consuming this addon. https://github.com/ef4/ember-browserify/issues/29 - if (typeof app.import !== 'function' && app.app) { - app = app.app; - } + app = findHost.call(this); var enableSourcemaps = app.options.sourcemaps && app.options.sourcemaps.enabled && app.options.sourcemaps.extensions.indexOf('js') > -1;