Skip to content

Commit

Permalink
Merge pull request #45 from Windvis/require-rework
Browse files Browse the repository at this point in the history
Use `require` to retrieve the app's config
  • Loading branch information
mansona authored Jun 28, 2022
2 parents 73c2592 + 5493d11 commit 7d8dbf3
Show file tree
Hide file tree
Showing 13 changed files with 50 additions and 7 deletions.
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);
});

0 comments on commit 7d8dbf3

Please sign in to comment.