You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: workspaces/config/CHANGELOG.md
+4-1Lines changed: 4 additions & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -373,7 +373,10 @@
373
373
374
374
### ⚠️ BREAKING CHANGES
375
375
376
-
* unscoped auth configuration is no longer automatically scoped to a registry. the `validate` method is no longer called automatically. the `_auth` configuration key is no longer split into `username` and `_password`. errors will be thrown by `validate()` if problems are found.
376
+
* unscoped auth configuration is no longer automatically scoped to a registry.
377
+
the `validate` method is no longer called automatically.
378
+
the `_auth` configuration key is no longer split into `username` and `_password`.
379
+
errors will be thrown by `validate()` if problems are found.
377
380
*`@npmcli/config` is now compatible with the following semver range for node: `^14.17.0 || ^16.13.0 || >=18.0.0`
Copy file name to clipboardExpand all lines: workspaces/config/README.md
+63-94Lines changed: 63 additions & 94 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -2,53 +2,42 @@
2
2
3
3
Configuration management for the npm cli.
4
4
5
-
This module is the spiritual descendant of
6
-
[`npmconf`](http://npm.im/npmconf), and the code that once lived in npm's
5
+
This module is the spiritual descendant of [`npmconf`](http://npm.im/npmconf), and the code that once lived in npm's
7
6
`lib/config/` folder.
8
7
9
-
It does the management of configuration files that npm uses, but
10
-
importantly, does _not_ define all the configuration defaults or types, as
11
-
those parts make more sense to live within the npm CLI itself.
8
+
It does the management of configuration files that npm uses, but importantly, does _not_ define all the configuration defaults or types, as those parts make more sense to live within the npm CLI itself.
12
9
13
10
The only exceptions:
14
11
15
-
- The `prefix` config value has some special semantics, setting the local
16
-
prefix if specified on the CLI options and not in global mode, or the
17
-
global prefix otherwise.
18
-
- The `project` config file is loaded based on the local prefix (which can
19
-
only be set by the CLI config options, and otherwise defaults to a walk
20
-
up the folder tree to the first parent containing a `node_modules`
21
-
folder, `package.json` file, or `package-lock.json` file.)
12
+
- The `prefix` config value has some special semantics, setting the local prefix if specified on the CLI options and not in global mode, or the global prefix otherwise.
13
+
- The `project` config file is loaded based on the local prefix (which can only be set by the CLI config options, and otherwise defaults to a walk up the folder tree to the first parent containing a `node_modules` folder, `package.json` file, or `package-lock.json` file.)
22
14
- The `userconfig` value, as set by the environment and CLI (defaulting to
23
15
`~/.npmrc`, is used to load user configs.
24
16
- The `globalconfig` value, as set by the environment, CLI, and
25
-
`userconfig` file (defaulting to `$PREFIX/etc/npmrc`) is used to load
26
-
global configs.
27
-
- A `builtin` config, read from a `npmrc` file in the root of the npm
28
-
project itself, overrides all defaults.
17
+
`userconfig` file (defaulting to `$PREFIX/etc/npmrc`) is used to load global configs.
18
+
- A `builtin` config, read from a `npmrc` file in the root of the npm project itself, overrides all defaults.
29
19
30
20
The resulting hierarchy of configs:
31
21
32
-
- CLI switches. eg `--some-key=some-value` on the command line. These are
33
-
parsed by [`nopt`](http://npm.im/nopt), which is not a great choice, but
34
-
it's the one that npm has used forever, and changing it will be
35
-
difficult.
36
-
- Environment variables. eg `npm_config_some_key=some_value` in the
37
-
environment. There is no way at this time to modify this prefix.
38
-
- INI-formatted project configs. eg `some-key = some-value` in the
39
-
`localPrefix` folder (ie, the `cwd`, or its nearest parent that contains
40
-
either a `node_modules` folder or `package.json` file.)
41
-
- INI-formatted userconfig file. eg `some-key = some-value` in `~/.npmrc`.
22
+
- CLI switches.
23
+
eg `--some-key=some-value` on the command line.
24
+
These are parsed by [`nopt`](http://npm.im/nopt), which is not a great choice, but it's the one that npm has used forever, and changing it will be difficult.
25
+
- Environment variables.
26
+
eg `npm_config_some_key=some_value` in the environment.
27
+
There is no way at this time to modify this prefix.
28
+
- INI-formatted project configs.
29
+
eg `some-key = some-value` in the
30
+
`localPrefix` folder (ie, the `cwd`, or its nearest parent that contains either a `node_modules` folder or `package.json` file.)
31
+
- INI-formatted userconfig file.
32
+
eg `some-key = some-value` in `~/.npmrc`.
42
33
The `userconfig` config value can be overridden by the `cli`, `env`, or
43
34
`project` configs to change this value.
44
-
- INI-formatted globalconfig file. eg `some-key = some-value` in
45
-
the `globalPrefix` folder, which is inferred by looking at the location
46
-
of the node executable, or the `prefix` setting in the `cli`, `env`,
47
-
`project`, or `userconfig`. The `globalconfig` value at any of those
48
-
levels can override this.
49
-
- INI-formatted builtin config file. eg `some-key = some-value` in
50
-
`/usr/local/lib/node_modules/npm/npmrc`. This is not configurable, and
51
-
is determined by looking in the `npmPath` folder.
35
+
- INI-formatted globalconfig file.
36
+
eg `some-key = some-value` in the `globalPrefix` folder, which is inferred by looking at the location of the node executable, or the `prefix` setting in the `cli`, `env`, `project`, or `userconfig`.
37
+
The `globalconfig` value at any of those levels can override this.
38
+
- INI-formatted builtin config file.
39
+
eg `some-key = some-value` in `/usr/local/lib/node_modules/npm/npmrc`.
40
+
This is not configurable, and is determined by looking in the `npmPath` folder.
52
41
- Default values (passed in by npm when it loads this module).
The type definitions passed to `nopt` for CLI option parsing and known
107
-
configuration validation.
95
+
The type definitions passed to `nopt` for CLI option parsing and known configuration validation.
108
96
109
97
### constructor `new Config(options)`
110
98
111
99
Options:
112
100
113
-
-`types` Types of all known config values. Note that some are effectively
114
-
given semantic value in the config loading process itself.
115
-
-`shorthands` An object mapping a shorthand value to an array of CLI
116
-
arguments that replace it.
101
+
-`types` Types of all known config values.
102
+
Note that some are effectively given semantic value in the config loading process itself.
103
+
-`shorthands` An object mapping a shorthand value to an array of CLI arguments that replace it.
117
104
-`defaults` Default values for each of the known configuration keys.
118
105
These should be defined for all configs given a type, and must be valid.
119
-
-`npmPath` The path to the `npm` module, for loading the `builtin` config
120
-
file.
106
+
-`npmPath` The path to the `npm` module, for loading the `builtin` config file.
121
107
-`cwd` Optional, defaults to `process.cwd()`, used for inferring the
122
108
`localPrefix` and loading the `project` config.
123
-
-`platform` Optional, defaults to `process.platform`. Used when inferring
124
-
the `globalPrefix` from the `execPath`, since this is done differently on
125
-
Windows.
126
-
-`execPath` Optional, defaults to `process.execPath`. Used to infer the
109
+
-`platform` Optional, defaults to `process.platform`.
110
+
Used when inferring the `globalPrefix` from the `execPath`, since this is done differently on Windows.
111
+
-`execPath` Optional, defaults to `process.execPath`.
112
+
Used to infer the
127
113
`globalPrefix`.
128
-
-`env` Optional, defaults to `process.env`. Source of the environment
129
-
variables for configuration.
130
-
-`argv` Optional, defaults to `process.argv`. Source of the CLI options
131
-
used for configuration.
114
+
-`env` Optional, defaults to `process.env`.
115
+
Source of the environment variables for configuration.
116
+
-`argv` Optional, defaults to `process.argv`.
117
+
Source of the CLI options used for configuration.
132
118
133
119
Returns a `config` object, which is not yet loaded.
134
120
135
121
Fields:
136
122
137
-
-`config.globalPrefix` The prefix for `global` operations. Set by the
123
+
-`config.globalPrefix` The prefix for `global` operations.
124
+
Set by the
138
125
`prefix` config value, or defaults based on the location of the
139
126
`execPath` option.
140
-
-`config.localPrefix` The prefix for `local` operations. Set by the
141
-
`prefix` config value on the CLI only, or defaults to either the `cwd` or
142
-
its nearest ancestor containing a `node_modules` folder or `package.json`
143
-
file.
144
-
-`config.sources` A read-only `Map` of the file (or a comment, if no file
145
-
found, or relevant) to the config level loaded from that source.
146
-
-`config.data` A `Map` of config level to `ConfigData` objects. These
147
-
objects should not be modified directly under any circumstances.
127
+
-`config.localPrefix` The prefix for `local` operations.
128
+
Set by the
129
+
`prefix` config value on the CLI only, or defaults to either the `cwd` or its nearest ancestor containing a `node_modules` folder or `package.json` file.
130
+
-`config.sources` A read-only `Map` of the file (or a comment, if no file found, or relevant) to the config level loaded from that source.
131
+
-`config.data` A `Map` of config level to `ConfigData` objects.
132
+
These objects should not be modified directly under any circumstances.
148
133
-`source` The source where this data was loaded from.
149
-
-`raw` The raw data used to generate this config data, as it was parsed
150
-
initially from the environment, config file, or CLI options.
151
-
-`data` The data object reflecting the inheritance of configs up to this
152
-
point in the chain.
153
-
-`loadError` Any errors encountered that prevented the loading of this
154
-
config data.
155
-
-`config.list` A list sorted in priority of all the config data objects in
156
-
the prototype chain. `config.list[0]` is the `cli` level,
134
+
-`raw` The raw data used to generate this config data, as it was parsed initially from the environment, config file, or CLI options.
135
+
-`data` The data object reflecting the inheritance of configs up to this point in the chain.
136
+
-`loadError` Any errors encountered that prevented the loading of this config data.
137
+
-`config.list` A list sorted in priority of all the config data objects in the prototype chain.
138
+
`config.list[0]` is the `cli` level,
157
139
`config.list[1]` is the `env` level, and so on.
158
140
-`cwd` The `cwd` param
159
141
-`env` The `env` param
@@ -166,21 +148,17 @@ Fields:
166
148
-`npmPath` The `npmPath` param
167
149
-`globalPrefix` The effective `globalPrefix`
168
150
-`localPrefix` The effective `localPrefix`
169
-
-`prefix` If `config.get('global')` is true, then `globalPrefix`,
170
-
otherwise `localPrefix`
171
-
-`home` The user's home directory, found by looking at `env.HOME` or
172
-
calling `os.homedir()`.
151
+
-`prefix` If `config.get('global')` is true, then `globalPrefix`, otherwise `localPrefix`
152
+
-`home` The user's home directory, found by looking at `env.HOME` or calling `os.homedir()`.
173
153
-`loaded` A boolean indicating whether or not configs are loaded
174
154
-`valid` A getter that returns `true` if all the config objects are valid.
175
-
Any data objects that have been modified with `config.set(...)` will be
176
-
re-evaluated when `config.valid` is read.
155
+
Any data objects that have been modified with `config.set(...)` will be re-evaluated when `config.valid` is read.
177
156
178
157
### `config.load()`
179
158
180
159
Load configuration from the various sources of information.
181
160
182
-
Returns a `Promise` that resolves when configuration is loaded, and fails
183
-
if a fatal error is encountered.
161
+
Returns a `Promise` that resolves when configuration is loaded, and fails if a fatal error is encountered.
184
162
185
163
### `config.find(key)`
186
164
@@ -196,21 +174,17 @@ Load the given key from the config stack.
196
174
197
175
### `config.set(key, value, where = 'cli')`
198
176
199
-
Set the key to the specified value, at the specified level in the config
200
-
stack.
177
+
Set the key to the specified value, at the specified level in the config stack.
201
178
202
179
### `config.delete(key, where = 'cli')`
203
180
204
181
Delete the configuration key from the specified level in the config stack.
205
182
206
183
### `config.validate(where)`
207
184
208
-
Verify that all known configuration options are set to valid values, and
209
-
log a warning if they are invalid.
185
+
Verify that all known configuration options are set to valid values, and log a warning if they are invalid.
210
186
211
-
Invalid auth options will cause this method to throw an error with a `code`
212
-
property of `ERR_INVALID_AUTH`, and a `problems` property listing the specific
213
-
concerns with the current configuration.
187
+
Invalid auth options will cause this method to throw an error with a `code` property of `ERR_INVALID_AUTH`, and a `problems` property listing the specific concerns with the current configuration.
214
188
215
189
If `where` is not set, then all config objects are validated.
216
190
@@ -222,36 +196,31 @@ Note that it's usually enough (and more efficient) to just check
222
196
223
197
### `config.repair(problems)`
224
198
225
-
Accept an optional array of problems (as thrown by `config.validate()`) and
226
-
perform the necessary steps to resolve them. If no problems are provided,
227
-
this method will call `config.validate()` internally to retrieve them.
199
+
Accept an optional array of problems (as thrown by `config.validate()`) and perform the necessary steps to resolve them.
200
+
If no problems are provided, this method will call `config.validate()` internally to retrieve them.
228
201
229
202
Note that you must `await config.save('user')` in order to persist the changes.
230
203
231
204
### `config.isDefault(key)`
232
205
233
-
Returns `true` if the value is coming directly from the
234
-
default definitions, if the current value for the key config is
235
-
coming from any other source, returns `false`.
206
+
Returns `true` if the value is coming directly from the default definitions, if the current value for the key config is coming from any other source, returns `false`.
236
207
237
208
This method can be used for avoiding or tweaking default values, e.g:
238
209
239
-
> Given a global default definition of foo='foo' it's possible to read that
240
-
> value such as:
210
+
> Given a global default definition of foo='foo' it's possible to read that value such as:
241
211
>
242
212
> ```js
243
213
>constsave=config.get('foo')
244
214
>```
245
215
>
246
-
> Now in a different place of your app it's possible to avoid using the `foo`
247
-
> default value, by checking to see if the current config value is currently
248
-
> one that was defined by the default definitions:
216
+
> Now in a different place of your app it's possible to avoid using the `foo` default value, by checking to see if the current config value is currently one that was defined by the default definitions:
0 commit comments