Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

bob-ts

Package Overview
Dependencies
Maintainers
1
Versions
37
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

bob-ts

Transpile your **TypeScript** projects quickly using **esbuild** + **rollup**, made to accelerate and simplify the TypeScript development with watcher and first class support for JavaScript testing frameworks.

  • 1.0.0
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
238
increased by5.78%
Maintainers
1
Weekly downloads
 
Created
Source

bob-ts

Transpile your TypeScript projects quickly using esbuild + rollup, made to accelerate and simplify the TypeScript development with watcher and first class support for JavaScript testing frameworks.

This library doesn't handle type definitions, but you can add them simply doing tsc --declaration --emitDeclarationOnly

Install

pnpm add -D bob-ts esbuild
yarn add -D bob-ts esbuild
npm install -D bob-ts esbuild

Usage

By default bob-ts is ESM first, but you can change it to be either CJS with: -f cjs or -f interop to transpile for both CommonJS & ESM.

If you don't have "type": "module" in your package.json, ESM will be outputted with the extension .mjs and CJS as .js

If you do have "type": "module" in your package.json, ESM will be outputted with the extension .js and CJS as .cjs.

Build

Usage: bob-ts [options]

Options:
  -d, --dir <directory>      Custom output dir (default: "dist")
  -i, --input <patterns...>  Input patterns (default: ".")
  -f, --format <format>      Format, it can be 'cjs', 'esm' or 'interop' (default: "esm")
  --cwd <dir>                Custom target directory (default: "__current_directory__")
  --no-clean                 No clean output dir (default: true)
  -h, --help                 display help for **command**

This will transpile all your src folder, and its structure will be kept as is in the dist folder

{
  "scripts": {
    "prepare": "bob-ts -i src"
  }
}

Development / Watch Mode

Usage: bob-ts-watch [options]

Options:
  -d, --dir <directory>      Custom output dir (default: "dist")
  -i, --input <patterns...>  Input patterns (default: ".")
  -f, --format <format>      Format, it can be 'cjs', 'esm' or 'interop' (default: "esm")
  --no-clean                 No clean output dir (default: true)
  --cwd <dir>                Custom target directory (default: "/home/pablosz/learner-model-gql/gateway")
  -c, --command <cmd>        Execute script after successful JS build
  -h, --help                 display help for command
{
  "scripts": {
    "dev": "bob-ts-watch -i src -c \"node dist/index.mjs\""
  }
}

Usage with Testing

The primary reason that for the default input being "." is because this library has primary support for being used for JavaScript test frameworks like Mocha and Node-Tap, and having all the tests files inside an specific test directory, for example, test, and simply executing the transpiled version of your tests with all the sourcemaps, being a better and faster alternative than ts-node/register, specially for ESM support, which ts-node struggles with.

Example structure

src/
  index.ts
test/
  main.test.ts
package.json

Mocha

pnpm add -D mocha nyc @istanbuljs/esm-loader-hook
yarn add -D mocha nyc @istanbuljs/esm-loader-hook
npm install -D mocha nyc @istanbuljs/esm-loader-hook

ESM

{
  "scripts": {
    "dev": "bob-ts-watch -c \"node/dist/src/index.mjs\"",
    "start": "bob-ts && node/dist/src/index.mjs",
    "test": "bob-ts && nyc mocha dist/test",
    "test:watch": "bob-ts-watch -c \"nyc mocha dist/test\""
  },
  "mocha": {
    "enable-source-maps": true,
    "no-warnings": true,
    "experimental-loader": "@istanbuljs/esm-loader-hook"
  }
}

CJS

{
  "scripts": {
    "dev": "bob-ts-watch -f cjs -c \"node dist/src/index.js\"",
    "start": "bob-ts -f cjs && node dist/src/index.js",
    "test": "bob-ts -f cjs && nyc mocha dist/test",
    "test:watch": "bob-ts-watch -f cjs -c \"nyc mocha dist/test\""
  },
  "mocha": {
    "enable-source-maps": true
  }
}

Node Tap

pnpm add -D tap @istanbuljs/esm-loader-hook
yarn add -D tap @istanbuljs/esm-loader-hook
npm install -D tap @istanbuljs/esm-loader-hook

ESM

Assumming that your tests are inside a test directory

{
  "scripts": {
    "dev": "bob-ts-watch -c \"node/dist/src/index.mjs\"",
    "start": "bob-ts && node/dist/src/index.mjs",
    "test": "bob-ts && tap dist/test",
    "test:watch": "bob-ts-watch -c \"tap dist/test\""
  },
  "tap": {
    "node-arg": ["--no-warnings", "--experimental-loader", "@istanbuljs/esm-loader-hook"]
  }
}

CJS

{
  "scripts": {
    "dev": "bob-ts-watch -f cjs -c \"node/dist/src/index.js\"",
    "start": "bob-ts -f cjs && node/dist/src/index.js",
    "test": "bob-ts -f cjs && tap dist/test",
    "test:watch": "bob-ts-watch -f cjs -c \"tap dist/test\""
  }
}

LICENSE

MIT

FAQs

Package last updated on 01 Sep 2021

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc