Log when name error is found
I recently learned that when using a custom .json file for node2nix a missing name is reported as an error. However, if there is also a package.json with no name, we get the old error.
- package.json // no name
- node2nix.json // has name and version
node2nix -i node2nix.json
results in
name: this.config.name.replace("@", "_at_").replace("/", "_slash_"), // Escape characters from scoped package names that aren't allowed
This leads me to believe that the config.name undefined error is just not so limited it can be addressed with a single check. This PR adds more logging so that when this error occurs for yet unknown reasons, it's easier to debug.
Hi, could you perhaps provide me an example, or simplified example that can reproduce the problem you're facing?
Although I could probably do a better job in error prevention/handling, printing a warning message in a conversion method is a somewhat strange place IMO. I much rather do this before the generation phase starts ,e.g. in the very beginning or during the download process.
Btw, about node2nix's requirements for name and version fields: it actually does not matter what name a JSON file has -- the only thing that matters is the data structure that the JSON file declares:
- If a JSON file defines an object, then
node2nixconsiders it apackage.jsonspecification and requires anameandversionfield. - If a JSON file defines an array, then
node2nixconsiders each entry a package that is obtained from a specific kind of source (e.g. NPM registry, Git repo, URL, directory etc.). It basically interprets string elements as the latest version of a package from the NPM registry, whereas an object is interpreted in the same way as a NPM project dependency.
Maybe this can be explained more clearly in the README.md file.