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

Add typescript support for script files. #294

Open
ST-DDT opened this issue Oct 5, 2022 · 5 comments
Open

Add typescript support for script files. #294

ST-DDT opened this issue Oct 5, 2022 · 5 comments
Labels
enhancement New feature or request

Comments

@ST-DDT
Copy link

ST-DDT commented Oct 5, 2022

Is your feature request related to a problem? Please describe.

All my source is typescript except for the ones for githup-script.

Describe the solution you'd like

Add support for loading typescript files.

Describe alternatives you've considered

Run the typescript compiler to convert the ts file to a js file before executing it with this action.

Additional context

@nomeata
Copy link

nomeata commented Dec 14, 2023

This would also allow to statically check these scripts before running, e.g. help with rhysd/actionlint#55. This would have prevented plenty of mishaps that I caused…

@Flydiverny
Copy link

As a PoC I made a wrapper around github-script to use typescript sources https://github.com/Flydiverny/github-typescript it adds a small overhead as it uses esbuild binary to convert into JS.

@kf6kjg
Copy link

kf6kjg commented Jun 27, 2024

Also the tsx project allows for doing some workarounds, and might lead to a solution here:

        uses: actions/github-script@v7
        with:
          github-token: ${{ secrets.github_token }}
          script: |
            const { tsImport } = await import('tsx/esm/api');
            const { main } = await tsImport('./report.ts', '${{ github.workspace }}/');
            await main(github, context, '${{ job.status }}');

In this I'm using tsx's programmatic API to load another file that's typescript.

Only caveat is that it can't find tsx in order to import it... So I'm solving that problem...

@cscleison
Copy link

Only caveat is that it can't find tsx in order to import it... So I'm solving that problem...

@kf6kjg thanks for you suggestion! I managed to make it work with:

const { tsImport } = await import('${{ github.workspace }}/.github/node_modules/tsx/dist/esm/api/index.cjs');
const { myFn } = await tsImport('./.github/scripts/my-file.ts', '${{ github.workspace }}/');

@kf6kjg
Copy link

kf6kjg commented Jul 6, 2024

Just put in #477 with what is unit testing as a functional support for TypeScript!

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

No branches or pull requests

6 participants