reslop 0.1.9 → 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/CHANGELOG.md +12 -1
- package/README.md +2 -1
- package/bin/reslop.js +2 -2
- package/lib/ansi.js +4 -2
- package/lib/api.js +2 -2
- package/lib/capabilities.js +7 -14
- package/lib/cli.js +28 -47
- package/lib/clipboard.js +1 -1
- package/lib/{deps/changes.js → deps-diff.js} +309 -19
- package/lib/deps.js +498 -29
- package/lib/detect.js +1 -7
- package/lib/diff/align.js +7 -10
- package/lib/diff/diff.js +53 -0
- package/lib/diff/display.js +5 -4
- package/lib/diff/inline.js +26 -21
- package/lib/diff/items.js +6 -4
- package/lib/diff/patch.js +1 -3
- package/lib/diff/unit.js +392 -0
- package/lib/files.js +5 -8
- package/lib/{git/branches.js → git-branches.js} +6 -5
- package/lib/{git/dependencies.js → git-deps.js} +111 -38
- package/lib/git.js +589 -68
- package/lib/github.js +28 -197
- package/lib/gitlab.js +24 -195
- package/lib/highlight/bash.js +1 -3
- package/lib/highlight/css.js +1 -3
- package/lib/highlight/js.js +11 -14
- package/lib/highlight.js +6 -9
- package/lib/keys.js +14 -8
- package/lib/manifest.js +330 -0
- package/lib/remote.js +374 -0
- package/lib/render/branches.js +14 -68
- package/lib/render/chrome.js +24 -9
- package/lib/render/commits.js +6 -59
- package/lib/render/diff.js +16 -16
- package/lib/render/files.js +6 -34
- package/lib/render/frame.js +23 -12
- package/lib/render/notes.js +4 -3
- package/lib/render/primitives.js +45 -0
- package/lib/{render.js → render/render.js} +5 -5
- package/lib/render/unit.js +41 -0
- package/lib/review.js +750 -14
- package/lib/select.js +5 -10
- package/lib/session/accessors.js +9 -1
- package/lib/session/actions.js +32 -16
- package/lib/session/branches.js +116 -128
- package/lib/session/change-actions.js +202 -123
- package/lib/session/commit.js +105 -112
- package/lib/session/compose.js +158 -13
- package/lib/session/dispatch.js +104 -60
- package/lib/session/files-pane.js +142 -148
- package/lib/session/items.js +22 -30
- package/lib/session/lifecycle.js +44 -44
- package/lib/session/load.js +19 -33
- package/lib/session/navigation.js +12 -1
- package/lib/session/ops.js +28 -41
- package/lib/session/pointer.js +54 -57
- package/lib/session/review.js +23 -37
- package/lib/session/terminal.js +6 -12
- package/lib/session/todos.js +8 -12
- package/lib/session/unit.js +208 -0
- package/lib/session/update.js +33 -46
- package/lib/session/view.js +78 -9
- package/lib/session/watch.js +11 -19
- package/lib/session.js +21 -246
- package/lib/source.js +3 -3
- package/lib/update.js +40 -75
- package/lib/{git/proc.js → utilities.js} +75 -11
- package/lib/wrap.js +1 -3
- package/package.json +1 -1
- package/lib/deps/items.js +0 -134
- package/lib/deps/manifest.js +0 -152
- package/lib/deps/merge.js +0 -120
- package/lib/deps/proposals.js +0 -164
- package/lib/deps/reports.js +0 -180
- package/lib/deps/rows.js +0 -176
- package/lib/deps/scan.js +0 -138
- package/lib/deps/usage.js +0 -68
- package/lib/deps/versions.js +0 -119
- package/lib/diff.js +0 -33
- package/lib/git/changes.js +0 -164
- package/lib/git/read.js +0 -253
- package/lib/git/run.js +0 -100
- package/lib/npm/commands.js +0 -100
- package/lib/remote/changes.js +0 -37
- package/lib/remote/headers.js +0 -36
- package/lib/remote/http.js +0 -122
- package/lib/remote/notes.js +0 -94
- package/lib/review/format.js +0 -434
- package/lib/review/storage.js +0 -150
- package/lib/review/store.js +0 -178
- package/lib/review/templates.js +0 -49
- package/lib/session/origins.js +0 -7
- package/lib/sys.js +0 -84
package/lib/diff.js
DELETED
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
const { diffChars } = require('./diff/inline.js');
|
|
4
|
-
const { isCtxType, pairIndices, attachInline } = require('./diff/align.js');
|
|
5
|
-
const { parseDiff } = require('./diff/parse.js');
|
|
6
|
-
const patch = require('./diff/patch.js');
|
|
7
|
-
const { splitHunk, flattenBlock, countSides, formatPatch } = patch;
|
|
8
|
-
const display = require('./diff/display.js');
|
|
9
|
-
const { DISPLAY_CONTEXT, displayLines, blockAddText } = display;
|
|
10
|
-
const edit = require('./diff/edit.js');
|
|
11
|
-
const { addBlockRange, replaceBlockAdds } = edit;
|
|
12
|
-
const items = require('./diff/items.js');
|
|
13
|
-
const { synthesizeNewFile, itemsFromFiles, refreshIndexPatches } = items;
|
|
14
|
-
|
|
15
|
-
module.exports = {
|
|
16
|
-
DISPLAY_CONTEXT,
|
|
17
|
-
isCtxType,
|
|
18
|
-
diffChars,
|
|
19
|
-
pairIndices,
|
|
20
|
-
attachInline,
|
|
21
|
-
parseDiff,
|
|
22
|
-
splitHunk,
|
|
23
|
-
flattenBlock,
|
|
24
|
-
countSides,
|
|
25
|
-
formatPatch,
|
|
26
|
-
displayLines,
|
|
27
|
-
blockAddText,
|
|
28
|
-
addBlockRange,
|
|
29
|
-
replaceBlockAdds,
|
|
30
|
-
synthesizeNewFile,
|
|
31
|
-
itemsFromFiles,
|
|
32
|
-
refreshIndexPatches,
|
|
33
|
-
};
|
package/lib/git/changes.js
DELETED
|
@@ -1,164 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
const fs = require('node:fs');
|
|
4
|
-
const path = require('node:path');
|
|
5
|
-
|
|
6
|
-
const { itemPath } = require('../files.js');
|
|
7
|
-
const { replaceBlockAdds } = require('../diff/edit.js');
|
|
8
|
-
const { requireOk, runGit } = require('./run.js');
|
|
9
|
-
|
|
10
|
-
const applyPatch = (cwd, patch, flags) => {
|
|
11
|
-
const args = ['apply', ...flags, '--whitespace=nowarn', '-'];
|
|
12
|
-
const result = runGit(args, cwd, patch);
|
|
13
|
-
requireOk(result, 'apply failed');
|
|
14
|
-
};
|
|
15
|
-
|
|
16
|
-
const addItem = (top, item) => {
|
|
17
|
-
if (item.origin === 'staged' || item.origin === 'commit') return;
|
|
18
|
-
if (item.origin === 'untracked' || item.file.isBinary) {
|
|
19
|
-
requireOk(runGit(['add', '--', item.file.newPath], top));
|
|
20
|
-
return;
|
|
21
|
-
}
|
|
22
|
-
applyPatch(top, item.patchAdd, ['--cached']);
|
|
23
|
-
};
|
|
24
|
-
|
|
25
|
-
const unstageItem = (top, item) => {
|
|
26
|
-
if (item.origin !== 'staged') return;
|
|
27
|
-
const rel = itemPath(item);
|
|
28
|
-
if (item.file.isBinary) {
|
|
29
|
-
requireOk(runGit(['restore', '--staged', '--', rel], top));
|
|
30
|
-
return;
|
|
31
|
-
}
|
|
32
|
-
applyPatch(top, item.patchAdd, ['--reverse', '--cached']);
|
|
33
|
-
};
|
|
34
|
-
|
|
35
|
-
const revertOnePath = (top, rel, items) => {
|
|
36
|
-
const origins = new Set();
|
|
37
|
-
let isNew = false;
|
|
38
|
-
for (const item of items) {
|
|
39
|
-
origins.add(item.origin);
|
|
40
|
-
if (item.file && item.file.isNew) isNew = true;
|
|
41
|
-
}
|
|
42
|
-
if (isNew) {
|
|
43
|
-
if (origins.has('staged')) {
|
|
44
|
-
requireOk(runGit(['rm', '-f', '--', rel], top));
|
|
45
|
-
return;
|
|
46
|
-
}
|
|
47
|
-
fs.unlinkSync(path.join(top, rel));
|
|
48
|
-
return;
|
|
49
|
-
}
|
|
50
|
-
if (origins.has('untracked') && origins.size === 1) {
|
|
51
|
-
fs.unlinkSync(path.join(top, rel));
|
|
52
|
-
return;
|
|
53
|
-
}
|
|
54
|
-
const args = ['restore', '-s', 'HEAD', '--worktree', '--staged', '--', rel];
|
|
55
|
-
requireOk(runGit(args, top));
|
|
56
|
-
};
|
|
57
|
-
|
|
58
|
-
const revertItem = (top, item) => {
|
|
59
|
-
if (item.origin === 'commit') return;
|
|
60
|
-
const rel = itemPath(item);
|
|
61
|
-
if (item.origin === 'untracked') {
|
|
62
|
-
fs.unlinkSync(path.join(top, rel));
|
|
63
|
-
return;
|
|
64
|
-
}
|
|
65
|
-
if (item.file.isBinary) {
|
|
66
|
-
const args = ['restore', '-s', 'HEAD', '--worktree'];
|
|
67
|
-
if (item.origin === 'staged') args.push('--staged');
|
|
68
|
-
args.push('--', rel);
|
|
69
|
-
requireOk(runGit(args, top));
|
|
70
|
-
return;
|
|
71
|
-
}
|
|
72
|
-
if (item.origin === 'unstaged') {
|
|
73
|
-
applyPatch(top, item.patchRevert, ['--reverse']);
|
|
74
|
-
return;
|
|
75
|
-
}
|
|
76
|
-
applyPatch(top, item.patchRevert, ['--reverse', '--cached']);
|
|
77
|
-
try {
|
|
78
|
-
applyPatch(top, item.patchRevert, ['--reverse']);
|
|
79
|
-
} catch (error) {
|
|
80
|
-
if (!error.message.includes('does not apply')) throw error;
|
|
81
|
-
}
|
|
82
|
-
};
|
|
83
|
-
|
|
84
|
-
const revertFile = (top, rel, items) => {
|
|
85
|
-
const group = [];
|
|
86
|
-
for (const item of items) {
|
|
87
|
-
if (itemPath(item) === rel) group.push(item);
|
|
88
|
-
}
|
|
89
|
-
const targets = group.length ? group : items;
|
|
90
|
-
revertOnePath(top, rel, targets);
|
|
91
|
-
};
|
|
92
|
-
|
|
93
|
-
const indexText = (top, rel) => {
|
|
94
|
-
const result = runGit(['show', `:${rel}`], top);
|
|
95
|
-
requireOk(result, 'show failed');
|
|
96
|
-
return result.stdout ?? '';
|
|
97
|
-
};
|
|
98
|
-
|
|
99
|
-
const indexMode = (top, rel) => {
|
|
100
|
-
const result = runGit(['ls-files', '--stage', '--', rel], top);
|
|
101
|
-
if (result.status !== 0) return '100644';
|
|
102
|
-
const line = (result.stdout ?? '').trim();
|
|
103
|
-
if (!line) return '100644';
|
|
104
|
-
const mode = line.split(' ')[0];
|
|
105
|
-
return mode || '100644';
|
|
106
|
-
};
|
|
107
|
-
|
|
108
|
-
const writeIndex = (top, rel, text) => {
|
|
109
|
-
const hashed = runGit(['hash-object', '-w', '--stdin'], top, text);
|
|
110
|
-
requireOk(hashed, 'hash-object failed');
|
|
111
|
-
const sha = (hashed.stdout ?? '').trim();
|
|
112
|
-
const mode = indexMode(top, rel);
|
|
113
|
-
const args = ['update-index', '--cacheinfo', mode, sha, rel];
|
|
114
|
-
requireOk(runGit(args, top), 'update-index failed');
|
|
115
|
-
};
|
|
116
|
-
|
|
117
|
-
const writeWorktree = (abs, text) => {
|
|
118
|
-
fs.writeFileSync(abs, text);
|
|
119
|
-
};
|
|
120
|
-
|
|
121
|
-
const editStaged = (top, rel, abs, hunk, blockId, text) => {
|
|
122
|
-
const source = indexText(top, rel);
|
|
123
|
-
const next = replaceBlockAdds(source, hunk, blockId, text);
|
|
124
|
-
writeIndex(top, rel, next);
|
|
125
|
-
let work = null;
|
|
126
|
-
try {
|
|
127
|
-
work = fs.readFileSync(abs, 'utf8');
|
|
128
|
-
} catch (error) {
|
|
129
|
-
if (error.code !== 'ENOENT') throw error;
|
|
130
|
-
}
|
|
131
|
-
if (work === null) {
|
|
132
|
-
writeWorktree(abs, next);
|
|
133
|
-
return;
|
|
134
|
-
}
|
|
135
|
-
if (work === source) writeWorktree(abs, next);
|
|
136
|
-
};
|
|
137
|
-
|
|
138
|
-
const editWorktree = (abs, hunk, blockId, text) => {
|
|
139
|
-
const source = fs.readFileSync(abs, 'utf8');
|
|
140
|
-
const next = replaceBlockAdds(source, hunk, blockId, text);
|
|
141
|
-
if (next === source) return;
|
|
142
|
-
writeWorktree(abs, next);
|
|
143
|
-
};
|
|
144
|
-
|
|
145
|
-
const editItem = (top, item, text) => {
|
|
146
|
-
if (item.origin === 'commit' || item.origin === 'pr') return;
|
|
147
|
-
const rel = itemPath(item);
|
|
148
|
-
if (!rel || !item.hunk) return;
|
|
149
|
-
const abs = path.join(top, rel);
|
|
150
|
-
if (item.origin === 'staged') {
|
|
151
|
-
editStaged(top, rel, abs, item.hunk, item.blockId, text);
|
|
152
|
-
return;
|
|
153
|
-
}
|
|
154
|
-
editWorktree(abs, item.hunk, item.blockId, text);
|
|
155
|
-
};
|
|
156
|
-
|
|
157
|
-
module.exports = {
|
|
158
|
-
addItem,
|
|
159
|
-
unstageItem,
|
|
160
|
-
revertOnePath,
|
|
161
|
-
revertItem,
|
|
162
|
-
revertFile,
|
|
163
|
-
editItem,
|
|
164
|
-
};
|
package/lib/git/read.js
DELETED
|
@@ -1,253 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
const fs = require('node:fs');
|
|
4
|
-
const path = require('node:path');
|
|
5
|
-
|
|
6
|
-
const diff = require('../diff.js');
|
|
7
|
-
const { parseDiff, synthesizeNewFile, itemsFromFiles } = diff;
|
|
8
|
-
const { itemPath, REVIEW_DIR } = require('../files.js');
|
|
9
|
-
const git = require('./run.js');
|
|
10
|
-
const { requireOk, runGit, runGitAsync } = git;
|
|
11
|
-
const { pathArgsOf, cachedDiffArgs, worktreeDiffArgs, commitDiffArgs } = git;
|
|
12
|
-
|
|
13
|
-
const BINARY_SIZE = 1000000;
|
|
14
|
-
|
|
15
|
-
const isReviewFile = (rel) => {
|
|
16
|
-
if (!rel) return false;
|
|
17
|
-
const first = rel.split(/[/\\]/)[0];
|
|
18
|
-
return first === REVIEW_DIR;
|
|
19
|
-
};
|
|
20
|
-
|
|
21
|
-
const dropReviewItems = (items) => {
|
|
22
|
-
const kept = [];
|
|
23
|
-
for (const item of items) {
|
|
24
|
-
if (isReviewFile(itemPath(item))) continue;
|
|
25
|
-
kept.push(item);
|
|
26
|
-
}
|
|
27
|
-
return kept;
|
|
28
|
-
};
|
|
29
|
-
|
|
30
|
-
const isBinaryBuffer = (buf) => {
|
|
31
|
-
if (buf.length > BINARY_SIZE) return true;
|
|
32
|
-
return buf.includes(0);
|
|
33
|
-
};
|
|
34
|
-
|
|
35
|
-
const namesFromLs = (stdout) => {
|
|
36
|
-
if (!stdout) return [];
|
|
37
|
-
return stdout.split('\0').filter(Boolean);
|
|
38
|
-
};
|
|
39
|
-
|
|
40
|
-
const untrackedLsArgs = (paths) => {
|
|
41
|
-
const args = ['ls-files', '-o', '--exclude-standard', '-z'];
|
|
42
|
-
if (paths.length) args.push('--', ...paths);
|
|
43
|
-
return args;
|
|
44
|
-
};
|
|
45
|
-
|
|
46
|
-
const listUntracked = (top, paths) => {
|
|
47
|
-
const result = requireOk(runGit(untrackedLsArgs(paths), top));
|
|
48
|
-
return namesFromLs(result.stdout);
|
|
49
|
-
};
|
|
50
|
-
|
|
51
|
-
const binaryNewFile = (rel) => ({
|
|
52
|
-
oldPath: rel,
|
|
53
|
-
newPath: rel,
|
|
54
|
-
isNew: true,
|
|
55
|
-
isDeleted: false,
|
|
56
|
-
isBinary: true,
|
|
57
|
-
preamble: [`diff --git a/${rel} b/${rel}`, 'new file mode 100644'],
|
|
58
|
-
hunks: [],
|
|
59
|
-
});
|
|
60
|
-
|
|
61
|
-
const untrackedItemsFrom = (top, names) => {
|
|
62
|
-
const files = [];
|
|
63
|
-
for (const rel of names) {
|
|
64
|
-
if (isReviewFile(rel)) continue;
|
|
65
|
-
const full = path.join(top, rel);
|
|
66
|
-
let buf;
|
|
67
|
-
try {
|
|
68
|
-
buf = fs.readFileSync(full);
|
|
69
|
-
} catch (error) {
|
|
70
|
-
if (error.code === 'ENOENT') continue;
|
|
71
|
-
throw error;
|
|
72
|
-
}
|
|
73
|
-
if (isBinaryBuffer(buf)) {
|
|
74
|
-
files.push(binaryNewFile(rel));
|
|
75
|
-
continue;
|
|
76
|
-
}
|
|
77
|
-
files.push(synthesizeNewFile(rel, buf.toString('utf8')));
|
|
78
|
-
}
|
|
79
|
-
return itemsFromFiles(files, 'untracked');
|
|
80
|
-
};
|
|
81
|
-
|
|
82
|
-
const mergeItems = (groups) => {
|
|
83
|
-
const byPath = new Map();
|
|
84
|
-
for (const group of groups) {
|
|
85
|
-
for (const item of group) {
|
|
86
|
-
const rel = itemPath(item);
|
|
87
|
-
const list = byPath.get(rel);
|
|
88
|
-
if (list) {
|
|
89
|
-
list.push(item);
|
|
90
|
-
continue;
|
|
91
|
-
}
|
|
92
|
-
byPath.set(rel, [item]);
|
|
93
|
-
}
|
|
94
|
-
}
|
|
95
|
-
const items = [];
|
|
96
|
-
for (const list of byPath.values()) {
|
|
97
|
-
for (const item of list) items.push(item);
|
|
98
|
-
}
|
|
99
|
-
return items;
|
|
100
|
-
};
|
|
101
|
-
|
|
102
|
-
const gitText = (top, spec) => {
|
|
103
|
-
const result = runGit(['show', spec], top);
|
|
104
|
-
if (result.status !== 0) return '';
|
|
105
|
-
return result.stdout ?? '';
|
|
106
|
-
};
|
|
107
|
-
|
|
108
|
-
const worktreeText = (top, rel) => {
|
|
109
|
-
try {
|
|
110
|
-
return fs.readFileSync(path.join(top, rel), 'utf8');
|
|
111
|
-
} catch {
|
|
112
|
-
return '';
|
|
113
|
-
}
|
|
114
|
-
};
|
|
115
|
-
|
|
116
|
-
const readDepSides = (top, rev, origin, rel) => {
|
|
117
|
-
if (origin === 'untracked') {
|
|
118
|
-
const newText = worktreeText(top, rel);
|
|
119
|
-
return { oldText: '', newText };
|
|
120
|
-
}
|
|
121
|
-
if (origin === 'staged') {
|
|
122
|
-
const oldText = gitText(top, `HEAD:${rel}`);
|
|
123
|
-
const newText = gitText(top, `:${rel}`);
|
|
124
|
-
return { oldText, newText };
|
|
125
|
-
}
|
|
126
|
-
if (origin === 'unstaged') {
|
|
127
|
-
const indexed = gitText(top, `:${rel}`);
|
|
128
|
-
const oldText = indexed || gitText(top, `HEAD:${rel}`);
|
|
129
|
-
const newText = worktreeText(top, rel);
|
|
130
|
-
return { oldText, newText };
|
|
131
|
-
}
|
|
132
|
-
if (origin === 'commit' && rev) {
|
|
133
|
-
const oldText = gitText(top, `${rev}^:${rel}`);
|
|
134
|
-
const newText = gitText(top, `${rev}:${rel}`);
|
|
135
|
-
return { oldText, newText };
|
|
136
|
-
}
|
|
137
|
-
return { oldText: '', newText: '' };
|
|
138
|
-
};
|
|
139
|
-
|
|
140
|
-
const toplevel = (cwd) => {
|
|
141
|
-
const result = runGit(['rev-parse', '--show-toplevel'], cwd);
|
|
142
|
-
if (result.status !== 0) throw new Error('not a git repository');
|
|
143
|
-
return result.stdout.trim();
|
|
144
|
-
};
|
|
145
|
-
|
|
146
|
-
const resolveRev = (cwd, spec) => {
|
|
147
|
-
if (!spec) return null;
|
|
148
|
-
const top = toplevel(cwd);
|
|
149
|
-
const args = ['rev-parse', '--verify', `${spec}^{commit}`];
|
|
150
|
-
const result = runGit(args, top);
|
|
151
|
-
if (result.status !== 0) return null;
|
|
152
|
-
return result.stdout.trim();
|
|
153
|
-
};
|
|
154
|
-
|
|
155
|
-
const shortRev = (top, commit) => {
|
|
156
|
-
const result = runGit(['rev-parse', '--short', commit], top);
|
|
157
|
-
if (result.status !== 0) return commit.slice(0, 7);
|
|
158
|
-
return result.stdout.trim();
|
|
159
|
-
};
|
|
160
|
-
|
|
161
|
-
const currentBranch = (top) => {
|
|
162
|
-
const args = ['rev-parse', '--abbrev-ref', 'HEAD'];
|
|
163
|
-
const result = runGit(args, top);
|
|
164
|
-
if (result.status !== 0) return '';
|
|
165
|
-
const name = result.stdout.trim();
|
|
166
|
-
if (!name || name === 'HEAD') return '';
|
|
167
|
-
return name;
|
|
168
|
-
};
|
|
169
|
-
|
|
170
|
-
const snapshotWorktree = (top, stagedOut, unstagedOut, names) => {
|
|
171
|
-
const stagedDiff = parseDiff(stagedOut);
|
|
172
|
-
const unstagedDiff = parseDiff(unstagedOut);
|
|
173
|
-
const staged = itemsFromFiles(stagedDiff, 'staged');
|
|
174
|
-
const unstaged = itemsFromFiles(unstagedDiff, 'unstaged');
|
|
175
|
-
const untracked = untrackedItemsFrom(top, names);
|
|
176
|
-
const combined = mergeItems([staged, unstaged, untracked]);
|
|
177
|
-
const parsed = dropReviewItems(combined);
|
|
178
|
-
const branch = currentBranch(top);
|
|
179
|
-
return { top, parsed, branch };
|
|
180
|
-
};
|
|
181
|
-
|
|
182
|
-
const snapshotCommit = (top, commit, files) => {
|
|
183
|
-
const commitItems = itemsFromFiles(files, 'commit');
|
|
184
|
-
const parsed = dropReviewItems(commitItems);
|
|
185
|
-
const revShort = shortRev(top, commit);
|
|
186
|
-
const branch = currentBranch(top);
|
|
187
|
-
return { top, parsed, rev: commit, revShort, branch };
|
|
188
|
-
};
|
|
189
|
-
|
|
190
|
-
const loadCommit = (top, commit, extra) => {
|
|
191
|
-
const parent = runGit(['rev-parse', '--verify', `${commit}^`], top);
|
|
192
|
-
const args = commitDiffArgs(commit, parent, extra);
|
|
193
|
-
const result = requireOk(runGit(args, top));
|
|
194
|
-
return parseDiff(result.stdout);
|
|
195
|
-
};
|
|
196
|
-
|
|
197
|
-
const loadCommitAsync = async (top, commit, extra, signal) => {
|
|
198
|
-
const parent = await runGitAsync(
|
|
199
|
-
['rev-parse', '--verify', `${commit}^`],
|
|
200
|
-
top,
|
|
201
|
-
{ signal },
|
|
202
|
-
);
|
|
203
|
-
const args = commitDiffArgs(commit, parent, extra);
|
|
204
|
-
const result = requireOk(await runGitAsync(args, top, { signal }));
|
|
205
|
-
return parseDiff(result.stdout);
|
|
206
|
-
};
|
|
207
|
-
|
|
208
|
-
const readSnapshot = (cwd, paths, options) => {
|
|
209
|
-
const top = toplevel(cwd);
|
|
210
|
-
const extra = pathArgsOf(paths);
|
|
211
|
-
const rev = options.commit;
|
|
212
|
-
if (rev) return snapshotCommit(top, rev, loadCommit(top, rev, extra));
|
|
213
|
-
const stagedRes = requireOk(runGit(cachedDiffArgs(extra), top));
|
|
214
|
-
const unstagedRes = requireOk(runGit(worktreeDiffArgs(extra), top));
|
|
215
|
-
const names = listUntracked(top, paths);
|
|
216
|
-
return snapshotWorktree(top, stagedRes.stdout, unstagedRes.stdout, names);
|
|
217
|
-
};
|
|
218
|
-
|
|
219
|
-
const readSnapshotAsync = async (cwd, paths, options) => {
|
|
220
|
-
const top = toplevel(cwd);
|
|
221
|
-
const extra = pathArgsOf(paths);
|
|
222
|
-
const rev = options.commit;
|
|
223
|
-
const signal = options.signal;
|
|
224
|
-
if (rev) {
|
|
225
|
-
const files = await loadCommitAsync(top, rev, extra, signal);
|
|
226
|
-
return snapshotCommit(top, rev, files);
|
|
227
|
-
}
|
|
228
|
-
const stagedArgs = cachedDiffArgs(extra);
|
|
229
|
-
const unstagedArgs = worktreeDiffArgs(extra);
|
|
230
|
-
const lsArgs = untrackedLsArgs(paths);
|
|
231
|
-
const stagedP = runGitAsync(stagedArgs, top, { signal });
|
|
232
|
-
const unstagedP = runGitAsync(unstagedArgs, top, { signal });
|
|
233
|
-
const lsP = runGitAsync(lsArgs, top, { signal });
|
|
234
|
-
const extras = await Promise.all([stagedP, unstagedP, lsP]);
|
|
235
|
-
const stagedRes = extras[0];
|
|
236
|
-
const unstagedRes = extras[1];
|
|
237
|
-
const lsRes = extras[2];
|
|
238
|
-
requireOk(stagedRes);
|
|
239
|
-
requireOk(unstagedRes);
|
|
240
|
-
const names = namesFromLs(requireOk(lsRes).stdout);
|
|
241
|
-
return snapshotWorktree(top, stagedRes.stdout, unstagedRes.stdout, names);
|
|
242
|
-
};
|
|
243
|
-
|
|
244
|
-
module.exports = {
|
|
245
|
-
toplevel,
|
|
246
|
-
resolveRev,
|
|
247
|
-
currentBranch,
|
|
248
|
-
gitText,
|
|
249
|
-
worktreeText,
|
|
250
|
-
readDepSides,
|
|
251
|
-
readSnapshot,
|
|
252
|
-
readSnapshotAsync,
|
|
253
|
-
};
|
package/lib/git/run.js
DELETED
|
@@ -1,100 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
const proc = require('./proc.js');
|
|
4
|
-
const { runProc, runProcSync, isAbort } = proc;
|
|
5
|
-
|
|
6
|
-
const oneLine = (text, fallback = 'git failed') => proc.oneLine(text, fallback);
|
|
7
|
-
|
|
8
|
-
const GIT_CONFIG = [
|
|
9
|
-
'-c',
|
|
10
|
-
'core.quotepath=false',
|
|
11
|
-
'-c',
|
|
12
|
-
'i18n.logOutputEncoding=utf-8',
|
|
13
|
-
];
|
|
14
|
-
const DIFF_OPTS = ['--no-color', '--no-ext-diff', '--no-renames', '-U3'];
|
|
15
|
-
const GIT_ENCODING = proc.DEFAULT_ENCODING;
|
|
16
|
-
const GIT_MAX_BUFFER = proc.DEFAULT_MAX_BUFFER;
|
|
17
|
-
|
|
18
|
-
const gitEnv = () => ({ ...process.env, GIT_OPTIONAL_LOCKS: '0' });
|
|
19
|
-
|
|
20
|
-
const gitProcOptions = (cwd, extra = {}) => ({
|
|
21
|
-
cwd,
|
|
22
|
-
env: gitEnv(),
|
|
23
|
-
encoding: GIT_ENCODING,
|
|
24
|
-
maxBuffer: GIT_MAX_BUFFER,
|
|
25
|
-
input: extra.input,
|
|
26
|
-
signal: extra.signal,
|
|
27
|
-
});
|
|
28
|
-
|
|
29
|
-
const gitResult = (result) => {
|
|
30
|
-
if (!result.error) return result;
|
|
31
|
-
if (isAbort(result.error)) throw result.error;
|
|
32
|
-
if (result.error.code === 'ENOENT') throw new Error('git not found');
|
|
33
|
-
throw result.error;
|
|
34
|
-
};
|
|
35
|
-
|
|
36
|
-
const requireOk = (result, fallback = 'git failed') => {
|
|
37
|
-
if (result.status === 0) return result;
|
|
38
|
-
const msg = result.stderr || result.stdout || fallback;
|
|
39
|
-
throw new Error(oneLine(msg, fallback));
|
|
40
|
-
};
|
|
41
|
-
|
|
42
|
-
const runGit = (args, cwd, input) => {
|
|
43
|
-
const options = gitProcOptions(cwd, { input });
|
|
44
|
-
return gitResult(runProcSync('git', args, options));
|
|
45
|
-
};
|
|
46
|
-
|
|
47
|
-
const runGitAsync = (args, cwd, extra = {}) => {
|
|
48
|
-
const options = gitProcOptions(cwd, extra);
|
|
49
|
-
return runProc('git', args, options).then(gitResult);
|
|
50
|
-
};
|
|
51
|
-
|
|
52
|
-
const pathArgsOf = (paths) => (paths.length ? ['--', ...paths] : []);
|
|
53
|
-
|
|
54
|
-
const cachedDiffArgs = (pathArgs) => [
|
|
55
|
-
...GIT_CONFIG,
|
|
56
|
-
'diff',
|
|
57
|
-
'--cached',
|
|
58
|
-
...DIFF_OPTS,
|
|
59
|
-
...pathArgs,
|
|
60
|
-
];
|
|
61
|
-
|
|
62
|
-
const worktreeDiffArgs = (pathArgs) => [
|
|
63
|
-
...GIT_CONFIG,
|
|
64
|
-
'diff',
|
|
65
|
-
...DIFF_OPTS,
|
|
66
|
-
...pathArgs,
|
|
67
|
-
];
|
|
68
|
-
|
|
69
|
-
const commitDiffArgs = (commit, parent, pathArgs) => {
|
|
70
|
-
if (parent.status === 0) {
|
|
71
|
-
const from = parent.stdout.trim();
|
|
72
|
-
return [...GIT_CONFIG, 'diff', ...DIFF_OPTS, from, commit, ...pathArgs];
|
|
73
|
-
}
|
|
74
|
-
return [
|
|
75
|
-
...GIT_CONFIG,
|
|
76
|
-
'diff-tree',
|
|
77
|
-
'--no-commit-id',
|
|
78
|
-
'--root',
|
|
79
|
-
'-p',
|
|
80
|
-
...DIFF_OPTS,
|
|
81
|
-
commit,
|
|
82
|
-
...pathArgs,
|
|
83
|
-
];
|
|
84
|
-
};
|
|
85
|
-
|
|
86
|
-
module.exports = {
|
|
87
|
-
GIT_CONFIG,
|
|
88
|
-
DIFF_OPTS,
|
|
89
|
-
GIT_ENCODING,
|
|
90
|
-
GIT_MAX_BUFFER,
|
|
91
|
-
oneLine,
|
|
92
|
-
gitResult,
|
|
93
|
-
requireOk,
|
|
94
|
-
runGit,
|
|
95
|
-
runGitAsync,
|
|
96
|
-
pathArgsOf,
|
|
97
|
-
cachedDiffArgs,
|
|
98
|
-
worktreeDiffArgs,
|
|
99
|
-
commitDiffArgs,
|
|
100
|
-
};
|
package/lib/npm/commands.js
DELETED
|
@@ -1,100 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
const path = require('node:path');
|
|
4
|
-
|
|
5
|
-
const { npmBin, npmOpts } = require('../sys.js');
|
|
6
|
-
const { depFileMeta, LOCKFILE } = require('../deps.js');
|
|
7
|
-
const proc = require('../git/proc.js');
|
|
8
|
-
const { runProc, runProcSync } = proc;
|
|
9
|
-
|
|
10
|
-
const AUDIT_MS = 15000;
|
|
11
|
-
const INSTALL_MS = 120000;
|
|
12
|
-
|
|
13
|
-
const npmProcOptions = (cwd, extra = {}) => ({
|
|
14
|
-
cwd,
|
|
15
|
-
encoding: proc.DEFAULT_ENCODING,
|
|
16
|
-
maxBuffer: proc.DEFAULT_MAX_BUFFER,
|
|
17
|
-
timeout: extra.timeout,
|
|
18
|
-
signal: extra.signal,
|
|
19
|
-
shell: npmOpts().shell,
|
|
20
|
-
});
|
|
21
|
-
|
|
22
|
-
const runNpm = (cwd, args) =>
|
|
23
|
-
runProcSync(npmBin(), args, npmProcOptions(cwd, { timeout: INSTALL_MS }));
|
|
24
|
-
|
|
25
|
-
const runNpmAsync = (cwd, args, extra = {}) =>
|
|
26
|
-
runProc(
|
|
27
|
-
npmBin(),
|
|
28
|
-
args,
|
|
29
|
-
npmProcOptions(cwd, { timeout: INSTALL_MS, signal: extra.signal }),
|
|
30
|
-
);
|
|
31
|
-
|
|
32
|
-
const runNpmJson = (top, args, timeout) => {
|
|
33
|
-
const result = runProcSync(npmBin(), args, npmProcOptions(top, { timeout }));
|
|
34
|
-
if (result.error) return '';
|
|
35
|
-
return result.stdout || '';
|
|
36
|
-
};
|
|
37
|
-
|
|
38
|
-
const runNpmJsonAsync = async (top, args, timeout, signal) => {
|
|
39
|
-
const result = await runProc(
|
|
40
|
-
npmBin(),
|
|
41
|
-
args,
|
|
42
|
-
npmProcOptions(top, { timeout, signal }),
|
|
43
|
-
);
|
|
44
|
-
if (result.error) return '';
|
|
45
|
-
return result.stdout || '';
|
|
46
|
-
};
|
|
47
|
-
|
|
48
|
-
const depChange = (item) => item.dep?.change ?? null;
|
|
49
|
-
|
|
50
|
-
const depPaths = (item) => item.dep?.files ?? [];
|
|
51
|
-
|
|
52
|
-
const firstDepRel = (files, kind) => {
|
|
53
|
-
for (const rel of files) {
|
|
54
|
-
const meta = depFileMeta(rel);
|
|
55
|
-
if (meta && meta.kind === kind) return rel;
|
|
56
|
-
}
|
|
57
|
-
return '';
|
|
58
|
-
};
|
|
59
|
-
|
|
60
|
-
const proposedNpmPlan = (top, item) => {
|
|
61
|
-
const change = depChange(item);
|
|
62
|
-
if (!change) return null;
|
|
63
|
-
const files = depPaths(item);
|
|
64
|
-
const lockOnly = change.section === 'resolved';
|
|
65
|
-
const removing = !!change.unused;
|
|
66
|
-
const manifest = firstDepRel(files, 'manifest');
|
|
67
|
-
const lockRel = firstDepRel(files, 'lockfile');
|
|
68
|
-
const picked = lockOnly ? lockRel : manifest;
|
|
69
|
-
const target = picked || files[0] || '';
|
|
70
|
-
const meta = depFileMeta(target);
|
|
71
|
-
if (!meta) return null;
|
|
72
|
-
const cwd = meta.dir === '.' ? top : path.join(top, meta.dir);
|
|
73
|
-
let npmArgs = ['i'];
|
|
74
|
-
if (removing) npmArgs = ['uninstall', change.name];
|
|
75
|
-
else if (lockOnly) npmArgs = ['audit', 'fix'];
|
|
76
|
-
const fail = removing ? 'npm uninstall failed' : 'npm i failed';
|
|
77
|
-
const dirLock = meta.dir === '.' ? LOCKFILE : `${meta.dir}/${LOCKFILE}`;
|
|
78
|
-
const lockPath = lockRel || dirLock;
|
|
79
|
-
const prepareManifest = !lockOnly && !removing && !!manifest;
|
|
80
|
-
return {
|
|
81
|
-
cwd,
|
|
82
|
-
npmArgs,
|
|
83
|
-
fail,
|
|
84
|
-
lockOnly,
|
|
85
|
-
lockPath,
|
|
86
|
-
manifest,
|
|
87
|
-
prepareManifest,
|
|
88
|
-
runner: item.dep.install,
|
|
89
|
-
};
|
|
90
|
-
};
|
|
91
|
-
|
|
92
|
-
module.exports = {
|
|
93
|
-
AUDIT_MS,
|
|
94
|
-
INSTALL_MS,
|
|
95
|
-
runNpm,
|
|
96
|
-
runNpmAsync,
|
|
97
|
-
runNpmJson,
|
|
98
|
-
runNpmJsonAsync,
|
|
99
|
-
proposedNpmPlan,
|
|
100
|
-
};
|
package/lib/remote/changes.js
DELETED
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
const { itemPath, isPathInScope } = require('../files.js');
|
|
4
|
-
|
|
5
|
-
const changePath = (file) => file.newPath || file.oldPath || '';
|
|
6
|
-
|
|
7
|
-
const filterChangeFiles = (files, paths) => {
|
|
8
|
-
if (!paths.length) return files;
|
|
9
|
-
const kept = [];
|
|
10
|
-
for (const file of files) {
|
|
11
|
-
if (isPathInScope(changePath(file), paths)) kept.push(file);
|
|
12
|
-
}
|
|
13
|
-
return kept;
|
|
14
|
-
};
|
|
15
|
-
|
|
16
|
-
const pushChangeFile = (files, seen, rel) => {
|
|
17
|
-
if (!rel || seen.has(rel)) return;
|
|
18
|
-
seen.add(rel);
|
|
19
|
-
files.push(rel);
|
|
20
|
-
};
|
|
21
|
-
|
|
22
|
-
const changeFiles = (items) => {
|
|
23
|
-
const files = [];
|
|
24
|
-
const seen = new Set();
|
|
25
|
-
for (const item of items) {
|
|
26
|
-
if (item.dep) {
|
|
27
|
-
const depFiles = item.dep.files ?? [];
|
|
28
|
-
for (const rel of depFiles) pushChangeFile(files, seen, rel);
|
|
29
|
-
continue;
|
|
30
|
-
}
|
|
31
|
-
const rel = itemPath(item);
|
|
32
|
-
pushChangeFile(files, seen, rel);
|
|
33
|
-
}
|
|
34
|
-
return files;
|
|
35
|
-
};
|
|
36
|
-
|
|
37
|
-
module.exports = { changePath, filterChangeFiles, changeFiles };
|