@cloudpss/lint-staged-config 2.1.3 → 3.0.0-rc.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (3) hide show
  1. package/index.d.ts +2 -0
  2. package/index.js +8 -31
  3. package/package.json +6 -5
package/index.d.ts ADDED
@@ -0,0 +1,2 @@
1
+ const config: import('lint-staged').Config;
2
+ export default config;
package/index.js CHANGED
@@ -1,18 +1,19 @@
1
1
  /* eslint-disable no-console */
2
2
 
3
- const path = require('node:path');
3
+ import { getFileInfo } from 'prettier';
4
+ import { loadESLint } from 'eslint';
4
5
 
5
- const prettier = require('prettier');
6
- const eslintCli = new (require('eslint').ESLint)({});
6
+ const eslintCli = new (await loadESLint({ useFlatConfig: true }))();
7
7
 
8
8
  const DEBUG = (process.env['DEBUG'] ?? '').includes('lint-staged-config');
9
9
 
10
10
  /**
11
11
  * 检查文件是否是 prettier 支持的文件
12
12
  * @param {string} f 文件路径
13
+ * @returns {Promise<boolean>}
13
14
  */
14
15
  const isPrettierFile = async (f) => {
15
- const fileInfo = await prettier.getFileInfo(f, {
16
+ const fileInfo = await getFileInfo(f, {
16
17
  ignorePath: ['.prettierignore', '.gitignore'],
17
18
  resolveConfig: false,
18
19
  });
@@ -22,34 +23,17 @@ const isPrettierFile = async (f) => {
22
23
  /**
23
24
  * 检查文件是否是 eslint 支持的文件
24
25
  * @param {string} f 文件路径
26
+ * @returns {Promise<boolean>}
25
27
  */
26
28
  const isEslintFile = async (f) => {
27
- const ext = path.extname(f);
28
- if (!ext || !['.js', '.jsx', '.ts', '.tsx', '.vue'].includes(ext)) return false;
29
29
  return !(await eslintCli.isPathIgnored(f));
30
30
  };
31
31
 
32
- /**
33
- * 检查文件是否是 stylelint 支持的文件
34
- * @param {string} f 文件路径
35
- */
36
- const isStylelintFile = (() => {
37
- try {
38
- require.resolve('stylelint');
39
- return (/** @type {string} */ f) => {
40
- const ext = path.extname(f);
41
- if (!ext || !['.css', '.scss', '.sass'].includes(ext)) return false;
42
- return true;
43
- };
44
- } catch {
45
- return () => false;
46
- }
47
- })();
48
-
49
32
  /**
50
33
  * 生成命令
51
34
  * @param {string[]} files 文件列表
52
35
  * @param {string[]} commands 命令列表
36
+ * @returns {string[]}
53
37
  */
54
38
  function makeCommands(files, commands) {
55
39
  if (files.length === 0) return [];
@@ -76,17 +60,14 @@ function handler(impl) {
76
60
  };
77
61
  }
78
62
 
79
- module.exports = /** @type {import('lint-staged').Config} */ ({
63
+ export default /** @type {import('lint-staged').Config} */ ({
80
64
  '*': handler(async (files) => {
81
65
  const commands = [];
82
66
  const eslintFiles = [];
83
- const stylelintFiles = [];
84
67
  const prettierFiles = [];
85
68
  for (const file of files) {
86
69
  if (await isEslintFile(file)) {
87
70
  eslintFiles.push(file);
88
- } else if (isStylelintFile(file)) {
89
- stylelintFiles.push(file);
90
71
  } else if (await isPrettierFile(file)) {
91
72
  prettierFiles.push(file);
92
73
  }
@@ -98,10 +79,6 @@ module.exports = /** @type {import('lint-staged').Config} */ ({
98
79
  `eslint ${cacheOptions} --cache-location node_modules/.cache/eslint/ --fix --max-warnings 0 --no-error-on-unmatched-pattern`,
99
80
  `git add`,
100
81
  ]),
101
- ...makeCommands(stylelintFiles, [
102
- `stylelint ${cacheOptions} --cache-location node_modules/.cache/stylelint/ --fix`,
103
- `git add`,
104
- ]),
105
82
  ...makeCommands(prettierFiles, [`prettier ${cacheOptions} --write`, `git add`]),
106
83
  );
107
84
  return commands;
package/package.json CHANGED
@@ -3,12 +3,13 @@
3
3
  "license": "MIT",
4
4
  "homepage": "https://cloudpss.net/",
5
5
  "repository": "https://codeup.aliyun.com/cloudpss/code-quality.git",
6
- "version": "2.1.3",
7
- "type": "commonjs",
6
+ "version": "3.0.0-rc.2",
7
+ "type": "module",
8
8
  "main": "./index.js",
9
+ "exports": "./index.js",
9
10
  "dependencies": {
10
- "eslint": "^8.57.0",
11
- "lint-staged": "^15.2.7",
12
- "prettier": "^3.3.2"
11
+ "eslint": "^9.8.0",
12
+ "lint-staged": "^15.2.8",
13
+ "prettier": "^3.3.3"
13
14
  }
14
15
  }