DEV Community

WH yang
WH yang

Posted on

Build A Watch Option for TypeScript Runtime in Rust

Andromeda is a new TypeScript runtime that uses the Nova Engine and Oxc, which is written in Rust.

Node.js has had a --watch feature since 2022, and you can find the pull request (PR) for it on GitHub. This watch mode, or hot reload, is very popular for frontend frameworks, testing frameworks, and even in Node.js itself. It automatically reruns the code whenever you change a file in the working directory, making life easier for developers today.

I had never tried Rust before sending this PR, and it was a bit reckless to ask the maintainer to assign the issue to me. However, I think it was the best decision I made during Hacktoberfest.

I didn’t think much about how watch mode was implemented, but I used it a lot. My approach was:

  1. Go to the Node.js release page to find out when the watch option was announced.
  2. Locate the PR related to the --watch option.
  3. Read the core implementation.

Then, I needed to use Rust to create a similar function. I did the following:

  1. I read The Rust Programming Language to get a basic understanding of Rust and its tools.
  2. I used AI to help explain each package in the Cargo.toml file, which is like package.json for JavaScript projects.
  3. I looked at the main entry point of the project, even though I didn’t fully understand it. The function names and variables gave me clues about the watch option.
  4. I wrote a folder watch program in a test project and then copied that code to Andromeda.

It was a long journey to solve all the problems I faced. I made some progress but had many doubts over the past two weeks. However, I felt more satisfied than I expected after sending the PR. It reminded me of the first time I compiled and ran my "Hello World" program when I started learning to code.

Top comments (0)