Skip to content

Instantly share code, notes, and snippets.

@IHLight
Forked from cgcardona/ts-dev-env-setup.md
Created March 30, 2021 22:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save IHLight/afdad68cb6bf61557cd4aff12ad14171 to your computer and use it in GitHub Desktop.
Save IHLight/afdad68cb6bf61557cd4aff12ad14171 to your computer and use it in GitHub Desktop.

TS Dev Environment Setup

Resources

Node Version Manager

Currently we're using nodeJS v12.14.1. IIRC there's a new LTS but Emre asked that we stay on this version due to issues upgrading the web wallet.

Install

wget -qO- https://raw.githubusercontent.com/nvm-sh/nvm/v0.35.3/install.sh | bash

List remote versions

nvm ls-remote

List installed versions

nvm ls

Install a version

nvm install v12.14.1

Use an installed version

nvm use 12.14.1

Default to an installed version

nvm default 12.14.1

TS Node

Installation

# With TypeScript.
npm install -g typescript
npm install -g ts-node

Usage

# Execute a script as `node` + `tsc`.
ts-node script.ts

# Starts a TypeScript REPL.
ts-node

VSCode Debugging

TSConfig

{
  "compilerOptions": {
    "target": "es6",
    "module": "commonjs",
    "lib": ["es2015", "dom"],
    "allowJs": true,
    "skipLibCheck": true,
    "sourceMap": true,
    "outDir": "dist",
    "strict": true,
    "noImplicitAny": true,
    "moduleResolution": "node",
    "baseUrl": "./",
    "esModuleInterop": true
  },
  "include": ["*"],
  "exclude": ["node_modules"]
}

.vscode/launch.json

{
  "version": "0.2.0",
  "configurations": [
    {
      "type": "node",
      "request": "launch",
      "name": "Launch Program",
      "skipFiles": [
        "<node_internals>/**"
      ],
      "program": "${workspaceFolder}/FILENAME-TO-CHANGE.ts",
      "preLaunchTask": "tsc: build - tsconfig.json",
      "outFiles": [
        "${workspaceFolder}/dist/**/*.js"
      ]
    }
  ]
}

Usage

  1. Add breakpoinst to FILENAME-TO-CHANGE from the previous step.
  2. Open the "Run" tab with cmd+shift+D.
  3. Have the top dropdown menu read "Launch Program" and click the green "Start Debugging" play button.
  4. If you see a popup error click "Debug Anyway"
  5. You'll now be debugging. You can step over/in/out of functions. You can observe the stack. You can inspect variable values and call methods from the debug terminal tab.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment