Skip to content

Commit

Permalink
(PostCSS plugin): Add postcss to used dependencies when using PostC…
Browse files Browse the repository at this point in the history
…SS with Tailwind CSS (#764)

Co-authored-by: Lars Kappert <[email protected]>
  • Loading branch information
taro-28 and webpro authored Aug 21, 2024
1 parent 53a50ae commit 23526a9
Show file tree
Hide file tree
Showing 6 changed files with 45 additions and 1 deletion.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"name": "@fixtures/postcss-tailwindcss",
"devDependencies": {
"postcss": "*"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
module.exports = {
plugins: {
tailwindcss: {},
},
};
5 changes: 4 additions & 1 deletion packages/knip/src/plugins/postcss/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,16 @@ const config = [
];

const resolveConfig: ResolveConfig<PostCSSConfig> = config => {
return config.plugins
const plugins = config.plugins
? (Array.isArray(config.plugins) ? config.plugins : Object.keys(config.plugins)).flatMap(plugin => {
if (typeof plugin === 'string') return plugin;
if (Array.isArray(plugin) && typeof plugin[0] === 'string') return plugin[0];
return [];
})
: [];

// Because postcss is not included in peerDependencies of tailwindcss
return plugins.includes('tailwindcss') ? [...plugins, 'postcss'] : plugins;
};

export default {
Expand Down
24 changes: 24 additions & 0 deletions packages/knip/test/plugins/postcss-tailwindcss.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import { test } from 'bun:test';
import assert from 'node:assert/strict';
import { main } from '../../src/index.js';
import { resolve } from '../../src/util/path.js';
import baseArguments from '../helpers/baseArguments.js';
import baseCounters from '../helpers/baseCounters.js';

const cwd = resolve('fixtures/plugins/postcss-tailwindcss');

test('Find dependencies with the PostCSS plugin (with tailwindcss)', async () => {
const { issues, counters } = await main({
...baseArguments,
cwd,
});

assert(issues.unlisted['postcss.config.js']['tailwindcss']);

assert.deepEqual(counters, {
...baseCounters,
unlisted: 1,
processed: 1,
total: 1,
});
});

0 comments on commit 23526a9

Please sign in to comment.