{"name":"@npmcli/config","version":"10.0.0","author":{"name":"GitHub Inc."},"license":"ISC","_id":"@npmcli/config@10.0.0","maintainers":[{"name":"fritzy","email":"fritzy@github.com"},{"name":"gar","email":"gar+npm@danger.computer"},{"name":"saquibkhan","email":"saquibkhan@github.com"},{"name":"npm-cli-ops","email":"npm-cli+bot@github.com"},{"name":"reggi","email":"reggi@github.com"},{"name":"hashtagchris","email":"hashtagchris@github.com"}],"homepage":"https://github.com/npm/cli#readme","bugs":{"url":"https://github.com/npm/cli/issues"},"tap":{"nyc-arg":["--exclude","tap-snapshots/**"]},"dist":{"shasum":"41aff849fe643f57be6b7f5a62fec17464f79865","tarball":"http://registry-npm.ywwl.com/@npmcli/config/download/@npmcli/config-10.0.0.tgz","fileCount":15,"integrity":"sha512-SXnVmSOQKfxouhrTV2sA2s6KV9v+nfLuddljCl5CtNS89AkVk5Bqkz8wqoqIzR6KjAGjiP1zXDZokqHR5kPYoQ==","signatures":[{"sig":"MEQCIEJCp7VTK0oY2cvQHJQcHaYt82T5dBJW36TiA/b3fgRtAiB04uM21Fsl0GEmRcH1OO2wTm96oDoEjILtYObCF8eMkg==","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}],"unpackedSize":133539,"size":37763,"noattachment":false,"key":"/@npmcli/config/-/@npmcli/config-10.0.0.tgz"},"main":"lib/index.js","engines":{"node":"^20.17.0 || >=22.9.0"},"scripts":{"lint":"npm run eslint","snap":"tap","test":"tap","eslint":"eslint \"**/*.{js,cjs,ts,mjs,jsx,tsx}\"","lintfix":"npm run eslint -- --fix","postlint":"template-oss-check","posttest":"npm run lint","template-oss-apply":"template-oss-apply --force"},"_npmUser":{"name":"gar","email":"gar+npm@danger.computer"},"repository":{"url":"git+https://github.com/npm/cli.git","type":"git","directory":"workspaces/config"},"_npmVersion":"11.0.0","description":"Configuration management for the npm cli","directories":{},"templateOSS":{"content":"../../scripts/template-oss/index.js","version":"4.23.6","//@npmcli/template-oss":"This file is partially managed by @npmcli/template-oss. Edits may be overwritten."},"_nodeVersion":"22.12.0","dependencies":{"ini":"^5.0.0","nopt":"^8.0.0","semver":"^7.3.5","ci-info":"^4.0.0","proc-log":"^5.0.0","walk-up-path":"^4.0.0","@npmcli/package-json":"^6.0.1","@npmcli/map-workspaces":"^4.0.1"},"_hasShrinkwrap":false,"devDependencies":{"tap":"^16.3.8","@npmcli/mock-globals":"^1.0.0","@npmcli/template-oss":"4.23.6","@npmcli/eslint-config":"^5.0.1"},"_npmOperationalInternal":{"tmp":"tmp/config_10.0.0_1734369110792_0.5446946422511896","host":"s3://npm-registry-packages-npm-production"},"readme":"# `@npmcli/config`\n\nConfiguration management for the npm cli.\n\nThis module is the spiritual descendant of [`npmconf`](http://npm.im/npmconf), and the code that once lived in npm's\n`lib/config/` folder.\n\nIt 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.\n\nThe only exceptions:\n\n- 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.\n- 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.)\n- The `userconfig` value, as set by the environment and CLI (defaulting to\n  `~/.npmrc`, is used to load user configs.\n- The `globalconfig` value, as set by the environment, CLI, and\n  `userconfig` file (defaulting to `$PREFIX/etc/npmrc`) is used to load global configs.\n- A `builtin` config, read from a `npmrc` file in the root of the npm project itself, overrides all defaults.\n\nThe resulting hierarchy of configs:\n\n- CLI switches.\n  eg `--some-key=some-value` on the command line.\n  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.\n- Environment variables.\n  eg `npm_config_some_key=some_value` in the environment.\n  There is no way at this time to modify this prefix.\n- INI-formatted project configs.\n  eg `some-key = some-value` in the\n  `localPrefix` folder (ie, the `cwd`, or its nearest parent that contains either a `node_modules` folder or `package.json` file.)\n- INI-formatted userconfig file.\n  eg `some-key = some-value` in `~/.npmrc`.\n  The `userconfig` config value can be overridden by the `cli`, `env`, or\n  `project` configs to change this value.\n- INI-formatted globalconfig file.\n  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`.\n  The `globalconfig` value at any of those levels can override this.\n- INI-formatted builtin config file.\n  eg `some-key = some-value` in `/usr/local/lib/node_modules/npm/npmrc`.\n  This is not configurable, and is determined by looking in the `npmPath` folder.\n- Default values (passed in by npm when it loads this module).\n\n## USAGE\n\n```js\nconst Config = require('@npmcli/config')\nconst { shorthands, definitions, flatten } = require('@npmcli/config/lib/definitions')\n\nconst conf = new Config({\n  // path to the npm module being run\n  npmPath: resolve(__dirname, '..'),\n  definitions,\n  shorthands,\n  flatten,\n  // optional, defaults to process.argv\n  // argv: [] <- if you are using this package in your own cli\n  //             and don't want to have colliding argv\n  argv: process.argv,\n  // optional, defaults to process.env\n  env: process.env,\n  // optional, defaults to process.execPath\n  execPath: process.execPath,\n  // optional, defaults to process.platform\n  platform: process.platform,\n  // optional, defaults to process.cwd()\n  cwd: process.cwd(),\n})\n\n// emits log events on the process object\n// see `proc-log` for more info\nprocess.on('log', (level, ...args) => {\n  console.log(level, ...args)\n})\n\n// returns a promise that fails if config loading fails, and\n// resolves when the config object is ready for action\nconf.load().then(() => {\n  conf.validate()\n  console.log('loaded ok! some-key = ' + conf.get('some-key'))\n}).catch(er => {\n  console.error('error loading configs!', er)\n})\n```\n\n## API\n\nThe `Config` class is the sole export.\n\n```js\nconst Config = require('@npmcli/config')\n```\n\n### static `Config.typeDefs`\n\nThe type definitions passed to `nopt` for CLI option parsing and known configuration validation.\n\n### constructor `new Config(options)`\n\nOptions:\n\n- `types` Types of all known config values.\nNote that some are effectively given semantic value in the config loading process itself.\n- `shorthands` An object mapping a shorthand value to an array of CLI arguments that replace it.\n- `defaults` Default values for each of the known configuration keys.\n  These should be defined for all configs given a type, and must be valid.\n- `npmPath` The path to the `npm` module, for loading the `builtin` config file.\n- `cwd` Optional, defaults to `process.cwd()`, used for inferring the\n  `localPrefix` and loading the `project` config.\n- `platform` Optional, defaults to `process.platform`.\nUsed when inferring the `globalPrefix` from the `execPath`, since this is done differently on Windows.\n- `execPath` Optional, defaults to `process.execPath`.\nUsed to infer the\n  `globalPrefix`.\n- `env` Optional, defaults to `process.env`.\nSource of the environment variables for configuration.\n- `argv` Optional, defaults to `process.argv`.\nSource of the CLI options used for configuration.\n\nReturns a `config` object, which is not yet loaded.\n\nFields:\n\n- `config.globalPrefix` The prefix for `global` operations.\nSet by the\n  `prefix` config value, or defaults based on the location of the\n  `execPath` option.\n- `config.localPrefix` The prefix for `local` operations.\nSet by the\n  `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.\n- `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.\n- `config.data` A `Map` of config level to `ConfigData` objects.\nThese objects should not be modified directly under any circumstances.\n  - `source` The source where this data was loaded from.\n  - `raw` The raw data used to generate this config data, as it was parsed initially from the environment, config file, or CLI options.\n  - `data` The data object reflecting the inheritance of configs up to this point in the chain.\n  - `loadError` Any errors encountered that prevented the loading of this config data.\n- `config.list` A list sorted in priority of all the config data objects in the prototype chain.\n`config.list[0]` is the `cli` level,\n  `config.list[1]` is the `env` level, and so on.\n- `cwd` The `cwd` param\n- `env` The `env` param\n- `argv` The `argv` param\n- `execPath` The `execPath` param\n- `platform` The `platform` param\n- `defaults` The `defaults` param\n- `shorthands` The `shorthands` param\n- `types` The `types` param\n- `npmPath` The `npmPath` param\n- `globalPrefix` The effective `globalPrefix`\n- `localPrefix` The effective `localPrefix`\n- `prefix` If `config.get('global')` is true, then `globalPrefix`, otherwise `localPrefix`\n- `home` The user's home directory, found by looking at `env.HOME` or calling `os.homedir()`.\n- `loaded` A boolean indicating whether or not configs are loaded\n- `valid` A getter that returns `true` if all the config objects are valid.\n  Any data objects that have been modified with `config.set(...)` will be re-evaluated when `config.valid` is read.\n\n### `config.load()`\n\nLoad configuration from the various sources of information.\n\nReturns a `Promise` that resolves when configuration is loaded, and fails if a fatal error is encountered.\n\n### `config.find(key)`\n\nFind the effective place in the configuration levels a given key is set.\nReturns one of: `cli`, `env`, `project`, `user`, `global`, `builtin`, or\n`default`.\n\nReturns `null` if the key is not set.\n\n### `config.get(key, where = 'cli')`\n\nLoad the given key from the config stack.\n\n### `config.set(key, value, where = 'cli')`\n\nSet the key to the specified value, at the specified level in the config stack.\n\n### `config.delete(key, where = 'cli')`\n\nDelete the configuration key from the specified level in the config stack.\n\n### `config.validate(where)`\n\nVerify that all known configuration options are set to valid values, and log a warning if they are invalid.\n\nInvalid 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.\n\nIf `where` is not set, then all config objects are validated.\n\nReturns `true` if all configs are valid.\n\nNote that it's usually enough (and more efficient) to just check\n`config.valid`, since each data object is marked for re-evaluation on every\n`config.set()` operation.\n\n### `config.repair(problems)`\n\nAccept an optional array of problems (as thrown by `config.validate()`) and perform the necessary steps to resolve them.\nIf no problems are provided, this method will call `config.validate()` internally to retrieve them.\n\nNote that you must `await config.save('user')` in order to persist the changes.\n\n### `config.isDefault(key)`\n\nReturns `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`.\n\nThis method can be used for avoiding or tweaking default values, e.g:\n\n>  Given a global default definition of foo='foo' it's possible to read that value such as:\n>\n>  ```js\n>     const save = config.get('foo')\n>  ```\n>\n>  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:\n>\n>  ```js\n>     const save = config.isDefault('foo') ? 'bar' : config.get('foo')\n>  ```\n\n### `config.save(where)`\n\nSave the config file specified by the `where` param.\nMust be one of\n`project`, `user`, `global`, `builtin`.\n","publish_time":1734369111009,"_cnpm_publish_time":1734369111009,"dist-tags":{"backport":"10.14.0","latest":"11.2.0","prerelease":"11.0.0-pre.3"}}