Skip to content

Commit

Permalink
feat: add compat adapter for ember-get-config
Browse files Browse the repository at this point in the history
  • Loading branch information
alexlafroscia committed Apr 21, 2021
1 parent 8b2c20d commit 1a1295b
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 1 deletion.
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,
public app: V1App,
private packageCache: PackageCache,
private orderIdx: number
) {
Expand Down

0 comments on commit 1a1295b

Please sign in to comment.