Skip to content

Conversation

HowieHz
Copy link
Contributor

@HowieHz HowieHz commented Apr 6, 2024

这个pr修复了不可用的prettier脚本(在vscode下测试)

Copy link
Owner

@guqing guqing left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

你的修改貌似不正确,正确的命令就是需要使用单引号包裹路径 pattern 的,请参考 https://prettier.io/docs/en/cli

@HowieHz
Copy link
Contributor Author

HowieHz commented Apr 15, 2024

你的修改貌似不正确,正确的命令就是需要使用单引号包裹路径 pattern 的,请参考 https://prettier.io/docs/en/cli

那这可能是我环境独有的问题
不知道是否能复现 windows10 最新vscode x64
image
image

@guqing
Copy link
Owner

guqing commented Apr 16, 2024

那这可能是我环境独有的问题 不知道是否能复现 windows10 最新vscode x64

估计是windows 上路径和通配符的不同,我在 mac 和 linux 执行都是没有问题的但对于你的修改则无法正确执行,你可以尝试使用 git bash shell 打开执行试试或者使用 wsl

@HowieHz
Copy link
Contributor Author

HowieHz commented Apr 16, 2024

git bash shell

@guqing

image
bash环境下也无法工作
cmd和powershell7也测试了,同样无法运行

我在单独的终端中测试了,显然这不是vsc的问题
image

但是如果是powershell7直接执行pnpm prettier --write './src/**/*.{js,ts,css,json,ml,yaml,html}' './templates/**/*.html',反倒可以运行
image
image
。cmd运行上面的指令一样无法运行,会产生一样的error
image

在上面的多张错误消息里可以发现[error]提示消息中的路径,在单引号外面错误的被添加了第二层双引号,

[error] No files matching the pattern were found: "'./src/**/*.{js,ts,css,json,ml,yaml,html}'".
[error] No files matching the pattern were found: "'./templates/**/*.html'".

这应该就是问题的原因,我想也就是我把引号删掉的原因

之前删掉引号的方式的确有点蠢,经过短暂的思考我想到了两种解决方法
第一种是外层用单引号,内层用双引号,但是这是不合法的
image

第二种是不用单引号全用双引号,但是需要转义\
prettier --write \"./src/**/*.{js,ts,css,json,ml,yaml,html}\" \"./templates/**/*.html\"
image

我想这可能就是解决方法了
或者有其他方法,但是我目前学业紧张,周末的时候可能可以进行进一步的检索

这个commit修复了不可用的prettier脚本(在windows下测试)
@HowieHz
Copy link
Contributor Author

HowieHz commented Apr 16, 2024

那这可能是我环境独有的问题 不知道是否能复现 windows10 最新vscode x64

估计是windows 上路径和通配符的不同,我在 mac 和 linux 执行都是没有问题的但对于你的修改则无法正确执行,你可以尝试使用 git bash shell 打开执行试试或者使用 wsl

image
https://prettier.io/docs/en/watching-files

另外我在官方文档中发现在watching-files这一章发现官方对于这种通配路径也是使用转义后的双引号而不是单引号

Copy link
Owner

@guqing guqing left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这样确实可以,感谢贡献👍

@guqing guqing merged commit f3e6b52 into guqing:main Apr 18, 2024
@guqing guqing changed the title chore: fix package.json chore: unavailable prettier task config Apr 18, 2024
guqing added a commit that referenced this pull request Apr 18, 2024
@HowieHz HowieHz deleted the patch-1 branch April 18, 2024 11:32
f2c-ci-robot bot pushed a commit to halo-dev/theme-earth that referenced this pull request Aug 22, 2024
这个pr修复了不可用的 prettier 脚本
顺便跑了一遍 prettier
guqing/halo-theme-higan#91 (comment)

```release-note
None
```
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

Successfully merging this pull request may close these issues.

2 participants