Options
All
  • Public
  • Public/Protected
  • All
Menu

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

extends

ConfigFile

example

const localConfig = await Config.retrieve(); localConfig.set('defaultusername', 'username@company.org'); await localConfig.write();

see

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

Hierarchy

Implements

Index

Constructors

constructor

Properties

Protected options

options: Options

Static API_VERSION

API_VERSION: "apiVersion" = "apiVersion"

The api version

type

{string}

Static DEFAULT_DEV_HUB_USERNAME

DEFAULT_DEV_HUB_USERNAME: string = "defaultdevhubusername"

Username associated with the default dev hub org.

type

{string}

Static DEFAULT_USERNAME

DEFAULT_USERNAME: string = "defaultusername"

Username associate with the default org.

type

{string}

Static ISV_DEBUGGER_SID

ISV_DEBUGGER_SID: string = "isvDebuggerSid"

The sid for the debugger configuration.

type

{string}

Static ISV_DEBUGGER_URL

ISV_DEBUGGER_URL: string = "isvDebuggerUrl"

The url for the debugger configuration.

type

{string}

Static USE_BACKUP_POLLING_ORG_CREATE

USE_BACKUP_POLLING_ORG_CREATE: "useBackupPolling.org:create" = "useBackupPolling.org:create"

true if polling should be used over streaming when creating scratch orgs.

type

{string}

Methods

access

  • access(perm: number): Promise<boolean>
  • Determines if the config file is read/write accessible.

    see

    fs.access

    Parameters

    • perm: number

      The permission.

    Returns Promise<boolean>

    true if the user has capabilities specified by perm.

awaitEach

  • awaitEach(actionFn: function): Promise<void>
  • Asynchronously invokes actionFn once for each key-value pair present in the config object.

    Parameters

    • actionFn: function

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

        • Parameters

          Returns Promise<void>

    Returns Promise<void>

clear

  • clear(): void

entries

exists

  • exists(): Promise<boolean>
  • Check to see if the config file exists.

    Returns Promise<boolean>

    True if the config file exists and has access, false otherwise.

forEach

  • forEach(actionFn: function): void
  • Invokes actionFn once for each key-value pair present in the config object.

    Parameters

    • actionFn: function

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

    Returns void

get

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

    Parameters

    • key: string

      The key.

    Returns Optional<ConfigValue>

getContents

getKeysByValue

getPath

  • getPath(): string
  • Returns the path to the config file.

    Returns string

has

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

    Parameters

    • key: string

      The key.

    Returns boolean

Protected init

  • init(): Promise<void>
  • Returns Promise<void>

isGlobal

  • isGlobal(): boolean
  • Returns true if this config is using the global path, false otherwise.

    Returns boolean

keys

  • keys(): string[]
  • Returns an array that contains the keys for each element in the config object.

    Returns string[]

read

set

  • Sets a value for a property.

    throws

    {SfdxError} {name: 'InvalidConfigValue'} Invalid configuration value.

    Parameters

    • key: string
    • value: ConfigValue

      The value of the property.

    Returns ConfigContents

setContents

setContentsFromObject

  • setContentsFromObject<U>(obj: U): void

stat

  • stat(): Promise<fsStats>
  • Get the stats of the file.

    see

    fs.stat

    Returns Promise<fsStats>

    The stats of the file.

toObject

  • toObject(): JsonMap
  • Convert the config object to a JSON object.

    Returns JsonMap

    Returns the config contents. Same as calling ConfigStore.getContents

unlink

  • unlink(): Promise<void>
  • Delete the config file if it exists.

    see

    fs.unlink

    Returns Promise<void>

    True if the file was deleted, false otherwise.

unset

  • unset(key: string): boolean
  • Returns true if an element in the config object existed and has been removed, or false if the element does not exist. {@link BaseConfigStore.has(key)} will return false afterwards.

    Parameters

    • key: string

      The key.

    Returns boolean

unsetAll

  • unsetAll(keys: string[]): 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). {@link BaseConfigStore.has(key)} will return false afterwards.

    Parameters

    • keys: string[]

      The keys.

    Returns boolean

values

write

  • Writes Config properties taking into account encrypted properties.

    Parameters

    • Optional newContents: ConfigContents

      The new Config value to persist.

    Returns Promise<ConfigContents>

Static clear

  • clear(): Promise<void>
  • Clear all the configured properties both local and global.

    Returns Promise<void>

Static create

  • create<P, T>(this: object, options: P): Promise<T>
  • Asynchronously constructs and initializes a new instance of a concrete subclass with the provided options.

    Type parameters

    • P

    • T: AsyncCreatable<P>

    Parameters

    • this: object
    • options: P

      An options object providing initialization params to the async constructor.

    Returns Promise<T>

Static getAllowedProperties

  • Returns ConfigPropertyMeta[]

    Returns an object representing the supported allowed properties.

Static getDefaultOptions

  • getDefaultOptions(isGlobal?: boolean, filename?: undefined | string): Options
  • Parameters

    • Default value isGlobal: boolean = false
    • Optional filename: undefined | string

    Returns Options

Static getFileName

  • getFileName(): string

Static resolveRootFolder

  • resolveRootFolder(isGlobal: boolean): Promise<string>
  • Helper used to determined what the local and global folder point to.

    Parameters

    • isGlobal: boolean

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

    Returns Promise<string>

    The file path of the root folder.

Static retrieve

  • retrieve<T>(options: Options): Promise<T>
  • Creates the config instance and reads the contents of the existing file, if there is one.

    This is the same as

    const myConfig = await MyConfig.create<MyConfig>();
    await myConfig.read();

    Note: Cast to the extended class. e.g. await MyConfig.retrieve<MyConfig>();

    Type parameters

    Parameters

    Returns Promise<T>

Static update

  • update(isGlobal: boolean, propertyName: string, value?: ConfigValue): Promise<any>
  • The value of a supported config property.

    Parameters

    • isGlobal: boolean

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

    • propertyName: string

      The name of the property to set.

    • Optional value: ConfigValue

    Returns Promise<any>