Skip to content

Commit

Permalink
fix: support string as plugin option in custom postcss plugin config
Browse files Browse the repository at this point in the history
In certain cases, the plugin option may be a string value, as shown in the example below:

```json
{
 "plugins": {
  "tailwindcss/nesting": "postcss-nesting"
  }
}
```
  • Loading branch information
alan-agius4 committed Feb 14, 2024
1 parent c578e66 commit bb67204
Showing 1 changed file with 4 additions and 6 deletions.
10 changes: 4 additions & 6 deletions src/lib/styles/postcss-configuration.ts
Expand Up @@ -2,11 +2,11 @@ import { readFile, readdir } from 'node:fs/promises';
import { join } from 'node:path';

export interface PostcssConfiguration {
plugins: [name: string, options?: object][];
plugins: [name: string, options?: object | string][];
}

interface RawPostcssConfiguration {
plugins?: Record<string, object | boolean> | (string | [string, object])[];
plugins?: Record<string, object | string | boolean> | (string | [string, object])[];
}

const postcssConfigurationFiles: string[] = ['postcss.config.json', '.postcssrc.json'];
Expand Down Expand Up @@ -46,9 +46,7 @@ async function readPostcssConfiguration(configurationFile: string): Promise<RawP
return config;
}

export async function loadPostcssConfiguration(
projectRoot: string,
): Promise<PostcssConfiguration | undefined> {
export async function loadPostcssConfiguration(projectRoot: string): Promise<PostcssConfiguration | undefined> {
// A configuration file can exist in the project or workspace root
const searchDirectories = await generateSearchDirectories([projectRoot]);

Expand Down Expand Up @@ -90,7 +88,7 @@ export async function loadPostcssConfiguration(

const config: PostcssConfiguration = { plugins: [] };
for (const [name, options] of entries) {
if (!options || typeof options !== 'object') {
if (!options || (typeof options !== 'object' && typeof options !== 'string')) {
continue;
}

Expand Down

0 comments on commit bb67204

Please sign in to comment.