A Node.js project that demonstrates running TypeScript files natively without transpilation using Node.js v22.15.0+ and the experimental type stripping feature.
- Node.js v22.15.0 or higher
- npm (comes with Node.js)
-
Clone this repository:
git clone https://github.com/codenote-net/github-rag-examples.git cd github-rag-examples
-
Install dependencies:
npm install
This project is configured to run TypeScript files directly with Node.js without the need for transpilation, using the --experimental-strip-types
flag.
Run the basic example:
npm start
This executes the src/index.ts
file directly using Node.js.
This project includes a script to clone a GitHub repository using a GitHub App installation token. The script uses the x-access-token authentication method as described in the GitHub documentation.
The src/clone-repo.ts
script:
- Uses the GitHub App installation token with the
x-access-token
authentication method - Validates environment variables for token and repository information
- Constructs a secure clone URL with the token
- Removes any existing clone directory to ensure a clean clone
- Clones the repository with optimized options:
--single-branch
: Clones only the default branch--no-tags
: Skips downloading tags--depth 1
: Creates a shallow clone with only the latest commit
The script is configured in package.json
to run with the --experimental-strip-types
flag, which enables TypeScript execution without transpilation:
{
"scripts": {
"clone": "node --experimental-strip-types src/clone-repo.ts"
}
}
- Set the required environment variables:
export GITHUB_TOKEN="your_github_app_installation_token"
export REPO_OWNER="repository_owner"
export REPO_NAME="repository_name"
export CLONE_DIR="./cloned-repo" # Optional, defaults to './cloned-repo'
- Run the clone script using npm:
npm run clone
This command executes the TypeScript file directly using Node.js with type stripping, eliminating the need for a separate build step before running the script.
Starting with Node.js v22.6.0, Node.js has experimental support for TypeScript syntax through "type stripping". This allows you to run valid TypeScript code directly in Node.js without the need to transpile it first.
From Node.js v23.6.0 onwards, type stripping is enabled by default, but this project explicitly uses the flag for compatibility with Node.js v22.x.
/src
- TypeScript source filespackage.json
- Project configuration