getSassImplementation.js 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", {
  3. value: true
  4. });
  5. exports.default = void 0;
  6. var _semver = _interopRequireDefault(require("semver"));
  7. var _getDefaultSassImplementation = _interopRequireDefault(require("./getDefaultSassImplementation"));
  8. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
  9. function getSassImplementation(implementation) {
  10. let resolvedImplementation = implementation;
  11. if (!resolvedImplementation) {
  12. // eslint-disable-next-line no-param-reassign
  13. resolvedImplementation = (0, _getDefaultSassImplementation.default)();
  14. }
  15. const {
  16. info
  17. } = resolvedImplementation;
  18. if (!info) {
  19. throw new Error('Unknown Sass implementation.');
  20. }
  21. const infoParts = info.split('\t');
  22. if (infoParts.length < 2) {
  23. throw new Error(`Unknown Sass implementation "${info}".`);
  24. }
  25. const [implementationName, version] = infoParts;
  26. if (implementationName === 'dart-sass') {
  27. if (!_semver.default.satisfies(version, '^1.3.0')) {
  28. throw new Error(`Dart Sass version ${version} is incompatible with ^1.3.0.`);
  29. }
  30. return resolvedImplementation;
  31. } else if (implementationName === 'node-sass') {
  32. if (!_semver.default.satisfies(version, '^4.0.0')) {
  33. throw new Error(`Node Sass version ${version} is incompatible with ^4.0.0.`);
  34. }
  35. return resolvedImplementation;
  36. }
  37. throw new Error(`Unknown Sass implementation "${implementationName}".`);
  38. }
  39. var _default = getSassImplementation;
  40. exports.default = _default;