Repositorio del curso CCOM4030 el semestre B91 del proyecto Artesanías con el Instituto de Cultura

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. 'use strict';
  2. const path = require('path');
  3. const os = require('os');
  4. const fs = require('fs');
  5. const ini = require('ini');
  6. const isWindows = process.platform === 'win32';
  7. const readRc = filePath => {
  8. try {
  9. return ini.parse(fs.readFileSync(filePath, 'utf8')).prefix;
  10. } catch (_) {}
  11. };
  12. const getEnvNpmPrefix = () => {
  13. return Object.keys(process.env).reduce((prefix, name) => {
  14. return (/^npm_config_prefix$/i).test(name) ? process.env[name] : prefix;
  15. }, undefined);
  16. };
  17. const getGlobalNpmrc = () => {
  18. if (isWindows && process.env.APPDATA) {
  19. // Hardcoded contents of `c:\Program Files\nodejs\node_modules\npm\npmrc`
  20. return path.join(process.env.APPDATA, '/npm/etc/npmrc');
  21. }
  22. // Homebrew special case: `$(brew --prefix)/lib/node_modules/npm/npmrc`
  23. if (process.execPath.includes('/Cellar/node')) {
  24. const homebrewPrefix = process.execPath.slice(0, process.execPath.indexOf('/Cellar/node'));
  25. return path.join(homebrewPrefix, '/lib/node_modules/npm/npmrc');
  26. }
  27. if (process.execPath.endsWith('/bin/node')) {
  28. const installDir = path.dirname(path.dirname(process.execPath));
  29. return path.join(installDir, '/etc/npmrc');
  30. }
  31. };
  32. const getDefaultNpmPrefix = () => {
  33. if (isWindows) {
  34. // `c:\node\node.exe` → `prefix=c:\node\`
  35. return path.dirname(process.execPath);
  36. }
  37. // `/usr/local/bin/node` → `prefix=/usr/local`
  38. return path.dirname(path.dirname(process.execPath));
  39. };
  40. const getNpmPrefix = () => {
  41. const envPrefix = getEnvNpmPrefix();
  42. if (envPrefix) {
  43. return envPrefix;
  44. }
  45. const homePrefix = readRc(path.join(os.homedir(), '.npmrc'));
  46. if (homePrefix) {
  47. return homePrefix;
  48. }
  49. if (process.env.PREFIX) {
  50. return process.env.PREFIX;
  51. }
  52. const globalPrefix = readRc(getGlobalNpmrc());
  53. if (globalPrefix) {
  54. return globalPrefix;
  55. }
  56. return getDefaultNpmPrefix();
  57. };
  58. const npmPrefix = path.resolve(getNpmPrefix());
  59. const getYarnWindowsDirectory = () => {
  60. if (isWindows && process.env.LOCALAPPDATA) {
  61. const dir = path.join(process.env.LOCALAPPDATA, 'Yarn');
  62. if (fs.existsSync(dir)) {
  63. return dir;
  64. }
  65. }
  66. return false;
  67. };
  68. const getYarnPrefix = () => {
  69. if (process.env.PREFIX) {
  70. return process.env.PREFIX;
  71. }
  72. const windowsPrefix = getYarnWindowsDirectory();
  73. if (windowsPrefix) {
  74. return windowsPrefix;
  75. }
  76. const configPrefix = path.join(os.homedir(), '.config/yarn');
  77. if (fs.existsSync(configPrefix)) {
  78. return configPrefix;
  79. }
  80. const homePrefix = path.join(os.homedir(), '.yarn-config');
  81. if (fs.existsSync(homePrefix)) {
  82. return homePrefix;
  83. }
  84. // Yarn supports the npm conventions but the inverse is not true
  85. return npmPrefix;
  86. };
  87. exports.npm = {};
  88. exports.npm.prefix = npmPrefix;
  89. exports.npm.packages = path.join(npmPrefix, isWindows ? 'node_modules' : 'lib/node_modules');
  90. exports.npm.binaries = isWindows ? npmPrefix : path.join(npmPrefix, 'bin');
  91. const yarnPrefix = path.resolve(getYarnPrefix());
  92. exports.yarn = {};
  93. exports.yarn.prefix = yarnPrefix;
  94. exports.yarn.packages = path.join(yarnPrefix, getYarnWindowsDirectory() ? 'Data/global/node_modules' : 'global/node_modules');
  95. exports.yarn.binaries = path.join(exports.yarn.packages, '.bin');