diff --git a/.eslintrc.js b/.eslintrc.js index ab627f4..6138736 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -32,6 +32,7 @@ module.exports = { './testem.js', './blueprints/*/index.js', './config/**/*.js', + './lib/**/*.js', './tests/dummy/config/**/*.js', ], parserOptions: { diff --git a/.npmignore b/.npmignore index 399ddfe..402abbf 100644 --- a/.npmignore +++ b/.npmignore @@ -26,6 +26,7 @@ /CONTRIBUTING.md /ember-cli-build.js /testem.js +/lib/baz/ /tests/ /yarn-error.log /yarn.lock diff --git a/addon/index.js b/addon/index.js index 4310895..f9c78ee 100644 --- a/addon/index.js +++ b/addon/index.js @@ -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; diff --git a/ember-cli-build.js b/ember-cli-build.js index e211c63..9bd9615 100644 --- a/ember-cli-build.js +++ b/ember-cli-build.js @@ -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', diff --git a/lib/baz/config/environment.js b/lib/baz/config/environment.js new file mode 100644 index 0000000..3e6848f --- /dev/null +++ b/lib/baz/config/environment.js @@ -0,0 +1,7 @@ +'use strict'; + +module.exports = function (/* environment, appConfig */) { + return { + baz: 'qux', + }; +}; diff --git a/lib/baz/index.js b/lib/baz/index.js new file mode 100644 index 0000000..702881b --- /dev/null +++ b/lib/baz/index.js @@ -0,0 +1,9 @@ +'use strict'; + +module.exports = { + name: require('./package').name, + + isDevelopingAddon() { + return true; + }, +}; diff --git a/lib/baz/package.json b/lib/baz/package.json new file mode 100644 index 0000000..9a00405 --- /dev/null +++ b/lib/baz/package.json @@ -0,0 +1,6 @@ +{ + "name": "baz", + "keywords": [ + "ember-addon" + ] +} diff --git a/package.json b/package.json index 9ce93db..b34e742 100644 --- a/package.json +++ b/package.json @@ -79,6 +79,9 @@ "edition": "octane" }, "ember-addon": { - "configPath": "tests/dummy/config" + "configPath": "tests/dummy/config", + "paths": [ + "lib/baz" + ] } } diff --git a/tests/acceptance/ember-get-config-test.js b/tests/acceptance/ember-get-config-test.js index 668043d..e16de03 100644 --- a/tests/acceptance/ember-get-config-test.js +++ b/tests/acceptance/ember-get-config-test.js @@ -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'); + }); }); diff --git a/tests/dummy/app/controllers/application.js b/tests/dummy/app/controllers/application.js index 0477bbf..07deb0d 100644 --- a/tests/dummy/app/controllers/application.js +++ b/tests/dummy/app/controllers/application.js @@ -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, }); diff --git a/tests/dummy/app/templates/application.hbs b/tests/dummy/app/templates/application.hbs index 79d4a19..7a76c59 100644 --- a/tests/dummy/app/templates/application.hbs +++ b/tests/dummy/app/templates/application.hbs @@ -1 +1,2 @@ +
{{this.baz}}
{{this.foo}}
\ No newline at end of file diff --git a/tests/fastboot/basic-test.js b/tests/fastboot/basic-test.js index 429e9e2..a17e835 100644 --- a/tests/fastboot/basic-test.js +++ b/tests/fastboot/basic-test.js @@ -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'); }); }); diff --git a/tests/unit/ember-get-config-test.js b/tests/unit/ember-get-config-test.js index 1fc2421..1bf22bd 100644 --- a/tests/unit/ember-get-config-test.js +++ b/tests/unit/ember-get-config-test.js @@ -1,3 +1,4 @@ +import configApp from 'dummy/config/environment'; import config from 'ember-get-config'; import { module, test } from 'qunit'; @@ -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); +});