ubborg-cjsbundle-depscan-helper-pmb
v0.1.2
Published
Express CJS bundle dependencies in a way that can be picked up by naive dependency scanners.
Downloads
3
Readme
ubborg-cjsbundle-depscan-helper-pmb
Express CJS bundle dependencies in a way that can be picked up by naive dependency scanners.
API
This module exports one function:
relateCjsBundles(bun, fakeCode[, opt])
Declares relations (see kind
below) of ubborg bundle bun
to CJS bundles.
The IDs of the related CJS bundles are obtained from fakeCode
using an algorithm equivalent to:
- Split
fakeCode
into lines. - Discard outer whitespace from each line.
- Discard lines that start with
#
or//
. - Discard lines that contain less than two quote characters.
- In each line, discard the first quote character and anything in front.
- In each line, discard the last quote character and anything behind it.
- Discard lines that are (now) empty.
- Treat remaining lines as CJS module IDs.
Returns a Promise for an array of all related resource plans.
opt
is an optional options object that supports these keys:
kind
: The kind of relation. Should be a string. Defaults to'needs'
.nMin
: The minimum number of module IDs that are expected to be found infakeCode
. Default:1
opt
may also be a non-empty string, in which case it is used as the kind
.
Usage
see usage_example.mjs.
Known issues
- Needs more/better tests and docs.
License
ISC