Deno Tools

Deno provides some built-in tooling support for TypeScript and JavaScript.

Deno Tools

Let’s understand a few of the deno tools.

  • Bundler
  • Formatter
  • Linter
  • Documentation Generator
  • Dependency Inspector
  • Repl

Bundler

deno bundle [URL] will output a single JavaScript file, which includes all dependencies of the specified input.

> deno bundle https://deno.land/std@0.81.0/examples/colors.ts colors.bundle.js
Bundle https://deno.land/std@0.81.0/examples/colors.ts
Download https://deno.land/std@0.81.0/examples/colors.ts
Download https://deno.land/std@0.81.0/fmt/colors.ts
Emit "colors.bundle.js" (9.83KB)

Formatter

Auto formats Typescript and Javascript code.

# format all JS/TS files in the current directory and subdirectories
deno fmt

# format specific files
deno fmt myfile1.ts myfile2.ts

# check if all the JS/TS files in the current directory and 
# subdirectories are formatted
deno fmt --check

# format stdin and write to stdout
cat file.ts | deno fmt -

Linter

Deno ships with a built-in linter for Typescript and Javascript.

# lint all JS/TS files in the current directory and subdirectories
deno lint --unstable

# lint specific files
deno lint --unstable myfile1.ts myfile2.ts

# print result as JSON
deno lint --unstable --json

# read from stdin
cat file.ts | deno lint --unstable -

refer to this link for the available linting rules.

Note: linter is a new feature and still unstable thus it requires --unstable flag

Documentation Generator

deno doc is used to print the JSDoc documentation for each of the module’s exported members.

Filename: add.ts

/**
 * Adds x and y.
 * @param {number} x
 * @param {number} y
 * @returns {number} Sum of x and y
 */
export function add(x: number, y: number): number {
  return x + y;
}

When we run the deno doc command, it will print the JSDoc to the standard output.

deno doc add.ts
function add(x: number, y: number): number
  Adds x and y. @param {number} x @param {number} y @returns {number} Sum of x and y

Dependency Inspector

deno info [URL] will inspect the ES module and all of its dependencies.

  1. It works with any local or remote ES module.
  2. It can be used to display information about cache location.

deno tools

Repl

deno repl starts a read-eval-print-loop that lets you interactively build-up program state in the global context. For keyboard shortcuts and respective actions check here.

In this section, we have learned built-in deno tools. In the next section, we will explore resources to learn deno.