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

Use require to retrieve the app's config #45

Merged
merged 4 commits into from
Jun 28, 2022
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
1 change: 1 addition & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ module.exports = {
'./testem.js',
'./blueprints/*/index.js',
'./config/**/*.js',
'./lib/**/*.js',
'./tests/dummy/config/**/*.js',
],
parserOptions: {
Expand Down
1 change: 1 addition & 0 deletions .npmignore
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
/CONTRIBUTING.md
/ember-cli-build.js
/testem.js
/lib/baz/
/tests/
/yarn-error.log
/yarn.lock
Expand Down
8 changes: 3 additions & 5 deletions addon/index.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
import { getOwnConfig, importSync } from '@embroider/macros';
/* global require */
import { getOwnConfig } from '@embroider/macros';

let configModulePath = `${getOwnConfig().modulePrefix}/config/environment`;

let config = importSync(configModulePath);

// fix problem with fastboot config being wrapped in a second "default" object
export default config.default?.default ?? config.default;
export default require(configModulePath).default;
5 changes: 5 additions & 0 deletions ember-cli-build.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,11 @@ module.exports = function (defaults) {

const { maybeEmbroider } = require('@embroider/test-setup');
return maybeEmbroider(app, {
compatAdapters: new Map(
Object.entries({
'ember-get-config': null,
})
),
skipBabel: [
{
package: 'qunit',
Expand Down
7 changes: 7 additions & 0 deletions lib/baz/config/environment.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
'use strict';

module.exports = function (/* environment, appConfig */) {
return {
baz: 'qux',
};
};
9 changes: 9 additions & 0 deletions lib/baz/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
'use strict';

module.exports = {
name: require('./package').name,

isDevelopingAddon() {
return true;
},
};
6 changes: 6 additions & 0 deletions lib/baz/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"name": "baz",
"keywords": [
"ember-addon"
]
}
5 changes: 4 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,9 @@
"edition": "octane"
},
"ember-addon": {
"configPath": "tests/dummy/config"
"configPath": "tests/dummy/config",
"paths": [
"lib/baz"
]
}
}
6 changes: 6 additions & 0 deletions tests/acceptance/ember-get-config-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,10 @@ module('Acceptance | ember get config', function (hooks) {

assert.equal(find('#foo').innerText.trim(), 'bar', 'text correct');
});

test('it includes config from addons', async function (assert) {
await visit('/');

assert.dom('#baz').hasText('qux');
});
});
1 change: 1 addition & 0 deletions tests/dummy/app/controllers/application.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,6 @@ import Controller from '@ember/controller';
import config from 'ember-get-config';

export default Controller.extend({
baz: config.baz,
foo: config.foo,
});
1 change: 1 addition & 0 deletions tests/dummy/app/templates/application.hbs
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
<div id="baz">{{this.baz}}</div>
<div id="foo">{{this.foo}}</div>
2 changes: 1 addition & 1 deletion tests/fastboot/basic-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@ module('FastBoot | basic', function (hooks) {
test('it renders a page...', async function (assert) {
let { htmlDocument } = await visit('/');

assert.dom('body', htmlDocument).hasText('bar');
assert.dom('body', htmlDocument).hasText('qux bar');
});
});
5 changes: 5 additions & 0 deletions tests/unit/ember-get-config-test.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import configApp from 'dummy/config/environment';
import config from 'ember-get-config';
import { module, test } from 'qunit';

Expand All @@ -6,3 +7,7 @@ module('ember-get-config');
test('it exports the app config file', function (assert) {
assert.equal(config.environment, 'test');
});

test("it exports a reference to the app's config", function (assert) {
assert.equal(config, configApp);
});