Skip to content

Commit bf8e1e7

Browse files
committed
replace minimist with dashdash argv parser
1 parent eaf6538 commit bf8e1e7

File tree

2 files changed

+32
-27
lines changed

2 files changed

+32
-27
lines changed

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,6 @@
5454
"@types/fs-extra": "^5.0.5",
5555
"@types/is-ci": "^1.1.0",
5656
"@types/jest": "^24.0.11",
57-
"@types/minimist": "^1.2.0",
5857
"@types/node": "^11.11.6",
5958
"@types/rimraf": "^2.0.2",
6059
"@types/semver": "^5.5.0",
@@ -72,14 +71,15 @@
7271
"typescript": "^4.2.2"
7372
},
7473
"dependencies": {
74+
"@types/dashdash": "^1.14.0",
7575
"@yarnpkg/lockfile": "^1.1.0",
7676
"chalk": "^2.4.2",
7777
"cross-spawn": "^6.0.5",
78+
"dashdash": "^2.0.0",
7879
"find-yarn-workspace-root": "^2.0.0",
7980
"fs-extra": "^7.0.1",
8081
"is-ci": "^2.0.0",
8182
"klaw-sync": "^6.0.0",
82-
"minimist": "^1.2.0",
8383
"open": "^7.4.2",
8484
"rimraf": "^2.6.3",
8585
"semver": "^5.6.0",

src/index.ts

Lines changed: 30 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,29 @@
11
import chalk from "chalk"
22
import process from "process"
3-
import minimist from "minimist"
3+
import dashdash from "dashdash"
44

55
import { getAppRootPath } from "./getAppRootPath"
66
import { join } from "./path"
77

88
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
2227

2328
console.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

3338
if (isDebug) {
3439
console.log(`patch-package/index: argv:`)
@@ -43,12 +48,12 @@ import { normalize, sep } from "path"
4348
import slash = require("slash")
4449
import 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
/package\.json$/,
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

Comments
 (0)