Skip to content
Closed

TEST3 #308

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
10 changes: 6 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# TEST

<p align="center">
<img alt="Gasket" src="site/logo-cover.svg" width="496">
</p>
Expand Down Expand Up @@ -142,7 +144,7 @@ Available presets
| Name | Version | Description |
| ----------------------- | ------- | ------------------------------------------ |
| [@gasket/preset-api] | 6.7.0 | Create Express-based API with Gasket |
| [@gasket/preset-nextjs] | 6.8.0 | Basic NextJS Framework |
| [@gasket/preset-nextjs] | 6.8.2 | Basic NextJS Framework |
| [@gasket/preset-pwa] | 6.0.12 | Turn Gasket apps into Progressive Web Apps |

## Plugins
Expand All @@ -162,7 +164,7 @@ Available plugins
| [@gasket/plugin-fastify] | 6.0.12 | Adds fastify support to your application |
| [@gasket/plugin-git] | 6.2.0 | Adds git support to your application |
| [@gasket/plugin-https] | 6.5.1 | Create http/s servers with graceful termination |
| [@gasket/plugin-intl] | 6.8.0 | NodeJS script to build localization files. |
| [@gasket/plugin-intl] | 6.8.2 | NodeJS script to build localization files. |
| [@gasket/plugin-jest] | 6.0.12 | Integrated jest into your application. |
| [@gasket/plugin-lifecycle] | 6.8.1 | Allows a gasket/ directory to be used for lifecycle hooks in applications. |
| [@gasket/plugin-lint] | 6.3.0 | Adds GoDaddy standard linting to your application |
Expand All @@ -171,12 +173,12 @@ Available plugins
| [@gasket/plugin-metadata] | 6.3.0 | Adds metadata to gasket lifecycles |
| [@gasket/plugin-metrics] | 6.0.12 | Collect metrics for gasket commands |
| [@gasket/plugin-mocha] | 6.0.12 | Integrates mocha based testing in to your Gasket application |
| [@gasket/plugin-nextjs] | 6.8.0 | Adds Next support to your application |
| [@gasket/plugin-nextjs] | 6.8.2 | Adds Next support to your application |
| [@gasket/plugin-redux] | 6.1.0 | Gasket Redux Setup |
| [@gasket/plugin-service-worker] | 6.0.12 | Gasket Service Worker Plugin |
| [@gasket/plugin-start] | 6.0.12 | Adds commands for building and starting Gasket apps |
| [@gasket/plugin-swagger] | 6.7.0 | Generate and serve swagger docs |
| [@gasket/plugin-webpack] | 6.6.0 | Adds webpack support to your application |
| [@gasket/plugin-webpack] | 6.8.2 | Adds webpack support to your application |
| [@gasket/plugin-workbox] | 6.0.12 | Gasket Workbox Plugin |

## Modules
Expand Down
2 changes: 1 addition & 1 deletion lerna.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"version": "6.8.1",
"version": "6.8.2",
"packages": [
"packages/*",
"scripts/generate-docs-index"
Expand Down
5 changes: 5 additions & 0 deletions packages/gasket-plugin-intl/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# `@gasket/plugin-intl`

### 6.8.2

- Handle malformed and inconsistent formatted accept-language header ([#302])

### 6.7.2

- Minor fix to update logger to use `gasket.logger.warning` ([#297])
Expand Down Expand Up @@ -135,3 +139,4 @@
[#274]: https://github.com/godaddy/gasket/pull/274
[#290]: https://github.com/godaddy/gasket/pull/290
[#297]: https://github.com/godaddy/gasket/pull/297
[#302]: https://github.com/godaddy/gasket/pull/302
34 changes: 28 additions & 6 deletions packages/gasket-plugin-intl/lib/middleware.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,29 @@ const { LocaleUtils } = require('@gasket/helper-intl');
const { getIntlConfig } = require('./configure');


function capitalize(str) {
return str[0].toUpperCase() + str.substring(1).toLowerCase();
}

/**
* Ensure consistent locale format coming from accept-language header.
*
* @example
* - az-AZ
* - az-Arab
* - az-AZ-Latn
*
* @param {string} language - Selected accept-language
* @returns {string} locale
*/
function formatLocale(language) {
const [lang, ...rest] = language ? language.split('-') : [];
return [
lang.toLowerCase(),
...rest.map(o => o.length === 2 ? o.toUpperCase() : capitalize(o))
].join('-');
}

module.exports = function middlewareHook(gasket) {
const { defaultLocale, basePath, localesMap, localesDir, manifestFilename, locales } = getIntlConfig(gasket);

Expand All @@ -16,13 +39,12 @@ module.exports = function middlewareHook(gasket) {
let preferredLocale = defaultLocale;
if (req.headers['accept-language']) {
try {
// if we have a list of support locales, fallback to one.
preferredLocale = locales && locales.length ?
accept.language(req.headers['accept-language'], locales) :
// Otherwise just run with the first accept language.
req.headers['accept-language'].split(',')[0];
// Get highest or highest from locales if configured
preferredLocale = formatLocale(
accept.language(req.headers['accept-language'], locales)
);
} catch (error) {
gasket.logger.warning(`Unable to parse accept-language header: ${error.message}`);
gasket.logger.warning(`Unable to parse accept-language header: ${ error.message }`);
}
}

Expand Down
2 changes: 1 addition & 1 deletion packages/gasket-plugin-intl/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion packages/gasket-plugin-intl/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@gasket/plugin-intl",
"version": "6.8.0",
"version": "6.8.2",
"description": "NodeJS script to build localization files.",
"main": "lib",
"scripts": {
Expand Down
37 changes: 33 additions & 4 deletions packages/gasket-plugin-intl/test/middleware.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,19 +56,32 @@ describe('middleware', function () {

it('passes first accepted from supported locales', async function () {
mockGasket.config.intl.locales = ['de'];

layer = middlewareHook(mockGasket);
req.headers['accept-language'] = 'fr-CH, fr;q=0.9, en;q=0.8, de;q=0.7, *;q=0.5';
await layer(req, res, next);
assume(mockGasket.execWaterfall).calledWith('intlLocale', 'de', { req, res });
});

it('passes first accept-header', async function () {
it('passes first accept-language header', async function () {
req.headers['accept-language'] = 'fr-CH, fr;q=0.9, en;q=0.8, de;q=0.7, *;q=0.5';
await layer(req, res, next);
assume(mockGasket.execWaterfall).calledWith('intlLocale', 'fr-CH', { req, res });
});

it('passes defaultLocale if no accept-header', async function () {
it('formats accept-language to lower-UPPER', async function () {
req.headers['accept-language'] = 'fr-fr';
await layer(req, res, next);
assume(mockGasket.execWaterfall).calledWith('intlLocale', 'fr-FR', { req, res });
});

it('formats accept-language to lo-UP-Capitals', async function () {
req.headers['accept-language'] = 'az-az-latn';
await layer(req, res, next);
assume(mockGasket.execWaterfall).calledWith('intlLocale', 'az-AZ-Latn', { req, res });
});

it('passes defaultLocale if no accept-language header', async function () {
delete req.headers['accept-language'];
await layer(req, res, next);
assume(mockGasket.execWaterfall).calledWith('intlLocale', 'en-US', { req, res });
Expand Down Expand Up @@ -110,12 +123,28 @@ describe('middleware', function () {
assume(res.locals).property('localesDir', mockGasket.config.intl.localesDir);
});

context('when preferredLocale exception is thrown', function () {
context('when accept-language header is malformed', function () {
beforeEach(function () {
req.headers['accept-language'] = 'fr-CH;+malformed';
});

it('logs a gasket warn log', async function () {
req.headers['accept-language'] = new Error('mock error');
await layer(req, res, next);
assume(mockGasket.logger.warning).called();
});

it('passes defaultLocale with supported locales', async function () {
mockGasket.config.intl.locales = ['de'];
layer = middlewareHook(mockGasket);
await layer(req, res, next);
assume(mockGasket.execWaterfall).calledWith('intlLocale', 'en-US', { req, res });
});

it('passes defaultLocale without supported locales', async function () {
layer = middlewareHook(mockGasket);
await layer(req, res, next);
assume(mockGasket.execWaterfall).calledWith('intlLocale', 'en-US', { req, res });
});
});

describe('req.withLocaleRequired', function () {
Expand Down
4 changes: 2 additions & 2 deletions packages/gasket-plugin-nextjs/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@gasket/plugin-nextjs",
"version": "6.8.0",
"version": "6.8.2",
"description": "Adds Next support to your application",
"main": "index.js",
"scripts": {
Expand Down Expand Up @@ -36,7 +36,7 @@
},
"homepage": "https://github.com/godaddy/gasket/tree/master/packages/gasket-plugin-nextjs",
"dependencies": {
"@gasket/plugin-webpack": "^6.6.0",
"@gasket/plugin-webpack": "^6.8.2",
"@gasket/resolve": "^6.3.0"
},
"devDependencies": {
Expand Down
2 changes: 2 additions & 0 deletions packages/gasket-plugin-swagger/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ const accessFile = promisify(fs.access);

const isYaml = /\.ya?ml$/;

const thisIsATestChange = 'Test Change';

let __swaggerSpec;

/**
Expand Down
5 changes: 5 additions & 0 deletions packages/gasket-plugin-webpack/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# `@gasket/plugin-webpack`

### 6.8.2

- Fix lazy require `initWebpack` dependencies ([#303])

### 6.6.0

- Created new webpackConfig lifecycle ([#284])
Expand Down Expand Up @@ -35,3 +39,4 @@
[#247]: https://github.com/godaddy/gasket/pull/247
[#252]: https://github.com/godaddy/gasket/pull/252
[#284]: https://github.com/godaddy/gasket/pull/284
[#303]: https://github.com/godaddy/gasket/pull/303
9 changes: 5 additions & 4 deletions packages/gasket-plugin-webpack/index.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
const webpack = require('webpack');
const WebpackChain = require('webpack-chain');
const webpackMerge = require('webpack-merge');
const WebpackMetricsPlugin = require('./webpack-metrics-plugin');
const { name, devDependencies } = require('./package');

/**
Expand All @@ -12,6 +8,11 @@ const { name, devDependencies } = require('./package');
* @returns {Object} Final webpack config
*/
function initWebpack(gasket, initConfig, context) {
const webpack = require('webpack');
const WebpackChain = require('webpack-chain');
const webpackMerge = require('webpack-merge');
const WebpackMetricsPlugin = require('./webpack-metrics-plugin');

const { execSync, execWaterfallSync, config } = gasket;

const standardPlugins = { plugins: [new WebpackMetricsPlugin({ gasket })] };
Expand Down
2 changes: 1 addition & 1 deletion packages/gasket-plugin-webpack/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@gasket/plugin-webpack",
"version": "6.6.0",
"version": "6.8.2",
"description": "Adds webpack support to your application",
"main": "index.js",
"scripts": {
Expand Down
6 changes: 3 additions & 3 deletions packages/gasket-preset-nextjs/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@gasket/preset-nextjs",
"version": "6.8.0",
"version": "6.8.2",
"description": "Basic NextJS Framework",
"repository": {
"type": "git",
Expand All @@ -18,8 +18,8 @@
"@gasket/plugin-express": "^6.5.0",
"@gasket/plugin-https": "^6.5.1",
"@gasket/plugin-log": "^6.1.0",
"@gasket/plugin-nextjs": "^6.8.0",
"@gasket/plugin-nextjs": "^6.8.2",
"@gasket/plugin-redux": "^6.1.0",
"@gasket/plugin-webpack": "^6.6.0"
"@gasket/plugin-webpack": "^6.8.2"
}
}