zumwald / oss-attribution-generator

utility to parse bower and npm packages used in a project and generate an attribution file to include in your product
MIT License
37 stars 23 forks source link

Unable to locate package.json from local package dependencies #25

Open mtomaska opened 4 years ago

mtomaska commented 4 years ago

I run into an issue where the generator would fail with an error \<package name>: unable to locate package.json . The package for which the script fails to locate the package.json is inside a node_module directory of another local package which is referenced by a relative path in my main project.

For example:

mainProject package.json: "dependencies: { "@mylocalPackageFoo: "file: ../mylocalPackage" }

local package directory structure: ../mylocalPackage/node_module/\<name of the package for which the generator failed>

Note, the package for which the generator fails to find package.json is not a direct dependency of the local package(not listed in its package.json).

The packagePath used here is incorrect for the scenario described above.

Workaround The package.json is usually located next to the license file so I decided to add one more check for package.json at the location of the license file. I simply added else if on the line 139 before giving up.

else if (!itemAtPath) { packageJson = jetpack.read(path.join(path.dirname(package['licenseFile']), 'package.json'), 'json'); }