cartridge-resolver-plugin
Advanced tools
Comparing version
{ | ||
"name": "cartridge-resolver-plugin", | ||
"version": "2.0.0", | ||
"version": "2.0.1", | ||
"description": "Webpack Plugin: Provide the cartridge inheritance behavior same as Demandware server side scripts.", | ||
"keywords": ["webpack", "salesforce", "demandware", "cartridge", "compile"], | ||
"keywords": [ | ||
"webpack", | ||
"salesforce", | ||
"demandware", | ||
"cartridge", | ||
"compile" | ||
], | ||
"author": "Vinh Trinh <vinhtrinh.live@gmail.com>", | ||
@@ -19,7 +25,9 @@ "contributers": [ | ||
"mocha": "^5.2.0", | ||
"nyc": "^13.1.0", | ||
"webpack": "^4.27.1" | ||
}, | ||
"scripts": { | ||
"test": "./node_modules/.bin/mocha" | ||
"test": "./node_modules/.bin/nyc mocha", | ||
"coverage": "./node_modules/.bin/nyc report --reporter=lcovonly" | ||
} | ||
} |
222
README.md
@@ -1,37 +0,23 @@ | ||
## Table of Contents | ||
- [Table of Contents](#table-of-contents) | ||
- [Badges and Build status](#badges-and-build-status) | ||
- [Webpack: Cartridge Resolver Plugin](#webpack-cartridge-resolver-plugin) | ||
- [Asset Solving Rules](#asset-solving-rules) | ||
- [Installation](#installation) | ||
- [Usage](#usage) | ||
- [API Documentation](#api-documentation) | ||
- [CartridgeResolverPlugin](#cartridgeresolverplugin) | ||
- [new CartridgeResolverPlugin(cartridges, aliases)](#new-cartridgeresolverplugincartridges-aliases) | ||
- [cartridgeResolverPlugin.apply(resolver)](#cartridgeresolverpluginapplyresolver) | ||
- [cartridgeResolverPlugin.resolve(resolver, requestContext, resolveContext, callback)](#cartridgeresolverpluginresolveresolver-requestcontext-resolvecontext-callback) | ||
- [cartridgeResolverPlugin.isAbsoluteCartridge(assetPath) ⇒ <code>boolean</code>](#cartridgeresolverpluginisabsolutecartridgeassetpath-%E2%87%92-codebooleancode) | ||
- [cartridgeResolverPlugin.isAliasRequest(assetPath) ⇒ <code>boolean</code>](#cartridgeresolverpluginisaliasrequestassetpath-%E2%87%92-codebooleancode) | ||
- [cartridgeResolverPlugin.getRelativeAsset(assetPath) ⇒ <code>string</code>](#cartridgeresolverplugingetrelativeassetassetpath-%E2%87%92-codestringcode) | ||
- [cartridgeResolverPlugin.getCartridge(assetPath) ⇒ <code>string</code>](#cartridgeresolverplugingetcartridgeassetpath-%E2%87%92-codestringcode) | ||
- [cartridgeResolverPlugin.getLocale(assetPath) ⇒ <code>string</code>](#cartridgeresolverplugingetlocaleassetpath-%E2%87%92-codestringcode) | ||
- [cartridgeResolverPlugin.resolveFromCartrdiges(relativeAsset, cartridges, locale) ⇒ <code>string</code> \| <code>null</code>](#cartridgeresolverpluginresolvefromcartrdigesrelativeasset-cartridges-locale-%E2%87%92-codestringcode--codenullcode) | ||
<div align="center"> | ||
<a href="https://github.com/webpack/webpack"> | ||
<img width="200" height="200" src="https://webpack.js.org/assets/icon-square-big.svg"> | ||
</a> | ||
## Badges and Build status | ||
 | ||
 | ||
 | ||
 | ||
[](https://opensource.org/licenses/MIT) | ||
 | ||
[](https://badge.fury.io/js/cartridge-resolver-plugin) | ||
 | ||
 | ||
``` | ||
Test Coverage: 98.55% | ||
+-----------+----------+----------+----------+----------+-------------------+ | ||
| File | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s | | ||
+-----------+----------+----------+----------+----------+-------------------+ | ||
| All files | 98.55 | 90.91 | 100 | 98.44 | | | ||
| index.js | 98.55 | 90.91 | 100 | 98.44 | 62 | | ||
+-----------+----------+----------+----------+----------+-------------------+ | ||
``` | ||
 | ||
 | ||
 | ||
 | ||
# | ||
</div> | ||
## Webpack: Cartridge Resolver Plugin | ||
@@ -112,175 +98,1 @@ | ||
``` | ||
## API Documentation | ||
<a name="CartridgeResolverPlugin"></a> | ||
### CartridgeResolverPlugin | ||
Webpack: Cartridge Resolver Plugin | ||
Provide the cartridge inheritance behavior same as DW server side. | ||
- **Kind**: global class | ||
- **Author**: Vinh Trinh <vinhtrinh.live@gmail.com> | ||
<a name="new_CartridgeResolverPlugin_new"></a> | ||
#### new CartridgeResolverPlugin(cartridges, aliases) | ||
Constructor | ||
| Param | Type | Description | | ||
| --- | --- | --- | | ||
| cartridges | <code>object</code> | An associative object where the key is the cartridge name and the value is the local installed cartridge path | | ||
| aliases | <code>object</code> | An associative object where the key is the alias name and the value is the full cartridge name | | ||
<a name="CartridgeResolverPlugin+apply"></a> | ||
#### cartridgeResolverPlugin.apply(resolver) | ||
Applying the plugin | ||
**Kind**: instance method of [<code>CartridgeResolverPlugin</code>](#CartridgeResolverPlugin) | ||
| Param | Type | | ||
| --- | --- | | ||
| resolver | <code>Resolver</code> | | ||
<a name="CartridgeResolverPlugin+resolve"></a> | ||
#### cartridgeResolverPlugin.resolve(resolver, requestContext, resolveContext, callback) | ||
Do the resolve asset for the given request | ||
Flags: | ||
``` | ||
*: solving asset from across registered cartridges | ||
^: solving asset from registered cartridges which have lower priority with current cartridge | ||
~: solving asset in current cartridge | ||
``` | ||
Absolute asset path using with cartridge name or alias {@see isAbsoluteCartridge} | ||
app_storefront_base:product/product === base:product/product | ||
**Kind**: instance method of [<code>CartridgeResolverPlugin</code>](#CartridgeResolverPlugin) | ||
| Param | Type | Description | | ||
| --- | --- | --- | | ||
| resolver | <code>Resolver</code> | | | ||
| requestContext | <code>object</code> | The asset request object | | ||
| resolveContext | <code>object</code> | | | ||
| callback | <code>function</code> | The callback function | | ||
<a name="CartridgeResolverPlugin+isAbsoluteCartridge"></a> | ||
#### cartridgeResolverPlugin.isAbsoluteCartridge(assetPath) ⇒ <code>boolean</code> | ||
Checks if the given asset is a cartrdige absolute path. | ||
A cartridge absolute path start with cartridge name or alias and separate with asset path a colon `:` | ||
**Kind**: instance method of [<code>CartridgeResolverPlugin</code>](#CartridgeResolverPlugin) | ||
**Returns**: <code>boolean</code> - True if the given asset path is a cartridge absolute path | ||
| Param | Type | Description | | ||
| --- | --- | --- | | ||
| assetPath | <code>string</code> | The asset path | | ||
**Example** | ||
```js | ||
base:checkout/address.js -> true | ||
app_storefront_base:orderHistory/orderHistory.js -> true | ||
wishlists:components/miniCart.js -> true | ||
plugin_wishlists:product/wishlist.js -> true | ||
not_registered_alias:product/details.js -> false | ||
not_registered_cartridge:product/details.js -> false | ||
``` | ||
<a name="CartridgeResolverPlugin+isAliasRequest"></a> | ||
#### cartridgeResolverPlugin.isAliasRequest(assetPath) ⇒ <code>boolean</code> | ||
Checks if the given request asset using an aliased path | ||
**Kind**: instance method of [<code>CartridgeResolverPlugin</code>](#CartridgeResolverPlugin) | ||
**Returns**: <code>boolean</code> - True if the given asset path start with an aliased | ||
| Param | Type | | ||
| --- | --- | | ||
| assetPath | <code>string</code> | | ||
**Example** | ||
```js | ||
base/components/consentTracking -> true | ||
base/components/footer -> true | ||
./components/miniCart -> false | ||
base/components/collapsibleItem -> true | ||
base/components/search -> true | ||
base/components/clientSideValidation -> true | ||
``` | ||
<a name="CartridgeResolverPlugin+getRelativeAsset"></a> | ||
#### cartridgeResolverPlugin.getRelativeAsset(assetPath) ⇒ <code>string</code> | ||
Gets relative path for the given asset without extension follow pattern: | ||
/cartridge/client/{locale}/js/{relativeAsset}.js | ||
**Kind**: instance method of [<code>CartridgeResolverPlugin</code>](#CartridgeResolverPlugin) | ||
**Returns**: <code>string</code> - The relative path to cartridge asset path without extension | ||
| Param | Type | Description | | ||
| --- | --- | --- | | ||
| assetPath | <code>string</code> | The asset path | | ||
**Example** | ||
```js | ||
app_storefront_base/cartridge/client/default/js/product/base.js -> product/base | ||
app_storefront_base/cartridge/client/default/js/components/../cart/cart.js -> cart/cart | ||
plugin_wishlists/cartridge/client/default/js/components/miniCart.js -> components/miniCart | ||
plugin_wishlists/cartridge/client/default/js/product/wishlist.js -> product/wishlist | ||
``` | ||
<a name="CartridgeResolverPlugin+getCartridge"></a> | ||
#### cartridgeResolverPlugin.getCartridge(assetPath) ⇒ <code>string</code> | ||
Extract the cartridge name from the given asset path follow pattern: | ||
/{cartridgeName}/cartridge/client/ | ||
**Kind**: instance method of [<code>CartridgeResolverPlugin</code>](#CartridgeResolverPlugin) | ||
**Returns**: <code>string</code> - The extracted cartridge name, null if no cartridge found | ||
| Param | Type | Description | | ||
| --- | --- | --- | | ||
| assetPath | <code>string</code> | The absolute asset path | | ||
**Example** | ||
```js | ||
project_root/cartridges/app_storefront_base/cartridge/client/default/js/cart/cart.js -> app_storefront_base | ||
project_root/vendors/plugin_wishlists/cartridge/client/default/js/main.js -> plugin_wishlists | ||
project_root/vendors/link_adyen/cartridges/int_adyen_SFRA/cartridge/client/default/js/checkout/billing.js -> int_adyen_SFRA | ||
``` | ||
<a name="CartridgeResolverPlugin+getLocale"></a> | ||
#### cartridgeResolverPlugin.getLocale(assetPath) ⇒ <code>string</code> | ||
Extract locale from the given asset path follow pattern: | ||
/cartridge/client/{locale}/js/ | ||
**Kind**: instance method of [<code>CartridgeResolverPlugin</code>](#CartridgeResolverPlugin) | ||
**Returns**: <code>string</code> - The extracted locale, null if no cartridge found | ||
| Param | Type | Description | | ||
| --- | --- | --- | | ||
| assetPath | <code>string</code> | The absolute asset path | | ||
**Example** | ||
```js | ||
app_storefront_base/cartridge/client/default/js/profile/profile.js -> default | ||
app_storefront_base/cartridge/client/default/js/checkout/billing.js -> default | ||
app_storefront_base/cartridge/client/fr_FR/js/account/addressBook.js -> fr_FR | ||
``` | ||
<a name="CartridgeResolverPlugin+resolveFromCartrdiges"></a> | ||
#### cartridgeResolverPlugin.resolveFromCartrdiges(relativeAsset, cartridges, locale) ⇒ <code>string</code> \| <code>null</code> | ||
Resolve the relative asset using the given cartridge names | ||
**Kind**: instance method of [<code>CartridgeResolverPlugin</code>](#CartridgeResolverPlugin) | ||
**Returns**: <code>string</code> \| <code>null</code> - The absolute path of solved asset. `null` will be returned if nothing found. | ||
| Param | Type | Default | Description | | ||
| --- | --- | --- | --- | | ||
| relativeAsset | <code>string</code> | | The relative request asset without extension | | ||
| cartridges | <code>Array.<string></code> | | List of cartridge names will be lookup for the given request asset | | ||
| locale | <code>string</code> | <code>"default"</code> | Asset locale | | ||
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
20
5.26%1
-50%36302
-18.54%4
33.33%98
-65.73%