diff --git a/package.json b/package.json index 22e6275..fc1180d 100644 --- a/package.json +++ b/package.json @@ -11,13 +11,12 @@ "node": ">= 18" }, "scripts": { - "test:lint": "standard", + "test:lint": "eslint .", "test:converage": "c8 pnpm unit", "test": "pnpm run /^test:/", "unit": "node --test test/*.test.js", "docs": "jsdoc2md src/*.js > DOCS.md", - "clean": "npx rimraf ./coverage", - "release": "standard-version" + "clean": "npx rimraf ./coverage" }, "funding": [ { @@ -34,17 +33,25 @@ "yaml": "^2.3.4" }, "devDependencies": { + "@logux/eslint-config": "^52.0.2", "@types/node": "^20.10.0", "@types/postcss-import": "^14.0.3", "c8": "^8.0.1", "clean-publish": "^4.2.0", "cssnano": "^6.0.1", + "eslint": "^8.54.0", + "eslint-config-standard": "^17.1.0", + "eslint-plugin-import": "^2.29.0", + "eslint-plugin-n": "^16.3.1", + "eslint-plugin-node-import": "^1.0.4", + "eslint-plugin-perfectionist": "^2.5.0", + "eslint-plugin-prefer-let": "^3.0.1", + "eslint-plugin-promise": "^6.1.1", "jiti": "^1.21.0", "jsdoc-to-markdown": "^8.0.0", "postcss": "^8.4.31", "postcss-import": "^15.1.0", "postcss-nested": "^6.0.1", - "standard": "^17.1.0", "sugarss": "^4.0.1", "typescript": "5.3.2" }, @@ -60,12 +67,21 @@ "optional": true } }, + "eslintConfig": { + "extends": "@logux/eslint-config" + }, "c8": { "exclude": [ "test/**/*" ], "lines": 100, - "check-coverage": true + "check-coverage": true, + "reporter": [ + "text", + "lcov" + ], + "skip-full": true, + "clean": true }, "prettier": { "arrowParens": "avoid", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 240aee2..538dbd0 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -13,6 +13,9 @@ dependencies: version: 2.3.4 devDependencies: + '@logux/eslint-config': + specifier: ^52.0.2 + version: 52.0.2(eslint-config-standard@17.1.0)(eslint-plugin-import@2.29.0)(eslint-plugin-n@16.3.1)(eslint-plugin-node-import@1.0.4)(eslint-plugin-perfectionist@2.5.0)(eslint-plugin-prefer-let@3.0.1)(eslint-plugin-promise@6.1.1)(eslint@8.54.0) '@types/node': specifier: ^20.10.0 version: 20.10.1 @@ -28,6 +31,30 @@ devDependencies: cssnano: specifier: ^6.0.1 version: 6.0.1(postcss@8.4.31) + eslint: + specifier: ^8.54.0 + version: 8.54.0 + eslint-config-standard: + specifier: ^17.1.0 + version: 17.1.0(eslint-plugin-import@2.29.0)(eslint-plugin-n@16.3.1)(eslint-plugin-promise@6.1.1)(eslint@8.54.0) + eslint-plugin-import: + specifier: ^2.29.0 + version: 2.29.0(eslint@8.54.0) + eslint-plugin-n: + specifier: ^16.3.1 + version: 16.3.1(eslint@8.54.0) + eslint-plugin-node-import: + specifier: ^1.0.4 + version: 1.0.4(eslint@8.54.0) + eslint-plugin-perfectionist: + specifier: ^2.5.0 + version: 2.5.0(eslint@8.54.0)(typescript@5.3.2) + eslint-plugin-prefer-let: + specifier: ^3.0.1 + version: 3.0.1 + eslint-plugin-promise: + specifier: ^6.1.1 + version: 6.1.1(eslint@8.54.0) jiti: specifier: ^1.21.0 version: 1.21.0 @@ -176,6 +203,29 @@ packages: lodash: 4.17.21 dev: true + /@logux/eslint-config@52.0.2(eslint-config-standard@17.1.0)(eslint-plugin-import@2.29.0)(eslint-plugin-n@16.3.1)(eslint-plugin-node-import@1.0.4)(eslint-plugin-perfectionist@2.5.0)(eslint-plugin-prefer-let@3.0.1)(eslint-plugin-promise@6.1.1)(eslint@8.54.0): + resolution: {integrity: sha512-oD569Lqs5P/QvlkBLL9GWpKOmI3wXCKb+0VHuY41VVnP8cRpD0LzUbnEqV9pIeld8f9DJwWc+I6JgndtgotElw==} + engines: {node: '>=10.0.0'} + peerDependencies: + eslint: ^8.53.0 + eslint-config-standard: ^17.1.0 + eslint-plugin-import: ^2.29.0 + eslint-plugin-n: ^16.3.1 + eslint-plugin-node-import: ^1.0.4 + eslint-plugin-perfectionist: ^2.4.0 + eslint-plugin-prefer-let: ^3.0.1 + eslint-plugin-promise: ^6.1.1 + dependencies: + eslint: 8.54.0 + eslint-config-standard: 17.1.0(eslint-plugin-import@2.29.0)(eslint-plugin-n@16.3.1)(eslint-plugin-promise@6.1.1)(eslint@8.54.0) + eslint-plugin-import: 2.29.0(eslint@8.54.0) + eslint-plugin-n: 16.3.1(eslint@8.54.0) + eslint-plugin-node-import: 1.0.4(eslint@8.54.0) + eslint-plugin-perfectionist: 2.5.0(eslint@8.54.0)(typescript@5.3.2) + eslint-plugin-prefer-let: 3.0.1 + eslint-plugin-promise: 6.1.1(eslint@8.54.0) + dev: true + /@nodelib/fs.scandir@2.1.5: resolution: {integrity: sha512-vq24Bq3ym5HEQm2NKCr3yXDwjc7vTsEThRDnkp2DK9p1uqLR+DHurm/NOTo0KG7HYHU7eppKZj3MyqYuMBf62g==} engines: {node: '>= 8'} @@ -206,6 +256,10 @@ packages: resolution: {integrity: sha512-2QF/t/auWm0lsy8XtKVPG19v3sSOQlJe/YHZgfjb/KBBHOGSV+J2q/S671rcq9uTBrLAXmZpqJiaQbMT+zNU1w==} dev: true + /@types/json-schema@7.0.15: + resolution: {integrity: sha512-5+fP8P8MFNC+AyZCDxrB2pkZFPGzqQWUzpSeuuVLvm8VMcorNYavBqoFcxK8bQz4Qsbn4oUEEem4wDLfcysGHA==} + dev: true + /@types/json5@0.0.29: resolution: {integrity: sha512-dRLjCWHYg4oaA77cxO64oO+7JwCwnIzkZPdrrC71jQmQtlhM556pwKo5bUzqvZndkVbeFLIIi+9TC40JNF5hNQ==} dev: true @@ -237,6 +291,71 @@ packages: postcss: 8.4.31 dev: true + /@types/semver@7.5.6: + resolution: {integrity: sha512-dn1l8LaMea/IjDoHNd9J52uBbInB796CDffS6VdIxvqYCPSG0V0DzHp76GpaWnlhg88uYyPbXCDIowa86ybd5A==} + dev: true + + /@typescript-eslint/scope-manager@6.13.1: + resolution: {integrity: sha512-BW0kJ7ceiKi56GbT2KKzZzN+nDxzQK2DS6x0PiSMPjciPgd/JRQGMibyaN2cPt2cAvuoH0oNvn2fwonHI+4QUQ==} + engines: {node: ^16.0.0 || >=18.0.0} + dependencies: + '@typescript-eslint/types': 6.13.1 + '@typescript-eslint/visitor-keys': 6.13.1 + dev: true + + /@typescript-eslint/types@6.13.1: + resolution: {integrity: sha512-gjeEskSmiEKKFIbnhDXUyiqVma1gRCQNbVZ1C8q7Zjcxh3WZMbzWVfGE9rHfWd1msQtPS0BVD9Jz9jded44eKg==} + engines: {node: ^16.0.0 || >=18.0.0} + dev: true + + /@typescript-eslint/typescript-estree@6.13.1(typescript@5.3.2): + resolution: {integrity: sha512-sBLQsvOC0Q7LGcUHO5qpG1HxRgePbT6wwqOiGLpR8uOJvPJbfs0mW3jPA3ujsDvfiVwVlWUDESNXv44KtINkUQ==} + engines: {node: ^16.0.0 || >=18.0.0} + peerDependencies: + typescript: '*' + peerDependenciesMeta: + typescript: + optional: true + dependencies: + '@typescript-eslint/types': 6.13.1 + '@typescript-eslint/visitor-keys': 6.13.1 + debug: 4.3.4 + globby: 11.1.0 + is-glob: 4.0.3 + semver: 7.5.4 + ts-api-utils: 1.0.3(typescript@5.3.2) + typescript: 5.3.2 + transitivePeerDependencies: + - supports-color + dev: true + + /@typescript-eslint/utils@6.13.1(eslint@8.54.0)(typescript@5.3.2): + resolution: {integrity: sha512-ouPn/zVoan92JgAegesTXDB/oUp6BP1v8WpfYcqh649ejNc9Qv+B4FF2Ff626kO1xg0wWwwG48lAJ4JuesgdOw==} + engines: {node: ^16.0.0 || >=18.0.0} + peerDependencies: + eslint: ^7.0.0 || ^8.0.0 + dependencies: + '@eslint-community/eslint-utils': 4.4.0(eslint@8.54.0) + '@types/json-schema': 7.0.15 + '@types/semver': 7.5.6 + '@typescript-eslint/scope-manager': 6.13.1 + '@typescript-eslint/types': 6.13.1 + '@typescript-eslint/typescript-estree': 6.13.1(typescript@5.3.2) + eslint: 8.54.0 + semver: 7.5.4 + transitivePeerDependencies: + - supports-color + - typescript + dev: true + + /@typescript-eslint/visitor-keys@6.13.1: + resolution: {integrity: sha512-NDhQUy2tg6XGNBGDRm1XybOHSia8mcXmlbKWoQP+nm1BIIMxa55shyJfZkHpEBN62KNPLrocSM2PdPcaLgDKMQ==} + engines: {node: ^16.0.0 || >=18.0.0} + dependencies: + '@typescript-eslint/types': 6.13.1 + eslint-visitor-keys: 3.4.3 + dev: true + /@ungap/structured-clone@1.2.0: resolution: {integrity: sha512-zuVdFrMJiuCDQUMCzQaD6KL28MjnqqN8XnAqiEq9PNm/hCPTSGfrXCOfwj1ow4LFb/tNymJPwsNbVePc1xFqrQ==} dev: true @@ -339,6 +458,11 @@ packages: is-string: 1.0.7 dev: true + /array-union@2.1.0: + resolution: {integrity: sha512-HGyxoOTYUyCM6stUe6EJgnd4EoewAI7zMdfqO+kGjnlZmBDz/cR5pf8r/cR4Wq60sL/p0IkcjUEEPwS3GFrIyw==} + engines: {node: '>=8'} + dev: true + /array.prototype.findlastindex@1.2.3: resolution: {integrity: sha512-LzLoiOMAxvy+Gd3BAq3B7VeIgPdo+Q8hthvKtXybMvRV0jrXfJM/t8mw7nNlpEcVlVUnCnM2KSX4XU5HmpodOA==} engines: {node: '>= 0.4'} @@ -423,6 +547,12 @@ packages: concat-map: 0.0.1 dev: true + /brace-expansion@2.0.1: + resolution: {integrity: sha512-XnAIvQ8eM+kC6aULx6wuQiwVsnzsi9d3WxzV3FpWTGA19F621kwdbsAcFKXgKUHZWsy+mY6iL1sHTxWEFCytDA==} + dependencies: + balanced-match: 1.0.2 + dev: true + /braces@3.0.2: resolution: {integrity: sha512-b8um+L1RzM3WDSzvhm6gIz1yfTbBt6YTlcEKAvsmqCZZFw46z626lVj9j1yEPW33H5H+lBQpZMP1k8l+78Ha0A==} engines: {node: '>=8'} @@ -441,6 +571,11 @@ packages: update-browserslist-db: 1.0.13(browserslist@4.22.1) dev: true + /builtin-modules@3.3.0: + resolution: {integrity: sha512-zhaCDicdLuWN5UbN5IMnFqNMhNfo919sH85y2/ea+5Yg9TsTkeZxpL+JLbp6cgYFS4sRLp3YV4S6yDuqVWHYOw==} + engines: {node: '>=6'} + dev: true + /builtins@5.0.1: resolution: {integrity: sha512-qwVpFEHNfhYJIzNRBvd2C1kyo6jz3ZSMPyyuR47OPdiKWlbYnZNyDWuyR175qDnAJLiCo5fBBqPb3RiXgWlkOQ==} dependencies: @@ -784,6 +919,13 @@ packages: object-keys: 1.1.1 dev: true + /dir-glob@3.0.1: + resolution: {integrity: sha512-WkrWp9GR4KXfKGYzOLmTuGVi1UWFfws377n9cc55/tb6DuqyF6pcQ5AbiHEshaDpY9v6oaSr2XCDidGmMwdzIA==} + engines: {node: '>=8'} + dependencies: + path-type: 4.0.0 + dev: true + /dmd@6.2.0: resolution: {integrity: sha512-uXWxLF1H7TkUAuoHK59/h/ts5cKavm2LnhrIgJWisip4BVzPoXavlwyoprFFn2CzcahKYgvkfaebS6oxzgflkg==} engines: {node: '>=12'} @@ -969,6 +1111,15 @@ packages: engines: {node: '>=10'} dev: true + /eslint-compat-utils@0.1.2(eslint@8.54.0): + resolution: {integrity: sha512-Jia4JDldWnFNIru1Ehx1H5s9/yxiRHY/TimCuUc0jNexew3cF1gI6CYZil1ociakfWO3rRqFjl1mskBblB3RYg==} + engines: {node: '>=12'} + peerDependencies: + eslint: '>=6.0.0' + dependencies: + eslint: 8.54.0 + dev: true + /eslint-config-standard-jsx@11.0.0(eslint-plugin-react@7.33.2)(eslint@8.54.0): resolution: {integrity: sha512-+1EV/R0JxEK1L0NGolAr8Iktm3Rgotx3BKwgaX+eAuSX8D952LULKtjgZD3F+e6SvibONnhLwoTi9DPxN5LvvQ==} peerDependencies: @@ -994,6 +1145,21 @@ packages: eslint-plugin-promise: 6.1.1(eslint@8.54.0) dev: true + /eslint-config-standard@17.1.0(eslint-plugin-import@2.29.0)(eslint-plugin-n@16.3.1)(eslint-plugin-promise@6.1.1)(eslint@8.54.0): + resolution: {integrity: sha512-IwHwmaBNtDK4zDHQukFDW5u/aTb8+meQWZvNFWkiGmbWjD6bqyuSSBxxXKkCftCUzc1zwCH2m/baCNDLGmuO5Q==} + engines: {node: '>=12.0.0'} + peerDependencies: + eslint: ^8.0.1 + eslint-plugin-import: ^2.25.2 + eslint-plugin-n: '^15.0.0 || ^16.0.0 ' + eslint-plugin-promise: ^6.0.0 + dependencies: + eslint: 8.54.0 + eslint-plugin-import: 2.29.0(eslint@8.54.0) + eslint-plugin-n: 16.3.1(eslint@8.54.0) + eslint-plugin-promise: 6.1.1(eslint@8.54.0) + dev: true + /eslint-import-resolver-node@0.3.9: resolution: {integrity: sha512-WFj2isz22JahUv+B788TlO3N6zL3nNJGU8CcZbPZvVEkBPaJdCV4vy5wyghty5ROFbCRnm132v8BScu5/1BQ8g==} dependencies: @@ -1032,6 +1198,18 @@ packages: - supports-color dev: true + /eslint-plugin-es-x@7.4.0(eslint@8.54.0): + resolution: {integrity: sha512-WJa3RhYzBtl8I37ebY9p76s61UhZyi4KaFOnX2A5r32RPazkXj5yoT6PGnD02dhwzEUj0KwsUdqfKDd/OuvGsw==} + engines: {node: ^14.18.0 || >=16.0.0} + peerDependencies: + eslint: '>=8' + dependencies: + '@eslint-community/eslint-utils': 4.4.0(eslint@8.54.0) + '@eslint-community/regexpp': 4.10.0 + eslint: 8.54.0 + eslint-compat-utils: 0.1.2(eslint@8.54.0) + dev: true + /eslint-plugin-es@4.1.0(eslint@8.54.0): resolution: {integrity: sha512-GILhQTnjYE2WorX5Jyi5i4dz5ALWxBIdQECVQavL6s7cI76IZTDWleTHkxz/QT3kvcs2QlGHvKLYsSlPOlPXnQ==} engines: {node: '>=8.10.0'} @@ -1094,6 +1272,68 @@ packages: semver: 7.5.4 dev: true + /eslint-plugin-n@16.3.1(eslint@8.54.0): + resolution: {integrity: sha512-w46eDIkxQ2FaTHcey7G40eD+FhTXOdKudDXPUO2n9WNcslze/i/HT2qJ3GXjHngYSGDISIgPNhwGtgoix4zeOw==} + engines: {node: '>=16.0.0'} + peerDependencies: + eslint: '>=7.0.0' + dependencies: + '@eslint-community/eslint-utils': 4.4.0(eslint@8.54.0) + builtins: 5.0.1 + eslint: 8.54.0 + eslint-plugin-es-x: 7.4.0(eslint@8.54.0) + get-tsconfig: 4.7.2 + ignore: 5.3.0 + is-builtin-module: 3.2.1 + is-core-module: 2.13.1 + minimatch: 3.1.2 + resolve: 1.22.8 + semver: 7.5.4 + dev: true + + /eslint-plugin-node-import@1.0.4(eslint@8.54.0): + resolution: {integrity: sha512-nn6EkM7+vJCDCXZiM0FDpYSekbhlk5LNoHJm9DlVSucGrsT9WoK+qOxIEm+SwoFBeH73cMHMavioDaHsu22b0Q==} + engines: {node: ^14.18.0 || ^16.0.0 || >= 18.0.0} + peerDependencies: + eslint: '>=7' + dependencies: + eslint: 8.54.0 + dev: true + + /eslint-plugin-perfectionist@2.5.0(eslint@8.54.0)(typescript@5.3.2): + resolution: {integrity: sha512-F6XXcq4mKKUe/SREoMGQqzgw6cgCgf3pFzkFfQVIGtqD1yXVpQjnhTepzhBeZfxZwgMzR9HO4yH4CUhIQ2WBcQ==} + peerDependencies: + astro-eslint-parser: ^0.16.0 + eslint: '>=8.0.0' + svelte: '>=3.0.0' + svelte-eslint-parser: ^0.33.0 + vue-eslint-parser: '>=9.0.0' + peerDependenciesMeta: + astro-eslint-parser: + optional: true + svelte: + optional: true + svelte-eslint-parser: + optional: true + vue-eslint-parser: + optional: true + dependencies: + '@typescript-eslint/utils': 6.13.1(eslint@8.54.0)(typescript@5.3.2) + eslint: 8.54.0 + minimatch: 9.0.3 + natural-compare-lite: 1.4.0 + transitivePeerDependencies: + - supports-color + - typescript + dev: true + + /eslint-plugin-prefer-let@3.0.1: + resolution: {integrity: sha512-vbznkkBSXB63d4o1o0NIm5C2ey3V5wKr/25dAvPdydQXdowAcnr69cbLgxd2YAG81IV5eddCO55Lp6gL7wSE4w==} + engines: {node: '>=0.10.0'} + dependencies: + requireindex: 1.2.0 + dev: true + /eslint-plugin-promise@6.1.1(eslint@8.54.0): resolution: {integrity: sha512-tjqWDwVZQo7UIPMeDReOpUgHCmCiH+ePnVT+5zVapL0uuHnegBUs2smM13CzOs2Xb5+MHMRFTs9v24yjba4Oig==} engines: {node: ^12.22.0 || ^14.17.0 || >=16.0.0} @@ -1402,6 +1642,12 @@ packages: get-intrinsic: 1.2.2 dev: true + /get-tsconfig@4.7.2: + resolution: {integrity: sha512-wuMsz4leaj5hbGgg4IvDU0bqJagpftG5l5cXIAvo8uZrqn0NJqwtfupTN00VnkQJPcIRrxYrm1Ue24btpCha2A==} + dependencies: + resolve-pkg-maps: 1.0.0 + dev: true + /glob-parent@5.1.2: resolution: {integrity: sha512-AOIgSQCepiJYwP3ARnGx+5VnTu2HBYdzbGP45eLw1vr3zB3vZLeyed1sC9hnbcOc9/SrMyM5RPQrkGz4aS9Zow==} engines: {node: '>= 6'} @@ -1441,6 +1687,18 @@ packages: define-properties: 1.2.1 dev: true + /globby@11.1.0: + resolution: {integrity: sha512-jhIXaOzy1sb8IyocaruWSn1TjmnBVs8Ayhcy83rmxNJ8q2uWKCAj3CnJY+KpGSXCueAPc0i05kVvVKtP1t9S3g==} + engines: {node: '>=10'} + dependencies: + array-union: 2.1.0 + dir-glob: 3.0.1 + fast-glob: 3.3.2 + ignore: 5.3.0 + merge2: 1.4.1 + slash: 3.0.0 + dev: true + /gopd@1.0.1: resolution: {integrity: sha512-d65bNlIadxvpb/A2abVdlqKqV563juRnZ1Wtk6s1sIR8uNsXR70xqIzVqxVf1eTqDunwT2MkczEeaezCKTZhwA==} dependencies: @@ -1582,6 +1840,13 @@ packages: has-tostringtag: 1.0.0 dev: true + /is-builtin-module@3.2.1: + resolution: {integrity: sha512-BSLE3HnV2syZ0FK0iMA/yUGplUeMmNz4AW5fnTunbCIqZi4vG3WjJT9FHMy5D69xmAYBHXQhJdALdpwVxV501A==} + engines: {node: '>=6'} + dependencies: + builtin-modules: 3.3.0 + dev: true + /is-callable@1.2.7: resolution: {integrity: sha512-1BC0BVFhS/p0qtw6enp8e+8OD0UrK0oFLztSjNzhcKA3WDuJxxAPXzPuPtKkjEY9UUoEWlX/8fgKeu2S8i9JTA==} engines: {node: '>= 0.4'} @@ -2043,6 +2308,13 @@ packages: brace-expansion: 1.1.11 dev: true + /minimatch@9.0.3: + resolution: {integrity: sha512-RHiac9mvaRw0x3AYRgDC1CxAP7HTcNrrECeA8YYJeWnpo+2Q5CegtZjaotWTWxDG3UeGA1coE05iH1mPjT/2mg==} + engines: {node: '>=16 || 14 >=14.17'} + dependencies: + brace-expansion: 2.0.1 + dev: true + /minimist@1.2.8: resolution: {integrity: sha512-2yyAR8qBkN3YuheJanUpWC5U3bb5osDywNB8RzDVlDwDHbocAJveqqj1u8+SVD7jkWT4yvsHCpWqqWqAxb0zCA==} dev: true @@ -2071,6 +2343,10 @@ packages: hasBin: true dev: true + /natural-compare-lite@1.4.0: + resolution: {integrity: sha512-Tj+HTDSJJKaZnfiuw+iaF9skdPpTo2GtEly5JHnWV/hfv2Qj/9RKsGISQtLh2ox3l5EAGw487hnBee0sIJ6v2g==} + dev: true + /natural-compare@1.4.0: resolution: {integrity: sha512-OWND8ei3VtNC9h7V60qff3SVobHr996CTwgxubgyQYEpg290h9J0buyECNNJexkFm5sOajh5G116RYA1c8ZMSw==} dev: true @@ -2255,6 +2531,11 @@ packages: resolution: {integrity: sha512-LDJzPVEEEPR+y48z93A0Ed0yXb8pAByGWo/k5YYdYgpY2/2EsOsksJrq7lOHxryrVOn1ejG6oAp8ahvOIQD8sw==} dev: true + /path-type@4.0.0: + resolution: {integrity: sha512-gDKb8aZMDeD/tZWs9P6+q0J9Mwkdl6xMV8TjnGP3qJVJ06bdMgkbBlLU8IdfOsIsFz2BW1rNVT3XuNEl8zPAvw==} + engines: {node: '>=8'} + dev: true + /picocolors@1.0.0: resolution: {integrity: sha512-1fygroTLlHu66zi26VoTDv8yRgm0Fccecssto+MhsZ0D/DGW2sm8E8AjW7NU5VVTRt5GxbeZ5qBuJr+HyLYkjQ==} dev: true @@ -2699,6 +2980,11 @@ packages: engines: {node: '>=0.10.0'} dev: true + /requireindex@1.2.0: + resolution: {integrity: sha512-L9jEkOi3ASd9PYit2cwRfyppc9NoABujTP8/5gFcbERmo5jUoAKovIC3fsF17pkTnGsrByysqX+Kxd2OTNI1ww==} + engines: {node: '>=0.10.5'} + dev: true + /requizzle@0.2.4: resolution: {integrity: sha512-JRrFk1D4OQ4SqovXOgdav+K8EAhSB/LJZqCz8tbX0KObcdeM15Ss59ozWMBWmmINMagCwmqn4ZNryUGpBsl6Jw==} dependencies: @@ -2710,6 +2996,10 @@ packages: engines: {node: '>=4'} dev: true + /resolve-pkg-maps@1.0.0: + resolution: {integrity: sha512-seS2Tj26TBVOC2NIc2rOe2y2ZO7efxITtLZcGSOnHHNOQ7CkiUBfw0Iw2ck6xkIhPwLhKNLS8BO+hEpngQlqzw==} + dev: true + /resolve@1.22.8: resolution: {integrity: sha512-oKWePCxqpd6FlLvGV1VU0x7bkPmmCNolxzjMf4NczoDnQcIWrAF+cPtZn5i6n+RfD2d9i0tzpKnG6Yk168yIyw==} hasBin: true @@ -2820,6 +3110,11 @@ packages: resolution: {integrity: sha512-wnD2ZE+l+SPC/uoS0vXeE9L1+0wuaMqKlfz9AMUo38JsyLSBWSFcHR1Rri62LZc12vLr1gb3jl7iwQhgwpAbGQ==} dev: true + /slash@3.0.0: + resolution: {integrity: sha512-g9Q1haeby36OSStwb4ntCGGGaKsaVSjQ68fBxoQcutl5fS1vuY18H3wSt3jFyFtrkx+Kz0V1G85A4MyAdDMi2Q==} + engines: {node: '>=8'} + dev: true + /sort-array@4.1.5: resolution: {integrity: sha512-Ya4peoS1fgFN42RN1REk2FgdNOeLIEMKFGJvs7VTP3OklF8+kl2SkpVliZ4tk/PurWsrWRsdNdU+tgyOBkB9sA==} engines: {node: '>=10'} @@ -3056,6 +3351,15 @@ packages: is-number: 7.0.0 dev: true + /ts-api-utils@1.0.3(typescript@5.3.2): + resolution: {integrity: sha512-wNMeqtMz5NtwpT/UZGY5alT+VoKdSsOOP/kqHFcUW1P/VRhH2wJ48+DN2WwUliNbQ976ETwDL0Ifd2VVvgonvg==} + engines: {node: '>=16.13.0'} + peerDependencies: + typescript: '>=4.2.0' + dependencies: + typescript: 5.3.2 + dev: true + /tsconfig-paths@3.14.2: resolution: {integrity: sha512-o/9iXgCYc5L/JxCHPe3Hvh8Q/2xm5Z+p18PESBU6Ff33695QnCHBEjcytY2q19ua7Mbl/DavtBOLq+oG0RCL+g==} dependencies: diff --git a/src/index.d.ts b/src/index.d.ts index 4979220..30b7d61 100644 --- a/src/index.d.ts +++ b/src/index.d.ts @@ -1,65 +1,65 @@ // based on @types/postcss-load-config@2.0.1 // Type definitions for postcss-load-config 2.1 -import Processor from 'postcss/lib/processor'; -import { Plugin, ProcessOptions, Transformer } from 'postcss'; -import { Options as ConfigOptions } from "lilconfig"; +import Processor from 'postcss/lib/processor' +import { Plugin, ProcessOptions, Transformer } from 'postcss' +import { Options as ConfigOptions } from 'lilconfig' declare function postcssrc( ctx?: postcssrc.ConfigContext, path?: string, options?: ConfigOptions -): Promise; +): Promise declare namespace postcssrc { // In the ConfigContext, these three options can be instances of the // appropriate class, or strings. If they are strings, postcss-load-config will // require() them and pass the instances along. export interface ProcessOptionsPreload { - parser?: string | ProcessOptions['parser']; - stringifier?: string | ProcessOptions['stringifier']; - syntax?: string | ProcessOptions['syntax']; + parser?: string | ProcessOptions['parser'] + stringifier?: string | ProcessOptions['stringifier'] + syntax?: string | ProcessOptions['syntax'] } // The remaining ProcessOptions, sans the three above. export type RemainingProcessOptions = Pick< ProcessOptions, Exclude - >; + > // Additional context options that postcss-load-config understands. export interface Context { - cwd?: string; - env?: string; + cwd?: string + env?: string } // The full shape of the ConfigContext. export type ConfigContext = Context & ProcessOptionsPreload & - RemainingProcessOptions; + RemainingProcessOptions // Result of postcssrc is a Promise containing the filename plus the options // and plugins that are ready to pass on to postcss. - export type ResultPlugin = Plugin | Transformer | Processor; + export type ResultPlugin = Plugin | Transformer | Processor export interface Result { - file: string; - options: ProcessOptions; - plugins: ResultPlugin[]; + file: string + options: ProcessOptions + plugins: ResultPlugin[] } - export type ConfigPlugin = Transformer | Plugin | Processor; + export type ConfigPlugin = Transformer | Plugin | Processor export interface Config { - parser?: string | ProcessOptions['parser'] | false; - stringifier?: string | ProcessOptions['stringifier'] | false; - syntax?: string | ProcessOptions['syntax'] | false; - map?: string | false; - from?: string; - to?: string; - plugins?: Array | Record; + parser?: string | ProcessOptions['parser'] | false + stringifier?: string | ProcessOptions['stringifier'] | false + syntax?: string | ProcessOptions['syntax'] | false + map?: string | false + from?: string + to?: string + plugins?: Array | Record } - export type ConfigFn = (ctx: ConfigContext) => Config | Promise; + export type ConfigFn = (ctx: ConfigContext) => Config | Promise } -export = postcssrc; +export = postcssrc diff --git a/src/index.js b/src/index.js index 082367d..25f3b00 100644 --- a/src/index.js +++ b/src/index.js @@ -1,7 +1,5 @@ -'use strict' - -const resolve = require('path').resolve -const url = require('url') +const { resolve } = require('node:path') +const url = require('node:url') const config = require('lilconfig') const yaml = require('yaml') @@ -11,7 +9,8 @@ const loadPlugins = require('./plugins.js') const TS_EXT_RE = /\.(c|m)?ts$/ -const interopRequireDefault = (obj) => obj && obj.__esModule ? obj : { default: obj } +const interopRequireDefault = obj => + obj && obj.__esModule ? obj : { default: obj } /** * Process the result from cosmiconfig @@ -21,25 +20,27 @@ const interopRequireDefault = (obj) => obj && obj.__esModule ? obj : { default: * * @return {Object} PostCSS Config */ -const processResult = (ctx, result) => { - const file = result.filepath || '' - let config = interopRequireDefault(result.config).default || {} +function processResult(ctx, result) { + let file = result.filepath || '' + let projectConfig = interopRequireDefault(result.config).default || {} - if (typeof config === 'function') { - config = config(ctx) + if (typeof projectConfig === 'function') { + projectConfig = projectConfig(ctx) } else { - config = Object.assign({}, config, ctx) + projectConfig = Object.assign({}, projectConfig, ctx) } - if (!config.plugins) { - config.plugins = [] + if (!projectConfig.plugins) { + projectConfig.plugins = [] } - return { - plugins: loadPlugins(config, file), - options: loadOptions(config, file), - file + let res = { + file, + options: loadOptions(projectConfig, file), + plugins: loadPlugins(projectConfig, file) } + delete projectConfig.plugins + return res } /** @@ -49,17 +50,20 @@ const processResult = (ctx, result) => { * * @return {Object} Config Context */ -const createContext = (ctx) => { +function createContext(ctx) { /** * @type {Object} * * @prop {String} cwd=process.cwd() Config search start location * @prop {String} env=process.env.NODE_ENV Config Enviroment, will be set to `development` by `postcss-load-config` if `process.env.NODE_ENV` is `undefined` */ - ctx = Object.assign({ - cwd: process.cwd(), - env: process.env.NODE_ENV - }, ctx) + ctx = Object.assign( + { + cwd: process.cwd(), + env: process.env.NODE_ENV + }, + ctx + ) if (!ctx.env) { process.env.NODE_ENV = 'development' @@ -71,9 +75,9 @@ const createContext = (ctx) => { /** @type {import('jiti').JITI | null} */ let jiti = null -const loader = async filepath => { +async function loader(filepath) { try { - const module = await import(url.pathToFileURL(filepath).href) + let module = await import(url.pathToFileURL(filepath).href) return module.default } catch (err) { /* c8 ignore start */ @@ -85,16 +89,16 @@ const loader = async filepath => { jiti = (await import('jiti')).default(__filename, { interopDefault: true }) - } catch (err) { + } catch (jitiErr) { if ( - err.code === 'ERR_MODULE_NOT_FOUND' && - err.message.includes("Cannot find package 'jiti'") + jitiErr.code === 'ERR_MODULE_NOT_FOUND' && + jitiErr.message.includes("Cannot find package 'jiti'") ) { throw new Error( - `'jiti' is required for the TypeScript configuration files. Make sure it is installed\nError: ${err.message}` + `'jiti' is required for the TypeScript configuration files. Make sure it is installed\nError: ${jitiErr.message}` ) } - throw err + throw jitiErr } /* c8 ignore stop */ } @@ -103,10 +107,21 @@ const loader = async filepath => { } const withLoaders = (options = {}) => { - const moduleName = 'postcss' + let moduleName = 'postcss' return { ...options, + loaders: { + ...options.loaders, + '.cjs': loader, + '.cts': loader, + '.js': loader, + '.mjs': loader, + '.mts': loader, + '.ts': loader, + '.yaml': (filepath, content) => yaml.parse(content), + '.yml': (filepath, content) => yaml.parse(content) + }, searchPlaces: [ ...(options.searchPlaces || []), 'package.json', @@ -126,18 +141,7 @@ const withLoaders = (options = {}) => { `${moduleName}.config.js`, `${moduleName}.config.cjs`, `${moduleName}.config.mjs` - ], - loaders: { - ...options.loaders, - '.yaml': (filepath, content) => yaml.parse(content), - '.yml': (filepath, content) => yaml.parse(content), - '.js': loader, - '.cjs': loader, - '.mjs': loader, - '.ts': loader, - '.cts': loader, - '.mts': loader - } + ] } } @@ -152,7 +156,7 @@ const withLoaders = (options = {}) => { * * @return {Promise} config PostCSS Config */ -const rc = (ctx, path, options) => { +function rc(ctx, path, options) { /** * @type {Object} The full Config Context */ @@ -163,13 +167,13 @@ const rc = (ctx, path, options) => { */ path = path ? resolve(path) : process.cwd() - return config.lilconfig('postcss', withLoaders(options)) + return config + .lilconfig('postcss', withLoaders(options)) .search(path) - .then((result) => { + .then(result => { if (!result) { throw new Error(`No PostCSS Config found in: ${path}`) } - return processResult(ctx, result) }) } diff --git a/src/options.js b/src/options.js index d3ef2d6..48c13c5 100644 --- a/src/options.js +++ b/src/options.js @@ -1,5 +1,3 @@ -'use strict' - const req = require('./req.js') /** @@ -12,12 +10,14 @@ const req = require('./req.js') * * @return {Object} options PostCSS Options */ -const options = (config, file) => { +function options(config, file) { if (config.parser && typeof config.parser === 'string') { try { config.parser = req(config.parser, file) } catch (err) { - throw new Error(`Loading PostCSS Parser failed: ${err.message}\n\n(@${file})`) + throw new Error( + `Loading PostCSS Parser failed: ${err.message}\n\n(@${file})` + ) } } @@ -25,7 +25,9 @@ const options = (config, file) => { try { config.syntax = req(config.syntax, file) } catch (err) { - throw new Error(`Loading PostCSS Syntax failed: ${err.message}\n\n(@${file})`) + throw new Error( + `Loading PostCSS Syntax failed: ${err.message}\n\n(@${file})` + ) } } @@ -33,14 +35,12 @@ const options = (config, file) => { try { config.stringifier = req(config.stringifier, file) } catch (err) { - throw new Error(`Loading PostCSS Stringifier failed: ${err.message}\n\n(@${file})`) + throw new Error( + `Loading PostCSS Stringifier failed: ${err.message}\n\n(@${file})` + ) } } - if (config.plugins) { - delete config.plugins - } - return config } diff --git a/src/plugins.js b/src/plugins.js index 6cb994b..8dacee9 100644 --- a/src/plugins.js +++ b/src/plugins.js @@ -1,5 +1,3 @@ -'use strict' - const req = require('./req.js') /** @@ -13,7 +11,7 @@ const req = require('./req.js') * * @return {Function} PostCSS Plugin */ -const load = (plugin, options, file) => { +function load(plugin, options, file) { try { if ( options === null || @@ -25,7 +23,9 @@ const load = (plugin, options, file) => { return req(plugin, file)(options) } } catch (err) { - throw new Error(`Loading PostCSS Plugin failed: ${err.message}\n\n(@${file})`) + throw new Error( + `Loading PostCSS Plugin failed: ${err.message}\n\n(@${file})` + ) } } @@ -39,23 +39,23 @@ const load = (plugin, options, file) => { * * @return {Array} plugins PostCSS Plugins */ -const plugins = (config, file) => { - let plugins = [] +function plugins(config, file) { + let list = [] if (Array.isArray(config.plugins)) { - plugins = config.plugins.filter(Boolean) + list = config.plugins.filter(Boolean) } else { - plugins = Object.keys(config.plugins) - .filter((plugin) => { + list = Object.keys(config.plugins) + .filter(plugin => { return config.plugins[plugin] !== false ? plugin : '' }) - .map((plugin) => { + .map(plugin => { return load(plugin, config.plugins[plugin], file) }) } - if (plugins.length && plugins.length > 0) { - plugins.forEach((plugin, i) => { + if (list.length && list.length > 0) { + list.forEach((plugin, i) => { if (plugin.default) { plugin = plugin.default } @@ -71,15 +71,17 @@ const plugins = (config, file) => { !( (typeof plugin === 'object' && Array.isArray(plugin.plugins)) || (typeof plugin === 'object' && plugin.postcssPlugin) || - (typeof plugin === 'function') + typeof plugin === 'function' ) ) { - throw new TypeError(`Invalid PostCSS Plugin found at: plugins[${i}]\n\n(@${file})`) + throw new TypeError( + `Invalid PostCSS Plugin found at: plugins[${i}]\n\n(@${file})` + ) } }) } - return plugins + return list } module.exports = plugins diff --git a/src/req.js b/src/req.js index 42020c9..ddebb85 100644 --- a/src/req.js +++ b/src/req.js @@ -1,9 +1,9 @@ // eslint-disable-next-line n/no-deprecated-api -const { createRequire, createRequireFromPath } = require('module') +const { createRequire, createRequireFromPath } = require('node:module') function req (name, rootFile) { - const create = createRequire || createRequireFromPath - const require = create(rootFile) + let create = createRequire || createRequireFromPath + let require = create(rootFile) return require(name) } diff --git a/test/Errors.test.js b/test/Errors.test.js index dde382d..bc3c467 100644 --- a/test/Errors.test.js +++ b/test/Errors.test.js @@ -1,4 +1,4 @@ -const { test, describe } = require('node:test') +const { describe, test } = require('node:test') const { match } = require('node:assert') const postcssrc = require('../src/index.js') diff --git a/test/js.test.js b/test/js.test.js index 244ac28..70309ee 100644 --- a/test/js.test.js +++ b/test/js.test.js @@ -1,11 +1,11 @@ -const path = require('path') -const { test, describe } = require('node:test') -const { equal, deepStrictEqual } = require('node:assert') +const path = require('node:path') +const { describe, test } = require('node:test') +const { deepStrictEqual, equal } = require('node:assert') const postcss = require('postcss') const postcssrc = require('../src/index.js') -const { fixture, expected } = require('./utils.js') +const { expected, fixture } = require('./utils.js') const ctx = { parser: true, @@ -14,33 +14,34 @@ const ctx = { describe('Object', () => { test('Load Config - postcss.config.mjs', async () => { - const config = await postcssrc(ctx, 'test/js/object/esm') + let config = await postcssrc(ctx, 'test/js/object/esm') assertExpectedConfig(config, 'test/js/object/esm/postcss.config.mjs') }) test('Load Config - postcss.config.js (ESM)', async () => { - const config = await postcssrc(ctx, 'test/js/object/esm-in-js') + let config = await postcssrc(ctx, 'test/js/object/esm-in-js') assertExpectedConfig(config, 'test/js/object/esm-in-js/postcss.config.js') }) test('Load Config - postcss.config.cjs', async () => { - const config = await postcssrc(ctx, 'test/js/object/cjs') + let config = await postcssrc(ctx, 'test/js/object/cjs') assertExpectedConfig(config, 'test/js/object/cjs/postcss.config.cjs') }) test('Load Config - postcss.config.js (CommonJS)', async () => { - const config = await postcssrc(ctx, 'test/js/object/cjs-in-js') + let config = await postcssrc(ctx, 'test/js/object/cjs-in-js') assertExpectedConfig(config, 'test/js/object/cjs-in-js/postcss.config.js') }) test('Process CSS - postcss.config.js (CommonJS)', async () => { - const ctx = { - parser: false, - syntax: false - } - - const config = await postcssrc(ctx, 'test/js/object/cjs-in-js') - const result = await postcss(config.plugins).process( + let config = await postcssrc( + { + parser: false, + syntax: false + }, + 'test/js/object/cjs-in-js' + ) + let result = await postcss(config.plugins).process( fixture('js/object', 'index.css'), config.options ) @@ -48,26 +49,27 @@ describe('Object', () => { }) test('Process SSS - postcss.config.js (CommonJS)', async () => { - const ctx = { - from: './test/js/object/fixtures/index.sss', - parser: true, - syntax: false - } - - const config = await postcssrc(ctx, 'test/js/object/cjs-in-js') - const result = await postcss(config.plugins).process( + let config = await postcssrc( + { + from: './test/js/object/fixtures/index.sss', + parser: true, + syntax: false + }, + 'test/js/object/cjs-in-js' + ) + let result = await postcss(config.plugins).process( fixture('js/object', 'index.sss'), config.options ) equal(result.css, expected('js/object', 'index.sss')) }) - function assertExpectedConfig (config, expectedConfigPath) { + function assertExpectedConfig(config, expectedConfigPath) { deepStrictEqual(config.options, { + from: './test/js/object/fixtures/index.css', + map: false, parser: require('sugarss'), syntax: require('sugarss'), - map: false, - from: './test/js/object/fixtures/index.css', to: './test/js/object/expect/index.css' }) @@ -81,33 +83,34 @@ describe('Object', () => { describe('Array', () => { test('Load Config - postcss.config.mjs', async () => { - const config = await postcssrc(ctx, 'test/js/array/esm') + let config = await postcssrc(ctx, 'test/js/array/esm') assertExpectedConfig(config, 'test/js/array/esm/postcss.config.mjs') }) test('Load Config - postcss.config.js (ESM)', async () => { - const config = await postcssrc(ctx, 'test/js/array/esm-in-js') + let config = await postcssrc(ctx, 'test/js/array/esm-in-js') assertExpectedConfig(config, 'test/js/array/esm-in-js/postcss.config.js') }) test('Load Config - postcss.config.cjs', async () => { - const config = await postcssrc(ctx, 'test/js/array/cjs') + let config = await postcssrc(ctx, 'test/js/array/cjs') assertExpectedConfig(config, 'test/js/array/cjs/postcss.config.cjs') }) test('Load Config - postcss.config.js (CommonJS)', async () => { - const config = await postcssrc(ctx, 'test/js/array/cjs-in-js') + let config = await postcssrc(ctx, 'test/js/array/cjs-in-js') assertExpectedConfig(config, 'test/js/array/cjs-in-js/postcss.config.js') }) test('Process CSS - postcss.config.js (CommonJS)', async () => { - const ctx = { - parser: false, - syntax: false - } - - const config = await postcssrc(ctx, 'test/js/array/cjs') - const result = await postcss(config.plugins).process( + let config = await postcssrc( + { + parser: false, + syntax: false + }, + 'test/js/array/cjs' + ) + let result = await postcss(config.plugins).process( fixture('js/array', 'index.css'), config.options ) @@ -115,14 +118,15 @@ describe('Array', () => { }) test('Process SSS - postcss.config.js (CommonJS)', async () => { - const ctx = { - from: './test/js/array/fixtures/index.sss', - parser: true, - syntax: false - } - - const config = await postcssrc(ctx, 'test/js/array/cjs') - const result = await postcss(config.plugins).process( + let config = await postcssrc( + { + from: './test/js/array/fixtures/index.sss', + parser: true, + syntax: false + }, + 'test/js/array/cjs' + ) + let result = await postcss(config.plugins).process( fixture('js/array', 'index.sss'), config.options ) @@ -130,12 +134,12 @@ describe('Array', () => { equal(result.css, expected('js/array', 'index.sss')) }) - function assertExpectedConfig (config, expectedPath) { + function assertExpectedConfig(config, expectedPath) { deepStrictEqual(config.options, { + from: './test/js/array/fixtures/index.css', + map: false, parser: require('sugarss'), syntax: require('sugarss'), - map: false, - from: './test/js/array/fixtures/index.css', to: './test/js/array/expect/index.css' }) diff --git a/test/pkg.test.js b/test/pkg.test.js index d0eb9ef..b7cbe3c 100644 --- a/test/pkg.test.js +++ b/test/pkg.test.js @@ -1,39 +1,38 @@ -const path = require('path') -const { test, describe } = require('node:test') +const path = require('node:path') +const { describe, test } = require('node:test') const { equal } = require('node:assert') const postcss = require('postcss') const postcssrc = require('../src/index.js') -const { fixture, expected } = require('./utils.js') +const { expected, fixture } = require('./utils.js') describe('package.json - {Object} - Load Config', () => { - const expected = config => { - equal(config.options.parser, require('sugarss')) - equal(config.options.syntax, require('sugarss')) - equal(config.options.map, false) - equal(config.options.from, './test/pkg/fixtures/index.css') - equal(config.options.to, './test/pkg/expect/index.css') - - equal(config.plugins.length, 2) - equal(typeof config.plugins[0], 'function') - equal(typeof config.plugins[1], 'function') - - equal(config.file, path.resolve('test/pkg', 'package.json')) - } - test('Async', () => { - return postcssrc({}, 'test/pkg').then(expected) + return postcssrc({}, 'test/pkg').then(config => { + equal(config.options.parser, require('sugarss')) + equal(config.options.syntax, require('sugarss')) + equal(config.options.map, false) + equal(config.options.from, './test/pkg/fixtures/index.css') + equal(config.options.to, './test/pkg/expect/index.css') + + equal(config.plugins.length, 2) + equal(typeof config.plugins[0], 'function') + equal(typeof config.plugins[1], 'function') + + equal(config.file, path.resolve('test/pkg', 'package.json')) + }) }) }) test('package.json - {Object} - Process CSS', () => { - const ctx = { - parser: false, - syntax: false - } - - return postcssrc(ctx, 'test/pkg').then(config => { + return postcssrc( + { + parser: false, + syntax: false + }, + 'test/pkg' + ).then(config => { return postcss(config.plugins) .process(fixture('pkg', 'index.css'), config.options) .then(result => { @@ -43,12 +42,13 @@ test('package.json - {Object} - Process CSS', () => { }) test('package.json - {Object} - Process SSS', () => { - const ctx = { - from: './test/pkg/fixtures/index.sss', - syntax: false - } - - return postcssrc(ctx, 'test/pkg').then(config => { + return postcssrc( + { + from: './test/pkg/fixtures/index.sss', + syntax: false + }, + 'test/pkg' + ).then(config => { return postcss(config.plugins) .process(fixture('pkg', 'index.sss'), config.options) .then(result => { diff --git a/test/plugins.test.js b/test/plugins.test.js index 8d2b3f1..fe67e57 100644 --- a/test/plugins.test.js +++ b/test/plugins.test.js @@ -9,6 +9,6 @@ const ctx = { } test('Interop default in validation', async () => { - const config = await postcssrc(ctx, 'test/plugins') + let config = await postcssrc(ctx, 'test/plugins') equal(config.plugins[0].default.called, true) }) diff --git a/test/rc.test.js b/test/rc.test.js index 44e68f8..643e3f5 100644 --- a/test/rc.test.js +++ b/test/rc.test.js @@ -1,34 +1,32 @@ -const path = require('path') -const { test, describe } = require('node:test') +const path = require('node:path') +const { describe, test } = require('node:test') const { equal } = require('node:assert') const postcss = require('postcss') const postcssrc = require('../src/index.js') -const { fixture, expected } = require('./utils.js') +const { expected, fixture } = require('./utils.js') describe('.postcssrc - {Object} - Load Config', () => { - const expected = config => { - equal(config.options.parser, require('sugarss')) - equal(config.options.syntax, require('sugarss')) - equal(config.options.map, false) - equal(config.options.from, './test/rc/fixtures/index.css') - equal(config.options.to, './test/rc/expect/index.css') - - equal(config.plugins.length, 2) - equal(typeof config.plugins[0], 'function') - equal(typeof config.plugins[1], 'function') - - equal(config.file, path.resolve('test/rc', '.postcssrc')) - } - test('Async', () => { - return postcssrc({}, 'test/rc').then(expected) + return postcssrc({}, 'test/rc').then(config => { + equal(config.options.parser, require('sugarss')) + equal(config.options.syntax, require('sugarss')) + equal(config.options.map, false) + equal(config.options.from, './test/rc/fixtures/index.css') + equal(config.options.to, './test/rc/expect/index.css') + + equal(config.plugins.length, 2) + equal(typeof config.plugins[0], 'function') + equal(typeof config.plugins[1], 'function') + + equal(config.file, path.resolve('test/rc', '.postcssrc')) + }) }) }) test('.postcssrc - {Object} - Process CSS', () => { - const ctx = { + let ctx = { parser: false, syntax: false } @@ -43,7 +41,7 @@ test('.postcssrc - {Object} - Process CSS', () => { }) test('.postcssrc - {Object} - Process SSS', () => { - const ctx = { + let ctx = { from: './test/rc/fixtures/index.sss', syntax: false } diff --git a/test/ts.test.js b/test/ts.test.js index 62c3980..0aa72df 100644 --- a/test/ts.test.js +++ b/test/ts.test.js @@ -1,11 +1,11 @@ -const path = require('path') -const { test, describe } = require('node:test') -const { equal, deepStrictEqual } = require('node:assert') +const path = require('node:path') +const { describe, test } = require('node:test') +const { deepStrictEqual, equal } = require('node:assert') const postcss = require('postcss') const postcssrc = require('../src/index.js') -const { fixture, expected } = require('./utils.js') +const { expected, fixture } = require('./utils.js') const ctx = { parser: true, @@ -14,33 +14,34 @@ const ctx = { describe('Object', () => { test('Load Config - postcss.config.mts', async () => { - const config = await postcssrc(ctx, 'test/ts/object/esm') + let config = await postcssrc(ctx, 'test/ts/object/esm') assertExpectedConfig(config, 'test/ts/object/esm/postcss.config.mts') }) test('Load Config - postcss.config.ts (ESM)', async () => { - const config = await postcssrc(ctx, 'test/ts/object/esm-in-ts') + let config = await postcssrc(ctx, 'test/ts/object/esm-in-ts') assertExpectedConfig(config, 'test/ts/object/esm-in-ts/postcss.config.ts') }) test('Load Config - postcss.config.cts', async () => { - const config = await postcssrc(ctx, 'test/ts/object/cjs') + let config = await postcssrc(ctx, 'test/ts/object/cjs') assertExpectedConfig(config, 'test/ts/object/cjs/postcss.config.cts') }) test('Load Config - postcss.config.ts (CommonJS)', async () => { - const config = await postcssrc(ctx, 'test/ts/object/cjs-in-ts') + let config = await postcssrc(ctx, 'test/ts/object/cjs-in-ts') assertExpectedConfig(config, 'test/ts/object/cjs-in-ts/postcss.config.ts') }) test('Process CSS - postcss.config.ts (CommonJS)', async () => { - const ctx = { - parser: false, - syntax: false - } - - const config = await postcssrc(ctx, 'test/ts/object/cjs-in-ts') - const result = await postcss(config.plugins).process( + let config = await postcssrc( + { + parser: false, + syntax: false + }, + 'test/ts/object/cjs-in-ts' + ) + let result = await postcss(config.plugins).process( fixture('ts/object', 'index.css'), config.options ) @@ -48,26 +49,27 @@ describe('Object', () => { }) test('Process SSS - postcss.config.ts (CommonJS)', async () => { - const ctx = { - from: './test/ts/object/fixtures/index.sss', - parser: true, - syntax: false - } - - const config = await postcssrc(ctx, 'test/ts/object/cjs-in-ts') - const result = await postcss(config.plugins).process( + let config = await postcssrc( + { + from: './test/ts/object/fixtures/index.sss', + parser: true, + syntax: false + }, + 'test/ts/object/cjs-in-ts' + ) + let result = await postcss(config.plugins).process( fixture('ts/object', 'index.sss'), config.options ) equal(result.css, expected('ts/object', 'index.sss')) }) - function assertExpectedConfig (config, expectedConfigPath) { + function assertExpectedConfig(config, expectedConfigPath) { deepStrictEqual(config.options, { + from: './test/ts/object/fixtures/index.css', + map: false, parser: require('sugarss'), syntax: require('sugarss'), - map: false, - from: './test/ts/object/fixtures/index.css', to: './test/ts/object/expect/index.css' }) @@ -81,33 +83,34 @@ describe('Object', () => { describe('Array', () => { test('Load Config - postcss.config.mts', async () => { - const config = await postcssrc(ctx, 'test/ts/array/esm') + let config = await postcssrc(ctx, 'test/ts/array/esm') assertExpectedConfig(config, 'test/ts/array/esm/postcss.config.mts') }) test('Load Config - postcss.config.ts (ESM)', async () => { - const config = await postcssrc(ctx, 'test/ts/array/esm-in-ts') + let config = await postcssrc(ctx, 'test/ts/array/esm-in-ts') assertExpectedConfig(config, 'test/ts/array/esm-in-ts/postcss.config.ts') }) test('Load Config - postcss.config.cts', async () => { - const config = await postcssrc(ctx, 'test/ts/array/cjs') + let config = await postcssrc(ctx, 'test/ts/array/cjs') assertExpectedConfig(config, 'test/ts/array/cjs/postcss.config.cts') }) test('Load Config - postcss.config.ts (CommonJS)', async () => { - const config = await postcssrc(ctx, 'test/ts/array/cjs-in-ts') + let config = await postcssrc(ctx, 'test/ts/array/cjs-in-ts') assertExpectedConfig(config, 'test/ts/array/cjs-in-ts/postcss.config.ts') }) test('Process CSS - postcss.config.ts (CommonJS)', async () => { - const ctx = { - parser: false, - syntax: false - } - - const config = await postcssrc(ctx, 'test/ts/array/cjs') - const result = await postcss(config.plugins).process( + let config = await postcssrc( + { + parser: false, + syntax: false + }, + 'test/ts/array/cjs' + ) + let result = await postcss(config.plugins).process( fixture('ts/array', 'index.css'), config.options ) @@ -115,14 +118,15 @@ describe('Array', () => { }) test('Process SSS - postcss.config.ts (CommonJS)', async () => { - const ctx = { - from: './test/ts/array/fixtures/index.sss', - parser: true, - syntax: false - } - - const config = await postcssrc(ctx, 'test/ts/array/cjs') - const result = await postcss(config.plugins).process( + let config = await postcssrc( + { + from: './test/ts/array/fixtures/index.sss', + parser: true, + syntax: false + }, + 'test/ts/array/cjs' + ) + let result = await postcss(config.plugins).process( fixture('ts/array', 'index.sss'), config.options ) @@ -130,12 +134,12 @@ describe('Array', () => { equal(result.css, expected('ts/array', 'index.sss')) }) - function assertExpectedConfig (config, expectedPath) { + function assertExpectedConfig(config, expectedPath) { deepStrictEqual(config.options, { + from: './test/ts/array/fixtures/index.css', + map: false, parser: require('sugarss'), syntax: require('sugarss'), - map: false, - from: './test/ts/array/fixtures/index.css', to: './test/ts/array/expect/index.css' }) diff --git a/test/utils.js b/test/utils.js index 2c11727..ec2bf98 100644 --- a/test/utils.js +++ b/test/utils.js @@ -1,7 +1,7 @@ 'use strict' -const fs = require('fs') -const path = require('path') +const fs = require('node:fs') +const path = require('node:path') const fixture = (dir, file) => { return fs.readFileSync(path.resolve('test', dir, 'fixtures', file), 'utf8') @@ -12,6 +12,6 @@ const expected = (dir, file) => { } module.exports = { - fixture, - expected + expected, + fixture }