@vibe-validate/git 0.14.2 → 0.15.0-rc.1
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/branch-sync.d.ts.map +1 -1
- package/dist/branch-sync.js +9 -7
- package/dist/branch-sync.js.map +1 -1
- package/dist/cache-key.d.ts +44 -0
- package/dist/cache-key.d.ts.map +1 -0
- package/dist/cache-key.js +89 -0
- package/dist/cache-key.js.map +1 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +4 -0
- package/dist/index.js.map +1 -1
- package/dist/post-merge-cleanup.d.ts +24 -0
- package/dist/post-merge-cleanup.d.ts.map +1 -1
- package/dist/post-merge-cleanup.js +81 -36
- package/dist/post-merge-cleanup.js.map +1 -1
- package/dist/tree-hash.d.ts.map +1 -1
- package/dist/tree-hash.js +6 -7
- package/dist/tree-hash.js.map +1 -1
- package/dist/yaml-detection.d.ts +65 -0
- package/dist/yaml-detection.d.ts.map +1 -0
- package/dist/yaml-detection.js +102 -0
- package/dist/yaml-detection.js.map +1 -0
- package/package.json +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"branch-sync.d.ts","sourceRoot":"","sources":["../src/branch-sync.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAMH,MAAM,WAAW,eAAe;IAC9B,UAAU,EAAE,OAAO,CAAC;IACpB,QAAQ,EAAE,MAAM,CAAC;IACjB,aAAa,EAAE,MAAM,CAAC;IACtB,SAAS,EAAE,OAAO,CAAC;IACnB,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB;AAGD,MAAM,MAAM,WAAW,GAAG,CAAC,KAAK,EAAE,MAAM,EAAE,KAAK,OAAO,CAAC;IAAE,MAAM,EAAE,MAAM,CAAC;IAAC,MAAM,EAAE,MAAM,CAAA;CAAE,CAAC,CAAC;AAE3F,MAAM,WAAW,gBAAgB;IAC/B,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,WAAW,CAAC,EAAE,WAAW,CAAC;CAC3B;
|
|
1
|
+
{"version":3,"file":"branch-sync.d.ts","sourceRoot":"","sources":["../src/branch-sync.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAMH,MAAM,WAAW,eAAe;IAC9B,UAAU,EAAE,OAAO,CAAC;IACpB,QAAQ,EAAE,MAAM,CAAC;IACjB,aAAa,EAAE,MAAM,CAAC;IACtB,SAAS,EAAE,OAAO,CAAC;IACnB,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB;AAGD,MAAM,MAAM,WAAW,GAAG,CAAC,KAAK,EAAE,MAAM,EAAE,KAAK,OAAO,CAAC;IAAE,MAAM,EAAE,MAAM,CAAC;IAAC,MAAM,EAAE,MAAM,CAAA;CAAE,CAAC,CAAC;AAE3F,MAAM,WAAW,gBAAgB;IAC/B,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,WAAW,CAAC,EAAE,WAAW,CAAC;CAC3B;AA4CD;;;;GAIG;AACH,qBAAa,iBAAiB;IAC5B,OAAO,CAAC,QAAQ,CAAC,YAAY,CAAS;IACtC,OAAO,CAAC,QAAQ,CAAC,WAAW,CAAc;gBAE9B,OAAO,GAAE,gBAAqB;IAK1C;;;;OAIG;IACG,SAAS,IAAI,OAAO,CAAC,eAAe,CAAC;YA0C7B,gBAAgB;YAUhB,eAAe;YAUf,WAAW;YAUX,gBAAgB;IAW9B;;;;;OAKG;IACH,WAAW,CAAC,MAAM,EAAE,eAAe,GAAG,MAAM;CAK7C;AAED;;;;;GAKG;AACH,wBAAsB,eAAe,CAAC,OAAO,GAAE,gBAAqB,GAAG,OAAO,CAAC,eAAe,CAAC,CAG9F"}
|
package/dist/branch-sync.js
CHANGED
|
@@ -10,7 +10,7 @@
|
|
|
10
10
|
* - Explicit instructions when manual intervention needed
|
|
11
11
|
* - Cross-platform compatibility
|
|
12
12
|
*/
|
|
13
|
-
import { spawn } from 'child_process';
|
|
13
|
+
import { spawn } from 'node:child_process';
|
|
14
14
|
const GIT_TIMEOUT = 30000; // 30 seconds timeout for git operations
|
|
15
15
|
/**
|
|
16
16
|
* Execute git command safely using spawn (prevents command injection)
|
|
@@ -21,7 +21,8 @@ const GIT_TIMEOUT = 30000; // 30 seconds timeout for git operations
|
|
|
21
21
|
function execGit(args) {
|
|
22
22
|
return new Promise((resolve, reject) => {
|
|
23
23
|
const child = spawn('git', args, {
|
|
24
|
-
timeout: GIT_TIMEOUT
|
|
24
|
+
timeout: GIT_TIMEOUT,
|
|
25
|
+
stdio: ['ignore', 'pipe', 'pipe'], // No stdin (git commands shouldn't need interactive input), capture stdout/stderr
|
|
25
26
|
});
|
|
26
27
|
let stdout = '';
|
|
27
28
|
let stderr = '';
|
|
@@ -57,8 +58,8 @@ export class BranchSyncChecker {
|
|
|
57
58
|
remoteBranch;
|
|
58
59
|
gitExecutor;
|
|
59
60
|
constructor(options = {}) {
|
|
60
|
-
this.remoteBranch = options.remoteBranch
|
|
61
|
-
this.gitExecutor = options.gitExecutor
|
|
61
|
+
this.remoteBranch = options.remoteBranch ?? 'origin/main';
|
|
62
|
+
this.gitExecutor = options.gitExecutor ?? execGit;
|
|
62
63
|
}
|
|
63
64
|
/**
|
|
64
65
|
* Check if the current branch is synchronized with remote branch
|
|
@@ -117,7 +118,8 @@ export class BranchSyncChecker {
|
|
|
117
118
|
await this.gitExecutor(['rev-parse', '--verify', this.remoteBranch]);
|
|
118
119
|
return true;
|
|
119
120
|
}
|
|
120
|
-
catch
|
|
121
|
+
catch {
|
|
122
|
+
// Expected when remote branch doesn't exist
|
|
121
123
|
return false;
|
|
122
124
|
}
|
|
123
125
|
}
|
|
@@ -134,8 +136,8 @@ export class BranchSyncChecker {
|
|
|
134
136
|
async getCommitsBehind() {
|
|
135
137
|
try {
|
|
136
138
|
const { stdout } = await this.gitExecutor(['rev-list', '--count', `HEAD..${this.remoteBranch}`]);
|
|
137
|
-
const count = parseInt(stdout.trim(), 10);
|
|
138
|
-
return isNaN(count) ? 0 : count;
|
|
139
|
+
const count = Number.parseInt(stdout.trim(), 10);
|
|
140
|
+
return Number.isNaN(count) ? 0 : count;
|
|
139
141
|
}
|
|
140
142
|
catch (error) {
|
|
141
143
|
const errorMessage = error instanceof Error ? error.message : String(error);
|
package/dist/branch-sync.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"branch-sync.js","sourceRoot":"","sources":["../src/branch-sync.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAEH,OAAO,EAAE,KAAK,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"branch-sync.js","sourceRoot":"","sources":["../src/branch-sync.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAEH,OAAO,EAAE,KAAK,EAAE,MAAM,oBAAoB,CAAC;AAE3C,MAAM,WAAW,GAAG,KAAK,CAAC,CAAC,wCAAwC;AAkBnE;;;;;GAKG;AACH,SAAS,OAAO,CAAC,IAAc;IAC7B,OAAO,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE;QACrC,MAAM,KAAK,GAAG,KAAK,CAAC,KAAK,EAAE,IAAI,EAAE;YAC/B,OAAO,EAAE,WAAW;YACpB,KAAK,EAAE,CAAC,QAAQ,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,kFAAkF;SACtH,CAAC,CAAC;QAEH,IAAI,MAAM,GAAG,EAAE,CAAC;QAChB,IAAI,MAAM,GAAG,EAAE,CAAC;QAEhB,IAAI,KAAK,CAAC,MAAM,EAAE,CAAC;YACjB,KAAK,CAAC,MAAM,CAAC,EAAE,CAAC,MAAM,EAAE,CAAC,IAAY,EAAE,EAAE;gBACvC,MAAM,IAAI,IAAI,CAAC,QAAQ,EAAE,CAAC;YAC5B,CAAC,CAAC,CAAC;QACL,CAAC;QAED,IAAI,KAAK,CAAC,MAAM,EAAE,CAAC;YACjB,KAAK,CAAC,MAAM,CAAC,EAAE,CAAC,MAAM,EAAE,CAAC,IAAY,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AC,CAAC;QACrE,CAAC;IACH,CAAC;IAED;;;;;OAKG;IACH,WAAW,CAAC,MAAuB;QACjC,IAAI,MAAM,CAAC,KAAK;YAAE,OAAO,CAAC,CAAC,CAAC,kBAAkB;QAC9C,IAAI,CAAC,MAAM,CAAC,SAAS;YAAE,OAAO,CAAC,CAAC,CAAC,yBAAyB;QAC1D,OAAO,MAAM,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,kCAAkC;IACtE,CAAC;CACF;AAED;;;;;GAKG;AACH,MAAM,CAAC,KAAK,UAAU,eAAe,CAAC,UAA4B,EAAE;IAClE,MAAM,OAAO,GAAG,IAAI,iBAAiB,CAAC,OAAO,CAAC,CAAC;IAC/C,OAAO,OAAO,CAAC,SAAS,EAAE,CAAC;AAC7B,CAAC"}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Cache key encoding for run command results
|
|
3
|
+
*
|
|
4
|
+
* Generates deterministic cache keys for storing command execution results in git notes.
|
|
5
|
+
*/
|
|
6
|
+
/**
|
|
7
|
+
* Encode a run command cache key
|
|
8
|
+
*
|
|
9
|
+
* Cache keys uniquely identify command+workdir combinations for caching purposes.
|
|
10
|
+
*
|
|
11
|
+
* Normalization rules:
|
|
12
|
+
* - Always trim leading/trailing whitespace from command and workdir
|
|
13
|
+
* - For simple commands (no quotes/escapes/shell metacharacters): collapse multiple spaces
|
|
14
|
+
* - For complex commands (has quotes, escapes, etc.): preserve internal spacing
|
|
15
|
+
*
|
|
16
|
+
* Format:
|
|
17
|
+
* - SHA256 hash of `command__workdir` (first 16 chars for brevity)
|
|
18
|
+
* - Examples: `85ac6127576393ac` (for command+workdir combination)
|
|
19
|
+
*
|
|
20
|
+
* @param command - The command to run (e.g., "npm test")
|
|
21
|
+
* @param workdir - Working directory relative to git root ("" for root, "packages/cli" for subdirectory)
|
|
22
|
+
* @returns SHA256 hash (first 16 chars) suitable for use in git ref paths
|
|
23
|
+
*
|
|
24
|
+
* @example
|
|
25
|
+
* ```ts
|
|
26
|
+
* // Simple command at root
|
|
27
|
+
* encodeRunCacheKey('npm test', '')
|
|
28
|
+
* // → SHA256('npm test__')[:16]
|
|
29
|
+
*
|
|
30
|
+
* // Command with workdir
|
|
31
|
+
* encodeRunCacheKey('npm test', 'packages/cli')
|
|
32
|
+
* // → SHA256('npm test__packages/cli')[:16]
|
|
33
|
+
*
|
|
34
|
+
* // Whitespace normalization (simple commands)
|
|
35
|
+
* encodeRunCacheKey(' npm test ', '')
|
|
36
|
+
* // → SHA256('npm test__')[:16]
|
|
37
|
+
*
|
|
38
|
+
* // Complex command (preserve internal spacing)
|
|
39
|
+
* encodeRunCacheKey('echo "hello world"', '')
|
|
40
|
+
* // → SHA256('echo "hello world"__')[:16]
|
|
41
|
+
* ```
|
|
42
|
+
*/
|
|
43
|
+
export declare function encodeRunCacheKey(command: string, workdir: string): string;
|
|
44
|
+
//# sourceMappingURL=cache-key.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cache-key.d.ts","sourceRoot":"","sources":["../src/cache-key.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAkCH;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAoCG;AACH,wBAAgB,iBAAiB,CAAC,OAAO,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,GAAG,MAAM,CAqB1E"}
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Cache key encoding for run command results
|
|
3
|
+
*
|
|
4
|
+
* Generates deterministic cache keys for storing command execution results in git notes.
|
|
5
|
+
*/
|
|
6
|
+
import { createHash } from 'node:crypto';
|
|
7
|
+
/**
|
|
8
|
+
* Shell metacharacters that indicate a "complex" command where internal spacing should be preserved
|
|
9
|
+
*/
|
|
10
|
+
const SHELL_METACHARACTERS = [
|
|
11
|
+
'"', // Double quotes
|
|
12
|
+
"'", // Single quotes
|
|
13
|
+
'`', // Backticks
|
|
14
|
+
'\\', // Backslash escapes
|
|
15
|
+
'|', // Pipes
|
|
16
|
+
'>', // Output redirect
|
|
17
|
+
'<', // Input redirect
|
|
18
|
+
'&', // Background/AND
|
|
19
|
+
';', // Command separator
|
|
20
|
+
'$', // Variable expansion
|
|
21
|
+
];
|
|
22
|
+
/**
|
|
23
|
+
* Check if command contains shell metacharacters that require preserving internal spacing
|
|
24
|
+
*/
|
|
25
|
+
function isComplexCommand(command) {
|
|
26
|
+
return SHELL_METACHARACTERS.some(char => command.includes(char));
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Normalize whitespace in a simple command (collapse multiple spaces/tabs to single space)
|
|
30
|
+
*/
|
|
31
|
+
function normalizeWhitespace(str) {
|
|
32
|
+
return str.replace(/\s+/g, ' ');
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Encode a run command cache key
|
|
36
|
+
*
|
|
37
|
+
* Cache keys uniquely identify command+workdir combinations for caching purposes.
|
|
38
|
+
*
|
|
39
|
+
* Normalization rules:
|
|
40
|
+
* - Always trim leading/trailing whitespace from command and workdir
|
|
41
|
+
* - For simple commands (no quotes/escapes/shell metacharacters): collapse multiple spaces
|
|
42
|
+
* - For complex commands (has quotes, escapes, etc.): preserve internal spacing
|
|
43
|
+
*
|
|
44
|
+
* Format:
|
|
45
|
+
* - SHA256 hash of `command__workdir` (first 16 chars for brevity)
|
|
46
|
+
* - Examples: `85ac6127576393ac` (for command+workdir combination)
|
|
47
|
+
*
|
|
48
|
+
* @param command - The command to run (e.g., "npm test")
|
|
49
|
+
* @param workdir - Working directory relative to git root ("" for root, "packages/cli" for subdirectory)
|
|
50
|
+
* @returns SHA256 hash (first 16 chars) suitable for use in git ref paths
|
|
51
|
+
*
|
|
52
|
+
* @example
|
|
53
|
+
* ```ts
|
|
54
|
+
* // Simple command at root
|
|
55
|
+
* encodeRunCacheKey('npm test', '')
|
|
56
|
+
* // → SHA256('npm test__')[:16]
|
|
57
|
+
*
|
|
58
|
+
* // Command with workdir
|
|
59
|
+
* encodeRunCacheKey('npm test', 'packages/cli')
|
|
60
|
+
* // → SHA256('npm test__packages/cli')[:16]
|
|
61
|
+
*
|
|
62
|
+
* // Whitespace normalization (simple commands)
|
|
63
|
+
* encodeRunCacheKey(' npm test ', '')
|
|
64
|
+
* // → SHA256('npm test__')[:16]
|
|
65
|
+
*
|
|
66
|
+
* // Complex command (preserve internal spacing)
|
|
67
|
+
* encodeRunCacheKey('echo "hello world"', '')
|
|
68
|
+
* // → SHA256('echo "hello world"__')[:16]
|
|
69
|
+
* ```
|
|
70
|
+
*/
|
|
71
|
+
export function encodeRunCacheKey(command, workdir) {
|
|
72
|
+
// Trim leading/trailing whitespace
|
|
73
|
+
const trimmedCommand = command.trim();
|
|
74
|
+
const trimmedWorkdir = workdir.trim();
|
|
75
|
+
// Handle empty command
|
|
76
|
+
if (trimmedCommand === '') {
|
|
77
|
+
return '';
|
|
78
|
+
}
|
|
79
|
+
// Normalize whitespace for simple commands only
|
|
80
|
+
const normalizedCommand = isComplexCommand(trimmedCommand)
|
|
81
|
+
? trimmedCommand
|
|
82
|
+
: normalizeWhitespace(trimmedCommand);
|
|
83
|
+
// Construct cache key input (command__workdir)
|
|
84
|
+
const cacheKeyInput = `${normalizedCommand}__${trimmedWorkdir}`;
|
|
85
|
+
// Hash for safe use in git ref paths (URL encoding produces % which git rejects)
|
|
86
|
+
// Use first 16 chars for brevity while maintaining uniqueness
|
|
87
|
+
return createHash('sha256').update(cacheKeyInput).digest('hex').substring(0, 16);
|
|
88
|
+
}
|
|
89
|
+
//# sourceMappingURL=cache-key.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cache-key.js","sourceRoot":"","sources":["../src/cache-key.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAEzC;;GAEG;AACH,MAAM,oBAAoB,GAAG;IAC3B,GAAG,EA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CAAC,CAAC,EAAE,EAAE,CAAC,CAAC;AACnF,CAAC"}
|
package/dist/index.d.ts
CHANGED
|
@@ -9,4 +9,6 @@
|
|
|
9
9
|
export { getGitTreeHash, getHeadTreeHash, hasWorkingTreeChanges } from './tree-hash.js';
|
|
10
10
|
export { BranchSyncChecker, checkBranchSync, type SyncCheckResult, type SyncCheckOptions } from './branch-sync.js';
|
|
11
11
|
export { PostPRMergeCleanup, cleanupMergedBranches, type CleanupResult, type CleanupOptions } from './post-merge-cleanup.js';
|
|
12
|
+
export { encodeRunCacheKey } from './cache-key.js';
|
|
13
|
+
export { extractYamlContent, extractYamlWithPreamble } from './yaml-detection.js';
|
|
12
14
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAGH,OAAO,EACL,cAAc,EACd,eAAe,EACf,qBAAqB,EACtB,MAAM,gBAAgB,CAAC;AAGxB,OAAO,EACL,iBAAiB,EACjB,eAAe,EACf,KAAK,eAAe,EACpB,KAAK,gBAAgB,EACtB,MAAM,kBAAkB,CAAC;AAG1B,OAAO,EACL,kBAAkB,EAClB,qBAAqB,EACrB,KAAK,aAAa,EAClB,KAAK,cAAc,EACpB,MAAM,yBAAyB,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAGH,OAAO,EACL,cAAc,EACd,eAAe,EACf,qBAAqB,EACtB,MAAM,gBAAgB,CAAC;AAGxB,OAAO,EACL,iBAAiB,EACjB,eAAe,EACf,KAAK,eAAe,EACpB,KAAK,gBAAgB,EACtB,MAAM,kBAAkB,CAAC;AAG1B,OAAO,EACL,kBAAkB,EAClB,qBAAqB,EACrB,KAAK,aAAa,EAClB,KAAK,cAAc,EACpB,MAAM,yBAAyB,CAAC;AAGjC,OAAO,EACL,iBAAiB,EAClB,MAAM,gBAAgB,CAAC;AAGxB,OAAO,EACL,kBAAkB,EAClB,uBAAuB,EACxB,MAAM,qBAAqB,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -12,4 +12,8 @@ export { getGitTreeHash, getHeadTreeHash, hasWorkingTreeChanges } from './tree-h
|
|
|
12
12
|
export { BranchSyncChecker, checkBranchSync } from './branch-sync.js';
|
|
13
13
|
// Post-merge cleanup (delete merged branches)
|
|
14
14
|
export { PostPRMergeCleanup, cleanupMergedBranches } from './post-merge-cleanup.js';
|
|
15
|
+
// Cache key encoding for run command
|
|
16
|
+
export { encodeRunCacheKey } from './cache-key.js';
|
|
17
|
+
// YAML output detection
|
|
18
|
+
export { extractYamlContent, extractYamlWithPreamble } from './yaml-detection.js';
|
|
15
19
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,uDAAuD;AACvD,OAAO,EACL,cAAc,EACd,eAAe,EACf,qBAAqB,EACtB,MAAM,gBAAgB,CAAC;AAExB,6CAA6C;AAC7C,OAAO,EACL,iBAAiB,EACjB,eAAe,EAGhB,MAAM,kBAAkB,CAAC;AAE1B,8CAA8C;AAC9C,OAAO,EACL,kBAAkB,EAClB,qBAAqB,EAGtB,MAAM,yBAAyB,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,uDAAuD;AACvD,OAAO,EACL,cAAc,EACd,eAAe,EACf,qBAAqB,EACtB,MAAM,gBAAgB,CAAC;AAExB,6CAA6C;AAC7C,OAAO,EACL,iBAAiB,EACjB,eAAe,EAGhB,MAAM,kBAAkB,CAAC;AAE1B,8CAA8C;AAC9C,OAAO,EACL,kBAAkB,EAClB,qBAAqB,EAGtB,MAAM,yBAAyB,CAAC;AAEjC,qCAAqC;AACrC,OAAO,EACL,iBAAiB,EAClB,MAAM,gBAAgB,CAAC;AAExB,wBAAwB;AACxB,OAAO,EACL,kBAAkB,EAClB,uBAAuB,EACxB,MAAM,qBAAqB,CAAC"}
|
|
@@ -58,6 +58,30 @@ export declare class PostPRMergeCleanup {
|
|
|
58
58
|
* Find and delete branches that have been merged
|
|
59
59
|
*/
|
|
60
60
|
private deleteMergedBranches;
|
|
61
|
+
/**
|
|
62
|
+
* Get list of local branches to check (excluding main branch)
|
|
63
|
+
*/
|
|
64
|
+
private getLocalBranchesToCheck;
|
|
65
|
+
/**
|
|
66
|
+
* Process list of branches and delete merged ones
|
|
67
|
+
*/
|
|
68
|
+
private processMergedBranches;
|
|
69
|
+
/**
|
|
70
|
+
* Handle deletion of a single branch (dry run or actual deletion)
|
|
71
|
+
*/
|
|
72
|
+
private handleBranchDeletion;
|
|
73
|
+
/**
|
|
74
|
+
* Try to delete a branch (with fallback to force delete)
|
|
75
|
+
*/
|
|
76
|
+
private tryDeleteBranch;
|
|
77
|
+
/**
|
|
78
|
+
* Attempt regular branch deletion (git branch -d)
|
|
79
|
+
*/
|
|
80
|
+
private attemptRegularDelete;
|
|
81
|
+
/**
|
|
82
|
+
* Attempt force branch deletion (git branch -D)
|
|
83
|
+
*/
|
|
84
|
+
private attemptForceDelete;
|
|
61
85
|
/**
|
|
62
86
|
* Check if a branch has been merged into main
|
|
63
87
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"post-merge-cleanup.d.ts","sourceRoot":"","sources":["../src/post-merge-cleanup.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AA4BH,MAAM,WAAW,aAAa;IAC5B,OAAO,EAAE,OAAO,CAAC;IACjB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,eAAe,EAAE,MAAM,EAAE,CAAC;IAC1B,aAAa,EAAE,MAAM,CAAC;IACtB,UAAU,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,GAAE,cAAmB;IAMxC;;OAEG;IACG,UAAU,IAAI,OAAO,CAAC,aAAa,CAAC;IAqC1C;;OAEG;IACH,OAAO,CAAC,gBAAgB;IAQxB;;OAEG;IACH,OAAO,CAAC,YAAY;IAQpB;;OAEG;IACH,OAAO,CAAC,cAAc;IAatB;;OAEG;IACH,OAAO,CAAC,eAAe;IAQvB;;OAEG;IACH,OAAO,CAAC,oBAAoB;IAU5B;;OAEG;IACH,OAAO,CAAC,uBAAuB;IAS/B;;OAEG;IACH,OAAO,CAAC,qBAAqB;IAe7B;;OAEG;IACH,OAAO,CAAC,oBAAoB;IAQ5B;;OAEG;IACH,OAAO,CAAC,eAAe;IAUvB;;OAEG;IACH,OAAO,CAAC,oBAAoB;IAU5B;;OAEG;IACH,OAAO,CAAC,kBAAkB;IAU1B;;OAEG;IACH,OAAO,CAAC,cAAc;IAYtB;;OAEG;IACH,OAAO,CAAC,qBAAqB;CAO9B;AAED;;;;;GAKG;AACH,wBAAsB,qBAAqB,CAAC,OAAO,GAAE,cAAmB,GAAG,OAAO,CAAC,aAAa,CAAC,CAGhG"}
|
|
@@ -12,7 +12,7 @@
|
|
|
12
12
|
* - Never deletes the current main branch or unmerged branches
|
|
13
13
|
* - Provides clear feedback on all actions taken
|
|
14
14
|
*/
|
|
15
|
-
import { spawnSync } from 'child_process';
|
|
15
|
+
import { spawnSync } from 'node:child_process';
|
|
16
16
|
const TIMEOUT = 30000; // 30 seconds timeout for git operations
|
|
17
17
|
/**
|
|
18
18
|
* Execute git command safely using spawnSync with array arguments
|
|
@@ -42,9 +42,9 @@ export class PostPRMergeCleanup {
|
|
|
42
42
|
remoteName;
|
|
43
43
|
dryRun;
|
|
44
44
|
constructor(options = {}) {
|
|
45
|
-
this.mainBranch = options.mainBranch
|
|
46
|
-
this.remoteName = options.remoteName
|
|
47
|
-
this.dryRun = options.dryRun
|
|
45
|
+
this.mainBranch = options.mainBranch ?? 'main';
|
|
46
|
+
this.remoteName = options.remoteName ?? 'origin';
|
|
47
|
+
this.dryRun = options.dryRun ?? false;
|
|
48
48
|
}
|
|
49
49
|
/**
|
|
50
50
|
* Run comprehensive post-PR merge cleanup workflow
|
|
@@ -130,38 +130,83 @@ export class PostPRMergeCleanup {
|
|
|
130
130
|
*/
|
|
131
131
|
deleteMergedBranches() {
|
|
132
132
|
try {
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
133
|
+
const branchesToCheck = this.getLocalBranchesToCheck();
|
|
134
|
+
return this.processMergedBranches(branchesToCheck);
|
|
135
|
+
}
|
|
136
|
+
catch {
|
|
137
|
+
// Error deleting merged branches - return empty array
|
|
138
|
+
return [];
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
/**
|
|
142
|
+
* Get list of local branches to check (excluding main branch)
|
|
143
|
+
*/
|
|
144
|
+
getLocalBranchesToCheck() {
|
|
145
|
+
const allBranches = execGitSync(['branch', '--format=%(refname:short)'])
|
|
146
|
+
.trim()
|
|
147
|
+
.split('\n')
|
|
148
|
+
.filter(branch => branch && branch !== this.mainBranch && !branch.startsWith('*'));
|
|
149
|
+
return allBranches;
|
|
150
|
+
}
|
|
151
|
+
/**
|
|
152
|
+
* Process list of branches and delete merged ones
|
|
153
|
+
*/
|
|
154
|
+
processMergedBranches(branches) {
|
|
155
|
+
const deletedBranches = [];
|
|
156
|
+
for (const branch of branches) {
|
|
157
|
+
if (this.isBranchMerged(branch)) {
|
|
158
|
+
const deleted = this.handleBranchDeletion(branch);
|
|
159
|
+
if (deleted) {
|
|
160
|
+
deletedBranches.push(branch);
|
|
159
161
|
}
|
|
160
162
|
}
|
|
161
|
-
return deletedBranches;
|
|
162
163
|
}
|
|
163
|
-
|
|
164
|
-
|
|
164
|
+
return deletedBranches;
|
|
165
|
+
}
|
|
166
|
+
/**
|
|
167
|
+
* Handle deletion of a single branch (dry run or actual deletion)
|
|
168
|
+
*/
|
|
169
|
+
handleBranchDeletion(branch) {
|
|
170
|
+
if (this.dryRun) {
|
|
171
|
+
return true;
|
|
172
|
+
}
|
|
173
|
+
return this.tryDeleteBranch(branch);
|
|
174
|
+
}
|
|
175
|
+
/**
|
|
176
|
+
* Try to delete a branch (with fallback to force delete)
|
|
177
|
+
*/
|
|
178
|
+
tryDeleteBranch(branch) {
|
|
179
|
+
// Try regular delete first
|
|
180
|
+
if (this.attemptRegularDelete(branch)) {
|
|
181
|
+
return true;
|
|
182
|
+
}
|
|
183
|
+
// Fallback to force delete
|
|
184
|
+
return this.attemptForceDelete(branch);
|
|
185
|
+
}
|
|
186
|
+
/**
|
|
187
|
+
* Attempt regular branch deletion (git branch -d)
|
|
188
|
+
*/
|
|
189
|
+
attemptRegularDelete(branch) {
|
|
190
|
+
try {
|
|
191
|
+
execGitSync(['branch', '-d', branch]);
|
|
192
|
+
return true;
|
|
193
|
+
}
|
|
194
|
+
catch {
|
|
195
|
+
// Regular delete failed
|
|
196
|
+
return false;
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
/**
|
|
200
|
+
* Attempt force branch deletion (git branch -D)
|
|
201
|
+
*/
|
|
202
|
+
attemptForceDelete(branch) {
|
|
203
|
+
try {
|
|
204
|
+
execGitSync(['branch', '-D', branch]);
|
|
205
|
+
return true;
|
|
206
|
+
}
|
|
207
|
+
catch {
|
|
208
|
+
// Force delete failed
|
|
209
|
+
return false;
|
|
165
210
|
}
|
|
166
211
|
}
|
|
167
212
|
/**
|
|
@@ -172,8 +217,8 @@ export class PostPRMergeCleanup {
|
|
|
172
217
|
const mergedBranches = execGitSync(['branch', '--merged', this.mainBranch, '--format=%(refname:short)']);
|
|
173
218
|
return mergedBranches.includes(branch);
|
|
174
219
|
}
|
|
175
|
-
catch
|
|
176
|
-
// If we can't determine merge status, don't delete the branch
|
|
220
|
+
catch {
|
|
221
|
+
// If we can't determine merge status, don't delete the branch (safer to keep)
|
|
177
222
|
return false;
|
|
178
223
|
}
|
|
179
224
|
}
|
|
@@ -184,7 +229,7 @@ export class PostPRMergeCleanup {
|
|
|
184
229
|
try {
|
|
185
230
|
execGitSync(['remote', 'prune', this.remoteName]);
|
|
186
231
|
}
|
|
187
|
-
catch
|
|
232
|
+
catch {
|
|
188
233
|
// Non-critical operation - don't fail on error
|
|
189
234
|
}
|
|
190
235
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"post-merge-cleanup.js","sourceRoot":"","sources":["../src/post-merge-cleanup.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAEH,OAAO,EAAE,SAAS,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"post-merge-cleanup.js","sourceRoot":"","sources":["../src/post-merge-cleanup.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAEH,OAAO,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAC;AAE/C,MAAM,OAAO,GAAG,KAAK,CAAC,CAAC,wCAAwC;AAE/D;;;GAGG;AACH,SAAS,WAAW,CAAC,IAAc;IACjC,MAAM,MAAM,GAAG,SAAS,CAAC,KAAK,EAAE,IAAI,EAAE;QACpC,QAAQ,EAAE,MAAM;QAChB,OAAO,EAAE,OAAO;QAChB,KAAK,EAAE,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,CAAC;KAChC,CAAC,CAAC;IAEH,IAAI,MAAM,CAAC,KAAK,EAAE,CAAC;QACjB,MAAM,MAAM,CAAC,KAAK,CAAC;IACrB,CAAC;IAED,IAAI,MAAM,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QACxB,MAAM,IAAI,KAAK,CAAC,OAAO,IAAI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ACH,CAAC;CACF;AAED;;;;;GAKG;AACH,MAAM,CAAC,KAAK,UAAU,qBAAqB,CAAC,UAA0B,EAAE;IACtE,MAAM,OAAO,GAAG,IAAI,kBAAkB,CAAC,OAAO,CAAC,CAAC;IAChD,OAAO,OAAO,CAAC,UAAU,EAAE,CAAC;AAC9B,CAAC"}
|
package/dist/tree-hash.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"tree-hash.d.ts","sourceRoot":"","sources":["../src/tree-hash.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAYH;;;;;;;;;;;;;;;;;;GAkBG;AACH,wBAAsB,cAAc,IAAI,OAAO,CAAC,MAAM,CAAC,
|
|
1
|
+
{"version":3,"file":"tree-hash.d.ts","sourceRoot":"","sources":["../src/tree-hash.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAYH;;;;;;;;;;;;;;;;;;GAkBG;AACH,wBAAsB,cAAc,IAAI,OAAO,CAAC,MAAM,CAAC,CAiFtD;AAED;;;;;;;GAOG;AACH,wBAAsB,eAAe,IAAI,OAAO,CAAC,MAAM,CAAC,CAQvD;AAED;;;;GAIG;AACH,wBAAsB,qBAAqB,IAAI,OAAO,CAAC,OAAO,CAAC,CAS9D"}
|
package/dist/tree-hash.js
CHANGED
|
@@ -10,8 +10,8 @@
|
|
|
10
10
|
* git stash create includes timestamps, making hashes non-deterministic.
|
|
11
11
|
* git write-tree produces content-based hashes only (no timestamps).
|
|
12
12
|
*/
|
|
13
|
-
import { execSync } from 'child_process';
|
|
14
|
-
import { copyFileSync, unlinkSync } from 'fs';
|
|
13
|
+
import { execSync } from 'node:child_process';
|
|
14
|
+
import { copyFileSync, unlinkSync } from 'node:fs';
|
|
15
15
|
const GIT_TIMEOUT = 30000; // 30 seconds timeout for git operations
|
|
16
16
|
const GIT_OPTIONS = {
|
|
17
17
|
encoding: 'utf8',
|
|
@@ -96,7 +96,7 @@ export async function getGitTreeHash() {
|
|
|
96
96
|
// Prevents potential command injection if tempIndexFile contains malicious characters
|
|
97
97
|
unlinkSync(tempIndexFile);
|
|
98
98
|
}
|
|
99
|
-
catch
|
|
99
|
+
catch {
|
|
100
100
|
// Ignore cleanup errors - temp file cleanup is best effort
|
|
101
101
|
// unlinkSync throws if file doesn't exist (same as rm -f behavior)
|
|
102
102
|
}
|
|
@@ -106,9 +106,8 @@ export async function getGitTreeHash() {
|
|
|
106
106
|
// Handle not-in-git-repo case
|
|
107
107
|
const errorMessage = error instanceof Error ? error.message : String(error);
|
|
108
108
|
if (errorMessage.includes('not a git repository')) {
|
|
109
|
-
// Not in git repo -
|
|
110
|
-
|
|
111
|
-
return `nogit-${Date.now()}`;
|
|
109
|
+
// Not in git repo - return "unknown" (caller should skip caching)
|
|
110
|
+
return 'unknown';
|
|
112
111
|
}
|
|
113
112
|
// Other git errors
|
|
114
113
|
throw new Error(`Failed to calculate git tree hash: ${errorMessage}`);
|
|
@@ -143,7 +142,7 @@ export async function hasWorkingTreeChanges() {
|
|
|
143
142
|
const headTreeHash = await getHeadTreeHash();
|
|
144
143
|
return workingTreeHash !== headTreeHash;
|
|
145
144
|
}
|
|
146
|
-
catch
|
|
145
|
+
catch {
|
|
147
146
|
// If we can't determine, assume there are changes (safe default)
|
|
148
147
|
return true;
|
|
149
148
|
}
|
package/dist/tree-hash.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"tree-hash.js","sourceRoot":"","sources":["../src/tree-hash.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAEH,OAAO,EAAE,QAAQ,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"tree-hash.js","sourceRoot":"","sources":["../src/tree-hash.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAEH,OAAO,EAAE,QAAQ,EAAE,MAAM,oBAAoB,CAAC;AAC9C,OAAO,EAAE,YAAY,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AAEnD,MAA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AAC,OAAO,KAAK,EAAE,CAAC;QACf,MAAM,YAAY,GAAG,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;QAC5E,MAAM,IAAI,KAAK,CAAC,iCAAiC,YAAY,EAAE,CAAC,CAAC;IACnE,CAAC;AACH,CAAC;AAED;;;;GAIG;AACH,MAAM,CAAC,KAAK,UAAU,qBAAqB;IACzC,IAAI,CAAC;QACH,MAAM,eAAe,GAAG,MAAM,cAAc,EAAE,CAAC;QAC/C,MAAM,YAAY,GAAG,MAAM,eAAe,EAAE,CAAC;QAC7C,OAAO,eAAe,KAAK,YAAY,CAAC;IAC1C,CAAC;IAAC,MAAM,CAAC;QACP,iEAAiE;QACjE,OAAO,IAAI,CAAC;IACd,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* YAML Output Detection Utilities
|
|
3
|
+
*
|
|
4
|
+
* Efficient detection and extraction of YAML output from command execution.
|
|
5
|
+
*
|
|
6
|
+
* Unlike traditional YAML frontmatter (which has leading and trailing `---`),
|
|
7
|
+
* this is used for commands that output YAML as their entire output:
|
|
8
|
+
*
|
|
9
|
+
* ```
|
|
10
|
+
* > preamble from package manager
|
|
11
|
+
* ---
|
|
12
|
+
* yaml: content
|
|
13
|
+
* goes: here
|
|
14
|
+
* (no trailing ---)
|
|
15
|
+
* ```
|
|
16
|
+
*
|
|
17
|
+
* @package @vibe-validate/git
|
|
18
|
+
*/
|
|
19
|
+
/**
|
|
20
|
+
* Extract YAML output content from command output
|
|
21
|
+
*
|
|
22
|
+
* Uses a single efficient regex pass instead of multiple string scans.
|
|
23
|
+
* Handles both Unix (\n) and Windows (\r\n) line endings.
|
|
24
|
+
*
|
|
25
|
+
* @param output - Raw output that may contain YAML
|
|
26
|
+
* @returns YAML content (including `---` separator) or null if no YAML found
|
|
27
|
+
*
|
|
28
|
+
* @example
|
|
29
|
+
* ```typescript
|
|
30
|
+
* extractYamlContent("---\nkey: value")
|
|
31
|
+
* // Returns: "---\nkey: value"
|
|
32
|
+
*
|
|
33
|
+
* extractYamlContent("preamble\n---\nkey: value")
|
|
34
|
+
* // Returns: "---\nkey: value"
|
|
35
|
+
*
|
|
36
|
+
* extractYamlContent("no yaml here")
|
|
37
|
+
* // Returns: null
|
|
38
|
+
* ```
|
|
39
|
+
*/
|
|
40
|
+
export declare function extractYamlContent(output: string): string | null;
|
|
41
|
+
/**
|
|
42
|
+
* Extract YAML content and preamble from command output
|
|
43
|
+
*
|
|
44
|
+
* Useful when you need to separate package manager noise (preamble) from YAML output.
|
|
45
|
+
*
|
|
46
|
+
* @param output - Raw output that may contain preamble + YAML
|
|
47
|
+
* @returns Object with yaml content and preamble, or null if no YAML found
|
|
48
|
+
*
|
|
49
|
+
* @example
|
|
50
|
+
* ```typescript
|
|
51
|
+
* extractYamlWithPreamble("> pnpm test\n---\nkey: value")
|
|
52
|
+
* // Returns: { yaml: "---\nkey: value", preamble: "> pnpm test" }
|
|
53
|
+
*
|
|
54
|
+
* extractYamlWithPreamble("---\nkey: value")
|
|
55
|
+
* // Returns: { yaml: "---\nkey: value", preamble: "" }
|
|
56
|
+
*
|
|
57
|
+
* extractYamlWithPreamble("no yaml")
|
|
58
|
+
* // Returns: null
|
|
59
|
+
* ```
|
|
60
|
+
*/
|
|
61
|
+
export declare function extractYamlWithPreamble(output: string): {
|
|
62
|
+
yaml: string;
|
|
63
|
+
preamble: string;
|
|
64
|
+
} | null;
|
|
65
|
+
//# sourceMappingURL=yaml-detection.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"yaml-detection.d.ts","sourceRoot":"","sources":["../src/yaml-detection.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;GAiBG;AA+BH;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,wBAAgB,kBAAkB,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CAGhE;AAED;;;;;;;;;;;;;;;;;;;GAmBG;AACH,wBAAgB,uBAAuB,CAAC,MAAM,EAAE,MAAM,GAAG;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,QAAQ,EAAE,MAAM,CAAA;CAAE,GAAG,IAAI,CAWjG"}
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* YAML Output Detection Utilities
|
|
3
|
+
*
|
|
4
|
+
* Efficient detection and extraction of YAML output from command execution.
|
|
5
|
+
*
|
|
6
|
+
* Unlike traditional YAML frontmatter (which has leading and trailing `---`),
|
|
7
|
+
* this is used for commands that output YAML as their entire output:
|
|
8
|
+
*
|
|
9
|
+
* ```
|
|
10
|
+
* > preamble from package manager
|
|
11
|
+
* ---
|
|
12
|
+
* yaml: content
|
|
13
|
+
* goes: here
|
|
14
|
+
* (no trailing ---)
|
|
15
|
+
* ```
|
|
16
|
+
*
|
|
17
|
+
* @package @vibe-validate/git
|
|
18
|
+
*/
|
|
19
|
+
/**
|
|
20
|
+
* YAML output regex pattern
|
|
21
|
+
*
|
|
22
|
+
* Matches YAML output from commands (NOT traditional frontmatter).
|
|
23
|
+
* Traditional frontmatter has both leading and trailing `---`, but command
|
|
24
|
+
* output only has leading `---` followed by YAML to end of output.
|
|
25
|
+
*
|
|
26
|
+
* Matches:
|
|
27
|
+
* - `---` at start of string followed by newline (no preamble)
|
|
28
|
+
* - OR `---` preceded by newline(s) (has preamble)
|
|
29
|
+
*
|
|
30
|
+
* Stops at trailing `---` if present (traditional frontmatter), otherwise matches to end.
|
|
31
|
+
*
|
|
32
|
+
* Pattern breakdown:
|
|
33
|
+
* - `(?:^|\r?\n)`: Non-capturing group - start of string OR newline (optional \r for Windows)
|
|
34
|
+
* - `(---\r?\n`: Capture group starts with `---` + newline
|
|
35
|
+
* - `(?:(?!---(?:\r?\n|$))[\s\S])*`: Match any char UNLESS it starts the pattern `---` + (newline or end)
|
|
36
|
+
* - `)`: End capture group
|
|
37
|
+
*
|
|
38
|
+
* The negative lookahead `(?!---(?:\r?\n|$))` prevents matching into a trailing `---` separator.
|
|
39
|
+
*
|
|
40
|
+
* Examples:
|
|
41
|
+
* - `"---\nkey: value"` → matches, captures `"---\nkey: value"`
|
|
42
|
+
* - `"preamble\n---\nkey: value"` → matches, captures `"---\nkey: value"`
|
|
43
|
+
* - `"---\ntitle: Post\n---\nContent"` → matches, captures `"---\ntitle: Post\n"` (stops at trailing `---`)
|
|
44
|
+
* - `"no yaml"` → no match
|
|
45
|
+
*/
|
|
46
|
+
const YAML_OUTPUT_PATTERN = /(?:^|\r?\n)(---\r?\n(?:(?!---(?:\r?\n|$))[\s\S])*)/;
|
|
47
|
+
/**
|
|
48
|
+
* Extract YAML output content from command output
|
|
49
|
+
*
|
|
50
|
+
* Uses a single efficient regex pass instead of multiple string scans.
|
|
51
|
+
* Handles both Unix (\n) and Windows (\r\n) line endings.
|
|
52
|
+
*
|
|
53
|
+
* @param output - Raw output that may contain YAML
|
|
54
|
+
* @returns YAML content (including `---` separator) or null if no YAML found
|
|
55
|
+
*
|
|
56
|
+
* @example
|
|
57
|
+
* ```typescript
|
|
58
|
+
* extractYamlContent("---\nkey: value")
|
|
59
|
+
* // Returns: "---\nkey: value"
|
|
60
|
+
*
|
|
61
|
+
* extractYamlContent("preamble\n---\nkey: value")
|
|
62
|
+
* // Returns: "---\nkey: value"
|
|
63
|
+
*
|
|
64
|
+
* extractYamlContent("no yaml here")
|
|
65
|
+
* // Returns: null
|
|
66
|
+
* ```
|
|
67
|
+
*/
|
|
68
|
+
export function extractYamlContent(output) {
|
|
69
|
+
const match = YAML_OUTPUT_PATTERN.exec(output);
|
|
70
|
+
return match ? match[1] : null;
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* Extract YAML content and preamble from command output
|
|
74
|
+
*
|
|
75
|
+
* Useful when you need to separate package manager noise (preamble) from YAML output.
|
|
76
|
+
*
|
|
77
|
+
* @param output - Raw output that may contain preamble + YAML
|
|
78
|
+
* @returns Object with yaml content and preamble, or null if no YAML found
|
|
79
|
+
*
|
|
80
|
+
* @example
|
|
81
|
+
* ```typescript
|
|
82
|
+
* extractYamlWithPreamble("> pnpm test\n---\nkey: value")
|
|
83
|
+
* // Returns: { yaml: "---\nkey: value", preamble: "> pnpm test" }
|
|
84
|
+
*
|
|
85
|
+
* extractYamlWithPreamble("---\nkey: value")
|
|
86
|
+
* // Returns: { yaml: "---\nkey: value", preamble: "" }
|
|
87
|
+
*
|
|
88
|
+
* extractYamlWithPreamble("no yaml")
|
|
89
|
+
* // Returns: null
|
|
90
|
+
* ```
|
|
91
|
+
*/
|
|
92
|
+
export function extractYamlWithPreamble(output) {
|
|
93
|
+
const match = YAML_OUTPUT_PATTERN.exec(output);
|
|
94
|
+
if (!match) {
|
|
95
|
+
return null;
|
|
96
|
+
}
|
|
97
|
+
const yamlContent = match[1];
|
|
98
|
+
const yamlStartIndex = match.index + (match[0].length - yamlContent.length);
|
|
99
|
+
const preamble = output.substring(0, yamlStartIndex).trim();
|
|
100
|
+
return { yaml: yamlContent, preamble };
|
|
101
|
+
}
|
|
102
|
+
//# sourceMappingURL=yaml-detection.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"yaml-detection.js","sourceRoot":"","sources":["../src/yaml-detection.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;GAiBG;AAEH;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AACH,MAAM,mBAAmB,GAAG,oDAAoD,CAAC;AAEjF;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,MAAM,UAAU,kBAAkB,CAAC,MAAc;IAC/C,MAAM,KAAK,GAAG,mBAAmB,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;IAC/C,OAAO,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC;AACjC,CAAC;AAED;;;;;;;;;;;;;;;;;;;GAmBG;AACH,MAAM,UAAU,uBAAuB,CAAC,MAAc;IACpD,MAAM,KAAK,GAAG,mBAAmB,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;IAC/C,IAAI,CAAC,KAAK,EAAE,CAAC;QACX,OAAO,IAAI,CAAC;IACd,CAAC;IAED,MAAM,WAAW,GAAG,KAAK,CAAC,CAAC,CAAC,CAAC;IAC7B,MAAM,cAAc,GAAG,KAAK,CAAC,KAAK,GAAG,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,MAAM,GAAG,WAAW,CAAC,MAAM,CAAC,CAAC;IAC5E,MAAM,QAAQ,GAAG,MAAM,CAAC,SAAS,CAAC,CAAC,EAAE,cAAc,CAAC,CAAC,IAAI,EAAE,CAAC;IAE5D,OAAO,EAAE,IAAI,EAAE,WAAW,EAAE,QAAQ,EAAE,CAAC;AACzC,CAAC"}
|
package/package.json
CHANGED