Skip to content

Commit

Permalink
feat(sdk): make config optional for the global postprocessor
Browse files Browse the repository at this point in the history
  • Loading branch information
michael-0acf4 committed Mar 13, 2024
1 parent b4eafae commit 99c96ba
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 12 deletions.
13 changes: 5 additions & 8 deletions typegraph/core/src/typegraph.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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());

Expand Down
14 changes: 10 additions & 4 deletions typegraph/core/src/utils/postprocess/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(())
}
Expand Down

0 comments on commit 99c96ba

Please sign in to comment.