2.0.0-beta.3 • Published 6 years ago

typescript-node-scripts v2.0.0-beta.3

Weekly downloads
224
License
MIT
Repository
github
Last release
6 years ago

typescript-node-scripts

Build Status npm npm install size Greenkeeper badge

Create Node.js applications based on TypeScript with zero-configuration.

Inspired by create-react-app and Dan Abramov's The Melting Pot of JavaScript.

  • Supports testing, building, and development in watch mode
  • Supports custom TypeScript path mappings, aka compilerOptions.path

Quick Start Guide

npx typescript-node-scripts create <appName>
cd <appName>
yarn start

Requirements

  • node >=8.0.0
  • process.platform !== 'win32'

Commands

yarn start or npm run start

Starts the development server with watch mode and incremental builds. This command generates a bundle which is located at build/bundle.js.

Options

ArgumentDescription
--no-collapseExpands all the collapsed errors
--no-auto-startDisables auto starting and stopping of the application. By default, it executes build/bundle.js.
--monorepoEnable support for monorepos

yarn build or npm run build

Builds a production ready bundle. This minifies all sources into one simple, distributable dist/bundle.prod.js alongside dist/bundle.prod.js.map which is ideal for Docker builds.

This command does not bundle any dependencies which is require-d or import-ed from node_modules!

Options

ArgumentDescription
--no-collapseExpands all the collapsed errors
--bypass-ci-warningsBypass CI warnings being treated as errors.
--monorepoEnable support for monorepo

yarn test or npm run test

Runs the Jest test runners in watch mode by default. You can add in Jest options as usual.

Example commands

yarn test --coverage

yarn test --watchAll

Tests

Jest is the main test runner that this package supports.

Test files

Everything that matches the globs below will be passed to Jest as a test file:

  • src/**/__tests__/**/*.(j|t)s?(x)
  • src/**/?(*.)(spec|test|t).(j|t)s?(x)

Setting up the test framework

You can use setupTests.ts in your project root to set up the testing framework before each test.

Overriding Jest configuration

You can override the Jest configuration in your package.json with the key jest.

The following options can be overriden:

  • collectCoverageFrom
  • coverageReporters
  • coverageThreshold

Custom Module Paths

TNS supports custom module path mappings. A default custom path mapping is provided in tsconfig.json

{
  "paths": {
    "~/*": ["src/*"]
  }
}

This configuration allows you to import any module which resolves absolutely to src.

// src/lib/a/b/Module.ts

// instead of
import Module from '../../../Module'

// you can do
import Module from '~/Module'

Source Maps

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.

In order to tell Node to use these source maps, you would need to install source-map-support.

# if you're using yarn
yarn add source-map-support

# if you're using npm
npm i -S source-map-support

Then, in src/index.ts, add:

import 'source-map-support/register'

Monorepo Support

To use typescript-node-scripts with a monorepo like lerna + yarn workspaces, you need to add --monorepo to the start and build scripts.

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

Debugging

Visual Studio Code

Webpack Build

TNS incrementally outputs a single bundle in build/bundle.js (via webpack) when running yarn build. To debug the bundle, add the following into the configurations array of your launch.json file:

{
  "type": "node",
  "request": "launch",
  "name": "Debug Webpack Build (via Node)",
  "protocol": "inspector",
  "program": "${workspaceFolder}/build/bundle.js"
}

You can now set breakpoints and run the task in order to debug your build.

TypeScript Source via ts-node

This method is NOT recommended due to ts-node being quite slow at running and compiling your source code.

First off, you would need to install ts-node and tsconfig-paths:

yarn add ts-node tsconfig-paths --dev

Then add the following into your configuration:

{
  "type": "node",
  "request": "launch",
  "name": "Debug Source (ts-node)",
  "protocol": "inspector",
  "runtimeArgs": ["-r", "ts-node/register", "-r", "tsconfig-paths/register"],
  "args": ["${workspaceFolder}/src/index.ts"],
  "env": {
    "TS_NODE_PROJECT": "./tsconfig.json",
    "TS_NODE_FILES": "true"
  }
}

Next, add the files entry into your tsconfig.json:

{
  "files": ["src"]
}

You can now use breakpoints and run the build under debug mode.

Webpack

Overriding Webpack Configuration

This feature is marked as experimental and should not be used in production, unless you know exactly what you're doing

To override and merge your custom webpack configuration, create a file called webpack.config.override.js in your root folder.

This file is then used to be merged into the base configuration that TNS provides, for example:

module.exports = {
  mode: 'production' // always force production mode
}
5.1.0

3 years ago

5.0.0-beta.0

4 years ago

5.0.1

4 years ago

5.0.0

4 years ago

4.1.0

4 years ago

4.0.0

5 years ago

3.2.0-alpha.8

5 years ago

3.2.0-alpha.9

5 years ago

3.2.0-alpha.10

5 years ago

3.2.0-alpha.4

5 years ago

3.2.0-alpha.5

5 years ago

3.2.0-alpha.6

5 years ago

3.2.0-alpha.7

5 years ago

3.2.0-alpha.1

5 years ago

3.2.0-alpha.2

5 years ago

3.2.0-alpha.3

5 years ago

3.1.2

5 years ago

3.1.1

5 years ago

3.1.0

6 years ago

0.0.0-04370b9

6 years ago

0.0.0-794693

6 years ago

0.0.0-78d7200

6 years ago

4.0.0-alpha.0

6 years ago

0.0.0-7d8bcb2

6 years ago

0.0.0-f9213d7

6 years ago

0.0.0-e838833

6 years ago

0.0.0-dcb4896

6 years ago

0.0.0-10f14e5

6 years ago

3.0.0

6 years ago

3.0.0-alpha.1

6 years ago

3.0.0-alpha.0

6 years ago

2.0.6

6 years ago

2.0.5

6 years ago

2.0.4

6 years ago

2.0.3

6 years ago

2.0.2

6 years ago

2.0.1

6 years ago

2.0.0

6 years ago

2.0.0-beta.5

6 years ago

2.0.0-beta.4

6 years ago

2.0.0-beta.3

6 years ago

2.0.0-beta.2

6 years ago

2.0.0-beta.1

6 years ago

2.0.0-alpha.1

6 years ago

2.0.0-alpha.0

6 years ago

1.3.0

6 years ago

1.2.0

7 years ago

1.1.1

7 years ago

1.1.0

7 years ago

1.0.7

7 years ago

1.0.6

7 years ago

1.0.5

7 years ago

1.0.4

7 years ago

1.0.3

7 years ago

1.0.2

7 years ago

1.0.1

7 years ago

1.0.0

7 years ago

0.5.0

7 years ago

0.4.4

7 years ago

0.4.2

7 years ago

0.4.1

7 years ago

0.4.0

7 years ago

0.3.0

7 years ago

0.2.4

7 years ago

0.2.3

7 years ago

0.2.2

7 years ago

0.2.1

7 years ago

0.2.0

7 years ago

0.1.22

7 years ago

0.1.21

7 years ago

0.1.20

7 years ago

0.1.19

7 years ago

0.1.18

7 years ago

0.1.17

7 years ago

0.1.16

7 years ago

0.1.15

7 years ago

0.1.14

7 years ago

0.1.13

7 years ago

0.1.12

7 years ago

0.1.11

7 years ago

0.1.10

7 years ago

0.1.9

7 years ago

0.1.8

7 years ago

0.1.7

7 years ago

0.1.6

7 years ago

0.1.5

7 years ago

0.1.4

7 years ago

0.1.3

7 years ago

0.1.2

7 years ago

0.1.1

7 years ago

0.1.0

7 years ago