reslop 0.2.5 → 0.2.6

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.
Files changed (105) hide show
  1. package/CHANGELOG.md +12 -1
  2. package/LICENSE +1 -1
  3. package/README.md +11 -11
  4. package/bin/reslop.js +3 -8
  5. package/lib/ansi.js +32 -19
  6. package/lib/capabilities.js +8 -8
  7. package/lib/cli.js +40 -74
  8. package/lib/clipboard.js +39 -47
  9. package/lib/dashboard/git.js +128 -0
  10. package/lib/dashboard/model.js +332 -0
  11. package/lib/dashboard/npm.js +193 -0
  12. package/lib/dashboard/tree.js +278 -0
  13. package/lib/deps-diff.js +197 -402
  14. package/lib/deps.js +113 -240
  15. package/lib/detect.js +8 -18
  16. package/lib/diff/align.js +41 -113
  17. package/lib/diff/diff.js +12 -43
  18. package/lib/diff/display.js +25 -36
  19. package/lib/diff/edit.js +6 -20
  20. package/lib/diff/inline.js +76 -144
  21. package/lib/diff/items.js +33 -47
  22. package/lib/diff/parse.js +28 -56
  23. package/lib/diff/patch.js +12 -33
  24. package/lib/diff/unit.js +79 -178
  25. package/lib/editor.js +52 -69
  26. package/lib/files.js +71 -89
  27. package/lib/git-branches.js +254 -416
  28. package/lib/git-deps.js +147 -272
  29. package/lib/git-reword-todo.js +5 -13
  30. package/lib/git-worktree.js +141 -212
  31. package/lib/git.js +21 -49
  32. package/lib/github.js +67 -181
  33. package/lib/gitlab.js +40 -90
  34. package/lib/highlight/bash.js +55 -177
  35. package/lib/highlight/core.js +155 -141
  36. package/lib/highlight/css.js +25 -58
  37. package/lib/highlight/csv.js +19 -37
  38. package/lib/highlight/dart.js +72 -213
  39. package/lib/highlight/dot.js +14 -14
  40. package/lib/highlight/html.js +42 -63
  41. package/lib/highlight/js.js +177 -506
  42. package/lib/highlight/json.js +17 -37
  43. package/lib/highlight/log.js +19 -25
  44. package/lib/highlight/txt.js +7 -10
  45. package/lib/highlight.js +17 -46
  46. package/lib/keys.js +49 -82
  47. package/lib/manifest.js +67 -126
  48. package/lib/npm-commands.js +120 -169
  49. package/lib/remote.js +140 -190
  50. package/lib/render/branches.js +63 -61
  51. package/lib/render/chrome.js +220 -333
  52. package/lib/render/commits.js +160 -361
  53. package/lib/render/dash-activity.js +212 -0
  54. package/lib/render/dash-blocks.js +245 -0
  55. package/lib/render/dash-table.js +290 -0
  56. package/lib/render/dashboard.js +62 -0
  57. package/lib/render/diff.js +123 -258
  58. package/lib/render/files.js +40 -85
  59. package/lib/render/frame.js +78 -117
  60. package/lib/render/notes.js +139 -210
  61. package/lib/render/npm.js +213 -177
  62. package/lib/render/present.js +4 -11
  63. package/lib/render/primitives.js +72 -174
  64. package/lib/render/render.js +5 -14
  65. package/lib/render/report.js +43 -0
  66. package/lib/render/tiles.js +260 -0
  67. package/lib/render/unit.js +15 -31
  68. package/lib/report-model.js +110 -33
  69. package/lib/report-parse.js +56 -37
  70. package/lib/report-render.js +102 -59
  71. package/lib/report-run.js +87 -77
  72. package/lib/report-test.js +221 -99
  73. package/lib/report-tools.js +96 -154
  74. package/lib/review-merge.js +33 -41
  75. package/lib/review.js +68 -129
  76. package/lib/runs.js +225 -0
  77. package/lib/select.js +53 -91
  78. package/lib/session/accessors.js +14 -21
  79. package/lib/session/actions.js +61 -43
  80. package/lib/session/branches.js +166 -222
  81. package/lib/session/change-actions.js +49 -119
  82. package/lib/session/commit.js +274 -355
  83. package/lib/session/compose.js +556 -714
  84. package/lib/session/dashboard.js +385 -0
  85. package/lib/session/dispatch.js +162 -170
  86. package/lib/session/files-pane.js +76 -44
  87. package/lib/session/items.js +6 -17
  88. package/lib/session/lifecycle.js +393 -466
  89. package/lib/session/load.js +1 -14
  90. package/lib/session/navigation.js +2 -2
  91. package/lib/session/npm.js +403 -420
  92. package/lib/session/ops.js +5 -13
  93. package/lib/session/pointer.js +16 -14
  94. package/lib/session/progress.js +39 -30
  95. package/lib/session/review.js +1 -3
  96. package/lib/session/tasks.js +276 -235
  97. package/lib/session/templates.js +51 -59
  98. package/lib/session/terminal.js +85 -132
  99. package/lib/session/view.js +47 -81
  100. package/lib/session/watch.js +196 -212
  101. package/lib/session.js +81 -161
  102. package/lib/update.js +44 -111
  103. package/lib/utilities.js +46 -88
  104. package/lib/wrap.js +29 -55
  105. package/package.json +1 -1
