diff options
| author | nsfisis <nsfisis@gmail.com> | 2026-02-21 11:18:26 +0900 |
|---|---|---|
| committer | nsfisis <nsfisis@gmail.com> | 2026-02-21 11:18:26 +0900 |
| commit | 8ecb8e5ea476886cb3f62a8efa4a8189e2aa4740 (patch) | |
| tree | 3750a7b722f4d0ceb8435a9b3dc898a8a731e59b /crates/mozart/src/commands | |
| parent | f030dc63ea84a13f1e494a1541b6120c0969f383 (diff) | |
| download | php-mozart-8ecb8e5ea476886cb3f62a8efa4a8189e2aa4740.tar.gz php-mozart-8ecb8e5ea476886cb3f62a8efa4a8189e2aa4740.tar.zst php-mozart-8ecb8e5ea476886cb3f62a8efa4a8189e2aa4740.zip | |
feat(autoload): generate Composer-compatible PHP autoloader files
Implement autoloader generation that produces all standard Composer
autoloader files (autoload.php, autoload_real.php, autoload_static.php,
autoload_psr4.php, autoload_namespaces.php, autoload_classmap.php,
autoload_files.php, installed.php) plus embeds ClassLoader.php,
InstalledVersions.php, and LICENSE from the Composer submodule. Wire
into the install command (gated by --no-autoloader) and replace the
todo!() in dump-autoload with a working implementation.
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Diffstat (limited to 'crates/mozart/src/commands')
| -rw-r--r-- | crates/mozart/src/commands/dump_autoload.rs | 30 | ||||
| -rw-r--r-- | crates/mozart/src/commands/install.rs | 16 |
2 files changed, 44 insertions, 2 deletions
diff --git a/crates/mozart/src/commands/dump_autoload.rs b/crates/mozart/src/commands/dump_autoload.rs index cd932b0..ff3dfc2 100644 --- a/crates/mozart/src/commands/dump_autoload.rs +++ b/crates/mozart/src/commands/dump_autoload.rs @@ -1,4 +1,5 @@ use clap::Args; +use std::path::PathBuf; #[derive(Args)] pub struct DumpAutoloadArgs { @@ -47,6 +48,31 @@ pub struct DumpAutoloadArgs { pub strict_ambiguous: bool, } -pub fn execute(_args: &DumpAutoloadArgs, _cli: &super::Cli) -> anyhow::Result<()> { - todo!() +pub fn execute(args: &DumpAutoloadArgs, cli: &super::Cli) -> anyhow::Result<()> { + let working_dir = match &cli.working_dir { + Some(dir) => PathBuf::from(dir), + None => std::env::current_dir()?, + }; + + let vendor_dir = working_dir.join("vendor"); + let dev_mode = !args.no_dev; + + // Determine suffix: read from existing autoload.php, or from lock file, or generate + let suffix = crate::autoload::determine_suffix(&working_dir, &vendor_dir)?; + + if args.dry_run { + eprintln!("Dry run: would generate autoload files"); + return Ok(()); + } + + crate::autoload::generate(&crate::autoload::AutoloadConfig { + project_dir: working_dir, + vendor_dir, + dev_mode, + suffix, + })?; + + eprintln!("Generated autoload files"); + + Ok(()) } diff --git a/crates/mozart/src/commands/install.rs b/crates/mozart/src/commands/install.rs index ddf7be8..97f42e7 100644 --- a/crates/mozart/src/commands/install.rs +++ b/crates/mozart/src/commands/install.rs @@ -395,6 +395,22 @@ pub fn execute(args: &InstallArgs, cli: &super::Cli) -> anyhow::Result<()> { } new_installed.write(&vendor_dir)?; + + // Step 14: Generate autoloader (unless --no-autoloader) + if !args.no_autoloader { + eprintln!("Generating autoload files"); + + let suffix = lock.content_hash.clone(); + + crate::autoload::generate(&crate::autoload::AutoloadConfig { + project_dir: working_dir.clone(), + vendor_dir: vendor_dir.clone(), + dev_mode, + suffix, + })?; + + eprintln!("Generated autoload files"); + } } Ok(()) |
