-
Notifications
You must be signed in to change notification settings - Fork 3.2k
/
definitions.js
2384 lines (2109 loc) · 63.7 KB
/
definitions.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
const definitions = {}
module.exports = definitions
const Definition = require('./definition.js')
const ciInfo = require('ci-info')
const querystring = require('querystring')
const { join } = require('path')
const isWindows = process.platform === 'win32'
// used by cafile flattening to flatOptions.ca
const fs = require('fs')
const maybeReadFile = file => {
try {
return fs.readFileSync(file, 'utf8')
} catch (er) {
if (er.code !== 'ENOENT') {
throw er
}
return null
}
}
const buildOmitList = obj => {
const include = obj.include || []
const omit = obj.omit || []
const only = obj.only
if (/^prod(uction)?$/.test(only) || obj.production) {
omit.push('dev')
} else if (obj.production === false) {
include.push('dev')
}
if (/^dev/.test(obj.also)) {
include.push('dev')
}
if (obj.dev) {
include.push('dev')
}
if (obj.optional === false) {
omit.push('optional')
} else if (obj.optional === true) {
include.push('optional')
}
obj.omit = [...new Set(omit)].filter(type => !include.includes(type))
obj.include = [...new Set(include)]
if (obj.omit.includes('dev')) {
process.env.NODE_ENV = 'production'
}
return obj.omit
}
const editor = process.env.EDITOR ||
process.env.VISUAL ||
(isWindows ? `${process.env.SYSTEMROOT}\\notepad.exe` : 'vi')
const shell = isWindows ? process.env.ComSpec || 'cmd'
: process.env.SHELL || 'sh'
const { tmpdir, networkInterfaces } = require('os')
const getLocalAddresses = () => {
try {
return Object.values(networkInterfaces()).map(
int => int.map(({ address }) => address)
).reduce((set, addrs) => set.concat(addrs), [null])
} catch (e) {
return [null]
}
}
const unicode = /UTF-?8$/i.test(
process.env.LC_ALL ||
process.env.LC_CTYPE ||
process.env.LANG
)
// use LOCALAPPDATA on Windows, if set
// https://github.com/npm/cli/pull/899
const cacheRoot = (isWindows && process.env.LOCALAPPDATA) || '~'
const cacheExtra = isWindows ? 'npm-cache' : '.npm'
const cache = `${cacheRoot}/${cacheExtra}`
// TODO: refactor these type definitions so that they are less
// weird to pull out of the config module.
// TODO: use better type definition/validation API, nopt's is so weird.
const {
semver: { type: semver },
Umask: { type: Umask },
url: { type: url },
path: { type: path },
} = require('../type-defs.js')
const define = (key, def) => {
/* istanbul ignore if - this should never happen, prevents mistakes below */
if (definitions[key]) {
throw new Error(`defining key more than once: ${key}`)
}
definitions[key] = new Definition(key, def)
}
// basic flattening function, just copy it over camelCase
const flatten = (key, obj, flatOptions) => {
const camel = key.replace(/-([a-z])/g, (_0, _1) => _1.toUpperCase())
flatOptions[camel] = obj[key]
}
// TODO:
// Instead of having each definition provide a flatten method,
// provide the (?list of?) flat option field(s?) that it impacts.
// When that config is set, we mark the relevant flatOption fields
// dirty. Then, a getter for that field defines how we actually
// set it.
//
// So, `save-dev`, `save-optional`, `save-prod`, et al would indicate
// that they affect the `saveType` flat option. Then the config.flat
// object has a `get saveType () { ... }` that looks at the "real"
// config settings from files etc and returns the appropriate value.
//
// Getters will also (maybe?) give us a hook to audit flat option
// usage, so we can document and group these more appropriately.
//
// This will be a problem with cases where we currently do:
// const opts = { ...npm.flatOptions, foo: 'bar' }, but we can maybe
// instead do `npm.config.set('foo', 'bar')` prior to passing the
// config object down where it needs to go.
//
// This way, when we go hunting for "where does saveType come from anyway!?"
// while fixing some Arborist bug, we won't have to hunt through too
// many places.
// Define all config keys we know about
define('_auth', {
default: null,
type: [null, String],
description: `
A basic-auth string to use when authenticating against the npm registry.
This will ONLY be used to authenticate against the npm registry. For other
registries you will need to scope it like "//other-registry.tld/:_auth"
Warning: This should generally not be set via a command-line option. It
is safer to use a registry-provided authentication bearer token stored in
the ~/.npmrc file by running \`npm login\`.
`,
flatten,
})
define('access', {
default: null,
defaultDescription: `
'public' for new packages, existing packages it will not change the current level
`,
type: [null, 'restricted', 'public'],
description: `
If you do not want your scoped package to be publicly viewable (and
installable) set \`--access=restricted\`.
Unscoped packages can not be set to \`restricted\`.
Note: This defaults to not changing the current access level for existing
packages. Specifying a value of \`restricted\` or \`public\` during
publish will change the access for an existing package the same way that
\`npm access set status\` would.
`,
flatten,
})
define('all', {
default: false,
type: Boolean,
short: 'a',
description: `
When running \`npm outdated\` and \`npm ls\`, setting \`--all\` will show
all outdated or installed packages, rather than only those directly
depended upon by the current project.
`,
flatten,
})
define('allow-same-version', {
default: false,
type: Boolean,
description: `
Prevents throwing an error when \`npm version\` is used to set the new
version to the same value as the current version.
`,
flatten,
})
define('also', {
default: null,
type: [null, 'dev', 'development'],
description: `
When set to \`dev\` or \`development\`, this is an alias for
\`--include=dev\`.
`,
deprecated: 'Please use --include=dev instead.',
flatten (key, obj, flatOptions) {
definitions.omit.flatten('omit', obj, flatOptions)
},
})
define('audit', {
default: true,
type: Boolean,
description: `
When "true" submit audit reports alongside the current npm command to the
default registry and all registries configured for scopes. See the
documentation for [\`npm audit\`](/commands/npm-audit) for details on what
is submitted.
`,
flatten,
})
define('audit-level', {
default: null,
type: [null, 'info', 'low', 'moderate', 'high', 'critical', 'none'],
description: `
The minimum level of vulnerability for \`npm audit\` to exit with
a non-zero exit code.
`,
flatten,
})
define('auth-type', {
default: 'web',
type: ['legacy', 'web'],
description: `
What authentication strategy to use with \`login\`.
Note that if an \`otp\` config is given, this value will always be set to \`legacy\`.
`,
flatten,
})
define('before', {
default: null,
type: [null, Date],
description: `
If passed to \`npm install\`, will rebuild the npm tree such that only
versions that were available **on or before** the \`--before\` time get
installed. If there's no versions available for the current set of
direct dependencies, the command will error.
If the requested version is a \`dist-tag\` and the given tag does not
pass the \`--before\` filter, the most recent version less than or equal
to that tag will be used. For example, \`foo@latest\` might install
\`foo@1.2\` even though \`latest\` is \`2.0\`.
`,
flatten,
})
define('bin-links', {
default: true,
type: Boolean,
description: `
Tells npm to create symlinks (or \`.cmd\` shims on Windows) for package
executables.
Set to false to have it not do this. This can be used to work around the
fact that some file systems don't support symlinks, even on ostensibly
Unix systems.
`,
flatten,
})
define('browser', {
default: null,
defaultDescription: `
OS X: \`"open"\`, Windows: \`"start"\`, Others: \`"xdg-open"\`
`,
type: [null, Boolean, String],
description: `
The browser that is called by npm commands to open websites.
Set to \`false\` to suppress browser behavior and instead print urls to
terminal.
Set to \`true\` to use default system URL opener.
`,
flatten,
})
define('ca', {
default: null,
type: [null, String, Array],
description: `
The Certificate Authority signing certificate that is trusted for SSL
connections to the registry. Values should be in PEM format (Windows
calls it "Base-64 encoded X.509 (.CER)") with newlines replaced by the
string "\\n". For example:
\`\`\`ini
ca="-----BEGIN CERTIFICATE-----\\nXXXX\\nXXXX\\n-----END CERTIFICATE-----"
\`\`\`
Set to \`null\` to only allow "known" registrars, or to a specific CA
cert to trust only that specific signing authority.
Multiple CAs can be trusted by specifying an array of certificates:
\`\`\`ini
ca[]="..."
ca[]="..."
\`\`\`
See also the \`strict-ssl\` config.
`,
flatten,
})
define('cache', {
default: cache,
defaultDescription: `
Windows: \`%LocalAppData%\\npm-cache\`, Posix: \`~/.npm\`
`,
type: path,
description: `
The location of npm's cache directory.
`,
flatten (key, obj, flatOptions) {
flatOptions.cache = join(obj.cache, '_cacache')
flatOptions.npxCache = join(obj.cache, '_npx')
flatOptions.tufCache = join(obj.cache, '_tuf')
},
})
define('cache-max', {
default: Infinity,
type: Number,
description: `
\`--cache-max=0\` is an alias for \`--prefer-online\`
`,
deprecated: `
This option has been deprecated in favor of \`--prefer-online\`
`,
flatten (key, obj, flatOptions) {
if (obj[key] <= 0) {
flatOptions.preferOnline = true
}
},
})
define('cache-min', {
default: 0,
type: Number,
description: `
\`--cache-min=9999 (or bigger)\` is an alias for \`--prefer-offline\`.
`,
deprecated: `
This option has been deprecated in favor of \`--prefer-offline\`.
`,
flatten (key, obj, flatOptions) {
if (obj[key] >= 9999) {
flatOptions.preferOffline = true
}
},
})
define('cafile', {
default: null,
type: path,
description: `
A path to a file containing one or multiple Certificate Authority signing
certificates. Similar to the \`ca\` setting, but allows for multiple
CA's, as well as for the CA information to be stored in a file on disk.
`,
flatten (key, obj, flatOptions) {
// always set to null in defaults
if (!obj.cafile) {
return
}
const raw = maybeReadFile(obj.cafile)
if (!raw) {
return
}
const delim = '-----END CERTIFICATE-----'
flatOptions.ca = raw.replace(/\r\n/g, '\n').split(delim)
.filter(section => section.trim())
.map(section => section.trimLeft() + delim)
},
})
define('call', {
default: '',
type: String,
short: 'c',
description: `
Optional companion option for \`npm exec\`, \`npx\` that allows for
specifying a custom command to be run along with the installed packages.
\`\`\`bash
npm exec --package yo --package generator-node --call "yo node"
\`\`\`
`,
flatten,
})
define('cert', {
default: null,
type: [null, String],
description: `
A client certificate to pass when accessing the registry. Values should
be in PEM format (Windows calls it "Base-64 encoded X.509 (.CER)") with
newlines replaced by the string "\\n". For example:
\`\`\`ini
cert="-----BEGIN CERTIFICATE-----\\nXXXX\\nXXXX\\n-----END CERTIFICATE-----"
\`\`\`
It is _not_ the path to a certificate file, though you can set a registry-scoped
"certfile" path like "//other-registry.tld/:certfile=/path/to/cert.pem".
`,
deprecated: `
\`key\` and \`cert\` are no longer used for most registry operations.
Use registry scoped \`keyfile\` and \`certfile\` instead.
Example:
//other-registry.tld/:keyfile=/path/to/key.pem
//other-registry.tld/:certfile=/path/to/cert.crt
`,
flatten,
})
define('ci-name', {
default: ciInfo.name ? ciInfo.name.toLowerCase().split(' ').join('-') : null,
defaultDescription: `
The name of the current CI system, or \`null\` when not on a known CI
platform.
`,
type: [null, String],
deprecated: `
This config is deprecated and will not be changeable in future version of npm.
`,
description: `
The name of a continuous integration system. If not set explicitly, npm
will detect the current CI environment using the
[\`ci-info\`](http://npm.im/ci-info) module.
`,
flatten,
})
define('cidr', {
default: null,
type: [null, String, Array],
description: `
This is a list of CIDR address to be used when configuring limited access
tokens with the \`npm token create\` command.
`,
flatten,
})
// This should never be directly used, the flattened value is the derived value
// and is sent to other modules, and is also exposed as `npm.color` for use
// inside npm itself.
define('color', {
default: !process.env.NO_COLOR || process.env.NO_COLOR === '0',
usage: '--color|--no-color|--color always',
defaultDescription: `
true unless the NO_COLOR environ is set to something other than '0'
`,
type: ['always', Boolean],
description: `
If false, never shows colors. If \`"always"\` then always shows colors.
If true, then only prints color codes for tty file descriptors.
`,
flatten (key, obj, flatOptions) {
flatOptions.color = !obj.color ? false
: obj.color === 'always' ? true
: !!process.stdout.isTTY
flatOptions.logColor = !obj.color ? false
: obj.color === 'always' ? true
: !!process.stderr.isTTY
},
})
define('commit-hooks', {
default: true,
type: Boolean,
description: `
Run git commit hooks when using the \`npm version\` command.
`,
flatten,
})
define('depth', {
default: null,
defaultDescription: `
\`Infinity\` if \`--all\` is set, otherwise \`1\`
`,
type: [null, Number],
description: `
The depth to go when recursing packages for \`npm ls\`.
If not set, \`npm ls\` will show only the immediate dependencies of the
root project. If \`--all\` is set, then npm will show all dependencies
by default.
`,
flatten,
})
define('description', {
default: true,
type: Boolean,
usage: '--no-description',
description: `
Show the description in \`npm search\`
`,
flatten (key, obj, flatOptions) {
flatOptions.search = flatOptions.search || { limit: 20 }
flatOptions.search[key] = obj[key]
},
})
define('dev', {
default: false,
type: Boolean,
description: `
Alias for \`--include=dev\`.
`,
deprecated: 'Please use --include=dev instead.',
flatten (key, obj, flatOptions) {
definitions.omit.flatten('omit', obj, flatOptions)
},
})
define('diff', {
default: [],
hint: '<package-spec>',
type: [String, Array],
description: `
Define arguments to compare in \`npm diff\`.
`,
flatten,
})
define('diff-ignore-all-space', {
default: false,
type: Boolean,
description: `
Ignore whitespace when comparing lines in \`npm diff\`.
`,
flatten,
})
define('diff-name-only', {
default: false,
type: Boolean,
description: `
Prints only filenames when using \`npm diff\`.
`,
flatten,
})
define('diff-no-prefix', {
default: false,
type: Boolean,
description: `
Do not show any source or destination prefix in \`npm diff\` output.
Note: this causes \`npm diff\` to ignore the \`--diff-src-prefix\` and
\`--diff-dst-prefix\` configs.
`,
flatten,
})
define('diff-dst-prefix', {
default: 'b/',
hint: '<path>',
type: String,
description: `
Destination prefix to be used in \`npm diff\` output.
`,
flatten,
})
define('diff-src-prefix', {
default: 'a/',
hint: '<path>',
type: String,
description: `
Source prefix to be used in \`npm diff\` output.
`,
flatten,
})
define('diff-text', {
default: false,
type: Boolean,
description: `
Treat all files as text in \`npm diff\`.
`,
flatten,
})
define('diff-unified', {
default: 3,
type: Number,
description: `
The number of lines of context to print in \`npm diff\`.
`,
flatten,
})
define('dry-run', {
default: false,
type: Boolean,
description: `
Indicates that you don't want npm to make any changes and that it should
only report what it would have done. This can be passed into any of the
commands that modify your local installation, eg, \`install\`,
\`update\`, \`dedupe\`, \`uninstall\`, as well as \`pack\` and
\`publish\`.
Note: This is NOT honored by other network related commands, eg
\`dist-tags\`, \`owner\`, etc.
`,
flatten,
})
define('editor', {
default: editor,
defaultDescription: `
The EDITOR or VISUAL environment variables, or '%SYSTEMROOT%\\notepad.exe' on Windows,
or 'vi' on Unix systems
`,
type: String,
description: `
The command to run for \`npm edit\` and \`npm config edit\`.
`,
flatten,
})
define('engine-strict', {
default: false,
type: Boolean,
description: `
If set to true, then npm will stubbornly refuse to install (or even
consider installing) any package that claims to not be compatible with
the current Node.js version.
This can be overridden by setting the \`--force\` flag.
`,
flatten,
})
define('fetch-retries', {
default: 2,
type: Number,
description: `
The "retries" config for the \`retry\` module to use when fetching
packages from the registry.
npm will retry idempotent read requests to the registry in the case
of network failures or 5xx HTTP errors.
`,
flatten (key, obj, flatOptions) {
flatOptions.retry = flatOptions.retry || {}
flatOptions.retry.retries = obj[key]
},
})
define('fetch-retry-factor', {
default: 10,
type: Number,
description: `
The "factor" config for the \`retry\` module to use when fetching
packages.
`,
flatten (key, obj, flatOptions) {
flatOptions.retry = flatOptions.retry || {}
flatOptions.retry.factor = obj[key]
},
})
define('fetch-retry-maxtimeout', {
default: 60000,
defaultDescription: '60000 (1 minute)',
type: Number,
description: `
The "maxTimeout" config for the \`retry\` module to use when fetching
packages.
`,
flatten (key, obj, flatOptions) {
flatOptions.retry = flatOptions.retry || {}
flatOptions.retry.maxTimeout = obj[key]
},
})
define('fetch-retry-mintimeout', {
default: 10000,
defaultDescription: '10000 (10 seconds)',
type: Number,
description: `
The "minTimeout" config for the \`retry\` module to use when fetching
packages.
`,
flatten (key, obj, flatOptions) {
flatOptions.retry = flatOptions.retry || {}
flatOptions.retry.minTimeout = obj[key]
},
})
define('fetch-timeout', {
default: 5 * 60 * 1000,
defaultDescription: `${5 * 60 * 1000} (5 minutes)`,
type: Number,
description: `
The maximum amount of time to wait for HTTP requests to complete.
`,
flatten (key, obj, flatOptions) {
flatOptions.timeout = obj[key]
},
})
define('force', {
default: false,
type: Boolean,
short: 'f',
description: `
Removes various protections against unfortunate side effects, common
mistakes, unnecessary performance degradation, and malicious input.
* Allow clobbering non-npm files in global installs.
* Allow the \`npm version\` command to work on an unclean git repository.
* Allow deleting the cache folder with \`npm cache clean\`.
* Allow installing packages that have an \`engines\` declaration
requiring a different version of npm.
* Allow installing packages that have an \`engines\` declaration
requiring a different version of \`node\`, even if \`--engine-strict\`
is enabled.
* Allow \`npm audit fix\` to install modules outside your stated
dependency range (including SemVer-major changes).
* Allow unpublishing all versions of a published package.
* Allow conflicting peerDependencies to be installed in the root project.
* Implicitly set \`--yes\` during \`npm init\`.
* Allow clobbering existing values in \`npm pkg\`
* Allow unpublishing of entire packages (not just a single version).
If you don't have a clear idea of what you want to do, it is strongly
recommended that you do not use this option!
`,
flatten,
})
define('foreground-scripts', {
default: false,
type: Boolean,
description: `
Run all build scripts (ie, \`preinstall\`, \`install\`, and
\`postinstall\`) scripts for installed packages in the foreground
process, sharing standard input, output, and error with the main npm
process.
Note that this will generally make installs run slower, and be much
noisier, but can be useful for debugging.
`,
flatten,
})
define('format-package-lock', {
default: true,
type: Boolean,
description: `
Format \`package-lock.json\` or \`npm-shrinkwrap.json\` as a human
readable file.
`,
flatten,
})
define('fund', {
default: true,
type: Boolean,
description: `
When "true" displays the message at the end of each \`npm install\`
acknowledging the number of dependencies looking for funding.
See [\`npm fund\`](/commands/npm-fund) for details.
`,
flatten,
})
define('git', {
default: 'git',
type: String,
description: `
The command to use for git commands. If git is installed on the
computer, but is not in the \`PATH\`, then set this to the full path to
the git binary.
`,
flatten,
})
define('git-tag-version', {
default: true,
type: Boolean,
description: `
Tag the commit when using the \`npm version\` command. Setting this to
false results in no commit being made at all.
`,
flatten,
})
define('global', {
default: false,
type: Boolean,
short: 'g',
description: `
Operates in "global" mode, so that packages are installed into the
\`prefix\` folder instead of the current working directory. See
[folders](/configuring-npm/folders) for more on the differences in
behavior.
* packages are installed into the \`{prefix}/lib/node_modules\` folder,
instead of the current working directory.
* bin files are linked to \`{prefix}/bin\`
* man pages are linked to \`{prefix}/share/man\`
`,
flatten: (key, obj, flatOptions) => {
flatten(key, obj, flatOptions)
if (flatOptions.global) {
flatOptions.location = 'global'
}
},
})
// the globalconfig has its default defined outside of this module
define('globalconfig', {
type: path,
default: '',
defaultDescription: `
The global --prefix setting plus 'etc/npmrc'. For example,
'/usr/local/etc/npmrc'
`,
description: `
The config file to read for global config options.
`,
flatten,
})
define('global-style', {
default: false,
type: Boolean,
description: `
Only install direct dependencies in the top level \`node_modules\`,
but hoist on deeper dependencies.
Sets \`--install-strategy=shallow\`.
`,
deprecated: `
This option has been deprecated in favor of \`--install-strategy=shallow\`
`,
flatten (key, obj, flatOptions) {
if (obj[key]) {
obj['install-strategy'] = 'shallow'
flatOptions.installStrategy = 'shallow'
}
},
})
define('heading', {
default: 'npm',
type: String,
description: `
The string that starts all the debugging log output.
`,
flatten,
})
define('https-proxy', {
default: null,
type: [null, url],
description: `
A proxy to use for outgoing https requests. If the \`HTTPS_PROXY\` or
\`https_proxy\` or \`HTTP_PROXY\` or \`http_proxy\` environment variables
are set, proxy settings will be honored by the underlying
\`make-fetch-happen\` library.
`,
flatten,
})
define('if-present', {
default: false,
type: Boolean,
envExport: false,
description: `
If true, npm will not exit with an error code when \`run-script\` is
invoked for a script that isn't defined in the \`scripts\` section of
\`package.json\`. This option can be used when it's desirable to
optionally run a script when it's present and fail if the script fails.
This is useful, for example, when running scripts that may only apply for
some builds in an otherwise generic CI setup.
`,
flatten,
})
define('ignore-scripts', {
default: false,
type: Boolean,
description: `
If true, npm does not run scripts specified in package.json files.
Note that commands explicitly intended to run a particular script, such
as \`npm start\`, \`npm stop\`, \`npm restart\`, \`npm test\`, and \`npm
run-script\` will still run their intended script if \`ignore-scripts\` is
set, but they will *not* run any pre- or post-scripts.
`,
flatten,
})
define('include', {
default: [],
type: [Array, 'prod', 'dev', 'optional', 'peer'],
description: `
Option that allows for defining which types of dependencies to install.
This is the inverse of \`--omit=<type>\`.
Dependency types specified in \`--include\` will not be omitted,
regardless of the order in which omit/include are specified on the
command-line.
`,
flatten (key, obj, flatOptions) {
// just call the omit flattener, it reads from obj.include
definitions.omit.flatten('omit', obj, flatOptions)
},
})
define('include-staged', {
default: false,
type: Boolean,
description: `
Allow installing "staged" published packages, as defined by [npm RFC PR
#92](https://github.com/npm/rfcs/pull/92).
This is experimental, and not implemented by the npm public registry.
`,
flatten,
})
define('include-workspace-root', {
default: false,
type: Boolean,
envExport: false,
description: `
Include the workspace root when workspaces are enabled for a command.
When false, specifying individual workspaces via the \`workspace\` config,
or all workspaces via the \`workspaces\` flag, will cause npm to operate only
on the specified workspaces, and not on the root project.
`,
flatten,
})
define('init-author-email', {
default: '',
type: String,
description: `
The value \`npm init\` should use by default for the package author's
email.
`,
})
define('init-author-name', {
default: '',
type: String,
description: `
The value \`npm init\` should use by default for the package author's name.
`,
})
define('init-author-url', {
default: '',
type: ['', url],
description: `
The value \`npm init\` should use by default for the package author's homepage.
`,
})
define('init-license', {
default: 'ISC',
type: String,
description: `
The value \`npm init\` should use by default for the package license.
`,
})
define('init-module', {
default: '~/.npm-init.js',
type: path,
description: `
A module that will be loaded by the \`npm init\` command. See the
documentation for the
[init-package-json](https://github.com/npm/init-package-json) module for
more information, or [npm init](/commands/npm-init).