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

Another bug wrt sort pre/post scripts with colon together #332

Open
rfalke-rtl opened this issue Jan 20, 2025 · 5 comments
Open

Another bug wrt sort pre/post scripts with colon together #332

rfalke-rtl opened this issue Jan 20, 2025 · 5 comments

Comments

@rfalke-rtl
Copy link

Similar to #307

Sorted input with extra blank lines for clarification:

  "scripts": {
    "test": "echo",
    "test:coverage": "echo",

    "pretest:es-check": "echo",
    "test:es-check": "echo",
    "posttest:es-check": "echo",

    "test:types": "echo"
  },

Output with npx [email protected]:

  "scripts": {
    "pretest:es-check": "echo",
    "test": "echo",
    "test:coverage": "echo",
    "test:es-check": "echo",
    "test:types": "echo",
    "posttest:es-check": "echo"
  }
@rfalke-rtl rfalke-rtl changed the title Another sort pre/post scripts with colon together Another bug wrt sort pre/post scripts with colon together Jan 20, 2025
@keithamus
Copy link
Owner

PRs welcome!

@rfalke-rtl
Copy link
Author

After looking into this further is shows that 2.12.0 works as I would expect it. The change of #330 changed the behavior.

The question is what is the correct/intended behavior. I think the expected order in

{
  "scripts": {
    "prebuild": "run-s prebuild:*",
    "prebuild:1": "node prebuild.js 1",
    "prebuild:2": "node prebuild.js 2",
    "prebuild:3": "node prebuild.js 3",
    "build": "run-s build:*",
    "build:bar": "node bar.js",
    "build:baz": "node baz.js",
    "build:foo": "node foo.js",
    "postbuild": "run-s prebuild:*",
    "postbuild:1": "node prebuild.js 1",
    "postbuild:2": "node prebuild.js 2",
    "postbuild:3": "node prebuild.js 3",
    "d-unrelated": "..",
    "e-unrelated": "..",
    "f-unrelated": "..",
  }
}

is quite special and a generic tool like sort-package-json should support the common case (see my expectations from above) out of the box.

rfalke-rtl added a commit to rfalke-rtl/sort-package-json that referenced this issue Jan 21, 2025
@rfalke-rtl
Copy link
Author

Ok than I propose #333 to revert the recent changes.

@keithamus
Copy link
Owner

@chouchouji thoughts?

@chouchouji
Copy link
Contributor

@chouchouji thoughts?

I check the issue and pr. The result of sorting pre/post scripts you expected is quite different with #307. I am not sure that which is better? Maybe we can take a discussion.

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

No branches or pull requests

3 participants