mixu/gluejs

Don't assume environment variables exist

uipoet opened this issue · 5 comments

Our deployments started failing after upgrading from version 2.0.

Turns out this was because our environment did not define HOME during deployment.

var homePath = process.env[(process.platform == 'win32') ? 'USERPROFILE' : 'HOME'];

Probably best to use a more reliable path in Linux for the default.

This environment variable is only intended as a sane default for the cache-path. You can override this variable via the command line:

$ gluejs --cache-path /home/jibsales

Or you can do it programmatically:

var glue = require('gluejs');
glue.set('cache-path', '/home/jibsales');

Tried that. The way the code is written, if HOME doesn't exist, path.normalize method fails that the object doesn't exist. This happened even when we tried disabling cache or manually defining cache-path. We use Glue.js programmatically.

Ahhhh – yes, I see now. Quick fix in the code would be:

var homePath = process.env[(process.platform == 'win32') ? 'USERPROFILE' : 'HOME'];
homePath = path.normalize(homePath);

...

  this.options = {
    replaced: {},
    remap: {},
    cache: true,
    'cache-path': homePath + path.sep + '.gluejs-cache' + path.sep
  };
mixu commented

awesome @JibSales, thanks for looking into this. I'll merge this now and test / release it tomorrow.

Thanks for the speedy responses. We are excited to gain the performance bump of late as we continue rolling with Glue.js in production.