Skip to content

Commit 6dbc1fe

Browse files
committed
Merge branch 'pr/50'
2 parents 13f86dc + ea5a6bb commit 6dbc1fe

File tree

2 files changed

+16
-16
lines changed

2 files changed

+16
-16
lines changed

src/lib/index.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ function toArray(x) {
4444
* @returns {string[]} replaced
4545
*/
4646
function applyArguments(patterns, args) {
47-
return patterns.map(pattern => pattern.replace(ARGS_PATTERN, (match, index) => {
47+
return patterns.map(pattern => pattern.replace(ARGS_PATTERN, (unused, index) => {
4848
if (index === "@") {
4949
return shellQuote.quote(args)
5050
}
@@ -57,7 +57,7 @@ function applyArguments(patterns, args) {
5757
return shellQuote.quote([args[position - 1]])
5858
}
5959

60-
return match
60+
return ""
6161
}))
6262
}
6363

@@ -72,9 +72,9 @@ function applyArguments(patterns, args) {
7272
*/
7373
function parsePatterns(patternOrPatterns, args) {
7474
const patterns = toArray(patternOrPatterns)
75-
const hasArguments = Array.isArray(args) && args.length > 0
75+
const hasPlaceholder = patterns.some(pattern => ARGS_PATTERN.test(pattern))
7676

77-
return hasArguments ? applyArguments(patterns, args) : patterns
77+
return hasPlaceholder ? applyArguments(patterns, args) : patterns
7878
}
7979

8080
/**

test/argument-placeholders.js

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -28,40 +28,40 @@ describe("[argument-placeholders]", () => {
2828

2929
beforeEach(removeResult)
3030

31-
describe("If arguments preceded by '--' are nothing, '{1}' should be as is:", () => {
31+
describe("If arguments preceded by '--' are nothing, '{1}' should be empty:", () => {
3232
it("Node API", () =>
3333
nodeApi("test-task:dump {1}")
34-
.then(() => assert(result() === "[\"{1}\"]"))
34+
.then(() => assert(result() === "[]"))
3535
)
3636

3737
it("npm-run-all command", () =>
3838
runAll(["test-task:dump {1}"])
39-
.then(() => assert(result() === "[\"{1}\"]"))
39+
.then(() => assert(result() === "[]"))
4040
)
4141

4242
it("npm-run-all command (only '--' exists)", () =>
4343
runAll(["test-task:dump {1}", "--"])
44-
.then(() => assert(result() === "[\"{1}\"]"))
44+
.then(() => assert(result() === "[]"))
4545
)
4646

4747
it("run-s command", () =>
4848
runSeq(["test-task:dump {1}"])
49-
.then(() => assert(result() === "[\"{1}\"]"))
49+
.then(() => assert(result() === "[]"))
5050
)
5151

5252
it("run-s command (only '--' exists)", () =>
5353
runSeq(["test-task:dump {1}", "--"])
54-
.then(() => assert(result() === "[\"{1}\"]"))
54+
.then(() => assert(result() === "[]"))
5555
)
5656

5757
it("run-p command", () =>
5858
runPar(["test-task:dump {1}"])
59-
.then(() => assert(result() === "[\"{1}\"]"))
59+
.then(() => assert(result() === "[]"))
6060
)
6161

6262
it("run-p command (only '--' exists)", () =>
6363
runPar(["test-task:dump {1}", "--"])
64-
.then(() => assert(result() === "[\"{1}\"]"))
64+
.then(() => assert(result() === "[]"))
6565
)
6666
})
6767

@@ -156,22 +156,22 @@ describe("[argument-placeholders]", () => {
156156
describe("Every '{1}', '{2}', '{@}' and '{*}' should be replaced by the arguments preceded by '--':", () => {
157157
it("Node API", () =>
158158
nodeApi("test-task:dump {1} {2} {3} {@} {*}", {arguments: ["1st", "2nd"]})
159-
.then(() => assert(result() === "[\"1st\",\"2nd\",\"{3}\",\"1st\",\"2nd\",\"1st 2nd\"]"))
159+
.then(() => assert(result() === "[\"1st\",\"2nd\",\"1st\",\"2nd\",\"1st 2nd\"]"))
160160
)
161161

162162
it("npm-run-all command", () =>
163163
runAll(["test-task:dump {1} {2} {3} {@} {*}", "--", "1st", "2nd"])
164-
.then(() => assert(result() === "[\"1st\",\"2nd\",\"{3}\",\"1st\",\"2nd\",\"1st 2nd\"]"))
164+
.then(() => assert(result() === "[\"1st\",\"2nd\",\"1st\",\"2nd\",\"1st 2nd\"]"))
165165
)
166166

167167
it("run-s command", () =>
168168
runSeq(["test-task:dump {1} {2} {3} {@} {*}", "--", "1st", "2nd"])
169-
.then(() => assert(result() === "[\"1st\",\"2nd\",\"{3}\",\"1st\",\"2nd\",\"1st 2nd\"]"))
169+
.then(() => assert(result() === "[\"1st\",\"2nd\",\"1st\",\"2nd\",\"1st 2nd\"]"))
170170
)
171171

172172
it("run-p command", () =>
173173
runPar(["test-task:dump {1} {2} {3} {@} {*}", "--", "1st", "2nd"])
174-
.then(() => assert(result() === "[\"1st\",\"2nd\",\"{3}\",\"1st\",\"2nd\",\"1st 2nd\"]"))
174+
.then(() => assert(result() === "[\"1st\",\"2nd\",\"1st\",\"2nd\",\"1st 2nd\"]"))
175175
)
176176
})
177177
})

0 commit comments

Comments
 (0)