This repository was archived by the owner on Aug 18, 2024. It is now read-only.
File tree Expand file tree Collapse file tree 6 files changed +45
-8
lines changed Expand file tree Collapse file tree 6 files changed +45
-8
lines changed Original file line number Diff line number Diff line change @@ -134,6 +134,7 @@ exports.run = async (options) => {
134
134
135
135
if ( allowScripts [ name ] === false ) {
136
136
console . warn ( `==========> skip ${ path } (because it is not allowed in package.json)` ) ;
137
+ return false ;
137
138
}
138
139
139
140
if ( allowScripts [ name ] === true ) {
Original file line number Diff line number Diff line change 7
7
"url" : " https://github.com/dominykas/allow-scripts.git"
8
8
},
9
9
"scripts" : {
10
- "test" : " lab -L -t 78 -m 5000"
10
+ "test" : " lab -L -t 80 -m 5000"
11
11
},
12
12
"bin" : {
13
13
"allow-scripts" : " ./bin/allow-scripts.js"
Original file line number Diff line number Diff line change
1
+ {
2
+ "private" : true ,
3
+ "name" : " @example/allowed-false" ,
4
+ "version" : " 0.0.0" ,
5
+ "dependencies" : {
6
+ "@example/with-install-script" : " *" ,
7
+ "@example/with-postinstall-script" : " *" ,
8
+ "@example/without-scripts" : " *"
9
+ },
10
+ "allowScripts" : {
11
+ "@example/with-install-script" : false ,
12
+ "@example/with-postinstall-script" : " *"
13
+ }
14
+ }
Original file line number Diff line number Diff line change 12
12
"allowScripts" : {
13
13
"@example/with-preinstall-script" : " *" ,
14
14
"@example/with-install-script" : " *" ,
15
- "@example/with-postinstall-script" : " * "
15
+ "@example/with-postinstall-script" : true
16
16
},
17
17
"scripts" : {
18
18
"preinstall" : " echo preinstall from basic >> ${OUTPUT}" ,
Original file line number Diff line number Diff line change @@ -5,6 +5,7 @@ const Fs = require('fs');
5
5
const Mkdirp = require ( 'mkdirp' ) ;
6
6
const Path = require ( 'path' ) ;
7
7
const Rimraf = require ( 'rimraf' ) ;
8
+ const Sinon = require ( 'sinon' ) ;
8
9
9
10
10
11
const internals = {
@@ -43,6 +44,16 @@ exports.setup = (main, deps) => {
43
44
process . env . OUTPUT = originalOutput ;
44
45
} ) ;
45
46
47
+ const log = [ ] ;
48
+ const appendLog = ( ...items ) => {
49
+
50
+ log . push ( items . map ( ( i ) => i || '' ) . join ( ' ' ) . replace ( new RegExp ( cwd , 'g' ) , '.' ) ) ;
51
+ } ;
52
+
53
+ Sinon . stub ( console , 'info' ) . callsFake ( appendLog ) ;
54
+ Sinon . stub ( console , 'log' ) . callsFake ( appendLog ) ;
55
+ Sinon . stub ( console , 'warn' ) . callsFake ( appendLog ) ;
56
+
46
57
return {
47
58
getExpectedResult : ( ) => {
48
59
@@ -55,7 +66,7 @@ exports.setup = (main, deps) => {
55
66
56
67
getLog : ( ) => {
57
68
58
- return console . log . args . map ( ( args ) => args [ 0 ] || '' ) . join ( '\n' ) . replace ( new RegExp ( cwd , 'g' ) , '. ') . trim ( ) ;
69
+ return log . join ( '\n' ) . trim ( ) ;
59
70
}
60
71
} ;
61
72
} ;
@@ -64,4 +75,5 @@ exports.restore = () => {
64
75
65
76
internals . restore . forEach ( ( restore ) => restore ( ) ) ;
66
77
internals . restore = [ ] ;
78
+ Sinon . restore ( ) ;
67
79
} ;
Original file line number Diff line number Diff line change 1
1
'use strict' ;
2
2
3
3
const Fixtures = require ( './fixtures' ) ;
4
- const Sinon = require ( 'sinon' ) ;
5
4
6
5
7
6
const Allow = require ( '..' ) ;
@@ -17,15 +16,12 @@ describe('allow-scripts', () => {
17
16
let cwd ;
18
17
beforeEach ( ( ) => {
19
18
20
- Sinon . stub ( console , 'log' ) ;
21
- Sinon . stub ( console , 'info' ) ;
22
19
cwd = process . cwd ( ) ;
23
20
} ) ;
24
21
25
22
afterEach ( ( ) => {
26
23
27
24
Fixtures . restore ( ) ;
28
- Sinon . restore ( ) ;
29
25
process . chdir ( cwd ) ;
30
26
} ) ;
31
27
@@ -56,9 +52,23 @@ describe('allow-scripts', () => {
56
52
57
53
await expect ( Allow . run ( { } ) ) . to . reject ( 'No entry for @example/with-install-script' ) ;
58
54
59
- expect ( fixture . getActualResult ( ) ) . not . to . contain ( 'with-postinstall-script' ) ;
60
55
expect ( fixture . getActualResult ( ) ) . to . equal ( '' ) ;
61
56
expect ( fixture . getLog ( ) ) . to . equal ( '' ) ;
62
57
} ) ;
58
+
59
+ it ( 'skips scripts which are forbidden' , async ( ) => {
60
+
61
+ const fixture = Fixtures . setup ( 'allowed-false' , [
62
+ 'with-install-script' ,
63
+ 'with-postinstall-script' ,
64
+ 'without-scripts'
65
+ ] ) ;
66
+
67
+ await Allow . run ( { } ) ;
68
+
69
+ expect ( fixture . getActualResult ( ) ) . not . to . contain ( 'with-install-script' ) ;
70
+ expect ( fixture . getActualResult ( ) ) . to . equal ( 'postinstall from with-postinstall-script' ) ;
71
+ expect ( fixture . getLog ( ) ) . to . contain ( 'skip node_modules/@example/with-install-script (because it is not allowed in package.json)' ) ;
72
+ } ) ;
63
73
} ) ;
64
74
} ) ;
You can’t perform that action at this time.
0 commit comments