File tree 2 files changed +11
-6
lines changed
2 files changed +11
-6
lines changed Original file line number Diff line number Diff line change @@ -12,8 +12,7 @@ const chosenPM = process.argv[2];
12
12
if ( lockFiles . hasOwnProperty ( chosenPM ) ) {
13
13
const allowedLock = lockFiles [ chosenPM ] ;
14
14
const forbiddenLocks = Object . values ( lockFiles ) . filter ( ( lock ) => lock !== allowedLock ) ;
15
- const stagedFiles = git ( [ 'diff' , '--name-only' , '--cached' ] ) . stdout . split ( '\n' ) ;
16
- stagedFiles . pop ( ) ;
15
+ const stagedFiles = git ( [ 'diff' , '--name-only' , '--cached' ] ) . stdout . trim ( ) . split ( '\n' ) ;
17
16
for ( let lock of forbiddenLocks ) {
18
17
if ( stagedFiles . indexOf ( lock ) !== - 1 ) {
19
18
git ( [ 'rm' , '-f' , lock ] ) ;
@@ -28,3 +27,6 @@ if (lockFiles.hasOwnProperty(chosenPM)) {
28
27
}
29
28
}
30
29
}
30
+ else {
31
+ throw new Error ( `"${ chosenPM } " is not supported by enforcepm.\n\tFor a list of supported package managers, visit https://github.com/DaviDevMod/enforcepm#usage` ) ;
32
+ }
Original file line number Diff line number Diff line change 1
1
#!/usr/bin/env node
2
2
import cp = require ( 'child_process' ) ;
3
3
4
- // A map of package managers and relative lock files supported by enforcepm
4
+ // An hash table of the lock files of the supported package managers
5
5
const lockFiles = {
6
6
npm : 'package-lock.json' ,
7
7
yarn : 'yarn.lock' ,
@@ -18,12 +18,11 @@ if (lockFiles.hasOwnProperty(chosenPM)) {
18
18
19
19
const forbiddenLocks = Object . values ( lockFiles ) . filter ( ( lock ) => lock !== allowedLock ) ;
20
20
21
- const stagedFiles = git ( [ 'diff' , '--name-only' , '--cached' ] ) . stdout . split ( '\n' ) ;
22
- stagedFiles . pop ( ) ; // pop trailing empty string
21
+ const stagedFiles = git ( [ 'diff' , '--name-only' , '--cached' ] ) . stdout . trim ( ) . split ( '\n' ) ;
23
22
24
23
for ( let lock of forbiddenLocks ) {
25
24
if ( stagedFiles . indexOf ( lock ) !== - 1 ) {
26
- // Remove the staged forbidden lock file
25
+ // Remove the forbidden lock file
27
26
git ( [ 'rm' , '-f' , lock ] ) ;
28
27
29
28
// Notify
@@ -37,4 +36,8 @@ if (lockFiles.hasOwnProperty(chosenPM)) {
37
36
console . log ( blue , '\t\t~ enforcepm ~' , resetColor ) ;
38
37
}
39
38
}
39
+ } else {
40
+ throw new Error (
41
+ `"${ chosenPM } " is not supported by enforcepm.\n\tFor a list of supported package managers, visit https://github.com/DaviDevMod/enforcepm#usage`
42
+ ) ;
40
43
}
You can’t perform that action at this time.
0 commit comments