keithamus / sort-package-json

Sort an Object or package.json based on the well-known package.json keys
MIT License
790 stars 83 forks source link

feat: don’t sort scripts when `npm-run-all2` is installed #309

Closed kachkaev closed 7 months ago

kachkaev commented 7 months ago

Closes https://github.com/keithamus/sort-package-json/issues/308. Context: https://github.com/keithamus/sort-package-json/pull/232

github-actions[bot] commented 7 months ago

:tada: This PR is included in version 2.7.0 :tada:

The release is available on:

Your semantic-release bot :package::rocket:

bcomnes commented 7 months ago

You can also add numerics to your script names to force a specific sort order while retaining the ability to alphanumeric sort. IMO this is preferable than adding tool specific behaviors.

viceice commented 7 months ago

You can also add numerics to your script names to force a specific sort order while retaining the ability to alphanumeric sort. IMO this is preferable than adding tool specific behaviors.

doesn't work for postinstall. I would expect to have scripts sorted alphanumeric, but postinstall was sorted before lint. 🤔

benquarmby commented 6 months ago

If I wanted to control the order of execution with a tool like npm-run-all2, why the flerking shnit wouldn't I be explicit about it?:

{
-    "do": "run-s do:*"
+    "do": "run-s do:clean do:build do:translate do:version do:publish"
}

Relying on a magic * and the arbitrary order of scripts is fragile.

Excuse the rant, but I'm frustrated that I can no longer use npm-run-all2 as an escape hatch from this silly "skip sorting scripts when npm-run-all is installed" behavior. Scripts should always be sorted! This behavior is promoting bad practice.

bcomnes commented 6 months ago

I generally agree that disabling behavior automatically as a side effect of other tools being detected is an odd design choice. If order of execution matters in your npm-run-all scripts, you should add numerics to your scripts to guarantee order, even when external tools run stylistic sorts on them. This approach lets you keep your top level script short, but still define explicit order. If no such sorting is ever going to occur, you don't need to do this.

{
"do": "run-s do:*"
"do:01-clean": "clean"
"do:02-build": "build"
"do:03-translate": "translate"
"do:04-version": "version"
"do:05-publish": "publish"
}