resolveConfigPath.js 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", {
  3. value: true
  4. });
  5. function _export(target, all) {
  6. for(var name in all)Object.defineProperty(target, name, {
  7. enumerable: true,
  8. get: all[name]
  9. });
  10. }
  11. _export(exports, {
  12. default: ()=>resolveConfigPath,
  13. resolveDefaultConfigPath: ()=>resolveDefaultConfigPath
  14. });
  15. const _fs = /*#__PURE__*/ _interopRequireDefault(require("fs"));
  16. const _path = /*#__PURE__*/ _interopRequireDefault(require("path"));
  17. function _interopRequireDefault(obj) {
  18. return obj && obj.__esModule ? obj : {
  19. default: obj
  20. };
  21. }
  22. const defaultConfigFiles = [
  23. "./tailwind.config.js",
  24. "./tailwind.config.cjs",
  25. "./tailwind.config.mjs",
  26. "./tailwind.config.ts"
  27. ];
  28. function isObject(value) {
  29. return typeof value === "object" && value !== null;
  30. }
  31. function isEmpty(obj) {
  32. return Object.keys(obj).length === 0;
  33. }
  34. function isString(value) {
  35. return typeof value === "string" || value instanceof String;
  36. }
  37. function resolveConfigPath(pathOrConfig) {
  38. // require('tailwindcss')({ theme: ..., variants: ... })
  39. if (isObject(pathOrConfig) && pathOrConfig.config === undefined && !isEmpty(pathOrConfig)) {
  40. return null;
  41. }
  42. // require('tailwindcss')({ config: 'custom-config.js' })
  43. if (isObject(pathOrConfig) && pathOrConfig.config !== undefined && isString(pathOrConfig.config)) {
  44. return _path.default.resolve(pathOrConfig.config);
  45. }
  46. // require('tailwindcss')({ config: { theme: ..., variants: ... } })
  47. if (isObject(pathOrConfig) && pathOrConfig.config !== undefined && isObject(pathOrConfig.config)) {
  48. return null;
  49. }
  50. // require('tailwindcss')('custom-config.js')
  51. if (isString(pathOrConfig)) {
  52. return _path.default.resolve(pathOrConfig);
  53. }
  54. // require('tailwindcss')
  55. return resolveDefaultConfigPath();
  56. }
  57. function resolveDefaultConfigPath() {
  58. for (const configFile of defaultConfigFiles){
  59. try {
  60. const configPath = _path.default.resolve(configFile);
  61. _fs.default.accessSync(configPath);
  62. return configPath;
  63. } catch (err) {}
  64. }
  65. return null;
  66. }