Relative path inconsistency in configuration
Bug report
| Question | Answer |
|---|---|
| PHP-Scoper version | 0.18.14@d4e7ffa |
| PHP version | 8.2.8 |
| Platform with version | Windows 11 |
| Github Repo | - |
While 'output-dir' is relative to working dir, until then paths in 'exclude-files' are realtive to config file location. This behavior is not mentioned in documentation and is very confusing.
This is actually a bug.
The configuration file out-dir should be relative to the config file location, any settings from the config file should remain identical regardless of the working directory, hence having them relative to the config file is the sensible behaviour.
Note that the same cannot be said about the executed commands, so if you were to pass a relative path to the command for the output dir, this one should be relative to the working dir.
The fix should be simple: in the Configuration factory if the path is provided it should be made absolute
For me, having relative paths relative to working dir (sources root) seems more logical.
- The files are actually there.
- Also no need to rewrite paths in case config file moved to another place.
If you have:
<?php
// /path/to/project/php-scoper.inc.php
return [
'out-dir' => 'my-dir',
];
The expectation is /path/to/project/my-dir.
If you execute
$ php-scoper add-prefix --out-dir=my-dir
Then the expectation (as for any CLI command that allows a relative directory – make, git, ls, cp, npm, composer etc.) is that the directory used is $(pwd)/my-dir.
Either way it should be documented though.
I have /path/to/project ├─ build ├─ src │ ├── include_me.php │ └── exclude_me.php ├─ scoper │ ├── vendor │ └── scoper.inc.php
/path/to/project/scoper$ vendor/bin/php-scoper add-prefix --working-dir=../src --config=../scoper/scoper.inc.php
// /path/to/project/scoper/scoper.inc.php
$excludedFiles = [
'../src/exclude_me.php',
];
return [
'output-dir' => '../build',
'exclude-files' => [
// 'src/an-excluded-file.php',
...$excludedFiles,
],
];
--configarg is relative to--working-dirarg (/path/to/project/src../scoper/scoper.inc.php)'output-dir'is relative to--working-dir(/path/to/project/src../build)'exclude-files'paths are relative toscoper.inc.phplocation (/path/to/project/scoper../src/exclude_me.php)
Would be more logical to define 'exclude-files' paths relative to --working-dir since the files in question are actualy in working dir. Not to mention what a nightmare it is to maintain config file if its moved to another loaction. All 'exclude-files' paths must be recalculated relative to new config file location. Which is very weird, since all files remained in place inside working dir.