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

Setting up prettier-package-json #23

Closed
tomdavidson opened this issue Mar 11, 2023 · 7 comments
Closed

Setting up prettier-package-json #23

tomdavidson opened this issue Mar 11, 2023 · 7 comments

Comments

@tomdavidson
Copy link

Version: 0.34.5

I'm running prettier-package-json with the exec plugin. The associated files are formatted just fine but dprint exits with the error:

The original file text was greater than 100 characters, but the formatted text was empty. Perhaps dprint-plugin-exec has been misconfigured?

Entire config file attached, but heres exec:

  "exec": {
    "associations": [
      "**/*.{sh,bash}",
      "**/package.json"
    ],
    "prettier-package-json.associations": "**/package.json",
    "prettier-package-json": "node_modules/.bin/prettier-package-json --write",
}

Got something wrong with the config or a bug?

dprint.json.txt

@dsherret dsherret transferred this issue from dprint/dprint Mar 11, 2023
@dsherret
Copy link
Member

dsherret commented Mar 11, 2023

That’s to prevent you from accidentally overwriting all your files to empty files due to misconfiguration.

I’m just on my phone, but I think you need to set the stdin option to false. I don’t see a way to get that CLI to output its formatting to stdout (maybe there is a way and that’s preferred over this):

Side note: this config is too verbose. I opened #24 now that it’s possible

@dsherret
Copy link
Member

Oh wait, I think I did that wrong. I’ll go over to my computer

@dsherret
Copy link
Member

dsherret commented Mar 11, 2023

Ok, this is what you're going to want to do (don't use the --write flag):

// EDIT: THIS IS WRONG. SEE BELOW FOR CORRECT ANSWER
"exec": {
    "associations": [
      "**/*.{sh,bash}",
      "**/package.json"
    ],
    "prettier-package-json.associations": "**/package.json",
    "prettier-package-json": "node_modules/.bin/prettier-package-json"
  },

I just tested it out and it works for me.

@tomdavidson
Copy link
Author

tomdavidson commented Mar 11, 2023

Thanks for looking at this right away. With out the --write flag I experience some weirdness. So much so, that I did a screen grab. The workspace package.json gets replaced with the content of the root level package.json. Same when I turn off stdin. Note that some of my term history shows errors from trying older versions of exec, but this recording uses 0.3.5.

dprint-exec-prettier-packagejson-vodoo

@tomdavidson
Copy link
Author

If I use pretty-package-json which supports stdin/out, things work as they should.

@dsherret
Copy link
Member

Oh, I guess the plugin is not reading stdin. Providing the filepath seems to work and you can just ignore providing stdin since the plugin doesn't use it (I just checked its sourcecode):

"exec": {
    "associations": [
      "**/*.{sh,bash}",
      "**/package.json"
    ],
    "prettier-package-json.associations": "**/package.json",
    "prettier-package-json": "node_modules/.bin/prettier-package-json {{file_path}}",
    "prettier-package-json.stdin": false
  },

Sorry, getting the config setup sometimes can be tricky, but afterwards it's not so bad

@tomdavidson
Copy link
Author

Sorry, getting the config setup sometimes can be tricky, but afterwards it's not so bad

No complaints here. I love it. Just stumbled (forgot all about {{file_path}} and stdin: false) and thank you for your help!

@dsherret dsherret changed the title Error formatting - false positive Setting up prettier-package-json Mar 11, 2023
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

2 participants