Skip to content

Node

The Node SDM pack provides various tools for JavaScript and TypeScript projects. It includes full support for building using npm scripts. There are also code inspections, reviewers, and more. You can use all or part of this support.

Find the full API Doc here.

Bundled automations

You can install a chunk of node support by installing the pack with:

sdm.addExtensionPack(nodeSupport({
    inspectGoal,
    autofixGoal,
    review: { typescriptErrors: true },
    autofix: { typescriptErrors: true },
}))

This will get you the autofixes and code inspections listed below.

Autofixes

Let Atomist correct some common nitpicks in code.

Add these autofixes to your autofix goal, or let the pack installation do it for you.

tslint

If a project is TypeScript, is Node, and has tslint.json, the tslintFix will run npm run lint:fix and commit the results for you.

You need to define a “lint:fix” npm script in package.json for this to work. This lets you pass additional options. We have the following in our package.json:

  "scripts": {
      ...
    "lint": "tslint --format verbose --project . --exclude \"{build,node_modules}/**\" --exclude \"**/*.d.ts\" \"**/*.ts\"",
    "lint:fix": "npm run lint -- --fix",
    ...
  }

Add Build Script

Our node build goals expect every project to have a “build” script in package.json. The AddBuildScript autofix adds one if you don’t have it.

The build script will echo something about “build goes here,” giving you a placeholder.

Code Inspections

Notice problems in TypeScript code.

Add this to your autoinspect goal, or let the pack installation do it for you.

DontImportOwnIndex

We like to re-export the definitions that compose our external API from index.ts. Sometimes the IDE tries to import from index.ts even within the project, which creates circular imports and causes problems.

This inspection makes that an error.

PushTests

Push Tests measure qualities of a project or push, so that you can decide whether goals or operations apply to them. This pack includes:

Code Transforms

Code transforms operate on the code inside a project, performing well-defined modifications in place. This pack includes two that are used in generating new Node projects:

Update Package Identification

UpdatePackageJsonIdentification helps transform a seed into a new Node project. It sets the app name, description, version, author, repository, homepage, and bugs URL in package.json.

Update README Title

UpdateReadmeTitle helps transform a seed into a new Node project.

Fingerprinters

Fingerprinters identify significant bits of a project so that we can react when they change.

package-lock.json Fingerprinter

This computes a SHA of the package-lock.json, which changes whenever dependencies are updated.

Goals

This pack includes some useful parts to build your own goals. I recommend looking at the code for these when you decide whether to use them (or copy them).

nodeBuilder

Supply a list of commands to run your build. This builder adds

  • error finding: if the log includes “ERR!” or “[error]” the build fails
  • log interpretation: pulls out the relevant bits of the log for some npm errors and mocha test failures
  • app info extraction: pulls the project version name and out of package.json

Register this builder on a build goal to use it:

import { Build } from "@atomist/sdm-pack-build";

const build = new Build().with({
    name: "npm-build",
    builder: nodeBuilder("npm run compile", "npm test"),
    pushTest: IsNode,
});

npm publish

executePublish as a GoalExecutor; you can use it to create a custom goal that publishes to npm.

Examples of this pack in action

Within Atomist, we use this pack extensively in the node support within our own SDM.