@lumpcode/core 0.0.9 → 0.0.11

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 (38) hide show
  1. package/dist/helpers/executeStepsForContextList/main.d.ts.map +1 -1
  2. package/dist/helpers/getContextStatus/main.d.ts.map +1 -1
  3. package/dist/index.cjs +35 -52
  4. package/dist/index.cjs.map +1 -1
  5. package/dist/index.js +35 -51
  6. package/dist/index.js.map +1 -1
  7. package/dist/utils/appendMissingGitignoreLines/index.d.ts +2 -0
  8. package/dist/utils/appendMissingGitignoreLines/index.d.ts.map +1 -0
  9. package/dist/utils/appendMissingGitignoreLines/main.d.ts +6 -0
  10. package/dist/utils/appendMissingGitignoreLines/main.d.ts.map +1 -0
  11. package/dist/utils/historyFile/main.d.ts.map +1 -1
  12. package/dist/utils/index.d.ts +2 -3
  13. package/dist/utils/index.d.ts.map +1 -1
  14. package/dist/utils/isProcessAlive/index.d.ts +2 -0
  15. package/dist/utils/isProcessAlive/index.d.ts.map +1 -0
  16. package/dist/utils/isProcessAlive/main.d.ts +6 -0
  17. package/dist/utils/isProcessAlive/main.d.ts.map +1 -0
  18. package/dist/utils/nodeErrnoCode/index.d.ts +2 -0
  19. package/dist/utils/nodeErrnoCode/index.d.ts.map +1 -0
  20. package/dist/utils/nodeErrnoCode/main.d.ts +3 -0
  21. package/dist/utils/nodeErrnoCode/main.d.ts.map +1 -0
  22. package/dist/utils/parseGitLogHashSubjectLines/index.d.ts +2 -0
  23. package/dist/utils/parseGitLogHashSubjectLines/index.d.ts.map +1 -0
  24. package/dist/utils/parseGitLogHashSubjectLines/main.d.ts +7 -0
  25. package/dist/utils/parseGitLogHashSubjectLines/main.d.ts.map +1 -0
  26. package/dist/utils/pathExists/index.d.ts +2 -0
  27. package/dist/utils/pathExists/index.d.ts.map +1 -0
  28. package/dist/utils/pathExists/main.d.ts +3 -0
  29. package/dist/utils/pathExists/main.d.ts.map +1 -0
  30. package/dist/utils/readJsonFile/index.d.ts +2 -0
  31. package/dist/utils/readJsonFile/index.d.ts.map +1 -0
  32. package/dist/utils/readJsonFile/main.d.ts +21 -0
  33. package/dist/utils/readJsonFile/main.d.ts.map +1 -0
  34. package/dist/utils/resolveBundledAssetPath/index.d.ts +2 -0
  35. package/dist/utils/resolveBundledAssetPath/index.d.ts.map +1 -0
  36. package/dist/utils/resolveBundledAssetPath/main.d.ts +3 -0
  37. package/dist/utils/resolveBundledAssetPath/main.d.ts.map +1 -0
  38. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -4,7 +4,7 @@ import * as fs from 'node:fs';
4
4
  import * as path from 'node:path';
5
5
  import { extname, dirname } from 'node:path';
6
6
  import * as fs$1 from 'node:fs/promises';
7
- import { readFile, mkdir, writeFile, stat } from 'node:fs/promises';
7
+ import { readFile, mkdir, writeFile } from 'node:fs/promises';
8
8
  import ignore from 'ignore';
9
9
  import z from 'zod';
10
10
 
@@ -38,18 +38,6 @@ function failure(data) {
38
38
  };
39
39
  }
40
40
 
