Git Product home page Git Product logo

babel-plugin-sfcc-modules's Introduction

NPM version Downloads star this repo fork this repo CI Coverage Status

babel-plugin-sfcc-modules

Babel plugin to handle non-standard module paths used by Salesforce Commerce Cloud (SFCC)

Server-side code for Salesforce Commerce Cloud uses non-standard module resolution patterns:

  • first matching cartridge from cartridge path
require('*/cartridge/scripts/foo')
  • current cartridge
require('~/cartridge/scripts/bar')

Also there is a non-standard extension

module.superModule

to reference the next match in cartridge path for the current module.

Node.js does not have solutions for these cases.. This can cause problems when you need to run this code in a Node.js environment. The most common case should be for unit testing.

This plugin removes the pain of dealing with modules like proxyquire or sandboxed-module.

Install

$ yarn add babel-plugin-sfcc-modules --dev

Usage

Add to your Babel configuration:

"plugins": [
  ["babel-plugin-sfcc-modules", {
    "cartridgePath": [
      "app_brand",
      "app_core",
      "app_storefront_base"
    ],
    "basePath": "./path/to/cartridges"
  }]
]

Options

Option Type Description
cartridgePath Array the cartridge path used for lookup
basePath string path to the folder containing the cartridges

️️⚠️️️️⚠️⚠️ Warning ⚠️⚠️⚠️

kitten.png

You shouldn't use it for frontend code. There are better alternatives to deal with a cartridge path, NODE_PATH and the handling of frontend assets in sgmf-scripts.

In my opinion the best way to handle frontend code is to have a clean configuration of Webpack aliases.

The cartridge path concept isn't common for Node.js/frontend code. This plugin will work for it but I won't officially support it.

License

MIT © 2023 Jens Simon

babel-plugin-sfcc-modules's People

Contributors

dependabot[bot] avatar jenssimon avatar renovate-bot avatar renovate[bot] avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

babel-plugin-sfcc-modules's Issues

Dependency Dashboard

This issue lists Renovate updates and detected dependencies. Read the Dependency Dashboard docs to learn more.

Open

These updates have all been created already. Click a checkbox below to force a retry/rebase of any.

Detected dependencies

github-actions
.github/workflows/ci.yml
  • actions/checkout v4
  • actions/setup-node v4
  • codecov/codecov-action v4
  • actions/checkout v4
  • actions/setup-node v4
.github/workflows/codeql-analysis.yml
  • actions/checkout v4
  • github/codeql-action v3
  • github/codeql-action v3
  • github/codeql-action v3
.github/workflows/commitlint.yml
  • actions/checkout v4
  • wagoid/commitlint-github-action v6
npm
package.json
  • @babel/types ^7.23.0
  • imports-visitor ^2.0.0
  • @babel/core ^7.23.2
  • @babel/eslint-parser ^7.22.15
  • @commitlint/cli ^19.0.0
  • @commitlint/config-conventional ^19.0.0
  • @jenssimon/eslint-config-base ^7.3.1
  • @jenssimon/eslint-config-sfcc ^4.8.0
  • @jest/globals ^29.7.0
  • commitizen ^4.3.0
  • cz-conventional-changelog ^3.3.0
  • eslint ^8.52.0
  • husky ^9.0.0
  • jest ^29.7.0
  • lint-staged ^15.0.2
  • pinst ^3.0.0
  • semantic-release ^23.0.0
  • yarn 4.2.2
nvm
.nvmrc
  • node 20.13.1

  • Check this box to trigger a request for Renovate to run again on this repository

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.