Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Compatibility: npm, yarn and pnpm run scripts #144

Closed
wants to merge 2 commits into from
Closed
Changes from 1 commit
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
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 @@
* @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 = pattern.match(ARGS_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) => pattern.match(ARGS_PATTERN))

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