Skip to content

Commit

Permalink
Compatibility: npm, yarn and pnpm run scripts
Browse files Browse the repository at this point in the history
  • Loading branch information
ayu-exorcist committed Jul 3, 2024
1 parent 25738ae commit b8d3ded
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)

Check failure

Code scanning / CodeQL

Polynomial regular expression used on uncontrolled data High

This
regular expression
that depends on
library input
may run slow on strings starting with '{{%' and with many repetitions of '00'.

if (!match) {
return pattern
}

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

return pattern

Check warning on line 133 in lib/index.js

View check run for this annotation

Codecov / codecov/patch

lib/index.js#L127-L133

Added lines #L127 - L133 were not covered by tests
})
}

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

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

0 comments on commit b8d3ded

Please sign in to comment.