The files where sfdx config values are stored for projects and the global space.

Note: It is not recommended to instantiate this object directly when resolving config values. Instead use ConfigAggregator

const localConfig = await Config.create();
localConfig.set('target-org', 'username@company.org');
await localConfig.write();

https://developer.salesforce.com/docs/atlas.en-us.sfdx_dev.meta/sfdx_dev/sfdx_dev_cli_config_values.htm

Hierarchy

Constructors

Methods

  • Check to see if the config file exists. Returns true if the config file exists and has access, false otherwise.

    Returns Promise<boolean>

  • Invokes actionFn once for each key-value pair present in the config object.

    Parameters

    • actionFn: ((key, value) => void)

      The function (key: string, value: ConfigValue) => void to be called for each element.

        • (key, value): void
        • Parameters

          • key: string
          • value: AnyJson

          Returns void

    Returns void

  • Returns the value associated to the key, or undefined if there is none.

    Type Parameters

    • K extends string

    Parameters

    • key: K

      The key (object property)

    • Optional decrypt: boolean

      If it is an encrypted key, decrypt the value. If the value is an object, a clone will be returned.

    Returns Optional<AnyJson>

  • Type Parameters

    • V = AnyJson

    Parameters

    • key: string
    • Optional decrypt: boolean

    Returns V

  • Returns the entire config contents.

    NOTE: Data will still be encrypted unless decrypt is passed in. A clone of the data will be returned to prevent storing un-encrypted data in memory and potentially saving to the file system.

    Parameters

    • decrypt: boolean = false

    Returns Readonly<ConfigProperties>

  • Returns the absolute path to the config file.

    The first time getPath is called, the path is resolved and becomes immutable. This allows implementers to override options properties, like filePath, on the init method for async creation. If that is required for creation, the config files can not be synchronously created.

    Returns string

  • Get an individual property config.

    Throws SfError{ name: 'UnknownConfigKeyError' } An attempt to get a property that's not supported.

    Parameters

    • propertyName: string

      The name of the property.

    Returns ConfigPropertyMeta

  • Returns a boolean asserting whether a value has been associated to the key in the config object or not.

    Parameters

    • key: string

    Returns boolean

  • Read the config file and set the config contents. Returns the config contents of the config file. As an optimization, files are only read once per process and updated in memory and via write(). To force a read from the filesystem pass force=true. Throws SfError{ name: 'UnexpectedJsonFileFormat' } There was a problem reading or parsing the file.

    Parameters

    • force: boolean = true

      Optionally indicate if a throw should occur on file read.

    Returns ConfigProperties

  • Sets a value for a property.

    Throws SfError{ name: 'UnknownConfigKeyError' } An attempt to get a property that's not supported. Throws SfError{ name: 'InvalidConfigValueError' } If the input validator fails.

    Type Parameters

    • K extends string

    Parameters

    • key: K

      The property to set.

    • value: Optional<AnyJson>

      The value of the property.

    Returns ConfigProperties

  • Delete the config file if it exists.

    Throws Error{ name: 'TargetFileNotFound' } If the ConfigFile.getFilename file is not found. fs.unlink

    Returns Promise<void>

  • Delete the config file if it exists.

    Throws Error{ name: 'TargetFileNotFound' } If the ConfigFile.getFilename file is not found. fs.unlink

    Returns void

  • Unsets a value for a property.

    Throws SfError{ name: 'UnknownConfigKeyError' } If the input validator fails.

    Parameters

    • key: string

      The property to unset.

    Returns boolean

  • Returns true if all elements in the config object existed and have been removed, or false if all the elements do not exist (some may have been removed). (key) will return false afterwards.

    Parameters

    • keys: string[]

      The keys

    Returns boolean

  • Updates the value for the key in the config object. If the value is an object, it will be merged with the existing object.

    Type Parameters

    • K extends string

    Parameters

    • key: K

      The key.

    • value: Partial<Optional<AnyJson>>

      The value.

    Returns void

  • Add an array of allowed config properties.

    Parameters

    Returns void

  • Clear all the configured properties both local and global.

    Returns Promise<void>

  • Helper used to determine what the local and global folder point to. Returns the file path of the root folder.

    Parameters

    • isGlobal: boolean

      True if the config should be global. False for local.

    Returns Promise<string>

  • Helper used to determine what the local and global folder point to. Returns the file path of the root folder.

    Parameters

    • isGlobal: boolean

      True if the config should be global. False for local.

    Returns string

  • The value of a supported config property.

    Type Parameters

    • K extends string

    Parameters

    • isGlobal: boolean

      True for a global config. False for a local config.

    • propertyName: K

      The name of the property to set.

    • Optional value: Optional<AnyJson>

      The property value.

    Returns Promise<ConfigContents<AnyJson>>