Merge pull request #11296 from creative-commoners/pulls/6/manifest-composer

ENH Do not require _config dir or _config.php for modules
This commit is contained in:
Guy Sartorelli 2024-07-02 10:06:13 +12:00 committed by GitHub
commit d96d85248a
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
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_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 @@ class ManifestFileFinder extends FileFinder
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;
}

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"
}