@carbon-labs/vscode-snippets

中文文档
0.5.0发布于 2026/05/14Apache-2.0ES Module零依赖构建来源已验证近 30 天下载 4189

Carbon Labs - VSCode snippets for Carbon Design System SCSS

原始使用文档
文档目录13 节
  1. Installation
  2. Viewing Installation Output
  3. Snippet Files
  4. Usage
  5. Example Snippets
  6. How It Works
  7. Compatibility
  8. Notes
  9. Development
  10. Running Tests
  11. Test Coverage
  12. License
  13. Contributing

@carbon-labs/vscode-snippets

VSCode snippets for Carbon Design System SCSS

This package provides code snippets for Carbon Design System SCSS development, compatible with VSCode, IBM Bob, and other VSCode-based IDEs.

Installation

npm install @carbon-labs/vscode-snippets

or

yarn add @carbon-labs/vscode-snippets

The package will automatically install snippet files to your project's .vscode folder via a post-install script.

Viewing Installation Output

To see the installation output, use the --foreground-scripts flag:

npm install @carbon-labs/vscode-snippets --foreground-scripts

Snippet Files

The package installs the following organized snippet files:

  • carbon-general.code-snippets - Block class BEM pattern and @use imports
  • carbon-linter-disables.code-snippets - Stylelint disable comments
  • carbon-spacing.code-snippets - Spacing tokens ($spacing-01 through $spacing-13)
  • carbon-typography.code-snippets - Typography styles (@include type-style)
  • carbon-motion.code-snippets - Duration tokens and motion mixins
  • carbon-theme.code-snippets - Theme-related snippets

Usage

After installation, the snippets are immediately available in your SCSS files. Simply start typing the snippet prefix and the IDE will suggest the completion.

Example Snippets

  • Type block-class to generate a BEM block class structure
  • Type @use spacing to import Carbon spacing utilities
  • Type $spacing-05 to insert the spacing-05 token
  • Type type to access typography style mixins

How It Works

  1. After installation, the package automatically runs a post-install script
  2. The script copies all snippet files from the package to your project's .vscode/ folder
  3. VSCode and compatible IDEs automatically load all .code-snippets files from .vscode/
  4. The snippets become immediately available in your SCSS files

Compatibility

This package works with:

  • Visual Studio Code - Microsoft's official IDE
  • IBM Bob - IBM's VSCode-based IDE
  • VSCodium - Open-source VSCode builds
  • Cursor - AI-powered VSCode-based IDE
  • Any other VSCode-based IDE that supports .code-snippets files

Notes

  • Snippets are installed at the workspace level (.vscode/ folder)
  • Re-running package installation will overwrite any local modifications to the snippet files
  • The .vscode/ folder will be created automatically if it doesn't exist
  • Existing Carbon snippet files (from previous versions) are automatically removed before installation

Development

Running Tests

The package includes comprehensive tests for the installation logic:

cd packages/vscode-snippets
yarn test

Tests cover:

  • Removing old snippet files (both old and new package name formats)
  • Copying snippet files to .vscode directory
  • Error handling for file system operations
  • Integration testing of the complete installation flow

All tests use mocked file system operations and run with Node's experimental VM modules for ES module support.

Test Coverage

  • 12 tests covering all installation scenarios
  • Tests run automatically in CI on every PR and merge
  • Uses Jest with ES module support

License

Apache-2.0

Contributing

This package is part of the Carbon Labs monorepo.

版本与发布记录

@carbon-labs/vscode-snippets 共发布 4 个版本,首次发布于 2026/01/15;过去 12 个月发布了 4 个版本。最新版本附带 npm provenance 构建来源证明,可追溯到公开的 CI 构建记录。

版本发布日期距今
0.5.0latest2026/05/145 个月前
0.4.02026/01/299 个月前
0.3.02026/01/229 个月前
0.2.02026/01/159 个月前

关于 @carbon-labs/vscode-snippets 的常见问题

@carbon-labs/vscode-snippets 是什么?

Carbon Labs - VSCode snippets for Carbon Design System SCSS

如何安装 @carbon-labs/vscode-snippets?

在项目目录运行 npm install @carbon-labs/vscode-snippets,或使用 pnpm add / yarn add / bun add。

@carbon-labs/vscode-snippets 支持 TypeScript 吗?

该包的 package.json 没有声明类型入口。需要类型提示时,可以在 npm 上查找社区维护的 @types/carbon-labs__vscode-snippets 是否存在。

@carbon-labs/vscode-snippets 支持 ESM 还是 CommonJS?

以 ES Module 形式发布,推荐使用 import 引入。在 CommonJS 项目中,Node.js 20.19+ / 22.12+ 可以直接 require() 不含顶层 await 的 ES Module,更早的版本需要改用动态 import()。

@carbon-labs/vscode-snippets 可以商用吗?

@carbon-labs/vscode-snippets 使用 Apache-2.0 许可。宽松许可:允许商业使用、修改和再分发,并附带明确的专利授权;分发时需保留许可与 NOTICE 文件,修改过的文件要注明改动。以上为概括,不构成法律意见,请以许可原文为准。

@carbon-labs/vscode-snippets 的下载量有多少?

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

@carbon-labs/vscode-snippets 还在维护吗?

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