Skip to content

Commit e65c423

Browse files
authored
Merge pull request #121 from php-etl/fix/autoloads
add autoloads with PHP instead of using JQ
2 parents 3c5e39f + a10bc39 commit e65c423

File tree

1 file changed

+5
-10
lines changed

1 file changed

+5
-10
lines changed

src/Adapter/Composer.php

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,7 @@ public function init(string $name): void
129129
'init',
130130
'--no-interaction',
131131
sprintf('--name=%s', $name),
132+
'--require=php:^8.2',
132133
);
133134

134135
$this->allowPlugins('php-http/discovery');
@@ -163,20 +164,14 @@ public function denyPlugins(string ...$plugins): void
163164
*/
164165
public function autoload(array $autoloads): void
165166
{
167+
$composer = json_decode(file_get_contents($this->workdir.'/composer.json'), true, 512, \JSON_THROW_ON_ERROR);
166168
foreach ($autoloads as $type => $autoload) {
167169
match ($type) {
168-
'psr4' => $this->pipe(
169-
$this->subcommand('cat', 'composer.json'),
170-
$this->subcommand('jq', '--indent', '4', sprintf('.autoload."psr-4" |= . + %s', json_encode($autoload, \JSON_THROW_ON_ERROR))),
171-
$this->subcommand('tee', 'composer.json'),
172-
),
173-
'file' => $this->pipe(
174-
$this->subcommand('cat', 'composer.json'),
175-
$this->subcommand('jq', '--indent', '4', sprintf('.autoload."file" |= . + %s', json_encode($autoload, \JSON_THROW_ON_ERROR))),
176-
$this->subcommand('tee', 'composer.json'),
177-
)
170+
'psr4' => $composer['autoload']['psr-4'] = $autoload,
171+
'file' => $composer['autoload']['file'] = $autoload,
178172
};
179173
}
174+
file_put_contents($this->workdir.'/composer.json', json_encode($composer, \JSON_PRETTY_PRINT | \JSON_UNESCAPED_SLASHES));
180175
}
181176

182177
public function install(): void

0 commit comments

Comments
 (0)