processResult.js 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. 'use strict';
  2. var removeSourceMappingUrl = require('./removeSourceMappingUrl');
  3. var 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. var callback = loaderContext.callback;
  12. resultPromise.then(function (_ref) {
  13. var css = _ref.css,
  14. map = _ref.map,
  15. imports = _ref.imports;
  16. imports.forEach(loaderContext.addDependency, loaderContext);
  17. return {
  18. // Removing the sourceMappingURL comment.
  19. // See removeSourceMappingUrl.js for the reasoning behind this.
  20. css: removeSourceMappingUrl(css),
  21. map: typeof map === 'string' ? JSON.parse(map) : map
  22. };
  23. }, function (lessError) {
  24. throw formatLessError(lessError);
  25. }).then(function (_ref2) {
  26. var css = _ref2.css,
  27. map = _ref2.map;
  28. callback(null, css, map);
  29. }, callback);
  30. }
  31. module.exports = processResult;