Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,7 @@ function applyArguments (patterns, args) {

const unfoldedPatterns = patterns
.flatMap(pattern => {
const match = ARGS_UNPACK_PATTERN.exec(pattern)
if (match && match[2] === '%') {
if (pattern.search(ARGS_UNPACK_PATTERN) !== -1) {
const result = []
for (let i = 0, length = args.length; i < length; i++) {
const argPosition = i + 1
Expand Down Expand Up @@ -153,7 +152,7 @@ function applyArguments (patterns, args) {
*/
function parsePatterns (patternOrPatterns, args) {
const patterns = toArray(patternOrPatterns)
const hasPlaceholder = patterns.some(pattern => ARGS_PATTERN.test(pattern))
const hasPlaceholder = patterns.some(pattern => pattern.search(ARGS_PATTERN) !== -1)

return hasPlaceholder ? applyArguments(patterns, args) : patterns
}
Expand Down
47 changes: 47 additions & 0 deletions test/argument-placeholders.js
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,53 @@ describe('[argument-placeholders]', () => {
})
})

describe("'{%}' should skip every command when there are no arguments:", () => {
test('Node API', async () => {
const tasks = await nodeApi(['test-task:dump {%}', 'test-task:dump {%}'])
strictEqual(tasks, null)
strictEqual(result(), null)
})

test('npm-run-all command', async () => {
await runAll(['test-task:dump {%}', 'test-task:dump {%}', '--'])
strictEqual(result(), null)
})

test('run-s command', async () => {
await runSeq(['test-task:dump {%}', 'test-task:dump {%}', '--'])
strictEqual(result(), null)
})

test('run-p command', async () => {
await runPar(['test-task:dump {%}', 'test-task:dump {%}', '--'])
strictEqual(result(), null)
})

test('repeated Node API calls', async () => {
strictEqual(await nodeApi('test-task:dump {%}'), null)
strictEqual(await nodeApi('test-task:dump {%}'), null)
strictEqual(result(), null)
})

test('Node API call followed by a positional placeholder', async () => {
await nodeApi('test-task:dump {%}')
await nodeApi('test-task:dump {1}', { arguments: ['1st'] })
strictEqual(result(), '["1st"]')
})

test('Node API call followed by arguments to unfold', async () => {
await nodeApi('test-task:dump {%}')
await nodeApi('test-task:dump {%}', { arguments: ['1st', '2nd'] })
strictEqual(result(), '["1st"]["2nd"]')
})

test('Node API call followed by mixed placeholders', async () => {
await nodeApi('test-task:dump {%}')
await nodeApi('test-task:dump {%} {1}', { arguments: ['1st', '2nd'] })
strictEqual(result(), '["1st","1st"]["2nd","1st"]')
})
})

describe("Every '{1}', '{2}', '{@}' and '{*}' should be replaced by the arguments preceded by '--':", () => {
test('Node API', async () => {
await nodeApi('test-task:dump {1} {2} {3} {@} {*}', { arguments: ['1st', '2nd'] })
Expand Down