@huaiyou/hooks-git 2.2.0 → 2.2.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.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,17 @@
1
1
  # @huaiyou/hooks-git
2
2
 
3
+ ## 2.2.2
4
+
5
+ ### Patch Changes
6
+
7
+ - Fix hook scripts to use correct bin commands
8
+
9
+ ## 2.2.1
10
+
11
+ ### Patch Changes
12
+
13
+ - Fix build issue with function naming conflicts
14
+
3
15
  ## 2.2.0
4
16
 
5
17
  ### Minor Changes
package/dist/cli.cjs CHANGED
@@ -14,7 +14,7 @@ const cac__default = /*#__PURE__*/_interopDefaultCompat(cac);
14
14
  const fs__default = /*#__PURE__*/_interopDefaultCompat(fs);
15
15
  const picocolors__default = /*#__PURE__*/_interopDefaultCompat(picocolors);
16
16
 
17
- const version = "2.2.0";
17
+ const version = "2.2.2";
18
18
 
19
19
  const logger = {
20
20
  /**
@@ -75,6 +75,15 @@ const updatePackageJson = async (callback) => {
75
75
  await fs__default.writeJson(pkgPath, newPkg, { spaces: 2 });
76
76
  };
77
77
 
78
+ function checkComplexTsConfig() {
79
+ try {
80
+ const tsconfigPath = node_path.resolve(process.cwd(), "tsconfig.json");
81
+ const tsconfig = fs__default.readJsonSync(tsconfigPath);
82
+ return tsconfig.files === "" || Array.isArray(tsconfig.files) && tsconfig.files.length === 0 && tsconfig.references;
83
+ } catch {
84
+ return false;
85
+ }
86
+ }
78
87
  const init = async () => {
79
88
  logger.box("Initializing @huaiyou/hooks-git");
80
89
  const gitDirPath = node_path.resolve(process.cwd(), ".git");
@@ -105,26 +114,26 @@ const init = async () => {
105
114
  }
106
115
  try {
107
116
  await runCommand(pm === "yarn" ? "npx" : pm, ["husky", "install"]);
108
- } catch (e) {
117
+ } catch {
109
118
  logger.error("Failed to initialize husky.");
110
119
  }
111
120
  logger.info("Adding hooks...");
112
121
  const huskyDir = node_path.resolve(process.cwd(), ".husky");
113
122
  const commitMsgPath = node_path.resolve(huskyDir, "commit-msg");
114
- const commitMsgContent = `npx --no -- @huaiyou/hooks-git/wrappers commitlint --edit \${1}
123
+ const commitMsgContent = `npx --no -- hy-hooks-commitlint commitlint --edit \${1}
115
124
  `;
116
125
  await fs__default.outputFile(commitMsgPath, commitMsgContent, { mode: 493 });
117
126
  const preCommitPath = node_path.resolve(huskyDir, "pre-commit");
118
- const preCommitContent = `npx --no -- @huaiyou/hooks-git/wrappers lint-staged
127
+ const preCommitContent = `npx --no -- hy-hooks-lint-staged lint-staged
119
128
  `;
120
129
  await fs__default.outputFile(preCommitPath, preCommitContent, { mode: 493 });
121
130
  logger.info("Creating configuration files...");
122
131
  const isModule = pkg.type === "module";
123
132
  const isTsProject = fs__default.existsSync(node_path.resolve(process.cwd(), "tsconfig.json"));
124
- const isComplexTsConfig2 = isTsProject && isComplexTsConfig2();
133
+ const hasComplexTsConfig = isTsProject && checkComplexTsConfig();
125
134
  let commitlintFile;
126
135
  let lintStagedFile;
127
- if (isComplexTsConfig2) {
136
+ if (hasComplexTsConfig) {
128
137
  commitlintFile = "commitlint.config.cjs";
129
138
  lintStagedFile = "lint-staged.config.cjs";
130
139
  } else if (isTsProject) {
package/dist/cli.mjs CHANGED
@@ -6,7 +6,7 @@ import { consola } from 'consola';
6
6
  import { execa } from 'execa';
7
7
  import picocolors from 'picocolors';
8
8
 
9
- const version = "2.2.0";
9
+ const version = "2.2.2";
10
10
 
11
11
  const logger = {
12
12
  /**
@@ -67,6 +67,15 @@ const updatePackageJson = async (callback) => {
67
67
  await fs.writeJson(pkgPath, newPkg, { spaces: 2 });
68
68
  };
69
69
 
70
+ function checkComplexTsConfig() {
71
+ try {
72
+ const tsconfigPath = resolve(process.cwd(), "tsconfig.json");
73
+ const tsconfig = fs.readJsonSync(tsconfigPath);
74
+ return tsconfig.files === "" || Array.isArray(tsconfig.files) && tsconfig.files.length === 0 && tsconfig.references;
75
+ } catch {
76
+ return false;
77
+ }
78
+ }
70
79
  const init = async () => {
71
80
  logger.box("Initializing @huaiyou/hooks-git");
72
81
  const gitDirPath = resolve(process.cwd(), ".git");
@@ -97,26 +106,26 @@ const init = async () => {
97
106
  }
98
107
  try {
99
108
  await runCommand(pm === "yarn" ? "npx" : pm, ["husky", "install"]);
100
- } catch (e) {
109
+ } catch {
101
110
  logger.error("Failed to initialize husky.");
102
111
  }
103
112
  logger.info("Adding hooks...");
104
113
  const huskyDir = resolve(process.cwd(), ".husky");
105
114
  const commitMsgPath = resolve(huskyDir, "commit-msg");
106
- const commitMsgContent = `npx --no -- @huaiyou/hooks-git/wrappers commitlint --edit \${1}
115
+ const commitMsgContent = `npx --no -- hy-hooks-commitlint commitlint --edit \${1}
107
116
  `;
108
117
  await fs.outputFile(commitMsgPath, commitMsgContent, { mode: 493 });
109
118
  const preCommitPath = resolve(huskyDir, "pre-commit");
110
- const preCommitContent = `npx --no -- @huaiyou/hooks-git/wrappers lint-staged
119
+ const preCommitContent = `npx --no -- hy-hooks-lint-staged lint-staged
111
120
  `;
112
121
  await fs.outputFile(preCommitPath, preCommitContent, { mode: 493 });
113
122
  logger.info("Creating configuration files...");
114
123
  const isModule = pkg.type === "module";
115
124
  const isTsProject = fs.existsSync(resolve(process.cwd(), "tsconfig.json"));
116
- const isComplexTsConfig2 = isTsProject && isComplexTsConfig2();
125
+ const hasComplexTsConfig = isTsProject && checkComplexTsConfig();
117
126
  let commitlintFile;
118
127
  let lintStagedFile;
119
- if (isComplexTsConfig2) {
128
+ if (hasComplexTsConfig) {
120
129
  commitlintFile = "commitlint.config.cjs";
121
130
  lintStagedFile = "lint-staged.config.cjs";
122
131
  } else if (isTsProject) {
@@ -40,24 +40,25 @@ async function runCommitlint(args) {
40
40
  reject: false
41
41
  });
42
42
  } catch (error) {
43
- if (error.stdout) {
44
- const translated = translateError$1(error.stdout);
45
- console.error(translated);
43
+ const err = error;
44
+ if (err.stdout) {
45
+ const translated = translateError$1(err.stdout);
46
+ process.stderr.write(translated + "\n");
46
47
  }
47
- if (error.stderr) {
48
- const translated = translateError$1(error.stderr);
49
- console.error(translated);
48
+ if (err.stderr) {
49
+ const translated = translateError$1(err.stderr);
50
+ process.stderr.write(translated + "\n");
50
51
  }
51
- if (error.message) {
52
- const translated = translateError$1(error.message);
53
- console.error(translated);
52
+ if (err.message) {
53
+ const translated = translateError$1(err.message);
54
+ process.stderr.write(translated + "\n");
54
55
  }
55
56
  process.exit(1);
56
57
  }
57
58
  }
58
59
 
59
60
  const errorMessages = {
60
- // ���置相关
61
+ // 配置相关
61
62
  "Failed to read config from file": "\u65E0\u6CD5\u8BFB\u53D6\u914D\u7F6E\u6587\u4EF6",
62
63
  "could not find any valid configuration": "\u627E\u4E0D\u5230\u6709\u6548\u7684\u914D\u7F6E",
63
64
  "No valid configurations found": "\u627E\u4E0D\u5230\u6709\u6548\u7684\u914D\u7F6E",
@@ -72,10 +73,10 @@ const errorMessages = {
72
73
  // 错误相关
73
74
  "Something went wrong": "\u51FA\u9519\u4E86",
74
75
  "Command failed": "\u547D\u4EE4\u6267\u884C\u5931\u8D25",
75
- "Task": "\u4EFB\u52A1",
76
- "failed": "\u5931\u8D25",
77
- "passed": "\u901A\u8FC7",
78
- "skipped": "\u8DF3\u8FC7"
76
+ Task: "\u4EFB\u52A1",
77
+ failed: "\u5931\u8D25",
78
+ passed: "\u901A\u8FC7",
79
+ skipped: "\u8DF3\u8FC7"
79
80
  };
80
81
  function translateError(message) {
81
82
  let translated = message;
@@ -85,7 +86,7 @@ function translateError(message) {
85
86
  return translated;
86
87
  }
87
88
  function translateLine(line) {
88
- if (!line.trim() || /^[\s\─│┌┐└┘]+$/g.test(line)) {
89
+ if (!line.trim() || /^[\s─│┌┐└┘]+$/g.test(line)) {
89
90
  return line;
90
91
  }
91
92
  return translateError(line);
@@ -98,26 +99,27 @@ async function runLintStaged() {
98
99
  if (stdout) {
99
100
  const lines = stdout.split("\n");
100
101
  lines.forEach((line) => {
101
- console.log(translateLine(line));
102
+ process.stdout.write(translateLine(line) + "\n");
102
103
  });
103
104
  }
104
105
  if (stderr) {
105
106
  const lines = stderr.split("\n");
106
107
  lines.forEach((line) => {
107
- console.error(translateLine(line));
108
+ process.stderr.write(translateLine(line) + "\n");
108
109
  });
109
110
  }
110
111
  } catch (error) {
111
- if (error.stdout) {
112
- const lines = error.stdout.split("\n");
112
+ const err = error;
113
+ if (err.stdout) {
114
+ const lines = err.stdout.split("\n");
113
115
  lines.forEach((line) => {
114
- console.log(translateLine(line));
116
+ process.stdout.write(translateLine(line) + "\n");
115
117
  });
116
118
  }
117
- if (error.stderr) {
118
- const lines = error.stderr.split("\n");
119
+ if (err.stderr) {
120
+ const lines = err.stderr.split("\n");
119
121
  lines.forEach((line) => {
120
- console.error(translateLine(line));
122
+ process.stderr.write(translateLine(line) + "\n");
121
123
  });
122
124
  }
123
125
  process.exit(1);
@@ -34,24 +34,25 @@ async function runCommitlint(args) {
34
34
  reject: false
35
35
  });
36
36
  } catch (error) {
37
- if (error.stdout) {
38
- const translated = translateError$1(error.stdout);
39
- console.error(translated);
37
+ const err = error;
38
+ if (err.stdout) {
39
+ const translated = translateError$1(err.stdout);
40
+ process.stderr.write(translated + "\n");
40
41
  }
41
- if (error.stderr) {
42
- const translated = translateError$1(error.stderr);
43
- console.error(translated);
42
+ if (err.stderr) {
43
+ const translated = translateError$1(err.stderr);
44
+ process.stderr.write(translated + "\n");
44
45
  }
45
- if (error.message) {
46
- const translated = translateError$1(error.message);
47
- console.error(translated);
46
+ if (err.message) {
47
+ const translated = translateError$1(err.message);
48
+ process.stderr.write(translated + "\n");
48
49
  }
49
50
  process.exit(1);
50
51
  }
51
52
  }
52
53
 
53
54
  const errorMessages = {
54
- // ���置相关
55
+ // 配置相关
55
56
  "Failed to read config from file": "\u65E0\u6CD5\u8BFB\u53D6\u914D\u7F6E\u6587\u4EF6",
56
57
  "could not find any valid configuration": "\u627E\u4E0D\u5230\u6709\u6548\u7684\u914D\u7F6E",
57
58
  "No valid configurations found": "\u627E\u4E0D\u5230\u6709\u6548\u7684\u914D\u7F6E",
@@ -66,10 +67,10 @@ const errorMessages = {
66
67
  // 错误相关
67
68
  "Something went wrong": "\u51FA\u9519\u4E86",
68
69
  "Command failed": "\u547D\u4EE4\u6267\u884C\u5931\u8D25",
69
- "Task": "\u4EFB\u52A1",
70
- "failed": "\u5931\u8D25",
71
- "passed": "\u901A\u8FC7",
72
- "skipped": "\u8DF3\u8FC7"
70
+ Task: "\u4EFB\u52A1",
71
+ failed: "\u5931\u8D25",
72
+ passed: "\u901A\u8FC7",
73
+ skipped: "\u8DF3\u8FC7"
73
74
  };
74
75
  function translateError(message) {
75
76
  let translated = message;
@@ -79,7 +80,7 @@ function translateError(message) {
79
80
  return translated;
80
81
  }
81
82
  function translateLine(line) {
82
- if (!line.trim() || /^[\s\─│┌┐└┘]+$/g.test(line)) {
83
+ if (!line.trim() || /^[\s─│┌┐└┘]+$/g.test(line)) {
83
84
  return line;
84
85
  }
85
86
  return translateError(line);
@@ -92,26 +93,27 @@ async function runLintStaged() {
92
93
  if (stdout) {
93
94
  const lines = stdout.split("\n");
94
95
  lines.forEach((line) => {
95
- console.log(translateLine(line));
96
+ process.stdout.write(translateLine(line) + "\n");
96
97
  });
97
98
  }
98
99
  if (stderr) {
99
100
  const lines = stderr.split("\n");
100
101
  lines.forEach((line) => {
101
- console.error(translateLine(line));
102
+ process.stderr.write(translateLine(line) + "\n");
102
103
  });
103
104
  }
104
105
  } catch (error) {
105
- if (error.stdout) {
106
- const lines = error.stdout.split("\n");
106
+ const err = error;
107
+ if (err.stdout) {
108
+ const lines = err.stdout.split("\n");
107
109
  lines.forEach((line) => {
108
- console.log(translateLine(line));
110
+ process.stdout.write(translateLine(line) + "\n");
109
111
  });
110
112
  }
111
- if (error.stderr) {
112
- const lines = error.stderr.split("\n");
113
+ if (err.stderr) {
114
+ const lines = err.stderr.split("\n");
113
115
  lines.forEach((line) => {
114
- console.error(translateLine(line));
116
+ process.stderr.write(translateLine(line) + "\n");
115
117
  });
116
118
  }
117
119
  process.exit(1);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@huaiyou/hooks-git",
3
- "version": "2.2.0",
3
+ "version": "2.2.2",
4
4
  "description": "Git hooks configuration with Husky, Commitlint and Lint-staged",
5
5
  "bin": {
6
6
  "hy-hooks-git": "./dist/cli.mjs",