Statically parse dependency trees of JavaScript and TypeScript projects

Downloads in past


1.2.73 years ago6 years agoMinified + gzip package size for hawthorn in KB


Statically parse dependency trees of JavaScript and TypeScript projects.
Build Status npm version Dependency Status
Supports CommonJS and ES6 imports, and TSX.


hawthorn is a static analyzer that can build a dependency tree data structure out of a JavaScript or TypeScript project by recursively parsing and scanning for require() calls and import expressions.


The easiest way to use hawthorn is with its example CLI that you can install with:
npm install --global hawthorn

The CLI takes a --directory/-d option which is the base directory of the project you want to scan, and one or more glob patterns to use as entry points (defaults to lib/**/*.js).
You can test hawthorn on itself by running:
$ git clone https://github.com/jviotti/hawthorn.git
$ hawthorn --directory ./hawthorn 'lib/*.js' > tree.json

See an example of the generated output here: https://github.com/jviotti/hawthorn/blob/master/example.json.


If you install hawthorn as a dependency, you can require('hawthorn') and the module will export a top level function that takes an array of path globs, an options object, and resolves a JavaScript object with the resulting dependency tree.

hawthorn(String[] paths, Object options) -> Object

The available options are:
  • directory: The base directory to use when scanning. Should be usually set
to the root directory of the project you want to scan
  • types: The types of dependencies to consider. Defaults to ` 'module',
'local', 'internal' `
const hawthorn = require('hawthorn')
const tree = hawthorn([
], {
  directory: '~/projects/hawthorn'


If you're having any problem, please raise an issue on GitHub and I'll be happy to help.


Run the test suite by doing:
npm test


Before submitting a PR, please make sure that you include tests, and that the linter runs without any warning


The project is licensed under the Apache 2.0 license.