Skip to content

Commit

Permalink
Merge pull request #4607 from HSLdevcom/bump-libs-2
Browse files Browse the repository at this point in the history
raise min. Node version to 16, upgrade some dev dependencies
  • Loading branch information
vesameskanen authored Sep 22, 2022
2 parents 23c3de9 + 9ee0778 commit 07c454c
Show file tree
Hide file tree
Showing 23 changed files with 4,162 additions and 3,356 deletions.
38 changes: 5 additions & 33 deletions .github/workflows/dev-pipeline.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
node-version: [10.x]
node-version: [16.x]
steps:
- name: Checkout
uses: actions/checkout@v2
Expand All @@ -33,7 +33,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
node-version: [10.x]
node-version: [16.x]
steps:
- name: Checkout
uses: actions/checkout@v2
Expand All @@ -55,38 +55,12 @@ jobs:
run: yarn run test-coverage
- name: Send test coverage report
run: yarn run test-report
accessibility-test:
runs-on: ubuntu-latest
strategy:
matrix:
node-version: [10.x]
steps:
- name: Checkout
uses: actions/checkout@v2
- name: "Set time zone to Europe/Helsinki"
uses: zcong1993/setup-timezone@master
with:
timezone: "Europe/Helsinki"
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v1
with:
node-version: ${{ matrix.node-version }}
- name: Install dependencies
run: yarn
- name: Install dependencies and build shared components
run: yarn setup
- name: build relay queries
run: yarn relay
- name: Build UI
run: yarn build
- name: Run accessibility tests
run: yarn test-accessibility
# build:
# needs: install
# runs-on: ubuntu-18.04
# runs-on: ubuntu-20.04
# strategy:
# matrix:
# node-version: [10.x]
# node-version: [16.x]
# steps:
# - name: Checkout
# uses: actions/checkout@v2
Expand Down Expand Up @@ -115,11 +89,10 @@ jobs:
needs:
- lint
- unit-test
- accessibility-test
runs-on: ubuntu-latest
strategy:
matrix:
node-version: [ 10.x ]
node-version: [16.x]
steps:
- uses: actions/checkout@v2
- name: Set time zone to Europe/Helsinki
Expand Down Expand Up @@ -164,7 +137,6 @@ jobs:
- lint
- publish-npm
- unit-test
- accessibility-test
runs-on: ubuntu-latest
steps:
- name: Checkout
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/hotfix-pipeline.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ on:
jobs:
docker-push:
if: github.ref == 'refs/heads/hotfix'
runs-on: ubuntu-18.04
runs-on: ubuntu-20.04
steps:
- name: Checkout
uses: actions/checkout@v2
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/prod-pipeline.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ on:
- published
jobs:
prod-push:
runs-on: ubuntu-18.04
runs-on: ubuntu-20.04
steps:
- name: Checkout
uses: actions/checkout@v2
Expand Down

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion .yarnrc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@ plugins:
- path: .yarn/plugins/@yarnpkg/plugin-version.cjs
spec: "@yarnpkg/plugin-version"

yarnPath: .yarn/releases/yarn-berry.cjs
yarnPath: .yarn/releases/yarn-2.4.3.cjs
11 changes: 1 addition & 10 deletions app/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ import {
cacheMiddleware,
} from 'react-relay-network-modern';
import RelayClientSSR from 'react-relay-network-modern-ssr/lib/client';
import OfflinePlugin from 'offline-plugin/runtime';
import { Helmet } from 'react-helmet';
import { Environment, RecordSource, Store } from 'relay-runtime';
import { ReactRelayContext } from 'react-relay';
Expand All @@ -32,7 +31,6 @@ import configureMoment from './util/configure-moment';
import StoreListeningIntlProvider from './util/StoreListeningIntlProvider';
import appCreator from './app';
import translations from './translations';
import { BUILD_TIME } from './buildInfo';
import ErrorBoundary from './component/ErrorBoundary';
import oldParamParser from './util/oldParamParser';
import { ClientProvider as ClientBreakpointProvider } from './util/withBreakpoint';
Expand Down Expand Up @@ -269,14 +267,7 @@ async function init() {
</ClientBreakpointProvider>
);

ReactDOM.hydrate(content, root, () => {
// Run only in production mode and when built in a docker container
if (process.env.NODE_ENV === 'production' && BUILD_TIME !== 'unset') {
OfflinePlugin.install({
onUpdateReady: () => OfflinePlugin.applyUpdate(),
});
}
});
ReactDOM.hydrate(content, root);

