configure.js 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. 'use strict';
  2. module.exports = exports = configure;
  3. exports.usage = 'Attempts to configure node-gyp or nw-gyp build';
  4. const napi = require('./util/napi.js');
  5. const compile = require('./util/compile.js');
  6. const handle_gyp_opts = require('./util/handle_gyp_opts.js');
  7. function configure(gyp, argv, callback) {
  8. handle_gyp_opts(gyp, argv, (err, result) => {
  9. let final_args = result.gyp.concat(result.pre);
  10. // pull select node-gyp configure options out of the npm environ
  11. const known_gyp_args = ['dist-url', 'python', 'nodedir', 'msvs_version'];
  12. known_gyp_args.forEach((key) => {
  13. const val = gyp.opts[key] || gyp.opts[key.replace('-', '_')];
  14. if (val) {
  15. final_args.push('--' + key + '=' + val);
  16. }
  17. });
  18. // --ensure=false tell node-gyp to re-install node development headers
  19. // but it is only respected by node-gyp install, so we have to call install
  20. // as a separate step if the user passes it
  21. if (gyp.opts.ensure === false) {
  22. const install_args = final_args.concat(['install', '--ensure=false']);
  23. compile.run_gyp(install_args, result.opts, (err2) => {
  24. if (err2) return callback(err2);
  25. if (result.unparsed.length > 0) {
  26. final_args = final_args.
  27. concat(['--']).
  28. concat(result.unparsed);
  29. }
  30. compile.run_gyp(['configure'].concat(final_args), result.opts, (err3) => {
  31. return callback(err3);
  32. });
  33. });
  34. } else {
  35. if (result.unparsed.length > 0) {
  36. final_args = final_args.
  37. concat(['--']).
  38. concat(result.unparsed);
  39. }
  40. compile.run_gyp(['configure'].concat(final_args), result.opts, (err4) => {
  41. if (!err4 && result.opts.napi_build_version) {
  42. napi.swap_build_dir_out(result.opts.napi_build_version);
  43. }
  44. return callback(err4);
  45. });
  46. }
  47. });
  48. }