Skip to content

Conversation

@isaacs
Copy link
Contributor

@isaacs isaacs commented Feb 14, 2020

Related to npm/rfcs#102.

wip, needs tests.

@isaacs isaacs requested a review from a team as a code owner February 14, 2020 02:40

const flatOptions = npm => ({
// Note that many of these do not come from configs or cli flags
// per se, though they may be implied or defined by them.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Speaking as someone who maintains a CLI (lerna) that implements npm publishing using current libnpm* packages (with an alarming amount of copypasta from npm's source) and attempts to stay as consistent as possible with npm CLI patterns, extracting "How npm reads and serializes its configuration" into a separate package would be a great boon.

I realize it's extremely low on the priority list, but I just wanted to register the sentiment while it's top-of-mind, and before I inevitably feel the urge to make more copypasta...

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, that would be really nice, I agree. (Also speaking as someone who maintains and uses a lot of npm deps ;)

We had once upon a time a package called npmconf that housed all of the config reading and management as well as all the default values. The problem was that every time we wanted to add or modify a config value, it meant an update in a bunch of disparate places, and it was kind of a pain to manage, so we folded it back in. This gets more convoluted when we have a bunch of other modules expecting to get a preferOnline option and need to know to convert that from config.get('prefer-online') (or even config.get('cache-min')<=0). The goal of figgy-pudding was to make this easier, but in practice, has made it much harder, which is why we're moving to the simplest possible approach, and from there can build up something a bit more maintainable. Just taking an inventory of all our configs as part of this upgrade process has been really enlightening. The clever technical solution didn't actually get at the root of the problem, and doing the work to dredge it all up and clean the actual mess has been sorely needed.

Some day, I'd really like to consider dropping nopt in favor of something a bit more simple and declarative, like jackspeak or even yargs, and then have a package that doesn't handle defaults, but just reads and updates config files, so that the set of defaults and expected types can still live in npm/cli maybe. It's a weird sort of animal to cut in half, though, because I do want to be able to provide some feedback to the user that --umask=notanumber is an invalid config value. So I'm not sure exactly what that'll look like. We may be in this "create a pojo and share it" mode for a while, most likely at least through the v7 release line. It just makes it so much easier to manage our deps if they can get an options object like any other JavaScript module out there does, without the extra translation layer of fp.

@isaacs
Copy link
Contributor Author

isaacs commented Feb 14, 2020

Suggestion was made (and I think it's a good ideal) to Object.freeze() this object. npm/rfcs#102 (comment)

@isaacs isaacs force-pushed the isaacs/config-opts-object branch from 27e96cd to 2265302 Compare February 14, 2020 22:34
@claudiahdz claudiahdz force-pushed the feature/update-deps-v1 branch from 1421928 to ed30363 Compare February 18, 2020 21:42
@isaacs
Copy link
Contributor Author

isaacs commented Feb 19, 2020

The good bits of this landed already in the feature/update-deps-v1 branch, so I'm closing this PR.

@isaacs isaacs closed this Feb 19, 2020
@isaacs isaacs deleted the isaacs/config-opts-object branch October 2, 2020 21:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants