Skip to content

Commit

Permalink
Merge branch 'develop' into 2854-i18n-named-formatting
Browse files Browse the repository at this point in the history
* develop: (21 commits)
  changelog updated
  changelog updated
  add-to-car-fixed
  Small docs improvement
  featurer: output compression + html minifier
  Updated changelog vuestorefront#3456
  productId should support number as well as string https://vuejs.org/v2/guide/components-props.html#Prop-Validation Followed as described for Multiple possible types
  Improved: changes number to number | string It should support numeric as well string values
  Fixed: issue changing item_id to  string | number [tsl] ERROR in /vue-storefront/vue-storefront/core/modules/cart/helpers/productsEquals.ts(16,3)       TS2322: Type 'string | number' is not assignable to type 'number'.   Type 'string' is not assignable to type 'number'.
  Improved: id values should be either number or string. Changing type to any removes types.
  Changed productId type to null so that it supports numeric as well as string values https://vuejs.org/v2/guide/components-props.html#Prop-Validation
  Added tracing support
  Improved: changed type of all the id values to any instead of number VSF should be flexible to support id values to be numeric as well as alphanumeric It may be possible that the ecommerce ERP, it is integrated with may have support for alphanumeric identifier.
  Fixed test
  updated CHANGELOG.md
  Added an mock when you want to overwrite the api search implementation
  Created src/search/adapter as we need to have the folder
  Removed the loading of global as it is not working so easy.
  Added logging for debugging it while developing
  Changed order if imports for search adapter
  ...
  • Loading branch information
phoenixdev-kl committed Sep 17, 2019
2 parents 6e5aa49 + d0ebe54 commit 81646c9
Show file tree
Hide file tree
Showing 35 changed files with 501 additions and 64 deletions.
7 changes: 6 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### Added

- Sort CSV i18n files alphabetically in pre-commit Git hook - @defudef(#2657)
- HTML Minifier has been added, to enable it please switch the `config.server.useHtmlMinifier` - @pkarw (#2182)
- Output compression module has been added; it's enabled by default on production builds; to disable it please switch the `src/modules/serrver.ts` configuration - @pkarw (#2182)
- Sort CSV i18n files alphabetically in pre-commit Git hook - @defudef (#2657)
- Cache invalidate requests forwarding support - @pkarw (#3367)
- Extend storeview config after another storeview in multistore mode - @lukeromanowicz (#3057, #3270)
- Default storeview settings are now overridden by specific storeview settings - @lukeromanowicz (#3057)
Expand All @@ -36,6 +38,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Added husky package to manage lint check only for staged files in git @lorenaramonda (#3444)
- Change text from "is out of the stock" to "is out of stock" - @indiebytes (#3452)
- Added general purpose hooks - @andrzejewsky (#3389)
- Added loading of your own searchAdaptor - @resubaka (#3405K)
- Added lazy hydration for home page - @filrak (#3496)
- Added i18n support for modules - @dz3n (#3369)
- Added tests for actions and mutations in 'core/modules/recently-viewed' - @gibkigonzo (#3467)
Expand Down Expand Up @@ -85,6 +88,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Fixed "Clear Wishlist" Button - @dz3n (#3522)
- Fixed hash in dynamically resolved urls causing resolving issues - @lukeromanowicz (#3515)
- Fix invalid routes in ButtonOutline and ButtonFull - @lukeromanowicz (#3541, #3545)
- Fix for the "add to cart" test

### Changed / Improved

Expand Down Expand Up @@ -121,6 +125,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Refactored vuex cms module - @andrzejewsky (#3337)
- Refactored vuex review module - @andrzejewsky (#3337)
- Refactored vuex newsletter module - @andrzejewsky (#3337)
- Changed type of Id fields related to product, category and attribute to support numeric as well as string - @adityasharma7 (#3456)
- Optimized fetching product data on homepage - @lukeromanowicz (#3512)
- `localizedRoute()` now supports path (and prefers over fullPath) in LocalizedRoute objects - @lukeromanowicz (#3515)
- Move setting review_status from VSF to VSF-API - @afirlejczyk
Expand Down
9 changes: 9 additions & 0 deletions config/default.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@
"protocol": "http",
"api": "api",
"devServiceWorker": false,
"useHtmlMinifier": true,
"htmlMinifierOptions": {
"minifyJS": true,
"minifyCSS": true
},
"useOutputCacheTagging": false,
"useOutputCache": false,
"outputCacheDefaultTtl": 86400,
Expand All @@ -19,6 +24,10 @@
"elasticCacheQuota": 4096,
"ssrDisabledFor": {
"extensions": [".png", ".gif", ".jpg", ".jpeg", ".woff", ".eot", ".woff2", ".ttf", ".svg", ".css", ".js", ".json", ".ico", ".tiff", ".tif", ".raw"]
},
"trace": {
"enabled": false,
"config": {}
}
},
"staticPages": {
Expand Down
2 changes: 1 addition & 1 deletion core/data-resolver/types/DataResolver.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import Review from 'core/modules/review/types/Review';
declare namespace DataResolver {

interface CategorySearchOptions {
parentId?: number,
parentId?: number | string,
filters?: { [key: string]: string[] | string },
level?: number,
onlyActive?: boolean,
Expand Down
19 changes: 17 additions & 2 deletions core/lib/search/adapter/searchAdapterFactory.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,28 @@
import { server } from 'config'

import { Logger } from '@vue-storefront/core/lib/logger'
let instances = {}

const isImplementingSearchAdapterInterface = (obj) => {
return typeof obj.search === 'function' && typeof obj.registerEntityType === 'function'
}

export const getSearchAdapter = async (adapterName = server.api) => {
const SearchAdapterModule = await import(/* webpackChunkName: "vsf-search-adapter-" */ `./${adapterName}/searchAdapter`)
let SearchAdapterModule

try {
SearchAdapterModule = await import(/* webpackChunkName: "vsf-search-adapter-" */ `src/search/adapter/${adapterName}/searchAdapter`)
} catch (e) {
Logger.debug(`Search adapter was not found in src/search/adapter/${adapterName}/searchAdapter`)()
}

if (!SearchAdapterModule) {
try {
SearchAdapterModule = await import(/* webpackChunkName: "vsf-search-adapter-" */ `./${adapterName}/searchAdapter`)
} catch (e) {
Logger.debug(`Search adapter ${adapterName} was not found in in the core`)()
}
}

const SearchAdapter = SearchAdapterModule.SearchAdapter

if (!SearchAdapter) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,14 @@ import {getSearchAdapter} from '@vue-storefront/core/lib/search/adapter/searchAd
jest.mock('config', () => {
return {server: {api: 'api'}};
});
jest.mock('@vue-storefront/core/lib/logger', () => ({
Logger: {
log: jest.fn(() => () => {}),
debug: jest.fn(() => () => {}),
warn: jest.fn(() => () => {}),
error: jest.fn(() => () => {})
}
}));

const mockSearchAdapterModule = {
SearchAdapter: jest.fn().mockImplementation(() => {
Expand Down
2 changes: 1 addition & 1 deletion core/modules/cart/helpers/productsEquals.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ const getChecksum = (product: CartItem) => {
const getProductType = (product: CartItem): string =>
product.type_id || product.product_type

const getServerItemId = (product: CartItem): number =>
const getServerItemId = (product: CartItem): string | number =>
product.server_item_id || product.item_id

const isServerIdsEquals = (product1: CartItem, product2: CartItem): boolean =>
Expand Down
4 changes: 2 additions & 2 deletions core/modules/cart/types/CartItem.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ export default interface CartItem extends Product {
qty: number,
options: CartItemOption[],
totals: CartItemTotals,
server_item_id: number,
server_item_id: number | string,
server_cart_id: any,
product_type?: string,
item_id?: number,
item_id?: number | string,
checksum?: string,
quoteId?: string
}
2 changes: 1 addition & 1 deletion core/modules/cart/types/CartItemTotals.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ export default interface CartItemTotals {
base_tax_amount: number,
discount_amount: number,
discount_percent: number,
item_id: number,
item_id: number | string,
name: string,
options: CartItemOption[],
price: number,
Expand Down
2 changes: 1 addition & 1 deletion core/modules/cart/types/Totals.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
export default interface Totals {
item_id?: number,
item_id?: number | string,
options?: string,
name: string,
qty: number,
Expand Down
6 changes: 3 additions & 3 deletions core/modules/catalog-next/types/Category.d.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
export interface ChildrenData {
id: number,
id: number | string,
children_data?: ChildrenData[],
name?: string,
slug?: string,
Expand All @@ -12,9 +12,9 @@ export interface Category {
level: number,
product_count: number,
children_count: string,
parent_id: number,
parent_id: number | string,
name: string,
id: number,
id: number | string,
url_path: string,
url_key: string,
children_data: ChildrenData[],
Expand Down
2 changes: 1 addition & 1 deletion core/modules/catalog/types/Attribute.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export default interface Attribute {
attribute_code?: string,
attribute_id?: number
attribute_id?: number | string
}
6 changes: 3 additions & 3 deletions core/modules/catalog/types/Product.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ export default interface Product {
category: Record<string, any>[],
category_ids: string[],
color: string,
color_options?: number[],
color_options?: number[] | string[],
configurable_children: Record<string, any>[],
configurable_options: Record<string, any>[],
custom_attributes?: any,
Expand All @@ -11,7 +11,7 @@ export default interface Product {
final_price: number,
gift_message_available: string,
has_options?: string,
id?: number,
id?: number | string,
image: string,
info?: Record<string, any>,
is_configured?: true,
Expand All @@ -36,7 +36,7 @@ export default interface Product {
sale?: string,
sgn?: string,
size: string,
size_options?: number[],
size_options?: number[] | string[],
sku: string,
slug?: string,
small_image?: string,
Expand Down
2 changes: 1 addition & 1 deletion core/modules/catalog/types/ProductConfiguration.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
export interface ProductOption {
attribute_code?: string,
id: number,
id: number | string,
label: string
}

Expand Down
2 changes: 1 addition & 1 deletion core/modules/checkout/types/PaymentDetails.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ export default interface PaymentDetails {
streetAddress: string,
apartmentNumber: string,
city: string,
region_id: number,
region_id: number | string,
state: string,
zipCode: string,
phoneNumber: string,
Expand Down
2 changes: 1 addition & 1 deletion core/modules/checkout/types/ShippingDetails.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ export default interface ShippingDetails {
apartmentNumber: string,
city: string,
state: string,
region_id: number,
region_id: number | string,
zipCode: string,
phoneNumber: string,
shippingMethod: string
Expand Down
4 changes: 2 additions & 2 deletions core/modules/order/types/Order.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ export interface Order {
user_id?: string,
cart_id?: string,
store_code?: string,
store_id?: number,
store_id?: number | string,
/**
* Products list
*/
Expand All @@ -26,7 +26,7 @@ export interface Order {
addressInformation: {
shippingAddress?: {
region?: string,
region_id?: number,
region_id?: number | string,
country_id?: string,
/**
* Street name
Expand Down
4 changes: 2 additions & 2 deletions core/modules/review/types/Review.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
export default interface Review {
product_id: number,
product_id: number | string,
title: string,
detail: string,
nickname: string,
review_entity: string,
review_status: number,
customer_id?: number | null,
customer_id?: number | string | null,
[k: string]: any
}
2 changes: 1 addition & 1 deletion core/modules/user/types/UserProfile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ export interface UserProfile {
email: string,
firstname: string,
lastname: string,
website_id?: number,
website_id?: number | string,
addresses?: {
firstname: string,
lastname: string,
Expand Down
2 changes: 2 additions & 0 deletions core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,10 @@
},
"dependencies": {
"bodybuilder": "2.2.13",
"compression": "^1.7.4",
"config": "^1.30.0",
"express": "^4.14.0",
"html-minifier": "^4.0.0",
"lean-he": "^2.0.0",
"localforage": "^1.7.2",
"lodash-es": "^4.17.10",
Expand Down
1 change: 1 addition & 0 deletions core/scripts/server.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
require('../../src/trace').default()
const path = require('path')
const express = require('express')
const ms = require('ms')
Expand Down
11 changes: 11 additions & 0 deletions core/scripts/utils/ssr-renderer.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ const omit = require('lodash/omit')
const set = require('lodash/set')
const get = require('lodash/get')
const config = require('config')
const minify = require('html-minifier').minify

function createRenderer (bundle, clientManifest, template) {
// https://github.com/vuejs/vue/blob/dev/packages/vue-server-renderer/README.md#why-use-bundlerenderer
Expand Down Expand Up @@ -63,6 +64,15 @@ function applyAdvancedOutputProcessing (context, output, templatesCache, isProd
output = output.replace(new RegExp('href="/', 'g'), `href="${relativePath}/`)
}

if (config.server.useHtmlMinifier) {
console.debug('HTML Minifier is enabled')
output = minify(output, config.server.htmlMinifierOptions)
}

if ((typeof context.output.filter === 'function')) {
output = context.output.filter(output, context)
}

return output;
}

Expand All @@ -84,6 +94,7 @@ function initSSRRequestContext (app, req, res, config) {
output: {
prepend: (context) => { return ''; },
append: (context) => { return ''; },
filter: (output, context) => { return output },
appendHead: (context) => { return ''; },
template: 'default',
cacheTags: null
Expand Down
12 changes: 11 additions & 1 deletion docs/guide/basics/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,22 @@ Please find the configuration properties reference below.
```json
"server": {
"host": "localhost",
"port": 3000
"port": 3000,
"useHtmlMinifier": false,
"htmlMinifierOptions": {
"minifyJS": true,
"minifyCSS": true
},
"useOutputCacheTagging": false,
"useOutputCache": false
},
```

Vue Storefront starts an HTTP server to deliver the SSR (server-side rendered) pages and static assets. Its node.js server is located in the `core/scripts/server.js`. This is the hostname and TCP port which Vue Storefront is binding.

When the `useHtmlMinifier` is set to true the generated SSR HTML is being minified [using the `htmlMinifierOptions`](https://www.npmjs.com/package/html-minifier#options-quick-reference).

When the `useOutputCacheTagging` and `useOutputCache` options are enabled, Vue Storefront is storing the rendered pages in the Redis-based output cache. Some additional config options are available for the output cache. [Check the details](ssr-cache.md)

## Seo

Expand Down
7 changes: 7 additions & 0 deletions docs/guide/core-themes/layouts.md
Original file line number Diff line number Diff line change
Expand Up @@ -184,3 +184,10 @@ output = contentPrepend + output + contentAppend;
Please note that the `context` contains a lot of interesting features you can use to control the CSS, SCRIPT and META injection. [Read more on Vue SSR Styles and Scripts injection](https://ssr.vuejs.org/guide/build-config.html#client-config)

**Note: [The context object = Vue.prototype.$ssrContext](https://ssr.vuejs.org/guide/head.html)**


## Output compression

HTML Minifier has been added to Vue Storefront 1.11. To enable this feature please switch the `config.server.useHtmlMinifier`. You can set the specific configuration of the `htmlMinifier` using the `config.server.htmlMinifierOptions`. Read more on the [available configuration](https://www.npmjs.com/package/html-minifier). The minified output is tthen being cached by `SSR Output cache` mechanism.

Output compression has been also enabled (if the `src/modules/server.ts` contains the `compression` module on the list). By default it works just for produdction builds. It uses the `gzip` compression by default. [Read more about the `compression` module](https://www.npmjs.com/package/compression) that we're using for this implementation.
1 change: 1 addition & 0 deletions docs/guide/upgrade-notes/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ We're trying to keep the upgrade process as easy as possible. Unfortunately, som

This is the last major release of Vue Storefront 1.x before 2.0 therefore more manual updates are required to keep external packages compatible with 1.x as long as possible.
- `src/modules/index.ts` was renamed to `client.ts`, exported property was renamed toi `registerClientModules`
- Output compression moddule has been added; it's enabled by default on produdction builds; to disable it please switch the `src/modules/server.ts` configuration
- The [`formatCategoryLink`](https://github.com/DivanteLtd/vue-storefront/blob/develop/core/modules/url/helpers/index.ts) now supports multistore - adding the `storeCode` when necessary; it could have caused double store prefixes like `/de/de` - but probably only in the Breadcrumbs (#3359)
- All modules were refactored to new API. You can still register modules in previous format until 2.0
- `DroppointShipping` and `magento-2-cms `modules were deleted
Expand Down
5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -140,19 +140,19 @@
"file-loader": "^1.1.11",
"fs-exists-sync": "^0.1.0",
"html-webpack-plugin": "^3.2.0",
"husky": "^2.6.0",
"inquirer": "^3.3.0",
"is-windows": "^1.0.1",
"jest": "^24.8.0",
"jest-serializer-vue": "^2.0.2",
"jsonfile": "^4.0.0",
"lerna": "^3.14.1",
"lint-staged": "^8.2.1",
"mkdirp": "^0.5.1",
"node-sass": "^4.12.0",
"phantomjs-prebuilt": "^2.1.10",
"postcss-flexbugs-fixes": "^4.1.0",
"postcss-loader": "^3.0.0",
"husky": "^2.6.0",
"lint-staged": "^8.2.1",
"print-message": "^2.1.0",
"rimraf": "^2.6.0",
"sass-loader": "^7.1.0",
Expand Down Expand Up @@ -196,6 +196,7 @@
"core/i18n",
"src/extensions/*",
"src/modules/*",
"src/trace/*",
"src/themes/*",
"docs",
"core/modules/*",
Expand Down
8 changes: 8 additions & 0 deletions src/modules/compress/server.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@

const compression = require('compression')
module.exports = (app, moduleConfig) => {
if (moduleConfig.enabled) {
console.log('Output Compression is enabled')
app.use(compression(moduleConfig))
}
}
Loading

0 comments on commit 81646c9

Please sign in to comment.