mwittig / npm-license-crawler

Analyzes license information for multiple node.js modules (package.json files) as part of your software project.
BSD 3-Clause "New" or "Revised" License
234 stars 45 forks source link

--onlyDirectDependencies option fails if package.json is missing a 'dependencies' section #18

Closed adamsteinbok closed 6 years ago

adamsteinbok commented 6 years ago

When using the '--onlyDirectDependencies' option on a project with a package.json that has no 'dependencies' field (e.g a project that only has devDependencies), the following error is thrown:

/usr/local/lib/node_modules/npm-license-crawler/lib/index.js:23

                    onlyDirectDependenciesFilter[packageJsonContents.name] = Object.keys(packageJsonContents.dependencies);
                                                                                    ^

TypeError: Cannot convert undefined or null to object
    at Function.keys (<anonymous>)
    at DirectoryReader.<anonymous> (/usr/local/lib/node_modules/npm-license-crawler/lib/index.js:23:85)
    at DirectoryReader.emit (events.js:180:13)
    at /usr/local/lib/node_modules/npm-license-crawler/lib/directoryreader.js:145:26
    at FSReqWrap.oncomplete (fs.js:171:5)

It seems like this is down to the packageJsonContents.dependencies condition in the if-statement at line 23 of 'index.js' being insufficient. Adding a typeof packageJsonContents.dependencies !== 'undefined' condition should resolve this.

mwittig commented 6 years ago

Thanks for reporting. Should be fixed in release npm-license-crawler@0.1.8. Re-open otherwise.