Skip to content

Commit

Permalink
feat(config): move workbox config from environment to ember-cli-build
Browse files Browse the repository at this point in the history
BREAKING CHANGE: workbox config has been moved to ember-cli-build.js
  • Loading branch information
next-joserepresa committed Jun 8, 2021
1 parent ba9de62 commit 44f8fdf
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 7 deletions.
2 changes: 1 addition & 1 deletion addon/instance-initializers/sw.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export function getConfig(appInstance) {
return {
isEnabled: getWithDefault(config, 'ember-cli-workbox.enabled', isProdBuild),
debugAddon: getWithDefault(config, 'ember-cli-workbox.debug', !isProdBuild),
swDestFile: getWithDefault(config, 'workbox.swDest', 'sw.js'),
swDestFile: getWithDefault(config, 'ember-cli-workbox.swDest', 'sw.js'),
autoRegister: getWithDefault(config, 'ember-cli-workbox.autoRegister', true)
};
}
Expand Down
6 changes: 5 additions & 1 deletion ember-cli-build.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,11 @@
const EmberAddon = require('ember-cli/lib/broccoli/ember-addon');

module.exports = function(defaults) {
const app = new EmberAddon(defaults, {});
const app = new EmberAddon(defaults, {
workbox: {
swDest: 'sw.js'
}
});

// Use `app.import` to add additional libraries to the generated
// output files.
Expand Down
10 changes: 8 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,9 @@ module.exports = {
isDevelopingAddon: () => true,

config(env, baseConfig) {
const workboxOptions = baseConfig.workbox || {};
const options = baseConfig['ember-cli-workbox'] || {};
const workboxOptions = this.app.options.workbox || {};
const emberCliWorkboxOptions = baseConfig['ember-cli-workbox'];
const options = emberCliWorkboxOptions || {};
const appOptions = this.app.options['ember-cli-workbox'] || {};
const projectName = baseConfig.APP && baseConfig.APP.name || 'app';

Expand Down Expand Up @@ -43,6 +44,11 @@ module.exports = {

this._options = options;
this.workboxOptions = workboxOptions;

// Append "workbox" config to "ember-cli-workbox" config
if (emberCliWorkboxOptions) {
emberCliWorkboxOptions.swDest = workboxOptions.swDest;
}
},

postprocessTree(type, tree) {
Expand Down
19 changes: 19 additions & 0 deletions tests/acceptance/configuration-test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import { module, test } from 'qunit';
import { setupApplicationTest } from 'ember-qunit';

module('Acceptance | Simple Acceptance Test', (hooks) => {
setupApplicationTest(hooks);

test('"workbox" configuration is not in environment config', async function(assert) {
const config = this.owner.resolveRegistration('config:environment');

assert.notOk(config.workbox);
});

test('"workbox" configuration is setted in "ember-cli-workbox" config object', async function(assert) {
const config = this.owner.resolveRegistration('config:environment');

assert.equal(config['ember-cli-workbox'].swDest, 'sw.js');
});
});

3 changes: 0 additions & 3 deletions tests/dummy/config/environment.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,6 @@ module.exports = function(environment) {
'ember-cli-workbox': {
enabled: true
},
workbox: {
swDest: 'sw.js'
},
EmberENV: {
FEATURES: {
// Here you can enable experimental features on an ember canary build
Expand Down

0 comments on commit 44f8fdf

Please sign in to comment.