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

CLI behaves differently on Windows (doesn't work) than on Linux #4086

Closed
sandrosc opened this issue Mar 1, 2018 · 9 comments
Closed

CLI behaves differently on Windows (doesn't work) than on Linux #4086

sandrosc opened this issue Mar 1, 2018 · 9 comments
Labels
area:cli Issues with Prettier's Command Line Interface locked-due-to-inactivity Please open a new issue and fill out the template instead of commenting. type:bug Issues identifying ugly output, or a defect in the program

Comments

@sandrosc
Copy link

sandrosc commented Mar 1, 2018

A friend and I found this bug when the prettier command worked on his Mac, but not on my Windows laptop.

If I use the Linux subsystem for Windows prettier works:

C:\git\core>yarn lint
yarn run v1.3.2
$ prettier 'lib/**/*.ts' 'spec/**/*.js' --write && tslint -c tslint.json 'lib/**/*.ts'
[error] No matching files. Patterns tried: 'lib/**/*.ts' 'spec/**/*.js' !**/node_modules/** !./node_modules/**
error Command failed with exit code 2.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.

C:\git\core>bash
sandro@R:/mnt/c/git/core$ yarn lint
yarn run v1.3.2
$ prettier 'lib/**/*.ts' 'spec/**/*.js' --write && tslint -c tslint.json 'lib/**/*.ts'
lib/blackbox/getRandomValues.ts 594ms
[...]
Done in 4.20s.
sandro@R:/mnt/c/git/core$
@j-f1 j-f1 added type:bug Issues identifying ugly output, or a defect in the program area:cli Issues with Prettier's Command Line Interface labels Mar 1, 2018
@j-f1
Copy link
Member

j-f1 commented Mar 1, 2018

Does running

C:\git\core>prettier 'lib\**\*.ts' 'spec\**\*.js' --write

work for you?

@j-f1 j-f1 added the status:awaiting response Issues that require answers to questions from maintainers before action can be taken label Mar 1, 2018
@alexander-akait
Copy link
Member

alexander-akait commented Mar 1, 2018

@j-f1
!**/node_modules/** !./node_modules/**

Without quotes?

@j-f1
Copy link
Member

j-f1 commented Mar 1, 2018

I think those are the built-in ignores. It doesn’t matter that they’re not quoted since they aren’t parsed by the shell AFAIK.

@sandrosc
Copy link
Author

sandrosc commented Mar 1, 2018

@j-f1 no, following output:

C:\git\tichu-core>yarn lint
yarn run v1.3.2
$ prettier 'lib\**\*.ts' 'spec\**\*.js' --write && tslint -c tslint.json 'lib/**/*.ts'
[error] No matching files. Patterns tried: 'lib\**\*.ts' 'spec\**\*.js' !**/node_modules/** !./node_modules/**
error Command failed with exit code 2.

edit for clarity, tried the command directly instead of editing the package.json:

C:\git\tichu-core>prettier 'lib\**\*.ts' 'spec\**\*.js' --write
No matching files. Patterns tried: 'lib\**\*.ts' 'spec\**\*.js' !**/node_modules/** !./node_modules/**

@no-response no-response bot removed the status:awaiting response Issues that require answers to questions from maintainers before action can be taken label Mar 1, 2018
@MarkTiedemann
Copy link

MarkTiedemann commented Mar 4, 2018

Single quotes don't identify strings in Windows cmd.exe.

A common mistake is git commit -m 'Initial commit', which will be interpreted as two words: "'initial" and "commit'", thus ruining your commit message in this example.

So, to make prettier work on Windows and Unix systems well, just use double quotes. :)

You must escape the double quotes in your package.json script, however:

{
  "scripts": {
  ‎  "format": "prettier --write \"lib/**/*.ts\""
  }
}

Hope this helps!

@sandrosc
Copy link
Author

sandrosc commented Mar 6, 2018

Thank you very much, @MarkTiedemann!
Replacing ' with \" indeed solved my problem.

@j-f1
Copy link
Member

j-f1 commented Mar 6, 2018

@sandrosc Can we close this then?

@sandrosc
Copy link
Author

sandrosc commented Mar 6, 2018

Perhaps this would be worth documenting over at https://prettier.io/docs/en/cli.html?

@j-f1 j-f1 added status:awaiting response Issues that require answers to questions from maintainers before action can be taken and removed status:awaiting response Issues that require answers to questions from maintainers before action can be taken labels Mar 6, 2018
@sandrosc
Copy link
Author

sandrosc commented Mar 6, 2018

@j-f1 yes, this issue can be closed. Thanks for the help!

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area:cli Issues with Prettier's Command Line Interface locked-due-to-inactivity Please open a new issue and fill out the template instead of commenting. type:bug Issues identifying ugly output, or a defect in the program
Projects
None yet
Development

No branches or pull requests

4 participants