From ebdb00397b2af92a2b3812a6dd2f8c997fd4797e Mon Sep 17 00:00:00 2001 From: mshanemc Date: Tue, 13 Aug 2024 12:38:27 -0500 Subject: [PATCH] feat: refresh a project --- src/sfProject.ts | 14 ++++++++++++++ src/testSetup.ts | 3 +-- 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/src/sfProject.ts b/src/sfProject.ts index 5980a2d37..c89c22c18 100644 --- a/src/sfProject.ts +++ b/src/sfProject.ts @@ -84,6 +84,12 @@ export class SfProjectJson extends ConfigFile { return contents; } + /** force a reread of the project contents if you know they may have been modified */ + public refreshSync(): SfProjectJson { + super.readSync(false, true); + return this; + } + public readSync(): ProjectJson { const contents = super.readSync(); this.validateKeys(); @@ -369,6 +375,14 @@ export class SfProject { */ protected constructor(private path: string) {} + /** + * Clear the cache to force reading from disk. + * + * *NOTE: Only call this method if you must and you know what you are doing.* + */ + public static clearInstances(): void { + SfProject.instances.clear(); + } /** * Get a Project from a given path or from the working directory. * diff --git a/src/testSetup.ts b/src/testSetup.ts index b126782c6..e664994c6 100644 --- a/src/testSetup.ts +++ b/src/testSetup.ts @@ -666,8 +666,7 @@ export const restoreContext = (testContext: TestContext): void => { testContext.configStubs = {}; // Give each test run a clean StateAggregator StateAggregator.clearInstance(); - // @ts-expect-error accessing a private property - SfProject.instances.clear(); + SfProject.clearInstances(); // Allow each test to have their own config aggregator // @ts-ignore clear for testing. delete ConfigAggregator.instance;