createInnerContext.js 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. /*
  2. MIT License http://www.opensource.org/licenses/mit-license.php
  3. Author Tobias Koppers @sokra
  4. */
  5. "use strict";
  6. /** @typedef {import("./Resolver").ResolveContext} ResolveContext */
  7. /**
  8. * @param {ResolveContext} options options for inner context
  9. * @param {null|string} message message to log
  10. * @returns {ResolveContext} inner context
  11. */
  12. module.exports = function createInnerContext(options, message) {
  13. let messageReported = false;
  14. let innerLog = undefined;
  15. if (options.log) {
  16. if (message) {
  17. /**
  18. * @param {string} msg message
  19. */
  20. innerLog = msg => {
  21. if (!messageReported) {
  22. /** @type {(function(string): void)} */
  23. (options.log)(message);
  24. messageReported = true;
  25. }
  26. /** @type {(function(string): void)} */
  27. (options.log)(" " + msg);
  28. };
  29. } else {
  30. innerLog = options.log;
  31. }
  32. }
  33. return {
  34. log: innerLog,
  35. yield: options.yield,
  36. fileDependencies: options.fileDependencies,
  37. contextDependencies: options.contextDependencies,
  38. missingDependencies: options.missingDependencies,
  39. stack: options.stack
  40. };
  41. };