diff --git a/.eslintrc.js b/.eslintrc.js index 760ce7b..aec49d1 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -1,7 +1,7 @@ module.exports = { root: true, parserOptions: { - ecmaVersion: 2017 + ecmaVersion: 2019 }, env: { node: true, diff --git a/lib/utils/get-module-path-for.js b/lib/utils/get-module-path-for.js index dc14fa1..149e720 100644 --- a/lib/utils/get-module-path-for.js +++ b/lib/utils/get-module-path-for.js @@ -18,12 +18,37 @@ for (let packagePath of packagePaths) { let packageDir = path.dirname(path.resolve(cwd, packagePath)); if (pkg.keywords && pkg.keywords.includes('ember-addon')) { - ADDON_PATHS[packageDir] = pkg.name; + // build addon instance + ADDON_PATHS[packageDir] = getAddonPackageName(packagePath); } else if (isEmberCliProject(pkg)) { APP_PATHS[packageDir] = pkg.name; } } +/** + * takes a package path and returns the runtime name of the addon. + * + * @param {String} packagePath the path on disk (from current working directory) + * @returns {String} The runtime name of the addon + */ +function getAddonPackageName(packagePath) { + const pkg = require(packagePath); + const entryPoint = + pkg['ember-addon'] && pkg['ember-addon'].main ? pkg['ember-addon'].main : 'index.js'; + + let moduleName = pkg.name; + try { + let entryModule = require(path.join(packagePath, entryPoint)); + if (typeof entryModule.moduleName === 'function') { + moduleName = entryModule.moduleName(); + } + } catch { + // do nothing, this falls back to using package name + } + + return moduleName; +} + function isEmberCliProject(pkg) { return ( pkg &&