From 5cfbe5fa7b92c736dd25d9aa7705ae012983b330 Mon Sep 17 00:00:00 2001
From: Darren Oh <9472-darrenoh@users.noreply.drupalcode.org>
Date: Wed, 12 Feb 2025 00:24:04 +0000
Subject: [PATCH] Issue #3498018: Add configuration for additional known files
 in project root

---
 .../install/package_manager.settings.yml      |  1 +
 .../config/schema/package_manager.schema.yml  |  3 +++
 .../src/PathExcluder/UnknownPathExcluder.php  |  2 ++
 .../PathExcluder/UnknownPathExcluderTest.php  | 25 +++++++++++++++++++
 4 files changed, 31 insertions(+)

diff --git a/package_manager/config/install/package_manager.settings.yml b/package_manager/config/install/package_manager.settings.yml
index edd2c6ed40..0ec2dbcf33 100644
--- a/package_manager/config/install/package_manager.settings.yml
+++ b/package_manager/config/install/package_manager.settings.yml
@@ -2,4 +2,5 @@ executables:
   composer: ~
   rsync: ~
 additional_trusted_composer_plugins: []
+additional_known_files_in_project_root: []
 include_unknown_files_in_project_root: false
diff --git a/package_manager/config/schema/package_manager.schema.yml b/package_manager/config/schema/package_manager.schema.yml
index e048fd67a7..751d004d70 100644
--- a/package_manager/config/schema/package_manager.schema.yml
+++ b/package_manager/config/schema/package_manager.schema.yml
@@ -22,6 +22,9 @@ package_manager.settings:
       sequence:
         type: package_name
         label: 'Trusted composer plugin'
+    additional_known_files_in_project_root:
+      type: sequence
+      label: 'Known files that would otherwise be excluded from staging operations'
     include_unknown_files_in_project_root:
       type: boolean
       label: 'Include unrecognized files and directories in the project root in staging operations'
diff --git a/package_manager/src/PathExcluder/UnknownPathExcluder.php b/package_manager/src/PathExcluder/UnknownPathExcluder.php
index b09a01e053..bafd8f137d 100644
--- a/package_manager/src/PathExcluder/UnknownPathExcluder.php
+++ b/package_manager/src/PathExcluder/UnknownPathExcluder.php
@@ -104,6 +104,8 @@ final class UnknownPathExcluder implements EventSubscriberInterface, LoggerAware
       $web_root,
       'composer.json',
       'composer.lock',
+      ...$this->configFactory->get('package_manager.settings')
+        ->get('additional_known_files_in_project_root'),
     ];
     foreach ($this->getScaffoldFiles() as $scaffold_file_path) {
       // The web root is always included in staging operations, so we don't need
diff --git a/package_manager/tests/src/Kernel/PathExcluder/UnknownPathExcluderTest.php b/package_manager/tests/src/Kernel/PathExcluder/UnknownPathExcluderTest.php
index d68da1cba9..8687fa9885 100644
--- a/package_manager/tests/src/Kernel/PathExcluder/UnknownPathExcluderTest.php
+++ b/package_manager/tests/src/Kernel/PathExcluder/UnknownPathExcluderTest.php
@@ -203,6 +203,31 @@ class UnknownPathExcluderTest extends PackageManagerKernelTestBase {
     }
   }
 
+  /**
+   * Tests that additional known files can be added in config.
+   */
+  public function testExcluderKnownFilesCanBeAdded(): void {
+    $this->createTestProjectForTemplate(TRUE);
+
+    $project_root = $this->container->get(PathLocator::class)
+      ->getProjectRoot();
+    mkdir($project_root . '/known');
+    touch($project_root . '/known/file.txt');
+
+    $config = $this->config('package_manager.settings');
+    $config->set('additional_known_files_in_project_root', ['known'])->save();
+
+    $stage = $this->createStage();
+    $stage->create();
+    $this->assertFileExists($stage->getStageDirectory() . '/known/file.txt');
+    $stage->destroy();
+
+    $config->set('additional_known_files_in_project_root', [])->save();
+    $this->assertFileExists($project_root . '/known/file.txt');
+    $stage->create();
+    $this->assertFileDoesNotExist($stage->getStageDirectory() . '/known/file.txt');
+  }
+
   /**
    * Tests that the excluder can be disabled by a config flag.
    */
-- 
GitLab