// Listen for Web App Install Banner events
window.addEventListener('beforeinstallprompt', e => {
Expand Down
22 changes: 9 additions & 13 deletions app/component/RoutePage.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ class RoutePage extends React.Component {
const { breakpoint, router, route, error } = this.props;
const { config } = this.context;
const tripId = this.props.match.params?.tripId;
const patternId = this.props.match.params?.patternId;

// Render something in client side to clear SSR
if (isBrowser && error && !route) {
Expand All @@ -71,6 +72,8 @@ class RoutePage extends React.Component {
}
const mode = getRouteMode(route);
const label = route.shortName ? route.shortName : route.longName || '';
const headsign =
patternId && route.patterns.find(p => p.code === patternId).headsign;

return (
<div className={cx('route-page-container')}>
Expand Down Expand Up @@ -113,19 +116,12 @@ class RoutePage extends React.Component {
</span>
{label}
</h1>
{tripId &&
route.patterns[1]?.headsign &&
!label.includes(route.patterns[1].headsign) && (
<div className="trip-destination">
<Icon
className="in-text-arrow"
img="icon-icon_arrow-right"
/>
<div className="destination-headsign">
{route.patterns[1].headsign}
</div>
</div>
)}
{tripId && headsign && (
<div className="trip-destination">
<Icon className="in-text-arrow" img="icon-icon_arrow-right" />
<div className="destination-headsign">{headsign}</div>
</div>
)}
</div>
{!tripId && (
<LazilyLoad modules={modules}>
Expand Down
2 changes: 1 addition & 1 deletion app/configurations/config.varely.js
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ export default configMerger(walttiConfig, {
{
header: 'Om tjänsten',
paragraphs: [
'Den här tjänsten erbjuds av HRT för reseplanering inom huvudstadsregionen (Åbo, Aura, Masku, Mynämäki, Nousis, Pemar and Pargas). Reseplaneraren täcker med vissa begränsningar kollektivtrafik, promenad, cykling samt privatbilism. Tjänsten baserar sig på Digitransit-plattformen.',
'Den här tjänsten är för reseplanering inom Egentliga Finland (Åbo, Aura, Masku, Mynämäki, Nousis, Pemar and Pargas). Reseplaneraren täcker med vissa begränsningar kollektivtrafik, promenad, cykling samt privatbilism. Tjänsten baserar sig på Digitransit-plattformen.',
],
},
{
Expand Down
7 changes: 6 additions & 1 deletion app/configurations/config.walttiOpas.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ export default configMerger(walttiConfig, {
// Navbar logo
logo: 'walttiOpas/waltti-logo.png',

feedIds: ['Kotka', 'Kouvola', 'Salo'],
feedIds: ['Kotka', 'Kouvola', 'Salo', 'Kajaani'],

defaultEndpoint: {
address: 'Helsinki-Vantaan Lentoasema',
Expand Down Expand Up @@ -154,6 +154,11 @@ export default configMerger(walttiConfig, {
sv: 'Kouvola',
en: 'Kouvola',
},
Kajaani: {
fi: 'Kajaani',
sv: 'Kajaani',
en: 'Kajaani',
},
Salo: {
fi: 'Salo',
sv: 'Salo',
Expand Down
6 changes: 3 additions & 3 deletions app/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,9 @@ if (process.env.NODE_ENV !== 'development') {
// eslint-disable-next-line global-require, import/no-unresolved
assets = require('../manifest.json');
// eslint-disable-next-line global-require, import/no-unresolved
mainAssets = require('../stats.json').entrypoints.main.assets.filter(
asset => !asset.endsWith('.map'),
);
mainAssets = require('../stats.json')
.entrypoints.main.assets.filter(asset => !asset.name.endsWith('.map'))
.map(asset => asset.name);

const manifestFiles = mainAssets.filter(asset =>
asset.startsWith('js/runtime'),
Expand Down
13 changes: 10 additions & 3 deletions app/util/fetchUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,15 @@ const addSubscriptionHeader = (headers, config) => {
return updatedHeaders;
};

const addSubscriptionParam = (url, config) => {
if (config.hasAPISubscriptionQueryParameter) {
return `${encodeURI(url)}${url.search(/\?/) === -1 ? '?' : '&'}${
config.API_SUBSCRIPTION_QUERY_PARAMETER_NAME
}=${config.API_SUBSCRIPTION_TOKEN}`;
}
return encodeURI(url);
};

// Tries to fetch 1 + retryCount times until 200 is returned.
// Uses retryDelay (ms) between requests. url and options are normal fetch parameters
export const retryFetch = (
Expand Down Expand Up @@ -62,6 +71,4 @@ export const retryFetch = (
* @returns fetch's promise
*/
export const fetchWithSubscription = (URL, config) =>
fetch(URL, {
headers: addSubscriptionHeader({}, config),
});
fetch(addSubscriptionParam(URL, config));
7 changes: 7 additions & 0 deletions app/util/mapIconUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,9 @@ function getImageFromSpriteSync(icon, width, height, fill) {
return null;
}
const symbol = document.getElementById(icon);
if (!symbol) {
return null;
}
const svg = document.createElementNS('http://www.w3.org/2000/svg', 'svg');
svg.setAttribute('width', width);
svg.setAttribute('height', height);
Expand Down Expand Up @@ -237,6 +240,10 @@ function getImageFromSpriteAsync(icon, width, height, fill) {
return new Promise(resolve => {
// TODO: check that icon exists using MutationObserver
const image = getImageFromSpriteSync(icon, width, height, fill);
if (!image) {
resolve(null);
return;
}
image.onload = () => resolve(image);
});
}
Expand Down
3 changes: 2 additions & 1 deletion babel.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,13 @@ module.exports = {
},
],
'@babel/plugin-syntax-dynamic-import',
['@babel/plugin-proposal-class-properties', { loose: true }],
'@babel/plugin-proposal-class-properties',
'@babel/plugin-proposal-json-strings',
],
env: {
test: {
plugins: ['istanbul'],
},
},
ignore: ['.yarn'],
};
58 changes: 27 additions & 31 deletions build/contextHelper.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@
/* eslint import/no-extraneous-dependencies: ["error", {"devDependencies": true}] */

const fs = require('fs');

const FaviconsWebpackPlugin = require('favicons-webpack-plugin');
const { getNamedConfiguration } = require('../app/config');

function getAllConfigs() {
if (process.env.CONFIG && process.env.CONFIG !== '') {
return [require('../app/config').getNamedConfiguration(process.env.CONFIG)];
return [getNamedConfiguration(process.env.CONFIG)];
}

const srcDirectory = './app/configurations';
Expand All @@ -16,7 +16,7 @@ function getAllConfigs() {
.filter(file => /^config\.\w+\.js$/.test(file))
.map(file => {
const theme = file.replace('config.', '').replace('.js', '');
return require('../app/config').getNamedConfiguration(theme);
return getNamedConfiguration(theme);
});
}

Expand All @@ -43,12 +43,11 @@ function getEntries(theme, sprites) {

function getAllThemeEntries() {
if (process.env.CONFIG && process.env.CONFIG !== '') {
const config = require('../app/config').getNamedConfiguration(
process.env.CONFIG,
);
const defaultConfig = getNamedConfiguration('default');
const config = getNamedConfiguration(process.env.CONFIG);

return {
...getEntries('default'),
...getEntries('default', defaultConfig.sprites),
...getEntries(process.env.CONFIG, config.sprites),
};
}
Expand All @@ -69,40 +68,37 @@ function faviconPluginFromConfig(config) {
logo = './app/configurations/images/default/favicon.png';
}

// Newer versions of this plugin don't support `statsFilename` anymore, but
// this file is being used by app/config.js.
// todo: find a different way to implement this
return new FaviconsWebpackPlugin({
// Your source logo
logo,
// The prefix for all image files (might be a folder or a name)
prefix: `assets/icons-${config.CONFIG}-[hash]/`,
// Emit all stats of the generated icons
emitStats: true,
// The name of the json containing all favicon information
statsFilename: `assets/iconstats-${config.CONFIG}.json`,
prefix: `assets/icons-${config.CONFIG}-[contenthash]/`,

inject: false,
// favicon background color (see https://github.com/haydenbleasel/favicons#usage)
// This matches the application background color
background: '#eef1f3',
theme_color: config.colors ? config.colors.primary : '#eef1f3',
// favicon app title (see https://github.com/haydenbleasel/favicons#usage)
title: config.title,
appName: config.title,
appDescription: config.meta.description,
icons: {
android: true,
appleIcon: true,
appleStartup: true,
coast: false,
favicons: true,
firefox: true,
opengraph: false,
twitter: false,
yandex: false,
windows: false,
favicons: {
appName: config.title,
appDescription: config.meta.description,
background: '#eef1f3',
theme_color: config.colors ? config.colors.primary : '#eef1f3',
icons: {
android: true,
appleIcon: true,
appleStartup: true,
coast: false,
favicons: true,
firefox: true,
windows: false,
yandex: false,
},
},
});
}

function getAllFaviconPlugins() {
// return [];
return getAllConfigs().map(faviconPluginFromConfig);
}

Expand Down
4 changes: 2 additions & 2 deletions config/babel.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ module.exports = function (api) {
const plugins = [
['relay', { compat: true, schema: 'schema.json' }],
'babel-plugin-optimize-clsx',
['@babel/plugin-proposal-class-properties', { loose: true }],
['@babel/plugin-proposal-object-rest-spread', { loose: true }],
'@babel/plugin-proposal-class-properties',
'@babel/plugin-proposal-object-rest-spread',
[
'@babel/plugin-transform-runtime',
{
Expand Down
Loading

0 comments on commit 07c454c

Please sign in to comment.