un-ts / toml-tools

A set of tools for working with the Toml configuration file format.
MIT License
73 stars 10 forks source link

`prettier-plugin-toml` does not seem to work using the command line #69

Closed David-Else closed 10 months ago

David-Else commented 1 year ago
npm ls -g
/usr/local/lib
├── prettier-plugin-toml@1.0.0
├── prettier@3.0.2
$ node --version
v18.13.0
$ npm --version
9.2.0

I have Prettier and prettier-plugin-toml installed globally.

I try:

prettier --write testconfig.toml

and get:

[error] No parser could be inferred for file "/home/david/Downloads/testconfig.toml".

I also try:

prettier --plugin=prettier-plugin-toml testconfig.toml

and get:

[error] Cannot find package 'prettier-plugin-toml' imported from /home/david/Downloads/noop.js

Am I missing something here, or is there a bug? Thanks.

JounQin commented 1 year ago

Maybe a prettier core bug?

David-Else commented 1 year ago

Maybe a prettier core bug?

Seems unlikely, could you give an example of a command that you have used that definitely works?

JounQin commented 1 year ago

Seems unlikely

How do you confirm this? I've never used global installed plugins. Did you tried any other plugin that works?

bruceadams commented 1 year ago

I see the same problem using npx. I cannot use the 1.0.0 release of prettier-plugin-toml. The 0.4.0 release works fine. (I'm using npx here outside of any JavaScript project.)

% npx --package=prettier-plugin-toml@1.0.0 prettier --tab-width 4 --write pyproject.toml
[error] No parser could be inferred for file "/Users/bruce/clo/triple-settlement-rewards-network/pyproject.toml".
% npx --package=prettier-plugin-toml@0.4.0 prettier --tab-width 4 --write pyproject.toml
pyproject.toml 7ms
kassiansun commented 1 year ago

I see the same problem using npx. I cannot use the 1.0.0 release of prettier-plugin-toml. The 0.4.0 release works fine. (I'm using npx here outside of any JavaScript project.)

% npx --package=prettier-plugin-toml@1.0.0 prettier --tab-width 4 --write pyproject.toml
[error] No parser could be inferred for file "/Users/bruce/clo/triple-settlement-rewards-network/pyproject.toml".
% npx --package=prettier-plugin-toml@0.4.0 prettier --tab-width 4 --write pyproject.toml
pyproject.toml 7ms

Thanks a lot for this reply, I finally find a way to run prettier-plugin-toml with npx and vim autocmd

Tatsh commented 1 year ago

Newest version of Prettier seems to need plugins set. Seems to no longer auto-load them. Either with --plugin=NAME or in configuration:

 "plugins": ["prettier-plugin-ini", "prettier-plugin-toml"]

https://prettier.io/docs/en/plugins

bruceadams commented 1 year ago

@Tatsh Thanks for the pointer to the Prettier documentation about plugins! Unfortunately, Prettier's --plugin option doesn't seem to work with npx 😢

% npx --package=prettier-plugin-toml prettier --plugin=prettier-plugin-toml --tab-width 4 --write pyproject.toml
[error] Cannot find package 'prettier-plugin-toml' imported from /Users/bruce/sample-pythoni/noop.js
bruceadams commented 1 year ago

The workaround in this comment on a Prettier issue works with npx 🎉.

% npx prettier-pnp --pn toml --tab-width 4 --write pyproject.toml

----- Already installed ----

 - prettier-plugin-toml

----- Running prettier -----

pyproject.toml 5ms
Tatsh commented 1 year ago

With a global install the full path to the main export must be given (.exports['.'] in package.json):

prettier --plugin=${HOME}/somewhere/node_modules/prettier-plugin-toml/lib/api.js a.toml

This can be made easier by using a global config.

JounQin commented 10 months ago

So it's really a prettier core issue, I'll close this issue for now, if you still confirm it's related to this plugin instead, please raise a new issue with reproduction, thanks all.