1
0
Fork 0

Auto-detect dev-mode in autoload-dump and deprecate dump-autoload --no-dev (#9714)

pull/9542/head
Jordi Boggiano 2021-02-24 21:17:05 +01:00 committed by GitHub
parent 91b6ff27ac
commit d0aac44ed2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 31 additions and 9 deletions

View File

@ -284,7 +284,7 @@ uninstalled.
* **--no-scripts:** Skips execution of scripts defined in `composer.json`. * **--no-scripts:** Skips execution of scripts defined in `composer.json`.
* **--update-no-dev:** Run the dependency update with the --no-dev option. * **--update-no-dev:** Run the dependency update with the --no-dev option.
* **--update-with-dependencies (-w):** Also update dependencies of the removed packages. * **--update-with-dependencies (-w):** Also update dependencies of the removed packages.
(Deprecrated, is now default behavior) (Deprecated, is now default behavior)
* **--update-with-all-dependencies (-W):** Allows all inherited dependencies to be updated, * **--update-with-all-dependencies (-W):** Allows all inherited dependencies to be updated,
including those that are root requirements. including those that are root requirements.
* **--ignore-platform-reqs:** ignore all platform requirements (`php`, `hhvm`, * **--ignore-platform-reqs:** ignore all platform requirements (`php`, `hhvm`,
@ -790,7 +790,8 @@ performance.
* **--apcu:** Use APCu to cache found/not-found classes. * **--apcu:** Use APCu to cache found/not-found classes.
* **--apcu-prefix:** Use a custom prefix for the APCu autoloader cache. * **--apcu-prefix:** Use a custom prefix for the APCu autoloader cache.
Implicitly enables `--apcu`. Implicitly enables `--apcu`.
* **--no-dev:** Disables autoload-dev rules. * **--no-dev:** Disables autoload-dev rules. (Deprecated: Composer now infers this
automatically according to the last `install` or `update` run.)
* **--ignore-platform-reqs:** ignore all `php`, `hhvm`, `lib-*` and `ext-*` * **--ignore-platform-reqs:** ignore all `php`, `hhvm`, `lib-*` and `ext-*`
requirements and skip the [platform check](07-runtime.md#platform-check) for these. requirements and skip the [platform check](07-runtime.md#platform-check) for these.
See also the [`platform`](06-config.md#platform) config option. See also the [`platform`](06-config.md#platform) config option.

View File

@ -162,10 +162,11 @@ class MyClass
} }
``` ```
**Note:** During a composer install or update process, a variable named **Note:** During a Composer `install` or `update` command run, a variable named
`COMPOSER_DEV_MODE` will be added to the environment. If the command was run `COMPOSER_DEV_MODE` will be added to the environment. If the command was run
with the `--no-dev` flag, this variable will be set to 0, otherwise it will be with the `--no-dev` flag, this variable will be set to 0, otherwise it will be
set to 1. set to 1. The variable is also available while `dump-autoload` runs, and it
will be set to same as the last `install` or `update` was run in.
## Event classes ## Event classes

View File

@ -26,6 +26,7 @@ use Composer\Semver\Constraint\MatchAllConstraint;
use Composer\Util\Filesystem; use Composer\Util\Filesystem;
use Composer\Script\ScriptEvents; use Composer\Script\ScriptEvents;
use Composer\Util\PackageSorter; use Composer\Util\PackageSorter;
use Composer\Json\JsonFile;
/** /**
* @author Igor Wiedler <igor@wiedler.ch> * @author Igor Wiedler <igor@wiedler.ch>
@ -44,9 +45,9 @@ class AutoloadGenerator
private $io; private $io;
/** /**
* @var bool * @var ?bool
*/ */
private $devMode = false; private $devMode = null;
/** /**
* @var bool * @var bool
@ -144,6 +145,23 @@ class AutoloadGenerator
$scanPsrPackages = true; $scanPsrPackages = true;
} }
if ($this->runScripts) { if ($this->runScripts) {
$installedJson = new JsonFile($config->get('vendor-dir').'/composer/installed.json');
$isDevInstall = null;
if ($installedJson->exists()) {
$installedJson = $installedJson->read();
$isDevInstall = isset($installedJson['dev']) ? $installedJson['dev'] : null;
}
// auto-set devMode based on whether dev dependencies are installed or not
if (null !== $isDevInstall && null === $this->devMode) {
$this->devMode = $isDevInstall;
}
// set COMPOSER_DEV_MODE in case not set yet so it is available in the dump-autoload autoload
if (!isset($_SERVER['COMPOSER_DEV_MODE'])) {
$_SERVER['COMPOSER_DEV_MODE'] = $this->devMode ? '1' : '0';
putenv('COMPOSER_DEV_MODE='.$_SERVER['COMPOSER_DEV_MODE']);
}
$this->eventDispatcher->dispatchScript(ScriptEvents::PRE_AUTOLOAD_DUMP, $this->devMode, array(), array( $this->eventDispatcher->dispatchScript(ScriptEvents::PRE_AUTOLOAD_DUMP, $this->devMode, array(), array(
'optimize' => (bool) $scanPsrPackages, 'optimize' => (bool) $scanPsrPackages,
)); ));

View File

@ -35,7 +35,7 @@ class DumpAutoloadCommand extends BaseCommand
new InputOption('classmap-authoritative', 'a', InputOption::VALUE_NONE, 'Autoload classes from the classmap only. Implicitly enables `--optimize`.'), new InputOption('classmap-authoritative', 'a', InputOption::VALUE_NONE, 'Autoload classes from the classmap only. Implicitly enables `--optimize`.'),
new InputOption('apcu', null, InputOption::VALUE_NONE, 'Use APCu to cache found/not-found classes.'), new InputOption('apcu', null, InputOption::VALUE_NONE, 'Use APCu to cache found/not-found classes.'),
new InputOption('apcu-prefix', null, InputOption::VALUE_REQUIRED, 'Use a custom prefix for the APCu autoloader cache. Implicitly enables --apcu'), new InputOption('apcu-prefix', null, InputOption::VALUE_REQUIRED, 'Use a custom prefix for the APCu autoloader cache. Implicitly enables --apcu'),
new InputOption('no-dev', null, InputOption::VALUE_NONE, 'Disables autoload-dev rules.'), new InputOption('no-dev', null, InputOption::VALUE_NONE, 'DEPRECATED: Disables autoload-dev rules. Composer now infers this automatically according to the last install or update run.'),
new InputOption('ignore-platform-req', null, InputOption::VALUE_REQUIRED | InputOption::VALUE_IS_ARRAY, 'Ignore a specific platform requirement (php & ext- packages).'), new InputOption('ignore-platform-req', null, InputOption::VALUE_REQUIRED | InputOption::VALUE_IS_ARRAY, 'Ignore a specific platform requirement (php & ext- packages).'),
new InputOption('ignore-platform-reqs', null, InputOption::VALUE_NONE, 'Ignore all platform requirements (php & ext- packages).'), new InputOption('ignore-platform-reqs', null, InputOption::VALUE_NONE, 'Ignore all platform requirements (php & ext- packages).'),
)) ))
@ -77,7 +77,10 @@ EOT
$ignorePlatformReqs = $input->getOption('ignore-platform-reqs') ?: ($input->getOption('ignore-platform-req') ?: false); $ignorePlatformReqs = $input->getOption('ignore-platform-reqs') ?: ($input->getOption('ignore-platform-req') ?: false);
$generator = $composer->getAutoloadGenerator(); $generator = $composer->getAutoloadGenerator();
$generator->setDevMode(!$input->getOption('no-dev')); if ($input->getOption('no-dev')) {
$this->getIO()->writeError('<warning>You are using the deprecated option "--no-dev". Composer now infers the value automatically according to the last install or update run.</warning>');
$generator->setDevMode(false);
}
$generator->setClassMapAuthoritative($authoritative); $generator->setClassMapAuthoritative($authoritative);
$generator->setApcu($apcu, $apcuPrefix); $generator->setApcu($apcu, $apcuPrefix);
$generator->setRunScripts(!$input->getOption('no-scripts')); $generator->setRunScripts(!$input->getOption('no-scripts'));

View File

@ -302,7 +302,6 @@ class Installer
$this->io->writeError('<info>Generating autoload files</info>'); $this->io->writeError('<info>Generating autoload files</info>');
} }
$this->autoloadGenerator->setDevMode($this->devMode);
$this->autoloadGenerator->setClassMapAuthoritative($this->classMapAuthoritative); $this->autoloadGenerator->setClassMapAuthoritative($this->classMapAuthoritative);
$this->autoloadGenerator->setApcu($this->apcuAutoloader, $this->apcuAutoloaderPrefix); $this->autoloadGenerator->setApcu($this->apcuAutoloader, $this->apcuAutoloaderPrefix);
$this->autoloadGenerator->setRunScripts($this->runScripts); $this->autoloadGenerator->setRunScripts($this->runScripts);