From 3cb13f1d7025351615c254b9225a4c5d1bcbd170 Mon Sep 17 00:00:00 2001 From: nsfisis Date: Sat, 27 Jun 2026 19:44:09 +0900 Subject: fix(autoload): correct generated autoloader blank lines PHP heredocs drop the newline before the closing marker, so a two-blank-line fragment must port to "\n\n", not "\n\n\n", and the static initializer needs a "\n" after the $initializer placeholder. This makes autoload_real.php and autoload_static.php byte-identical to Composer's output. Rewrite the templates as raw strings mirroring the PHP heredocs. Co-Authored-By: Claude Opus 4.8 (1M context) --- crates/shirabe/src/autoload/autoload_generator.rs | 98 ++++++++++++++++++++--- 1 file changed, 87 insertions(+), 11 deletions(-) (limited to 'crates/shirabe/src') diff --git a/crates/shirabe/src/autoload/autoload_generator.rs b/crates/shirabe/src/autoload/autoload_generator.rs index 1d0960d..133348c 100644 --- a/crates/shirabe/src/autoload/autoload_generator.rs +++ b/crates/shirabe/src/autoload/autoload_generator.rs @@ -1322,26 +1322,67 @@ impl AutoloadGenerator { check_platform: bool, ) -> String { let mut file = format!( - "register({});\n\n\n", + r#" $loader->register({}); + +"#, prepend_autoloader )); if use_include_files { file.push_str(&format!( - " $filesToLoad = \\Composer\\Autoload\\ComposerStaticInit{}::$files;\n $requireFile = \\Closure::bind(static function ($fileIdentifier, $file) {{\n if (empty($GLOBALS['__composer_autoload_files'][$fileIdentifier])) {{\n $GLOBALS['__composer_autoload_files'][$fileIdentifier] = true;\n\n require $file;\n }}\n }}, null, null);\n foreach ($filesToLoad as $fileIdentifier => $file) {{\n $requireFile($fileIdentifier, $file);\n }}\n\n\n", + r#" $filesToLoad = \Composer\Autoload\ComposerStaticInit{}::$files; + $requireFile = \Closure::bind(static function ($fileIdentifier, $file) {{ + if (empty($GLOBALS['__composer_autoload_files'][$fileIdentifier])) {{ + $GLOBALS['__composer_autoload_files'][$fileIdentifier] = true; + + require $file; + }} + }}, null, null); + foreach ($filesToLoad as $fileIdentifier => $file) {{ + $requireFile($fileIdentifier, $file); + }} + +"#, suffix )); } - file.push_str(" return $loader;\n }\n\n"); + file.push_str( + r#" return $loader; + } +"#, + ); if let Some(target_dir_loader_str) = target_dir_loader { file.push_str(&target_dir_loader_str); @@ -1404,7 +1465,15 @@ impl AutoloadGenerator { base_path: &str, ) -> String { let mut file = format!( - "