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

Option to ignore scripts or specific pattern #237

Open
muuvmuuv opened this issue Nov 23, 2021 · 5 comments
Open

Option to ignore scripts or specific pattern #237

muuvmuuv opened this issue Nov 23, 2021 · 5 comments

Comments

@muuvmuuv
Copy link

I am sorting my scripts like below to have it more readable as it's become bigger. Also, npm offers a nice list of all commands which work pretty well together with my comments hack. Unfortunately, when sorting my package.json it destroys the hole order. It would be very cool to have an option to ignore scripts (or any other group) or allow specific patterns not be sorted (in that case the hash #) and everything in between if that is even possible ^^.

  "scripts": {
    "dev": "nx serve",
    "==================== BUILD ====================": "",
    "build": "nx build -c development",
    "build-ios": "cross-env BROWSERSLIST_ENV=mobile nx run entergon:cap --cmd='build ios'",
    "build-android": "cross-env BROWSERSLIST_ENV=mobile nx run entergon:cap --cmd='build android'",
    "==================== TESTS ====================": "",
    "test": "nx test",
    "test-all": "nx run-many --target=test --all --exclude=entergon",
    "e2e": "nx e2e entergon-e2e --headless=false --watch",
    "lint": "nx workspace-lint && pnpm lint-all && pnpm lint-all-styles",
    "lint-app": "nx lint --cache && nx lint-styles --cache",
    "lint-all": "nx run-many --target=lint --all",
    "lint-all-styles": "nx run-many --target=lint-styles --all",
    "==================== TOOLS ====================": "",
    "postinstall": "jetifier",
    "preinstall": "npx -y only-allow pnpm",
    "update": "nx migrate latest",
    "generator": "nx workspace-generator",
    "copy-deps": "pnpm generator copy-dependencies",
    "bump": "pnpm generator bump-version",
    "dep-graph": "nx dep-graph"
  },
@jrson83
Copy link

jrson83 commented Jul 2, 2022

As an alternative I'm using https://www.npmjs.com/package/vscode-sort-package-json-without-scripts

@websolutions-hamburg
Copy link

Is there already an update here? Will there be a configuration option for it?

@SrBrahma
Copy link

SrBrahma commented Jan 6, 2024

@keithamus can you take a look? The package is great but I don't want it to scramble my scripts order

@Everettss
Copy link

This is an issue when using running multiple scripts by pnpm https://pnpm.io/cli/run#running-multiple-scripts

 "scripts": {
    "watch": pnpm run /^watch:.*/",
    "watch:b": "some script for b --watch",
    "watch:a": "some script for a --watch"
  },
  

And I want to have defined "watch:a" after ""watch:b" since it influence order of appearance in output in script "watch".

@keithamus
Copy link
Owner

Please take a look at https://github.com/keithamus/sort-package-json?tab=readme-ov-file#i-would-like-this-tool-to-be-configurable-with-a-config-file-or-command-line-arguments

The lack of configuration here is a feature, not a bug. The intent of this tool is that a user can open a package json and always expect to see keys in a particular order. If we add a configuration for this tool, then that promise is broken, as users will first need to look at the configuration for each project to learn the ways in which this tool will change the package.json. The structure of the package.json should always be predictable & deterministic from project to project. I think the reason why this project is well used is because it is not another "tool" you have to set up with yet another JSON file and more cruft in your project to support it. You run a command and it does what it says on the tin.

A lot of people who ask for configuration cite the use case that they simply don't like the given order that exists and want to make sweeping changes. To me this seems far better suited to simply making a fork of this project as then you can go far further than specifying configuration.

If you think the heuristics can be improved, please send a PR to improve the heuristics and we can review it accordingly.

In the case of pnpm, we can do what we already do with npm-run-all, which is opt out of sorting the scripts key if we detect pnpm.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants