From 21eaf6b71e253a13e5a3b08723f64063623566c3 Mon Sep 17 00:00:00 2001 From: ayu <54145886+ayu-exorcist@users.noreply.github.com> Date: Thu, 4 Jul 2024 23:17:56 +0800 Subject: [PATCH 1/2] Compatibility: npm, yarn and pnpm run scripts Fix: https://github.com/bcomnes/npm-run-all2/pull/143 --- lib/index.js | 25 +++++++++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-) diff --git a/lib/index.js b/lib/index.js index c35c034..e3324de 100644 --- a/lib/index.js +++ b/lib/index.js @@ -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 = pattern.match(ARGS_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) => pattern.match(ARGS_PATTERN)) return hasPlaceholder ? applyArguments(patterns, args) : patterns } From beb1e8a529c9b91d3ebc015c33d6421842bd9cce Mon Sep 17 00:00:00 2001 From: ayu <54145886+ayu-exorcist@users.noreply.github.com> Date: Fri, 5 Jul 2024 14:01:24 +0800 Subject: [PATCH 2/2] Fix test case in test\argument-placeholders.js --- lib/index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/index.js b/lib/index.js index e3324de..0d23e07 100644 --- a/lib/index.js +++ b/lib/index.js @@ -127,7 +127,7 @@ function parsePatterns (patternOrPatterns, args) { const patternList = pattern.split(' ') const doubleDashIndex = patternList.findIndex((item) => item === '--') - patternList.splice(doubleDashIndex, 1) + doubleDashIndex !== -1 && patternList.splice(doubleDashIndex, 1) pattern = patternList.join(' ') return pattern