I want to access ~/.sfdx/alias.json from an SFDX plug-in. (I know I can use sfdx force:alias for this; it's just an example.) I'm having a very hard time figuring out what the docs at https://forcedotcom.github.io/sfdx-core/classes/configfile.html mean. I can't even see how to do something as basic as finding that file and reading it in. Do I have to hard-wire the file name? Does it know how to find .sfdx wherever it is? Is it too much to hope for a TS typings file for the contents of the alias.json file?

These docs seem to have been auto-generated and to say they're sparse would be an understatement. I looked in vain for a tutorial for using this API. I looked at the implementations of related commands such as force:org:list in salesforce-alm but they seem to use APIs that are not public or accessible.

The specific task I am trying to accomplish is to import and export org information from a home-grown format that some of our internal tools use to and from SFDX.

1 Answer 1


What you need can be achieved by below

import {Aliases, fs} from '@salesforce/core';

//for global aliases it is always .sfdx folder in your root directory
const globalRoot = await Aliases.resolveRootFolder(true); // Make it false for local one

const aliasfileName = Aliases.getFileName(); // alias file name

const result = await fs.readJson(globalRoot + '/.sfdx/' + aliasfileName); // Available values as JSON data type

I am with you that better documentation is required that shows some helpful examples.

  • Thank you for pointing me to the Aliases class. I tried doing Aliases.create({}) as shown in the docs, but TS is unhappy; it says Argument of type '{}' is not assignable to parameter of type 'Options'. Property 'defaultGroup' is missing in type '{}' but required in type 'Options'.ts(2345). What's going on with that? Also, you suggest using fs.readJson, but I notice there is also a read method. Is there some reason to use one or the other?
    – kamezaburo
    Commented May 27, 2020 at 20:16
  • read method does not output as json type. On the other issue I think it needs another question Commented May 27, 2020 at 20:26

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .