You're Invited:Meet the Socket Team at BlackHat and DEF CON in Las Vegas, Aug 4-6.RSVP
Socket
Book a DemoInstallSign in
Socket

cartridge-resolver-plugin

Package Overview
Dependencies
Maintainers
1
Versions
7
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

cartridge-resolver-plugin - npm Package Compare versions

Comparing version

to
2.0.1

sonar-project.properties

14

package.json
{
"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"
}
}

@@ -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://img.shields.io/npm/l/cartridge-resolver-plugin.svg?style=flat-square)
![](https://img.shields.io/github/size/vinhtrinh/cartridge-resolver-plugin/src/index.js.svg?style=flat-square)
![](https://img.shields.io/npm/v/cartridge-resolver-plugin.svg?style=flat-square)
![](https://img.shields.io/npm/dt/cartridge-resolver-plugin.svg?style=flat-square)
[![License: MIT](https://img.shields.io/badge/License-MIT-brightgreen.svg)](https://opensource.org/licenses/MIT)
![Coverage: 98.55%](https://img.shields.io/badge/Coverage-98.55%-brightgreen.svg)
[![npm version](https://badge.fury.io/js/cartridge-resolver-plugin.svg)](https://badge.fury.io/js/cartridge-resolver-plugin)
![](https://img.shields.io/david/vinhtrinh/cartridge-resolver-plugin.svg?style=flat-square)
![](https://img.shields.io/david/dev/vinhtrinh/cartridge-resolver-plugin.svg?style=flat-square)
```
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 |
+-----------+----------+----------+----------+----------+-------------------+
```
![](https://sonarcloud.io/api/project_badges/measure?project=vinhtrinh_cartridge-resolver-plugin&metric=alert_status)
![](https://sonarcloud.io/api/project_badges/measure?project=vinhtrinh_cartridge-resolver-plugin&metric=sqale_rating)
![](https://sonarcloud.io/api/project_badges/measure?project=vinhtrinh_cartridge-resolver-plugin&metric=reliability_rating)
![](https://sonarcloud.io/api/project_badges/measure?project=vinhtrinh_cartridge-resolver-plugin&metric=coverage)
#
</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.&lt;string&gt;</code> | | List of cartridge names will be lookup for the given request asset |
| locale | <code>string</code> | <code>&quot;default&quot;</code> | Asset locale |