Skip to content

Commit 9f74995

Browse files
committed
Only run dump autoload no-dev if target is not vendor
1 parent d8b3f90 commit 9f74995

File tree

2 files changed

+64
-1
lines changed

2 files changed

+64
-1
lines changed

src/Pipeline/Autoload/DumpAutoload.php

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,14 @@ protected function generatedMainAutoloader(): void
111111
// $generator->setApcu($apcu, $apcuPrefix);
112112
// $generator->setPlatformRequirementFilter($this->getPlatformRequirementFilter($input));
113113
$optimize = true; // $input->getOption('optimize') || $config->get('optimize-autoloader');
114-
$generator->setDevMode(false);
114+
115+
/**
116+
* If the target directory is different to the vendor directory, then we do not want to include dev
117+
* dependencies, but if it is vendor, then unless composer install was run with --no-dev, we do want them.
118+
*/
119+
if ($this->config->getVendorDirectory() !== $this->config->getTargetDirectory()) {
120+
$generator->setDevMode(false);
121+
}
115122

116123
$localRepo = new InstalledFilesystemRepository(new JsonFile($this->config->getTargetDirectory() . 'composer/installed.json'));
117124

@@ -179,6 +186,10 @@ protected function createInstalledVersionsFiles(): void
179186

180187
protected function prefixNewAutoloader(): void
181188
{
189+
if ($this->config->getVendorDirectory() === $this->config->getTargetDirectory()) {
190+
return;
191+
}
192+
182193
$this->logger->debug('Prefixing the new Composer autoloader.');
183194

184195
$projectFiles = $this->fileEnumerator->compileFileListForPaths([
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
<?php
2+
/**
3+
* @see https://github.com/BrianHenryIE/strauss/pull/198
4+
*/
5+
6+
namespace BrianHenryIE\Strauss\Tests\Issues;
7+
8+
use BrianHenryIE\Strauss\Tests\Integration\Util\IntegrationTestCase;
9+
10+
/**
11+
* @package BrianHenryIE\Strauss\Tests\Issues
12+
* @coversNothing
13+
*/
14+
class StraussIssue198Test extends IntegrationTestCase
15+
{
16+
public function test_does_not_remove_vendor_autoload_dev_entries()
17+
{
18+
19+
$composerJsonString = <<<'EOD'
20+
{
21+
"require": {
22+
"psr/log": "*"
23+
},
24+
"require-dev": {
25+
"psr/simple-cache": "*"
26+
},
27+
"extra": {
28+
"strauss": {
29+
"target_directory": "vendor",
30+
"namespace_prefix": "Company\\Project\\"
31+
}
32+
}
33+
}
34+
EOD;
35+
36+
chdir($this->testsWorkingDir);
37+
38+
file_put_contents($this->testsWorkingDir . '/composer.json', $composerJsonString);
39+
40+
exec('composer install');
41+
$exitCode = $this->runStrauss($output);
42+
assert(0 === $exitCode, $output);
43+
44+
$php_string = file_get_contents($this->testsWorkingDir . 'vendor/composer/installed.json');
45+
$this->assertStringContainsString("Company\\\\Project\\\\Psr\\\\Log\\\\", $php_string);
46+
$this->assertStringContainsString("\"Psr\\\\SimpleCache\\\\", $php_string);
47+
48+
$php_string = file_get_contents($this->testsWorkingDir . 'vendor/composer/autoload_psr4.php');
49+
$this->assertStringContainsString("Company\\\\Project\\\\Psr\\\\Log\\\\", $php_string);
50+
$this->assertStringContainsString("Psr\\\\SimpleCache\\\\", $php_string);
51+
}
52+
}

0 commit comments

Comments
 (0)