Skip to content

Commit

Permalink
Add ignore-npm-dependencies setting
Browse files Browse the repository at this point in the history
  • Loading branch information
PhMemmel committed Mar 7, 2024
1 parent 158d5fd commit a1fce6a
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 8 deletions.
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] [--node-version NODE-VERSION] [--ignore-npm-dependencies]`

Install everything required for CI testing

Expand Down Expand Up @@ -1025,6 +1025,16 @@ Node.js version to use for nvm install (this will override one defined in .nvmrc
* Is negatable: no
* Default: `NULL`

#### `--ignore-npm-dependencies`

Does not execute npm install for the plugin

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

#### `--help|-h`

Display help for the given command. When no command is given display help for the list command
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`
4 changes: 3 additions & 1 deletion src/Command/InstallCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,8 @@ 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('node-version', null, InputOption::VALUE_REQUIRED, 'Node.js version to use for nvm install (this will override one defined in .nvmrc)', $node);
->addOption('node-version', null, InputOption::VALUE_REQUIRED, 'Node.js version to use for nvm install (this will override one defined in .nvmrc)', $node)
->addOption('ignore-npm-dependencies', null, InputOption::VALUE_NONE, 'Does not execute npm install for the plugin');
}

protected function initialize(InputInterface $input, OutputInterface $output): void
Expand Down Expand Up @@ -175,6 +176,7 @@ public function initializeInstallerFactory(InputInterface $input): InstallerFact
$factory->pluginsDir = $pluginsDir;
$factory->noInit = $input->getOption('no-init');
$factory->nodeVer = $input->getOption('node-version');
$factory->ignoreNpmDependencies = $input->getOption('ignore-npm-dependencies');
$factory->database = $resolver->resolveDatabase(
$input->getOption('db-type'),
$input->getOption('db-name'),
Expand Down
3 changes: 2 additions & 1 deletion src/Installer/InstallerFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ class InstallerFactory
public ?string $pluginsDir;
public bool $noInit;
public ?string $nodeVer;
public ?string $ignoreNpmDependencies;

/**
* Given a big bag of install options, add installers to the collection.
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->nodeVer, $this->ignoreNpmDependencies));

if ($this->noInit) {
return;
Expand Down
7 changes: 4 additions & 3 deletions src/Installer/VendorInstaller.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class VendorInstaller extends AbstractInstaller
private MoodlePlugin $plugin;
private Execute $execute;
public ?string $nodeVer;

private ?string $ignoreNpmDependencies;
/**
* 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, ?string $nodeVer, ?string $ignoreNpmDependencies)
{
$this->moodle = $moodle;
$this->plugin = $plugin;
$this->execute = $execute;
$this->nodeVer = $nodeVer;
$this->ignoreNpmDependencies = $ignoreNpmDependencies;
}

public function install(): void
Expand All @@ -69,7 +70,7 @@ public function install(): void
$this->execute->mustRun(
Process::fromShellCommandline('npm install --no-progress', $this->moodle->directory, null, null, null)
);
if ($this->plugin->hasNodeDependencies()) {
if (is_null($this->ignoreNpmDependencies) && $this->plugin->hasNodeDependencies()) {
$this->execute->mustRun(
Process::fromShellCommandline('npm install --no-progress', $this->plugin->directory, null, null, null)
);
Expand Down

0 comments on commit a1fce6a

Please sign in to comment.