This repository was archived by the owner on Jul 28, 2021. It is now read-only.
File tree Expand file tree Collapse file tree 1 file changed +40
-1
lines changed Expand file tree Collapse file tree 1 file changed +40
-1
lines changed Original file line number Diff line number Diff line change 1
1
'use strict'
2
2
3
3
const figgyPudding = require ( 'figgy-pudding' )
4
+ const spawn = require ( 'child_process' ) . spawn
4
5
5
- module . exports = figgyPudding ( {
6
+ const frogConfig = module . exports = figgyPudding ( {
6
7
also : { } ,
7
8
cache : { } ,
8
9
dev : { } ,
9
10
development : { } ,
10
11
force : { } ,
12
+ global : { } ,
11
13
'ignore-scripts' : { } ,
12
14
log : { } ,
15
+ loglevel : { } ,
13
16
only : { } ,
14
17
prefix : { } ,
15
18
production : { } ,
19
+ then : { } , // omfg
16
20
umask : { }
17
21
} )
22
+
23
+ module . exports . fromNpm = getNpmConfig
24
+ async function getNpmConfig ( argv ) {
25
+ const npmBin = process . platform === 'win32' ? 'npm.cmd' : 'npm'
26
+ const child = spawn ( npmBin , [
27
+ 'config' , 'ls' , '--json' , '-l'
28
+ // We add argv here to get npm to parse those options for us :D
29
+ ] . concat ( argv || [ ] ) , {
30
+ env : process . env ,
31
+ cwd : process . cwd ( ) ,
32
+ stdio : [ 0 , 'pipe' , 2 ]
33
+ } )
34
+
35
+ let stdout = ''
36
+ if ( child . stdout ) {
37
+ child . stdout . on ( 'data' , ( chunk ) => {
38
+ stdout += chunk
39
+ } )
40
+ }
41
+
42
+ return await new Promise ( ( resolve , reject ) => {
43
+ child . on ( 'error' , reject )
44
+ child . on ( 'close' , ( code ) => {
45
+ if ( code === 127 ) {
46
+ reject ( new Error ( '`npm` command not found. Please ensure you have npm@5.4.0 or later installed.' ) )
47
+ } else {
48
+ try {
49
+ resolve ( frogConfig ( JSON . parse ( stdout ) ) )
50
+ } catch ( e ) {
51
+ reject ( new Error ( '`npm config ls --json` failed to output json. Please ensure you have npm@5.4.0 or later installed.' ) )
52
+ }
53
+ }
54
+ } )
55
+ } )
56
+ }
You can’t perform that action at this time.
0 commit comments