Skip to content
This repository has been archived by the owner on Oct 25, 2022. It is now read-only.

Update dependencies and Ember #59

Merged
merged 2 commits into from
Nov 6, 2020
Merged
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
1 change: 0 additions & 1 deletion .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ module.exports = {
'@typescript-eslint/adjacent-overload-signatures': 2,
'@typescript-eslint/array-type': [2, {default: 'array-simple'}],
'@typescript-eslint/await-thenable': 2,
'@typescript-eslint/ban-ts-ignore': 2,
'@typescript-eslint/consistent-type-assertions': [
2,
{assertionStyle: 'as'}
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ jobs:

- uses: actions/setup-node@v1
with:
node-version: 10.19
node-version: 14.15

- uses: actions/cache@v2
id: npm-cache
Expand All @@ -24,7 +24,7 @@ jobs:
restore-keys: |
${{ runner.os }}-npm-

- run: make dependencies
- run: make ci-dependencies
- run: make lint
- run: make check
- run: make test
Expand Down
8 changes: 6 additions & 2 deletions .prettierrc
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
{
"singleQuote": true,
"arrowParens": "avoid",
"bracketSpacing": false,
"quoteProps": "consistent"
"printWidth": 120,
charlesdemers marked this conversation as resolved.
Show resolved Hide resolved
"quoteProps": "consistent",
"semi": true,
"singleQuote": true,
"tabWidth": 2
}
4 changes: 2 additions & 2 deletions BOILERPLATE_README.fr.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@

## 🚧 Dépendances

- Node.js (`~> 10.19`)
- NPM (`~> 6.13`)
- Node.js (`~> 14.15`)
- NPM (`~> 6.14`)

## 🏎 Départ rapide

Expand Down
4 changes: 2 additions & 2 deletions BOILERPLATE_README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@

## 🚧 Dependencies

- Node.js (`~> 10.19`)
- NPM (`~> 6.13`)
- Node.js (`~> 14.15`)
- NPM (`~> 6.14`)

## 🏎 Kickstart

Expand Down
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM node:10.19-alpine
FROM node:14.15-alpine

WORKDIR /opt/app

Expand Down
4 changes: 4 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,10 @@ push: ## Push the Docker image to the registry
dependencies: ## Install dependencies required by the application
npm install

.PHONY: dependencies
ci-dependencies: ## Install dependencies required by the application in CI
charlesdemers marked this conversation as resolved.
Show resolved Hide resolved
npm ci

.PHONY: build-app
build-app: ## Build the application
npm run build
Expand Down
14 changes: 7 additions & 7 deletions app/formats.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,22 @@ export default {
hhmmss: {
hour: 'numeric',
minute: 'numeric',
second: 'numeric'
}
second: 'numeric',
},
},
date: {
hhmmss: {
hour: 'numeric',
minute: 'numeric',
second: 'numeric'
}
second: 'numeric',
},
},
number: {
CAD: {
style: 'currency',
currency: 'CAD',
minimumFractionDigits: 2,
maximumFractionDigits: 2
}
}
maximumFractionDigits: 2,
},
},
};
9 changes: 3 additions & 6 deletions app/initializers/sentry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,15 @@ export const initialize = () => {

if (typeof error !== 'object') return event;

if (
error?.name === 'TransitionAborted' ||
error?.name === 'TaskCancelation'
) {
if (error?.name === 'TransitionAborted' || error?.name === 'TaskCancelation') {
return null;
}

return event;
}
},
});
};

