@commerce-klaus/typescript-sfcc

中文文档
1.8.1发布于 2026/11/07MITTypeScriptESM + CJS构建来源已验证近 30 天下载 2124

TypeScript tooling for Salesforce Commerce Cloud cartridge projects

原始使用文档
文档目录5 节
  1. Highlights
  2. What Commerce Klaus adds
  3. Install
  4. Documentation
  5. License

NPM version Downloads

@commerce-klaus/typescript-sfcc

TypeScript tooling for Salesforce Commerce Cloud cartridge projects. It provides cartridge-aware editor resolution, command-line type checking, and project-specific generated types while SFCC runtime code remains JavaScript with JSDoc.

Highlights

  • Resolves dw/*, */, ~/, cartridge aliases, and module.superModule
  • Typechecks cartridges with TypeScript 5.5–6 or the TypeScript 7.1+ native API
  • Generates types for custom attributes, hooks, Custom APIs, and custom job steps with overridable chunk item types
  • Validates hook registrations and statically detectable exports

What Commerce Klaus adds

The official Salesforce B2C Commerce IDE Extension is the preferred foundation for Script API IntelliSense and standard cartridge module resolution in VS Code. The broader Salesforce B2C Developer Tooling also bundles XSD schemas and offers XML validation through its CLI. Commerce Klaus composes with these tools and adds generated project guarantees that can also run outside the editor:

AreaCommerce Klaus additionPractical benefit
Project contractsProjects metadata, hooks.json, Custom API schemas, and steptypes.json into TypeScript declarationsConfiguration and JavaScript implementation are checked together
Super modulesResolves and types module.superModule chainsCartridge overrides remain navigable and type-safe
Type checkingRuns the cartridge-aware TypeScript compiler from the command lineThe same class of diagnostics can block CI without a VS Code extension
Registration validationChecks hook descriptors, referenced scripts, and required CommonJS exportsBroken registrations fail before deployment
Shared toolingReuses the same cartridge semantics across TypeScript, ESLint, Vite, Babel, and Vitest packagesLocal tools agree about which cartridge implementation wins

Install

Salesforce Script API declarations are synchronized through the Salesforce B2C Developer Tooling CLI.

pnpm add -D @commerce-klaus/typescript-sfcc typescript @salesforce/b2c-cli
npm install -D @commerce-klaus/typescript-sfcc typescript @salesforce/b2c-cli
yarn add -D @commerce-klaus/typescript-sfcc typescript @salesforce/b2c-cli
vp install -D @commerce-klaus/typescript-sfcc typescript @salesforce/b2c-cli

While TypeScript 7.1 is on the beta channel, replace typescript with typescript@beta in the command for your package manager.

With TypeScript 5.5–6, enable the editor plugin in a cartridge jsconfig.json or tsconfig.json:

{
  "compilerOptions": {
    "plugins": [{ "name": "@commerce-klaus/typescript-sfcc" }]
  }
}

The plugin composes with the official Salesforce B2C Commerce VS Code extension. Existing language-service resolutions from Salesforce take precedence; Commerce Klaus fills unresolved modules and adds generated project declarations and module.superModule support.

TypeScript 7.1 uses a native language server and no longer loads tsserver plugins. The CLI and type generators support TypeScript 7.1+, but the editor plugin currently requires TypeScript 5.5–6. Projects that only use the CLI and generators can adopt TypeScript 7.1 without installing an older project compiler.

Synchronize types and run the cartridge typecheck:

pnpm exec sfcc-ts-sync-types
pnpm exec sfcc-ts-typecheck
npm exec -- sfcc-ts-sync-types
npm exec -- sfcc-ts-typecheck
yarn exec sfcc-ts-sync-types
yarn exec sfcc-ts-typecheck
vp exec sfcc-ts-sync-types
vp exec sfcc-ts-typecheck

Both standalone commands use the same oclif command implementation as the B2C CLI plugin, including --help, --json, consistent errors, and color-aware terminal output. Typechecks use the TypeScript compiler installed by the project, including when invoked through the B2C CLI plugin.

The Salesforce extension provides editor IntelliSense but does not run a project-wide TypeScript check. Keep sfcc-ts-typecheck in local and CI workflows for reproducible diagnostics outside the editor.

The package API also exposes cleanGeneratedTypes() for removing only the four project-specific sfcc-*.generated.d.ts outputs managed by Commerce Klaus. It preserves synchronized Salesforce Script API types and unrelated declarations, and accepts dryRun: true for a read-only preview.

Documentation

See the complete setup, CLI, and generated types reference.

License

MIT

版本与发布记录

@commerce-klaus/typescript-sfcc 共发布 26 个版本,首次发布于 2026/06/29;过去 12 个月发布了 26 个版本。最新版本附带 npm provenance 构建来源证明,可追溯到公开的 CI 构建记录。

版本发布日期距今
1.8.1latest2026/11/073 天前
1.8.02026/10/2417 天前
1.7.52026/10/081 个月前
1.7.42026/10/051 个月前
1.7.32026/10/011 个月前
1.7.22026/09/261 个月前

关于 @commerce-klaus/typescript-sfcc 的常见问题

@commerce-klaus/typescript-sfcc 是什么?

TypeScript tooling for Salesforce Commerce Cloud cartridge projects

如何安装 @commerce-klaus/typescript-sfcc?

在项目目录运行 npm install @commerce-klaus/typescript-sfcc,或使用 pnpm add / yarn add / bun add。它还需要宿主项目提供 peer 依赖:typescript(>=5.5.0 <7 || >=7.1.0-beta <8)、@salesforce/b2c-cli(>=1.18.0)。npm 7 及以上与 pnpm 8 及以上默认会自动安装必需的 peer 依赖,Yarn 需要手动安装。它还提供命令行工具 sfcc-ts-typecheck、sfcc-ts-sync-types,可以用 npx sfcc-ts-typecheck 直接运行。

@commerce-klaus/typescript-sfcc 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@commerce-klaus/typescript-sfcc 支持 ESM 还是 CommonJS?

同时提供 ES Module 与 CommonJS 入口,import 和 require() 都可以使用,打包工具会自动选择合适的版本。

@commerce-klaus/typescript-sfcc 可以商用吗?

@commerce-klaus/typescript-sfcc 使用 MIT 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

@commerce-klaus/typescript-sfcc 的下载量有多少?

根据 npm 官方下载统计,@commerce-klaus/typescript-sfcc 在 2026/10/11 – 2026/11/09 这 30 天内被下载 2,124 次,日均约 71 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@commerce-klaus/typescript-sfcc 还在维护吗?

最新版本 1.8.1 发布于 2026/11/07(3 天前);至今共发布 26 个版本,其中过去 12 个月发布了 26 个;首次发布于 2026/06/29。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。