rushstack icon indicating copy to clipboard operation
rushstack copied to clipboard

[node-core-libary] Require at least a "name" field in package.json files

Open eemeli opened this issue 3 years ago • 1 comments

Summary

Fixes #2070

PackageJsonLookup is erroneously presuming that all package.json files include a "name" field, and will complain when attempting to load a package.json file that does not include that field.

In the npm docs on the file format, it's quite clear that the name+version requirements only apply to published packages:

If you don't plan to publish your package, the name and version fields are optional.

This means that when e.g. a third-party dependency follows the guidance given for the "type" field in the Node.js documentation, it's not possible to successfully run api-extractor.

Details

To fix this, each package.json file is loaded during lookup before returning it as valid, and in case the load fails with the The required field "name" was not found error, the lookup continues in the parent directory.

This should have no real-world effect on performance, as practically all such lookups are immediately followed by a load, which will then use the result cached during the lookup.

How it was tested

A test case is added to validate this behaviour.

eemeli avatar Jul 28 '22 18:07 eemeli

CLA assistant check
All CLA requirements met.

ghost avatar Jul 28 '22 18:07 ghost