fenge 0.5.2 → 0.5.3

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 CHANGED
@@ -1,5 +1,18 @@
1
1
  # fenge
2
2
 
3
+ ## 0.5.3
4
+
5
+ ### Patch Changes
6
+
7
+ - ee96c15: chore: upgrade deps
8
+ - e0456a0: feat(fenge): support `--timing` option for CLI
9
+ - 8de30ed: fix(fenge): fix the problem that eslint messages disappear sometimes when error occurs
10
+ - Updated dependencies [ee96c15]
11
+ - Updated dependencies [67f3677]
12
+ - Updated dependencies [3927795]
13
+ - @fenge/prettier-config@0.2.2
14
+ - @fenge/eslint-config@0.5.10
15
+
3
16
  ## 0.5.2
4
17
 
5
18
  ### Patch Changes
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "fenge",
3
- "version": "0.5.2",
3
+ "version": "0.5.3",
4
4
  "description": "A CLI tool for code quality",
5
5
  "keywords": [
6
6
  "cli",
@@ -49,10 +49,10 @@
49
49
  "lilconfig": "3.1.3",
50
50
  "lint-staged": "15.4.3",
51
51
  "ora": "8.2.0",
52
- "prettier": "3.5.2",
52
+ "prettier": "3.5.3",
53
53
  "yoctocolors": "2.1.1",
54
- "@fenge/eslint-config": "0.5.9",
55
- "@fenge/prettier-config": "0.2.1",
54
+ "@fenge/eslint-config": "0.5.10",
55
+ "@fenge/prettier-config": "0.2.2",
56
56
  "@fenge/tsconfig": "0.3.2",
57
57
  "@fenge/types": "0.2.0",
58
58
  "prettier-ignore": "0.2.0"
@@ -54,6 +54,7 @@ program
54
54
  "--default",
55
55
  "force to use built-in default config, ignore specified config and local config",
56
56
  )
57
+ .option("--timing", "print timing information")
57
58
  .option(
58
59
  "-d, --dry-run",
59
60
  "print what command will be executed under the hood instead of executing",
@@ -5,7 +5,7 @@ import { dir, execAsync, getBinPath } from "../utils.js";
5
5
 
6
6
  /**
7
7
  * @param {Array<string>} paths
8
- * @param {{update?: boolean, fix?: boolean, dryRun?: boolean, config?: string, default?: boolean}} options
8
+ * @param {{update?: boolean, fix?: boolean, dryRun?: boolean, config?: string, default?: boolean, timing?: boolean}} options
9
9
  */
10
10
  export async function lint(paths = [], options = {}) {
11
11
  const {
@@ -14,6 +14,7 @@ export async function lint(paths = [], options = {}) {
14
14
  dryRun = false,
15
15
  config,
16
16
  default: useDefaultConfig = false,
17
+ timing = false,
17
18
  } = options;
18
19
 
19
20
  return execAsync(
@@ -33,6 +34,7 @@ export async function lint(paths = [], options = {}) {
33
34
  env: {
34
35
  ...(config && { FENGE_CONFIG: config }),
35
36
  ...(useDefaultConfig && { FENGE_USE_DEFAULT_CONFIG: "true" }),
37
+ ...(timing && { TIMING: "1" }),
36
38
  },
37
39
  },
38
40
  );
package/src/utils.js CHANGED
@@ -8,7 +8,7 @@ import process from "node:process";
8
8
  import { fileURLToPath } from "node:url";
9
9
  import { lilconfig } from "lilconfig";
10
10
  import ora from "ora";
11
- import colors from "yoctocolors";
11
+ import colors from "yoctocolors"; // TODO: Use [util.styleText](https://nodejs.org/api/util.html#utilstyletextformat-text-options) once we drop support for Node.js < 20.12.0.
12
12
 
13
13
  /**
14
14
  * @param {string} filepath
@@ -89,27 +89,25 @@ export function execAsync(command, { topic, dryRun, env }) {
89
89
  const cp = childProcess.spawn(cmd, args, {
90
90
  env: { FORCE_COLOR: "true", ...process.env, ...env },
91
91
  });
92
- let stdout = Buffer.from([]);
93
- let stderr = Buffer.from([]);
92
+ let stdout = Buffer.alloc(0);
93
+ let stderr = Buffer.alloc(0);
94
94
  cp.stdout.on("data", (data) => {
95
95
  stdout = Buffer.concat([stdout, data]);
96
96
  });
97
97
  cp.stderr.on("data", (data) => {
98
98
  stderr = Buffer.concat([stderr, data]);
99
99
  });
100
- // The 'close' event will always emit after 'exit' was already emitted, or 'error' if the child failed to spawn.
101
- cp.on("close", () => {
102
- process.stdout.write(stdout);
103
- process.stderr.write(stderr);
104
- });
105
100
  cp.on("error", (err) => {
106
101
  spinner.fail(
107
102
  `${topic} got error in ${colors.yellow(getSpentTime(startTime))}`,
108
103
  );
104
+ process.stderr.write(err.message);
109
105
  resolve(getExitCode(err));
110
106
  });
111
- // The 'exit' event may or may not fire after an error has occurred.
112
- cp.on("exit", (code, signal) => {
107
+ // Why not listen to the 'exit' event?
108
+ // 1. The 'close' event will always emit after 'exit' was already emitted, or 'error' if the child failed to spawn.
109
+ // 2. The 'exit' event may or may not fire after an error has occurred.
110
+ cp.on("close", (code, signal) => {
113
111
  const exitCode = getExitCode({ code, signal });
114
112
  if (exitCode === 0) {
115
113
  spinner.succeed(
@@ -120,6 +118,8 @@ export function execAsync(command, { topic, dryRun, env }) {
120
118
  `${topic} failed in ${colors.yellow(getSpentTime(startTime))}`,
121
119
  );
122
120
  }
121
+ process.stdout.write(stdout);
122
+ process.stderr.write(stderr);
123
123
  resolve(exitCode);
124
124
  });
125
125
  process.on("SIGINT", () => !cp.killed && cp.kill("SIGINT"));