createInnerCallback.js 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. /*
  2. MIT License http://www.opensource.org/licenses/mit-license.php
  3. Author Tobias Koppers @sokra
  4. */
  5. "use strict";
  6. const util = require("util");
  7. // TODO remove in enhanced-resolve 5
  8. module.exports = util.deprecate(function createInnerCallback(
  9. callback,
  10. options,
  11. message,
  12. messageOptional
  13. ) {
  14. const log = options.log;
  15. if (!log) {
  16. if (options.stack !== callback.stack) {
  17. const callbackWrapper = function callbackWrapper() {
  18. return callback.apply(this, arguments);
  19. };
  20. callbackWrapper.stack = options.stack;
  21. callbackWrapper.missing = options.missing;
  22. return callbackWrapper;
  23. }
  24. return callback;
  25. }
  26. function loggingCallbackWrapper() {
  27. return callback.apply(this, arguments);
  28. }
  29. if (message) {
  30. if (!messageOptional) {
  31. log(message);
  32. }
  33. loggingCallbackWrapper.log = function writeLog(msg) {
  34. if (messageOptional) {
  35. log(message);
  36. messageOptional = false;
  37. }
  38. log(" " + msg);
  39. };
  40. } else {
  41. loggingCallbackWrapper.log = function writeLog(msg) {
  42. log(msg);
  43. };
  44. }
  45. loggingCallbackWrapper.stack = options.stack;
  46. loggingCallbackWrapper.missing = options.missing;
  47. return loggingCallbackWrapper;
  48. },
  49. "Pass resolveContext instead and use createInnerContext");