@pyyupsk/nit 0.1.0 → 0.2.0

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/dist/cli.cjs CHANGED
@@ -30,6 +30,19 @@ var import_node_path6 = require("path");
30
30
  var import_node_fs = require("fs");
31
31
  var import_promises = require("fs/promises");
32
32
  var import_node_path = require("path");
33
+
34
+ // src/core/hook-script.ts
35
+ var NIT_FINGERPRINT = '#!/bin/sh\nif [ "$SKIP_NIT"';
36
+ function hookScript(cmd) {
37
+ return `#!/bin/sh
38
+ if [ "$SKIP_NIT" = "1" ]; then
39
+ exit 0
40
+ fi
41
+ ${cmd}
42
+ `;
43
+ }
44
+
45
+ // src/core/check.ts
33
46
  async function checkHooks(hooks, hooksDir) {
34
47
  try {
35
48
  await (0, import_promises.stat)(hooksDir);
@@ -56,17 +69,28 @@ async function checkHooks(hooks, hooksDir) {
56
69
  return [null, false];
57
70
  }
58
71
  }
72
+ try {
73
+ const entries = await (0, import_promises.readdir)(hooksDir, { withFileTypes: true });
74
+ const configuredNames = new Set(Object.keys(hooks));
75
+ for (const e of entries) {
76
+ if (!e.isFile() || configuredNames.has(e.name)) continue;
77
+ const hookPath = (0, import_node_path.join)(hooksDir, e.name);
78
+ try {
79
+ const content = await (0, import_promises.readFile)(hookPath, "utf8");
80
+ if (content.startsWith(NIT_FINGERPRINT)) {
81
+ return [null, false];
82
+ }
83
+ } catch {
84
+ }
85
+ }
86
+ } catch {
87
+ }
59
88
  return [null, true];
60
89
  }
61
90
 
62
91
  // src/core/install.ts
63
92
  var import_promises2 = require("fs/promises");
64
93
  var import_node_path2 = require("path");
65
- function hookScript(cmd) {
66
- return `#!/bin/sh
67
- ${cmd}
68
- `;
69
- }
70
94
  async function installHooks(hooks, hooksDir) {
71
95
  try {
72
96
  await (0, import_promises2.stat)(hooksDir);
@@ -89,6 +113,23 @@ async function installHooks(hooks, hooksDir) {
89
113
  ];
90
114
  }
91
115
  }
116
+ try {
117
+ const entries = await (0, import_promises2.readdir)(hooksDir, { withFileTypes: true });
118
+ const configuredNames = new Set(Object.keys(hooks));
119
+ await Promise.all(
120
+ entries.filter((e) => e.isFile() && !configuredNames.has(e.name)).map(async (e) => {
121
+ const hookPath = (0, import_node_path2.join)(hooksDir, e.name);
122
+ try {
123
+ const content = await (0, import_promises2.readFile)(hookPath, "utf8");
124
+ if (content.startsWith(NIT_FINGERPRINT)) {
125
+ await (0, import_promises2.unlink)(hookPath);
126
+ }
127
+ } catch {
128
+ }
129
+ })
130
+ );
131
+ } catch {
132
+ }
92
133
  return [null, true];
93
134
  }
94
135
 
package/dist/cli.js CHANGED
@@ -5,8 +5,21 @@ import { join as join6 } from "path";
5
5
 
6
6
  // src/core/check.ts
7
7
  import { existsSync } from "fs";
8
- import { readFile, stat } from "fs/promises";
8
+ import { readdir, readFile, stat } from "fs/promises";
9
9
  import { join } from "path";
10
+
11
+ // src/core/hook-script.ts
12
+ var NIT_FINGERPRINT = '#!/bin/sh\nif [ "$SKIP_NIT"';
13
+ function hookScript(cmd) {
14
+ return `#!/bin/sh
15
+ if [ "$SKIP_NIT" = "1" ]; then
16
+ exit 0
17
+ fi
18
+ ${cmd}
19
+ `;
20
+ }
21
+
22
+ // src/core/check.ts
10
23
  async function checkHooks(hooks, hooksDir) {
11
24
  try {
12
25
  await stat(hooksDir);
@@ -33,17 +46,35 @@ async function checkHooks(hooks, hooksDir) {
33
46
  return [null, false];
34
47
  }
35
48
  }
49
+ try {
50
+ const entries = await readdir(hooksDir, { withFileTypes: true });
51
+ const configuredNames = new Set(Object.keys(hooks));
52
+ for (const e of entries) {
53
+ if (!e.isFile() || configuredNames.has(e.name)) continue;
54
+ const hookPath = join(hooksDir, e.name);
55
+ try {
56
+ const content = await readFile(hookPath, "utf8");
57
+ if (content.startsWith(NIT_FINGERPRINT)) {
58
+ return [null, false];
59
+ }
60
+ } catch {
61
+ }
62
+ }
63
+ } catch {
64
+ }
36
65
  return [null, true];
37
66
  }
38
67
 
39
68
  // src/core/install.ts
40
- import { chmod, stat as stat2, unlink, writeFile } from "fs/promises";
69
+ import {
70
+ chmod,
71
+ readdir as readdir2,
72
+ readFile as readFile2,
73
+ stat as stat2,
74
+ unlink,
75
+ writeFile
76
+ } from "fs/promises";
41
77
  import { join as join2 } from "path";
42
- function hookScript(cmd) {
43
- return `#!/bin/sh
44
- ${cmd}
45
- `;
46
- }
47
78
  async function installHooks(hooks, hooksDir) {
48
79
  try {
49
80
  await stat2(hooksDir);
@@ -66,6 +97,23 @@ async function installHooks(hooks, hooksDir) {
66
97
  ];
67
98
  }
68
99
  }
100
+ try {
101
+ const entries = await readdir2(hooksDir, { withFileTypes: true });
102
+ const configuredNames = new Set(Object.keys(hooks));
103
+ await Promise.all(
104
+ entries.filter((e) => e.isFile() && !configuredNames.has(e.name)).map(async (e) => {
105
+ const hookPath = join2(hooksDir, e.name);
106
+ try {
107
+ const content = await readFile2(hookPath, "utf8");
108
+ if (content.startsWith(NIT_FINGERPRINT)) {
109
+ await unlink(hookPath);
110
+ }
111
+ } catch {
112
+ }
113
+ })
114
+ );
115
+ } catch {
116
+ }
69
117
  return [null, true];
70
118
  }
71
119
 
@@ -94,13 +142,13 @@ function validateHooks(hooks) {
94
142
  }
95
143
 
96
144
  // src/utils/config.ts
97
- import { readFile as readFile2 } from "fs/promises";
145
+ import { readFile as readFile3 } from "fs/promises";
98
146
  import { join as join4 } from "path";
99
147
  async function readConfig(cwd) {
100
148
  const pkgPath = join4(cwd, "package.json");
101
149
  let raw;
102
150
  try {
103
- raw = await readFile2(pkgPath, "utf8");
151
+ raw = await readFile3(pkgPath, "utf8");
104
152
  } catch {
105
153
  return [new Error(`Cannot find package.json at ${pkgPath}`), null];
106
154
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pyyupsk/nit",
3
- "version": "0.1.0",
3
+ "version": "0.2.0",
4
4
  "description": "Lightweight zero-dependency Git hooks manager for JavaScript/Node.js projects",
5
5
  "license": "MIT",
6
6
  "packageManager": "bun@1.3.11",