File tree 3 files changed +91
-20
lines changed
3 files changed +91
-20
lines changed Original file line number Diff line number Diff line change @@ -21,7 +21,7 @@ const ci = async () => {
21
21
}
22
22
23
23
const where = npm . prefix
24
- const { scriptShell } = npm . flatOptions
24
+ const { scriptShell, ignoreScripts } = npm . flatOptions
25
25
const arb = new Arborist ( { ...npm . flatOptions , path : where } )
26
26
27
27
await Promise . all ( [
@@ -39,24 +39,26 @@ const ci = async () => {
39
39
await arb . reify ( { ...npm . flatOptions , save : false } )
40
40
41
41
// run the same set of scripts that `npm install` runs.
42
- const scripts = [
43
- 'preinstall' ,
44
- 'install' ,
45
- 'postinstall' ,
46
- 'prepublish' , // XXX should we remove this finally??
47
- 'preprepare' ,
48
- 'prepare' ,
49
- 'postprepare' ,
50
- ]
51
- for ( const event of scripts ) {
52
- await runScript ( {
53
- path : where ,
54
- args : [ ] ,
55
- scriptShell,
56
- stdio : 'inherit' ,
57
- stdioString : true ,
58
- event,
59
- } )
42
+ if ( ! ignoreScripts ) {
43
+ const scripts = [
44
+ 'preinstall' ,
45
+ 'install' ,
46
+ 'postinstall' ,
47
+ 'prepublish' , // XXX should we remove this finally??
48
+ 'preprepare' ,
49
+ 'prepare' ,
50
+ 'postprepare' ,
51
+ ]
52
+ for ( const event of scripts ) {
53
+ await runScript ( {
54
+ path : where ,
55
+ args : [ ] ,
56
+ scriptShell,
57
+ stdio : 'inherit' ,
58
+ stdioString : true ,
59
+ event,
60
+ } )
61
+ }
60
62
}
61
63
await reifyFinish ( arb )
62
64
}
Original file line number Diff line number Diff line change @@ -6,6 +6,41 @@ const { test } = require('tap')
6
6
7
7
const requireInject = require ( 'require-inject' )
8
8
9
+ test ( 'should ignore scripts with --ignore-scripts' , ( t ) => {
10
+ const SCRIPTS = [ ]
11
+ let REIFY_CALLED = false
12
+ const ci = requireInject ( '../../lib/ci.js' , {
13
+ '../../lib/utils/reify-finish.js' : async ( ) => { } ,
14
+ '../../lib/npm.js' : {
15
+ globalDir : 'path/to/node_modules/' ,
16
+ prefix : 'foo' ,
17
+ flatOptions : {
18
+ global : false ,
19
+ ignoreScripts : true
20
+ } ,
21
+ config : {
22
+ get : ( ) => false ,
23
+ } ,
24
+ } ,
25
+ '@npmcli/run-script' : ( { event } ) => {
26
+ SCRIPTS . push ( event )
27
+ } ,
28
+ '@npmcli/arborist' : function ( ) {
29
+ this . loadVirtual = async ( ) => { }
30
+ this . reify = ( ) => {
31
+ REIFY_CALLED = true
32
+ }
33
+ } ,
34
+ } )
35
+ ci ( [ ] , er => {
36
+ if ( er )
37
+ throw er
38
+ t . equal ( REIFY_CALLED , true , 'called reify' )
39
+ t . strictSame ( SCRIPTS , [ ] , 'no scripts when running ci' )
40
+ t . end ( )
41
+ } )
42
+ } )
43
+
9
44
test ( 'should use Arborist and run-script' , ( t ) => {
10
45
const scripts = [
11
46
'preinstall' ,
Original file line number Diff line number Diff line change @@ -72,14 +72,48 @@ test('should install using Arborist', (t) => {
72
72
t . end ( )
73
73
} )
74
74
75
+ test ( 'should ignore scripts with --ignore-scripts' , ( t ) => {
76
+ const SCRIPTS = [ ]
77
+ let REIFY_CALLED = false
78
+ const install = requireInject ( '../../lib/install.js' , {
79
+ '../../lib/utils/reify-finish.js' : async ( ) => { } ,
80
+ '../../lib/npm.js' : {
81
+ globalDir : 'path/to/node_modules/' ,
82
+ prefix : 'foo' ,
83
+ flatOptions : {
84
+ global : false ,
85
+ ignoreScripts : true
86
+ } ,
87
+ config : {
88
+ get : ( ) => false ,
89
+ } ,
90
+ } ,
91
+ '@npmcli/run-script' : ( { event } ) => {
92
+ SCRIPTS . push ( event )
93
+ } ,
94
+ '@npmcli/arborist' : function ( ) {
95
+ this . reify = ( ) => {
96
+ REIFY_CALLED = true
97
+ }
98
+ } ,
99
+ } )
100
+ install ( [ ] , er => {
101
+ if ( er )
102
+ throw er
103
+ t . equal ( REIFY_CALLED , true , 'called reify' )
104
+ t . strictSame ( SCRIPTS , [ ] , 'no scripts when adding dep' )
105
+ t . end ( )
106
+ } )
107
+ } )
108
+
75
109
test ( 'should install globally using Arborist' , ( t ) => {
76
110
const install = requireInject ( '../../lib/install.js' , {
77
111
'../../lib/utils/reify-finish.js' : async ( ) => { } ,
78
112
'../../lib/npm.js' : {
79
113
globalDir : 'path/to/node_modules/' ,
80
114
prefix : 'foo' ,
81
115
flatOptions : {
82
- global : ' true' ,
116
+ global : true ,
83
117
} ,
84
118
config : {
85
119
get : ( ) => false ,
You can’t perform that action at this time.
0 commit comments