Getting started
Commerce Klaus is a set of focused packages. Adopt only the parts your project needs, or combine them into one consistent SFCC development workflow.
Requirements
- Node.js 22.13 or newer
- An SFCC cartridge project
- Vite+, pnpm, Yarn, or npm
Recommended setup
Start with static runtime checks and cartridge-aware types:
pnpm add -D eslint typescript @salesforce/b2c-cli \
@commerce-klaus/eslint-config-sfcc \
@commerce-klaus/typescript-sfccyarn add -D eslint typescript @salesforce/b2c-cli \
@commerce-klaus/eslint-config-sfcc \
@commerce-klaus/typescript-sfccnpm install -D eslint typescript @salesforce/b2c-cli \
@commerce-klaus/eslint-config-sfcc \
@commerce-klaus/typescript-sfccvp install -D eslint typescript @salesforce/b2c-cli \
@commerce-klaus/eslint-config-sfcc \
@commerce-klaus/typescript-sfccAdd the recommended ESLint flat config:
import { defineConfig } from "eslint/config"
import sfcc from "@commerce-klaus/eslint-config-sfcc"
export default defineConfig(sfcc.configs.recommended)For a faster lint path, Commerce Klaus also exposes its supported SFCC and SiteGenesis rules through Oxlint's JavaScript plugin API:
pnpm add -D oxlint @commerce-klaus/eslint-config-sfccyarn add -D oxlint @commerce-klaus/eslint-config-sfccnpm install -D oxlint @commerce-klaus/eslint-config-sfccvp install -D oxlint @commerce-klaus/eslint-config-sfccimport sfcc from "@commerce-klaus/eslint-config-sfcc/configs/oxlint"
export default sfccOxlint cannot run the three rules whose input is invalid JavaScript syntax. Projects that need those checks can follow Oxlint with the minimal ESLint fallback instead of running the complete ESLint preset twice.
Enable cartridge-aware TypeScript resolution:
{
"compilerOptions": {
"plugins": [{ "name": "@commerce-klaus/typescript-sfcc" }]
}
}Synchronize Salesforce types and check the cartridges:
pnpm exec sfcc-ts-sync-types
pnpm exec sfcc-ts-typecheckyarn exec sfcc-ts-sync-types
yarn exec sfcc-ts-typechecknpm exec -- sfcc-ts-sync-types
npm exec -- sfcc-ts-typecheckvp exec sfcc-ts-sync-types
vp exec sfcc-ts-typecheckTo run the same operations through the Salesforce B2C CLI, add the Commerce Klaus plugin as a development dependency:
pnpm add -D @commerce-klaus/b2c-plugin @salesforce/b2c-cliyarn add -D @commerce-klaus/b2c-plugin @salesforce/b2c-clinpm install -D @commerce-klaus/b2c-plugin @salesforce/b2c-clivp install -D @commerce-klaus/b2c-plugin @salesforce/b2c-cliRegister the project-local plugin after dependency installation:
{
"scripts": {
"prepare": "b2c plugins link node_modules/@commerce-klaus/b2c-plugin --no-install"
}
}The package manager runs prepare during installation. Then use the plugin commands in project scripts or invoke them directly:
pnpm exec b2c klaus types sync
pnpm exec b2c klaus types checkyarn exec b2c klaus types sync
yarn exec b2c klaus types checknpm exec -- b2c klaus types sync
npm exec -- b2c klaus types checkvp exec b2c klaus types sync
vp exec b2c klaus types checkKeep the standalone sfcc-ts-* commands for project-local scripts and CI when plugin installation state should not be shared outside the lockfile.
Add SFCC-aware unit tests
Use the dedicated Vitest integration when tests need to execute cartridge code:
pnpm add -D vitest @commerce-klaus/vitest-sfccyarn add -D vitest @commerce-klaus/vitest-sfccnpm install -D vitest @commerce-klaus/vitest-sfccvp install -D vitest @commerce-klaus/vitest-sfccConfigure the same cartridge path used by the application:
import sfccVitest from "@commerce-klaus/vitest-sfcc"
import { defineConfig } from "vitest/config"
export default defineConfig({
plugins: [
sfccVitest({
basePath: "./cartridges",
cartridgePath: ["app_custom", "app_storefront_base"],
}),
],
})The plugin loads CommonJS cartridge modules with SFCC-aware resolution and provides controlled platform modules, globals, dependency mocks, and harnesses for controllers, hooks, and job steps. See the Vitest integration guide for runtime setup and test examples.
Add local module resolution
Choose the adapter that matches the tool running your server-side code:
- Use the Vitest plugin for unit tests that execute cartridge code.
- Use the Vite plugin when another Vite-based tool needs cartridge-aware module resolution without the test runtime.
- Use the Babel plugin for existing Babel-based tests and tooling.
These integrations use the same resolver core, so */, ~/, cartridge aliases, and module.superModule follow the same ordering rules. Do not configure the Vite and Vitest plugins together; the Vitest package already includes the required module resolution.
Complete example
See the ESLint, TypeScript, and Vitest SFCC example for a runnable two-cartridge setup. It demonstrates a shared cartridge path loaded from the site template, generated SFCC types, custom attributes, hooks, a Custom API, cartridge overrides, and the SFCC-aware Vitest runtime.
For a smaller Vite+ setup, see the Oxlint and ESLint SFCC example. It runs the Oxlint-compatible SFCC rules through Vite+ and follows them with the minimal ESLint fallback while using the same TypeScript and Vite module resolution.