Skip to content

Commit 47b09c9

Browse files
authoredOct 18, 2023
support postcss cjs format (#304)
1 parent 773d341 commit 47b09c9

File tree

8 files changed

+67
-2
lines changed

8 files changed

+67
-2
lines changed
 

‎fixtures/plugins/postcss-cjs/node_modules/autoprefixer/index.js

+1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎fixtures/plugins/postcss-cjs/node_modules/autoprefixer/package.json

+3
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎fixtures/plugins/postcss-cjs/node_modules/postcss/package.json

+4
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
{
2+
"name": "@fixtures/postcss-cjs",
3+
"scripts": {
4+
"postcss": "postcss"
5+
},
6+
"devDependencies": {
7+
"postcss": "*"
8+
},
9+
"postcss": {
10+
"plugins": [
11+
"autoprefixer"
12+
]
13+
}
14+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
module.exports = {
2+
plugins: [require('autoprefixer')],
3+
};

‎src/plugins/postcss/README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ or `devDependencies`:
1313
```json
1414
{
1515
"postcss": {
16-
"config": ["postcss.config.js", "postcss.config.json", "package.json"]
16+
"config": ["postcss.config.{cjs,js}", "postcss.config.json", "package.json"]
1717
}
1818
}
1919
```

‎src/plugins/postcss/index.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ export const ENABLERS = ['postcss', 'next'];
1010

1111
export const isEnabled: IsPluginEnabledCallback = ({ dependencies }) => hasDependency(dependencies, ENABLERS);
1212

13-
export const CONFIG_FILE_PATTERNS = ['postcss.config.js', 'postcss.config.json', 'package.json'];
13+
export const CONFIG_FILE_PATTERNS = ['postcss.config.{cjs,js}', 'postcss.config.json', 'package.json'];
1414

1515
const findPostCSSDependencies: GenericPluginCallback = async (configFilePath, options) => {
1616
const { manifest, isProduction } = options;

‎test/plugins/postcss-cjs.test.ts

+40
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
import assert from 'node:assert/strict';
2+
import test from 'node:test';
3+
import { main } from '../../src/index.js';
4+
import * as postcss from '../../src/plugins/postcss/index.js';
5+
import { resolve, join } from '../../src/util/path.js';
6+
import baseArguments from '../helpers/baseArguments.js';
7+
import baseCounters from '../helpers/baseCounters.js';
8+
import { getManifest } from '../helpers/index.js';
9+
10+
const cwd = resolve('fixtures/plugins/postcss-cjs');
11+
const manifestFilePath = join(cwd, 'package.json');
12+
const manifest = getManifest(cwd);
13+
14+
test('Find dependencies in PostCSS configuration (package.json)', async () => {
15+
const dependencies = await postcss.findDependencies(manifestFilePath, { manifest });
16+
assert.deepEqual(dependencies, ['autoprefixer']);
17+
});
18+
19+
test('Find dependencies in PostCSS configuration (postcss.config.cjs)', async () => {
20+
const configFilePath = join(cwd, 'postcss.config.cjs');
21+
const dependencies = await postcss.findDependencies(configFilePath, { manifest });
22+
assert.deepEqual(dependencies, []);
23+
});
24+
25+
test('Find dependencies in PostCSS configuration (postcss.config.cjs function)', async () => {
26+
const { issues, counters } = await main({
27+
...baseArguments,
28+
cwd,
29+
});
30+
31+
assert(issues.unlisted['package.json']['autoprefixer']);
32+
assert(issues.unlisted['postcss.config.cjs']['autoprefixer']);
33+
34+
assert.deepEqual(counters, {
35+
...baseCounters,
36+
unlisted: 2,
37+
processed: 1,
38+
total: 1,
39+
});
40+
});

0 commit comments

Comments
 (0)
Please sign in to comment.