Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ensure sfdx dir exists #716

Merged
merged 1 commit into from
Jun 28, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/shared/orgListUtil.ts
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,10 @@ export class OrgListUtil {
* @param fileNames All the filenames in the global hidden folder
*/
public static async readAuthFiles(fileNames: string[]): Promise<AuthInfo[]> {
// Ensure that the Global.SFDX_DIR exists
// https://github.com/forcedotcom/cli/issues/2222
await fs.mkdir(Global.SFDX_DIR, { recursive: true });
Copy link
Contributor

@WillieRuemmele WillieRuemmele Jun 16, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this'll throw if the directory already exists though, do we need to wrap this in try/catch?

just testing this in dreamhouse

 ➜  ls
1686770905635-command-debug.log  CODE_OF_CONDUCT.md               SECURITY.md                      data                             jest.config.js                   tests
1686770905635-command-stdout.log CONTRIBUTION.md                  bin                              dreamhouse-logo.png              package-lock.json
1686770924292-command-debug.log  LICENSE                          codecov.yml                      force-app                        package.json
1686770924292-command-stdout.log README.md                        config                           jest-sa11y-setup.js              sfdx-project.json
➜  dreamhouse-lwc git:(main) ✗  hub:(DevHub) scratch:([email protected])
 ➜  node   
Welcome to Node.js v18.16.0.
Type ".help" for more information.
> fs.mkdirSync('config')
Uncaught Error: EEXIST: file already exists, mkdir 'config'
    at Object.mkdirSync (node:fs:1396:3) {
  errno: -17,
  syscall: 'mkdir',
  code: 'EEXIST',
  path: 'config'
}

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh! I didn't look closely at what you were testing. The mkdir function will throw if you are not passing { recursive: true } (docs). I just tested this code several more times and it is working as expected.


const orgFileNames = (await fs.readdir(Global.SFDX_DIR)).filter((filename: string) =>
filename.match(/^00D.{15}\.json$/g)
);
Expand Down