Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add compat adapter for ember-get-config #770

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions packages/compat/src/compat-adapters/ember-get-config.ts
Original file line number Diff line number Diff line change
@@ -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));
}
}
2 changes: 1 addition & 1 deletion packages/compat/src/v1-addon.ts
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ export default class V1Addon {
constructor(
protected addonInstance: any,
protected addonOptions: Required<Options>,
private app: V1App,
protected app: V1App,
private packageCache: PackageCache,
private orderIdx: number
) {
Expand Down