ENH Do not require _config dir or _config.php for modules

This commit is contained in:
Steve Boyd 2024-07-01 16:21:49 +12:00
parent a4149d12cf
commit 98dc238d2a
6 changed files with 62 additions and 0 deletions

View File

@ -18,6 +18,11 @@ class ManifestFileFinder extends FileFinder
const CONFIG_FILE = '_config.php'; const CONFIG_FILE = '_config.php';
const CONFIG_DIR = '_config'; const CONFIG_DIR = '_config';
const COMPOSER_FILE = 'composer.json';
const COMPOSER_TYPES = [
'silverstripe-vendormodule',
'silverstripe-theme',
];
const EXCLUDE_FILE = '_manifest_exclude'; const EXCLUDE_FILE = '_manifest_exclude';
const LANG_DIR = 'lang'; const LANG_DIR = 'lang';
const TESTS_DIR = 'tests'; const TESTS_DIR = 'tests';
@ -179,6 +184,16 @@ class ManifestFileFinder extends FileFinder
return true; 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; return false;
} }

View File

@ -120,4 +120,36 @@ class ManifestFileFinderTest extends SapphireTest
] ]
); );
} }
/**
* 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);
}
}
} }

View File

@ -0,0 +1,3 @@
{
"name": "silverstripe/manifestfilefindertest"
}

View File

@ -0,0 +1,4 @@
{
"name": "silverstripe/manifestfilefindertest",
"type": "silverstripe-somethingelse"
}

View File

@ -0,0 +1,4 @@
{
"name": "silverstripe/manifestfilefindertest",
"type": "silverstripe-theme"
}

View File

@ -0,0 +1,4 @@
{
"name": "silverstripe/manifestfilefindertest",
"type": "silverstripe-vendormodule"
}