volta-cli / volta

Volta: JS Toolchains as Code. ⚡
https://volta.sh
Other
11.15k stars 238 forks source link

How can I verify Volta hooks.json is valid? #1918

Closed ivestszheng closed 3 weeks ago

ivestszheng commented 3 weeks ago

Here's my hooks.json in global.

{
    "node": {
        "index": {
            "template": "https://cdn.npmmirror.com/binaries/node/index.json"
        },
        "distro": {
            "template": "https://registry.npmmirror.com/-/binary/node/v{{version}}/{{filename}}"
        }
    },
    "npm": {
        "index": {
            "prefix": "https://registry.npmmirror.com/npm/"
        },
        "latest": {
            "bin": "~/npm-latest"
        },
        "distro": {
            "template": "https://registry.npmmirror.com/npm/npm-{{version}}.tgz"
        }
    },
    "yarn": {
        "index": {
            "template": "https://registry.npmmirror.com/yarn/{{os}}/{{arch}}/yarn-{{version}}.tgz"
        },
        "latest": {
            "prefix": "https://registry.npmmirror.com/yarnpkg/"
        },
        "distro": {
            "bin": "~/yarn-distro"
        }
    }
}

When I use npm config get registry ,output is still https://registry.npmjs.org/. It seems not to work. How can I verify Volta hooks.json is valid?

Is it supposed to output https://registry.npmmirror.com/ ?

ivestszheng commented 3 weeks ago

Is "npm" only set to download itselt not registry? It seems when I want to change npm registry I still need to use 'npm config set registry' .

rwjblue commented 3 weeks ago

Yes, the hooks.json is specifically about fetching node, npm, yarn, &c themselves. It does not change the behaviors of the individual tools on how to actually fetch individual packages from a customized location. In order to do both things, you would usually use hooks.json along with an .npmrc or .yarnrc.yml.

For example, you might use the following .npmrc:

registry=https://custom.registry.com/
//custom.registry.com/:_authToken=YOUR_AUTH_TOKEN

Or the following .yarnrc.yml:

npmRegistryServer: "https://custom.registry.com/"
npmAuthToken: "YOUR_AUTH_TOKEN"

The docs for the hooks.json are here (source code here), if you have the time we'd love a PR updating the docs so that it makes things clearer here.