Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Relative path inconsistency in configuration #1058

Open
MIvanIsten opened this issue Jul 3, 2024 · 5 comments
Open

Relative path inconsistency in configuration #1058

MIvanIsten opened this issue Jul 3, 2024 · 5 comments
Labels

Comments

@MIvanIsten
Copy link

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.

@theofidry
Copy link
Member

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.

@theofidry theofidry added the bug label Jul 3, 2024
@theofidry
Copy link
Member

The fix should be simple: in the Configuration factory if the path is provided it should be made absolute

@MIvanIsten
Copy link
Author

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.

@theofidry
Copy link
Member

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.

@MIvanIsten
Copy link
Author

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,
    ],
];
  • --config arg is relative to --working-dir arg (/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 to scoper.inc.php location (/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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants