bun-git-hooks 0.2.5 → 0.2.7
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/bin/cli.js +19 -19
- package/dist/index.js +110 -105
- package/package.json +1 -1
package/dist/bin/cli.js
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
// @bun
|
|
3
3
|
|
|
4
4
|
// bin/cli.ts
|
|
5
|
-
import
|
|
5
|
+
import process5 from "process";
|
|
6
6
|
|
|
7
7
|
// node_modules/cac/dist/index.mjs
|
|
8
8
|
import { EventEmitter } from "events";
|
|
@@ -604,15 +604,15 @@ class CAC extends EventEmitter {
|
|
|
604
604
|
}
|
|
605
605
|
}
|
|
606
606
|
// package.json
|
|
607
|
-
var version = "0.2.
|
|
607
|
+
var version = "0.2.7";
|
|
608
608
|
|
|
609
609
|
// src/git-hooks.ts
|
|
610
610
|
import fs from "fs";
|
|
611
611
|
import path from "path";
|
|
612
|
-
import
|
|
612
|
+
import process4 from "process";
|
|
613
613
|
|
|
614
614
|
// src/config.ts
|
|
615
|
-
import
|
|
615
|
+
import process3 from "process";
|
|
616
616
|
|
|
617
617
|
// node_modules/bunfig/dist/index.js
|
|
618
618
|
import { existsSync, mkdirSync, readdirSync, writeFileSync } from "fs";
|
|
@@ -788,15 +788,15 @@ var defaultConfigDir = resolve(process2.cwd(), "config");
|
|
|
788
788
|
var defaultGeneratedDir = resolve(process2.cwd(), "src/generated");
|
|
789
789
|
|
|
790
790
|
// src/config.ts
|
|
791
|
-
var __dirname = "/home/runner/work/bun-git-hooks/bun-git-hooks/src";
|
|
792
791
|
var defaultConfig = {
|
|
793
792
|
verbose: true
|
|
794
793
|
};
|
|
795
794
|
var config = await loadConfig({
|
|
796
795
|
name: "git-hooks",
|
|
797
|
-
cwd:
|
|
796
|
+
cwd: process3.cwd(),
|
|
798
797
|
defaultConfig
|
|
799
798
|
});
|
|
799
|
+
console.log("config", process3.cwd());
|
|
800
800
|
|
|
801
801
|
// src/git-hooks.ts
|
|
802
802
|
var VALID_GIT_HOOKS = [
|
|
@@ -841,7 +841,7 @@ if [ -f "$BUN_GIT_HOOKS_RC" ]; then
|
|
|
841
841
|
fi
|
|
842
842
|
|
|
843
843
|
`;
|
|
844
|
-
function getGitProjectRoot(directory =
|
|
844
|
+
function getGitProjectRoot(directory = process4.cwd()) {
|
|
845
845
|
if (directory.endsWith(".git")) {
|
|
846
846
|
return path.normalize(directory);
|
|
847
847
|
}
|
|
@@ -872,7 +872,7 @@ function getGitProjectRoot(directory = process3.cwd()) {
|
|
|
872
872
|
}
|
|
873
873
|
return getGitProjectRoot(parentDir);
|
|
874
874
|
}
|
|
875
|
-
function setHooksFromConfig(projectRootPath =
|
|
875
|
+
function setHooksFromConfig(projectRootPath = process4.cwd(), options = {}) {
|
|
876
876
|
if (!config || Object.keys(config).length === 0)
|
|
877
877
|
throw new Error("[ERROR] Config was not found! Please add `.git-hooks.config.{ts,js,mjs,cjs,mts,cts,json}` or `git-hooks.config.{ts,js,mjs,cjs,mts,cts,json}` or the `git-hooks` entry in package.json.\r\nCheck README for details");
|
|
878
878
|
console.log("setHooksFromConfig config", config);
|
|
@@ -897,7 +897,7 @@ function setHooksFromConfig(projectRootPath = process3.cwd(), options = {}) {
|
|
|
897
897
|
}
|
|
898
898
|
}
|
|
899
899
|
}
|
|
900
|
-
function _setHook(hook, command, projectRoot =
|
|
900
|
+
function _setHook(hook, command, projectRoot = process4.cwd()) {
|
|
901
901
|
const gitRoot = getGitProjectRoot(projectRoot);
|
|
902
902
|
if (!gitRoot) {
|
|
903
903
|
console.info("[INFO] No `.git` root folder found, skipping");
|
|
@@ -914,11 +914,11 @@ function _setHook(hook, command, projectRoot = process3.cwd()) {
|
|
|
914
914
|
console.log("Create/Write hook");
|
|
915
915
|
fs.writeFileSync(hookPath, hookCommand, { mode: 493 });
|
|
916
916
|
}
|
|
917
|
-
function removeHooks(projectRoot =
|
|
917
|
+
function removeHooks(projectRoot = process4.cwd(), verbose = false) {
|
|
918
918
|
for (const configEntry of VALID_GIT_HOOKS)
|
|
919
919
|
_removeHook(configEntry, projectRoot, verbose);
|
|
920
920
|
}
|
|
921
|
-
function _removeHook(hook, projectRoot =
|
|
921
|
+
function _removeHook(hook, projectRoot = process4.cwd(), verbose = false) {
|
|
922
922
|
const gitRoot = getGitProjectRoot(projectRoot);
|
|
923
923
|
const hookPath = path.normalize(`${gitRoot}/hooks/${hook}`);
|
|
924
924
|
if (fs.existsSync(hookPath))
|
|
@@ -929,35 +929,35 @@ function _removeHook(hook, projectRoot = process3.cwd(), verbose = false) {
|
|
|
929
929
|
|
|
930
930
|
// bin/cli.ts
|
|
931
931
|
var cli = new CAC("git-hooks");
|
|
932
|
-
var { SKIP_INSTALL_GIT_HOOKS } =
|
|
932
|
+
var { SKIP_INSTALL_GIT_HOOKS } = process5.env;
|
|
933
933
|
if (["1", "true"].includes(SKIP_INSTALL_GIT_HOOKS || "")) {
|
|
934
934
|
console.log(`[INFO] SKIP_INSTALL_GIT_HOOKS is set to "${SKIP_INSTALL_GIT_HOOKS}", skipping installing hooks.`);
|
|
935
|
-
|
|
935
|
+
process5.exit(0);
|
|
936
936
|
}
|
|
937
937
|
cli.command("[configPath]", "Install git hooks, optionally from specified config file").option("--verbose", "Enable verbose logging").example("bun-git-hooks").example("bun-git-hooks ../src/config.ts").example("bun-git-hooks --verbose").action(async (configPath, options) => {
|
|
938
938
|
try {
|
|
939
939
|
if (options?.verbose) {
|
|
940
940
|
console.log("[DEBUG] Config path:", configPath || "using default");
|
|
941
|
-
console.log("[DEBUG] Working directory:",
|
|
941
|
+
console.log("[DEBUG] Working directory:", process5.cwd());
|
|
942
942
|
}
|
|
943
943
|
console.log("setHooksFromConfig", { configFile: configPath });
|
|
944
|
-
setHooksFromConfig(
|
|
944
|
+
setHooksFromConfig(process5.cwd(), { configFile: configPath });
|
|
945
945
|
console.log("[INFO] Successfully set all git hooks");
|
|
946
946
|
} catch (err) {
|
|
947
947
|
console.error("[ERROR] Was not able to set git hooks. Error:", err);
|
|
948
|
-
|
|
948
|
+
process5.exit(1);
|
|
949
949
|
}
|
|
950
950
|
});
|
|
951
951
|
cli.command("uninstall", "Remove all git hooks").alias("remove").option("--verbose", "Enable verbose logging").example("bun-git-hooks uninstall").example("bunx bun-git-hooks remove").example("bunx git-hooks uninstall --verbose").action(async (options) => {
|
|
952
952
|
try {
|
|
953
953
|
if (options?.verbose) {
|
|
954
|
-
console.log("[DEBUG] Removing hooks from:",
|
|
954
|
+
console.log("[DEBUG] Removing hooks from:", process5.cwd());
|
|
955
955
|
}
|
|
956
|
-
removeHooks(
|
|
956
|
+
removeHooks(process5.cwd(), options?.verbose);
|
|
957
957
|
console.log("[INFO] Successfully removed all git hooks");
|
|
958
958
|
} catch (err) {
|
|
959
959
|
console.error("[ERROR] Was not able to remove git hooks. Error:", err);
|
|
960
|
-
|
|
960
|
+
process5.exit(1);
|
|
961
961
|
}
|
|
962
962
|
});
|
|
963
963
|
cli.version(version);
|
package/dist/index.js
CHANGED
|
@@ -1,28 +1,28 @@
|
|
|
1
1
|
var __esm = (fn, res) => () => (fn && (res = fn(fn = 0)), res);
|
|
2
2
|
|
|
3
3
|
// node:process
|
|
4
|
-
var C,
|
|
4
|
+
var C, T, q, A, I, Q, S = (e, t) => () => (t || e((t = { exports: {} }).exports, t), t.exports), N = (e, t) => {
|
|
5
5
|
for (var n in t)
|
|
6
|
-
|
|
6
|
+
T(e, n, { get: t[n], enumerable: true });
|
|
7
7
|
}, d = (e, t, n, w) => {
|
|
8
8
|
if (t && typeof t == "object" || typeof t == "function")
|
|
9
9
|
for (let l of A(t))
|
|
10
|
-
!
|
|
10
|
+
!Q.call(e, l) && l !== n && T(e, l, { get: () => t[l], enumerable: !(w = q(t, l)) || w.enumerable });
|
|
11
11
|
return e;
|
|
12
|
-
},
|
|
12
|
+
}, h = (e, t, n) => (d(e, t, "default"), n && d(n, t, "default")), y = (e, t, n) => (n = e != null ? C(I(e)) : {}, d(t || !e || !e.__esModule ? T(n, "default", { value: e, enumerable: true }) : n, e)), v, f, j;
|
|
13
13
|
var init_process = __esm(() => {
|
|
14
14
|
C = Object.create;
|
|
15
|
-
|
|
16
|
-
|
|
15
|
+
T = Object.defineProperty;
|
|
16
|
+
q = Object.getOwnPropertyDescriptor;
|
|
17
17
|
A = Object.getOwnPropertyNames;
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
v =
|
|
21
|
-
var r =
|
|
18
|
+
I = Object.getPrototypeOf;
|
|
19
|
+
Q = Object.prototype.hasOwnProperty;
|
|
20
|
+
v = S((B, E) => {
|
|
21
|
+
var r = E.exports = {}, i, u;
|
|
22
22
|
function p() {
|
|
23
23
|
throw new Error("setTimeout has not been defined");
|
|
24
24
|
}
|
|
25
|
-
function
|
|
25
|
+
function g() {
|
|
26
26
|
throw new Error("clearTimeout has not been defined");
|
|
27
27
|
}
|
|
28
28
|
(function() {
|
|
@@ -32,9 +32,9 @@ var init_process = __esm(() => {
|
|
|
32
32
|
i = p;
|
|
33
33
|
}
|
|
34
34
|
try {
|
|
35
|
-
typeof clearTimeout == "function" ?
|
|
35
|
+
typeof clearTimeout == "function" ? u = clearTimeout : u = g;
|
|
36
36
|
} catch {
|
|
37
|
-
|
|
37
|
+
u = g;
|
|
38
38
|
}
|
|
39
39
|
})();
|
|
40
40
|
function b(e) {
|
|
@@ -52,35 +52,35 @@ var init_process = __esm(() => {
|
|
|
52
52
|
}
|
|
53
53
|
}
|
|
54
54
|
}
|
|
55
|
-
function
|
|
56
|
-
if (
|
|
55
|
+
function O(e) {
|
|
56
|
+
if (u === clearTimeout)
|
|
57
57
|
return clearTimeout(e);
|
|
58
|
-
if ((
|
|
59
|
-
return
|
|
58
|
+
if ((u === g || !u) && clearTimeout)
|
|
59
|
+
return u = clearTimeout, clearTimeout(e);
|
|
60
60
|
try {
|
|
61
|
-
return
|
|
61
|
+
return u(e);
|
|
62
62
|
} catch {
|
|
63
63
|
try {
|
|
64
|
-
return
|
|
64
|
+
return u.call(null, e);
|
|
65
65
|
} catch {
|
|
66
|
-
return
|
|
66
|
+
return u.call(this, e);
|
|
67
67
|
}
|
|
68
68
|
}
|
|
69
69
|
}
|
|
70
70
|
var o = [], s = false, a, m = -1;
|
|
71
|
-
function
|
|
72
|
-
!s || !a || (s = false, a.length ? o = a.concat(o) : m = -1, o.length &&
|
|
71
|
+
function U() {
|
|
72
|
+
!s || !a || (s = false, a.length ? o = a.concat(o) : m = -1, o.length && x());
|
|
73
73
|
}
|
|
74
|
-
function
|
|
74
|
+
function x() {
|
|
75
75
|
if (!s) {
|
|
76
|
-
var e = b(
|
|
76
|
+
var e = b(U);
|
|
77
77
|
s = true;
|
|
78
78
|
for (var t = o.length;t; ) {
|
|
79
79
|
for (a = o, o = [];++m < t; )
|
|
80
80
|
a && a[m].run();
|
|
81
81
|
m = -1, t = o.length;
|
|
82
82
|
}
|
|
83
|
-
a = null, s = false,
|
|
83
|
+
a = null, s = false, O(e);
|
|
84
84
|
}
|
|
85
85
|
}
|
|
86
86
|
r.nextTick = function(e) {
|
|
@@ -88,12 +88,12 @@ var init_process = __esm(() => {
|
|
|
88
88
|
if (arguments.length > 1)
|
|
89
89
|
for (var n = 1;n < arguments.length; n++)
|
|
90
90
|
t[n - 1] = arguments[n];
|
|
91
|
-
o.push(new
|
|
91
|
+
o.push(new L(e, t)), o.length === 1 && !s && b(x);
|
|
92
92
|
};
|
|
93
|
-
function
|
|
93
|
+
function L(e, t) {
|
|
94
94
|
this.fun = e, this.array = t;
|
|
95
95
|
}
|
|
96
|
-
|
|
96
|
+
L.prototype.run = function() {
|
|
97
97
|
this.fun.apply(null, this.array);
|
|
98
98
|
};
|
|
99
99
|
r.title = "browser";
|
|
@@ -129,32 +129,38 @@ var init_process = __esm(() => {
|
|
|
129
129
|
};
|
|
130
130
|
});
|
|
131
131
|
f = {};
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
132
|
+
N(f, { default: () => j });
|
|
133
|
+
h(f, y(v()));
|
|
134
|
+
j = y(v());
|
|
135
135
|
});
|
|
136
136
|
|
|
137
|
+
// src/config.ts
|
|
138
|
+
init_process();
|
|
139
|
+
|
|
140
|
+
// node_modules/bunfig/dist/index.js
|
|
141
|
+
var {existsSync, mkdirSync, readdirSync, writeFileSync} = (() => ({}));
|
|
142
|
+
|
|
137
143
|
// node:path
|
|
138
144
|
var L = Object.create;
|
|
139
|
-
var
|
|
145
|
+
var h2 = Object.defineProperty;
|
|
140
146
|
var D = Object.getOwnPropertyDescriptor;
|
|
141
|
-
var
|
|
147
|
+
var T2 = Object.getOwnPropertyNames;
|
|
142
148
|
var _ = Object.getPrototypeOf;
|
|
143
149
|
var E = Object.prototype.hasOwnProperty;
|
|
144
150
|
var R = (s, e) => () => (e || s((e = { exports: {} }).exports, e), e.exports);
|
|
145
|
-
var
|
|
151
|
+
var N2 = (s, e, r, t) => {
|
|
146
152
|
if (e && typeof e == "object" || typeof e == "function")
|
|
147
|
-
for (let i of
|
|
148
|
-
!E.call(s, i) && i !== r &&
|
|
153
|
+
for (let i of T2(e))
|
|
154
|
+
!E.call(s, i) && i !== r && h2(s, i, { get: () => e[i], enumerable: !(t = D(e, i)) || t.enumerable });
|
|
149
155
|
return s;
|
|
150
156
|
};
|
|
151
|
-
var
|
|
157
|
+
var j2 = (s, e, r) => (r = s != null ? L(_(s)) : {}, N2(e || !s || !s.__esModule ? h2(r, "default", { value: s, enumerable: true }) : r, s));
|
|
152
158
|
var k = R((W, w) => {
|
|
153
|
-
function
|
|
159
|
+
function v2(s) {
|
|
154
160
|
if (typeof s != "string")
|
|
155
161
|
throw new TypeError("Path must be a string. Received " + JSON.stringify(s));
|
|
156
162
|
}
|
|
157
|
-
function
|
|
163
|
+
function C2(s, e) {
|
|
158
164
|
for (var r = "", t = 0, i = -1, a = 0, n, l = 0;l <= s.length; ++l) {
|
|
159
165
|
if (l < s.length)
|
|
160
166
|
n = s.charCodeAt(l);
|
|
@@ -168,9 +174,9 @@ var k = R((W, w) => {
|
|
|
168
174
|
if (i !== l - 1 && a === 2) {
|
|
169
175
|
if (r.length < 2 || t !== 2 || r.charCodeAt(r.length - 1) !== 46 || r.charCodeAt(r.length - 2) !== 46) {
|
|
170
176
|
if (r.length > 2) {
|
|
171
|
-
var
|
|
172
|
-
if (
|
|
173
|
-
|
|
177
|
+
var f2 = r.lastIndexOf("/");
|
|
178
|
+
if (f2 !== r.length - 1) {
|
|
179
|
+
f2 === -1 ? (r = "", t = 0) : (r = r.slice(0, f2), t = r.length - 1 - r.lastIndexOf("/")), i = l, a = 0;
|
|
174
180
|
continue;
|
|
175
181
|
}
|
|
176
182
|
} else if (r.length === 2 || r.length === 1) {
|
|
@@ -194,55 +200,55 @@ var k = R((W, w) => {
|
|
|
194
200
|
var m = { resolve: function() {
|
|
195
201
|
for (var e = "", r = false, t, i = arguments.length - 1;i >= -1 && !r; i--) {
|
|
196
202
|
var a;
|
|
197
|
-
i >= 0 ? a = arguments[i] : (t === undefined && (t = process.cwd()), a = t),
|
|
203
|
+
i >= 0 ? a = arguments[i] : (t === undefined && (t = process.cwd()), a = t), v2(a), a.length !== 0 && (e = a + "/" + e, r = a.charCodeAt(0) === 47);
|
|
198
204
|
}
|
|
199
|
-
return e =
|
|
205
|
+
return e = C2(e, !r), r ? e.length > 0 ? "/" + e : "/" : e.length > 0 ? e : ".";
|
|
200
206
|
}, normalize: function(e) {
|
|
201
|
-
if (
|
|
207
|
+
if (v2(e), e.length === 0)
|
|
202
208
|
return ".";
|
|
203
209
|
var r = e.charCodeAt(0) === 47, t = e.charCodeAt(e.length - 1) === 47;
|
|
204
|
-
return e =
|
|
210
|
+
return e = C2(e, !r), e.length === 0 && !r && (e = "."), e.length > 0 && t && (e += "/"), r ? "/" + e : e;
|
|
205
211
|
}, isAbsolute: function(e) {
|
|
206
|
-
return
|
|
212
|
+
return v2(e), e.length > 0 && e.charCodeAt(0) === 47;
|
|
207
213
|
}, join: function() {
|
|
208
214
|
if (arguments.length === 0)
|
|
209
215
|
return ".";
|
|
210
216
|
for (var e, r = 0;r < arguments.length; ++r) {
|
|
211
217
|
var t = arguments[r];
|
|
212
|
-
|
|
218
|
+
v2(t), t.length > 0 && (e === undefined ? e = t : e += "/" + t);
|
|
213
219
|
}
|
|
214
220
|
return e === undefined ? "." : m.normalize(e);
|
|
215
221
|
}, relative: function(e, r) {
|
|
216
|
-
if (
|
|
222
|
+
if (v2(e), v2(r), e === r || (e = m.resolve(e), r = m.resolve(r), e === r))
|
|
217
223
|
return "";
|
|
218
224
|
for (var t = 1;t < e.length && e.charCodeAt(t) === 47; ++t)
|
|
219
225
|
;
|
|
220
226
|
for (var i = e.length, a = i - t, n = 1;n < r.length && r.charCodeAt(n) === 47; ++n)
|
|
221
227
|
;
|
|
222
|
-
for (var l = r.length,
|
|
228
|
+
for (var l = r.length, f2 = l - n, c = a < f2 ? a : f2, d2 = -1, o = 0;o <= c; ++o) {
|
|
223
229
|
if (o === c) {
|
|
224
|
-
if (
|
|
230
|
+
if (f2 > c) {
|
|
225
231
|
if (r.charCodeAt(n + o) === 47)
|
|
226
232
|
return r.slice(n + o + 1);
|
|
227
233
|
if (o === 0)
|
|
228
234
|
return r.slice(n + o);
|
|
229
235
|
} else
|
|
230
|
-
a > c && (e.charCodeAt(t + o) === 47 ?
|
|
236
|
+
a > c && (e.charCodeAt(t + o) === 47 ? d2 = o : o === 0 && (d2 = 0));
|
|
231
237
|
break;
|
|
232
238
|
}
|
|
233
|
-
var
|
|
234
|
-
if (
|
|
239
|
+
var A2 = e.charCodeAt(t + o), z = r.charCodeAt(n + o);
|
|
240
|
+
if (A2 !== z)
|
|
235
241
|
break;
|
|
236
|
-
|
|
242
|
+
A2 === 47 && (d2 = o);
|
|
237
243
|
}
|
|
238
244
|
var b = "";
|
|
239
|
-
for (o = t +
|
|
245
|
+
for (o = t + d2 + 1;o <= i; ++o)
|
|
240
246
|
(o === i || e.charCodeAt(o) === 47) && (b.length === 0 ? b += ".." : b += "/..");
|
|
241
|
-
return b.length > 0 ? b + r.slice(n +
|
|
247
|
+
return b.length > 0 ? b + r.slice(n + d2) : (n += d2, r.charCodeAt(n) === 47 && ++n, r.slice(n));
|
|
242
248
|
}, _makeLong: function(e) {
|
|
243
249
|
return e;
|
|
244
250
|
}, dirname: function(e) {
|
|
245
|
-
if (
|
|
251
|
+
if (v2(e), e.length === 0)
|
|
246
252
|
return ".";
|
|
247
253
|
for (var r = e.charCodeAt(0), t = r === 47, i = -1, a = true, n = e.length - 1;n >= 1; --n)
|
|
248
254
|
if (r = e.charCodeAt(n), r === 47) {
|
|
@@ -256,12 +262,12 @@ var k = R((W, w) => {
|
|
|
256
262
|
}, basename: function(e, r) {
|
|
257
263
|
if (r !== undefined && typeof r != "string")
|
|
258
264
|
throw new TypeError('"ext" argument must be a string');
|
|
259
|
-
|
|
265
|
+
v2(e);
|
|
260
266
|
var t = 0, i = -1, a = true, n;
|
|
261
267
|
if (r !== undefined && r.length > 0 && r.length <= e.length) {
|
|
262
268
|
if (r.length === e.length && r === e)
|
|
263
269
|
return "";
|
|
264
|
-
var l = r.length - 1,
|
|
270
|
+
var l = r.length - 1, f2 = -1;
|
|
265
271
|
for (n = e.length - 1;n >= 0; --n) {
|
|
266
272
|
var c = e.charCodeAt(n);
|
|
267
273
|
if (c === 47) {
|
|
@@ -270,9 +276,9 @@ var k = R((W, w) => {
|
|
|
270
276
|
break;
|
|
271
277
|
}
|
|
272
278
|
} else
|
|
273
|
-
|
|
279
|
+
f2 === -1 && (a = false, f2 = n + 1), l >= 0 && (c === r.charCodeAt(l) ? --l === -1 && (i = n) : (l = -1, i = f2));
|
|
274
280
|
}
|
|
275
|
-
return t === i ? i =
|
|
281
|
+
return t === i ? i = f2 : i === -1 && (i = e.length), e.slice(t, i);
|
|
276
282
|
} else {
|
|
277
283
|
for (n = e.length - 1;n >= 0; --n)
|
|
278
284
|
if (e.charCodeAt(n) === 47) {
|
|
@@ -285,17 +291,17 @@ var k = R((W, w) => {
|
|
|
285
291
|
return i === -1 ? "" : e.slice(t, i);
|
|
286
292
|
}
|
|
287
293
|
}, extname: function(e) {
|
|
288
|
-
|
|
294
|
+
v2(e);
|
|
289
295
|
for (var r = -1, t = 0, i = -1, a = true, n = 0, l = e.length - 1;l >= 0; --l) {
|
|
290
|
-
var
|
|
291
|
-
if (
|
|
296
|
+
var f2 = e.charCodeAt(l);
|
|
297
|
+
if (f2 === 47) {
|
|
292
298
|
if (!a) {
|
|
293
299
|
t = l + 1;
|
|
294
300
|
break;
|
|
295
301
|
}
|
|
296
302
|
continue;
|
|
297
303
|
}
|
|
298
|
-
i === -1 && (a = false, i = l + 1),
|
|
304
|
+
i === -1 && (a = false, i = l + 1), f2 === 46 ? r === -1 ? r = l : n !== 1 && (n = 1) : r !== -1 && (n = -1);
|
|
299
305
|
}
|
|
300
306
|
return r === -1 || i === -1 || n === 0 || n === 1 && r === i - 1 && r === t + 1 ? "" : e.slice(r, i);
|
|
301
307
|
}, format: function(e) {
|
|
@@ -303,47 +309,46 @@ var k = R((W, w) => {
|
|
|
303
309
|
throw new TypeError('The "pathObject" argument must be of type Object. Received type ' + typeof e);
|
|
304
310
|
return F("/", e);
|
|
305
311
|
}, parse: function(e) {
|
|
306
|
-
|
|
312
|
+
v2(e);
|
|
307
313
|
var r = { root: "", dir: "", base: "", ext: "", name: "" };
|
|
308
314
|
if (e.length === 0)
|
|
309
315
|
return r;
|
|
310
316
|
var t = e.charCodeAt(0), i = t === 47, a;
|
|
311
317
|
i ? (r.root = "/", a = 1) : a = 0;
|
|
312
|
-
for (var n = -1, l = 0,
|
|
313
|
-
if (t = e.charCodeAt(
|
|
318
|
+
for (var n = -1, l = 0, f2 = -1, c = true, d2 = e.length - 1, o = 0;d2 >= a; --d2) {
|
|
319
|
+
if (t = e.charCodeAt(d2), t === 47) {
|
|
314
320
|
if (!c) {
|
|
315
|
-
l =
|
|
321
|
+
l = d2 + 1;
|
|
316
322
|
break;
|
|
317
323
|
}
|
|
318
324
|
continue;
|
|
319
325
|
}
|
|
320
|
-
|
|
326
|
+
f2 === -1 && (c = false, f2 = d2 + 1), t === 46 ? n === -1 ? n = d2 : o !== 1 && (o = 1) : n !== -1 && (o = -1);
|
|
321
327
|
}
|
|
322
|
-
return n === -1 ||
|
|
328
|
+
return n === -1 || f2 === -1 || o === 0 || o === 1 && n === f2 - 1 && n === l + 1 ? f2 !== -1 && (l === 0 && i ? r.base = r.name = e.slice(1, f2) : r.base = r.name = e.slice(l, f2)) : (l === 0 && i ? (r.name = e.slice(1, n), r.base = e.slice(1, f2)) : (r.name = e.slice(l, n), r.base = e.slice(l, f2)), r.ext = e.slice(n, f2)), l > 0 ? r.dir = e.slice(0, l - 1) : i && (r.dir = "/"), r;
|
|
323
329
|
}, sep: "/", delimiter: ":", win32: null, posix: null };
|
|
324
330
|
m.posix = m;
|
|
325
331
|
w.exports = m;
|
|
326
332
|
});
|
|
327
|
-
var x =
|
|
333
|
+
var x = j2(k());
|
|
328
334
|
var u = x;
|
|
329
335
|
var J = x;
|
|
330
336
|
var P = function(s) {
|
|
331
337
|
return s;
|
|
332
338
|
};
|
|
333
|
-
var
|
|
339
|
+
var S2 = function() {
|
|
334
340
|
throw new Error("Not implemented");
|
|
335
341
|
};
|
|
336
|
-
u.parse ??=
|
|
337
|
-
J.parse ??=
|
|
342
|
+
u.parse ??= S2;
|
|
343
|
+
J.parse ??= S2;
|
|
338
344
|
var g = { resolve: u.resolve.bind(u), normalize: u.normalize.bind(u), isAbsolute: u.isAbsolute.bind(u), join: u.join.bind(u), relative: u.relative.bind(u), toNamespacedPath: P, dirname: u.dirname.bind(u), basename: u.basename.bind(u), extname: u.extname.bind(u), format: u.format.bind(u), parse: u.parse.bind(u), sep: "/", delimiter: ":", win32: undefined, posix: undefined, _makeLong: P };
|
|
339
|
-
var
|
|
340
|
-
g.win32 =
|
|
345
|
+
var y2 = { sep: "\\", delimiter: ";", win32: undefined, ...g, posix: g };
|
|
346
|
+
g.win32 = y2.win32 = y2;
|
|
341
347
|
g.posix = g;
|
|
342
|
-
var
|
|
343
|
-
var { resolve: B, normalize: G, isAbsolute: H, join: K, relative:
|
|
348
|
+
var q2 = g;
|
|
349
|
+
var { resolve: B, normalize: G, isAbsolute: H, join: K, relative: Q2, toNamespacedPath: U, dirname: V, basename: X, extname: Y, format: Z, parse: $, sep: I2, delimiter: O } = g;
|
|
344
350
|
|
|
345
351
|
// node_modules/bunfig/dist/index.js
|
|
346
|
-
var {existsSync, mkdirSync, readdirSync, writeFileSync} = (() => ({}));
|
|
347
352
|
init_process();
|
|
348
353
|
function deepMerge(target, source) {
|
|
349
354
|
if (Array.isArray(source) && Array.isArray(target) && source.length === 2 && target.length === 2 && isObject(source[0]) && "id" in source[0] && source[0].id === 3 && isObject(source[1]) && "id" in source[1] && source[1].id === 4) {
|
|
@@ -492,7 +497,7 @@ async function loadConfig({
|
|
|
492
497
|
cwd,
|
|
493
498
|
defaultConfig
|
|
494
499
|
}) {
|
|
495
|
-
const baseDir = cwd ||
|
|
500
|
+
const baseDir = cwd || j.cwd();
|
|
496
501
|
const extensions = [".ts", ".js", ".mjs", ".cjs", ".json"];
|
|
497
502
|
const configPaths = [
|
|
498
503
|
`${name}.config`,
|
|
@@ -511,19 +516,19 @@ async function loadConfig({
|
|
|
511
516
|
console.error("Failed to load client config from any expected location");
|
|
512
517
|
return defaultConfig;
|
|
513
518
|
}
|
|
514
|
-
var defaultConfigDir = B(
|
|
515
|
-
var defaultGeneratedDir = B(
|
|
519
|
+
var defaultConfigDir = B(j.cwd(), "config");
|
|
520
|
+
var defaultGeneratedDir = B(j.cwd(), "src/generated");
|
|
516
521
|
|
|
517
522
|
// src/config.ts
|
|
518
|
-
var __dirname = "/home/runner/work/bun-git-hooks/bun-git-hooks/src";
|
|
519
523
|
var defaultConfig = {
|
|
520
524
|
verbose: true
|
|
521
525
|
};
|
|
522
526
|
var config = await loadConfig({
|
|
523
527
|
name: "git-hooks",
|
|
524
|
-
cwd:
|
|
528
|
+
cwd: j.cwd(),
|
|
525
529
|
defaultConfig
|
|
526
530
|
});
|
|
531
|
+
console.log("config", j.cwd());
|
|
527
532
|
// src/git-hooks.ts
|
|
528
533
|
var { default: fs} = (() => ({}));
|
|
529
534
|
init_process();
|
|
@@ -570,32 +575,32 @@ if [ -f "$BUN_GIT_HOOKS_RC" ]; then
|
|
|
570
575
|
fi
|
|
571
576
|
|
|
572
577
|
`;
|
|
573
|
-
function getGitProjectRoot(directory =
|
|
578
|
+
function getGitProjectRoot(directory = j.cwd()) {
|
|
574
579
|
if (directory.endsWith(".git")) {
|
|
575
|
-
return
|
|
580
|
+
return q2.normalize(directory);
|
|
576
581
|
}
|
|
577
|
-
let start =
|
|
578
|
-
if (!start || start ===
|
|
582
|
+
let start = q2.normalize(directory);
|
|
583
|
+
if (!start || start === q2.sep || start === ".") {
|
|
579
584
|
return;
|
|
580
585
|
}
|
|
581
|
-
const fullPath =
|
|
586
|
+
const fullPath = q2.join(start, ".git");
|
|
582
587
|
if (fs.existsSync(fullPath)) {
|
|
583
588
|
if (!fs.lstatSync(fullPath).isDirectory()) {
|
|
584
589
|
const content = fs.readFileSync(fullPath, { encoding: "utf-8" });
|
|
585
590
|
const match = /^gitdir: (.*)\s*$/.exec(content);
|
|
586
591
|
if (match) {
|
|
587
592
|
const gitDir = match[1];
|
|
588
|
-
let commonDir =
|
|
593
|
+
let commonDir = q2.join(gitDir, "commondir");
|
|
589
594
|
if (fs.existsSync(commonDir)) {
|
|
590
595
|
commonDir = fs.readFileSync(commonDir, "utf8").trim();
|
|
591
|
-
return
|
|
596
|
+
return q2.resolve(gitDir, commonDir);
|
|
592
597
|
}
|
|
593
|
-
return
|
|
598
|
+
return q2.normalize(gitDir);
|
|
594
599
|
}
|
|
595
600
|
}
|
|
596
|
-
return
|
|
601
|
+
return q2.normalize(fullPath);
|
|
597
602
|
}
|
|
598
|
-
const parentDir =
|
|
603
|
+
const parentDir = q2.dirname(start);
|
|
599
604
|
if (parentDir === start) {
|
|
600
605
|
return;
|
|
601
606
|
}
|
|
@@ -632,18 +637,18 @@ function checkBunGitHooksInDependencies(projectRootPath) {
|
|
|
632
637
|
}
|
|
633
638
|
return "bun-git-hooks" in packageJsonContent.devDependencies;
|
|
634
639
|
}
|
|
635
|
-
function _getPackageJson(projectPath =
|
|
640
|
+
function _getPackageJson(projectPath = j.cwd()) {
|
|
636
641
|
if (typeof projectPath !== "string") {
|
|
637
642
|
throw new TypeError("projectPath is not a string");
|
|
638
643
|
}
|
|
639
|
-
const targetPackageJson =
|
|
644
|
+
const targetPackageJson = q2.normalize(`${projectPath}/package.json`);
|
|
640
645
|
if (!fs.statSync(targetPackageJson).isFile()) {
|
|
641
646
|
throw new Error("Package.json doesn't exist");
|
|
642
647
|
}
|
|
643
648
|
const packageJsonDataRaw = fs.readFileSync(targetPackageJson, { encoding: "utf-8" });
|
|
644
649
|
return { packageJsonContent: JSON.parse(packageJsonDataRaw), packageJsonPath: targetPackageJson };
|
|
645
650
|
}
|
|
646
|
-
function setHooksFromConfig(projectRootPath =
|
|
651
|
+
function setHooksFromConfig(projectRootPath = j.cwd(), options = {}) {
|
|
647
652
|
if (!config || Object.keys(config).length === 0)
|
|
648
653
|
throw new Error("[ERROR] Config was not found! Please add `.git-hooks.config.{ts,js,mjs,cjs,mts,cts,json}` or `git-hooks.config.{ts,js,mjs,cjs,mts,cts,json}` or the `git-hooks` entry in package.json.\r\nCheck README for details");
|
|
649
654
|
console.log("setHooksFromConfig config", config);
|
|
@@ -668,15 +673,15 @@ function setHooksFromConfig(projectRootPath = j2.cwd(), options = {}) {
|
|
|
668
673
|
}
|
|
669
674
|
}
|
|
670
675
|
}
|
|
671
|
-
function _setHook(hook, command, projectRoot =
|
|
676
|
+
function _setHook(hook, command, projectRoot = j.cwd()) {
|
|
672
677
|
const gitRoot = getGitProjectRoot(projectRoot);
|
|
673
678
|
if (!gitRoot) {
|
|
674
679
|
console.info("[INFO] No `.git` root folder found, skipping");
|
|
675
680
|
return;
|
|
676
681
|
}
|
|
677
682
|
const hookCommand = PREPEND_SCRIPT + command;
|
|
678
|
-
const hookDirectory =
|
|
679
|
-
const hookPath =
|
|
683
|
+
const hookDirectory = q2.join(gitRoot, "hooks");
|
|
684
|
+
const hookPath = q2.normalize(q2.join(hookDirectory, hook));
|
|
680
685
|
console.log("hook", { hookPath, hookCommand, hookDirectory });
|
|
681
686
|
if (!fs.existsSync(hookDirectory)) {
|
|
682
687
|
console.log("hook folder not exists");
|
|
@@ -685,13 +690,13 @@ function _setHook(hook, command, projectRoot = j2.cwd()) {
|
|
|
685
690
|
console.log("Create/Write hook");
|
|
686
691
|
fs.writeFileSync(hookPath, hookCommand, { mode: 493 });
|
|
687
692
|
}
|
|
688
|
-
function removeHooks(projectRoot =
|
|
693
|
+
function removeHooks(projectRoot = j.cwd(), verbose = false) {
|
|
689
694
|
for (const configEntry of VALID_GIT_HOOKS)
|
|
690
695
|
_removeHook(configEntry, projectRoot, verbose);
|
|
691
696
|
}
|
|
692
|
-
function _removeHook(hook, projectRoot =
|
|
697
|
+
function _removeHook(hook, projectRoot = j.cwd(), verbose = false) {
|
|
693
698
|
const gitRoot = getGitProjectRoot(projectRoot);
|
|
694
|
-
const hookPath =
|
|
699
|
+
const hookPath = q2.normalize(`${gitRoot}/hooks/${hook}`);
|
|
695
700
|
if (fs.existsSync(hookPath))
|
|
696
701
|
fs.unlinkSync(hookPath);
|
|
697
702
|
if (verbose)
|
package/package.json
CHANGED