fenge 0.1.8 → 0.2.0-beta.1
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.
- package/CHANGELOG.md +41 -0
- package/README.md +3 -4
- package/package.json +13 -10
- package/src/bin/cli.js +1 -1
- package/src/command/format.js +29 -10
- package/src/command/lint.js +28 -11
- package/src/utils.js +27 -17
- package/tsconfig.json +1 -1
- package/tsconfig.build.json +0 -5
- /package/tsconfig/{tsconfig.json → index.json} +0 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,46 @@
|
|
|
1
1
|
# fenge
|
|
2
2
|
|
|
3
|
+
## 0.2.0-beta.1
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- c7a01e8: refactor(eslint-config): replace `override` and `extend` properties with `append` property for overriding or extending the built-in rules
|
|
8
|
+
- db82f69: feat(fenge): use local ESLint and Prettier first
|
|
9
|
+
|
|
10
|
+
### Patch Changes
|
|
11
|
+
|
|
12
|
+
- Updated dependencies [c7a01e8]
|
|
13
|
+
- Updated dependencies [c5a6425]
|
|
14
|
+
- Updated dependencies [d54f6af]
|
|
15
|
+
- Updated dependencies [740fdb7]
|
|
16
|
+
- @fenge/eslint-config@0.4.0-beta.1
|
|
17
|
+
- @fenge/types@0.2.0-beta.1
|
|
18
|
+
|
|
19
|
+
## 0.2.0-beta.0
|
|
20
|
+
|
|
21
|
+
### Minor Changes
|
|
22
|
+
|
|
23
|
+
- be7e3d5: chore(fenge): upgrade `prettier` to 3.4.1
|
|
24
|
+
- 4c6fa59: refactor(fenge): optimize tsconfig exports and rename tsconfig.json to index.json
|
|
25
|
+
|
|
26
|
+
### Patch Changes
|
|
27
|
+
|
|
28
|
+
- Updated dependencies [5adeeed]
|
|
29
|
+
- Updated dependencies [36d1fb0]
|
|
30
|
+
- Updated dependencies [3605e14]
|
|
31
|
+
- Updated dependencies [0d71378]
|
|
32
|
+
- Updated dependencies [a5fb6f8]
|
|
33
|
+
- Updated dependencies [41c783a]
|
|
34
|
+
- Updated dependencies [b1fc095]
|
|
35
|
+
- Updated dependencies [3f4e737]
|
|
36
|
+
- Updated dependencies [1f5fce3]
|
|
37
|
+
- Updated dependencies [51502cc]
|
|
38
|
+
- Updated dependencies [2f12ec2]
|
|
39
|
+
- @fenge/prettier-config@0.1.3-beta.0
|
|
40
|
+
- @fenge/eslint-config@0.4.0-beta.0
|
|
41
|
+
- @fenge/types@0.2.0-beta.0
|
|
42
|
+
- @fenge/tsconfig@0.1.1-beta.0
|
|
43
|
+
|
|
3
44
|
## 0.1.8
|
|
4
45
|
|
|
5
46
|
### Patch Changes
|
package/README.md
CHANGED
|
@@ -125,7 +125,7 @@ Config `tsconfig.json` file in your project root.
|
|
|
125
125
|
}
|
|
126
126
|
```
|
|
127
127
|
|
|
128
|
-
Config `tsconfig.build.json` file in
|
|
128
|
+
Config `tsconfig.build.json` file in your project root.
|
|
129
129
|
|
|
130
130
|
```json
|
|
131
131
|
{
|
|
@@ -242,9 +242,8 @@ export default {
|
|
|
242
242
|
omit: ["no-var"], // these rules will not work for js files
|
|
243
243
|
})
|
|
244
244
|
.enableTypescript({
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
// apply additional rules for ts files
|
|
245
|
+
// apply additional rules or override the built-in rules for ts files
|
|
246
|
+
append: {
|
|
248
247
|
"@typescript-eslint/no-explicit-any": "error",
|
|
249
248
|
"@typescript-eslint/consistent-type-assertions": [
|
|
250
249
|
"error",
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "fenge",
|
|
3
|
-
"version": "0.1
|
|
3
|
+
"version": "0.2.0-beta.1",
|
|
4
4
|
"description": "A CLI tool for code quality",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"cli",
|
|
@@ -35,9 +35,12 @@
|
|
|
35
35
|
"./types": {
|
|
36
36
|
"types": "./types/index.d.ts"
|
|
37
37
|
},
|
|
38
|
-
"./tsconfig": "./tsconfig/
|
|
39
|
-
"./tsconfig
|
|
40
|
-
"./tsconfig
|
|
38
|
+
"./tsconfig": "./tsconfig/index.json",
|
|
39
|
+
"./tsconfig.json": "./tsconfig/index.json",
|
|
40
|
+
"./tsconfig/esm": "./tsconfig/esm.json",
|
|
41
|
+
"./tsconfig/esm.json": "./tsconfig/esm.json",
|
|
42
|
+
"./tsconfig/cjs": "./tsconfig/cjs.json",
|
|
43
|
+
"./tsconfig/cjs.json": "./tsconfig/cjs.json"
|
|
41
44
|
},
|
|
42
45
|
"bin": "./src/bin/cli.js",
|
|
43
46
|
"dependencies": {
|
|
@@ -47,11 +50,11 @@
|
|
|
47
50
|
"lilconfig": "3.1.2",
|
|
48
51
|
"lint-staged": "15.2.10",
|
|
49
52
|
"ora": "8.1.1",
|
|
50
|
-
"prettier": "3.
|
|
51
|
-
"@fenge/eslint-config": "0.
|
|
52
|
-
"@fenge/prettier-config": "0.1.
|
|
53
|
-
"@fenge/tsconfig": "0.1.0",
|
|
54
|
-
"@fenge/types": "0.
|
|
53
|
+
"prettier": "3.4.1",
|
|
54
|
+
"@fenge/eslint-config": "0.4.0-beta.1",
|
|
55
|
+
"@fenge/prettier-config": "0.1.3-beta.0",
|
|
56
|
+
"@fenge/tsconfig": "0.1.1-beta.0",
|
|
57
|
+
"@fenge/types": "0.2.0-beta.1",
|
|
55
58
|
"prettier-ignore": "0.1.3"
|
|
56
59
|
},
|
|
57
60
|
"devDependencies": {
|
|
@@ -69,6 +72,6 @@
|
|
|
69
72
|
"node": ">=18"
|
|
70
73
|
},
|
|
71
74
|
"scripts": {
|
|
72
|
-
"build": "tsc --noEmit
|
|
75
|
+
"build": "tsc --noEmit"
|
|
73
76
|
}
|
|
74
77
|
}
|
package/src/bin/cli.js
CHANGED
|
@@ -29,7 +29,7 @@ program
|
|
|
29
29
|
.option("-c, --config <path>", "path to configuration file")
|
|
30
30
|
.option(
|
|
31
31
|
"--default",
|
|
32
|
-
"force to use built-in default config, ignore specified config and local
|
|
32
|
+
"force to use built-in default config, built-in prettier and built-in eslint. ignore specified config, local config, local prettier and local eslint",
|
|
33
33
|
)
|
|
34
34
|
.option(
|
|
35
35
|
"-d, --dry-run",
|
package/src/command/format.js
CHANGED
|
@@ -9,22 +9,21 @@ import { dir, execAsync, getBinPath } from "../utils.js";
|
|
|
9
9
|
* @param {{update?: boolean, write?: boolean, dryRun?: boolean, config?: string, default?: boolean}} options
|
|
10
10
|
*/
|
|
11
11
|
export async function format(paths = [], options = {}) {
|
|
12
|
-
const {
|
|
13
|
-
|
|
12
|
+
const {
|
|
13
|
+
update = false,
|
|
14
|
+
write = false,
|
|
15
|
+
dryRun = false,
|
|
16
|
+
config,
|
|
17
|
+
default: useDefaultConfig = false,
|
|
18
|
+
} = options;
|
|
14
19
|
|
|
15
|
-
if (config) {
|
|
16
|
-
process.env["FENGE_CONFIG"] = config;
|
|
17
|
-
}
|
|
18
|
-
if (useDefaultConfig) {
|
|
19
|
-
process.env["FENGE_USE_DEFAULT_CONFIG"] = "true";
|
|
20
|
-
}
|
|
21
20
|
const ignores = [".gitignore", ".prettierignore", prettierignore]
|
|
22
21
|
.map((p) => path.resolve(p))
|
|
23
22
|
.flatMap((p) => ["--ignore-path", p]);
|
|
24
23
|
return execAsync(
|
|
25
24
|
[
|
|
26
25
|
// "node",
|
|
27
|
-
await
|
|
26
|
+
await getPrettierPath(useDefaultConfig),
|
|
28
27
|
...ignores,
|
|
29
28
|
"--log-level",
|
|
30
29
|
"warn",
|
|
@@ -37,6 +36,26 @@ export async function format(paths = [], options = {}) {
|
|
|
37
36
|
path.resolve(process.cwd(), p),
|
|
38
37
|
),
|
|
39
38
|
],
|
|
40
|
-
{
|
|
39
|
+
{
|
|
40
|
+
topic: "💃 Checking formatting",
|
|
41
|
+
dryRun,
|
|
42
|
+
env: {
|
|
43
|
+
...(config && { FENGE_CONFIG: config }),
|
|
44
|
+
...(useDefaultConfig && { FENGE_USE_DEFAULT_CONFIG: "true" }),
|
|
45
|
+
},
|
|
46
|
+
},
|
|
47
|
+
);
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* @param {boolean} useDefaultConfig
|
|
52
|
+
*/
|
|
53
|
+
async function getPrettierPath(useDefaultConfig) {
|
|
54
|
+
const builtinBinPath = await getBinPath("prettier");
|
|
55
|
+
if (useDefaultConfig) {
|
|
56
|
+
return builtinBinPath;
|
|
57
|
+
}
|
|
58
|
+
return await getBinPath("prettier", process.cwd()).catch(
|
|
59
|
+
() => builtinBinPath,
|
|
41
60
|
);
|
|
42
61
|
}
|
package/src/command/lint.js
CHANGED
|
@@ -8,20 +8,18 @@ import { dir, execAsync, getBinPath } from "../utils.js";
|
|
|
8
8
|
* @param {{update?: boolean, fix?: boolean, dryRun?: boolean, config?: string, default?: boolean}} options
|
|
9
9
|
*/
|
|
10
10
|
export async function lint(paths = [], options = {}) {
|
|
11
|
-
const {
|
|
12
|
-
|
|
11
|
+
const {
|
|
12
|
+
update = false,
|
|
13
|
+
fix = false,
|
|
14
|
+
dryRun = false,
|
|
15
|
+
config,
|
|
16
|
+
default: useDefaultConfig = false,
|
|
17
|
+
} = options;
|
|
13
18
|
|
|
14
|
-
if (config) {
|
|
15
|
-
process.env["FENGE_CONFIG"] = config;
|
|
16
|
-
}
|
|
17
|
-
if (useDefaultConfig) {
|
|
18
|
-
process.env["FENGE_USE_DEFAULT_CONFIG"] = "true";
|
|
19
|
-
}
|
|
20
|
-
process.env["ESLINT_USE_FLAT_CONFIG"] = "true"; // TODO remove it once upgrade to eslint 9
|
|
21
19
|
return execAsync(
|
|
22
20
|
[
|
|
23
21
|
// "node",
|
|
24
|
-
await
|
|
22
|
+
await getEslintPath(useDefaultConfig),
|
|
25
23
|
"--config",
|
|
26
24
|
path.join(dir(import.meta.url), "..", "config", "eslint.config.js"),
|
|
27
25
|
...(update || fix ? ["--fix"] : []),
|
|
@@ -29,6 +27,25 @@ export async function lint(paths = [], options = {}) {
|
|
|
29
27
|
path.resolve(process.cwd(), p),
|
|
30
28
|
),
|
|
31
29
|
],
|
|
32
|
-
{
|
|
30
|
+
{
|
|
31
|
+
topic: "📏 Checking linting",
|
|
32
|
+
dryRun,
|
|
33
|
+
env: {
|
|
34
|
+
ESLINT_USE_FLAT_CONFIG: "true", // TODO remove it once upgrade to eslint 9
|
|
35
|
+
...(config && { FENGE_CONFIG: config }),
|
|
36
|
+
...(useDefaultConfig && { FENGE_USE_DEFAULT_CONFIG: "true" }),
|
|
37
|
+
},
|
|
38
|
+
},
|
|
33
39
|
);
|
|
34
40
|
}
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* @param {boolean} useDefaultConfig
|
|
44
|
+
*/
|
|
45
|
+
async function getEslintPath(useDefaultConfig) {
|
|
46
|
+
const builtinBinPath = await getBinPath("eslint");
|
|
47
|
+
if (useDefaultConfig) {
|
|
48
|
+
return builtinBinPath;
|
|
49
|
+
}
|
|
50
|
+
return await getBinPath("eslint", process.cwd()).catch(() => builtinBinPath);
|
|
51
|
+
}
|
package/src/utils.js
CHANGED
|
@@ -48,7 +48,7 @@ export async function resolveConfig(module, loadPath) {
|
|
|
48
48
|
*/
|
|
49
49
|
export async function importJson(importMetaUrl, jsonPath) {
|
|
50
50
|
return JSON.parse(
|
|
51
|
-
await fs.readFile(path.resolve(dir(importMetaUrl), jsonPath), "
|
|
51
|
+
await fs.readFile(path.resolve(dir(importMetaUrl), jsonPath), "utf8"),
|
|
52
52
|
);
|
|
53
53
|
}
|
|
54
54
|
|
|
@@ -69,23 +69,25 @@ function getSpentTime(startTime) {
|
|
|
69
69
|
|
|
70
70
|
/**
|
|
71
71
|
* @param {string[]} command
|
|
72
|
-
* @param {{topic: string, dryRun: boolean}} options
|
|
72
|
+
* @param {{topic: string, dryRun: boolean, env: Record<string, string>}} options
|
|
73
73
|
* @returns {Promise<number>}
|
|
74
74
|
*/
|
|
75
|
-
export
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
75
|
+
export function execAsync(command, { topic, dryRun, env }) {
|
|
76
|
+
return new Promise((resolve, reject) => {
|
|
77
|
+
const startTime = Date.now();
|
|
78
|
+
|
|
79
|
+
const [cmd, ...args] = command;
|
|
80
|
+
if (!cmd) {
|
|
81
|
+
return reject(new Error("cmd not found"));
|
|
82
|
+
}
|
|
83
|
+
if (dryRun) {
|
|
84
|
+
console.log(`${chalk.green(cmd)} ${args.join(" ")}`);
|
|
85
|
+
return resolve(0);
|
|
86
|
+
}
|
|
87
|
+
|
|
86
88
|
const spinner = ora(`${topic}...`).start();
|
|
87
89
|
const cp = childProcess.spawn(cmd, args, {
|
|
88
|
-
env: { FORCE_COLOR: "true", ...process.env },
|
|
90
|
+
env: { FORCE_COLOR: "true", ...process.env, ...env },
|
|
89
91
|
});
|
|
90
92
|
let stdout = Buffer.from([]);
|
|
91
93
|
let stderr = Buffer.from([]);
|
|
@@ -143,10 +145,18 @@ function getExitCode(error) {
|
|
|
143
145
|
|
|
144
146
|
/**
|
|
145
147
|
* @param {string} moduleName `eslint` or `prettier` or `@commitlint/cli` or `lint-staged`
|
|
146
|
-
* @param {string}
|
|
148
|
+
* @param {string} from directory path or file path
|
|
147
149
|
*/
|
|
148
|
-
export async function getBinPath(
|
|
149
|
-
|
|
150
|
+
export async function getBinPath(
|
|
151
|
+
moduleName,
|
|
152
|
+
from = fileURLToPath(import.meta.url),
|
|
153
|
+
) {
|
|
154
|
+
const fromPath =
|
|
155
|
+
!from.endsWith(path.sep) && (await fs.stat(from)).isDirectory()
|
|
156
|
+
? from + path.sep
|
|
157
|
+
: from;
|
|
158
|
+
const cliName = moduleName;
|
|
159
|
+
const packageJsonPath = createRequire(fromPath).resolve(
|
|
150
160
|
`${moduleName}/package.json`,
|
|
151
161
|
);
|
|
152
162
|
/** @type {any} */
|
package/tsconfig.json
CHANGED
package/tsconfig.build.json
DELETED
|
File without changes
|