node icon indicating copy to clipboard operation
node copied to clipboard

module: expose `getPackageScopeConfig` & add `findNearestPackageJSON`

Open JakobJingleheimer opened this issue 1 year ago • 2 comments

This draft is not ready for review. Opening it in its current state for visibility.

JakobJingleheimer avatar Sep 18 '24 09:09 JakobJingleheimer

Review requested:

  • [ ] @nodejs/loaders

nodejs-github-bot avatar Sep 18 '24 09:09 nodejs-github-bot

I'm planning to adjust GetPackageJSON to optionally include all fields from the package.json. I think for unrecognised fields, I need to generically handle (parse) each kind of valid json value. Does that functionality already exist in c++, or do I need detect each type and handle the parsing specifically?

GetPackageJSON currently has a loop with a bunch of if (key = …), else if (key = …), else if (key = …). If I need to handle each kind of value, I'm thinking to extract those to some kind of hash-map:

  • PJSONParsers['exports']
  • PJSONParsers['imports']
  • PJSONParsers['name']
  • PJSONParsers['script']
  • PJSONParsers['type']
  • PJSONParsers['default'] ← handles unrecognised fields (which can have any valid json value, and calls various "nonspecific*" methods on PJSONParsers)
  • PJSONParsers['nonspecificString']
  • PJSONParsers['nonspecificMap'] ← will call other "nonspecific*" methods

Side-note: I haven't worked in c++ in ~20 years, so I can't remember if there is potentially a performance implication here. I'm thinking extracting those avoids re-constructed on each loop (but that may be offset by the cost of function call(s)).

JakobJingleheimer avatar Sep 29 '24 16:09 JakobJingleheimer

Splitting this into atomic PRs:

  • https://github.com/nodejs/node/pull/55173

JakobJingleheimer avatar Sep 30 '24 10:09 JakobJingleheimer