41
- function decision(possibilities, defaultValue) {
42
- for (const [condition, result] of possibilities) {
43
- if (condition()) {
44
- return result();
45
- }
46
- }
47
- if (defaultValue) {
48
- return defaultValue;
49
- }
50
- throw new Error('No value found in decision');
51
- }
52
-
53
41
  /**
54
42
  * Wrap an arbitrary string in quotes so it can be safely embedded in
55
43
  * a shell command (e.g. the command string passed to `execAsync`).
@@ -64,18 +52,6 @@ function shellSingleQuote(value) {
64
52
  return `'${value.split("'").join(`'\\''`)}'`;
65
53
  }
66
54
 
67
- /**
68
- * Wrap a shell fragment so failure does not break a surrounding `&&` chain.
69
- *
70
- * Unix: `cmd || true`. Windows cmd.exe: `(cmd || cd .)`.
71
- */
72
- function shellBestEffort(command) {
73
- if (process.platform === 'win32') {
74
- return `(${command} || cd .)`;
75
- }
76
- return `${command} || true`;
77
- }
78
-
79
55
  const DEFAULT_WINDOWS_PATHEXT = [
80
56
  '.COM',
81
57
  '.EXE',
@@ -226,14 +202,6 @@ function createConsoleLogger(input) {
226
202
  return makeLogger(prefix);
227
203
  }
228
204
 
229
- const noopLogger = {
230
- error: () => { },
231
- warn: () => { },
232
- info: () => { },
233
- verbose: () => { },
234
- child: () => noopLogger,
235
- };
236
-
237
205
  function firstNonEmptyLine(value) {
238
206
  if (value == null)
239
207
  return undefined;
@@ -3165,6 +3133,17 @@ function dump(input, options = {}) {
3165
3133
  });
3166
3134
  }
3167
3135
 
