From 8a635996650c22ebe1e0e12960d46a7716d76c80 Mon Sep 17 00:00:00 2001 From: 2hu Date: Tue, 25 Jun 2019 12:28:25 +0800 Subject: [PATCH 1/2] Use the "app" argument if available The `app` argument passed to `included` is the host app or parent addon and the addon has a `import` api exposed since https://github.com/ember-cli/ember-cli/pull/5877. This PR does no changes to normal ember app but the app with a lazy engine which depend on `ember-highcharts` directly, it could distribute the `hightcharts` vendor to the `engine-vendor.js` instead of the `vendor.js` of the whole app so that other engines do not have to download the `hightcharts` vendor(also need other tricks like add the "ember-highcharts" to the `addons.blacklist` of the whole app option). --- index.js | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/index.js b/index.js index 58e911a..361ca55 100644 --- a/index.js +++ b/index.js @@ -17,22 +17,22 @@ module.exports = { } }, - included() { + included(app) { this._super.included.apply(this, arguments); - let app; - - // If the addon has the _findHost() method (in ember-cli >= 2.7.0), we'll just - // use that. - if (typeof this._findHost === 'function') { - app = this._findHost(); - } else { - // Otherwise, we'll use this implementation borrowed from the _findHost() - // method in ember-cli. - let current = this; - do { - app = current.app || app; - } while (current.parent.parent && (current = current.parent)); + if (typeof app.import !== 'function') { + // If the addon has the _findHost() method (in ember-cli >= 2.7.0), we'll just + // use that. + if (typeof this._findHost === 'function') { + app = this._findHost(); + } else { + // Otherwise, we'll use this implementation borrowed from the _findHost() + // method in ember-cli. + let current = this; + do { + app = current.app || app; + } while (current.parent.parent && (current = current.parent)); + } } let options = app.options.emberHighCharts || { includeHighCharts: true }; From 787d4b77c7dd2c637f08a4ce7a2d7153b286d308 Mon Sep 17 00:00:00 2001 From: 2hu Date: Wed, 26 Jun 2019 01:29:26 +0800 Subject: [PATCH 2/2] Add comment for "app.import" --- index.js | 3 +++ 1 file changed, 3 insertions(+) diff --git a/index.js b/index.js index 361ca55..b571f7b 100644 --- a/index.js +++ b/index.js @@ -20,6 +20,9 @@ module.exports = { included(app) { this._super.included.apply(this, arguments); + // The app argument passed to included is the host app or parent addon. + // And the addon has a `import` api exposed since ember-cli/ember-cli#5877. + // If the `app.import` is available we can just use that. if (typeof app.import !== 'function') { // If the addon has the _findHost() method (in ember-cli >= 2.7.0), we'll just // use that.