Skip to content

Commit

Permalink
fix: tailwind.config.ts support & cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
luckasRanarison committed Aug 3, 2024
1 parent 13f3742 commit cc19942
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 12 deletions.
24 changes: 12 additions & 12 deletions rplugin/node/tailwind-tools/src/index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
const fs = require("fs");
const path = require("path");
const fs = require("node:fs");
const path = require("node:path");
const { getNodeModuleResolver } = require("./utils");

class Plugin {
/**
Expand All @@ -19,21 +20,20 @@ class Plugin {

async getRawConfig() {
const cwd = await this.nvim.call("getcwd");
const tailwindPath = path.join(cwd, "node_modules/tailwindcss");
const tailwindPath = path.join(cwd, "node_modules", "tailwindcss");

if (!fs.existsSync(tailwindPath)) return;

const resolveFnPath = path.join(tailwindPath, "resolveConfig");
const resolveConfig = require(resolveFnPath);
const projectConfigPath = path.join(cwd, "tailwind.config.js");
const _require = getNodeModuleResolver(cwd);
const resolveConfig = _require("tailwindcss/resolveConfig");
const loadConfig = _require("tailwindcss/lib/public/load-config").default;

let projectConfig = {};
const configExtensions = ["js", "ts", "cjs"];
const configPath = configExtensions
.map((ext) => path.join(cwd, `tailwind.config.${ext}`))
.find((filePath) => fs.existsSync(filePath));

if (fs.existsSync(projectConfigPath)) {
projectConfig = await import(projectConfigPath);
}

return resolveConfig(projectConfig.default ?? projectConfig);
return resolveConfig(configPath ? loadConfig(configPath) : {});
}
}

Expand Down
8 changes: 8 additions & 0 deletions rplugin/node/tailwind-tools/src/utils.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
const path = require("node:path");

const getNodeModuleResolver = (rootDir) => (modulePath) =>
require(path.join(rootDir, "node_modules", modulePath));

module.exports = {
getNodeModuleResolver,
};

0 comments on commit cc19942

Please sign in to comment.