N°7331 - Add NPM cleanup scripts

This commit is contained in:
Molkobain
2024-03-11 13:53:10 +01:00
parent d1a4d333eb
commit f3dd414a51
6 changed files with 140 additions and 2 deletions

View File

@@ -419,6 +419,7 @@ return array(
'Combodo\\iTop\\Core\\Trigger\\Enum\\SubscriptionPolicy' => $baseDir . '/sources/Core/Trigger/Enum/SubscriptionPolicy.php',
'Combodo\\iTop\\Dependencies\\AbstractHook' => $baseDir . '/sources/Dependencies/AbstractHook.php',
'Combodo\\iTop\\Dependencies\\Composer\\iTopComposer' => $baseDir . '/sources/Dependencies/Composer/iTopComposer.php',
'Combodo\\iTop\\Dependencies\\NPM\\iTopNPM' => $baseDir . '/sources/Dependencies/NPM/iTopNPM.php',
'Combodo\\iTop\\DesignDocument' => $baseDir . '/core/designdocument.class.inc.php',
'Combodo\\iTop\\DesignElement' => $baseDir . '/core/designdocument.class.inc.php',
'Combodo\\iTop\\Form\\Field\\AbstractSimpleField' => $baseDir . '/sources/Form/Field/AbstractSimpleField.php',

View File

@@ -794,6 +794,7 @@ class ComposerStaticInit7f81b4a2a468a061c306af5e447a9a9f
'Combodo\\iTop\\Core\\Trigger\\Enum\\SubscriptionPolicy' => __DIR__ . '/../..' . '/sources/Core/Trigger/Enum/SubscriptionPolicy.php',
'Combodo\\iTop\\Dependencies\\AbstractHook' => __DIR__ . '/../..' . '/sources/Dependencies/AbstractHook.php',
'Combodo\\iTop\\Dependencies\\Composer\\iTopComposer' => __DIR__ . '/../..' . '/sources/Dependencies/Composer/iTopComposer.php',
'Combodo\\iTop\\Dependencies\\NPM\\iTopNPM' => __DIR__ . '/../..' . '/sources/Dependencies/NPM/iTopNPM.php',
'Combodo\\iTop\\DesignDocument' => __DIR__ . '/../..' . '/core/designdocument.class.inc.php',
'Combodo\\iTop\\DesignElement' => __DIR__ . '/../..' . '/core/designdocument.class.inc.php',
'Combodo\\iTop\\Form\\Field\\AbstractSimpleField' => __DIR__ . '/../..' . '/sources/Form/Field/AbstractSimpleField.php',

View File

@@ -3,7 +3,7 @@
'name' => 'combodo/itop',
'pretty_version' => 'dev-develop',
'version' => 'dev-develop',
'reference' => '0c3e839381fb70ad7856576de4fc1da17278dfa2',
'reference' => '26e588c1c3f3c4c30b0da3f14e0c4726d49d659e',
'type' => 'project',
'install_path' => __DIR__ . '/../../',
'aliases' => array(),
@@ -22,7 +22,7 @@
'combodo/itop' => array(
'pretty_version' => 'dev-develop',
'version' => 'dev-develop',
'reference' => '0c3e839381fb70ad7856576de4fc1da17278dfa2',
'reference' => '26e588c1c3f3c4c30b0da3f14e0c4726d49d659e',
'type' => 'project',
'install_path' => __DIR__ . '/../../',
'aliases' => array(),

View File

@@ -26,5 +26,9 @@
"showdown": "^2.0.0",
"tippy.js": "^6.2.5",
"toastify-js": "^1.12.0"
},
"scripts": {
"postinstall": "php .make/dependencies/rmUnnecessaryFolders.php --manager npm",
"postupdate": "php .make/dependencies/rmUnnecessaryFolders.php --manager npm"
}
}

View File

