node2nix icon indicating copy to clipboard operation
node2nix copied to clipboard

Log when name error is found

Open Fresheyeball opened this issue 5 years ago • 1 comments

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.

Fresheyeball avatar Jul 04 '20 18:07 Fresheyeball

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 node2nix considers it a package.json specification and requires a name and version field.
  • If a JSON file defines an array, then node2nix considers 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.

svanderburg avatar Jul 08 '20 20:07 svanderburg