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

postinstall incompatible with Windows #212

Closed
binki opened this issue Jul 14, 2017 · 2 comments · Fixed by opencomponents/base-templates#128
Closed

postinstall incompatible with Windows #212

binki opened this issue Jul 14, 2017 · 2 comments · Fixed by opencomponents/base-templates#128

Comments

@binki
Copy link
Contributor

binki commented Jul 14, 2017

C:\Users\ohnob\repos\lint-staged-play>npm install -S lint-staged

> [email protected] postinstall C:\Users\ohnob\repos\lint-staged-play\node_modules\lint-staged
> echo "🚫💩 lint-staged installed!
Do not forget to configure it. See https://github.com/okonet/lint-staged/blob/master/README.md" && exit 0

"🚫💩 lint-staged installed!
[email protected] C:\Users\ohnob\repos\lint-staged-play
`-- [email protected]
  +-- [email protected]
  +-- [email protected]
  | +-- [email protected]
  | +-- [email protected]
  | | +-- [email protected]
  | | | `-- [email protected]
  | | `-- [email protected]
  | +-- [email protected]
  | +-- [email protected]
  | +-- [email protected]
  | +-- [email protected]
  | | `-- [email protected]
  | |   `-- [email protected]
  | +-- [email protected]
  | | `-- [email protected]
  | `-- [email protected]
  +-- [email protected]
  | +-- [email protected]
  | | +-- [email protected]
  | | | +-- [email protected]
  | | | `-- [email protected]
  | | `-- [email protected]
  | |   `-- [email protected]
  | +-- [email protected]
  | +-- [email protected]
  | +-- [email protected]
  | | `-- [email protected]
  | +-- [email protected]
  | +-- [email protected]
  | `-- [email protected]
  +-- [email protected]
  | +-- [email protected]
  | | +-- [email protected]
  | | +-- [email protected]
  | | +-- [email protected]
  | | `-- [email protected]
  | +-- [email protected]
  | | +-- [email protected]
  | | `-- [email protected]
  | |   +-- [email protected]
  | |   `-- [email protected]
  | |     `-- [email protected]
  | +-- [email protected]
  | +-- [email protected]
  | | `-- [email protected]
  | |   `-- [email protected]
  | +-- [email protected]
  | +-- [email protected]
  | +-- [email protected]
  | | +-- [email protected]
  | | `-- [email protected]
  | +-- [email protected]
  | | +-- [email protected]
  | | | `-- [email protected]
  | | |   +-- [email protected]
  | | |   `-- [email protected]
  | | `-- [email protected]
  | +-- [email protected]
  | +-- [email protected]
  | | `-- [email protected]
  | +-- [email protected]
  | | `-- [email protected]
  | +-- [email protected]
  | | `-- [email protected]
  | +-- [email protected]
  | `-- [email protected]
  |   `-- [email protected]
  +-- [email protected]
  +-- [email protected]
  | `-- [email protected]
  |   +-- [email protected]
  |   `-- [email protected]
  +-- [email protected]
  | +-- [email protected]
  | +-- [email protected]
  | `-- [email protected]
  |   `-- [email protected]
  +-- [email protected]
  `-- [email protected]

npm WARN [email protected] No description
npm WARN [email protected] No repository field.

C:\Users\ohnob\repos\lint-staged-play>

As you can see, cmd’s ECHO does not treat " as a string delimiter in the same way that sh does. As a result, the " is printed in the output and only the first line is displayed.

Additionally, && exit 0 seems redundant.

If you want to use an echo that behaves consistently cross-platform, should either remove the double-quotes and use two echo commands:

{
  "postinstall": "echo 🚫💩 lint-staged installed! && echo Do not forget to configure it. See https://github.com/okonet/lint-staged/blob/master/README.md"
}
ohnobinki@gibby ~/lint-staged-play $ uname -s
Linux
ohnobinki@gibby ~/lint-staged-play $ npm run postinstall

> [email protected] postinstall /home/ohnobinki/lint-staged-play
> echo 🚫💩 lint-staged installed! && echo Do not forget to configure it. See https://github.com/okonet/lint-staged/blob/master/README.md

