Skip to content

Commit

Permalink
Merge pull request #143 from ayu-exorcist/master
Browse files Browse the repository at this point in the history
Compatibility: npm, yarn and pnpm run scripts
  • Loading branch information
bcomnes authored Jul 3, 2024
2 parents 25738ae + b8d3ded commit 32a4b46
Showing 1 changed file with 23 additions and 2 deletions.
25 changes: 23 additions & 2 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -112,8 +112,29 @@ function applyArguments (patterns, args) {
* @returns {string[]} Parsed patterns.
*/
function parsePatterns (patternOrPatterns, args) {
const patterns = toArray(patternOrPatterns)
const hasPlaceholder = patterns.some(pattern => ARGS_PATTERN.test(pattern))
let patterns = toArray(patternOrPatterns)

const isNPM = process.env.npm_config_user_agent && process.env.npm_config_user_agent.startsWith('npm')

if (!isNPM) {
// yarn | pnpm
patterns = patterns.map((pattern) => {
const match = ARGS_PATTERN.exec(pattern)

if (!match) {
return pattern
}

const patternList = pattern.split(' ')
const doubleDashIndex = patternList.findIndex((item) => item === '--')
patternList.splice(doubleDashIndex, 1)
pattern = patternList.join(' ')

return pattern
})
}

const hasPlaceholder = patterns.some((pattern) => ARGS_PATTERN.test(pattern))

return hasPlaceholder ? applyArguments(patterns, args) : patterns
}
Expand Down

0 comments on commit 32a4b46

Please sign in to comment.