From 99c96ba6d8b021216142dabcf9f195e153834d8f Mon Sep 17 00:00:00 2001
From: afmika <afmichael73@gmail.com>
Date: Wed, 13 Mar 2024 13:38:20 +0300
Subject: [PATCH] feat(sdk): make config optional for the global postprocessor

---
 typegraph/core/src/typegraph.rs             | 13 +++++--------
 typegraph/core/src/utils/postprocess/mod.rs | 14 ++++++++++----
 2 files changed, 15 insertions(+), 12 deletions(-)

diff --git a/typegraph/core/src/typegraph.rs b/typegraph/core/src/typegraph.rs
index f237b74267..181c8d2f32 100644
--- a/typegraph/core/src/typegraph.rs
+++ b/typegraph/core/src/typegraph.rs
@@ -215,14 +215,11 @@ pub fn finalize(res_config: Option<ArtifactResolutionConfig>) -> Result<String>
         deps: Default::default(),
     };
 
-    if let Some(config) = res_config {
-        // Typically happens when the cli is used
-        if let Some(prefix) = config.prefix.clone() {
-            tg.meta.prefix = Some(prefix);
-        }
-
-        TypegraphPostProcessor::new(config).postprocess(&mut tg)?;
-    }
+    let config = res_config.map(|config| {
+        tg.meta.prefix = config.prefix.clone();
+        config
+    });
+    TypegraphPostProcessor::new(config).postprocess(&mut tg)?;
 
     Store::restore(ctx.saved_store_state.unwrap());
 
diff --git a/typegraph/core/src/utils/postprocess/mod.rs b/typegraph/core/src/utils/postprocess/mod.rs
index af508fb698..3999735e71 100644
--- a/typegraph/core/src/utils/postprocess/mod.rs
+++ b/typegraph/core/src/utils/postprocess/mod.rs
@@ -24,22 +24,28 @@ pub trait PostProcessor {
 
 /// Compose all postprocessors
 pub struct TypegraphPostProcessor {
-    config: ArtifactResolutionConfig,
+    config: Option<ArtifactResolutionConfig>,
 }
 
 impl TypegraphPostProcessor {
-    pub fn new(config: ArtifactResolutionConfig) -> Self {
+    pub fn new(config: Option<ArtifactResolutionConfig>) -> Self {
         Self { config }
     }
 }
 
 impl PostProcessor for TypegraphPostProcessor {
     fn postprocess(self, tg: &mut Typegraph) -> Result<(), TgError> {
-        Store::set_deploy_cwd(self.config.dir);
-        PrismaProcessor::new(self.config.prisma_migration).postprocess(tg)?;
+        if let Some(config) = self.config {
+            Store::set_deploy_cwd(config.dir); // fs_host::cwd() will now use this value
+            PrismaProcessor::new(config.prisma_migration).postprocess(tg)?;
+        }
+
+        // Artifact resolution depends on the default cwd() (parent process)
+        // unless overwritten by `dir` through Store::set_deploy_cwd(..) (cli or custom dir with tgDeploy)
         DenoProcessor.postprocess(tg)?;
         PythonProcessor.postprocess(tg)?;
         WasmedgeProcessor.postprocess(tg)?;
+
         ValidationProcessor.postprocess(tg)?;
         Ok(())
     }