Skip to content

Commit

Permalink
NEW Do not require _config dir or _config.php for modules
Browse files Browse the repository at this point in the history
  • Loading branch information
emteknetnz committed Jul 1, 2024
1 parent a4149d1 commit 3507355
Show file tree
Hide file tree
Showing 6 changed files with 62 additions and 0 deletions.
15 changes: 15 additions & 0 deletions src/Core/Manifest/ManifestFileFinder.php
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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;
}

Expand Down
32 changes: 32 additions & 0 deletions tests/php/Core/Manifest/ManifestFileFinderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -120,4 +120,36 @@ public function testIncludeWithRootConfigFolder()
]
);
}

/**
* Note that this phpunit file is unable to use a dataProvider for some unknown eason
*/
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);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"name": "silverstripe/manifestfilefindertest"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"name": "silverstripe/manifestfilefindertest",
"type": "silverstripe-somethingelse"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"name": "silverstripe/manifestfilefindertest",
"type": "silverstripe-theme"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"name": "silverstripe/manifestfilefindertest",
"type": "silverstripe-vendormodule"
}

0 comments on commit 3507355

Please sign in to comment.