options.js 1.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. 'use strict'
  2. const req = require('import-cwd')
  3. /**
  4. * Load Options
  5. *
  6. * @private
  7. * @method options
  8. *
  9. * @param {Object} config PostCSS Config
  10. *
  11. * @return {Object} options PostCSS Options
  12. */
  13. const options = (config, file) => {
  14. if (config.parser && typeof config.parser === 'string') {
  15. try {
  16. config.parser = req(config.parser)
  17. } catch (err) {
  18. throw new Error(`Loading PostCSS Parser failed: ${err.message}\n\n(@${file})`)
  19. }
  20. }
  21. if (config.syntax && typeof config.syntax === 'string') {
  22. try {
  23. config.syntax = req(config.syntax)
  24. } catch (err) {
  25. throw new Error(`Loading PostCSS Syntax failed: ${err.message}\n\n(@${file})`)
  26. }
  27. }
  28. if (config.stringifier && typeof config.stringifier === 'string') {
  29. try {
  30. config.stringifier = req(config.stringifier)
  31. } catch (err) {
  32. throw new Error(`Loading PostCSS Stringifier failed: ${err.message}\n\n(@${file})`)
  33. }
  34. }
  35. if (config.plugins) {
  36. delete config.plugins
  37. }
  38. return config
  39. }
  40. module.exports = options