Skip to content

refactor: convert action to TS and bundle code#95

Merged
dsherret merged 6 commits intodenoland:mainfrom
csvn:refactor/convert-to-ts-and-build
May 12, 2025
Merged

refactor: convert action to TS and bundle code#95
dsherret merged 6 commits intodenoland:mainfrom
csvn:refactor/convert-to-ts-and-build

Conversation

@csvn
Copy link
Copy Markdown
Contributor

@csvn csvn commented Apr 29, 2025

In #89 I tried adding automatic caching of installed dependencies for Deno. But that PR makes the node_modules explode in size if added to Git, due to @actions/cache requiring a lot of subdependencies.

This PR adds bundling of the action code, which will reduce the impact by a lot (see below), since node_modules will no longer be cloned. If this PR is merged, it should make the remaining work on #89 trivial.

There's mostly pro's to using the approach in this PR (which works similarly to @actions/checkout and other GitHub created Actions), except that contributors to this action needs to run deno task build prior to committing any changes (or checks will fail in PRs).

Commits

  1. Convert action source code to TS
  2. Adds .vscode folder with setting enabling deno, formatting and linting
    • This was helpful during development, but I can remove it again if it's unwanted
  3. Adds a build script and a workflow to ensure built code is committed to dist/

Action size

The amount of files cloned when action is checked out, main vs this PR:

Before

  • 5.18 MB
  • 738 files (724 from node_modules)
  • 107 folders (103 from node_modules)

After

  • 1.62 MB
  • 16 files
  • 6 folders

image

So bundling code should make it much quicker to clone and run actions, due to smaller amount of files to for Git to handle, as well as a single file being much quicker to run in Node.js over hundreds.

Bundler choice

I landed at using tsdown, which is using rolldown under the hood. Things I tried that did not work well:

  • @deno/dnt: A had a lot of errors when I tried, and this also produces a lot of unnecessary files for this use-case (package.json, types, etc)
  • esbuild + jsr:@luca/esbuild-deno-loader: This worked to produce CJS output, but trying to produce ESM did not go well. Though this approach is very nice in avoiding an install step and downloading/caching dependencies during bundling.
  • tsdown + deno-vite-plugin: I tried to hack around making the vite plugin work (calling configResolved() manually), but had various issues and could not get this working in the end.

Finally, I gave up and used tsdown after just installing node_modules with Deno first. This worked well on the first try, and was quicker than the other options anyway. It also seems to work with ESM output without issues.

@csvn csvn requested a review from lucacasonato as a code owner April 29, 2025 13:55
@csvn csvn force-pushed the refactor/convert-to-ts-and-build branch 5 times, most recently from fa22023 to 40ef822 Compare April 29, 2025 14:38
@csvn csvn force-pushed the refactor/convert-to-ts-and-build branch from 40ef822 to 663669c Compare April 29, 2025 14:45
@csvn
Copy link
Copy Markdown
Contributor Author

csvn commented May 9, 2025

@crowlKats Sorry for pinging directly, I've tried the #contributing channel on Discord, but got no response. Any chance to get some feedback on this and the built-in caching PR (#89, which this PR was created to unblock)?

Copy link
Copy Markdown
Contributor

@dsherret dsherret left a comment

Choose a reason for hiding this comment

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

LGTM. Thanks!

I'm going to merge this in a bit. I just need to investigate this Deno bug with the frozen lockfile (opened denoland/deno#29265)

@dsherret dsherret merged commit 95bbb87 into denoland:main May 12, 2025
28 checks passed
@csvn csvn deleted the refactor/convert-to-ts-and-build branch May 12, 2025 16:41
@csvn
Copy link
Copy Markdown
Contributor Author

csvn commented May 12, 2025

Awesome, thanks for reviewing and merging this one @dsherret!

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.

2 participants