rejectUnauthorized.js 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. var pkg = require('../../package.json');
  2. /**
  3. * Get the value of a CLI argument
  4. *
  5. * @param {String} name
  6. * @param {Array} args
  7. * @api private
  8. */
  9. function getArgument(name, args) {
  10. var flags = args || process.argv.slice(2),
  11. index = flags.lastIndexOf(name);
  12. if (index === -1 || index + 1 >= flags.length) {
  13. return null;
  14. }
  15. return flags[index + 1];
  16. }
  17. /**
  18. * Get the value of reject-unauthorized
  19. * If environment variable SASS_REJECT_UNAUTHORIZED is non-zero,
  20. * .npmrc variable sass_reject_unauthorized or
  21. * process argument --sass-reject_unauthorized is provided,
  22. * set rejectUnauthorized to true
  23. * Else set to false by default
  24. *
  25. * @return {Boolean} The value of rejectUnauthorized
  26. * @api private
  27. */
  28. module.exports = function() {
  29. var rejectUnauthorized = false;
  30. if (getArgument('--sass-reject-unauthorized')) {
  31. rejectUnauthorized = getArgument('--sass-reject-unauthorized');
  32. } else if (process.env.SASS_REJECT_UNAUTHORIZED !== '0') {
  33. rejectUnauthorized = true;
  34. } else if (process.env.npm_config_sass_reject_unauthorized) {
  35. rejectUnauthorized = process.env.npm_config_sass_reject_unauthorized;
  36. } else if (pkg.nodeSassConfig && pkg.nodeSassConfig.rejectUnauthorized) {
  37. rejectUnauthorized = pkg.nodeSassConfig.rejectUnauthorized;
  38. }
  39. return rejectUnauthorized;
  40. };