Skip to content

Commit d6e6ff4

Browse files
committed
docs(debug): add documentation on debugging bundle + source
1 parent b959bc8 commit d6e6ff4

File tree

1 file changed

+76
-6
lines changed

1 file changed

+76
-6
lines changed

README.md

Lines changed: 76 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,21 @@
11
# typescript-node-scripts
2+
23
[![Build Status](https://travis-ci.com/liangchunn/typescript-node-scripts.svg?branch=master)](https://travis-ci.com/liangchunn/typescript-node-scripts) [![npm](https://img.shields.io/npm/v/typescript-node-scripts.svg)](https://www.npmjs.com/package/typescript-node-scripts) [![npm](https://img.shields.io/npm/dt/typescript-node-scripts.svg)](https://www.npmjs.com/package/typescript-node-scripts) [![install size](https://packagephobia.now.sh/badge?p=typescript-node-scripts)](https://packagephobia.now.sh/result?p=typescript-node-scripts) [![Greenkeeper badge](https://badges.greenkeeper.io/liangchunn/typescript-node-scripts.svg)](https://greenkeeper.io/)
34

45
Create Node.js applications based on TypeScript with zero-configuration.
6+
57
<p align="center">
68
<img
79
width="600" src="https://cdn.rawgit.com/liangchunn/typescript-node-scripts/12e1600/.resources/term.svg"/>
810
</p>
911

1012
Inspired by `create-react-app` and Dan Abramov's [The Melting Pot of JavaScript](https://increment.com/development/the-melting-pot-of-javascript/).
13+
1114
- Supports testing, building, and development in watch mode
1215
- Supports custom TypeScript path mappings, aka `compilerOptions.path`
1316

1417
## Quick Start Guide
18+
1519
```sh
1620
npx typescript-node-scripts create <appName>
1721
cd <appName>
@@ -20,9 +24,8 @@ yarn start
2024

2125
## Requirements
2226

23-
- node `>=6.0.0`
24-
- `process.platform !== 'win32'`
25-
27+
- node `>=8.0.0`
28+
- `process.platform !== 'win32'`
2629

2730
## Commands
2831

@@ -65,32 +68,39 @@ yarn test --watchAll
6568
```
6669

6770
## Tests
71+
6872
Jest is the main test runner that this package supports.
6973

7074
### Test files
75+
7176
Everything that matches the globs below will be passed to Jest as a test file:
77+
7278
- `src/**/__tests__/**/*.(j|t)s?(x)`
7379
- `src/**/?(*.)(spec|test|t).(j|t)s?(x)`
7480

7581
### Setting up the test framework
82+
7683
You can use `setupTests.ts` in your project root to set up the testing framework before each test.
7784

7885
### Overriding Jest configuration
86+
7987
You can override the Jest configuration in your `package.json` with the key `jest`.
8088

8189
The following options can be overriden:
90+
8291
- `collectCoverageFrom`
8392
- `coverageReporters`
8493
- `coverageThreshold`
8594

8695
## Custom Module Paths
96+
8797
TNS supports custom module path mappings. A default custom path mapping is provided in `tsconfig.json`
8898

8999
```json
90100
{
91-
"paths": {
92-
"~/*": ["src/*"]
93-
}
101+
"paths": {
102+
"~/*": ["src/*"]
103+
}
94104
}
95105
```
96106

@@ -107,6 +117,7 @@ import Module from '~/Module'
107117
```
108118

109119
## Source Maps
120+
110121
Source maps are enabled by default and postfixed with `.map` in the `build` and `dist` folders. These files provide accurate source mappings which are helpful when debugging errors and looking at stack traces during runtime.
111122

112123
In order to tell Node to use these source maps, you would need to install `source-map-support`.
@@ -120,12 +131,71 @@ npm i -S source-map-support
120131
```
121132

122133
Then, in `src/index.ts`, add:
134+
123135
```ts
124136
import 'source-map-support/register'
125137
```
126138

127139
## Monorepo Support
140+
128141
To use `typescript-node-scripts` with a monorepo like lerna + yarn workspaces, you need to add `--monorepo` to the start and build scripts.
129142

130143
Then, you can use `lerna run <start|build> --stream` in your root `package.json`.
131144

145+
## Debugging
146+
147+
### Visual Studio Code
148+
149+
#### Webpack Build
150+
151+
TNS incrementally outputs a single bundle in `build/bundle.js` (via webpack) when running `yarn build`.
152+
To debug the bundle, add the following into the `configurations` array of your `launch.json` file:
153+
154+
```json
155+
{
156+
"type": "node",
157+
"request": "launch",
158+
"name": "Debug Webpack Build (via Node)",
159+
"protocol": "inspector",
160+
"program": "${workspaceFolder}/build/bundle.js"
161+
}
162+
```
163+
164+
You can now set breakpoints and run the task in order to debug your build.
165+
166+
#### TypeScript Source via `ts-node`
167+
168+
_This method is **NOT** recommended due to ts-node being quite slow at running and compiling your source code._
169+
170+
First off, you would need to install `ts-node` and `tsconfig-paths`:
171+
172+
```sh
173+
yarn add ts-node tsconfig-paths --dev
174+
```
175+
176+
Then add the following into your configuration:
177+
178+
```json
179+
{
180+
"type": "node",
181+
"request": "launch",
182+
"name": "Debug Source (ts-node)",
183+
"protocol": "inspector",
184+
"runtimeArgs": ["-r", "ts-node/register", "-r", "tsconfig-paths/register"],
185+
"args": ["${workspaceFolder}/src/index.ts"],
186+
"env": {
187+
"TS_NODE_PROJECT": "./tsconfig.json",
188+
"TS_NODE_FILES": "true"
189+
}
190+
}
191+
```
192+
193+
Next, add the `files` entry into your `tsconfig.json`:
194+
195+
```json
196+
{
197+
"files": ["src"]
198+
}
199+
```
200+
201+
You can now use breakpoints and run the build under debug mode.

0 commit comments

Comments
 (0)