From 282a9d143c4c77988ce7465e29d78f206f3b1fd9 Mon Sep 17 00:00:00 2001 From: Fake Fake Date: Fri, 13 Dec 2024 12:43:52 -0500 Subject: [PATCH 1/5] Ensure that included files are actually included This resolves an issue where an ignored file will supercede an explicit include. Example: 1. If `.distfiles` includes `/node_modules/clipboard/**/*.min.js` 2. If `.distignore` includes `/node_modules`, it will override the above The fix is that if a file is a match for a `.distfiles` or `.distinclude`, that should win and the ignore is skipped. --- src/Commands/Package.php | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/Commands/Package.php b/src/Commands/Package.php index 2618b41..0e0f052 100644 --- a/src/Commands/Package.php +++ b/src/Commands/Package.php @@ -406,11 +406,17 @@ protected function syncFiles( string $root, string $destination ): int { foreach ( $iterator as $item ) { $path = ltrim( $iterator->getSubPathName(), '/\\' ); - if ( ! $this->isIncludedFile( $path, $include ) ) { + if ( strpos( $path, '.pup' ) !== false ) { continue; } - if ( $this->isIgnoredFile( $path, $ignore ) ) { + $is_included_file = $this->isIncludedFile( $path, $include ); + + if ( ! $is_included_file ) { + continue; + } + + if ( ! $is_included_file && $this->isIgnoredFile( $path, $ignore ) ) { continue; } From 8a276e9db6a4865c28b3bded45ebec2f7e0fb03b Mon Sep 17 00:00:00 2001 From: Fake Fake Date: Fri, 13 Dec 2024 14:48:16 -0500 Subject: [PATCH 2/5] Only include .distignore if .distfiles is absent --- src/Commands/Package.php | 92 ++++++++++++++++++++++++++++------------ 1 file changed, 66 insertions(+), 26 deletions(-) diff --git a/src/Commands/Package.php b/src/Commands/Package.php index 0e0f052..d01ecb4 100644 --- a/src/Commands/Package.php +++ b/src/Commands/Package.php @@ -201,6 +201,22 @@ protected function createZip( string $dir_to_zip, string $zip_filename, string $ return 0; } + /** + * Get the default things to exclude from sync. + * + * @return array + */ + public function getDefaultIgnoreLines(): array { + $working_dir = App::getConfig()->getWorkingDir(); + $zip_dir = str_replace( $working_dir, '', App::getConfig()->getZipDir() ); + + return [ + '.puprc', + '.pup-*', + $zip_dir, + ]; + } + /** * Get the files to exclude from sync. * @@ -230,33 +246,54 @@ public function getIgnoreLines( string $source ): array { } /** - * Get the files to include in sync. + * Get the distfiles lines to include in sync. * * @param string $source * * @return array */ - public function getIncludeLines( string $source ): array { - $include = []; - $include_files = [ - '.pup-distinclude', - '.pup-distfiles', - ]; + public function getDistfilesLines( string $source ): array { + $include = []; + $include_file = '.pup-distfiles'; - foreach ( $include_files as $include_file ) { - if ( ! file_exists( $source . $include_file ) ) { - continue; - } + if ( ! file_exists( $source . $include_file ) ) { + return []; + } - $lines = file( $source . $include_file, FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES ); + $lines = file( $source . $include_file, FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES ); - if ( ! $lines ) { - continue; - } + if ( ! $lines ) { + return []; + } + + $include = array_merge( $include, $lines ); - $include = array_merge( $include, $lines ); + return $include; + } + + /** + * Get the distinclude lines to include in sync. + * + * @param string $source + * + * @return array + */ + public function getDistincludeLines( string $source ): array { + $include = []; + $include_file = '.pup-include'; + + if ( ! file_exists( $source . $include_file ) ) { + return []; + } + + $lines = file( $source . $include_file, FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES ); + + if ( ! $lines ) { + return []; } + $include = array_merge( $include, $lines ); + return $include; } @@ -392,8 +429,17 @@ protected function syncFiles( string $root, string $destination ): int { $this->buildSyncFiles( $source ); - $include = $this->getIncludeLines( $source ); - $ignore = $this->getIgnoreLines( $source ); + $distfiles = $this->getDistfilesLines( $source ); + $distinclude = $this->getDistincludeLines( $source ); + $include = array_merge( $distfiles, $distinclude ); + + $ignore = $this->getDefaultIgnoreLines(); + + // We only observe .distignore if there is no .distfiles files. + if ( empty( $distfiles ) ) { + $ignore = array_merge( $ignore, $this->getIgnoreLines( $source ) ); + } + $results = $this->migrateNegatedLines( $include, $ignore ); $include = $results['include']; $ignore = $results['ignore']; @@ -406,17 +452,11 @@ protected function syncFiles( string $root, string $destination ): int { foreach ( $iterator as $item ) { $path = ltrim( $iterator->getSubPathName(), '/\\' ); - if ( strpos( $path, '.pup' ) !== false ) { - continue; - } - - $is_included_file = $this->isIncludedFile( $path, $include ); - - if ( ! $is_included_file ) { + if ( ! $this->isIncludedFile( $path, $include ) ) { continue; } - if ( ! $is_included_file && $this->isIgnoredFile( $path, $ignore ) ) { + if ( $this->isIgnoredFile( $path, $ignore ) ) { continue; } From b773c8f5424c8ff667c00005c603965717d8285c Mon Sep 17 00:00:00 2001 From: Fake Fake Date: Fri, 13 Dec 2024 14:57:17 -0500 Subject: [PATCH 3/5] Add messaging about ignoring .distignore --- src/Commands/Package.php | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/Commands/Package.php b/src/Commands/Package.php index d01ecb4..d19ea09 100644 --- a/src/Commands/Package.php +++ b/src/Commands/Package.php @@ -84,6 +84,13 @@ protected function execute( InputInterface $input, OutputInterface $output ) { $output->writeln( '✓ Updating version files...Complete.' ); $output->writeln( '- Synchronizing files to zip directory...' ); + + $distfiles = $this->getDistfilesLines( $root ); + if ( ! empty( $distfiles ) ) { + $distfiles_message = '>>> Your project has a .distfiles file, so .distignore and pup\'s default ignore rules will not be used.'; + $output->writeln( "{$distfiles_message}" ); + } + $pup_zip_dir = $config->getZipDir(); DirectoryUtils::rmdir( $pup_zip_dir ); From a1c652903f4dd688624dfd7789663bd46cbe1754 Mon Sep 17 00:00:00 2001 From: Fake Fake Date: Fri, 13 Dec 2024 14:59:14 -0500 Subject: [PATCH 4/5] Properly find the distfile --- src/Commands/Package.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Commands/Package.php b/src/Commands/Package.php index d19ea09..9c70804 100644 --- a/src/Commands/Package.php +++ b/src/Commands/Package.php @@ -85,7 +85,7 @@ protected function execute( InputInterface $input, OutputInterface $output ) { $output->writeln( '- Synchronizing files to zip directory...' ); - $distfiles = $this->getDistfilesLines( $root ); + $distfiles = $this->getDistfilesLines( $this->getSourceDir( $root ) ); if ( ! empty( $distfiles ) ) { $distfiles_message = '>>> Your project has a .distfiles file, so .distignore and pup\'s default ignore rules will not be used.'; $output->writeln( "{$distfiles_message}" ); From 5b9e907f05c0150a380d96b59395dc306942ada6 Mon Sep 17 00:00:00 2001 From: Fake Fake Date: Fri, 13 Dec 2024 17:50:22 -0500 Subject: [PATCH 5/5] Updating version --- pup | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pup b/pup index f46b7bd..a337df7 100755 --- a/pup +++ b/pup @@ -3,7 +3,7 @@ namespace StellarWP\Pup; -const PUP_VERSION = '1.3.7'; +const PUP_VERSION = '1.3.8'; define( '__PUP_DIR__', __DIR__ ); if ( ! \Phar::running() ) {