Verified Commit 7fb11404 authored by Dave Long's avatar Dave Long
Browse files

fix: #3572084 Dotfiles cannot be ignored cia *.starterkit.yml file

By: yannickoo
By: smustgrave
(cherry picked from commit 2275ac6b)
parent 4d6e1e22
Loading
Loading
Loading
Loading
Loading
+3 −1
Original line number Diff line number Diff line
@@ -295,7 +295,9 @@ private static function loadStarterKitConfig(
      );

      if (count($starterkit_config[$key]) > 0) {
        $files = self::createFilesFinder($theme->getPath())->path($starterkit_config[$key]);
        $files = self::createFilesFinder($theme->getPath())->path($starterkit_config[$key])
          ->ignoreDotFiles(FALSE)
          ->ignoreVCS(TRUE);
        $starterkit_config[$key] = array_map(static fn ($file) => $file->getRelativePathname(), iterator_to_array($files));
        if (count($starterkit_config[$key]) === 0) {
          throw new \RuntimeException("Paths were defined `$key` but no files found.");
+45 −0
Original line number Diff line number Diff line
@@ -599,6 +599,51 @@ public function testIncludeDotFiles(): void {
    self::assertFileExists($theme_path_absolute . '/.gitignore');
  }

  public function testIgnoredDotFiles(): void {
    $this->writeStarterkitConfig([
      'ignore' => [
        '/.npmrc',
      ],
    ]);

    file_put_contents($this->getWorkspaceDirectory() . '/core/themes/starterkit_theme/.npmrc', '*.map');
    $tester = $this->runCommand(
      [
        'machine-name' => 'test_custom_theme',
        '--name' => 'Test custom starterkit theme',
        '--description' => 'Custom theme generated from a starterkit theme',
      ]
    );

    $tester->assertCommandIsSuccessful($tester->getErrorOutput());
    $this->assertThemeExists('themes/test_custom_theme');

    // Verify that the .npmrc file is not present in the generated theme.
    $theme_path_absolute = $this->getWorkspaceDirectory() . '/themes/test_custom_theme';
    self::assertFileDoesNotExist($theme_path_absolute . '/.npmrc');
  }

  public function testExcludedGitFolder(): void {
    $path = $this->getWorkspaceDirectory() . '/core/themes/starterkit_theme/.git';
    mkdir($path);
    file_put_contents($path . '/config', '*.map');

    $tester = $this->runCommand(
      [
        'machine-name' => 'test_custom_theme',
        '--name' => 'Test custom starterkit theme',
        '--description' => 'Custom theme generated from a starterkit theme',
      ]
    );

    $tester->assertCommandIsSuccessful($tester->getErrorOutput());
    $this->assertThemeExists('themes/test_custom_theme');

    // Verify that the .git folder is not present in the generated theme.
    $theme_path_absolute = $this->getWorkspaceDirectory() . '/themes/test_custom_theme';
    self::assertFileDoesNotExist($theme_path_absolute . '/.git');
  }

  private function writeStarterkitConfig(array $config): void {
    $starterkit_yml = $this->getWorkspaceDirectory() . '/core/themes/starterkit_theme/starterkit_theme.starterkit.yml';
    $starterkit_config = Yaml::decode(file_get_contents($starterkit_yml));