@itcase/config 1.6.65 → 1.6.66

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/README.md CHANGED
@@ -87,13 +87,13 @@ npm install --save-dev commitizen @commitlint/cz-commitlint
87
87
 
88
88
  В репозитории остаются файлы, на которые опираются git и husky. Логика лежит в `@itcase/config/husky-hooks`. При установке пакета npm кладёт бинарь `itcase-config-husky-hooks` в `node_modules/.bin` — husky уже добавляет этот путь в `PATH`.
89
89
 
90
- При `npm i` пакет сам копирует `.husky/_run.sh` (git его не вызывает). Добавьте в `.gitignore`:
90
+ При `npm i` пакет копирует `.husky/_run.sh` и создаёт недостающие обёртки хуков. Свои полные хуки не перезаписывает. Добавьте в `.gitignore`:
91
91
 
92
92
  ```gitignore
93
93
  .husky/_run.sh
94
94
  ```
95
95
 
96
- Репы без обёрток скрипт не трогает. `npm i --ignore-scripts` файл не создаст.
96
+ Репы без обёрток и без одного только `.husky/config` скрипт не трогает. `npm i --ignore-scripts` файлы не создаст.
97
97
 
98
98
  В каждом git-hook оставьте обёртку:
99
99
 
@@ -1,7 +1,7 @@
1
1
  #!/usr/bin/env node
2
2
  /**
3
- * Copies husky-hooks/_run.sh into the project .husky/ on install.
4
- * Skips repos that do not use the wrappers.
3
+ * Copies husky-hooks/_run.sh into the project .husky/ on install
4
+ * and creates missing git-hook wrappers. Does not overwrite custom hooks.
5
5
  */
6
6
  import fs from 'node:fs'
7
7
  import path from 'node:path'
@@ -16,6 +16,10 @@ const GIT_HOOKS = [
16
16
  'set-release-message',
17
17
  ]
18
18
 
19
+ const WRAPPER = `#!/usr/bin/env sh
20
+ . "$(dirname "$0")/_run.sh"
21
+ `
22
+
19
23
  function projectRoot() {
20
24
  const initCwd = process.env.INIT_CWD
21
25
  if (
@@ -36,32 +40,61 @@ function projectRoot() {
36
40
  return cwd
37
41
  }
38
42
 
39
- function usesItcaseHooks(huskyDir) {
43
+ function readHook(huskyDir, name) {
44
+ try {
45
+ return fs.readFileSync(path.join(huskyDir, name), 'utf8')
46
+ } catch {
47
+ return null
48
+ }
49
+ }
50
+
51
+ function isItcaseHuskyDir(huskyDir) {
40
52
  if (fs.existsSync(path.join(huskyDir, '_run.sh'))) {
41
53
  return true
42
54
  }
43
55
 
44
- return GIT_HOOKS.some((name) => {
45
- try {
46
- const text = fs.readFileSync(path.join(huskyDir, name), 'utf8')
47
- return text.includes('_run.sh')
48
- } catch {
49
- return false
50
- }
51
- })
56
+ const hookContents = GIT_HOOKS.map((name) => readHook(huskyDir, name))
57
+ if (hookContents.some((text) => text?.includes('_run.sh'))) {
58
+ return true
59
+ }
60
+
61
+ const hasCustomHooks = hookContents.some(
62
+ (text) => text !== null && !text.includes('_run.sh'),
63
+ )
64
+ if (hasCustomHooks) {
65
+ return false
66
+ }
67
+
68
+ return fs.existsSync(path.join(huskyDir, 'config'))
69
+ }
70
+
71
+ function writeWrapper(huskyDir, name) {
72
+ const dest = path.join(huskyDir, name)
73
+ fs.writeFileSync(dest, WRAPPER)
74
+ try {
75
+ fs.chmodSync(dest, 0o755)
76
+ } catch {
77
+ // Windows may not support chmod; Git Bash still runs the file via sh.
78
+ }
52
79
  }
53
80
 
54
81
  const root = projectRoot()
55
82
  const huskyDir = path.join(root, '.husky')
56
- if (!fs.existsSync(huskyDir) || !usesItcaseHooks(huskyDir)) {
83
+ if (!fs.existsSync(huskyDir) || !isItcaseHuskyDir(huskyDir)) {
57
84
  process.exit(0)
58
85
  }
59
86
 
60
87
  const src = path.join(import.meta.dirname, '_run.sh')
61
- const dest = path.join(huskyDir, '_run.sh')
62
- fs.copyFileSync(src, dest)
88
+ fs.copyFileSync(src, path.join(huskyDir, '_run.sh'))
63
89
  try {
64
- fs.chmodSync(dest, 0o755)
90
+ fs.chmodSync(path.join(huskyDir, '_run.sh'), 0o755)
65
91
  } catch {
66
92
  // Windows may not support chmod; Git Bash still runs the file via sh.
67
93
  }
94
+
95
+ for (const name of GIT_HOOKS) {
96
+ const text = readHook(huskyDir, name)
97
+ if (text === null || text.includes('_run.sh')) {
98
+ writeWrapper(huskyDir, name)
99
+ }
100
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@itcase/config",
3
- "version": "1.6.65",
3
+ "version": "1.6.66",
4
4
  "author": "ITCase",
5
5
  "description": "ITCase Config",
6
6
  "engines": {
@@ -60,7 +60,7 @@
60
60
  "autoprefixer": "^10.5.4",
61
61
  "chokidar-cli": "^3.0.0",
62
62
  "commitizen": "^4.3.2",
63
- "conventional-changelog-conventionalcommits": "^10.3.0",
63
+ "conventional-changelog-conventionalcommits": "9.3.1",
64
64
  "cssnano": "^8.0.5",
65
65
  "cssnano-preset-default": "^8.0.5",
66
66
  "inquirer": "^14.0.2",
@@ -105,7 +105,7 @@
105
105
  "semantic-release-lerna": "^3.6.1"
106
106
  },
107
107
  "devDependencies": {
108
- "@itcase/lint": "^1.1.121",
108
+ "@itcase/lint": "^1.1.122",
109
109
  "eslint": "9.39.2",
110
110
  "husky": "^9.1.7",
111
111
  "inquirer": "^14.0.2",
@@ -113,6 +113,6 @@
113
113
  "prettier": "^3.9.6",
114
114
  "storybook": "^10.5.8",
115
115
  "stylelint": "^17.14.1",
116
- "typescript": "^6.0.2"
116
+ "typescript": "^6.0.3"
117
117
  }
118
118
  }