Trucker is a tool that helps manage dependencies between javascript files
It has three main functions:
-
Show all inbound and outbound dependencies for matching source files. (
trucker --info filename.jsortrucker -i filename.js) -
Move/rename source files while fixing up the paths used in imports. (
trucker --move source destinationortrucker -m source destination) -
Find unused files (files that are not importd by any other files). (
trucker --unusedortrucker -u)
Why is it called trucker? Because it hauls your files around without breaking them.
-
Javascript
-
Typescript
-
CommonJS 6 - i.e.
module.exportsandrequire() -
ECMAScript 6 - i.e.
exportandimport -
TypeScript - i.e.
exportandimport
npm install -g trucker
Trucker runs on node.js 10 or greater.
To move files:
trucker --move [flags] source [additional sources...] destination
To get info about files:
trucker --info [optional file paths]
If no paths are passed, trucker --info will spit out information for all files in the base path (see options below).
(experimental)
To get info about files:
trucker --info --format dot [optional file paths]
This will output a graphviz-compatible dot file that can be rendered into an image file by the dot tool that is part of graphviz.
For example:
trucker -i -f dot > ./build/dependencies.dot
dot -Tpng -o ./build/dependencies.png ./build/dependencies.dot
open ./build/dependencies.png
Here's a graph of trucker's internal structure, generated by the following command:
dot -Tsvg -o ./trucker-graph.svg <(trucker --exclude test --info --format dot)
Find files that are not importd by any other source files in given path
trucker --unused [path]
in the examples directory (provided), you can try the following (add n for dry run mode if desired):
-
Get info about all dependencies in the current directory and all sub directories
trucker --info -
Get dependencies for just one subdirectory
trucker -i stark/ -
Move a single file:
trucker --move stark/eddard.js deceased/ -
Move a single file, specifying destination path:
trucker -m stark/eddard.js deceased/ned.js -
Move multiple files explicitly
trucker -m stark/eddard.js tully/catelyn.js deceased/ -
Move a directory:
trucker -m stark deceased/stark -
Paths are automatically created:
trucker -m stark/eddard.js deceased/in/book1/
h, --help prints the help
n, --dry-run tells trucker not to move any files, but to instead print out a list of all of the changes that would have been made if this option was not set.
s, --scope can be used to expand or contract the set of files that trucker searches for dependencies. This defaults to the present working directory. If you have a very large project you may wish to constrain the scope for performance reasons (analysis takes time), or in some cases you may wish to expand the scope beyond the current directory. Use scope for this.
q, --quiet suppress output
e, --exclude Add file glob pattern to ignore to those found in the .gitignore file. Repeat this options to add many patterns.
Trucker ignores files using the first .gitignore it finds, starting from the base directory (usually cwd), and ascending to the root.
See too the --exclude option above.
Trucker does not resolve dynamic require and import statements.
Trucker can't recognize dynamic requires or imports that consiste of more than just a simple path string, for example:
var x = '../foo/bar';
var y = require(x);When moving a folder, trucker does not move other non-javascript/typescript files that exist in the folder, next to the source files.