Skip to content

Commit bd54894

Browse files
committed
chore: update stylelint-config to use CommonJS and ESM formats
- Updated configuration files to use .cjs and .mjs extensions for better compatibility. - Removed deprecated a11y configuration file and adjusted related tests. - Enhanced test cases to validate both ESM and CJS configurations. - Updated package.json to reflect changes in configuration paths.
1 parent b6c656d commit bd54894

File tree

6 files changed

+65
-69
lines changed

6 files changed

+65
-69
lines changed
Lines changed: 27 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,21 @@
11
import { describe, expect, it } from "vitest";
22

3-
import Index from "..";
3+
import IndexESM from "../index.mjs";
4+
import IndexCJS from "../index.cjs";
45

56
const isWindows = process.platform === "win32";
67

78
describe("stylelint", () => {
8-
it("should output no error", async () => {
9+
it("should output no error on esm errors", async () => {
910
expect.assertions(2);
1011

1112
const distributionFolderPath = __dirname.replace("__tests__", "dist");
1213

1314
// eslint-disable-next-line vitest/no-conditional-tests,vitest/no-conditional-in-test
1415
const pathReplaceValue = isWindows ? "\\" : "/";
1516

16-
expect(Index.extends.length > 0).toBeTruthy();
17-
expect(Index.extends).toStrictEqual([
18-
`${distributionFolderPath}/config/a11y.mjs`.replaceAll("/", pathReplaceValue),
17+
expect(IndexESM.extends.length > 0).toBeTruthy();
18+
expect(IndexESM.extends).toStrictEqual([
1919
`${distributionFolderPath}/config/best-practices.mjs`.replaceAll("/", pathReplaceValue),
2020
`${distributionFolderPath}/config/declaration-block-no-ignored-properties.mjs`.replaceAll("/", pathReplaceValue),
2121
`${distributionFolderPath}/config/high-performance-animation.mjs`.replaceAll("/", pathReplaceValue),
@@ -27,4 +27,26 @@ describe("stylelint", () => {
2727
"stylelint-config-clean-order",
2828
]);
2929
});
30+
31+
it("should output no error on cjs errors", async () => {
32+
expect.assertions(2);
33+
34+
const distributionFolderPath = __dirname.replace("__tests__", "dist");
35+
36+
// eslint-disable-next-line vitest/no-conditional-tests,vitest/no-conditional-in-test
37+
const pathReplaceValue = isWindows ? "\\" : "/";
38+
39+
expect(IndexCJS.extends.length > 0).toBeTruthy();
40+
expect(IndexCJS.extends).toStrictEqual([
41+
`${distributionFolderPath}/config/best-practices.cjs`.replaceAll("/", pathReplaceValue),
42+
`${distributionFolderPath}/config/declaration-block-no-ignored-properties.cjs`.replaceAll("/", pathReplaceValue),
43+
`${distributionFolderPath}/config/high-performance-animation.cjs`.replaceAll("/", pathReplaceValue),
44+
`${distributionFolderPath}/config/no-unsupported-browser-features.cjs`.replaceAll("/", pathReplaceValue),
45+
`${distributionFolderPath}/config/require-units.cjs`.replaceAll("/", pathReplaceValue),
46+
`${distributionFolderPath}/config/selector-no-empty.cjs`.replaceAll("/", pathReplaceValue),
47+
`${distributionFolderPath}/config/standard.cjs`.replaceAll("/", pathReplaceValue),
48+
`${distributionFolderPath}/config/tailwindcss.cjs`.replaceAll("/", pathReplaceValue),
49+
"stylelint-config-clean-order",
50+
]);
51+
});
3052
});

packages/stylelint-config/index.cjs

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,13 @@
11
// eslint-disable-next-line no-var
22
const config = [
3-
"./dist/config/a11y.js",
4-
"./dist/config/best-practices.js",
5-
"./dist/config/declaration-block-no-ignored-properties.js",
6-
"./dist/config/high-performance-animation.js",
7-
"./dist/config/no-unsupported-browser-features.js",
8-
"./dist/config/require-units.js",
9-
"./dist/config/selector-no-empty.js",
10-
"./dist/config/standard.js",
11-
"./dist/config/tailwindcss.js",
3+
"./dist/config/best-practices.cjs",
4+
"./dist/config/declaration-block-no-ignored-properties.cjs",
5+
"./dist/config/high-performance-animation.cjs",
6+
"./dist/config/no-unsupported-browser-features.cjs",
7+
"./dist/config/require-units.cjs",
8+
"./dist/config/selector-no-empty.cjs",
9+
"./dist/config/standard.cjs",
10+
"./dist/config/tailwindcss.cjs",
1211
];
1312

1413
module.exports = {

packages/stylelint-config/index.mjs

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
import { createRequire } from "node:module";
1+
import { fileURLToPath } from 'node:url';
2+
import path from 'node:path';
23

34
const cconfig = [
4-
"./dist/config/a11y.mjs",
55
"./dist/config/best-practices.mjs",
66
"./dist/config/declaration-block-no-ignored-properties.mjs",
77
"./dist/config/high-performance-animation.mjs",
@@ -12,12 +12,17 @@ const cconfig = [
1212
"./dist/config/tailwindcss.mjs",
1313
];
1414

15-
const resolvePath = async (path) => {
16-
return await import.meta.resolve(path, import.meta.url);
15+
/**
16+
* @param {string} specifier
17+
* @returns {string}
18+
*/
19+
const resolvePath = (specifier) => {
20+
const currentModuleDir = path.dirname(fileURLToPath(import.meta.url));
21+
return path.resolve(currentModuleDir, specifier);
1722
};
1823

1924
const config = {
20-
extends: [...cconfig.map((element) => resolvePath(element)), "stylelint-config-clean-order"],
25+
extends: [...cconfig.map(resolvePath), "stylelint-config-clean-order"],
2126
};
2227

2328
export default config;

packages/stylelint-config/package.json

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -54,14 +54,14 @@
5454
"default": "./index.mjs"
5555
}
5656
},
57-
"./a11y": {
57+
"./best-practices": {
5858
"require": {
59-
"types": "./dist/config/a11y.d.cts",
60-
"default": "./dist/config/a11y.cjs"
59+
"types": "./dist/config/best-practices.d.cts",
60+
"default": "./dist/config/best-practices.cjs"
6161
},
6262
"import": {
63-
"types": "./dist/config/a11y.d.mts",
64-
"default": "./dist/config/a11y.mjs"
63+
"types": "./dist/config/best-practices.d.mts",
64+
"default": "./dist/config/best-practices.mjs"
6565
}
6666
},
6767
"./declaration-block-no-ignored-properties": {
@@ -74,6 +74,16 @@
7474
"default": "./dist/config/declaration-block-no-ignored-properties.mjs"
7575
}
7676
},
77+
"./high-performance-animation": {
78+
"require": {
79+
"types": "./dist/config/high-performance-animation.d.cts",
80+
"default": "./dist/config/high-performance-animation.cjs"
81+
},
82+
"import": {
83+
"types": "./dist/config/high-performance-animation.d.mts",
84+
"default": "./dist/config/high-performance-animation.mjs"
85+
}
86+
},
7787
"./no-unsupported-browser-features": {
7888
"require": {
7989
"types": "./dist/config/no-unsupported-browser-features.d.cts",
@@ -131,12 +141,15 @@
131141
"types": "index.d.cts",
132142
"typesVersions": {
133143
">=5.0": {
134-
"a11y": [
135-
"./dist/config/a11y.d.ts"
144+
"best-practices": [
145+
"./dist/config/best-practices.d.ts"
136146
],
137147
"declaration-block-no-ignored-properties": [
138148
"./dist/config/declaration-block-no-ignored-properties.d.ts"
139149
],
150+
"high-performance-animation": [
151+
"./dist/config/high-performance-animation.d.ts"
152+
],
140153
"no-unsupported-browser-features": [
141154
"./dist/config/no-unsupported-browser-features.d.ts"
142155
],
@@ -174,7 +187,6 @@
174187
"test:coverage": "vitest --config ./vitest.config.ts --run --coverage"
175188
},
176189
"dependencies": {
177-
"@ronilaukkarinen/stylelint-a11y": "^1.2.9",
178190
"browserslist-config-anolilab": "5.0.14",
179191
"stylelint-config-clean-order": "^7.0.0",
180192
"stylelint-config-standard": "^38.0.0",

packages/stylelint-config/src/config/a11y.ts

Lines changed: 0 additions & 41 deletions
This file was deleted.

packages/stylelint-config/src/config/tailwindcss.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ const config = {
1717
],
1818
},
1919
],
20-
"declaration-block-trailing-semicolon": null,
2120
"function-no-unknown": [
2221
true,
2322
{

0 commit comments

Comments
 (0)