Elao / PhpEnums

:nut_and_bolt: Extended PHP 8.1+ enums features & specific integrations with frameworks and libraries
MIT License
326 stars 27 forks source link

JSDumper - Invalid import path generated ( windows maschines ) #108

Closed BeyerJC closed 4 years ago

BeyerJC commented 4 years ago

Hi,

when using the JSDumper the generated import path is not valid. Test "testDumpEnumToFIle" is also failing because the expectedImportPath is e.g. "'../../lib/enum', but the acutal result is '../../lib/enum.js/'.

Result in the application

//acutal
import { ReadableEnum } from '../../lib/enum.js/';

//expected
import { ReadableEnum } from '../../lib/enum';

with the following configuration

 js:
        base_dir: '%kernel.project_dir%/assets/js/symfony/enum'
        lib_path: '%kernel.project_dir%/assets/js/lib/enum.js'
        paths:
            App\Enum\ValueType: 'ValueType.js'

The reason is that the rtrim uses the DIRECTORY_SEPERATOR which is "\" on windows and so the preg_replace does not remove the / after .js.

        $relativeLibPath = preg_replace('#.js$#', '', rtrim(
            $this->fs->makePathRelative(realpath($this->libPath), realpath(\dirname($path))),
            DIRECTORY_SEPARATOR
        ));

We could replace DIRECTORY_SEPERATOR with "\\/" or adjust the .js$ to .js/$. I prefer extending the characters list.

BeyerJC commented 4 years ago

Afaik Travis also supports running the tests on windows os, doesnt it ? Would it make sense to add a test run with os: windows or is there already a plan to move to github actions ?

ogizanagi commented 4 years ago

I think Travis supports windows indeed, but I never tried. Another alternative is AppVeyor. I'd like to avoid github actions for now, as I'm not sure how it is calculated regarding allowed minutes on the organisation plan, with private and public repositories.

BeyerJC commented 4 years ago

If I understand https://docs.travis-ci.com/user/multi-os/ correctly, adding the OS in the config would be enough to run the whole matrix on both OS or set it individually on just one version

      # most recent versions:
      - php: 7.4
         os:
             - linux
             - windows
        env:
          - SYMFONY_VERSION="5.0.*"
          - CHECK_CODE_STYLE="yes" 

But since i have very little experience with Travis im not sure...

EDIT : Nvm, looks like PHP is not supported on windows build https://docs.travis-ci.com/user/reference/windows/#supported-languages

ogizanagi commented 4 years ago

Thanks for looking @WhiteRabbitDE . I've added https://github.com/Elao/PhpEnums/issues/110