egoist / tailwindcss-icons

Use any icon (100,000+) from Iconify, for TailwindCSS
MIT License
830 stars 17 forks source link

fix: pass directory of config to plugin loader #17

Closed loganmac closed 9 months ago

loganmac commented 10 months ago

When prettier is executed by user's editors, like VS Code, the calls to process.cwd() can return null. This is usually because the process is being run in a folder that doesn't exist.

This fix extends the getIconCollections function to accept a dir parameter when called, so that you can pass the directory of your tailwind.config.js file in with __dirname. The default value for the parameter for the function should also make it backwards compatible with the old way it was called.

Fixes the issues some users are still having with #3, #9, #16. Note that the users will have to update their tailwind.config.js like so:


const { iconsPlugin, getIconCollections } = require("@egoist/tailwindcss-icons")
module.exports = {
  plugins: [
    iconsPlugin({
      // Select the icon collections you want to use
      // collections: getIconCollections(["mdi", "lucide"]), <- old way of configuring plugin
      collections: getIconCollections(["mdi", "lucide"], __dirname), // <- new way
    }),
  ],
}
codesandbox[bot] commented 10 months ago

Review or Edit in CodeSandbox

Open the branch in Web EditorVS CodeInsiders
Open Preview

egoist commented 9 months ago

My previous fix (without introducing a new argument) only fixed it on macOS, I just made a new release, let me know if it works now