diff options
Diffstat (limited to 'crates/mozart-core/src/composer.rs')
| -rw-r--r-- | crates/mozart-core/src/composer.rs | 12 |
1 files changed, 12 insertions, 0 deletions
diff --git a/crates/mozart-core/src/composer.rs b/crates/mozart-core/src/composer.rs index effcae4..c76f428 100644 --- a/crates/mozart-core/src/composer.rs +++ b/crates/mozart-core/src/composer.rs @@ -644,6 +644,18 @@ impl Composer { create_composer(project_dir, &composer_json).map(Some) } + /// Load Composer state keyed on a specific `composer.json` file, deriving + /// the project directory from `file.parent()`. Mirrors + /// `ValidateCommand::createComposerInstance($file)` — Composer keys + /// instances on a file rather than a directory for non-default paths. + pub fn try_load_from_file(file: &Path) -> anyhow::Result<Option<Self>> { + let project_dir = file + .parent() + .map(Path::to_path_buf) + .unwrap_or_else(|| PathBuf::from(".")); + Self::try_load(project_dir) + } + pub fn project_dir(&self) -> &Path { &self.project_dir } |
