npm i resolve-dependencies
resolve-dependencies
is the very originally named bundler for nexe. It wasn't our intention to build a bundler but that is kind of what this is.
Options
: Object | string -- the entry to start from (if string)entries
: string[] -- a list of entrypoints to traverse, resolved against cwdcwd
: string -- the base directory that the resolution occurs fromloadContent
: boolean -- indicates that the content should be included int he FileMap (this may be unreasonable for large dependency trees)files
: ({ [key: string]: File | null })[] -- a cache of already resolved filesexpand
: 'all' | 'none' | 'variable' -- how module contexts should be expanded to include extra files
All options are deeply merged, string options are added as entries
Result returns a Promise of a result object:
Result
: Objectentries
: { [key: entry]: File } - all the entries as provided to theresolve
method and the tree of connectedfiles
files
: { [key: absPath]: File } - all resolved files keyed by their absolute pathwarnings
: string[] - an array warnings generated while processing thefiles
A File
has the following shape
File
: Object -- An object representing a filesize
: number -- file size of the link or fileabsPath
: string -- absolute path to the filemoduleRoot
: string | undefined -- Directory containing a modules package.jsonpackage
: any | undefineddeps
: { [key: request]: File | null } -- Dependencies identified in the file, keyed by requestbelongsTo
: File | undefined -- The main file of the owning modulerealSize
: number | undefined -- set to the realfile size if the absPath is a symlinkrealPath
: string | undefined -- set to the realpath if the absPath is a symlinkcontents
: string | nullcontextExpanded
: booleanvariableImports
: boolean
import resolveDependencies from 'resolve-dependencies'
const { entries, files } = resolveDependencies('./entry-file.js')
console.log(entries['./entry-file.js'])
// {
// absPath: "/path/to/entry-file.js",
// contents: "console.log('hello world')",
// realSize: 26,
// realPath: "/path/to/entry/lib/file.js"
// size: 12
// variableImports: false,
// deps: {
// "./dependency": {
// absPath: "/path/to/dependency.js"
// ...
// },
// path: null, //node builtin does not resolve
// mkdirp: {
// absPath: "/path/to/node_modules/mkdirp/index.js",
// modulePath: "/path/to/node_modules/mkdirp",
// package: {
// name: "mkdirp"
// ...
// }
// }
// }
// }
// `files` is a similar structure to entries, but
// is flat and keyed by the file's absolute path.