npx will cause a package to be downloaded and execute bin scripts provided by that package. The command npx prettier will cause the latest version of the prettier to be downloaded and the file ./bin/prettier.js will be executed.
npx also allows you specify which specific semantic version you want to download with the @ notation. So npx prettier runs latest, but npx prettier@2 will still run only version 2 even when prettier updates to a new major version.
See npx package docs:
npx [options] <command>[@version] [command-arg]...
and
-p, --package <package>- define the package to be installed. This defaults to the value of<command>. This is only needed for packages with multiple binaries if you want to call one of the other executables, or where the binary name does not match the package name. If this option is provided<command>will be executed as-is, without interpreting @version if it's there. Multiple--packageoptions may be provided, and all the packages specified will be installed.
A somewhat deeper look at your question makes things a little bit weirder though. I'm unsure why you get different results when you run both commands, they should be equivalent (right now at least since 2 is the current major version).
Try printing the version string with both and see if you get a difference, that might show some additional details
npx prettier --version
npx prettier@2 --version
Both give me the same string, but that might be different depending on your cache or config.
Answer from zero298 on Stack OverflowVideos
» npm install @6river/prettier-config
» npm install @rocketmakers/prettier-config
For *.ts files:
npx prettier 'src/**/*.ts' --write
If you want target other file extensions:
npx prettier 'src/**/*.{js,ts,mjs,cjs,json}' --write
To exclude files from formatting, create a .prettierignore file at the root of your project.
And to format only the *.ts files you should ignore everything but the *.ts files.
Example
# Ignore everything recursively
*
# But not the .ts files
!*.ts
# Check subdirectories too
!*/
In the code above, the * means to ignore everything including the subfolders, and the next line !*.ts tells the prettier to reverse the previous ignoring of the .ts files. The last line !*/ means to check the subdirectories too, but with the previous rule, it's only looking for the .ts files.
Check the prettier and gitignore docs for more information.
» npm install eslint-config-prettier