• Stars
    star
    109
  • Rank 319,077 (Top 7 %)
  • Language
    TypeScript
  • License
    MIT License
  • Created almost 6 years ago
  • Updated over 1 year ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

If the desired entry point to debugging is unclear (e.g. within webpack configurations) this tool will help you by not just waiting for a debugger to connect but also launching it from scratch. Don't use the excuse that attaching a debugger is cumbersome next time you use console.log for debugging!

Easy Attach

A helper tool that makes launching the debugger to step through node applications where the entry point is unclear (e.g. webpack configurations) extremely easy.

Like Debugger.Break() from C#. Everything the debugger; statement should be.

Why debugger; doesn't do it

debugger; does nothing if no debugger is attached.

This means you have to either launch the process in debug mode from the start (which is complicated if you don't control how the process is launched) or be quick to attach it before the line you want to break at is executed.

With this project you can just paste one line and it will launch a debugger of your choice (VSCode or Chrome) while suspending the running process, regardless of how it was started.

Requirements

Developed on Windows, tested on Windows and Linux.

Installation

easy-attach should best be installed globally:

yarn global add easy-attach

Or if you use npm:

npm install --global easy-attach

Demo

demo

Usage

Run easy-attach to see instructions:

cli

Then, in the script you want to debug, insert the code from the instructions:

function obscureFunction(args) {
	// this require call launches the debugger and waits
	require("C:\\Users\\henni\\AppData\\Local\\Yarn\\Data\\global\\node_modules\\easy-attach\\debugger")();
	anotherObscureFunction(args.data);
}

When the require("[...]\\debugger")() is called, a chrome window is launched with further instructions. By pasting the displayed link into chrome you can debug your node js application! This even works in node repl!

You can also pass a label to the call so that you don't mix up various breakpoints:

require("...\\easy-attach\\debugger")({ label: "Server" });

If you don't want the debugger to halt, you can pass a continue flag:

require("...\\easy-attach\\debugger")({ continue: true });

Connect with JetBrains (Webstorm / IntelliJ IDEA / etc...)

Required plugins: JavaScript and TypeScript, JavaScript Debugger, Node.js

You can connect to the node js application by following these steps:

  • Add a require("[...]\\debugger")({ debugProxyPort: PORT }) with some random port, e.g. 54834
  • Create an Attach to Node.js/Chrome - Run/Debug Configuration
  • Paste the port into the Port section
  • Make sure Reconnect automatically is checked, so whenever you restart the TypeScript Service, it can reconnect automatically
  • Wait for the statement to open a new chrome window
  • Click on the debug button to start debugging your application

Flags

You can specify flags by passing an object:

require("...\\easy-attach\\debugger")({ ...flags });

These flags are supported:

export interface EasyAttachArgs {
	/**
	 * Sets a label for the debug target.
	 * Defaults to `undefined`..
	 */
	label?: string;
	/**
	 * If enabled, it does not break after attaching the debugger.
	 * Defaults to `false`.
	 */
	continue?: boolean;
	/**
	 * Specifies the port to use for the debug port.
	 * Use `preconfigured` when the debugger was already launched.
	 * Defaults to `random`;
	 */
	debugPort?: DebugPortConfig;
	/**
	 * Specifies the port to use for the debug proxy.
	 * This is usefull if you want to forward this port.
	 * Defaults to `random`;
	 */
	debugProxyPort?: PortConfig;
	/**
	 * Use this option when the debug proxy does not recognize connection attempts and does not close automatically. Defaults to `false`.
	 */
	eagerExitDebugProxy?: boolean;
	/**
	 * Print logs from background worker. Defaults to `false`.
	 */
	logBackgroundWorker?: boolean;
	/**
	 * Use this option to control whether the UI is shown.
	 * If only the VS Code Extension is used, disabling the UI speeds up the auto attach feature.
	 * Defaults to `true`.
	 */
	showUI?: boolean;
}

export type PortConfig = "random" | number | number[];
export type DebugPortConfig = PortConfig | "preconfigured";

Design Notes

Actually, going from debugger; to C#'s Debugger.Break() was unexpectedly easy (in terms of a node js developer).

This sequence diagram roughly describes what is needed for that little upgrade:

sequence-diagram

background-worker

The background-worker process is required as we don't want to return from the require call before a debugger successfully attached, otherwise we would miss the debugger; breakpoint. Thus, we cannot use the event loop of the debugee and have to spawn a new process and wait for it to exit synchronously.

debugger-proxy

The debugger-proxy is used to inform the background-worker that a debugger has attached. There seems to be no other way. Care has to be taken that is exits neither too early nor never.

Used Dependencies

Utility functions:

For typed communicating between background-worker and debugger-proxy:

For proxying node debug:

For the CLI:

To get the chrome debug url and launch chrome:

To notify vscode:

To find free ports:

Known Problems

  • Sometimes, when launchend, the background-worker appears for a short moment as black terminal window. I don't know why.

Changelog

  • 2.0.0
    • Migrated from _debugProcess to inspector.open. This solves some race conditions.
    • Removed debug entry points.
    • Uses debug API to automatically step out or continue.

More Repositories

1

vscode-drawio

This unofficial extension integrates Draw.io (also known as diagrams.net) into VS Code.
TypeScript
9,062
star
2

vscode-debug-visualizer

An extension for VS Code that visualizes data during debugging.
TypeScript
7,859
star
3

vscode-realtime-debugging

An extension for VS Code that visualizes how a program is being executed in real time.
TypeScript
276
star
4

browser-ext-github-monaco

This extension brings the famous Monaco editor to Github
TypeScript
255
star
5

node-reload

An advanced hot reload solution for Node apps. Works very well for developing VSCode extensions and automating websites with puppeteer.
TypeScript
100
star
6

visualization

A framework for visualizing data encoded as json.
TypeScript
96
star
7

slideo

This tool uses OpenCV to automatically synchronize slides with videos that show these slides.
Rust
94
star
8

ts-typed-sql

A fully typed sql builder. Not maintained anymore, use it for your inspiration.
JavaScript
54
star
9

rxjs-playground

A typescript playground for rx js.
TypeScript
49
star
10

vscode-hediet-power-tools

This extension provides various helper commands.
TypeScript
34
star
11

visual-keyboard

A virtual keyboard displaying key bindings of VS Code as you type.
TypeScript
30
star
12

ts-cli

A CLI Library for NodeJS/TypeScript
TypeScript
26
star
13

pdf.js-viewer

This package makes the PDF.js viewer available to third party applications.
JavaScript
19
star
14

hediet-ts-refactoring-lsp

A language server plugin for my own refactorings. Feel free to use them too!
TypeScript
13
star
15

vscode-delorean-js-debug

TypeScript
11
star
16

vscode-rpc

Provides an RPC interface to automate VSCode from other processes
TypeScript
11
star
17

rust-ffmpeg-frame-grabber

Provides a frame iterator for videos by using ffmpeg. Decodes images using the image crate.
Rust
10
star
18

vscode-tasks-statusbar

This extension adds buttons to the status bar to quickly start and kill tasks.
TypeScript
10
star
19

vscode-unicode-data

TypeScript
9
star
20

typed-json-rpc

A modern implementation of JSON RPC in TypeScript for NodeJs and Browsers. Not stable yet.
TypeScript
7
star
21

typed-lexer

An easy to use lexer that features typescript typings.
TypeScript
7
star
22

blog

My blog where I write about TypeScript, my own projects and other cool programming related stuff.
TypeScript
5
star
23

geml

Yet another json alternative with markdown support. Aims to replace xml. Rich tooling is planned.
TypeScript
4
star
24

masters-thesis

TeX
4
star
25

vscode-multi-cursor-enhancer

VS Code Selection Utilities
TypeScript
4
star
26

live-debug

Provides services to send events to a debugger that supports live debug.
TypeScript
4
star
27

ts-webpack-react-template

A template for applications based on TypeScript, Webpack and React.
TypeScript
4
star
28

ts-semver

A TypeScript implementation of the Semantic Version 2.0.0 specification.
TypeScript
3
star
29

starship-twitter-bot

Get notified right before a starship is about to launch.
TypeScript
3
star
30

ts-std

Personal util functions that enhance the js std library. I don't give much value on backwards compatibility, but will consider semantic versioning. If you like this library, you should fork it and make it your own!
TypeScript
2
star
31

csharp-UnitsOfMeasure

A Units of Measure library for .Net
C#
2
star
32

vscode-debug-visualizer-personal-scripts

debug-visualizer-custom-scripts
JavaScript
2
star
33

HowNodeJsModulesShouldHaveBeenDesigned

Demonstrates how the Node JS Module Loader could work if it had been designed properly.
JavaScript
2
star
34

git-line-endings

Tests all combination of git line ending settings.
TypeScript
2
star
35

diff-merge-dataset

TypeScript
2
star
36

Neo2Net

Neo2 Keyboard Layout implemented in C#
C#
2
star
37

klingeling

JavaScript
2
star
38

semantic-json

TypeScript
2
star
39

rust-visualizer

Rust Visualizer Library. Based on the Debug Visualizer Extension for VS Code.
SCSS
2
star
40

project-issues-auto-importer

Automatically adds issues from a given repository to a given project
TypeScript
2
star
41

PredicateLogicProofValidator

A validator for predicate logic proofs that can be extended with custom axioms and rules.
TypeScript
2
star
42

sinfonie-und-kammerorchester.kit.edu

Some static files.
HTML
1
star
43

ext-vscode-syntax-tree-viewer

Visualizes Syntax Trees in VS Code
TypeScript
1
star
44

monaco-editor-react

This library exposes the monaco editor as a react component.
TypeScript
1
star
45

LambdaCalculus

TypeScript
1
star
46

GrammarTools

C#
1
star
47

lean-linear-integer-equation-solver

Lean
1
star
48

CodeItDebugger

JavaScript
1
star
49

rider-plugin-debug-visualizer-dotnet-sdk

C#
1
star
50

php-type-reflection

A library which provide classes to reflect php types in an unified way.
PHP
1
star
51

php-contracts

An assertion library for PHP to validate arguments and invariants.
PHP
1
star
52

propa2017

Haskell
1
star
53

vscode-3wm-test-repo

Test Repo For The VS Code 3 Way Merge Editor Feature
TypeScript
1
star
54

vscode-custom-web-editor

TypeScript
1
star
55

npm-template

TypeScript
1
star
56

ts-react-svg-demo

An application that demonstrates how react and svg can be used together.
TypeScript
1
star
57

ext-vs-ProjectAsCustomTool

Provides a custom tool that enables to use projects in the active solution for code generation.
C#
1
star
58

git-demo

Git Demo
TypeScript
1
star