From 98dc238d2aec1558a604941f6fc608c789702e03 Mon Sep 17 00:00:00 2001 From: Steve Boyd Date: Mon, 1 Jul 2024 16:21:49 +1200 Subject: [PATCH] ENH Do not require _config dir or _config.php for modules --- src/Core/Manifest/ManifestFileFinder.php | 15 +++++++++ .../Core/Manifest/ManifestFileFinderTest.php | 32 +++++++++++++++++++ .../silverstripe-notype/composer.json | 3 ++ .../silverstripe-somethingelse/composer.json | 4 +++ .../silverstripe-theme/composer.json | 4 +++ .../silverstripe-vendormodule/composer.json | 4 +++ 6 files changed, 62 insertions(+) create mode 100644 tests/php/Core/Manifest/fixtures/manifestfilefinder_rootconfigcomposer/silverstripe-notype/composer.json create mode 100644 tests/php/Core/Manifest/fixtures/manifestfilefinder_rootconfigcomposer/silverstripe-somethingelse/composer.json create mode 100644 tests/php/Core/Manifest/fixtures/manifestfilefinder_rootconfigcomposer/silverstripe-theme/composer.json create mode 100644 tests/php/Core/Manifest/fixtures/manifestfilefinder_rootconfigcomposer/silverstripe-vendormodule/composer.json diff --git a/src/Core/Manifest/ManifestFileFinder.php b/src/Core/Manifest/ManifestFileFinder.php index f2a110db53e..c90b8a2af91 100644 --- a/src/Core/Manifest/ManifestFileFinder.php +++ b/src/Core/Manifest/ManifestFileFinder.php @@ -18,6 +18,11 @@ class ManifestFileFinder extends FileFinder const CONFIG_FILE = '_config.php'; const CONFIG_DIR = '_config'; + const COMPOSER_FILE = 'composer.json'; + const COMPOSER_TYPES = [ + 'silverstripe-vendormodule', + 'silverstripe-theme', + ]; const EXCLUDE_FILE = '_manifest_exclude'; const LANG_DIR = 'lang'; const TESTS_DIR = 'tests'; @@ -179,6 +184,16 @@ public function isDirectoryModule($basename, $pathname, $depth) return true; } + // True if composer type + $path = $pathname . '/' . ManifestFileFinder::COMPOSER_FILE; + if (file_exists($path)) { + $composer = json_decode(file_get_contents($path), true); + $type = $composer['type'] ?? ''; + if (in_array($type, ManifestFileFinder::COMPOSER_TYPES)) { + return true; + } + } + return false; } diff --git a/tests/php/Core/Manifest/ManifestFileFinderTest.php b/tests/php/Core/Manifest/ManifestFileFinderTest.php index 7c0909b10c4..54d88b16c20 100644 --- a/tests/php/Core/Manifest/ManifestFileFinderTest.php +++ b/tests/php/Core/Manifest/ManifestFileFinderTest.php @@ -120,4 +120,36 @@ public function testIncludeWithRootConfigFolder() ] ); } + + /** + * Note that this phpunit file is unable to use a dataProvider for some unknown reason + */ + public function testIsDirectoryModule() + { + $provider = [ + 'vendormodule' => [ + 'silverstripe-vendormodule', + true, + ], + 'theme' => [ + 'silverstripe-theme', + true, + ], + 'somethingelse' => [ + 'silverstripe-somethingelse', + false, + ], + 'notype' => [ + 'silverstripe-notype', + false, + ], + ]; + foreach ($provider as $data) { + list($subdir, $expected) = $data; + $finder = new ManifestFileFinder(); + $pathname = __DIR__ . '/fixtures/manifestfilefinder_rootconfigcomposer/' . $subdir; + $actual = $finder->isDirectoryModule('', $pathname, 0); + $this->assertSame($expected, $actual); + } + } } diff --git a/tests/php/Core/Manifest/fixtures/manifestfilefinder_rootconfigcomposer/silverstripe-notype/composer.json b/tests/php/Core/Manifest/fixtures/manifestfilefinder_rootconfigcomposer/silverstripe-notype/composer.json new file mode 100644 index 00000000000..9bac409be60 --- /dev/null +++ b/tests/php/Core/Manifest/fixtures/manifestfilefinder_rootconfigcomposer/silverstripe-notype/composer.json @@ -0,0 +1,3 @@ +{ + "name": "silverstripe/manifestfilefindertest" +} diff --git a/tests/php/Core/Manifest/fixtures/manifestfilefinder_rootconfigcomposer/silverstripe-somethingelse/composer.json b/tests/php/Core/Manifest/fixtures/manifestfilefinder_rootconfigcomposer/silverstripe-somethingelse/composer.json new file mode 100644 index 00000000000..e52ed0708f4 --- /dev/null +++ b/tests/php/Core/Manifest/fixtures/manifestfilefinder_rootconfigcomposer/silverstripe-somethingelse/composer.json @@ -0,0 +1,4 @@ +{ + "name": "silverstripe/manifestfilefindertest", + "type": "silverstripe-somethingelse" +} diff --git a/tests/php/Core/Manifest/fixtures/manifestfilefinder_rootconfigcomposer/silverstripe-theme/composer.json b/tests/php/Core/Manifest/fixtures/manifestfilefinder_rootconfigcomposer/silverstripe-theme/composer.json new file mode 100644 index 00000000000..4cf824b059b --- /dev/null +++ b/tests/php/Core/Manifest/fixtures/manifestfilefinder_rootconfigcomposer/silverstripe-theme/composer.json @@ -0,0 +1,4 @@ +{ + "name": "silverstripe/manifestfilefindertest", + "type": "silverstripe-theme" +} diff --git a/tests/php/Core/Manifest/fixtures/manifestfilefinder_rootconfigcomposer/silverstripe-vendormodule/composer.json b/tests/php/Core/Manifest/fixtures/manifestfilefinder_rootconfigcomposer/silverstripe-vendormodule/composer.json new file mode 100644 index 00000000000..c19fb08c021 --- /dev/null +++ b/tests/php/Core/Manifest/fixtures/manifestfilefinder_rootconfigcomposer/silverstripe-vendormodule/composer.json @@ -0,0 +1,4 @@ +{ + "name": "silverstripe/manifestfilefindertest", + "type": "silverstripe-vendormodule" +}