1
1
import chalk from "chalk"
2
2
import process from "process"
3
- import minimist from "minimist "
3
+ import dashdash from "dashdash "
4
4
5
5
import { getAppRootPath } from "./getAppRootPath"
6
6
import { join } from "./path"
7
7
8
8
const appPath = getAppRootPath ( )
9
- const argv = minimist ( process . argv . slice ( 2 ) , {
10
- boolean : [
11
- "use-yarn" ,
12
- "case-sensitive-path-filtering" ,
13
- "reverse" ,
14
- "help" ,
15
- "version" ,
16
- "error-on-fail" ,
17
- "create-issue" ,
18
- ] ,
19
- string : [ "patch-dir" ] ,
20
- } )
21
- const packageNames = argv . _
9
+
10
+ var dashdashOptions = [
11
+ { name : "use-yarn" , type : "bool" } ,
12
+ { name : "case-sensitive-path-filtering" , type : "bool" } ,
13
+ { name : "reverse" , type : "bool" } ,
14
+ { names : [ "help" , "h" ] , type : "bool" } ,
15
+ { names : [ "version" , "v" ] , type : "bool" } ,
16
+ { name : "error-on-fail" , type : "bool" } ,
17
+ { name : "verbose" , type : "bool" } ,
18
+ { name : "debug" , type : "bool" } ,
19
+ { name : "patch-dir" , type : "string" } ,
20
+ { name : "include" , type : "string" } ,
21
+ { name : "exclude" , type : "string" } ,
22
+ ] ;
23
+
24
+ const argv = dashdash . parse ( { options : dashdashOptions } ) ;
25
+
26
+ const packageNames = argv . _args
22
27
23
28
console . log (
24
29
chalk . bold ( "patch-package" ) ,
@@ -27,8 +32,8 @@ console.log(
27
32
)
28
33
29
34
// used in imported modules
30
- const isDebug = ( global . patchPackageIsDebug = Boolean ( argv . debug ) )
31
- global . patchPackageIsVerbose = isDebug || Boolean ( argv . verbose )
35
+ const isDebug = global . patchPackageIsDebug = argv . debug
36
+ global . patchPackageIsVerbose = isDebug || argv . verbose
32
37
33
38
if ( isDebug ) {
34
39
console . log ( `patch-package/index: argv:` )
@@ -43,12 +48,12 @@ import { normalize, sep } from "path"
43
48
import slash = require( "slash" )
44
49
import isCi from "is-ci"
45
50
46
- if ( argv . version || argv . v ) {
51
+ if ( argv . version ) {
47
52
// noop
48
- } else if ( argv . help || argv . h ) {
53
+ } else if ( argv . help ) {
49
54
printHelp ( )
50
55
} else {
51
- const patchDir = slash ( normalize ( ( argv [ "patch-dir" ] || "patches" ) + sep ) )
56
+ const patchDir = slash ( normalize ( ( argv . patch_dir || "patches" ) + sep ) )
52
57
if ( patchDir . startsWith ( "/" ) ) {
53
58
throw new Error ( "--patch-dir must be a relative path" )
54
59
}
@@ -57,19 +62,19 @@ if (argv.version || argv.v) {
57
62
argv . include ,
58
63
"include" ,
59
64
/ .* / ,
60
- argv [ "case-sensitive-path-filtering" ] ,
65
+ argv . case_sensitive_path_filtering ,
61
66
)
62
67
const excludePaths = makeRegExp (
63
68
argv . exclude ,
64
69
"exclude" ,
65
70
/ p a c k a g e \. j s o n $ / ,
66
- argv [ "case-sensitive-path-filtering" ] ,
71
+ argv . case_sensitive_path_filtering ,
67
72
)
68
73
const packageManager = detectPackageManager (
69
74
appPath ,
70
- argv [ "use-yarn" ] ? "yarn" : null ,
75
+ argv . use_yarn ? "yarn" : null ,
71
76
)
72
- const createIssue = argv [ "create-issue" ]
77
+ const createIssue = argv . create_issue
73
78
packageNames . forEach ( ( packagePathSpecifier : string ) => {
74
79
makePatch ( {
75
80
packagePathSpecifier,
@@ -83,11 +88,11 @@ if (argv.version || argv.v) {
83
88
} )
84
89
} else {
85
90
console . log ( "Applying patches..." )
86
- const reverse = ! ! argv [ " reverse" ]
91
+ const reverse = argv . reverse
87
92
// don't want to exit(1) on postinsall locally.
88
93
// see https://github.com/ds300/patch-package/issues/86
89
94
const shouldExitWithError =
90
- ! ! argv [ "error-on-fail" ] || isCi || process . env . NODE_ENV === "test"
95
+ argv . error_on_fail || isCi || process . env . NODE_ENV === "test"
91
96
applyPatchesForApp ( { appPath, reverse, patchDir, shouldExitWithError } )
92
97
}
93
98
}
0 commit comments