vercel / hyper

A terminal built on web technologies
https://hyper.is
MIT License
43.27k stars 3.52k forks source link

.npmrc shell expansion variables fail #3805

Open sporkd opened 5 years ago

sporkd commented 5 years ago

Issue

One nice feature of .npmrc is the ability to add shell expansion variables. So for instance you can do something like:

~/.npmrc

registry = https://my.custom.registry.com/npm
_auth = ${REGISTRY_AUTH_TOKEN}

Where _auth will get evaluated to whatever env variable you set for REGISTRY_AUTH_TOKEN (can verify by running yarn config list).

This works fine when you start hyper from the command line because it preserves your env variables. However, when clicking on the Hyper.app icon, your shell env variables are not brought in, and plugin installation will fail with something like:

Trace: 
  Error: Failed to replace env in config: ${REGISTRY_AUTH_TOKEN}
      at value.replace (/Applications/Hyper.app/Contents/Resources/bin/yarn-standalone.js:90318:13)
      at String.replace (<anonymous>)
      at envReplace (/Applications/Hyper.app/Contents/Resources/bin/yarn-standalone.js:90313:16)
      at Function.normalizeConfig (/Applications/Hyper.app/Contents/Resources/bin/yarn-standalone.js:30313:69)
      at /Applications/Hyper.app/Contents/Resources/bin/yarn-standalone.js:30335:36
      at Generator.next (<anonymous>)
      at step (/Applications/Hyper.app/Contents/Resources/bin/yarn-standalone.js:98:30)
      at /Applications/Hyper.app/Contents/Resources/bin/yarn-standalone.js:109:13

The problem occurs in yarn-standalone.js when it tries to substitute the value for an env variable that is not found.

yarn-standalone.js:90318

if (undefined === env[envVarName]) {
  throw new Error('Failed to replace env in config: ' + match);
}

Ideally, the correct shell env would be passed in when clicking on Hyper.app. But alternatively we might not need to throw an error when an env variable is missing because this kind of ~/.npmrc customization is not relevant to hyper starting up. Or perhaps there is not even a need to parse ~/.npmrc (unless people are publishing custom plugins to private registries or proxying).

But at the very least, it seems yarn-standalone.js should continue with plugin install if an env variable can't be found, instead of throwing an error.

There are a few other issues I found related to ~/.npmrc, but nothing related to shell expansion:

sporkd commented 5 years ago

Bump😉 . I would say the desired behavior is for the shell ENV variables loaded in your default shell to always be supplied to hyper so it can correctly process your ~/.npmrc. This should happen even if you click on the hyper icon, because the intent when doing so is to fire up a terminal and load the config files for your default shell (bash, zsh, etc). Thoughts?