Use Libraries

We encourage plugin developers to use existing npm libraries that already have the functionality you need. There's no reason to reinvent the wheel.

Salesforce owns and maintains these npm libraries to implement common and useful functionality in your plugin.

@salesforce/core

The @salesforce/core library provides client-side management of Salesforce DX projects, org authentication, connections to Salesforce APIs, and other utilities. Much of the core functionality that powers the Salesforce CLI plugins comes from this library. You can use this functionality in your plugins too.

  • AuthInfo, Org, and Connection classes to interact with Salesforce orgs.
  • Messages class to work with messages in Markdown, JSON, or JavaScript.
  • ConfigFile class to work with configuration files.
  • SfError class to throw errors from your plugin.
  • SfProject class to work with Salesforce project directories.
  • testSetup utility to write unit tests.
  • See API docs for details.

@salesforce/sf-plugins-core

  • SfCommand class, the base class for every sf command.
  • Salesforce specific command flags, such as salesforceId, requiredOrg, requiredHub, and optionalOrg.
  • See API Docs for details.

@salesforce/kit

  • A collection of commonly needed utilities. It includes high level support for parsing and working with JSON data, interacting with environment variables, a minimal lodash replacement, and support for common design patterns.
  • See API docs for details.

@salesforce/source-deploy-retrieve

  • Functionality for working with Salesforce metadata.
  • See API docs for details.

@salesforce/ts-types

  • A collection of commonly used types and type-narrowing convenience functions for writing concise type guards.
  • See API docs for details.

@salesforce/cli-plugins-testkit

  • Testing library that provides utilities to write NUTs (non-unit-tests), such as integration, smoke, and e2e style testing. For example, you can write tests to make sure your plugin commands execute correctly using an isolated Salesforce project, scratch org, and different Salesforce CLI executables
  • See docs and examples for details.

@salesforce/ts-sinon

  • Library for creating test stubs with sinon.

@oclif/core

  • The underlying framework of the entire Salesforce CLI and all its plugins.
  • You don’t need to know much about this library to develop your plugin. But in case you're curious, here are the docs.

We encourage you to use libraries written by other developers in the npm community. Be sure, however, that you do your due diligence to make sure that you're using libraries that are well-maintained by trustworthy developers.

Here are a few libraries that we recommend:

  • got to make HTTP requests.
  • graceful-fs for resilient file system operations.
  • chalk to colorize output.
  • open to open URLs in a web browser.
  • change-case to convert strings between different cases, such as camelCase to TitleCase.
  • sinon, mocha, and chai to test your plugin.