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

Allow specifying SWC version #54

Merged
merged 7 commits into from
Sep 17, 2024
Merged

Conversation

pan93412
Copy link
Contributor

@pan93412 pan93412 commented Sep 17, 2024

Fix #53.

  • Allow specifying the swc_version in the configuration YAML file.
  • The downloaded binary name will contain the SWC version users picked.
  • Docs and tests are added.

By default, it uses the (current) latest SWC version v1.7.26:

$ php ./bin/console typescript:build -v

 ! [NOTE] Downloading SWC binary from "https://github.com/swc-project/swc/releases/download/v1.7.26/swc-darwin-arm64" to
 !        "/Volumes/Dev/ResearchProject/lets-php/app-sf/var/swc-v1.7.26-darwin-arm64"...                                

 34787224/34787224 [▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓] 100%  1 sec
 ! [NOTE] Executing SWC compile on assets.                                                                              

  Command:
    '/Volumes/Dev/ResearchProject/lets-php/app-sf/var/swc-v1.7.26-darwin-arm64' 'compile' 'assets' '--out-dir' '/Volumes/Dev/ResearchProject/lets-php/app-sf/var/typescript' '--config-file' '.swcrc'

Users can specify it in config:

sensiolabs_typescript:
  swc_version: v1.7.27-nightly-20240911.1

and AssetMapperTypeScriptBundle will download and use the user-picked version.

$ php ./bin/console typescript:build -v

 ! [NOTE] Downloading SWC binary from "https://github.com/swc-project/swc/releases/download/v1.7.27-nightly-20240911.1/swc-darwin-arm64" to
 !        "/Volumes/Dev/ResearchProject/lets-php/app-sf/var/swc-v1.7.27-nightly-20240911.1-darwin-arm64"...             

 34787224/34787224 [▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓] 100% 3 secs
 ! [NOTE] Executing SWC compile on assets.                                                                              

  Command:
    '/Volumes/Dev/ResearchProject/lets-php/app-sf/var/swc-v1.7.27-nightly-20240911.1-darwin-arm64' 'compile' 'assets' '--out-dir' '/Volumes/Dev/ResearchProject/lets-php/app-sf/var/typescript' '--config-file' '.swcrc'

Of course, the downloaded binary is still cached.

$ php ./bin/console typescript:build -v

 ! [NOTE] Executing SWC compile on assets.                                                                              

  Command:
    '/Volumes/Dev/ResearchProject/lets-php/app-sf/var/swc-v1.7.27-nightly-20240911.1-darwin-arm64' 'compile' 'assets' '--out-dir' '/Volumes/Dev/ResearchProject/lets-php/app-sf/var/typescript' '--config-file' '.swcrc'

CleanShot 2024-09-17 at 17 22 15@2x

@pan93412
Copy link
Contributor Author

r? @maelanleborgne would you mind checking this PR? thank you!

@maelanleborgne
Copy link
Contributor

Very nice PR @pan93412 ! I'm just a little worried that this is too big of a change to be forced over users : it will force the download of a new binary, that could be a problem on established production setups (will the permissions be ok ? There's no cleanup of the previous binary. And are there any breaking changes between 1.3.92 and 1.7.26 ? ...)

Do you think PR could be done at first without the binary file renaming ? So that users who don't need to update the binary won't be affected by the update, and maybe write in the docs that, in order to upgrade the binary version, you must delete it first then run the command (that's just a suggestion).

@pan93412
Copy link
Contributor Author

pan93412 commented Sep 17, 2024

Very nice PR @pan93412 ! I'm just a little worried that this is too big of a change to be forced over users : it will force the download of a new binary, that could be a problem on established production setups (will the permissions be ok ? There's no cleanup of the previous binary. And are there any breaking changes between 1.3.92 and 1.7.26 ? ...)

Do you think PR could be done at first without the binary file renaming ? So that users who don't need to update the binary won't be affected by the update, and maybe write in the docs that, in order to upgrade the binary version, you must delete it first then run the command (that's just a suggestion).

Good idea. Let me revert the filename commits and the SWC version changes. Thanks for your suggestion!

Old tag: 34f1783

@pan93412
Copy link
Contributor Author

Very nice PR @pan93412 ! I'm just a little worried that this is too big of a change to be forced over users : it will force the download of a new binary, that could be a problem on established production setups (will the permissions be ok ? There's no cleanup of the previous binary. And are there any breaking changes between 1.3.92 and 1.7.26 ? ...)

Do you think PR could be done at first without the binary file renaming ? So that users who don't need to update the binary won't be affected by the update, and maybe write in the docs that, in order to upgrade the binary version, you must delete it first then run the command (that's just a suggestion).

I have reverted the version and renaming part, and documented in order to upgrade the binary version, you must delete it first then run the command in the documentation. Would you mind checking this again? Thank you!

Copy link
Contributor

@maelanleborgne maelanleborgne left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just a few things but otherwise it looks good to me. I'll make some tests on my side to validate this, but I think it can be release today

doc/index.rst Outdated Show resolved Hide resolved
doc/index.rst Outdated Show resolved Hide resolved
Co-authored-by: maelanleborgne <[email protected]>
@maelanleborgne
Copy link
Contributor

Everything seem to run smoothly, just one last thing : I think we should throw an exception right away if the response isn't successful.
Right now the exception is thrown when streaming the response, which is after the destination file was created, leaving the application in a messy state.

I'd suggest adding somthing like this in TypeScriptBinaryFactory:129 just after the request is made :

        if (200 !== $statusCode = $response->getStatusCode()) {
            $exceptionMessage = \sprintf('Could not download SWC binary from "%s" (request responded with %d).', $url, $statusCode);
            if (404 === $statusCode) {
                $exceptionMessage .= PHP_EOL.\sprintf('Check that the version "%s" defined in "sensiolabs_typescript.swc_version" exists.', $this->swcVersion);
            }
            throw new \Exception($exceptionMessage);
        }

@pan93412
Copy link
Contributor Author

r? @maelanleborgne

Copy link
Contributor

@maelanleborgne maelanleborgne left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thank you very much for this feature @pan93412 🙏

@maelanleborgne maelanleborgne merged commit c6a6940 into sensiolabs:main Sep 17, 2024
5 of 6 checks passed
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 this pull request may close these issues.

Allow specifying the SWC version
2 participants