Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

RFC for context config parameter #336

Merged
merged 6 commits into from
Sep 13, 2021
Merged

RFC for context config parameter #336

merged 6 commits into from
Sep 13, 2021

Conversation

nlf
Copy link
Contributor

@nlf nlf commented Mar 8, 2021

This is a suggestion to allow for users to leverage the npm CLI to modify their project-level .npmrc files, as well as to remove ambiguity and inconsistency in the behavior of npm exec

@nlf
Copy link
Contributor Author

nlf commented Mar 8, 2021

this is going to be expanded to apply the where parameter to npm exec tomorrow updated!

@nlf nlf marked this pull request as draft March 8, 2021 23:13
@ruyadorno
Copy link
Contributor

heads up: the name "where" might be a little confusing in some situations and problematic in some other ones

(spoiler alert: I have all that info on top of my mind since I was thinking about turning this repeating where logic into its own mixin of sorts for all commands 😅 )

Given all that context, may I suggest picking a different name to err on the safe side?

@nlf
Copy link
Contributor Author

nlf commented Mar 9, 2021

fair enough, how about location? I'll try to think of others.. where felt so right

@ruyadorno
Copy link
Contributor

ruyadorno commented Mar 9, 2021

maybe it's the other way round and we might want to migrate the current usage of where to something else... I particularly prefer using cwd instead (and that's also used in some share of our ecosystem of packages) - Given the current timing with the multiple efforts on cleaning up configs, that might be a good alternative to propose too 👍

@nlf
Copy link
Contributor Author

nlf commented Mar 9, 2021

i like that better, where is such a perfect fit for this.

i'll use your head start and see if i can figure out what other modules in our ecosystem care about the where option so we can have a comprehensive list here of what will need modified.

@nlf nlf marked this pull request as ready for review March 9, 2021 16:03
@nlf nlf changed the title chore: add rfc for where config parameter RFC for where config parameter Mar 9, 2021
@nlf
Copy link
Contributor Author

nlf commented Mar 9, 2021

i didn't do the work ahead of time to audit the dependencies, but did make a note under implementation that work must be done before implementation here

@nlf
Copy link
Contributor Author

nlf commented Jun 16, 2021

due to the ambiguity of where as a config parameter, i've renamed it to context in the spirit of tools like kubectl which use context to refer to a specific portion of configuration.

our implementation will differ, however, as instead of referring to keys within one config file like kubectl the npm config command will use the context to refer to a named configuration location without the need to specify paths. for npm exec the context will refer to a named source a binary should be found in.

we chose this over something more specific like --config-location or --bin-location to avoid the implication that a directory can be provided. the context will always specifically be an enum with known values. language like "run foo from the global context" or "set the config in the local context" make sense, and there appears to be extremely minimal overlap with existing options in our dependencies.

@darcyclarke
Copy link
Contributor

darcyclarke commented Jun 16, 2021

I'm bias but think this is the right approach/nomenclature & helps standardize/centralize our understanding of these existing/known contexts

@darcyclarke darcyclarke removed the Agenda will be discussed at the Open RFC call label Jun 17, 2021
@@ -0,0 +1,116 @@
# {{TITLE: Add a `context` parameter for `npm config` and `npm exec` commands}}
Copy link
Contributor

Choose a reason for hiding this comment

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

@nlf I think we can remove the {{TITLE: ... }} wrapping syntax

Copy link
Contributor

@darcyclarke darcyclarke left a comment

Choose a reason for hiding this comment

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

Lets try to remove/update some of bikeshedding/unresolved questions


## Unresolved Questions and Bikeshedding

~Is `where` the best name for this config? What if there are too many conflicts in dependencies?~ EDIT: Document updated to use `context` instead of `where`.
Copy link
Contributor

Choose a reason for hiding this comment

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

I think we can remove this question since we've updated the name & consider that to be better/more concise then where was.

Copy link
Contributor

Choose a reason for hiding this comment

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

Sorry if I missed this discussion - I do not find "context" to be clear at all. It's a word with tons of conflated meanings.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

you didn't miss it, we did some bike shedding trying to come up with something else outside of the rfc calls. we also discussed having separate flags for each purpose like --config-location/--bin-location but there was some concern that "location" implies the value can be a path, which is not something we want to support. most alternatives i came up with had the same problem, such as --config-source. something like --config-type/--bin-type could work maybe?

we went with context because it is somewhat vague, but is language that can be reasoned about. if you've got better suggestions, though, i'm all ears. it's time to pick a color for our bike shed so we can get to painting it.

Copy link
Contributor

Choose a reason for hiding this comment

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

It is a location tho - location doesn’t necessarily imply path, and since it’s an enum, it’d immediately error if an invalid value was passed, so any confusion would be rapidly dispelled.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

what about just --location? npm config set foo=bar --location=user isn't terrible, nor is npx --location=remote tap, -L is open as a short form too (-l is --long)

Copy link
Contributor

Choose a reason for hiding this comment

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

That seems fine with me.


~Is `where` the best name for this config? What if there are too many conflicts in dependencies?~ EDIT: Document updated to use `context` instead of `where`.

What would the shortcut be? `-c` is currently the short form of `--call`.
Copy link
Contributor

Choose a reason for hiding this comment

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

-c is --call & -C is --prefix (a bit confusing there on that second one for sure....) so I feel like we could use -x


### `npm config`

Should we prevent a user from setting protected fields like `_auth` or `_token` to a local config?
Copy link
Contributor

Choose a reason for hiding this comment

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

Let's stay consistent with whatever is supported by npm config by default &/or when run in the global context. If we support different behaviour in the user or global contexts today I'd wonder why; The whole point of unlocking local/project-level context is to eliminate the need to manually manage an .npmrc file. Limiting the fields you can set would also reduce the usability of defining the local context

Copy link
Contributor Author

Choose a reason for hiding this comment

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

that's a fair point 👍


### `npm exec`

Should we prompt when multiple matches are found? If we would prompt but are unable to, what should we do?
Copy link
Contributor

Choose a reason for hiding this comment

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

Not sure what this means? I feel like this is already answered by the note, further up, outlining that we will follow the existing binary resolution pattern in npm exec (ref. https://github.com/npm/rfcs/pull/336/files#diff-e69970007bc5185a814912b41199ac9648ecfc70be343865a55d558f4c417028R56-R57)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

iirc there was some concern about which bin was linked being non-deterministic, but after a quick read through of bin-links it seems like that should only be possible if the user passed --force (or somehow we ended up reifying something deeper in the dep tree before something shallower, which shouldn't be possible since arborist sorts deps so shallowest are first) so maybe it's not something to worry about

@nlf nlf merged commit 31a691b into latest Sep 13, 2021
@nlf nlf deleted the nlf/where-option branch September 13, 2021 21:20
@ljharb
Copy link
Contributor

ljharb commented Sep 13, 2021

@nlf should the title of this PR be updated?

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants