From 44f8fdf433db6fad5e8ef125a017653bf8ca7fc8 Mon Sep 17 00:00:00 2001 From: Jose Luis Represa Date: Tue, 8 Jun 2021 13:36:05 +0200 Subject: [PATCH 1/2] feat(config): move workbox config from environment to ember-cli-build BREAKING CHANGE: workbox config has been moved to ember-cli-build.js --- addon/instance-initializers/sw.js | 2 +- ember-cli-build.js | 6 +++++- index.js | 10 ++++++++-- tests/acceptance/configuration-test.js | 19 +++++++++++++++++++ tests/dummy/config/environment.js | 3 --- 5 files changed, 33 insertions(+), 7 deletions(-) create mode 100755 tests/acceptance/configuration-test.js diff --git a/addon/instance-initializers/sw.js b/addon/instance-initializers/sw.js index a3ddb32..320370f 100644 --- a/addon/instance-initializers/sw.js +++ b/addon/instance-initializers/sw.js @@ -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) }; } diff --git a/ember-cli-build.js b/ember-cli-build.js index 6aa5913..fea509d 100644 --- a/ember-cli-build.js +++ b/ember-cli-build.js @@ -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. diff --git a/index.js b/index.js index 117edea..63007de 100644 --- a/index.js +++ b/index.js @@ -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'; @@ -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) { diff --git a/tests/acceptance/configuration-test.js b/tests/acceptance/configuration-test.js new file mode 100755 index 0000000..a9d4b5e --- /dev/null +++ b/tests/acceptance/configuration-test.js @@ -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'); + }); +}); + diff --git a/tests/dummy/config/environment.js b/tests/dummy/config/environment.js index 132b8ea..0380b60 100755 --- a/tests/dummy/config/environment.js +++ b/tests/dummy/config/environment.js @@ -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 From b4ad1aad14a7b40164b5e1724f56e78f546b1eac Mon Sep 17 00:00:00 2001 From: Jose Luis Represa Date: Tue, 8 Jun 2021 13:38:53 +0200 Subject: [PATCH 2/2] docs: update workbox config --- README.md | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/README.md b/README.md index d4d4a43..64c13c3 100644 --- a/README.md +++ b/README.md @@ -67,21 +67,23 @@ const app = new EmberAddon(defaults, { You can further customize ember-cli-workbox by setting **workbox configurations** in your `config/environment.js` on in your `ember-cli-build.js` -*Note*: `importScriptsTransform` must be defined in your `ember-cli-build.js`. +*Note*: `importScriptsTransform` and `workbox` must be defined in your `ember-cli-build.js`. ```javascript -//app/config/environment.js +//ember-cli-build.js -ENV['workbox'] = { - globPatterns: [ - '**\/*.{html,js,css}' - ], +const app = new EmberAddon(defaults, { + workbox: { + globPatterns: [ + '**\/*.{html,js,css}' + ], - globDirectory: './', + globDirectory: './', - globIgnores: [], - // ... -}; + globIgnores: [], + // ... + } +}); ``` | Property | Description |