gpt4 book ai didi

node.js - 当本地没有可用的 Node.js 时,将 Husky 与 Docker 结合使用

转载 作者:行者123 更新时间:2023-12-04 11:32:58 25 4
gpt4 key购买 nike

使用 Docker,当容器中有 Node.js 而本地机器上没有 Node.js 时,我试图让 Husky 工作。

因为它将用 git 命令触发,信息来自 here :“如果您在终端中运行 git 命令,husky 将使用在您的 shell 中定义的版本 PATH”,而这个 other :“如果 ~/.huskyrc 文件在运行钩子(Hook)脚本之前存在,Husky 将获取它的来源。例如,您可以使用它来加载 Node 版本管理器或在钩子(Hook)之前运行一些 shell 命令。”

可以像改变PATH这样的事情吗?所以它指向容器中的 Node.js 是一个解决方案吗?如果是这样,怎么办?

提前致谢!

最佳答案

如果我理解正确的话,我已经分两步解决了这个问题:

  • 通过与 guest 共享来自主机的 git

  • # at docker-compose.yaml
    version: '3'
    services:
    app:
    build:
    ...
    volumes:
    - /usr/bin/git:/usr/bin/git
    # installing dependencies missing at guest (in my case, guest debian, host ubuntu)
    - /lib/x86_64-linux-gnu/libpcre2-8.so.0:/lib/x86_64-linux-gnu/libpcre2-8.so.0

    2.通过在容器内运行hook命令,例如:
    # at .husky/pre-commit

    #!/bin/sh
    . "$(dirname "$0")/_/husky.sh"

    # instead of only npx lint-staged
    docker exec great-app npx lint-staged

    关于node.js - 当本地没有可用的 Node.js 时,将 Husky 与 Docker 结合使用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61015181/

    25 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com