CSJava is a learning project about embedding the Jint JavaScript engine in C# with TypeScript for scripting. It demonstrates running compiled TypeScript code inside a .NET app using Jint.
This project requires Node.js and npm
(Node Package Manager) to be installed on your system.
Run the following in the root of the cloned repository to install the project's dependencies and all required tooling for the build action:
dotnet tool restore
npm install
Note: If you encounter issues installing dependencies (e.g.,
esbuild
fails to install due to npm version conflicts), you may need to switch your Node.js version using nvm. For example:nvm use 20 npm installThis ensures compatibility with the required npm version for
esbuild
.
Compiles the whole project including transpiling the TypeScript source files to JavaScript:
dotnet build
The build file for CSJava includes a step that uses esbuild
to create all the required JavaScript files for the demo.
Run the C# application that loads and executes the compiled JavaScript:
dotnet run --project=src/CSJava/CSJava.csproj
This will invoke the project's build target as needed so you rarely need to build manually.
A VSCode task called "Build CSJava" is configured as the default build task (Ctrl+Shift+B
). Running this task will just run the same build script as dotnet build
just without having to type it yourself.
You may also use the command pallette to run the provided "Run CSJava" task that will skip needing to type `dotnet run --project ..." every time
- TypeScript files live in
src/<script name>/main.ts
and compile toJS/<script name>.js
for execution in the engine. src/
is the root of TypeScript resolution so all imports should be relative to it.- The C# project hosts the Jint engine and runs the compiled scripts from the
JS
folder.