getRenderFunctionFromSassImplementation.js 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", {
  3. value: true
  4. });
  5. exports.default = void 0;
  6. var _neoAsync = _interopRequireDefault(require("neo-async"));
  7. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
  8. let nodeSassJobQueue = null;
  9. /**
  10. * Verifies that the implementation and version of Sass is supported by this loader.
  11. *
  12. * @param {Object} implementation
  13. * @returns {Function}
  14. */
  15. function getRenderFunctionFromSassImplementation(implementation) {
  16. const isDartSass = implementation.info.includes('dart-sass');
  17. if (isDartSass) {
  18. return implementation.render.bind(implementation);
  19. } // There is an issue with node-sass when async custom importers are used
  20. // See https://github.com/sass/node-sass/issues/857#issuecomment-93594360
  21. // We need to use a job queue to make sure that one thread is always available to the UV lib
  22. if (nodeSassJobQueue === null) {
  23. const threadPoolSize = Number(process.env.UV_THREADPOOL_SIZE || 4);
  24. nodeSassJobQueue = _neoAsync.default.queue(implementation.render.bind(implementation), threadPoolSize - 1);
  25. }
  26. return nodeSassJobQueue.push.bind(nodeSassJobQueue);
  27. }
  28. var _default = getRenderFunctionFromSassImplementation;
  29. exports.default = _default;