@@ -0,0 +1,385 @@
1
+ 'use strict';
2
+
3
+ const files = require('../files.js');
4
+ const { fileEntries, fileTotals } = files;
5
+ const review = require('../review.js');
6
+ const { noteCounts } = review;
7
+ const runs = require('../runs.js');
8
+ const { readRuns, settleRecord, isRunsRel } = runs;
9
+ const tree = require('../dashboard/tree.js');
10
+ const { FileIndex, HEAT_MS } = tree;
11
+ const gitInfo = require('../dashboard/git.js');
12
+ const { readGitSummary } = gitInfo;
13
+ const npmInfo = require('../dashboard/npm.js');
14
+ const { readNpmSummary } = npmInfo;
15
+ const model = require('../dashboard/model.js');
16
+ const { buildModel } = model;
17
+ const filesPane = require('./files-pane.js');
18
+ const watch = require('./watch.js');
19
+ const { UNKNOWN_PATH, MODULES_STAMP } = watch;
20
+
21
+ const TICK_ID = 'dashboard';
22
+ const HEAT_TIMER = 'dashboard-heat';
23
+ const AGE_TIMER = 'dashboard-age';
24
+ const SAMPLES = 40;
25
+ const SWITCHES = 4;
26
+ const GIT_NAMES = new Set([
27
+ 'HEAD',
28
+ 'packed-refs',
29
+ 'FETCH_HEAD',
30
+ 'ORIG_HEAD',
31
+ 'refs',
32
+ 'logs',
33
+ 'rebase-merge',
34
+ 'rebase-apply',
35
+ ]);
36
+ const NPM_FILES = new Set(['package.json', 'package-lock.json', MODULES_STAMP]);
37
+ const AGE_FAST_MS = 1000;
38
+ const AGE_MID_MS = 30000;
39
+ const AGE_SLOW_MS = 600000;
40
+
41
+ class Coalesced {
42
+ constructor(run, onDone) {
43
+ this.run = run;
44
+ this.onDone = onDone;
45
+ this.running = false;
46
+ this.dirty = false;
47
+ }
48
+
49
+ request() {
50
+ this.dirty = true;
51
+ if (!this.running) void this.pump();
52
+ }
53
+
54
+ async pump() {
55
+ this.running = true;
56
+ while (this.dirty) {
57
+ this.dirty = false;
58
+ try {
59
+ await this.run();
60
+ } catch {
61
+ // keep the previous data until the next event
62
+ }
63
+ }
64
+ this.running = false;
65
+ this.onDone();
66
+ }
67
+ }
68
+
69
+ const totalsKey = (totals) =>
70
+ [
71
+ totals.stagedAdded,
72
+ totals.unstagedAdded,
73
+ totals.stagedRemoved,
74
+ totals.unstagedRemoved,
75
+ totals.remaining,
76
+ ].join(':');
77
+
78
+ const classify = (paths) => {
79
+ const found = { files: [], git: false, npm: false, runs: false, all: false };
80
+ for (const rel of paths) {
81
+ if (rel === UNKNOWN_PATH) {
82
+ found.all = true;
83
+ } else if (rel.startsWith('.git/')) {
84
+ if (GIT_NAMES.has(rel.split('/')[1])) found.git = true;
85
+ } else if (isRunsRel(rel)) {
86
+ found.runs = true;
87
+ } else {
88
+ if (NPM_FILES.has(rel)) found.npm = true;
89
+ found.files.push(rel);
90
+ }
91
+ }
92
+ return found;
93
+ };
94
+
95
+ const ageDelay = (ageMs) => {
96
+ if (ageMs < 90000) return AGE_FAST_MS;
97
+ if (ageMs < 5400000) return AGE_MID_MS;
98
+ return AGE_SLOW_MS;
99
+ };
100
+
101
+ class Dashboard {
102
+ constructor(ui) {
103
+ this.ui = ui;
104
+ this.epoch = 0;
105
+ const done = () => this.done();
106
+ this.tasks = {
107
+ files: new Coalesced(() => this.runFiles(), done),
108
+ git: new Coalesced(() => this.runGit(), done),
109
+ npm: new Coalesced(() => this.runNpm(), done),
110
+ runs: new Coalesced(() => this.runRuns(), done),
111
+ };
112
+ this.clear();
113
+ }
114
+
115
+ clear() {
116
+ this.epoch += 1;
117
+ this.active = false;
118
+ this.index = null;
119
+ this.touch = new Set();
120
+ this.fileDelta = null;
121
+ this.git = null;
122
+ this.npm = null;
123
+ this.runs = [];
124
+ this.totals = null;
125
+ this.totalsKey = '';
126
+ this.diffDelta = null;
127
+ this.samples = [];
128
+ this.switches = [];
129
+ this.branchAt = new Map();
130
+ this.branchSha = new Map();
131
+ this.lastSha = '';
132
+ this.marks = { npm: 0, commit: 0, branches: 0 };
133
+ }
134
+
135
+ root() {
136
+ return this.ui.top || this.ui.cwd;
137
+ }
138
+
139
+ visible() {
140
+ return this.ui.uiOpen && this.ui.nav.pane === 'dashboard';
141
+ }
142
+
143
+ paintIfVisible() {
144
+ if (this.visible()) this.ui.paint();
145
+ }
146
+
147
+ done() {
148
+ this.afterDraw();
149
+ this.paintIfVisible();
150
+ }
151
+
152
+ hotUntil() {
153
+ const { marks, index, fileDelta, diffDelta } = this;
154
+ return Math.max(
155
+ index ? index.hotUntil() : 0,
156
+ fileDelta ? fileDelta.at + HEAT_MS : 0,
157
+ diffDelta ? diffDelta.at + HEAT_MS : 0,
158
+ marks.npm + HEAT_MS,
159
+ marks.commit + HEAT_MS,
160
+ marks.branches + HEAT_MS,
161
+ );
162
+ }
163
+
164
+ liveRuns() {
165
+ return this.runs.map((run) => settleRecord(run));
166
+ }
167
+
168
+ youngest(runs) {
169
+ const last = this.git && this.git.commits.last;
170
+ let at = last ? last.at : 0;
171
+ for (const run of runs) at = Math.max(at, run.endedAt, run.startedAt);
172
+ return at;
173
+ }
174
+
175
+ cancelTimers() {
176
+ const { progress, term } = this.ui;
177
+ progress.stop(TICK_ID);
178
+ term.cancel(HEAT_TIMER);
179
+ term.cancel(AGE_TIMER);
180
+ }
181
+
182
+ afterDraw() {
183
+ if (!this.active) return;
184
+ if (!this.visible()) return void this.cancelTimers();
185
+ const { progress, term } = this.ui;
186
+ const now = Date.now();
187
+ const until = this.hotUntil();
188
+ const hot = now < until;
189
+ const runs = this.liveRuns();
190
+ const running = runs.some((run) => run.status === 'running');
191
+ if (running || hot) progress.start(TICK_ID);
192
+ else progress.stop(TICK_ID);
193
+ const repaint = () => this.paintIfVisible();
194
+ if (hot) term.later(HEAT_TIMER, repaint, until - now + 20);
195
+ const at = this.youngest(runs);
196
+ const delay = at ? ageDelay(now - at) : AGE_SLOW_MS;
197
+ term.later(AGE_TIMER, repaint, delay);
198
+ }
199
+
200
+ async runFiles() {
201
+ const { epoch, index } = this;
202
+ if (!index) return;
203
+ const wasReady = index.ready;
204
+ const before = index.summary().total;
205
+ const paths = [...this.touch];
206
+ this.touch.clear();
207
+ const changed = await index.touch(paths);
208
+ if (epoch !== this.epoch || !changed || !wasReady) return;
209
+ const after = index.summary().total;
210
+ const lines = after.lines - before.lines;
211
+ const bytes = after.bytes - before.bytes;
212
+ if (lines || bytes) this.fileDelta = { lines, at: Date.now() };
213
+ }
214
+
215
+ noteShas(next, now) {
216
+ const seen = this.branchSha;
217
+ const known = seen.size > 0;
218
+ let changed = false;
219
+ for (const entry of next.branches) {
220
+ if (known && seen.get(entry.name) !== entry.sha) {
221
+ this.branchAt.set(entry.name, now);
222
+ changed = true;
223
+ }
224
+ seen.set(entry.name, entry.sha);
225
+ }
226
+ return changed;
227
+ }
228
+
229
+ noteSwitch(next, now) {
230
+ const prev = this.git;
231
+ if (!prev || !prev.branch || !next.branch) return false;
232
+ if (prev.branch === next.branch) return false;
233
+ const entry = { from: prev.branch, to: next.branch, at: now };
234
+ this.switches = [entry, ...this.switches].slice(0, SWITCHES);
235
+ return true;
236
+ }
237
+
238
+ async runGit() {
239
+ const epoch = this.epoch;
240
+ const next = await readGitSummary(this.root());
241
+ if (epoch !== this.epoch) return;
242
+ const now = Date.now();
243
+ const moved = this.noteShas(next, now);
244
+ const switched = this.noteSwitch(next, now);
245
+ if (moved || switched) this.marks.branches = now;
246
+ const sha = next.commits.last ? next.commits.last.sha : '';
247
+ if (this.lastSha && sha !== this.lastSha) this.marks.commit = now;
248
+ this.lastSha = sha;
249
+ this.git = next;
250
+ }
251
+
252
+ async runNpm() {
253
+ const epoch = this.epoch;
254
+ const prev = this.npm;
255
+ const next = await readNpmSummary(this.root(), prev);
256
+ if (epoch !== this.epoch) return;
257
+ const changed =
258
+ prev &&
259
+ (prev.deps !== next.deps ||
260
+ prev.dev !== next.dev ||
261
+ prev.modules.stamp !== next.modules.stamp);
262
+ if (changed) this.marks.npm = Date.now();
263
+ this.npm = next;
264
+ }
265
+
266
+ runRuns() {
267
+ this.runs = readRuns(this.root());
268
+ }
269
+
270
+ noteLoaded() {
271
+ if (!this.active) return;
272
+ const totals = fileTotals(fileEntries(this.ui.items));
273
+ const key = totalsKey(totals);
274
+ if (key === this.totalsKey) return;
275
+ const prev = this.totals;
276
+ if (prev) {
277
+ const added = totals.added - prev.added;
278
+ const removed = totals.removed - prev.removed;
279
+ this.diffDelta = { added, removed, at: Date.now() };
280
+ }
281
+ this.totals = totals;
282
+ this.totalsKey = key;
283
+ this.samples.push(totals.added + totals.removed);
284
+ if (this.samples.length > SAMPLES) this.samples.shift();
285
+ }
286
+
287
+ requestAll() {
288
+ this.touch.add(UNKNOWN_PATH);
289
+ for (const task of Object.values(this.tasks)) task.request();
290
+ }
291
+
292
+ noteDisk(paths) {
293
+ if (!this.active) return;
294
+ const found = classify(paths);
295
+ if (found.all) return void this.requestAll();
296
+ const tasks = this.tasks;
297
+ if (found.files.length) {
298
+ for (const rel of found.files) this.touch.add(rel);
299
+ tasks.files.request();
300
+ }
301
+ if (found.git) tasks.git.request();
302
+ if (found.npm) tasks.npm.request();
303
+ if (found.runs) tasks.runs.request();
304
+ }
305
+
306
+ start() {
307
+ if (this.active) return;
308
+ this.clear();
309
+ this.active = true;
310
+ this.index = new FileIndex(this.root());
311
+ this.noteLoaded();
312
+ this.requestAll();
313
+ }
314
+
315
+ stop() {
316
+ this.epoch += 1;
317
+ this.active = false;
318
+ this.cancelTimers();
319
+ }
320
+
321
+ reset() {
322
+ this.stop();
323
+ this.clear();
324
+ }
325
+
326
+ view() {
327
+ const ui = this.ui;
328
+ const entries = fileEntries(ui.items);
329
+ const store = ui.review.store;
330
+ return buildModel({
331
+ now: Date.now(),
332
+ frame: ui.progressFrame,
333
+ busy: ui.ops.busy,
334
+ index: this.index,
335
+ fileDelta: this.fileDelta,
336
+ entries,
337
+ totals: this.totals ?? fileTotals(entries),
338
+ samples: this.samples,
339
+ diffDelta: this.diffDelta,
340
+ git: this.git,
341
+ switches: this.switches,
342
+ branchAt: this.branchAt,
343
+ marks: this.marks,
344
+ npm: this.npm,
345
+ npmExtras: ui.lifecycle.npmExtras(),
346
+ npmRun: ui.npm.lastRun,
347
+ runs: this.liveRuns(),
348
+ notes: noteCounts(store),
349
+ store,
350
+ });
351
+ }
352
+
353
+ showFiles(scope) {
354
+ const ui = this.ui;
355
+ ui.showFiles();
356
+ if (scope === 'file') filesPane.onFileScope(ui);
357
+ else filesPane.onDiffScope(ui);
358
+ ui.status = '';
359
+ }
360
+
361
+ open(id) {
362
+ const ui = this.ui;
363
+ const openers = {
364
+ files: () => this.showFiles('file'),
365
+ diffs: () => this.showFiles('diff'),
366
+ commits: () => ui.commits.onCommit(),
367
+ branches: () => ui.gitBranches.onBranch(),
368
+ npm: () => ui.npm.open(),
369
+ run: () => ui.npm.open(),
370
+ tasks: () => ui.composer.tasks.openTasksPage(),
371
+ };
372
+ const opener = openers[id];
373
+ if (!opener || ui.mode !== 'review') return;
374
+ opener();
375
+ this.afterDraw();
376
+ }
377
+
378
+ enter() {
379
+ if (!this.active) return;
380
+ this.tasks.runs.request();
381
+ this.afterDraw();
382
+ }
383
+ }
384
+
385
+ module.exports = { Dashboard, classify, ageDelay };