🚫💩 lint-staged installed!
Do not forget to configure it. See https://github.com/okonet/lint-staged/blob/master/README.md
C:\Users\ohnob\repos\lint-staged-play>\msys64\usr\bin\uname.exe -s
MSYS_NT-10.0

C:\Users\ohnob\repos\lint-staged-play>npm run postinstall

> [email protected] postinstall C:\Users\ohnob\repos\lint-staged-play
> echo 🚫💩 lint-staged installed! && echo Do not forget to configure it. See https://github.com/okonet/lint-staged/blob/master/README.md

🚫💩 lint-staged installed!
Do not forget to configure it. See https://github.com/okonet/lint-staged/blob/master/README.md

or, if you really want to surround the content of your messages in double-quotes, then use shx’s echo (note that single-quotes around arguments do not work on Windows):

{
  "postinstall": "shx echo \"🚫💩 lint-staged installed!\" && shx echo \"Do not forget to configure it. See https://github.com/okonet/lint-staged/blob/master/README.md\""
}
ohnobinki@gibby ~/lint-staged-play $ uname -s
Linux
ohnobinki@gibby ~/lint-staged-play $ npm run postinstall

> [email protected] postinstall /home/ohnobinki/lint-staged-play
> shx echo "🚫💩 lint-staged installed!" && shx echo "Do not forget to configure it. See https://github.com/okonet/lint-staged/blob/master/README.md"

🚫💩 lint-staged installed!
Do not forget to configure it. See https://github.com/okonet/lint-staged/blob/master/README.md
C:\Users\ohnob\repos\lint-staged-play>\msys64\usr\bin\uname.exe -s
MSYS_NT-10.0

C:\Users\ohnob\repos\lint-staged-play>npm run postinstall

> [email protected] postinstall C:\Users\ohnob\repos\lint-staged-play
> shx echo "🚫💩 lint-staged installed!" && shx echo "Do not forget to configure it. See https://github.com/okonet/lint-staged/blob/master/README.md"

🚫💩 lint-staged installed!
Do not forget to configure it. See https://github.com/okonet/lint-staged/blob/master/README.md

Double Quotes Unnecessary/Wrong

You might wonder why the exclamation mark (!) doesn’t cause any problems for sh (unix). That is because ! is only a special character in interactive shells where history expansion is enabled by default. Also, it only causes an error if there is no whitespace after it. So if you use ! that in a terminal, you will get an error. But not in a shellout:

ohnobinki@gibby ~ $ echo "!yo"
bash: !yo: event not found
ohnobinki@gibby ~ $ bash -c 'echo "!yo"'
!yo

Also, double quotes are wrong on Windows because Windows passes the whole command line as a single string. This means that splitting a command’s parameters into separate arguments and globbing is performed by the invoked application. Which in turn means that different commands implement different string splitting/quoting rules. ECHO literally prints everything passed unless if nothing is passed, in which case ECHO is ON or OFF is printed (to print a blank line, you do ECHO. [sic]).

C:\Users\ohnob\repos\lint-staged-play>ECHO "hi"
"hi"

C:\Users\ohnob\repos\lint-staged-play>ECHO hi
hi

C:\Users\ohnob\repos\lint-staged-play>ECHO
ECHO is on.

C:\Users\ohnob\repos\lint-staged-play>ECHO.


C:\Users\ohnob\repos\lint-staged-play>

Postinstall Pointless

Also, one could argue that if a developer installs this package, they could be expected to look up the documentation on how to use it without prompting. Note that postinstall runs even when the user just types npm install, so the postinstall runs even for projects which already are configured or even when it is an indirect dependency. So is there even a point in a postinstall step that prints stuff out like this? Maybe the best change to improve portability of the package by increasing the similarity of install behavior on different platforms would be to just remove the postinstall script.

binki added a commit to binki/lint-staged that referenced this issue Jul 14, 2017
@okonet
Copy link
Collaborator

okonet commented Jul 17, 2017

Wow that's a detailed bug report. I wish all issues were like this one 💯

okonet pushed a commit that referenced this issue Jul 17, 2017
@binki
Copy link
Contributor Author

binki commented Jul 17, 2017

Wow that's a detailed bug report. I wish all issues were like this one 💯

It kind of was a rant, sorry xD. Thanks for accepting the simple solution.

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