module: empty object fix in InternalModuleReadJSON for #30245
This fixes the bug posted in https://github.com/nodejs/node/issues/30245, where having a package.json with no "type" field would not apply the CommonJS default.
The issue turned out to be that InternalModuleReadJSON applies a string filter to avoid parsing unnecessary package.json files, but the case of the filter failing and a file being not found were indistinguishable. (and that is why in that issue report, having a "repository" field with a "type" was enough to get it to work again!)
The implemented fix returns "{}"
for when the filter finds no known package.json properties, to indicate it exists but has no properties we are interested in to avoid treating it the same as a not found package.json file. This way the default can still apply.
Checklist
-
make -j4 test
(UNIX), orvcbuild test
(Windows) passes -
tests and/or benchmarks are included -
commit message follows commit guidelines