PrimeIntellect/SWE-rebench-V2 huggingface dataset:
Repository: keithamus/sort-package-json (js)

Issue:
bug: scripts are getting sorted, even with run-s included
In https://github.com/keithamus/sort-package-json/commit/9f1101b0dc82276c0b72052bac2117ae570b5be4 there was a change that now sorts scripts.

We are using npm-run-all2 and a run-s inside a script but not at the start

https://github.com/prettier/plugin-pug/blob/25329d1968f7aad2a9793f1ffe6658cd9f35518a/package.json#L19

however there is even a script with run-s at the start https://github.com/prettier/plugin-pug/blob/25329d1968f7aad2a9793f1ffe6658cd9f35518a/package.json#L9

and it still sorts them as it wants

is there an option I can set to disable script sorting?

Pull request:
fix: prevent sorting when npm-run-all2 is used
Add support for npm-run-all2 to prevent script sorting when sequential wildcard execution is needed.

Closes #359

Patch:
diff --git a/index.js b/index.js
index 86057ab..44a214f 100755
--- a/index.js
+++ b/index.js
@@ -223,13 +223,16 @@ const hasDevDependency = (dependency, packageJson) => {
 }
 
 const runSRegExp =
-  /(?<=^|[\s&;<>|(])(?:run-s|npm-run-all .*(?:--sequential|--serial|-s))(?=$|[\s&;<>|)])/
+  /(?<=^|[\s&;<>|(])(?:run-s|npm-run-all2? .*(?:--sequential|--serial|-s))(?=$|[\s&;<>|)])/
 
 const isSequentialScript = (command) =>
   command.includes('*') && runSRegExp.test(command)
 
 const hasSequentialScript = (packageJson) => {
-  if (!hasDevDependency('npm-run-all', packageJson)) {
+  if (
+    !hasDevDependency('npm-run-all', packageJson) &&
+    !hasDevDependency('npm-run-all2', packageJson)
+  ) {
     return false
   }
   const scripts = ['scripts', 'betterScripts'].flatMap((field) =>


Test patch:
diff --git a/tests/scripts.js b/tests/scripts.js
index bc6b210..183731d 100644
--- a/tests/scripts.js
+++ b/tests/scripts.js
@@ -67,6 +67,15 @@ function sortScriptsWithNpmRunAll(script) {
 
   return Object.keys(sortPackageJson(packageJson).scripts)
 }
+function sortScriptsWithNpmRunAll2(script) {
+  const packageJson = {
+    scripts: { z: 'z', a: 'a', maybeRunS: script },
+    devDependencies: { 'npm-run-all2': '^1.0.0' },
+  }
+
+  return Object.keys(sortPackageJson(packageJson).scripts)
+}
+
 const sortedScripts = ['a', 'maybeRunS', 'z']
 const unsortedScripts = ['z', 'a', 'maybeRunS']
 for (const { script, expected } of [
@@ -108,6 +117,10 @@ for (const { script, expected } of [
   test(`command: '${script}'`, (t) => {
     t.deepEqual(sortScriptsWithNpmRunAll(script), expected)
   })
+
+  test(`command: '${script}' with npm-run-all2`, (t) => {
+    t.deepEqual(sortScriptsWithNpmRunAll2(script), expected)
+  })
 }
 
 for (const field of ['scripts', 'betterScripts']) {
@@ -127,6 +140,16 @@ for (const field of ['scripts', 'betterScripts']) {
   })
 }
 
+// npm-run-all2
+for (const { script, expected } of [
+  // Should NOT sort
+  { script: 'npm-run-all2 -s "lint:*"', expected: unsortedScripts },
+]) {
+  test(`command: '${script}' with npm-run-all2`, (t) => {
+    t.deepEqual(sortScriptsWithNpmRunAll2(script), expected)
+  })
+}
+
 for (const field of ['scripts', 'betterScripts']) {
   test(
     `${field} does not sort pre/post scripts with colon together`,