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

Invalid relative path used on Windows #94

Closed
szaleq opened this issue Apr 18, 2024 · 3 comments · Fixed by #100
Closed

Invalid relative path used on Windows #94

szaleq opened this issue Apr 18, 2024 · 3 comments · Fixed by #100

Comments

@szaleq
Copy link

szaleq commented Apr 18, 2024

Strauss creates invalid "relative" file paths on Windows, which are actually absolute. It causes an error: Unable to read file from location: (...), because it prepends the so called relative path with an absolute project path, creating paths which contain the absolute project base path twice.

Steps to reproduce

  1. Clone this repo on Windows: https://github.com/szaleq/strauss-example
  2. run composer install
  3. run composer prefix-namespaces
  4. see the error:
Unable to read file from location: I:/strauss-example/vendor/react/promise/src/functions_include.php. file_get_contents(I:\strauss-example\I:/strauss-example/vendor/react/promise/src/functions_include.php): Failed to open stream: No such file or directory

image

The solution

Here there is a line, which creates "relative" source file path using $vendorDir, which is an absolute path (at least on Windows - IDK how it behaves in other environments). Instead the $workingDir could be subtracted from the $sourceAbsolutePath to create a relative path (which actually works):

$sourceRelativePath = str_replace($this->workingDir, '', $sourceAbsolutePath);
@BrianHenryIE
Copy link
Owner

BrianHenryIE commented Apr 19, 2024

Yeah, $vendorDir = $config->getVendorDirectory() is a relative path on my Mac, i.e. just vendor/, meant to be relative from the project root.

I'm aware it doesn't work on Windows, see #30 for possible cause/solution.

Unfortunately I don't have or use a Windows computer myself, so the motivation to resolve this has been low. (i.e. I fix easier to fix problems first!)

I did add Windows to the GitHub Actions CI text matrix recently: 457b53c, so I do intend to address this, and your issue might help quite a bit.

It looks like something is going wrong here:

$vendorDirectory = str_replace($absolutePathDir, '', (string) $vendorDirectory);

BrianHenryIE added a commit that referenced this issue Apr 24, 2024
@BrianHenryIE
Copy link
Owner

That should work now. Please test dev-master and let me know. 148caba

@szaleq
Copy link
Author

szaleq commented Apr 24, 2024

@BrianHenryIE Thaks for the quick action. Unfortunately, it still does not work, now with the following error:

Unable to read file from location: vendor/src/I:/strauss-example/vendor/brianhenryie/strauss/src/Autoload.php. file_get_contents(I:\strauss-example\vendor/src/I:/strauss-example/vendor/brianhenryie/strauss/src/Autoload.php): Failed to open stream: No such file or directory

image

I've updated the Strauss version to dev-master in the repo linked above.

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

Successfully merging a pull request may close this issue.

2 participants