Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add ignore-npm-dependencies setting #277

Merged
merged 2 commits into from
Mar 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 13 additions & 3 deletions docs/CLI.md
Original file line number Diff line number Diff line change
Expand Up @@ -332,7 +332,7 @@ Number of times to rerun failures
Selenium Docker image

* Accept value: yes
* Is value required: no
* Is value required: yes
* Is multiple: no
* Is negatable: no
* Default: `NULL`
Expand Down Expand Up @@ -859,7 +859,7 @@ Install everything required for CI testing

### Usage

* `install [--moodle MOODLE] [--data DATA] [--repo REPO] [--branch BRANCH] [--plugin PLUGIN] [--db-type DB-TYPE] [--db-user DB-USER] [--db-pass DB-PASS] [--db-name DB-NAME] [--db-host DB-HOST] [--db-port DB-PORT] [--not-paths NOT-PATHS] [--not-names NOT-NAMES] [--extra-plugins EXTRA-PLUGINS] [--no-init] [--node-version NODE-VERSION]`
* `install [--moodle MOODLE] [--data DATA] [--repo REPO] [--branch BRANCH] [--plugin PLUGIN] [--db-type DB-TYPE] [--db-user DB-USER] [--db-pass DB-PASS] [--db-name DB-NAME] [--db-host DB-HOST] [--db-port DB-PORT] [--not-paths NOT-PATHS] [--not-names NOT-NAMES] [--extra-plugins EXTRA-PLUGINS] [--no-init] [--no-plugin-node] [--node-version NODE-VERSION]`

Install everything required for CI testing

Expand Down Expand Up @@ -1015,6 +1015,16 @@ Prevent PHPUnit and Behat initialization
* Is negatable: no
* Default: `false`

#### `--no-plugin-node`

Prevent Node.js plugin dependencies installation

* Accept value: no
* Is value required: no
* Is multiple: no
* Is negatable: no
* Default: `false`

#### `--node-version`

Node.js version to use for nvm install (this will override one defined in .nvmrc)
Expand Down Expand Up @@ -2395,4 +2405,4 @@ Do not ask any interactive question
* Is value required: no
* Is multiple: no
* Is negatable: no
* Default: `false`
* Default: `false`
26 changes: 14 additions & 12 deletions src/Command/InstallCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ protected function configure(): void
->addOption('not-names', null, InputOption::VALUE_REQUIRED, 'CSV of file names to exclude', $names)
->addOption('extra-plugins', null, InputOption::VALUE_REQUIRED, 'Directory of extra plugins to install', $extra)
->addOption('no-init', null, InputOption::VALUE_NONE, 'Prevent PHPUnit and Behat initialization')
->addOption('no-plugin-node', null, InputOption::VALUE_NONE, 'Prevent Node.js plugin dependencies installation')
->addOption('node-version', null, InputOption::VALUE_REQUIRED, 'Node.js version to use for nvm install (this will override one defined in .nvmrc)', $node);
}

Expand Down Expand Up @@ -164,18 +165,19 @@ public function initializeInstallerFactory(InputInterface $input): InstallerFact
$pluginsDir = realpath($validate->directory($pluginsDir));
}

$factory = new InstallerFactory();
$factory->moodle = new Moodle($input->getOption('moodle'));
$factory->plugin = new MoodlePlugin($pluginDir);
$factory->execute = $this->execute;
$factory->repo = $validate->gitUrl($input->getOption('repo'));
$factory->branch = $validate->gitBranch($input->getOption('branch'));
$factory->dataDir = $input->getOption('data');
$factory->dumper = $this->initializePluginConfigDumper($input);
$factory->pluginsDir = $pluginsDir;
$factory->noInit = $input->getOption('no-init');
$factory->nodeVer = $input->getOption('node-version');
$factory->database = $resolver->resolveDatabase(
$factory = new InstallerFactory();
$factory->moodle = new Moodle($input->getOption('moodle'));
$factory->plugin = new MoodlePlugin($pluginDir);
$factory->execute = $this->execute;
$factory->repo = $validate->gitUrl($input->getOption('repo'));
$factory->branch = $validate->gitBranch($input->getOption('branch'));
$factory->dataDir = $input->getOption('data');
$factory->dumper = $this->initializePluginConfigDumper($input);
$factory->pluginsDir = $pluginsDir;
$factory->noInit = $input->getOption('no-init');
$factory->noPluginNode = $input->getOption('no-plugin-node');
$factory->nodeVer = $input->getOption('node-version');
$factory->database = $resolver->resolveDatabase(
$input->getOption('db-type'),
$input->getOption('db-name'),
$input->getOption('db-user'),
Expand Down
3 changes: 2 additions & 1 deletion src/Installer/InstallerFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ class InstallerFactory
public ConfigDumper $dumper;
public ?string $pluginsDir;
public bool $noInit;
public bool $noPluginNode;
public ?string $nodeVer;

/**
Expand All @@ -51,7 +52,7 @@ public function addInstallers(InstallerCollection $installers): void
}

$installers->add(new PluginInstaller($this->moodle, $this->plugin, $this->pluginsDir, $this->dumper));
$installers->add(new VendorInstaller($this->moodle, $this->plugin, $this->execute, $this->nodeVer));
$installers->add(new VendorInstaller($this->moodle, $this->plugin, $this->execute, $this->noPluginNode, $this->nodeVer));

if ($this->noInit) {
return;
Expand Down
22 changes: 13 additions & 9 deletions src/Installer/VendorInstaller.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ class VendorInstaller extends AbstractInstaller
private Moodle $moodle;
private MoodlePlugin $plugin;
private Execute $execute;
private bool $noPluginNode;
public ?string $nodeVer;

/**
* Define legacy Node version to use when .nvmrc is absent (Moodle < 3.5).
*/
Expand All @@ -38,12 +38,13 @@ class VendorInstaller extends AbstractInstaller
* @param Execute $execute
* @param string|null $nodeVer
*/
public function __construct(Moodle $moodle, MoodlePlugin $plugin, Execute $execute, ?string $nodeVer)
public function __construct(Moodle $moodle, MoodlePlugin $plugin, Execute $execute, bool $noPluginNode, ?string $nodeVer)
{
$this->moodle = $moodle;
$this->plugin = $plugin;
$this->execute = $execute;
$this->nodeVer = $nodeVer;
$this->moodle = $moodle;
$this->plugin = $plugin;
$this->execute = $execute;
$this->nodeVer = $nodeVer;
$this->noPluginNode = $noPluginNode;
}

public function install(): void
Expand All @@ -64,12 +65,13 @@ public function install(): void

$this->execute->mustRunAll($processes);

$this->getOutput()->step('Install npm dependencies');
$this->getOutput()->step('Install Moodle npm dependencies');

$this->execute->mustRun(
Process::fromShellCommandline('npm install --no-progress', $this->moodle->directory, null, null, null)
);
if ($this->plugin->hasNodeDependencies()) {
if (!$this->noPluginNode && $this->plugin->hasNodeDependencies()) {
$this->getOutput()->step('Install plugin npm dependencies');
$this->execute->mustRun(
Process::fromShellCommandline('npm install --no-progress', $this->plugin->directory, null, null, null)
);
Expand All @@ -82,7 +84,9 @@ public function install(): void

public function stepCount(): int
{
return ($this->canInstallNode()) ? 3 : 2;
return 2 + // Normally 2 steps: global dependencies and Moodle npm dependencies.
($this->canInstallNode() ? 1 : 0) + // Plus Node.js installation.
((!$this->noPluginNode && $this->plugin->hasNodeDependencies()) ? 1 : 0); // Plus plugin npm dependencies step.
}

/**
Expand Down
7 changes: 7 additions & 0 deletions tests/Fixture/plugin/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"name": "VendorInstallerFixture",
"description": "",
"version": "0.1.0",
"dependencies": {},
"devDependencies": {}
}
37 changes: 37 additions & 0 deletions tests/Installer/VendorInstallerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ public function testInstall()
new DummyMoodle($this->moodleDir),
new MoodlePlugin($this->pluginDir),
new DummyExecute(),
false,
null
);
$installer->install();
Expand All @@ -39,6 +40,7 @@ public function testInstallNodeNoNvmrc()
new DummyMoodle($this->moodleDir),
new MoodlePlugin($this->pluginDir),
new DummyExecute(),
false,
null
);

Expand All @@ -58,6 +60,7 @@ public function testInstallNodeUserVersion()
new DummyMoodle($this->moodleDir),
new MoodlePlugin($this->pluginDir),
new DummyExecute(),
false,
$userVersion
);
$installer->installNode();
Expand All @@ -66,4 +69,38 @@ public function testInstallNodeUserVersion()
$this->assertTrue(is_file($this->moodleDir . '/.nvmrc'));
$this->assertSame($userVersion, file_get_contents($this->moodleDir . '/.nvmrc'));
}

public function testInstallNodePluginDependencies()
{
$installer = new VendorInstaller(
new DummyMoodle($this->moodleDir),
new MoodlePlugin($this->pluginDir),
new DummyExecute(),
false,
null
);

$this->fs->copy(__DIR__ . '/../Fixture/plugin/package.json', $this->pluginDir . '/package.json');

$installer->install();

$this->assertSame(4, $installer->getOutput()->getStepCount());
}

public function testSkipNodePluginDependencies()
{
$installer = new VendorInstaller(
new DummyMoodle($this->moodleDir),
new MoodlePlugin($this->pluginDir),
new DummyExecute(),
true,
null
);

$this->fs->copy(__DIR__ . '/../Fixture/plugin/package.json', $this->pluginDir . '/package.json');

$installer->install();

$this->assertSame(3, $installer->getOutput()->getStepCount());
}
}
Loading