npm.js 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186
  1. // Generated by IcedCoffeeScript 1.8.0-c
  2. (function() {
  3. var check_cmd, exec, fs, iced, log, npm, os, path, prng, run, strip, __iced_k, __iced_k_noop, _config;
  4. iced = require('iced-runtime');
  5. __iced_k = __iced_k_noop = function() {};
  6. run = require('iced-spawn').run;
  7. exec = require('child_process').exec;
  8. path = require('path');
  9. fs = require('fs');
  10. log = require('./log');
  11. prng = require('crypto').prng;
  12. strip = require('./util').strip;
  13. os = require('os');
  14. _config = null;
  15. exports.set_config = function(c) {
  16. return _config = c;
  17. };
  18. exports.npm = npm = function(_arg, cb) {
  19. var args, err, name, out, p, ___iced_passed_deferral, __iced_deferrals, __iced_k;
  20. __iced_k = __iced_k_noop;
  21. ___iced_passed_deferral = iced.findDeferral(arguments);
  22. args = _arg.args;
  23. name = _config.get_cmd('npm');
  24. p = _config.install_prefix();
  25. if ((p != null) && p.length) {
  26. args = ["--prefix", p].concat(args);
  27. }
  28. (function(_this) {
  29. return (function(__iced_k) {
  30. __iced_deferrals = new iced.Deferrals(__iced_k, {
  31. parent: ___iced_passed_deferral,
  32. filename: "/Users/max/src/keybase/node-installer/src/npm.iced"
  33. });
  34. run({
  35. args: args,
  36. name: name
  37. }, __iced_deferrals.defer({
  38. assign_fn: (function() {
  39. return function() {
  40. err = arguments[0];
  41. return out = arguments[1];
  42. };
  43. })(),
  44. lineno: 23
  45. }));
  46. __iced_deferrals._fulfill();
  47. });
  48. })(this)((function(_this) {
  49. return function() {
  50. return cb(err, out);
  51. };
  52. })(this));
  53. };
  54. exports.check = check_cmd = function(cb) {
  55. var err, ___iced_passed_deferral, __iced_deferrals, __iced_k;
  56. __iced_k = __iced_k_noop;
  57. ___iced_passed_deferral = iced.findDeferral(arguments);
  58. (function(_this) {
  59. return (function(__iced_k) {
  60. __iced_deferrals = new iced.Deferrals(__iced_k, {
  61. parent: ___iced_passed_deferral,
  62. filename: "/Users/max/src/keybase/node-installer/src/npm.iced"
  63. });
  64. npm({
  65. args: ["--version"]
  66. }, __iced_deferrals.defer({
  67. assign_fn: (function() {
  68. return function() {
  69. return err = arguments[0];
  70. };
  71. })(),
  72. lineno: 29
  73. }));
  74. __iced_deferrals._fulfill();
  75. });
  76. })(this)((function(_this) {
  77. return function() {
  78. return cb(err);
  79. };
  80. })(this));
  81. };
  82. exports.test_install = function(cb) {
  83. var dirname, err, out, r, test, tmp, ___iced_passed_deferral, __iced_deferrals, __iced_k;
  84. __iced_k = __iced_k_noop;
  85. ___iced_passed_deferral = iced.findDeferral(arguments);
  86. log.debug("+ Installer::test_npm_install");
  87. dirname = null;
  88. (function(_this) {
  89. return (function(__iced_k) {
  90. __iced_deferrals = new iced.Deferrals(__iced_k, {
  91. parent: ___iced_passed_deferral,
  92. filename: "/Users/max/src/keybase/node-installer/src/npm.iced",
  93. funcname: "test_install"
  94. });
  95. _this.npm({
  96. args: ["get", "prefix"]
  97. }, __iced_deferrals.defer({
  98. assign_fn: (function() {
  99. return function() {
  100. err = arguments[0];
  101. return out = arguments[1];
  102. };
  103. })(),
  104. lineno: 38
  105. }));
  106. __iced_deferrals._fulfill();
  107. });
  108. })(this)((function(_this) {
  109. return function() {
  110. (function(__iced_k) {
  111. if (typeof err !== "undefined" && err !== null) {
  112. return __iced_k(log.error("Failed to get a prefix from npm"));
  113. } else {
  114. dirname = strip(out.toString('utf8'));
  115. log.debug("| Testing install directory: " + dirname);
  116. r = prng(10).toString('hex');
  117. test = path.resolve(dirname, ".keybase_test_install_" + r);
  118. log.debug("| Writing temporary file, to see if install will work: " + test);
  119. (function(__iced_k) {
  120. __iced_deferrals = new iced.Deferrals(__iced_k, {
  121. parent: ___iced_passed_deferral,
  122. filename: "/Users/max/src/keybase/node-installer/src/npm.iced",
  123. funcname: "test_install"
  124. });
  125. fs.writeFile(test, new Buffer([]), {
  126. mode: 0x180
  127. }, __iced_deferrals.defer({
  128. assign_fn: (function() {
  129. return function() {
  130. return err = arguments[0];
  131. };
  132. })(),
  133. lineno: 47
  134. }));
  135. __iced_deferrals._fulfill();
  136. })(function() {
  137. (function(__iced_k) {
  138. var _ref;
  139. if (typeof err !== "undefined" && err !== null) {
  140. return __iced_k((_ref = err.code) === 'EACCES' || _ref === 'EPERM' ? os.platform() === 'win32' ? err = new Error("Permission denied - Node was installed as Admin.\n" + "\nWindows solution: launch another command window by right-clicking" + "\nand selecting \"Run as Administrator\"," + "\nthen run `keybase-installer`. (Then you may close the window.)\n") : err = new Error("Permission denied installing to " + dirname + ": try running `sudo keybase-installer` or use the `--prefix` option to install locally") : err = new Error("Can't write to directory " + dirname + ": " + err.code));
  141. } else {
  142. (function(__iced_k) {
  143. __iced_deferrals = new iced.Deferrals(__iced_k, {
  144. parent: ___iced_passed_deferral,
  145. filename: "/Users/max/src/keybase/node-installer/src/npm.iced",
  146. funcname: "test_install"
  147. });
  148. fs.unlink(test, __iced_deferrals.defer({
  149. assign_fn: (function() {
  150. return function() {
  151. return tmp = arguments[0];
  152. };
  153. })(),
  154. lineno: 60
  155. }));
  156. __iced_deferrals._fulfill();
  157. })(function() {
  158. return __iced_k(typeof tmp !== "undefined" && tmp !== null ? log.warn("Failed to unlink temporary file: " + test) : log.debug("| Unlinking file: " + test));
  159. });
  160. }
  161. })(__iced_k);
  162. });
  163. }
  164. })(function() {
  165. log.debug("- Installer::test_npm_install");
  166. return cb(err, dirname);
  167. });
  168. };
  169. })(this));
  170. };
  171. }).call(this);