@@ -0,0 +1,73 @@
<?php
/**
* Copyright (C) 2010-2023 Combodo SARL
*
* This file is part of iTop.
*
* iTop is free software; you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* iTop is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with iTop. If not, see <http: *www.gnu.org/licenses/>
*
*/
namespace Combodo\iTop\Dependencies\NPM;
use Combodo\iTop\Dependencies\AbstractHook;
class iTopNPM extends AbstractHook
{
/**
* @inheritDoc
*/
protected function GetDependenciesRootFolderAbsPath(): string
{
return $this->GetApprootPathWithSlashes() . "node_modules";
}
/**
* @inheritDoc
*/
public function ListAllowedQuestionnableFoldersAbsPaths(): array
{
$APPROOT_WITH_SLASHES = $this->GetDependenciesRootFolderAbsPath();
return [
// jQuery Sizzle used by jQuery
$APPROOT_WITH_SLASHES . '/jquery/external',
];
}
/**
* @inheritDoc
*/
public function ListDeniedQuestionnableFolderAbsPaths(): array
{
$APPROOT_WITH_SLASHES = $this->GetDependenciesRootFolderAbsPath();
return [
$APPROOT_WITH_SLASHES . '/c3/htdocs',
$APPROOT_WITH_SLASHES . '/clipboard/demo',
$APPROOT_WITH_SLASHES . '/clipboard/test',
$APPROOT_WITH_SLASHES . '/delegate/demo',
$APPROOT_WITH_SLASHES . '/delegate/test',
$APPROOT_WITH_SLASHES . '/good-listener/demo',
$APPROOT_WITH_SLASHES . '/good-listener/test',
$APPROOT_WITH_SLASHES . '/jquery-migrate/test',
$APPROOT_WITH_SLASHES . '/jquery-ui/external',
$APPROOT_WITH_SLASHES . '/jquery-ui-dist/external',
$APPROOT_WITH_SLASHES . '/mousetrap/plugins/record/tests',
$APPROOT_WITH_SLASHES . '/mousetrap/tests',
$APPROOT_WITH_SLASHES . '/select/demo',
$APPROOT_WITH_SLASHES . '/select/test',
$APPROOT_WITH_SLASHES . '/selectize-plugin-a11y/examples',
$APPROOT_WITH_SLASHES . '/tiny-emitter/test',
];
}
}

View File

@@ -0,0 +1,59 @@
<?php
namespace Combodo\iTop\Test\UnitTest\Dependencies\NPM;
use Combodo\iTop\Dependencies\NPM\iTopNPM;
use Combodo\iTop\Test\UnitTest\ItopTestCase;
/**
* Copyright (C) 2010-2023 Combodo SARL
*
* This file is part of iTop.
*
* iTop is free software; you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* iTop is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with iTop. If not, see <http: *www.gnu.org/licenses/>
*
*/
class iTopNPMTest extends ItopTestCase
{
protected function setUp(): void
{
parent::setUp();
clearstatcache();
}
/**
* This is NOT a unit test, this test the iTop instance running the test ...
*/
public function testAllFoldersCovered()
{
$oDependenciesHandler = new iTopNPM();
$aAllowedAndDeniedDirs = array_merge(
$oDependenciesHandler->ListAllowedQuestionnableFoldersAbsPaths(),
$oDependenciesHandler->ListDeniedQuestionnableFolderAbsPaths()
);
$aExistingDirs = $oDependenciesHandler->ListAllQuestionnableFoldersAbsPaths();
$aMissing = array_diff($aExistingDirs, $aAllowedAndDeniedDirs);
$aExtra = array_diff($aAllowedAndDeniedDirs, $aExistingDirs);
$this->assertEmpty(
$aMissing,
'Test dirs exists in /node_modules !'."\n"
.' They must be declared either in the allowed or denied list in '.iTopNPM::class." (see N°2651).\n"
.' List of dirs:'."\n".var_export($aMissing, true)
);
}
}