@@ -6,13 +6,15 @@ const util = require('util')
6
6
const readdir = util . promisify ( fs . readdir )
7
7
const npm = require ( './npm.js' )
8
8
const usageUtil = require ( './utils/usage.js' )
9
- const reifyOutput = require ( './utils/reify-output .js' )
9
+ const reifyFinish = require ( './utils/reify-finish .js' )
10
10
const log = require ( 'npmlog' )
11
11
const { resolve, join } = require ( 'path' )
12
12
const Arborist = require ( '@npmcli/arborist' )
13
13
const runScript = require ( '@npmcli/run-script' )
14
14
15
- const install = async ( args , cb ) => {
15
+ const cmd = async ( args , cb ) => install ( args ) . then ( ( ) => cb ( ) ) . catch ( cb )
16
+
17
+ const install = async args => {
16
18
// the /path/to/node_modules/..
17
19
const globalTop = resolve ( npm . globalDir , '..' )
18
20
const { ignoreScripts, global : isGlobalInstall } = npm . flatOptions
@@ -34,38 +36,33 @@ const install = async (args, cb) => {
34
36
path : where ,
35
37
} )
36
38
37
- try {
38
- await arb . reify ( {
39
- ...npm . flatOptions ,
40
- add : args ,
41
- } )
42
- if ( ! args . length && ! isGlobalInstall && ! ignoreScripts ) {
43
- const { scriptShell } = npm . flatOptions
44
- const scripts = [
45
- 'preinstall' ,
46
- 'install' ,
47
- 'postinstall' ,
48
- 'prepublish' , // XXX should we remove this finally??
49
- 'preprepare' ,
50
- 'prepare' ,
51
- 'postprepare' ,
52
- ]
53
- for ( const event of scripts ) {
54
- await runScript ( {
55
- path : where ,
56
- args : [ ] ,
57
- scriptShell,
58
- stdio : 'inherit' ,
59
- stdioString : true ,
60
- event,
61
- } )
62
- }
39
+ await arb . reify ( {
40
+ ...npm . flatOptions ,
41
+ add : args ,
42
+ } )
43
+ if ( ! args . length && ! isGlobalInstall && ! ignoreScripts ) {
44
+ const { scriptShell } = npm . flatOptions
45
+ const scripts = [
46
+ 'preinstall' ,
47
+ 'install' ,
48
+ 'postinstall' ,
49
+ 'prepublish' , // XXX should we remove this finally??
50
+ 'preprepare' ,
51
+ 'prepare' ,
52
+ 'postprepare' ,
53
+ ]
54
+ for ( const event of scripts ) {
55
+ await runScript ( {
56
+ path : where ,
57
+ args : [ ] ,
58
+ scriptShell,
59
+ stdio : 'inherit' ,
60
+ stdioString : true ,
61
+ event,
62
+ } )
63
63
}
64
- reifyOutput ( arb )
65
- cb ( )
66
- } catch ( er ) {
67
- cb ( er )
68
64
}
65
+ await reifyFinish ( arb )
69
66
}
70
67
71
68
const usage = usageUtil (
@@ -144,4 +141,4 @@ const completion = async (opts, cb) => {
144
141
cb ( )
145
142
}
146
143
147
- module . exports = Object . assign ( install , { usage, completion } )
144
+ module . exports = Object . assign ( cmd , { usage, completion } )
0 commit comments