3136
+ /** Returns whether `filePath` is accessible to this process (typically exists). */
3137
+ async function pathExists(filePath) {
3138
+ try {
3139
+ await fs$1.access(filePath);
3140
+ return true;
3141
+ }
3142
+ catch {
3143
+ return false;
3144
+ }
3145
+ }
3146
+
3168
3147
  function historyFormatFromPath(filePath) {
3169
3148
  const ext = extname(filePath).toLowerCase();
3170
3149
  if (ext === '.yaml' || ext === '.yml') {
@@ -3251,7 +3230,7 @@ async function appendHistoryEntry({ filePath, entry, }) {
3251
3230
  if (!formatResult.success) {
3252
3231
  return formatResult;
3253
3232
  }
3254
- const exists = await stat(filePath).then(() => true).catch(() => false);
3233
+ const exists = await pathExists(filePath);
3255
3234
  let entries;
3256
3235
  if (exists) {
3257
3236
  const readResult = await readHistoryFile({ filePath });
@@ -3268,6 +3247,21 @@ async function appendHistoryEntry({ filePath, entry, }) {
3268
3247
  return writeHistoryFile({ filePath, entries });
3269
3248
  }
3270
3249
 
3250
+ /** Parses `git log --format='%H %s'` lines into commit hash and subject pairs. */
3251
+ function parseGitLogHashSubjectLines(stdout) {
3252
+ return stdout
3253
+ .split('\n')
3254
+ .map((line) => line.trim())
3255
+ .filter(Boolean)
3256
+ .map((line) => {
3257
+ const sp = line.indexOf(' ');
3258
+ return {
3259
+ hash: sp === -1 ? line : line.slice(0, sp),
3260
+ subject: sp === -1 ? '' : line.slice(sp + 1),
3261
+ };
3262
+ });
3263
+ }
3264
+
3271
3265
  const execAsyncBase = promisify(exec);
3272
3266
  async function execAsync(command, options) {
3273
3267
  const { stdout, stderr, hasErrored } = await execAsyncBase(command, { cwd: options?.cwd })
@@ -3563,8 +3557,8 @@ async function executeStepsForContextList({ baseBranch, branchFn, lumpVariables,
3563
3557
  entry: postCommandExecFnInput,
3564
3558
  });
3565
3559
  if (!appendResult.success) {
3566
- stepWalkFailure = failure({ message: appendResult.data });
3567
- return;
3560
+ // TODO: sanitize history appending to avoid this warning for certain commands outputs
3561
+ logger.warn(`Failed to append history entry to ${keepHistoryFilePath}: ${appendResult.data}`);
3568
3562
  }
3569
3563
  }
3570
3564
  if (postCommandExecFn) {
@@ -3654,7 +3648,7 @@ async function getGitignoresMap({ startDir, stopAtDir }) {
3654
3648
  const stopAtDirParent = path.dirname(stopAtDir);
3655
3649
  while (currentDir !== stopAtDirParent) {
3656
3650
  const gitignorePath = path.join(currentDir, '.gitignore');
3657
- const hasGitignore = await fs$1.access(gitignorePath).then(() => true).catch(() => false);
3651
+ const hasGitignore = await pathExists(gitignorePath);
3658
3652
  if (hasGitignore) {
3659
3653
  const gitignoreContent = await fs$1.readFile(gitignorePath, 'utf-8');
3660
3654
  gitignores.set(currentDir, ignore().add(gitignoreContent));
@@ -3721,19 +3715,9 @@ async function getContextStatus(params) {
3721
3715
  return 'toDo';
3722
3716
  logger?.verbose(`logResult ${JSON.stringify(logResult.data)}`);
3723
3717
  const logResultOutput = logResult.data.stdout || logResult.data.stderr || '';
3724
- const matchingHashes = logResultOutput
3725
- .split('\n')
3726
- .map((line) => line.trim())
3727
- .filter((line) => !!line)
3728
- .map((line) => {
3729
- const sp = line ? line.indexOf(' ') : -1;
3730
- return {
3731
- hash: sp === -1 ? line : line.slice(0, sp),
3732
- subject: sp === -1 ? '' : line.slice(sp + 1),
3733
- };
3734
- })
3735
- .filter((c) => c.subject === commitMessage)
3736
- .map((c) => c.hash);
3718
+ const matchingHashes = parseGitLogHashSubjectLines(logResultOutput)
3719
+ .filter((entry) => entry.subject === commitMessage)
3720
+ .map((entry) => entry.hash);
3737
3721
  logger?.verbose(`remoteName ${remoteName}`);
3738
3722
  logger?.verbose(`baseBranch ${baseBranch}`);
3739
3723
  logger?.verbose(`commitMessage ${commitMessage}`);
@@ -3941,5 +3925,5 @@ async function runLump(input) {
3941
3925
  });
3942
3926
  }
3943
3927
 
3944
- export { appendHistoryEntry, collectStepsForContext, contextStatus, contextStatusSchema, createConsoleLogger, decision, defaultGitAddCommandFn, defaultGitCommitCommandFn, defaultGitCommitMessageFn, defaultGitPushCommandFn, defaultSetupWorkspaceFn, defaultSetupWorkspaceFnWithWorktree, defaultTeardownWorkspaceFn, defaultTeardownWorkspaceFnWithWorktree, execAsync, execBinary, executeStepsForContextList, failure, formatExecFailureMessage, getCodeBasePaths, getContextStatus, getToDoContextList, historyFormatFromPath, noopLogger, readHistoryFile, resolveSpawnExecutable, runLump, set, shellBestEffort, shellSingleQuote, success, validateContextListNames, writeHistoryFile };
3928
+ export { appendHistoryEntry, collectStepsForContext, contextStatus, contextStatusSchema, createConsoleLogger, defaultGitAddCommandFn, defaultGitCommitCommandFn, defaultGitCommitMessageFn, defaultGitPushCommandFn, defaultSetupWorkspaceFn, defaultSetupWorkspaceFnWithWorktree, defaultTeardownWorkspaceFn, defaultTeardownWorkspaceFnWithWorktree, execAsync, execBinary, executeStepsForContextList, failure, formatExecFailureMessage, getCodeBasePaths, getContextStatus, getToDoContextList, historyFormatFromPath, parseGitLogHashSubjectLines, pathExists, readHistoryFile, resolveSpawnExecutable, runLump, set, shellSingleQuote, success, validateContextListNames, writeHistoryFile };
3945
3929
  //# sourceMappingURL=index.js.map