processResult.js 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. "use strict";
  2. const removeSourceMappingUrl = require('./removeSourceMappingUrl');
  3. const formatLessError = require('./formatLessError');
  4. /**
  5. * Removes the sourceMappingURL from the generated CSS, parses the source map and calls the next loader.
  6. *
  7. * @param {loaderContext} loaderContext
  8. * @param {Promise<LessResult>} resultPromise
  9. */
  10. function processResult(loaderContext, resultPromise) {
  11. const {
  12. callback
  13. } = loaderContext;
  14. resultPromise.then(({
  15. css,
  16. map,
  17. imports
  18. }) => {
  19. imports.forEach(loaderContext.addDependency, loaderContext);
  20. return {
  21. // Removing the sourceMappingURL comment.
  22. // See removeSourceMappingUrl.js for the reasoning behind this.
  23. css: removeSourceMappingUrl(css),
  24. map: typeof map === 'string' ? JSON.parse(map) : map
  25. };
  26. }, lessError => {
  27. if (lessError.filename) {
  28. loaderContext.addDependency(lessError.filename);
  29. }
  30. throw formatLessError(lessError);
  31. }).then(({
  32. css,
  33. map
  34. }) => {
  35. callback(null, css, map);
  36. }, callback);
  37. }
  38. module.exports = processResult;