11import chalk from "chalk"
22import process from "process"
3- import minimist from "minimist "
3+ import dashdash from "dashdash "
44
55import { getAppRootPath } from "./getAppRootPath"
66import { join } from "./path"
77
88const 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
2227
2328console . log (
2429 chalk . bold ( "patch-package" ) ,
@@ -27,8 +32,8 @@ console.log(
2732)
2833
2934// 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
3237
3338if ( isDebug ) {
3439 console . log ( `patch-package/index: argv:` )
@@ -43,12 +48,12 @@ import { normalize, sep } from "path"
4348import slash = require( "slash" )
4449import isCi from "is-ci"
4550
46- if ( argv . version || argv . v ) {
51+ if ( argv . version ) {
4752 // noop
48- } else if ( argv . help || argv . h ) {
53+ } else if ( argv . help ) {
4954 printHelp ( )
5055} else {
51- const patchDir = slash ( normalize ( ( argv [ "patch-dir" ] || "patches" ) + sep ) )
56+ const patchDir = slash ( normalize ( ( argv . patch_dir || "patches" ) + sep ) )
5257 if ( patchDir . startsWith ( "/" ) ) {
5358 throw new Error ( "--patch-dir must be a relative path" )
5459 }
@@ -57,19 +62,19 @@ if (argv.version || argv.v) {
5762 argv . include ,
5863 "include" ,
5964 / .* / ,
60- argv [ "case-sensitive-path-filtering" ] ,
65+ argv . case_sensitive_path_filtering ,
6166 )
6267 const excludePaths = makeRegExp (
6368 argv . exclude ,
6469 "exclude" ,
6570 / p a c k a g e \. j s o n $ / ,
66- argv [ "case-sensitive-path-filtering" ] ,
71+ argv . case_sensitive_path_filtering ,
6772 )
6873 const packageManager = detectPackageManager (
6974 appPath ,
70- argv [ "use-yarn" ] ? "yarn" : null ,
75+ argv . use_yarn ? "yarn" : null ,
7176 )
72- const createIssue = argv [ "create-issue" ]
77+ const createIssue = argv . create_issue
7378 packageNames . forEach ( ( packagePathSpecifier : string ) => {
7479 makePatch ( {
7580 packagePathSpecifier,
@@ -83,11 +88,11 @@ if (argv.version || argv.v) {
8388 } )
8489 } else {
8590 console . log ( "Applying patches..." )
86- const reverse = ! ! argv [ " reverse" ]
91+ const reverse = argv . reverse
8792 // don't want to exit(1) on postinsall locally.
8893 // see https://github.com/ds300/patch-package/issues/86
8994 const shouldExitWithError =
90- ! ! argv [ "error-on-fail" ] || isCi || process . env . NODE_ENV === "test"
95+ argv . error_on_fail || isCi || process . env . NODE_ENV === "test"
9196 applyPatchesForApp ( { appPath, reverse, patchDir, shouldExitWithError } )
9297 }
9398}
0 commit comments