pi-var 1.0.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/.github/FUNDING.yml +4 -0
- package/.prettierrc +7 -0
- package/README.md +240 -0
- package/commitlint.config.cjs +3 -0
- package/extensions/pi-var/__tests__/integration/smoke.test.ts +308 -0
- package/extensions/pi-var/__tests__/unit/command.test.ts +322 -0
- package/extensions/pi-var/__tests__/unit/cow-detection.test.ts +340 -0
- package/extensions/pi-var/__tests__/unit/cow-git-merge.test.ts +404 -0
- package/extensions/pi-var/__tests__/unit/edr.test.ts +119 -0
- package/extensions/pi-var/__tests__/unit/environment.test.ts +369 -0
- package/extensions/pi-var/__tests__/unit/file-redirect.test.ts +295 -0
- package/extensions/pi-var/__tests__/unit/store.test.ts +489 -0
- package/extensions/pi-var/__tests__/unit/tools.test.ts +133 -0
- package/extensions/pi-var/__tests__/unit/variations.test.ts +352 -0
- package/extensions/pi-var/index.ts +111 -0
- package/extensions/pi-var/src/config.ts +30 -0
- package/extensions/pi-var/src/cow/clone.ts +46 -0
- package/extensions/pi-var/src/cow/detection.ts +215 -0
- package/extensions/pi-var/src/cow/index.ts +6 -0
- package/extensions/pi-var/src/edr/constants.ts +199 -0
- package/extensions/pi-var/src/edr/crowdstrike.ts +62 -0
- package/extensions/pi-var/src/edr/detection.ts +97 -0
- package/extensions/pi-var/src/edr/index.ts +6 -0
- package/extensions/pi-var/src/environment/copy-env.ts +79 -0
- package/extensions/pi-var/src/environment/detect.ts +91 -0
- package/extensions/pi-var/src/environment/index.ts +54 -0
- package/extensions/pi-var/src/environment/marker.ts +42 -0
- package/extensions/pi-var/src/environment/symlink.ts +82 -0
- package/extensions/pi-var/src/gitignore/manager.ts +77 -0
- package/extensions/pi-var/src/state/index.ts +7 -0
- package/extensions/pi-var/src/state/keys.ts +14 -0
- package/extensions/pi-var/src/state/store.ts +110 -0
- package/extensions/pi-var/src/state/types.ts +70 -0
- package/extensions/pi-var/src/tools/command/clean.ts +87 -0
- package/extensions/pi-var/src/tools/command/index.ts +95 -0
- package/extensions/pi-var/src/tools/command/status.ts +58 -0
- package/extensions/pi-var/src/tools/command/stop.ts +37 -0
- package/extensions/pi-var/src/tools/file-redirect.ts +126 -0
- package/extensions/pi-var/src/tools/redirect/bash.ts +75 -0
- package/extensions/pi-var/src/tools/redirect/edit.ts +60 -0
- package/extensions/pi-var/src/tools/redirect/index.ts +64 -0
- package/extensions/pi-var/src/tools/redirect/read.ts +61 -0
- package/extensions/pi-var/src/tools/redirect/write.ts +60 -0
- package/extensions/pi-var/src/tools/variation/create.ts +108 -0
- package/extensions/pi-var/src/tools/variation/merge.ts +80 -0
- package/extensions/pi-var/src/types/index.ts +139 -0
- package/extensions/pi-var/src/utils/names.ts +120 -0
- package/extensions/pi-var/src/variation/create-copy.ts +35 -0
- package/extensions/pi-var/src/variation/create-cow.ts +81 -0
- package/extensions/pi-var/src/variation/create-worktree.ts +31 -0
- package/extensions/pi-var/src/variation/create.ts +127 -0
- package/extensions/pi-var/src/variation/index.ts +9 -0
- package/extensions/pi-var/src/variation/merge/copy.ts +151 -0
- package/extensions/pi-var/src/variation/merge/git.ts +176 -0
- package/extensions/pi-var/src/variation/merge/index.ts +36 -0
- package/extensions/pi-var/src/variation/merge/rsync.ts +74 -0
- package/extensions/pi-var/src/variation/merge/strategy.ts +62 -0
- package/extensions/pi-var/src/variation/paths.ts +26 -0
- package/extensions/pi-var/src/variation/remove.ts +79 -0
- package/npm-shrinkwrap.json +6908 -0
- package/package.json +63 -0
- package/skills/variations/SKILL.md +182 -0
- package/tsconfig.json +25 -0
- package/vitest.config.ts +19 -0
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Variation removal and cleanup
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
import { exec } from 'child_process';
|
|
6
|
+
import { promisify } from 'util';
|
|
7
|
+
import { promises as fs } from 'fs';
|
|
8
|
+
import * as path from 'path';
|
|
9
|
+
import type { Variation } from '../types/index';
|
|
10
|
+
|
|
11
|
+
const execAsync = promisify(exec);
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* Remove a variation
|
|
15
|
+
*/
|
|
16
|
+
export async function removeVariation(variation: Variation): Promise<void> {
|
|
17
|
+
// Clean up based on variation type
|
|
18
|
+
switch (variation.type) {
|
|
19
|
+
case 'worktree':
|
|
20
|
+
// Remove git worktree
|
|
21
|
+
try {
|
|
22
|
+
await execAsync(
|
|
23
|
+
`git -C "${variation.sourcePath}" worktree remove "${variation.path}" --force`
|
|
24
|
+
);
|
|
25
|
+
} catch {
|
|
26
|
+
// If worktree remove fails, try manual cleanup
|
|
27
|
+
await fs.rm(variation.path, { recursive: true, force: true });
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
// Remove branch if we created it
|
|
31
|
+
if (variation.branchName?.startsWith('var/')) {
|
|
32
|
+
try {
|
|
33
|
+
await execAsync(`git -C "${variation.sourcePath}" branch -D "${variation.branchName}"`);
|
|
34
|
+
} catch {
|
|
35
|
+
// Ignore branch deletion errors
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
break;
|
|
39
|
+
|
|
40
|
+
case 'cow':
|
|
41
|
+
// For git-backed CoW variations, clean up any leftover temporary remote in the source
|
|
42
|
+
if (variation.branchName) {
|
|
43
|
+
const safe = variation.name.replace(/[^a-zA-Z0-9-_]/g, '-');
|
|
44
|
+
const remoteName = `pi-var-${safe}`;
|
|
45
|
+
try {
|
|
46
|
+
await execAsync(`git -C "${variation.sourcePath}" remote remove "${remoteName}"`);
|
|
47
|
+
} catch {
|
|
48
|
+
// Remote doesn't exist — that's fine
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
// Simple directory removal
|
|
53
|
+
await fs.rm(variation.path, { recursive: true, force: true });
|
|
54
|
+
break;
|
|
55
|
+
|
|
56
|
+
case 'copy':
|
|
57
|
+
// Simple directory removal
|
|
58
|
+
await fs.rm(variation.path, { recursive: true, force: true });
|
|
59
|
+
break;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
// Clean up empty parent directories
|
|
63
|
+
try {
|
|
64
|
+
const baseDir = path.dirname(variation.path);
|
|
65
|
+
const entries = await fs.readdir(baseDir);
|
|
66
|
+
if (entries.length === 0) {
|
|
67
|
+
await fs.rmdir(baseDir);
|
|
68
|
+
|
|
69
|
+
// Try to clean up .pi/variations if empty
|
|
70
|
+
const variationsDir = path.dirname(baseDir);
|
|
71
|
+
const varEntries = await fs.readdir(variationsDir);
|
|
72
|
+
if (varEntries.length === 0) {
|
|
73
|
+
await fs.rmdir(variationsDir);
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
} catch {
|
|
77
|
+
// Ignore cleanup errors
|
|
78
|
+
}
|
|
79
|
+
}
|