Attempts to traverse from filepath to basepath attempting to access type field of package.json. The type
is returned if it is set in the found package.json otherwise commonjs is returned.
Note: With only filepath set this function only reliably returns a positive result when there are no
intermediary package.json files in between a supposed root and path. If provided with malformed
data or there is any error / edge case triggered then 'commonjs' by default will be returned.
Traversal stops at the first valid package.json file as this is how Node works. If the first found package.json
does not have a type field then commonjs is returned.
Attempts to traverse from
filepath
tobasepath
attempting to accesstype
field ofpackage.json
. The type is returned if it is set in the foundpackage.json
otherwisecommonjs
is returned.Note: With only
filepath
set this function only reliably returns a positive result when there are no intermediarypackage.json
files in between a supposed root and path. If provided with malformed data or there is any error / edge case triggered then 'commonjs' by default will be returned.Traversal stops at the first valid
package.json
file as this is how Node works. If the first foundpackage.json
does not have atype
field thencommonjs
is returned.