export default {
initialize
initialize,
};
2 changes: 1 addition & 1 deletion app/instance-initializers/fastboot-error-handling.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,5 @@ export const initialize = (application: ApplicationInstance): void => {

export default {
initialize,
name: 'fastboot-error-handling'
name: 'fastboot-error-handling',
};
14 changes: 6 additions & 8 deletions app/pods/application/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,7 @@ import ServiceWorker from 'mirego-service-worker-plugin/services/service-worker'
import IntlService from 'ember-intl/services/intl';
import Apollo from 'ember-boilerplate/services/apollo';
import HeadData from 'ember-cli-head/services/head-data';
import Translations, {
AvailableLocale
} from 'ember-boilerplate/services/translations';
import Translations, {AvailableLocale} from 'ember-boilerplate/services/translations';

export default class ApplicationRoute extends Route {
@service('apollo')
Expand All @@ -35,6 +33,11 @@ export default class ApplicationRoute extends Route {
@service('translations')
translations: Translations;

@action
didTransition() {
this.shoebox.write(config.apollo.SSR_CACHE_KEY, this.apollo.extractCache());
}

async beforeModel() {
const locale = this.determineLocale();

Expand All @@ -55,11 +58,6 @@ export default class ApplicationRoute extends Route {
});
}

@action
didTransition() {
this.shoebox.write(config.apollo.SSR_CACHE_KEY, this.apollo.extractCache());
}

private determineLocale(): AvailableLocale {
return 'en-ca';
}
Expand Down
2 changes: 1 addition & 1 deletion app/router.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ export default class Router extends EmberRouter {
rootURL = config.rootURL;
}

Router.map(function() {
Router.map(function () {
this.route('welcome', {path: '/'});

// Catch-all error page, put your routes above this one
Expand Down
33 changes: 15 additions & 18 deletions app/services/apollo.ts → app/services/-apollo.ts
Original file line number Diff line number Diff line change
@@ -1,27 +1,27 @@
// Vendor
import {InMemoryCache, NormalizedCacheObject} from '@apollo/client/cache';
import {setContext} from '@apollo/client/link/context';
import {createHttpLink} from '@apollo/client/core';
import {onError} from '@apollo/client/link/error';
import {inject as service} from '@ember/service';
import {InMemoryCache, NormalizedCacheObject} from 'apollo-cache-inmemory';
import {setContext} from 'apollo-link-context';
import {createHttpLink} from 'apollo-link-http';
import {onError} from 'apollo-link-error';
import ApolloService from 'ember-apollo-client/services/apollo';
import * as Sentry from '@sentry/browser';
import fetch from 'fetch';

// Types
import ShoeBox from 'ember-boilerplate/services/shoebox';
import SessionFetcher from 'ember-boilerplate/services/session/fetcher';
import Session from 'ember-boilerplate/services/session';
import FastBoot from 'ember-cli-fastboot/services/fastboot';

// Config
import config from 'ember-boilerplate/config/environment';

const dataIdFromObject = (result: any): string | null => {
const dataIdFromObject = (result: any) => {
if (result.id && result.__typename) {
return `${result.__typename}${result.id}`;
}

return null;
return;
};

export default class Apollo extends ApolloService {
Expand All @@ -31,22 +31,22 @@ export default class Apollo extends ApolloService {
@service('fastboot')
fastboot: FastBoot;

@service('session/fetcher')
sessionFetcher: SessionFetcher;
@service('session')
session: Session;

clientOptions() {
return {
assumeImmutableResults: true,
cache: this.cache(),
link: this.link(),
ssrMode: this.fastboot.isFastBoot
ssrMode: this.fastboot.isFastBoot,
};
}

link() {
const httpLink = createHttpLink({
uri: config.apollo.API_URL,
fetch
fetch,
});

const authenticationLink = this.createAuthenticationLink();
Expand All @@ -58,12 +58,9 @@ export default class Apollo extends ApolloService {
cache() {
const cache = new InMemoryCache({
dataIdFromObject,
freezeResults: false
});

const cachedContent = this.shoebox.read(
config.apollo.SSR_CACHE_KEY
) as NormalizedCacheObject;
const cachedContent = this.shoebox.read(config.apollo.SSR_CACHE_KEY) as NormalizedCacheObject;

if (!cachedContent) return cache;

Expand All @@ -80,12 +77,12 @@ export default class Apollo extends ApolloService {

private createAuthenticationLink() {
return setContext(async () => {
const {token} = await this.sessionFetcher.fetch();
const token = await this.session.fetchAccessToken();

return {
headers: {
authorization: `Bearer ${token}`
}
authorization: `Bearer ${token}`,
},
};
});
}
Expand Down
2 changes: 2 additions & 0 deletions app/services/apollo.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export {default} from './-apollo';
export * from './-apollo';
4 changes: 1 addition & 3 deletions app/services/location.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,7 @@ export default class Location extends Service {
fastbootLocation: FastBootLocation;

get locationService(): LocationInterface {
return this.fastboot.isFastBoot
? this.fastbootLocation
: this.browserLocation;
return this.fastboot.isFastBoot ? this.fastbootLocation : this.browserLocation;
}

@reads('locationService.protocol')
Expand Down
3 changes: 1 addition & 2 deletions app/services/location/browser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@ import window from 'ember-window-mock';
// Types
import {LocationInterface} from 'ember-boilerplate/services/location';

export default class BrowserLocation extends Service
implements LocationInterface {
export default class BrowserLocation extends Service implements LocationInterface {
get protocol(): string {
return window.location.protocol;
}
Expand Down
3 changes: 1 addition & 2 deletions app/services/location/fastboot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@ import config from 'ember-boilerplate/config/environment';
import {LocationInterface} from 'ember-boilerplate/services/location';
import FastBoot from 'ember-cli-fastboot/services/fastboot';

export default class FastBootLocation extends Service
implements LocationInterface {
export default class FastBootLocation extends Service implements LocationInterface {
@service('fastboot')
fastboot: FastBoot;

Expand Down
14 changes: 14 additions & 0 deletions app/services/session.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
// Vendor
import Service from '@ember/service';

export default class Session extends Service {
async fetchAccessToken(): Promise<string> {
return Promise.reject(Error('[session] fetchAccessToken not implemented.'));
}
}

declare module '@ember/service' {
interface Registry {
session: Session;
}
}
18 changes: 0 additions & 18 deletions app/services/session/fetcher.ts

This file was deleted.

15 changes: 4 additions & 11 deletions app/services/translations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import config from 'ember-boilerplate/config/environment';
export type AvailableLocale = 'en-ca';

const pathForLocale: Record<AvailableLocale, string> = {
'en-ca': '/assets/translations/en-ca.json'
'en-ca': '/assets/translations/en-ca.json',
};

export default class Translations extends Service {
Expand Down Expand Up @@ -42,29 +42,22 @@ export default class Translations extends Service {
return this.fetchTranslationsFromNetwork(locale);
}

private async fetchTranslationsFromNetwork(
locale: AvailableLocale
): Promise<object> {
private async fetchTranslationsFromNetwork(locale: AvailableLocale): Promise<object> {
const translationsURL = pathForLocale[locale];

const response = await fetch(translationsURL);

const translations = await response.json();

if (this.fastboot.isFastBoot) {
this.shoebox.write(
`${config.intl.TRANSLATIONS_CACHE_KEY}-${locale}`,
translations
);
this.shoebox.write(`${config.intl.TRANSLATIONS_CACHE_KEY}-${locale}`, translations);
}

return translations;
}

private fetchTranslationsFromShoebox(locale: AvailableLocale) {
const translations = this.shoebox.read(
`${config.intl.TRANSLATIONS_CACHE_KEY}-${locale}`
) as object;
const translations = this.shoebox.read(`${config.intl.TRANSLATIONS_CACHE_KEY}-${locale}`) as object;

return translations;
}
Expand Down
6 changes: 3 additions & 3 deletions config/coverage-check.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@ module.exports = {
branches: 75,
functions: 75,
lines: 75,
statements: 75
statements: 75,
},
watermarks: {
branches: [70, 80],
functions: [70, 80],
lines: [70, 80],
statements: [70, 80]
}
statements: [70, 80],
},
};
Loading