diff --git a/packages/compat/src/compat-adapters/ember-get-config.ts b/packages/compat/src/compat-adapters/ember-get-config.ts new file mode 100644 index 000000000..d9f47d715 --- /dev/null +++ b/packages/compat/src/compat-adapters/ember-get-config.ts @@ -0,0 +1,29 @@ +import V1Addon from '../v1-addon'; +import writeFile from 'broccoli-file-creator'; +import { join } from 'path'; + +function createIndexContents(config: any): string { + return `export default ${JSON.stringify(config)};`; +} + +/** + * The `ember-get-config` addon conceptually does just one thing: re-exports the `config/environment` runtime module + * from the host app so that addons can import it themseles. It handles the "hard part" of knowing what the host app's + * module name is, since that's not something an addon can normally know ahead of time. + * + * From a dependency graph perspective though, declaring all of the dependencies correctly would require a circular + * dependency from the addon back to the host app itself, which we don't want to introduce. + * + * We need to basically re-implement the entire addon's behavior so that it still exports the app's + * `config/environment` runtime value, but without needing it to actually export from the host app's module. + */ +export default class extends V1Addon { + get v2Tree() { + const configModulePath = join(this.app.root, 'config/environment.js'); + // eslint-disable-next-line @typescript-eslint/no-require-imports + const configModule = require(configModulePath); + const appEnvironmentConfig = configModule(this.app.env); + + return writeFile('index.js', createIndexContents(appEnvironmentConfig)); + } +} diff --git a/packages/compat/src/v1-addon.ts b/packages/compat/src/v1-addon.ts index 75eae5ef8..51113bf37 100644 --- a/packages/compat/src/v1-addon.ts +++ b/packages/compat/src/v1-addon.ts @@ -113,7 +113,7 @@ export default class V1Addon { constructor( protected addonInstance: any, protected addonOptions: Required, - private app: V1App, + protected app: V1App, private packageCache: PackageCache, private orderIdx: number ) {