definitions.js 59 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234
  1. const definitions = {}
  2. module.exports = definitions
  3. const Definition = require('./definition.js')
  4. const { version: npmVersion } = require('../../../package.json')
  5. const ciDetect = require('@npmcli/ci-detect')
  6. const ciName = ciDetect()
  7. const querystring = require('querystring')
  8. const isWindows = require('../is-windows.js')
  9. const { join } = require('path')
  10. // used by cafile flattening to flatOptions.ca
  11. const fs = require('fs')
  12. const maybeReadFile = file => {
  13. try {
  14. return fs.readFileSync(file, 'utf8')
  15. } catch (er) {
  16. if (er.code !== 'ENOENT')
  17. throw er
  18. return null
  19. }
  20. }
  21. const buildOmitList = obj => {
  22. const include = obj.include || []
  23. const omit = obj.omit || []
  24. const only = obj.only
  25. if (/^prod(uction)?$/.test(only) || obj.production)
  26. omit.push('dev')
  27. else if (obj.production === false)
  28. include.push('dev')
  29. if (/^dev/.test(obj.also))
  30. include.push('dev')
  31. if (obj.dev)
  32. include.push('dev')
  33. if (obj.optional === false)
  34. omit.push('optional')
  35. else if (obj.optional === true)
  36. include.push('optional')
  37. obj.omit = [...new Set(omit)].filter(type => !include.includes(type))
  38. obj.include = [...new Set(include)]
  39. if (obj.omit.includes('dev'))
  40. process.env.NODE_ENV = 'production'
  41. return obj.omit
  42. }
  43. const editor = process.env.EDITOR ||
  44. process.env.VISUAL ||
  45. (isWindows ? 'notepad.exe' : 'vi')
  46. const shell = isWindows ? process.env.ComSpec || 'cmd'
  47. : process.env.SHELL || 'sh'
  48. const { tmpdir, networkInterfaces } = require('os')
  49. const getLocalAddresses = () => {
  50. try {
  51. return Object.values(networkInterfaces()).map(
  52. int => int.map(({ address }) => address)
  53. ).reduce((set, addrs) => set.concat(addrs), [null])
  54. } catch (e) {
  55. return [null]
  56. }
  57. }
  58. const unicode = /UTF-?8$/i.test(
  59. process.env.LC_ALL ||
  60. process.env.LC_CTYPE ||
  61. process.env.LANG
  62. )
  63. // use LOCALAPPDATA on Windows, if set
  64. // https://github.com/npm/cli/pull/899
  65. const cacheRoot = (isWindows && process.env.LOCALAPPDATA) || '~'
  66. const cacheExtra = isWindows ? 'npm-cache' : '.npm'
  67. const cache = `${cacheRoot}/${cacheExtra}`
  68. const Config = require('@npmcli/config')
  69. // TODO: refactor these type definitions so that they are less
  70. // weird to pull out of the config module.
  71. // TODO: use better type definition/validation API, nopt's is so weird.
  72. const {
  73. typeDefs: {
  74. semver: { type: semver },
  75. Umask: { type: Umask },
  76. url: { type: url },
  77. path: { type: path },
  78. },
  79. } = Config
  80. const define = (key, def) => {
  81. /* istanbul ignore if - this should never happen, prevents mistakes below */
  82. if (definitions[key])
  83. throw new Error(`defining key more than once: ${key}`)
  84. definitions[key] = new Definition(key, def)
  85. }
  86. // basic flattening function, just copy it over camelCase
  87. const flatten = (key, obj, flatOptions) => {
  88. const camel = key.replace(/-([a-z])/g, (_0, _1) => _1.toUpperCase())
  89. flatOptions[camel] = obj[key]
  90. }
  91. // TODO:
  92. // Instead of having each definition provide a flatten method,
  93. // provide the (?list of?) flat option field(s?) that it impacts.
  94. // When that config is set, we mark the relevant flatOption fields
  95. // dirty. Then, a getter for that field defines how we actually
  96. // set it.
  97. //
  98. // So, `save-dev`, `save-optional`, `save-prod`, et al would indicate
  99. // that they affect the `saveType` flat option. Then the config.flat
  100. // object has a `get saveType () { ... }` that looks at the "real"
  101. // config settings from files etc and returns the appropriate value.
  102. //
  103. // Getters will also (maybe?) give us a hook to audit flat option
  104. // usage, so we can document and group these more appropriately.
  105. //
  106. // This will be a problem with cases where we currently do:
  107. // const opts = { ...npm.flatOptions, foo: 'bar' }, but we can maybe
  108. // instead do `npm.config.set('foo', 'bar')` prior to passing the
  109. // config object down where it needs to go.
  110. //
  111. // This way, when we go hunting for "where does saveType come from anyway!?"
  112. // while fixing some Arborist bug, we won't have to hunt through too
  113. // many places.
  114. // Define all config keys we know about
  115. define('_auth', {
  116. default: null,
  117. type: [null, String],
  118. description: `
  119. A basic-auth string to use when authenticating against the npm registry.
  120. Warning: This should generally not be set via a command-line option. It
  121. is safer to use a registry-provided authentication bearer token stored in
  122. the ~/.npmrc file by running \`npm login\`.
  123. `,
  124. flatten,
  125. })
  126. define('access', {
  127. default: null,
  128. defaultDescription: `
  129. 'restricted' for scoped packages, 'public' for unscoped packages
  130. `,
  131. type: [null, 'restricted', 'public'],
  132. description: `
  133. When publishing scoped packages, the access level defaults to
  134. \`restricted\`. If you want your scoped package to be publicly viewable
  135. (and installable) set \`--access=public\`. The only valid values for
  136. \`access\` are \`public\` and \`restricted\`. Unscoped packages _always_
  137. have an access level of \`public\`.
  138. Note: Using the \`--access\` flag on the \`npm publish\` command will only
  139. set the package access level on the initial publish of the package. Any
  140. subsequent \`npm publish\` commands using the \`--access\` flag will not
  141. have an effect to the access level. To make changes to the access level
  142. after the initial publish use \`npm access\`.
  143. `,
  144. flatten,
  145. })
  146. define('all', {
  147. default: false,
  148. type: Boolean,
  149. short: 'a',
  150. description: `
  151. When running \`npm outdated\` and \`npm ls\`, setting \`--all\` will show
  152. all outdated or installed packages, rather than only those directly
  153. depended upon by the current project.
  154. `,
  155. flatten,
  156. })
  157. define('allow-same-version', {
  158. default: false,
  159. type: Boolean,
  160. description: `
  161. Prevents throwing an error when \`npm version\` is used to set the new
  162. version to the same value as the current version.
  163. `,
  164. flatten,
  165. })
  166. define('also', {
  167. default: null,
  168. type: [null, 'dev', 'development'],
  169. description: `
  170. When set to \`dev\` or \`development\`, this is an alias for
  171. \`--include=dev\`.
  172. `,
  173. deprecated: 'Please use --include=dev instead.',
  174. flatten (key, obj, flatOptions) {
  175. definitions.omit.flatten('omit', obj, flatOptions)
  176. },
  177. })
  178. define('audit', {
  179. default: true,
  180. type: Boolean,
  181. description: `
  182. When "true" submit audit reports alongside the current npm command to the
  183. default registry and all registries configured for scopes. See the
  184. documentation for [\`npm audit\`](/commands/npm-audit) for details on what
  185. is submitted.
  186. `,
  187. flatten,
  188. })
  189. define('audit-level', {
  190. default: null,
  191. type: [null, 'info', 'low', 'moderate', 'high', 'critical', 'none'],
  192. description: `
  193. The minimum level of vulnerability for \`npm audit\` to exit with
  194. a non-zero exit code.
  195. `,
  196. flatten,
  197. })
  198. define('auth-type', {
  199. default: 'legacy',
  200. type: ['legacy', 'sso', 'saml', 'oauth'],
  201. deprecated: `
  202. This method of SSO/SAML/OAuth is deprecated and will be removed in
  203. a future version of npm in favor of web-based login.
  204. `,
  205. description: `
  206. What authentication strategy to use with \`adduser\`/\`login\`.
  207. `,
  208. flatten,
  209. })
  210. define('before', {
  211. default: null,
  212. type: [null, Date],
  213. description: `
  214. If passed to \`npm install\`, will rebuild the npm tree such that only
  215. versions that were available **on or before** the \`--before\` time get
  216. installed. If there's no versions available for the current set of
  217. direct dependencies, the command will error.
  218. If the requested version is a \`dist-tag\` and the given tag does not
  219. pass the \`--before\` filter, the most recent version less than or equal
  220. to that tag will be used. For example, \`foo@latest\` might install
  221. \`foo@1.2\` even though \`latest\` is \`2.0\`.
  222. `,
  223. flatten,
  224. })
  225. define('bin-links', {
  226. default: true,
  227. type: Boolean,
  228. description: `
  229. Tells npm to create symlinks (or \`.cmd\` shims on Windows) for package
  230. executables.
  231. Set to false to have it not do this. This can be used to work around the
  232. fact that some file systems don't support symlinks, even on ostensibly
  233. Unix systems.
  234. `,
  235. flatten,
  236. })
  237. define('browser', {
  238. default: null,
  239. defaultDescription: `
  240. OS X: \`"open"\`, Windows: \`"start"\`, Others: \`"xdg-open"\`
  241. `,
  242. type: [null, Boolean, String],
  243. description: `
  244. The browser that is called by npm commands to open websites.
  245. Set to \`false\` to suppress browser behavior and instead print urls to
  246. terminal.
  247. Set to \`true\` to use default system URL opener.
  248. `,
  249. flatten,
  250. })
  251. define('ca', {
  252. default: null,
  253. type: [null, String, Array],
  254. description: `
  255. The Certificate Authority signing certificate that is trusted for SSL
  256. connections to the registry. Values should be in PEM format (Windows
  257. calls it "Base-64 encoded X.509 (.CER)") with newlines replaced by the
  258. string "\\n". For example:
  259. \`\`\`ini
  260. ca="-----BEGIN CERTIFICATE-----\\nXXXX\\nXXXX\\n-----END CERTIFICATE-----"
  261. \`\`\`
  262. Set to \`null\` to only allow "known" registrars, or to a specific CA
  263. cert to trust only that specific signing authority.
  264. Multiple CAs can be trusted by specifying an array of certificates:
  265. \`\`\`ini
  266. ca[]="..."
  267. ca[]="..."
  268. \`\`\`
  269. See also the \`strict-ssl\` config.
  270. `,
  271. flatten,
  272. })
  273. define('cache', {
  274. default: cache,
  275. defaultDescription: `
  276. Windows: \`%LocalAppData%\\npm-cache\`, Posix: \`~/.npm\`
  277. `,
  278. type: path,
  279. description: `
  280. The location of npm's cache directory. See [\`npm
  281. cache\`](/commands/npm-cache)
  282. `,
  283. flatten (key, obj, flatOptions) {
  284. flatOptions.cache = join(obj.cache, '_cacache')
  285. flatOptions.npxCache = join(obj.cache, '_npx')
  286. },
  287. })
  288. define('cache-max', {
  289. default: Infinity,
  290. type: Number,
  291. description: `
  292. \`--cache-max=0\` is an alias for \`--prefer-online\`
  293. `,
  294. deprecated: `
  295. This option has been deprecated in favor of \`--prefer-online\`
  296. `,
  297. flatten (key, obj, flatOptions) {
  298. if (obj[key] <= 0)
  299. flatOptions.preferOnline = true
  300. },
  301. })
  302. define('cache-min', {
  303. default: 0,
  304. type: Number,
  305. description: `
  306. \`--cache-min=9999 (or bigger)\` is an alias for \`--prefer-offline\`.
  307. `,
  308. deprecated: `
  309. This option has been deprecated in favor of \`--prefer-offline\`.
  310. `,
  311. flatten (key, obj, flatOptions) {
  312. if (obj[key] >= 9999)
  313. flatOptions.preferOffline = true
  314. },
  315. })
  316. define('cafile', {
  317. default: null,
  318. type: path,
  319. description: `
  320. A path to a file containing one or multiple Certificate Authority signing
  321. certificates. Similar to the \`ca\` setting, but allows for multiple
  322. CA's, as well as for the CA information to be stored in a file on disk.
  323. `,
  324. flatten (key, obj, flatOptions) {
  325. // always set to null in defaults
  326. if (!obj.cafile)
  327. return
  328. const raw = maybeReadFile(obj.cafile)
  329. if (!raw)
  330. return
  331. const delim = '-----END CERTIFICATE-----'
  332. flatOptions.ca = raw.replace(/\r\n/g, '\n').split(delim)
  333. .filter(section => section.trim())
  334. .map(section => section.trimLeft() + delim)
  335. },
  336. })
  337. define('call', {
  338. default: '',
  339. type: String,
  340. short: 'c',
  341. description: `
  342. Optional companion option for \`npm exec\`, \`npx\` that allows for
  343. specifying a custom command to be run along with the installed packages.
  344. \`\`\`bash
  345. npm exec --package yo --package generator-node --call "yo node"
  346. \`\`\`
  347. `,
  348. flatten,
  349. })
  350. define('cert', {
  351. default: null,
  352. type: [null, String],
  353. description: `
  354. A client certificate to pass when accessing the registry. Values should
  355. be in PEM format (Windows calls it "Base-64 encoded X.509 (.CER)") with
  356. newlines replaced by the string "\\n". For example:
  357. \`\`\`ini
  358. cert="-----BEGIN CERTIFICATE-----\\nXXXX\\nXXXX\\n-----END CERTIFICATE-----"
  359. \`\`\`
  360. It is _not_ the path to a certificate file (and there is no "certfile"
  361. option).
  362. `,
  363. flatten,
  364. })
  365. define('ci-name', {
  366. default: ciName || null,
  367. defaultDescription: `
  368. The name of the current CI system, or \`null\` when not on a known CI
  369. platform.
  370. `,
  371. type: [null, String],
  372. description: `
  373. The name of a continuous integration system. If not set explicitly, npm
  374. will detect the current CI environment using the
  375. [\`@npmcli/ci-detect\`](http://npm.im/@npmcli/ci-detect) module.
  376. `,
  377. flatten,
  378. })
  379. define('cidr', {
  380. default: null,
  381. type: [null, String, Array],
  382. description: `
  383. This is a list of CIDR address to be used when configuring limited access
  384. tokens with the \`npm token create\` command.
  385. `,
  386. flatten,
  387. })
  388. // This should never be directly used, the flattened value is the derived value
  389. // and is sent to other modules, and is also exposed as `npm.color` for use
  390. // inside npm itself.
  391. define('color', {
  392. default: !process.env.NO_COLOR || process.env.NO_COLOR === '0',
  393. usage: '--color|--no-color|--color always',
  394. defaultDescription: `
  395. true unless the NO_COLOR environ is set to something other than '0'
  396. `,
  397. type: ['always', Boolean],
  398. description: `
  399. If false, never shows colors. If \`"always"\` then always shows colors.
  400. If true, then only prints color codes for tty file descriptors.
  401. `,
  402. flatten (key, obj, flatOptions) {
  403. flatOptions.color = !obj.color ? false
  404. : obj.color === 'always' ? true
  405. : process.stdout.isTTY
  406. },
  407. })
  408. define('commit-hooks', {
  409. default: true,
  410. type: Boolean,
  411. description: `
  412. Run git commit hooks when using the \`npm version\` command.
  413. `,
  414. flatten,
  415. })
  416. define('depth', {
  417. default: null,
  418. defaultDescription: `
  419. \`Infinity\` if \`--all\` is set, otherwise \`1\`
  420. `,
  421. type: [null, Number],
  422. description: `
  423. The depth to go when recursing packages for \`npm ls\`.
  424. If not set, \`npm ls\` will show only the immediate dependencies of the
  425. root project. If \`--all\` is set, then npm will show all dependencies
  426. by default.
  427. `,
  428. flatten,
  429. })
  430. define('description', {
  431. default: true,
  432. type: Boolean,
  433. usage: '--no-description',
  434. description: `
  435. Show the description in \`npm search\`
  436. `,
  437. flatten (key, obj, flatOptions) {
  438. flatOptions.search = flatOptions.search || { limit: 20 }
  439. flatOptions.search[key] = obj[key]
  440. },
  441. })
  442. define('dev', {
  443. default: false,
  444. type: Boolean,
  445. description: `
  446. Alias for \`--include=dev\`.
  447. `,
  448. deprecated: 'Please use --include=dev instead.',
  449. flatten (key, obj, flatOptions) {
  450. definitions.omit.flatten('omit', obj, flatOptions)
  451. },
  452. })
  453. define('diff', {
  454. default: [],
  455. hint: '<pkg-name|spec|version>',
  456. type: [String, Array],
  457. description: `
  458. Define arguments to compare in \`npm diff\`.
  459. `,
  460. flatten,
  461. })
  462. define('diff-ignore-all-space', {
  463. default: false,
  464. type: Boolean,
  465. description: `
  466. Ignore whitespace when comparing lines in \`npm diff\`.
  467. `,
  468. flatten,
  469. })
  470. define('diff-name-only', {
  471. default: false,
  472. type: Boolean,
  473. description: `
  474. Prints only filenames when using \`npm diff\`.
  475. `,
  476. flatten,
  477. })
  478. define('diff-no-prefix', {
  479. default: false,
  480. type: Boolean,
  481. description: `
  482. Do not show any source or destination prefix in \`npm diff\` output.
  483. Note: this causes \`npm diff\` to ignore the \`--diff-src-prefix\` and
  484. \`--diff-dst-prefix\` configs.
  485. `,
  486. flatten,
  487. })
  488. define('diff-dst-prefix', {
  489. default: 'b/',
  490. hint: '<path>',
  491. type: String,
  492. description: `
  493. Destination prefix to be used in \`npm diff\` output.
  494. `,
  495. flatten,
  496. })
  497. define('diff-src-prefix', {
  498. default: 'a/',
  499. hint: '<path>',
  500. type: String,
  501. description: `
  502. Source prefix to be used in \`npm diff\` output.
  503. `,
  504. flatten,
  505. })
  506. define('diff-text', {
  507. default: false,
  508. type: Boolean,
  509. description: `
  510. Treat all files as text in \`npm diff\`.
  511. `,
  512. flatten,
  513. })
  514. define('diff-unified', {
  515. default: 3,
  516. type: Number,
  517. description: `
  518. The number of lines of context to print in \`npm diff\`.
  519. `,
  520. flatten,
  521. })
  522. define('dry-run', {
  523. default: false,
  524. type: Boolean,
  525. description: `
  526. Indicates that you don't want npm to make any changes and that it should
  527. only report what it would have done. This can be passed into any of the
  528. commands that modify your local installation, eg, \`install\`,
  529. \`update\`, \`dedupe\`, \`uninstall\`, as well as \`pack\` and
  530. \`publish\`.
  531. Note: This is NOT honored by other network related commands, eg
  532. \`dist-tags\`, \`owner\`, etc.
  533. `,
  534. flatten,
  535. })
  536. define('editor', {
  537. default: editor,
  538. defaultDescription: `
  539. The EDITOR or VISUAL environment variables, or 'notepad.exe' on Windows,
  540. or 'vim' on Unix systems
  541. `,
  542. type: String,
  543. description: `
  544. The command to run for \`npm edit\` and \`npm config edit\`.
  545. `,
  546. flatten,
  547. })
  548. define('engine-strict', {
  549. default: false,
  550. type: Boolean,
  551. description: `
  552. If set to true, then npm will stubbornly refuse to install (or even
  553. consider installing) any package that claims to not be compatible with
  554. the current Node.js version.
  555. This can be overridden by setting the \`--force\` flag.
  556. `,
  557. flatten,
  558. })
  559. define('fetch-retries', {
  560. default: 2,
  561. type: Number,
  562. description: `
  563. The "retries" config for the \`retry\` module to use when fetching
  564. packages from the registry.
  565. npm will retry idempotent read requests to the registry in the case
  566. of network failures or 5xx HTTP errors.
  567. `,
  568. flatten (key, obj, flatOptions) {
  569. flatOptions.retry = flatOptions.retry || {}
  570. flatOptions.retry.retries = obj[key]
  571. },
  572. })
  573. define('fetch-retry-factor', {
  574. default: 10,
  575. type: Number,
  576. description: `
  577. The "factor" config for the \`retry\` module to use when fetching
  578. packages.
  579. `,
  580. flatten (key, obj, flatOptions) {
  581. flatOptions.retry = flatOptions.retry || {}
  582. flatOptions.retry.factor = obj[key]
  583. },
  584. })
  585. define('fetch-retry-maxtimeout', {
  586. default: 60000,
  587. defaultDescription: '60000 (1 minute)',
  588. type: Number,
  589. description: `
  590. The "maxTimeout" config for the \`retry\` module to use when fetching
  591. packages.
  592. `,
  593. flatten (key, obj, flatOptions) {
  594. flatOptions.retry = flatOptions.retry || {}
  595. flatOptions.retry.maxTimeout = obj[key]
  596. },
  597. })
  598. define('fetch-retry-mintimeout', {
  599. default: 10000,
  600. defaultDescription: '10000 (10 seconds)',
  601. type: Number,
  602. description: `
  603. The "minTimeout" config for the \`retry\` module to use when fetching
  604. packages.
  605. `,
  606. flatten (key, obj, flatOptions) {
  607. flatOptions.retry = flatOptions.retry || {}
  608. flatOptions.retry.minTimeout = obj[key]
  609. },
  610. })
  611. define('fetch-timeout', {
  612. default: 5 * 60 * 1000,
  613. defaultDescription: `${5 * 60 * 1000} (5 minutes)`,
  614. type: Number,
  615. description: `
  616. The maximum amount of time to wait for HTTP requests to complete.
  617. `,
  618. flatten (key, obj, flatOptions) {
  619. flatOptions.timeout = obj[key]
  620. },
  621. })
  622. define('force', {
  623. default: false,
  624. type: Boolean,
  625. short: 'f',
  626. description: `
  627. Removes various protections against unfortunate side effects, common
  628. mistakes, unnecessary performance degradation, and malicious input.
  629. * Allow clobbering non-npm files in global installs.
  630. * Allow the \`npm version\` command to work on an unclean git repository.
  631. * Allow deleting the cache folder with \`npm cache clean\`.
  632. * Allow installing packages that have an \`engines\` declaration
  633. requiring a different version of npm.
  634. * Allow installing packages that have an \`engines\` declaration
  635. requiring a different version of \`node\`, even if \`--engine-strict\`
  636. is enabled.
  637. * Allow \`npm audit fix\` to install modules outside your stated
  638. dependency range (including SemVer-major changes).
  639. * Allow unpublishing all versions of a published package.
  640. * Allow conflicting peerDependencies to be installed in the root project.
  641. * Implicitly set \`--yes\` during \`npm init\`.
  642. * Allow clobbering existing values in \`npm pkg\`
  643. If you don't have a clear idea of what you want to do, it is strongly
  644. recommended that you do not use this option!
  645. `,
  646. flatten,
  647. })
  648. define('foreground-scripts', {
  649. default: false,
  650. type: Boolean,
  651. description: `
  652. Run all build scripts (ie, \`preinstall\`, \`install\`, and
  653. \`postinstall\`) scripts for installed packages in the foreground
  654. process, sharing standard input, output, and error with the main npm
  655. process.
  656. Note that this will generally make installs run slower, and be much
  657. noisier, but can be useful for debugging.
  658. `,
  659. flatten,
  660. })
  661. define('format-package-lock', {
  662. default: true,
  663. type: Boolean,
  664. description: `
  665. Format \`package-lock.json\` or \`npm-shrinkwrap.json\` as a human
  666. readable file.
  667. `,
  668. flatten,
  669. })
  670. define('fund', {
  671. default: true,
  672. type: Boolean,
  673. description: `
  674. When "true" displays the message at the end of each \`npm install\`
  675. acknowledging the number of dependencies looking for funding.
  676. See [\`npm fund\`](/commands/npm-fund) for details.
  677. `,
  678. flatten,
  679. })
  680. define('git', {
  681. default: 'git',
  682. type: String,
  683. description: `
  684. The command to use for git commands. If git is installed on the
  685. computer, but is not in the \`PATH\`, then set this to the full path to
  686. the git binary.
  687. `,
  688. flatten,
  689. })
  690. define('git-tag-version', {
  691. default: true,
  692. type: Boolean,
  693. description: `
  694. Tag the commit when using the \`npm version\` command.
  695. `,
  696. flatten,
  697. })
  698. define('global', {
  699. default: false,
  700. type: Boolean,
  701. short: 'g',
  702. description: `
  703. Operates in "global" mode, so that packages are installed into the
  704. \`prefix\` folder instead of the current working directory. See
  705. [folders](/configuring-npm/folders) for more on the differences in
  706. behavior.
  707. * packages are installed into the \`{prefix}/lib/node_modules\` folder,
  708. instead of the current working directory.
  709. * bin files are linked to \`{prefix}/bin\`
  710. * man pages are linked to \`{prefix}/share/man\`
  711. `,
  712. flatten: (key, obj, flatOptions) => {
  713. flatten(key, obj, flatOptions)
  714. if (flatOptions.global)
  715. flatOptions.location = 'global'
  716. },
  717. })
  718. define('global-style', {
  719. default: false,
  720. type: Boolean,
  721. description: `
  722. Causes npm to install the package into your local \`node_modules\` folder
  723. with the same layout it uses with the global \`node_modules\` folder.
  724. Only your direct dependencies will show in \`node_modules\` and
  725. everything they depend on will be flattened in their \`node_modules\`
  726. folders. This obviously will eliminate some deduping. If used with
  727. \`legacy-bundling\`, \`legacy-bundling\` will be preferred.
  728. `,
  729. flatten,
  730. })
  731. // the globalconfig has its default defined outside of this module
  732. define('globalconfig', {
  733. type: path,
  734. default: '',
  735. defaultDescription: `
  736. The global --prefix setting plus 'etc/npmrc'. For example,
  737. '/usr/local/etc/npmrc'
  738. `,
  739. description: `
  740. The config file to read for global config options.
  741. `,
  742. flatten,
  743. })
  744. define('heading', {
  745. default: 'npm',
  746. type: String,
  747. description: `
  748. The string that starts all the debugging log output.
  749. `,
  750. flatten,
  751. })
  752. define('https-proxy', {
  753. default: null,
  754. type: [null, url],
  755. description: `
  756. A proxy to use for outgoing https requests. If the \`HTTPS_PROXY\` or
  757. \`https_proxy\` or \`HTTP_PROXY\` or \`http_proxy\` environment variables
  758. are set, proxy settings will be honored by the underlying
  759. \`make-fetch-happen\` library.
  760. `,
  761. flatten,
  762. })
  763. define('if-present', {
  764. default: false,
  765. type: Boolean,
  766. description: `
  767. If true, npm will not exit with an error code when \`run-script\` is
  768. invoked for a script that isn't defined in the \`scripts\` section of
  769. \`package.json\`. This option can be used when it's desirable to
  770. optionally run a script when it's present and fail if the script fails.
  771. This is useful, for example, when running scripts that may only apply for
  772. some builds in an otherwise generic CI setup.
  773. `,
  774. flatten,
  775. })
  776. define('ignore-scripts', {
  777. default: false,
  778. type: Boolean,
  779. description: `
  780. If true, npm does not run scripts specified in package.json files.
  781. Note that commands explicitly intended to run a particular script, such
  782. as \`npm start\`, \`npm stop\`, \`npm restart\`, \`npm test\`, and \`npm
  783. run-script\` will still run their intended script if \`ignore-scripts\` is
  784. set, but they will *not* run any pre- or post-scripts.
  785. `,
  786. flatten,
  787. })
  788. define('include', {
  789. default: [],
  790. type: [Array, 'prod', 'dev', 'optional', 'peer'],
  791. description: `
  792. Option that allows for defining which types of dependencies to install.
  793. This is the inverse of \`--omit=<type>\`.
  794. Dependency types specified in \`--include\` will not be omitted,
  795. regardless of the order in which omit/include are specified on the
  796. command-line.
  797. `,
  798. flatten (key, obj, flatOptions) {
  799. // just call the omit flattener, it reads from obj.include
  800. definitions.omit.flatten('omit', obj, flatOptions)
  801. },
  802. })
  803. define('include-staged', {
  804. default: false,
  805. type: Boolean,
  806. description: `
  807. Allow installing "staged" published packages, as defined by [npm RFC PR
  808. #92](https://github.com/npm/rfcs/pull/92).
  809. This is experimental, and not implemented by the npm public registry.
  810. `,
  811. flatten,
  812. })
  813. define('include-workspace-root', {
  814. default: false,
  815. type: Boolean,
  816. description: `
  817. Include the workspace root when workspaces are enabled for a command.
  818. When false, specifying individual workspaces via the \`workspace\` config,
  819. or all workspaces via the \`workspaces\` flag, will cause npm to operate only
  820. on the specified workspaces, and not on the root project.
  821. `,
  822. flatten,
  823. })
  824. define('init-author-email', {
  825. default: '',
  826. type: String,
  827. description: `
  828. The value \`npm init\` should use by default for the package author's
  829. email.
  830. `,
  831. })
  832. define('init-author-name', {
  833. default: '',
  834. type: String,
  835. description: `
  836. The value \`npm init\` should use by default for the package author's name.
  837. `,
  838. })
  839. define('init-author-url', {
  840. default: '',
  841. type: ['', url],
  842. description: `
  843. The value \`npm init\` should use by default for the package author's homepage.
  844. `,
  845. })
  846. define('init-license', {
  847. default: 'ISC',
  848. type: String,
  849. description: `
  850. The value \`npm init\` should use by default for the package license.
  851. `,
  852. })
  853. define('init-module', {
  854. default: '~/.npm-init.js',
  855. type: path,
  856. description: `
  857. A module that will be loaded by the \`npm init\` command. See the
  858. documentation for the
  859. [init-package-json](https://github.com/npm/init-package-json) module for
  860. more information, or [npm init](/commands/npm-init).
  861. `,
  862. })
  863. define('init-version', {
  864. default: '1.0.0',
  865. type: semver,
  866. description: `
  867. The value that \`npm init\` should use by default for the package
  868. version number, if not already set in package.json.
  869. `,
  870. })
  871. // these "aliases" are historically supported in .npmrc files, unfortunately
  872. // They should be removed in a future npm version.
  873. define('init.author.email', {
  874. default: '',
  875. type: String,
  876. deprecated: `
  877. Use \`--init-author-email\` instead.`,
  878. description: `
  879. Alias for \`--init-author-email\`
  880. `,
  881. })
  882. define('init.author.name', {
  883. default: '',
  884. type: String,
  885. deprecated: `
  886. Use \`--init-author-name\` instead.
  887. `,
  888. description: `
  889. Alias for \`--init-author-name\`
  890. `,
  891. })
  892. define('init.author.url', {
  893. default: '',
  894. type: ['', url],
  895. deprecated: `
  896. Use \`--init-author-url\` instead.
  897. `,
  898. description: `
  899. Alias for \`--init-author-url\`
  900. `,
  901. })
  902. define('init.license', {
  903. default: 'ISC',
  904. type: String,
  905. deprecated: `
  906. Use \`--init-license\` instead.
  907. `,
  908. description: `
  909. Alias for \`--init-license\`
  910. `,
  911. })
  912. define('init.module', {
  913. default: '~/.npm-init.js',
  914. type: path,
  915. deprecated: `
  916. Use \`--init-module\` instead.
  917. `,
  918. description: `
  919. Alias for \`--init-module\`
  920. `,
  921. })
  922. define('init.version', {
  923. default: '1.0.0',
  924. type: semver,
  925. deprecated: `
  926. Use \`--init-version\` instead.
  927. `,
  928. description: `
  929. Alias for \`--init-version\`
  930. `,
  931. })
  932. define('json', {
  933. default: false,
  934. type: Boolean,
  935. description: `
  936. Whether or not to output JSON data, rather than the normal output.
  937. * In \`npm pkg set\` it enables parsing set values with JSON.parse()
  938. before saving them to your \`package.json\`.
  939. Not supported by all npm commands.
  940. `,
  941. flatten,
  942. })
  943. define('key', {
  944. default: null,
  945. type: [null, String],
  946. description: `
  947. A client key to pass when accessing the registry. Values should be in
  948. PEM format with newlines replaced by the string "\\n". For example:
  949. \`\`\`ini
  950. key="-----BEGIN PRIVATE KEY-----\\nXXXX\\nXXXX\\n-----END PRIVATE KEY-----"
  951. \`\`\`
  952. It is _not_ the path to a key file (and there is no "keyfile" option).
  953. `,
  954. flatten,
  955. })
  956. define('legacy-bundling', {
  957. default: false,
  958. type: Boolean,
  959. description: `
  960. Causes npm to install the package such that versions of npm prior to 1.4,
  961. such as the one included with node 0.8, can install the package. This
  962. eliminates all automatic deduping. If used with \`global-style\` this
  963. option will be preferred.
  964. `,
  965. flatten,
  966. })
  967. define('legacy-peer-deps', {
  968. default: false,
  969. type: Boolean,
  970. description: `
  971. Causes npm to completely ignore \`peerDependencies\` when building a
  972. package tree, as in npm versions 3 through 6.
  973. If a package cannot be installed because of overly strict
  974. \`peerDependencies\` that collide, it provides a way to move forward
  975. resolving the situation.
  976. This differs from \`--omit=peer\`, in that \`--omit=peer\` will avoid
  977. unpacking \`peerDependencies\` on disk, but will still design a tree such
  978. that \`peerDependencies\` _could_ be unpacked in a correct place.
  979. Use of \`legacy-peer-deps\` is not recommended, as it will not enforce
  980. the \`peerDependencies\` contract that meta-dependencies may rely on.
  981. `,
  982. flatten,
  983. })
  984. define('link', {
  985. default: false,
  986. type: Boolean,
  987. description: `
  988. Used with \`npm ls\`, limiting output to only those packages that are
  989. linked.
  990. `,
  991. })
  992. define('local-address', {
  993. default: null,
  994. type: getLocalAddresses(),
  995. typeDescription: 'IP Address',
  996. description: `
  997. The IP address of the local interface to use when making connections to
  998. the npm registry. Must be IPv4 in versions of Node prior to 0.12.
  999. `,
  1000. flatten,
  1001. })
  1002. define('location', {
  1003. default: 'user',
  1004. short: 'L',
  1005. type: [
  1006. 'global',
  1007. 'user',
  1008. 'project',
  1009. ],
  1010. defaultDescription: `
  1011. "user" unless \`--global\` is passed, which will also set this value to "global"
  1012. `,
  1013. description: `
  1014. When passed to \`npm config\` this refers to which config file to use.
  1015. `,
  1016. flatten: (key, obj, flatOptions) => {
  1017. flatten(key, obj, flatOptions)
  1018. if (flatOptions.global)
  1019. flatOptions.location = 'global'
  1020. },
  1021. })
  1022. define('lockfile-version', {
  1023. default: null,
  1024. type: [null, 1, 2, 3, '1', '2', '3'],
  1025. defaultDescription: `
  1026. Version 2 if no lockfile or current lockfile version less than or equal to
  1027. 2, otherwise maintain current lockfile version
  1028. `,
  1029. description: `
  1030. Set the lockfile format version to be used in package-lock.json and
  1031. npm-shrinkwrap-json files. Possible options are:
  1032. 1: The lockfile version used by npm versions 5 and 6. Lacks some data that
  1033. is used during the install, resulting in slower and possibly less
  1034. deterministic installs. Prevents lockfile churn when interoperating with
  1035. older npm versions.
  1036. 2: The default lockfile version used by npm version 7. Includes both the
  1037. version 1 lockfile data and version 3 lockfile data, for maximum
  1038. determinism and interoperability, at the expense of more bytes on disk.
  1039. 3: Only the new lockfile information introduced in npm version 7. Smaller
  1040. on disk than lockfile version 2, but not interoperable with older npm
  1041. versions. Ideal if all users are on npm version 7 and higher.
  1042. `,
  1043. flatten: (key, obj, flatOptions) => {
  1044. flatOptions.lockfileVersion = obj[key] && parseInt(obj[key], 10)
  1045. },
  1046. })
  1047. define('loglevel', {
  1048. default: 'notice',
  1049. type: [
  1050. 'silent',
  1051. 'error',
  1052. 'warn',
  1053. 'notice',
  1054. 'http',
  1055. 'timing',
  1056. 'info',
  1057. 'verbose',
  1058. 'silly',
  1059. ],
  1060. description: `
  1061. What level of logs to report. On failure, *all* logs are written to
  1062. \`npm-debug.log\` in the current working directory.
  1063. Any logs of a higher level than the setting are shown. The default is
  1064. "notice".
  1065. See also the \`foreground-scripts\` config.
  1066. `,
  1067. })
  1068. define('logs-max', {
  1069. default: 10,
  1070. type: Number,
  1071. description: `
  1072. The maximum number of log files to store.
  1073. `,
  1074. })
  1075. define('long', {
  1076. default: false,
  1077. type: Boolean,
  1078. short: 'l',
  1079. description: `
  1080. Show extended information in \`ls\`, \`search\`, and \`help-search\`.
  1081. `,
  1082. })
  1083. define('maxsockets', {
  1084. default: 15,
  1085. type: Number,
  1086. description: `
  1087. The maximum number of connections to use per origin (protocol/host/port
  1088. combination).
  1089. `,
  1090. flatten (key, obj, flatOptions) {
  1091. flatOptions.maxSockets = obj[key]
  1092. },
  1093. })
  1094. define('message', {
  1095. default: '%s',
  1096. type: String,
  1097. short: 'm',
  1098. description: `
  1099. Commit message which is used by \`npm version\` when creating version commit.
  1100. Any "%s" in the message will be replaced with the version number.
  1101. `,
  1102. flatten,
  1103. })
  1104. define('node-options', {
  1105. default: null,
  1106. type: [null, String],
  1107. description: `
  1108. Options to pass through to Node.js via the \`NODE_OPTIONS\` environment
  1109. variable. This does not impact how npm itself is executed but it does
  1110. impact how lifecycle scripts are called.
  1111. `,
  1112. })
  1113. define('node-version', {
  1114. default: process.version,
  1115. defaultDescription: 'Node.js `process.version` value',
  1116. type: semver,
  1117. description: `
  1118. The node version to use when checking a package's \`engines\` setting.
  1119. `,
  1120. flatten,
  1121. })
  1122. define('noproxy', {
  1123. default: '',
  1124. defaultDescription: `
  1125. The value of the NO_PROXY environment variable
  1126. `,
  1127. type: [String, Array],
  1128. description: `
  1129. Domain extensions that should bypass any proxies.
  1130. Also accepts a comma-delimited string.
  1131. `,
  1132. flatten (key, obj, flatOptions) {
  1133. if (Array.isArray(obj[key]))
  1134. flatOptions.noProxy = obj[key].join(',')
  1135. else
  1136. flatOptions.noProxy = obj[key]
  1137. },
  1138. })
  1139. define('npm-version', {
  1140. default: npmVersion,
  1141. defaultDescription: 'Output of `npm --version`',
  1142. type: semver,
  1143. description: `
  1144. The npm version to use when checking a package's \`engines\` setting.
  1145. `,
  1146. flatten,
  1147. })
  1148. define('offline', {
  1149. default: false,
  1150. type: Boolean,
  1151. description: `
  1152. Force offline mode: no network requests will be done during install. To allow
  1153. the CLI to fill in missing cache data, see \`--prefer-offline\`.
  1154. `,
  1155. flatten,
  1156. })
  1157. define('omit', {
  1158. default: process.env.NODE_ENV === 'production' ? ['dev'] : [],
  1159. defaultDescription: `
  1160. 'dev' if the \`NODE_ENV\` environment variable is set to 'production',
  1161. otherwise empty.
  1162. `,
  1163. type: [Array, 'dev', 'optional', 'peer'],
  1164. description: `
  1165. Dependency types to omit from the installation tree on disk.
  1166. Note that these dependencies _are_ still resolved and added to the
  1167. \`package-lock.json\` or \`npm-shrinkwrap.json\` file. They are just
  1168. not physically installed on disk.
  1169. If a package type appears in both the \`--include\` and \`--omit\`
  1170. lists, then it will be included.
  1171. If the resulting omit list includes \`'dev'\`, then the \`NODE_ENV\`
  1172. environment variable will be set to \`'production'\` for all lifecycle
  1173. scripts.
  1174. `,
  1175. flatten (key, obj, flatOptions) {
  1176. flatOptions.omit = buildOmitList(obj)
  1177. },
  1178. })
  1179. define('only', {
  1180. default: null,
  1181. type: [null, 'prod', 'production'],
  1182. deprecated: `
  1183. Use \`--omit=dev\` to omit dev dependencies from the install.
  1184. `,
  1185. description: `
  1186. When set to \`prod\` or \`production\`, this is an alias for
  1187. \`--omit=dev\`.
  1188. `,
  1189. flatten (key, obj, flatOptions) {
  1190. definitions.omit.flatten('omit', obj, flatOptions)
  1191. },
  1192. })
  1193. define('optional', {
  1194. default: null,
  1195. type: [null, Boolean],
  1196. deprecated: `
  1197. Use \`--omit=optional\` to exclude optional dependencies, or
  1198. \`--include=optional\` to include them.
  1199. Default value does install optional deps unless otherwise omitted.
  1200. `,
  1201. description: `
  1202. Alias for --include=optional or --omit=optional
  1203. `,
  1204. flatten (key, obj, flatOptions) {
  1205. definitions.omit.flatten('omit', obj, flatOptions)
  1206. },
  1207. })
  1208. define('otp', {
  1209. default: null,
  1210. type: [null, String],
  1211. description: `
  1212. This is a one-time password from a two-factor authenticator. It's needed
  1213. when publishing or changing package permissions with \`npm access\`.
  1214. If not set, and a registry response fails with a challenge for a one-time
  1215. password, npm will prompt on the command line for one.
  1216. `,
  1217. flatten,
  1218. })
  1219. define('package', {
  1220. default: [],
  1221. hint: '<pkg>[@<version>]',
  1222. type: [String, Array],
  1223. description: `
  1224. The package to install for [\`npm exec\`](/commands/npm-exec)
  1225. `,
  1226. flatten,
  1227. })
  1228. define('package-lock', {
  1229. default: true,
  1230. type: Boolean,
  1231. description: `
  1232. If set to false, then ignore \`package-lock.json\` files when installing.
  1233. This will also prevent _writing_ \`package-lock.json\` if \`save\` is
  1234. true.
  1235. When package package-locks are disabled, automatic pruning of extraneous
  1236. modules will also be disabled. To remove extraneous modules with
  1237. package-locks disabled use \`npm prune\`.
  1238. `,
  1239. flatten: (key, obj, flatOptions) => {
  1240. flatten(key, obj, flatOptions)
  1241. if (flatOptions.packageLockOnly)
  1242. flatOptions.packageLock = true
  1243. },
  1244. })
  1245. define('package-lock-only', {
  1246. default: false,
  1247. type: Boolean,
  1248. description: `
  1249. If set to true, the current operation will only use the \`package-lock.json\`,
  1250. ignoring \`node_modules\`.
  1251. For \`update\` this means only the \`package-lock.json\` will be updated,
  1252. instead of checking \`node_modules\` and downloading dependencies.
  1253. For \`list\` this means the output will be based on the tree described by the
  1254. \`package-lock.json\`, rather than the contents of \`node_modules\`.
  1255. `,
  1256. flatten: (key, obj, flatOptions) => {
  1257. flatten(key, obj, flatOptions)
  1258. if (flatOptions.packageLockOnly)
  1259. flatOptions.packageLock = true
  1260. },
  1261. })
  1262. define('pack-destination', {
  1263. default: '.',
  1264. type: String,
  1265. description: `
  1266. Directory in which \`npm pack\` will save tarballs.
  1267. `,
  1268. })
  1269. define('parseable', {
  1270. default: false,
  1271. type: Boolean,
  1272. short: 'p',
  1273. description: `
  1274. Output parseable results from commands that write to standard output. For
  1275. \`npm search\`, this will be tab-separated table format.
  1276. `,
  1277. flatten,
  1278. })
  1279. define('prefer-offline', {
  1280. default: false,
  1281. type: Boolean,
  1282. description: `
  1283. If true, staleness checks for cached data will be bypassed, but missing
  1284. data will be requested from the server. To force full offline mode, use
  1285. \`--offline\`.
  1286. `,
  1287. flatten,
  1288. })
  1289. define('prefer-online', {
  1290. default: false,
  1291. type: Boolean,
  1292. description: `
  1293. If true, staleness checks for cached data will be forced, making the CLI
  1294. look for updates immediately even for fresh package data.
  1295. `,
  1296. flatten,
  1297. })
  1298. // `prefix` has its default defined outside of this module
  1299. define('prefix', {
  1300. type: path,
  1301. short: 'C',
  1302. default: '',
  1303. defaultDescription: `
  1304. In global mode, the folder where the node executable is installed. In
  1305. local mode, the nearest parent folder containing either a package.json
  1306. file or a node_modules folder.
  1307. `,
  1308. description: `
  1309. The location to install global items. If set on the command line, then
  1310. it forces non-global commands to run in the specified folder.
  1311. `,
  1312. })
  1313. define('preid', {
  1314. default: '',
  1315. hint: 'prerelease-id',
  1316. type: String,
  1317. description: `
  1318. The "prerelease identifier" to use as a prefix for the "prerelease" part
  1319. of a semver. Like the \`rc\` in \`1.2.0-rc.8\`.
  1320. `,
  1321. flatten,
  1322. })
  1323. define('production', {
  1324. default: null,
  1325. type: [null, Boolean],
  1326. deprecated: 'Use `--omit=dev` instead.',
  1327. description: 'Alias for `--omit=dev`',
  1328. flatten (key, obj, flatOptions) {
  1329. definitions.omit.flatten('omit', obj, flatOptions)
  1330. },
  1331. })
  1332. define('progress', {
  1333. default: !ciName,
  1334. defaultDescription: `
  1335. \`true\` unless running in a known CI system
  1336. `,
  1337. type: Boolean,
  1338. description: `
  1339. When set to \`true\`, npm will display a progress bar during time
  1340. intensive operations, if \`process.stderr\` is a TTY.
  1341. Set to \`false\` to suppress the progress bar.
  1342. `,
  1343. })
  1344. define('proxy', {
  1345. default: null,
  1346. type: [null, false, url], // allow proxy to be disabled explicitly
  1347. description: `
  1348. A proxy to use for outgoing http requests. If the \`HTTP_PROXY\` or
  1349. \`http_proxy\` environment variables are set, proxy settings will be
  1350. honored by the underlying \`request\` library.
  1351. `,
  1352. flatten,
  1353. })
  1354. define('read-only', {
  1355. default: false,
  1356. type: Boolean,
  1357. description: `
  1358. This is used to mark a token as unable to publish when configuring
  1359. limited access tokens with the \`npm token create\` command.
  1360. `,
  1361. flatten,
  1362. })
  1363. define('rebuild-bundle', {
  1364. default: true,
  1365. type: Boolean,
  1366. description: `
  1367. Rebuild bundled dependencies after installation.
  1368. `,
  1369. flatten,
  1370. })
  1371. define('registry', {
  1372. default: 'https://registry.npmjs.org/',
  1373. type: url,
  1374. description: `
  1375. The base URL of the npm registry.
  1376. `,
  1377. flatten,
  1378. })
  1379. define('save', {
  1380. default: true,
  1381. usage: '-S|--save|--no-save|--save-prod|--save-dev|--save-optional|--save-peer',
  1382. type: Boolean,
  1383. short: 'S',
  1384. description: `
  1385. Save installed packages to a package.json file as dependencies.
  1386. When used with the \`npm rm\` command, removes the dependency from
  1387. package.json.
  1388. `,
  1389. flatten,
  1390. })
  1391. define('save-bundle', {
  1392. default: false,
  1393. type: Boolean,
  1394. short: 'B',
  1395. description: `
  1396. If a package would be saved at install time by the use of \`--save\`,
  1397. \`--save-dev\`, or \`--save-optional\`, then also put it in the
  1398. \`bundleDependencies\` list.
  1399. Ignore if \`--save-peer\` is set, since peerDependencies cannot be bundled.
  1400. `,
  1401. flatten (key, obj, flatOptions) {
  1402. // XXX update arborist to just ignore it if resulting saveType is peer
  1403. // otherwise this won't have the expected effect:
  1404. //
  1405. // npm config set save-peer true
  1406. // npm i foo --save-bundle --save-prod <-- should bundle
  1407. flatOptions.saveBundle = obj['save-bundle'] && !obj['save-peer']
  1408. },
  1409. })
  1410. // XXX: We should really deprecate all these `--save-blah` switches
  1411. // in favor of a single `--save-type` option. The unfortunate shortcut
  1412. // we took for `--save-peer --save-optional` being `--save-type=peerOptional`
  1413. // makes this tricky, and likely a breaking change.
  1414. define('save-dev', {
  1415. default: false,
  1416. type: Boolean,
  1417. short: 'D',
  1418. description: `
  1419. Save installed packages to a package.json file as \`devDependencies\`.
  1420. `,
  1421. flatten (key, obj, flatOptions) {
  1422. if (!obj[key]) {
  1423. if (flatOptions.saveType === 'dev')
  1424. delete flatOptions.saveType
  1425. return
  1426. }
  1427. flatOptions.saveType = 'dev'
  1428. },
  1429. })
  1430. define('save-exact', {
  1431. default: false,
  1432. type: Boolean,
  1433. short: 'E',
  1434. description: `
  1435. Dependencies saved to package.json will be configured with an exact
  1436. version rather than using npm's default semver range operator.
  1437. `,
  1438. flatten (key, obj, flatOptions) {
  1439. // just call the save-prefix flattener, it reads from obj['save-exact']
  1440. definitions['save-prefix'].flatten('save-prefix', obj, flatOptions)
  1441. },
  1442. })
  1443. define('save-optional', {
  1444. default: false,
  1445. type: Boolean,
  1446. short: 'O',
  1447. description: `
  1448. Save installed packages to a package.json file as
  1449. \`optionalDependencies\`.
  1450. `,
  1451. flatten (key, obj, flatOptions) {
  1452. if (!obj[key]) {
  1453. if (flatOptions.saveType === 'optional')
  1454. delete flatOptions.saveType
  1455. else if (flatOptions.saveType === 'peerOptional')
  1456. flatOptions.saveType = 'peer'
  1457. return
  1458. }
  1459. if (flatOptions.saveType === 'peerOptional')
  1460. return
  1461. if (flatOptions.saveType === 'peer')
  1462. flatOptions.saveType = 'peerOptional'
  1463. else
  1464. flatOptions.saveType = 'optional'
  1465. },
  1466. })
  1467. define('save-peer', {
  1468. default: false,
  1469. type: Boolean,
  1470. description: `
  1471. Save installed packages. to a package.json file as \`peerDependencies\`
  1472. `,
  1473. flatten (key, obj, flatOptions) {
  1474. if (!obj[key]) {
  1475. if (flatOptions.saveType === 'peer')
  1476. delete flatOptions.saveType
  1477. else if (flatOptions.saveType === 'peerOptional')
  1478. flatOptions.saveType = 'optional'
  1479. return
  1480. }
  1481. if (flatOptions.saveType === 'peerOptional')
  1482. return
  1483. if (flatOptions.saveType === 'optional')
  1484. flatOptions.saveType = 'peerOptional'
  1485. else
  1486. flatOptions.saveType = 'peer'
  1487. },
  1488. })
  1489. define('save-prefix', {
  1490. default: '^',
  1491. type: String,
  1492. description: `
  1493. Configure how versions of packages installed to a package.json file via
  1494. \`--save\` or \`--save-dev\` get prefixed.
  1495. For example if a package has version \`1.2.3\`, by default its version is
  1496. set to \`^1.2.3\` which allows minor upgrades for that package, but after
  1497. \`npm config set save-prefix='~'\` it would be set to \`~1.2.3\` which
  1498. only allows patch upgrades.
  1499. `,
  1500. flatten (key, obj, flatOptions) {
  1501. flatOptions.savePrefix = obj['save-exact'] ? '' : obj['save-prefix']
  1502. obj['save-prefix'] = flatOptions.savePrefix
  1503. },
  1504. })
  1505. define('save-prod', {
  1506. default: false,
  1507. type: Boolean,
  1508. short: 'P',
  1509. description: `
  1510. Save installed packages into \`dependencies\` specifically. This is
  1511. useful if a package already exists in \`devDependencies\` or
  1512. \`optionalDependencies\`, but you want to move it to be a non-optional
  1513. production dependency.
  1514. This is the default behavior if \`--save\` is true, and neither
  1515. \`--save-dev\` or \`--save-optional\` are true.
  1516. `,
  1517. flatten (key, obj, flatOptions) {
  1518. if (!obj[key]) {
  1519. if (flatOptions.saveType === 'prod')
  1520. delete flatOptions.saveType
  1521. return
  1522. }
  1523. flatOptions.saveType = 'prod'
  1524. },
  1525. })
  1526. define('scope', {
  1527. default: '',
  1528. defaultDescription: `
  1529. the scope of the current project, if any, or ""
  1530. `,
  1531. type: String,
  1532. hint: '<@scope>',
  1533. description: `
  1534. Associate an operation with a scope for a scoped registry.
  1535. Useful when logging in to or out of a private registry:
  1536. \`\`\`
  1537. # log in, linking the scope to the custom registry
  1538. npm login --scope=@mycorp --registry=https://registry.mycorp.com
  1539. # log out, removing the link and the auth token
  1540. npm logout --scope=@mycorp
  1541. \`\`\`
  1542. This will cause \`@mycorp\` to be mapped to the registry for future
  1543. installation of packages specified according to the pattern
  1544. \`@mycorp/package\`.
  1545. This will also cause \`npm init\` to create a scoped package.
  1546. \`\`\`
  1547. # accept all defaults, and create a package named "@foo/whatever",
  1548. # instead of just named "whatever"
  1549. npm init --scope=@foo --yes
  1550. \`\`\`
  1551. `,
  1552. flatten (key, obj, flatOptions) {
  1553. const value = obj[key]
  1554. flatOptions.projectScope = value && !/^@/.test(value) ? `@${value}` : value
  1555. },
  1556. })
  1557. define('script-shell', {
  1558. default: null,
  1559. defaultDescription: `
  1560. '/bin/sh' on POSIX systems, 'cmd.exe' on Windows
  1561. `,
  1562. type: [null, String],
  1563. description: `
  1564. The shell to use for scripts run with the \`npm exec\`,
  1565. \`npm run\` and \`npm init <pkg>\` commands.
  1566. `,
  1567. flatten (key, obj, flatOptions) {
  1568. flatOptions.scriptShell = obj[key] || undefined
  1569. },
  1570. })
  1571. define('searchexclude', {
  1572. default: '',
  1573. type: String,
  1574. description: `
  1575. Space-separated options that limit the results from search.
  1576. `,
  1577. flatten (key, obj, flatOptions) {
  1578. flatOptions.search = flatOptions.search || { limit: 20 }
  1579. flatOptions.search.exclude = obj[key]
  1580. },
  1581. })
  1582. define('searchlimit', {
  1583. default: 20,
  1584. type: Number,
  1585. description: `
  1586. Number of items to limit search results to. Will not apply at all to
  1587. legacy searches.
  1588. `,
  1589. flatten (key, obj, flatOptions) {
  1590. flatOptions.search = flatOptions.search || {}
  1591. flatOptions.search.limit = obj[key]
  1592. },
  1593. })
  1594. define('searchopts', {
  1595. default: '',
  1596. type: String,
  1597. description: `
  1598. Space-separated options that are always passed to search.
  1599. `,
  1600. flatten (key, obj, flatOptions) {
  1601. flatOptions.search = flatOptions.search || { limit: 20 }
  1602. flatOptions.search.opts = querystring.parse(obj[key])
  1603. },
  1604. })
  1605. define('searchstaleness', {
  1606. default: 15 * 60,
  1607. type: Number,
  1608. description: `
  1609. The age of the cache, in seconds, before another registry request is made
  1610. if using legacy search endpoint.
  1611. `,
  1612. flatten (key, obj, flatOptions) {
  1613. flatOptions.search = flatOptions.search || { limit: 20 }
  1614. flatOptions.search.staleness = obj[key]
  1615. },
  1616. })
  1617. define('shell', {
  1618. default: shell,
  1619. defaultDescription: `
  1620. SHELL environment variable, or "bash" on Posix, or "cmd.exe" on Windows
  1621. `,
  1622. type: String,
  1623. description: `
  1624. The shell to run for the \`npm explore\` command.
  1625. `,
  1626. flatten,
  1627. })
  1628. define('shrinkwrap', {
  1629. default: true,
  1630. type: Boolean,
  1631. deprecated: `
  1632. Use the --package-lock setting instead.
  1633. `,
  1634. description: `
  1635. Alias for --package-lock
  1636. `,
  1637. flatten (key, obj, flatOptions) {
  1638. obj['package-lock'] = obj.shrinkwrap
  1639. definitions['package-lock'].flatten('package-lock', obj, flatOptions)
  1640. },
  1641. })
  1642. define('sign-git-commit', {
  1643. default: false,
  1644. type: Boolean,
  1645. description: `
  1646. If set to true, then the \`npm version\` command will commit the new
  1647. package version using \`-S\` to add a signature.
  1648. Note that git requires you to have set up GPG keys in your git configs
  1649. for this to work properly.
  1650. `,
  1651. flatten,
  1652. })
  1653. define('sign-git-tag', {
  1654. default: false,
  1655. type: Boolean,
  1656. description: `
  1657. If set to true, then the \`npm version\` command will tag the version
  1658. using \`-s\` to add a signature.
  1659. Note that git requires you to have set up GPG keys in your git configs
  1660. for this to work properly.
  1661. `,
  1662. flatten,
  1663. })
  1664. define('sso-poll-frequency', {
  1665. default: 500,
  1666. type: Number,
  1667. deprecated: `
  1668. The --auth-type method of SSO/SAML/OAuth will be removed in a future
  1669. version of npm in favor of web-based login.
  1670. `,
  1671. description: `
  1672. When used with SSO-enabled \`auth-type\`s, configures how regularly the
  1673. registry should be polled while the user is completing authentication.
  1674. `,
  1675. flatten,
  1676. })
  1677. define('sso-type', {
  1678. default: 'oauth',
  1679. type: [null, 'oauth', 'saml'],
  1680. deprecated: `
  1681. The --auth-type method of SSO/SAML/OAuth will be removed in a future
  1682. version of npm in favor of web-based login.
  1683. `,
  1684. description: `
  1685. If \`--auth-type=sso\`, the type of SSO type to use.
  1686. `,
  1687. flatten,
  1688. })
  1689. define('strict-peer-deps', {
  1690. default: false,
  1691. type: Boolean,
  1692. description: `
  1693. If set to \`true\`, and \`--legacy-peer-deps\` is not set, then _any_
  1694. conflicting \`peerDependencies\` will be treated as an install failure,
  1695. even if npm could reasonably guess the appropriate resolution based on
  1696. non-peer dependency relationships.
  1697. By default, conflicting \`peerDependencies\` deep in the dependency graph
  1698. will be resolved using the nearest non-peer dependency specification,
  1699. even if doing so will result in some packages receiving a peer dependency
  1700. outside the range set in their package's \`peerDependencies\` object.
  1701. When such and override is performed, a warning is printed, explaining the
  1702. conflict and the packages involved. If \`--strict-peer-deps\` is set,
  1703. then this warning is treated as a failure.
  1704. `,
  1705. flatten,
  1706. })
  1707. define('strict-ssl', {
  1708. default: true,
  1709. type: Boolean,
  1710. description: `
  1711. Whether or not to do SSL key validation when making requests to the
  1712. registry via https.
  1713. See also the \`ca\` config.
  1714. `,
  1715. flatten (key, obj, flatOptions) {
  1716. flatOptions.strictSSL = obj[key]
  1717. },
  1718. })
  1719. define('tag', {
  1720. default: 'latest',
  1721. type: String,
  1722. description: `
  1723. If you ask npm to install a package and don't tell it a specific version,
  1724. then it will install the specified tag.
  1725. Also the tag that is added to the package@version specified by the \`npm
  1726. tag\` command, if no explicit tag is given.
  1727. When used by the \`npm diff\` command, this is the tag used to fetch the
  1728. tarball that will be compared with the local files by default.
  1729. `,
  1730. flatten (key, obj, flatOptions) {
  1731. flatOptions.defaultTag = obj[key]
  1732. },
  1733. })
  1734. define('tag-version-prefix', {
  1735. default: 'v',
  1736. type: String,
  1737. description: `
  1738. If set, alters the prefix used when tagging a new version when performing
  1739. a version increment using \`npm-version\`. To remove the prefix
  1740. altogether, set it to the empty string: \`""\`.
  1741. Because other tools may rely on the convention that npm version tags look
  1742. like \`v1.0.0\`, _only use this property if it is absolutely necessary_.
  1743. In particular, use care when overriding this setting for public packages.
  1744. `,
  1745. flatten,
  1746. })
  1747. define('timing', {
  1748. default: false,
  1749. type: Boolean,
  1750. description: `
  1751. If true, writes an \`npm-debug\` log to \`_logs\` and timing information
  1752. to \`_timing.json\`, both in your cache, even if the command completes
  1753. successfully. \`_timing.json\` is a newline delimited list of JSON
  1754. objects.
  1755. You can quickly view it with this [json](https://npm.im/json) command
  1756. line: \`npm exec -- json -g < ~/.npm/_timing.json\`.
  1757. `,
  1758. })
  1759. define('tmp', {
  1760. default: tmpdir(),
  1761. defaultDescription: `
  1762. The value returned by the Node.js \`os.tmpdir()\` method
  1763. <https://nodejs.org/api/os.html#os_os_tmpdir>
  1764. `,
  1765. type: path,
  1766. deprecated: `
  1767. This setting is no longer used. npm stores temporary files in a special
  1768. location in the cache, and they are managed by
  1769. [\`cacache\`](http://npm.im/cacache).
  1770. `,
  1771. description: `
  1772. Historically, the location where temporary files were stored. No longer
  1773. relevant.
  1774. `,
  1775. })
  1776. define('umask', {
  1777. default: 0,
  1778. type: Umask,
  1779. description: `
  1780. The "umask" value to use when setting the file creation mode on files and
  1781. folders.
  1782. Folders and executables are given a mode which is \`0o777\` masked
  1783. against this value. Other files are given a mode which is \`0o666\`
  1784. masked against this value.
  1785. Note that the underlying system will _also_ apply its own umask value to
  1786. files and folders that are created, and npm does not circumvent this, but
  1787. rather adds the \`--umask\` config to it.
  1788. Thus, the effective default umask value on most POSIX systems is 0o22,
  1789. meaning that folders and executables are created with a mode of 0o755 and
  1790. other files are created with a mode of 0o644.
  1791. `,
  1792. flatten,
  1793. })
  1794. define('unicode', {
  1795. default: unicode,
  1796. defaultDescription: `
  1797. false on windows, true on mac/unix systems with a unicode locale, as
  1798. defined by the \`LC_ALL\`, \`LC_CTYPE\`, or \`LANG\` environment variables.
  1799. `,
  1800. type: Boolean,
  1801. description: `
  1802. When set to true, npm uses unicode characters in the tree output. When
  1803. false, it uses ascii characters instead of unicode glyphs.
  1804. `,
  1805. })
  1806. define('update-notifier', {
  1807. default: true,
  1808. type: Boolean,
  1809. description: `
  1810. Set to false to suppress the update notification when using an older
  1811. version of npm than the latest.
  1812. `,
  1813. })
  1814. define('usage', {
  1815. default: false,
  1816. type: Boolean,
  1817. short: ['?', 'H', 'h'],
  1818. description: `
  1819. Show short usage output about the command specified.
  1820. `,
  1821. })
  1822. define('user-agent', {
  1823. default: 'npm/{npm-version} ' +
  1824. 'node/{node-version} ' +
  1825. '{platform} ' +
  1826. '{arch} ' +
  1827. 'workspaces/{workspaces} ' +
  1828. '{ci}',
  1829. type: String,
  1830. description: `
  1831. Sets the User-Agent request header. The following fields are replaced
  1832. with their actual counterparts:
  1833. * \`{npm-version}\` - The npm version in use
  1834. * \`{node-version}\` - The Node.js version in use
  1835. * \`{platform}\` - The value of \`process.platform\`
  1836. * \`{arch}\` - The value of \`process.arch\`
  1837. * \`{workspaces}\` - Set to \`true\` if the \`workspaces\` or \`workspace\`
  1838. options are set.
  1839. * \`{ci}\` - The value of the \`ci-name\` config, if set, prefixed with
  1840. \`ci/\`, or an empty string if \`ci-name\` is empty.
  1841. `,
  1842. flatten (key, obj, flatOptions) {
  1843. const value = obj[key]
  1844. const ciName = obj['ci-name']
  1845. let inWorkspaces = false
  1846. if (obj.workspaces || obj.workspace && obj.workspace.length)
  1847. inWorkspaces = true
  1848. flatOptions.userAgent =
  1849. value.replace(/\{node-version\}/gi, obj['node-version'])
  1850. .replace(/\{npm-version\}/gi, obj['npm-version'])
  1851. .replace(/\{platform\}/gi, process.platform)
  1852. .replace(/\{arch\}/gi, process.arch)
  1853. .replace(/\{workspaces\}/gi, inWorkspaces)
  1854. .replace(/\{ci\}/gi, ciName ? `ci/${ciName}` : '')
  1855. .trim()
  1856. // We can't clobber the original or else subsequent flattening will fail
  1857. // (i.e. when we change the underlying config values)
  1858. // obj[key] = flatOptions.userAgent
  1859. // user-agent is a unique kind of config item that gets set from a template
  1860. // and ends up translated. Because of this, the normal "should we set this
  1861. // to process.env also doesn't work
  1862. process.env.npm_config_user_agent = flatOptions.userAgent
  1863. },
  1864. })
  1865. define('userconfig', {
  1866. default: '~/.npmrc',
  1867. type: path,
  1868. description: `
  1869. The location of user-level configuration settings.
  1870. This may be overridden by the \`npm_config_userconfig\` environment
  1871. variable or the \`--userconfig\` command line option, but may _not_
  1872. be overridden by settings in the \`globalconfig\` file.
  1873. `,
  1874. })
  1875. define('version', {
  1876. default: false,
  1877. type: Boolean,
  1878. short: 'v',
  1879. description: `
  1880. If true, output the npm version and exit successfully.
  1881. Only relevant when specified explicitly on the command line.
  1882. `,
  1883. })
  1884. define('versions', {
  1885. default: false,
  1886. type: Boolean,
  1887. description: `
  1888. If true, output the npm version as well as node's \`process.versions\`
  1889. map and the version in the current working directory's \`package.json\`
  1890. file if one exists, and exit successfully.
  1891. Only relevant when specified explicitly on the command line.
  1892. `,
  1893. })
  1894. define('viewer', {
  1895. default: isWindows ? 'browser' : 'man',
  1896. defaultDescription: `
  1897. "man" on Posix, "browser" on Windows
  1898. `,
  1899. type: String,
  1900. description: `
  1901. The program to use to view help content.
  1902. Set to \`"browser"\` to view html help content in the default web browser.
  1903. `,
  1904. })
  1905. define('which', {
  1906. default: null,
  1907. hint: '<fundingSourceNumber>',
  1908. type: [null, Number],
  1909. description: `
  1910. If there are multiple funding sources, which 1-indexed source URL to open.
  1911. `,
  1912. })
  1913. define('workspace', {
  1914. default: [],
  1915. type: [String, Array],
  1916. hint: '<workspace-name>',
  1917. short: 'w',
  1918. envExport: false,
  1919. description: `
  1920. Enable running a command in the context of the configured workspaces of the
  1921. current project while filtering by running only the workspaces defined by
  1922. this configuration option.
  1923. Valid values for the \`workspace\` config are either:
  1924. * Workspace names
  1925. * Path to a workspace directory
  1926. * Path to a parent workspace directory (will result in selecting all
  1927. workspaces within that folder)
  1928. When set for the \`npm init\` command, this may be set to the folder of
  1929. a workspace which does not yet exist, to create the folder and set it
  1930. up as a brand new workspace within the project.
  1931. `,
  1932. flatten: (key, obj, flatOptions) => {
  1933. definitions['user-agent'].flatten('user-agent', obj, flatOptions)
  1934. },
  1935. })
  1936. define('workspaces', {
  1937. default: null,
  1938. type: [null, Boolean],
  1939. short: 'ws',
  1940. envExport: false,
  1941. description: `
  1942. Set to true to run the command in the context of **all** configured
  1943. workspaces.
  1944. Explicitly setting this to false will cause commands like \`install\` to
  1945. ignore workspaces altogether.
  1946. When not set explicitly:
  1947. - Commands that operate on the \`node_modules\` tree (install, update,
  1948. etc.) will link workspaces into the \`node_modules\` folder.
  1949. - Commands that do other things (test, exec, publish, etc.) will operate
  1950. on the root project, _unless_ one or more workspaces are specified in
  1951. the \`workspace\` config.
  1952. `,
  1953. flatten: (key, obj, flatOptions) => {
  1954. definitions['user-agent'].flatten('user-agent', obj, flatOptions)
  1955. // TODO: this is a derived value, and should be reworked when we have a
  1956. // pattern for derived value
  1957. // workspacesEnabled is true whether workspaces is null or true
  1958. // commands contextually work with workspaces or not regardless of
  1959. // configuration, so we need an option specifically to disable workspaces
  1960. flatOptions.workspacesEnabled = obj[key] !== false
  1961. },
  1962. })
  1963. define('yes', {
  1964. default: null,
  1965. type: [null, Boolean],
  1966. short: 'y',
  1967. description: `
  1968. Automatically answer "yes" to any prompts that npm might print on
  1969. the command line.
  1970. `,
  1971. })