Skip to content

Commit f7bd8e8

Browse files
authored
Merge pull request #84 from php-internal/velox-replace
Support `velox.plugin.replace` option
2 parents 147a67a + f79f0ea commit f7bd8e8

File tree

4 files changed

+33
-3
lines changed

4 files changed

+33
-3
lines changed

dload.xsd

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,11 @@
9595
<xs:documentation>Repository name</xs:documentation>
9696
</xs:annotation>
9797
</xs:attribute>
98+
<xs:attribute name="replace" type="xs:string">
99+
<xs:annotation>
100+
<xs:documentation>Replacement source for the plugin (e.g., local path or alternative repository for Go module replacement)</xs:documentation>
101+
</xs:annotation>
102+
</xs:attribute>
98103
</xs:complexType>
99104
</xs:element>
100105
</xs:sequence>

src/Module/Common/FileSystem/Path.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -184,14 +184,16 @@ public function isFile(): bool
184184

185185
/**
186186
* Return a normalized absolute version of this path
187+
*
188+
* @param non-empty-string|null $cwd Current working directory to resolve relative paths against.
187189
*/
188-
public function absolute(): self
190+
public function absolute(?string $cwd = null): self
189191
{
190192
if ($this->isAbsolute()) {
191193
return $this;
192194
}
193195

194-
$cwd = \getcwd();
196+
$cwd ??= \getcwd();
195197
$cwd === false and throw new \RuntimeException('Cannot get current working directory.');
196198
return self::create($cwd . self::DS . $this->path);
197199
}

src/Module/Config/Schema/Action/Velox/Plugin.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,4 +34,8 @@ final class Plugin
3434
/** @var non-empty-string|null $repository Repository name */
3535
#[XPath('@repository')]
3636
public ?string $repository = null;
37+
38+
/** @var non-empty-string|null $replace Replacement source */
39+
#[XPath('@replace')]
40+
public ?string $replace = null;
3741
}

src/Module/Velox/Internal/Config/Pipeline/Processor/BuildMixinsProcessor.php

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
namespace Internal\DLoad\Module\Velox\Internal\Config\Pipeline\Processor;
66

7+
use Internal\DLoad\Module\Common\FileSystem\Path;
78
use Internal\DLoad\Module\Velox\Internal\Config\Pipeline\ConfigContext;
89
use Internal\DLoad\Module\Velox\Internal\Config\Pipeline\ConfigProcessor;
910

@@ -27,10 +28,28 @@ public function __invoke(ConfigContext $context): ConfigContext
2728
$appliedMixins[] = 'roadrunner_ref';
2829
}
2930

31+
// Merge replacements
32+
foreach ($context->action->plugins as $plugin) {
33+
if ($plugin->replace === null) {
34+
continue;
35+
}
36+
37+
38+
$tomlData = $tomlData->set(
39+
'github.plugins.' . $plugin->name . '.replace',
40+
\str_starts_with($plugin->replace, 'github.com/')
41+
? $plugin->replace
42+
: Path::create($plugin->replace)->absolute()->__toString(),
43+
);
44+
}
45+
46+
3047
$tomlData = $tomlData->set('debug.enabled', $context->action->debug);
3148
$appliedMixins[] = 'debug_enabled';
49+
$tomlData->toToml();
3250

33-
return $context->withTomlData($tomlData)
51+
return $context
52+
->withTomlData($tomlData)
3453
->addMetadata('build_mixins_applied', true)
3554
->addMetadata('applied_mixins', $appliedMixins);
3655
}

0 commit comments

Comments
 (0)