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

Upgrade to 4.4 + minor fixes + add workbox-window (to "force" activate) #134

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
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
8 changes: 7 additions & 1 deletion .ember-cli
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,11 @@

Setting `disableAnalytics` to true will prevent any data from being sent.
*/
"disableAnalytics": false
"disableAnalytics": false,

/**
Setting `isTypeScriptProject` to true will force the blueprint generators to generate TypeScript
rather than JavaScript by default, when a TypeScript version of a given blueprint is available.
*/
"isTypeScriptProject": false
}
13 changes: 12 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,16 @@
name: CI
on: [push, pull_request]

on:
push:
branches:
- main
- master
pull_request: {}

concurrency:
group: ci-${{ github.head_ref || github.ref }}
cancel-in-progress: true

jobs:
test:
runs-on: ubuntu-latest
Expand Down
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,8 @@
/.node_modules.ember-try/
/bower.json.ember-try
/package.json.ember-try
/package-lock.json.ember-try
/yarn.lock.ember-try

# broccoli-debug
/DEBUG/
2 changes: 1 addition & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,4 @@
- `ember serve`
- Visit the dummy application at [http://localhost:4200](http://localhost:4200).

For more information on using ember-cli, visit [https://ember-cli.com/](https://ember-cli.com/).
For more information on using ember-cli, visit [https://cli.emberjs.com/release/](https://cli.emberjs.com/release/).
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ For more details on Workbox check out:

## Dependencies

"ember-cli-uglify": "^2.0.0",
"ember-cli-terser": "^2.0.0",
(previously ember-cli-uglify)

## Configuration

Expand Down
2 changes: 1 addition & 1 deletion addon/instance-initializers/sw.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ export function initialize(appInstance) {
swService.set('debug', debugAddon);

// first checks whether the browser supports service workers
if (swService.get('isSupported')) {
if (swService.isSupported) {
// Load and register pre-caching Service Worker
if (isEnabled) {
swService.register(swDestFile);
Expand Down
32 changes: 21 additions & 11 deletions addon/services/service-worker.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import Service from '@ember/service';
import Evented from '@ember/object/evented';
import { debug } from '@ember/debug';
import { getOwner } from '@ember/application';
import { Workbox } from 'workbox-window';

const EventedService = Service.extend(Evented);

Expand All @@ -22,6 +23,8 @@ const EventedService = Service.extend(Evented);
* "unregistrationComplete" - all sw are unregistered
*/
export default class ServiceWorker extends EventedService {
workbox;

get config() {
return getOwner(this).resolveRegistration('config:environment');
}
Expand All @@ -48,19 +51,26 @@ export default class ServiceWorker extends EventedService {
}
}

async register(swFile) {
try {
const registration = await this.sw.register(
`${this.config.rootURL}${swFile}`
);
forceActivate() {
if (this.wb) {
this.wb.messageSkipWaiting();
}
}

return this._onRegistration(registration);
} catch (error) {
this.trigger('error', error);
this._log('Service Worker registration failed: ', error);
async register(swFile) {
const swUrl = `${this.config.rootURL}${swFile}`;
this.wb = new Workbox(swUrl);

throw error;
}
return this.wb
.register()
.then((registration) => {
return this._onRegistration(registration);
})
.catch((error) => {
this.trigger('error', error);
this._log('Service Worker registration failed: ', error);
throw error;
});
}

/*
Expand Down
31 changes: 19 additions & 12 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,14 @@ module.exports = {
isDevelopingAddon: () => true,

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

workboxOptions = Object.assign(
const workboxOptions = Object.assign(
// Defaults
{
swDest: 'sw.js',
globDirectory: './',
Expand All @@ -27,34 +27,36 @@ module.exports = {
clientsClaim: false,
cacheId: projectName,
},
workboxOptions
// Options from environment config (workbox)
appWorkboxOptions
);

env = env || process.env.EMBER_ENV;

// Do nothing if no ENV. For example, when running an ember generator.
if (!env) {
if (!env && !process.env.EMBER_ENV) {
return;
}

const isProdBuild = Boolean(env.match('prod'));

options = Object.assign(
const options = Object.assign(
// Defaults
{
enabled: isProdBuild,
debug: !isProdBuild,
importScriptsGlobPatterns: ['assets/service-workers/*.js'],
},
options,
// Options from initial app config (ember-cli-workbox)
baseOptions,
// Options from environment config (ember-cli-workbox)
appOptions
);

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

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

Expand All @@ -63,11 +65,16 @@ module.exports = {
return tree;
}

// This 'all' tree has all the app's files and assets,
// which is exactly what we need for making a service worker using workbox

// Our BroccoliWorkbox plugin will generate the service worker for the given tree
const workboxFunnel = new BroccoliWorkbox([tree], {
options: this._options,
workboxOptions: this.workboxOptions,
});

// Add this BroccoliWorkbox tree to the app's tree
return mergeTrees([tree, workboxFunnel], {
overwrite: true,
});
Expand Down
33 changes: 17 additions & 16 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -55,48 +55,49 @@
"broccoli-plugin": "^4.0.7",
"chalk": "^4.1.0",
"debug": "^4.3.3",
"ember-auto-import": "^2.4.1",
"ember-cli-babel": "^7.26.11",
"ember-cli-htmlbars": "^6.0.1",
"glob": "^7.2.0",
"pretty-bytes": "^5.6.0",
"rimraf": "^3.0.1",
"workbox-build": "^5.0.0"
"workbox-build": "^6.5.4",
"workbox-window": "^6.5.4"
},
"devDependencies": {
"@commitlint/cli": "^16.1.0",
"@commitlint/config-conventional": "^16.0.0",
"@ember/optional-features": "^2.0.0",
"@ember/test-helpers": "^2.6.0",
"@embroider/test-setup": "^1.0.0",
"@glimmer/component": "^1.0.4",
"@glimmer/tracking": "^1.0.4",
"@ember/test-helpers": "^2.7.0",
"@embroider/test-setup": "^1.6.0",
"@glimmer/component": "^1.1.2",
"@glimmer/tracking": "^1.1.2",
"@semantic-release/changelog": "^6.0.1",
"@semantic-release/git": "^10.0.1",
"babel-eslint": "^10.1.0",
"broccoli-test-helpers": "0.0.9",
"chai": "^4.3.6",
"commitizen": "^4.2.4",
"cz-conventional-changelog": "^3.3.0",
"ember-auto-import": "^2.2.4",
"ember-cli": "~4.1.1",
"ember-cli": "~4.4.1",
"ember-cli-code-coverage": "^1.0.3",
"ember-cli-dependency-checker": "^3.2.0",
"ember-cli-dependency-checker": "^3.3.1",
"ember-cli-inject-live-reload": "^2.1.0",
"ember-cli-terser": "^4.0.2",
"ember-disable-prototype-extensions": "^1.1.3",
"ember-engines": "^0.8.20",
"ember-export-application-global": "^2.0.1",
"ember-page-title": "^7.0.0",
"ember-qunit": "^5.1.5",
"ember-qunit": "^6.1.1",
"ember-resolver": "^8.0.3",
"ember-sinon": "^5.0.0",
"ember-source": "^4.1.0",
"ember-source": "^4.4.0",
"ember-source-channel-url": "^3.0.0",
"ember-template-lint": "^4.0.0",
"ember-template-lint": "^4.8.0",
"ember-try": "~2.0.0",
"eslint": "^7.32.0",
"eslint-config-prettier": "^8.3.0",
"eslint-plugin-ember": "^10.5.8",
"eslint-config-prettier": "^8.5.0",
"eslint-plugin-ember": "^10.6.1",
"eslint-plugin-node": "^11.1.0",
"eslint-plugin-prettier": "^4.0.0",
"eslint-plugin-qunit": "^7.2.0",
Expand All @@ -108,11 +109,11 @@
"mocha": "^9.2.0",
"npm-run-all": "^4.1.5",
"nyc": "^15.0.0",
"prettier": "^2.5.1",
"qunit": "^2.17.2",
"prettier": "^2.6.2",
"qunit": "^2.19.1",
"qunit-dom": "^2.0.0",
"semantic-release": "^19.0.2",
"webpack": "^5.68.0"
"webpack": "^5.72.1"
},
"engines": {
"node": "12.* || 14.* || >= 16"
Expand Down
1 change: 0 additions & 1 deletion tests/dummy/app/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
<html>
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<title>Dummy</title>
<meta name="description" content="">
<meta name="viewport" content="width=device-width, initial-scale=1">
Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion tests/dummy/config/ember-cli-update.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"packages": [
{
"name": "ember-cli",
"version": "4.1.1",
"version": "4.4.1",
"blueprints": [
{
"name": "addon",
Expand Down
Empty file removed tests/helpers/.gitkeep
Empty file.
42 changes: 42 additions & 0 deletions tests/helpers/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import {
setupApplicationTest as upstreamSetupApplicationTest,
setupRenderingTest as upstreamSetupRenderingTest,
setupTest as upstreamSetupTest,
} from 'ember-qunit';

// This file exists to provide wrappers around ember-qunit's / ember-mocha's
// test setup functions. This way, you can easily extend the setup that is
// needed per test type.

function setupApplicationTest(hooks, options) {
upstreamSetupApplicationTest(hooks, options);

// Additional setup for application tests can be done here.
//
// For example, if you need an authenticated session for each
// application test, you could do:
//
// hooks.beforeEach(async function () {
// await authenticateSession(); // ember-simple-auth
// });
//
// This is also a good place to call test setup functions coming
// from other addons:
//
// setupIntl(hooks); // ember-intl
// setupMirage(hooks); // ember-cli-mirage
}

function setupRenderingTest(hooks, options) {
upstreamSetupRenderingTest(hooks, options);

// Additional setup for rendering tests can be done here.
}

function setupTest(hooks, options) {
upstreamSetupTest(hooks, options);

// Additional setup for unit tests can be done here.
}

export { setupApplicationTest, setupRenderingTest, setupTest };
1 change: 0 additions & 1 deletion tests/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
<html>
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<title>Dummy Tests</title>
<meta name="description" content="">
<meta name="viewport" content="width=device-width, initial-scale=1">
Expand Down
Loading