Pnpm 用于预提交自定义钩子

huangapple go评论150阅读模式
英文:

Pnpm for pre-commit custom hook

问题

我在一个使用python/svelte全栈应用上工作,我们使用pre-commit。我已经在前端的web目录中安装了stylelint并配置了自定义钩子:

- id: stylelint
  name: stylelint
  additional_dependencies:
    - stylelint
  entry: pnpm run --dir web lint:scss
  files: ^.*\.(css|scss|svelte)$
  language: node
  pass_filenames: false

问题是:我们的web文件夹由pnpm管理,但language: node会使用npm安装依赖,这样钩子不会起作用。

问题是:我如何告诉pre-commit总体使用pnpm并使用pnpm add -D stylelint来安装stylelint

英文:

I work on a python/svelte full-stack app where we use pre-commit. I've installed stylelint to frontend web dir and configured a custom hook for it :

- id: stylelint
        name: stylelint
        additional_dependencies:
          - stylelint
        entry: pnpm run --dir web lint:scss
        files: ^.*\.(css|scss|svelte)$
        language: node
        pass_filenames: false

And the problem is: our web folder is managed by pnpm, but language: node will install dependencies with npm, and hook not gonna work.

The question is: how could I tell to pre-commit to use pnpm overall and install the stylelint with pnpm add -D stylelint?

答案1

得分: 1

pre-commit在管理安装的工具时效果最好 - 否则,您的贡献者将不得不自行设置每个工具并确保版本同步和正确(这是该工具的主要目标之一)

pre-commit还在管理发送给工具的文件时效果最佳 - 这样它可以控制是否发送了正确的文件(特别是在各种工作流程阶段和冲突发生时)

您正在做的事情 应该已经可以工作 - 但是它正在做额外的工作,并且处于不受支持的路径中。这里的额外工作是 language: node - 它正在设置一个Node环境,然后基本上将其丢弃,因为您正在执行 pnpm

您可以使用 repo: local 钩子和 language: system,它只会运行在您的 $PATH 上的工具。请注意,这两者都存在上述问题,并且作为一种不受支持的逃生通道提供,不是正确操作的方式。调整您的配置,您可以移除 additional_dependencies 并相应调整 language

免责声明:我编写了pre-commit

英文:

pre-commit works best when it manages the installed tools -- without that your contributors will have to set up every tool themselves and make sure that versions are synchronized and correct (which is one of the primary goals of the tool)

pre-commit also works best when it manages the files that are sent to tools -- that way it can control whether the correct files are sent or not (especially during the various workflow stages and when conflicts arise)

what you're doing should already work -- however it's doing extra work and is in the unsupported pathway. the extra work here is language: node -- where it is setting up a node environment and then ~essentially discarding it because you're executing pnpm

you can use repo: local hooks with language: system which will just run the tools that are on your $PATH. note that both of these suffer from the issues above and are provided as an unsupported escape hatch from the right way to do things. adjusting your config you'd remove additional_dependencies and adjust language accordingly


disclaimer: I wrote pre-commit

huangapple
  • 本文由 发表于 2023年5月17日 10:51:27
  • 转载请务必保留本文链接:https://go.coder-hub.com/76268277.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定