sfdx-git-delta 7.0.1 → 7.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.
Files changed (139) hide show
  1. package/README.md +12 -3
  2. package/lib/adapter/GitAdapter.d.ts +25 -64
  3. package/lib/adapter/GitAdapter.js +352 -483
  4. package/lib/adapter/GitAdapter.js.map +1 -1
  5. package/lib/adapter/gitBlobReader.d.ts +8 -10
  6. package/lib/adapter/gitBlobReader.js.map +1 -1
  7. package/lib/adapter/ioExecutor.d.ts +5 -4
  8. package/lib/adapter/ioExecutor.js +22 -14
  9. package/lib/adapter/ioExecutor.js.map +1 -1
  10. package/lib/adapter/pathMatching.d.ts +9 -0
  11. package/lib/adapter/pathMatching.js +83 -0
  12. package/lib/adapter/pathMatching.js.map +1 -0
  13. package/lib/adapter/tsgitErrorMap.d.ts +7 -0
  14. package/lib/adapter/tsgitErrorMap.js +32 -0
  15. package/lib/adapter/tsgitErrorMap.js.map +1 -0
  16. package/lib/commands/sgd/source/delta.js.map +1 -1
  17. package/lib/constant/gitConstants.d.ts +0 -2
  18. package/lib/constant/gitConstants.js +0 -8
  19. package/lib/constant/gitConstants.js.map +1 -1
  20. package/lib/constant/metadataConstants.d.ts +1 -0
  21. package/lib/constant/metadataConstants.js +1 -0
  22. package/lib/constant/metadataConstants.js.map +1 -1
  23. package/lib/main.d.ts +2 -2
  24. package/lib/main.js +64 -35
  25. package/lib/main.js.map +1 -1
  26. package/lib/post-processor/baseProcessor.d.ts +9 -6
  27. package/lib/post-processor/baseProcessor.js +5 -6
  28. package/lib/post-processor/baseProcessor.js.map +1 -1
  29. package/lib/post-processor/changesManifestProcessor.d.ts +3 -2
  30. package/lib/post-processor/changesManifestProcessor.js +5 -4
  31. package/lib/post-processor/changesManifestProcessor.js.map +1 -1
  32. package/lib/post-processor/flowTranslationProcessor.d.ts +8 -7
  33. package/lib/post-processor/flowTranslationProcessor.js +20 -19
  34. package/lib/post-processor/flowTranslationProcessor.js.map +1 -1
  35. package/lib/post-processor/includeProcessor.d.ts +6 -5
  36. package/lib/post-processor/includeProcessor.js +7 -6
  37. package/lib/post-processor/includeProcessor.js.map +1 -1
  38. package/lib/post-processor/packageGenerator.d.ts +3 -2
  39. package/lib/post-processor/packageGenerator.js +5 -4
  40. package/lib/post-processor/packageGenerator.js.map +1 -1
  41. package/lib/post-processor/postProcessorManager.d.ts +5 -7
  42. package/lib/post-processor/postProcessorManager.js +23 -31
  43. package/lib/post-processor/postProcessorManager.js.map +1 -1
  44. package/lib/service/botHandler.d.ts +1 -2
  45. package/lib/service/botHandler.js +17 -10
  46. package/lib/service/botHandler.js.map +1 -1
  47. package/lib/service/containedDecomposedHandler.d.ts +4 -5
  48. package/lib/service/containedDecomposedHandler.js +13 -12
  49. package/lib/service/containedDecomposedHandler.js.map +1 -1
  50. package/lib/service/customFieldHandler.d.ts +1 -2
  51. package/lib/service/customFieldHandler.js +7 -6
  52. package/lib/service/customFieldHandler.js.map +1 -1
  53. package/lib/service/customLabelHandler.d.ts +1 -2
  54. package/lib/service/customLabelHandler.js +3 -3
  55. package/lib/service/customLabelHandler.js.map +1 -1
  56. package/lib/service/customObjectHandler.d.ts +3 -4
  57. package/lib/service/customObjectHandler.js +10 -9
  58. package/lib/service/customObjectHandler.js.map +1 -1
  59. package/lib/service/decomposedHandler.d.ts +3 -4
  60. package/lib/service/decomposedHandler.js +5 -4
  61. package/lib/service/decomposedHandler.js.map +1 -1
  62. package/lib/service/diffLineInterpreter.d.ts +3 -3
  63. package/lib/service/diffLineInterpreter.js +18 -14
  64. package/lib/service/diffLineInterpreter.js.map +1 -1
  65. package/lib/service/flowHandler.d.ts +1 -2
  66. package/lib/service/flowHandler.js +9 -4
  67. package/lib/service/flowHandler.js.map +1 -1
  68. package/lib/service/inFileHandler.d.ts +8 -9
  69. package/lib/service/inFileHandler.js +28 -27
  70. package/lib/service/inFileHandler.js.map +1 -1
  71. package/lib/service/inFolderHandler.d.ts +4 -5
  72. package/lib/service/inFolderHandler.js +6 -5
  73. package/lib/service/inFolderHandler.js.map +1 -1
  74. package/lib/service/inResourceHandler.d.ts +4 -5
  75. package/lib/service/inResourceHandler.js +8 -7
  76. package/lib/service/inResourceHandler.js.map +1 -1
  77. package/lib/service/objectTranslationHandler.d.ts +1 -2
  78. package/lib/service/objectTranslationHandler.js +6 -5
  79. package/lib/service/objectTranslationHandler.js.map +1 -1
  80. package/lib/service/reportingFolderHandler.d.ts +6 -7
  81. package/lib/service/reportingFolderHandler.js +6 -6
  82. package/lib/service/reportingFolderHandler.js.map +1 -1
  83. package/lib/service/sharedFolderHandler.d.ts +4 -5
  84. package/lib/service/sharedFolderHandler.js +6 -6
  85. package/lib/service/sharedFolderHandler.js.map +1 -1
  86. package/lib/service/standardHandler.d.ts +5 -9
  87. package/lib/service/standardHandler.js +28 -35
  88. package/lib/service/standardHandler.js.map +1 -1
  89. package/lib/service/typeHandlerFactory.d.ts +3 -3
  90. package/lib/service/typeHandlerFactory.js +6 -6
  91. package/lib/service/typeHandlerFactory.js.map +1 -1
  92. package/lib/types/config.d.ts +5 -1
  93. package/lib/types/handlerResult.d.ts +7 -7
  94. package/lib/types/handlerResult.js +10 -1
  95. package/lib/types/handlerResult.js.map +1 -1
  96. package/lib/types/work.d.ts +1 -1
  97. package/lib/utils/arrayUtils.d.ts +1 -1
  98. package/lib/utils/arrayUtils.js.map +1 -1
  99. package/lib/utils/bundleRollup.d.ts +6 -0
  100. package/lib/utils/bundleRollup.js +62 -0
  101. package/lib/utils/bundleRollup.js.map +1 -0
  102. package/lib/utils/changeSet.d.ts +12 -15
  103. package/lib/utils/changeSet.js +23 -120
  104. package/lib/utils/changeSet.js.map +1 -1
  105. package/lib/utils/changesAssembly.d.ts +8 -0
  106. package/lib/utils/changesAssembly.js +21 -0
  107. package/lib/utils/changesAssembly.js.map +1 -0
  108. package/lib/utils/configValidator.d.ts +7 -6
  109. package/lib/utils/configValidator.js +32 -11
  110. package/lib/utils/configValidator.js.map +1 -1
  111. package/lib/utils/fsHelper.d.ts +2 -1
  112. package/lib/utils/fsHelper.js +7 -3
  113. package/lib/utils/fsHelper.js.map +1 -1
  114. package/lib/utils/messageSanitizer.d.ts +1 -0
  115. package/lib/utils/messageSanitizer.js +48 -0
  116. package/lib/utils/messageSanitizer.js.map +1 -0
  117. package/lib/utils/metadataDiff/index.d.ts +0 -2
  118. package/lib/utils/metadataDiff/index.js.map +1 -1
  119. package/lib/utils/metadataDiff/streamingDiff.d.ts +1 -3
  120. package/lib/utils/metadataDiff/streamingDiff.js +16 -54
  121. package/lib/utils/metadataDiff/streamingDiff.js.map +1 -1
  122. package/lib/utils/pathspec.d.ts +15 -0
  123. package/lib/utils/pathspec.js +71 -0
  124. package/lib/utils/pathspec.js.map +1 -0
  125. package/lib/utils/renameResolver.d.ts +6 -6
  126. package/lib/utils/renameResolver.js +10 -9
  127. package/lib/utils/renameResolver.js.map +1 -1
  128. package/lib/utils/repoGitDiff.d.ts +2 -0
  129. package/lib/utils/repoGitDiff.js +14 -1
  130. package/lib/utils/repoGitDiff.js.map +1 -1
  131. package/messages/delta.md +26 -0
  132. package/oclif.manifest.json +2 -2
  133. package/package.json +28 -20
  134. package/lib/adapter/gitBatchCatFile.d.ts +0 -42
  135. package/lib/adapter/gitBatchCatFile.js +0 -203
  136. package/lib/adapter/gitBatchCatFile.js.map +0 -1
  137. package/lib/post-processor/bundleRollupProcessor.d.ts +0 -7
  138. package/lib/post-processor/bundleRollupProcessor.js +0 -81
  139. package/lib/post-processor/bundleRollupProcessor.js.map +0 -1
package/README.md CHANGED
@@ -119,7 +119,7 @@ It's also important to implement a way to switch back to full deployment in case
119
119
 
120
120
  ### Prerequisites
121
121
 
122
- The plugin requires git command line on the running environment.
122
+ No `git` binary is required: the plugin reads the repository's git object store in-process.
123
123
 
124
124
  **Node v22 or above is required**.
125
125
  To check if Salesforce CLI runs under a supported node version for SGD, run `sf --version`. You should see a node version of v22 or above to use SGD.
@@ -201,9 +201,13 @@ FLAG DESCRIPTIONS
201
201
  * If the folder exists, its contents will be processed.
202
202
  * If the folder doesn't exist, it usually won't show any output—unless the folder was recently deleted and is part
203
203
  of a diff, in which case changes may still be picked up.
204
+
205
+ Each value must be a literal repository-relative path: wildcards (`*`, `?`, `[`), git pathspec magic (`:(...)`),
206
+ absolute paths, `..` and the empty string are all rejected. Matching is rooted at the repository root, so
207
+ `--source-dir force-app` does not match `nested/force-app/...`.
204
208
  ```
205
209
 
206
- _See code: [src/commands/sgd/source/delta.ts](https://github.com/scolladon/sfdx-git-delta/blob/v7.0.1/src/commands/sgd/source/delta.ts)_
210
+ _See code: [src/commands/sgd/source/delta.ts](https://github.com/scolladon/sfdx-git-delta/blob/v7.2.0/src/commands/sgd/source/delta.ts)_
207
211
  <!-- commandsstop -->
208
212
 
209
213
  ### Windows users
@@ -511,6 +515,10 @@ $ tree
511
515
  $ sf sgd source delta --from commit --source-dir force-app/unpackaged/admin --source-dir force-app/unpackaged/ui
512
516
  ```
513
517
 
518
+ Each `--source-dir` value is a **literal** repository-relative folder (or file) path, matched from the repository root — `--source-dir force-app` matches `force-app/...` but never `nested/force-app/...`. A trailing slash or a leading `./` is accepted and canonicalised (`force-app/`, `./force-app` and `force-app` all scope the same folder).
519
+
520
+ Wildcards (`*`, `?`, `[`), git pathspec magic (`:(exclude)…`, `:!…`, `:(glob)…`, …), absolute paths, `..`, and the empty string are all rejected with an error — `--source-dir` never matches a glob pattern. For pattern matching, repeat `--source-dir` once per folder, or use `--include-file [-n]` / `--ignore-file [-i]` (gitignore-spec patterns) instead.
521
+
514
522
  > The ignored patterns specified using `--ignore-file [-i]` and `--ignore-destructive-file [-D]` still apply.
515
523
  > The `--source-dir` path must be relative to the `--repo-dir` path
516
524
 
@@ -525,7 +533,7 @@ sf sgd source delta --from baseline --to HEAD --output-dir ./delta --generate-de
525
533
  $(jq -r '.packageDirectories[] | "--source-dir", .path' sfdx-project.json)
526
534
  ```
527
535
 
528
- [jq](https://jqlang.github.io/jq/) reads every `packageDirectories[].path` entry and expands it into a `--source-dir` argument.
536
+ [jq](https://jqlang.github.io/jq/) reads every `packageDirectories[].path` entry and expands it into a `--source-dir` argument. `sfdx-project.json` package directory paths commonly carry a trailing slash (e.g. `"force-app/"`); since `--source-dir` canonicalises trailing slashes away, this recipe works unchanged whether or not your `packageDirectories[].path` entries end in `/`.
529
537
 
530
538
  > See [Scoping delta generation to specific folders](#scoping-delta-generation-to-specific-folders) for the `--source-dir` behavior.
531
539
  > Prefer `--ignore-file [-i]` when you only need to skip a few known paths (e.g. `**/.claude/**`) without coupling to `sfdx-project.json`.
@@ -604,6 +612,7 @@ const work = await sgd({
604
612
  output: '', // source package specific output. [default : "./output"]
605
613
  apiVersion: '', // salesforce API version. [default : latest]
606
614
  repo: '', // git repository location. [default : "."]
615
+ source: ['.'], // (required) one or more repo-relative folders to scope the diff to; '.' (or an empty array) means the whole repository
607
616
  })
608
617
 
609
618
  console.log(JSON.stringify(work))
@@ -1,91 +1,52 @@
1
- import { type Readable } from 'node:stream';
1
+ import { Readable } from 'node:stream';
2
+ import { type ObjectId, type Repository } from '@scolladon/tsgit';
2
3
  import type { Config } from '../types/config.js';
3
4
  import type { FileGitRef } from '../types/git.js';
4
- import { GitBatchCatFile } from './gitBatchCatFile.js';
5
- import type { GitBlobReader, SpawnFn } from './gitBlobReader.js';
5
+ import type { Pathspec } from '../utils/pathspec.js';
6
+ import { type GitBlobReader } from './gitBlobReader.js';
6
7
  import { TreeIndex } from './treeIndex.js';
8
+ export type DiffScopeVerdict = {
9
+ changesSeen: number;
10
+ linesYielded: number;
11
+ };
7
12
  export default class GitAdapter implements GitBlobReader {
8
13
  protected readonly config: Config;
9
14
  private static instances;
10
15
  private static keyFor;
11
16
  static getInstance(config: Config): GitAdapter;
17
+ static closeAll(): Promise<void>;
12
18
  protected readonly treeIndex: Map<string, TreeIndex>;
13
- protected batchCatFile: GitBatchCatFile | null;
14
- private readonly streamingChildren;
15
- private static readonly STDERR_BUFFER_CAP;
16
- private static readonly LFS_POINTER_CAP;
17
- private spawnFn;
19
+ protected readonly blobIdIndex: Map<string, Map<string, ObjectId>>;
20
+ private repoHandle;
18
21
  private constructor();
19
- /**
20
- * Testability seam: lets unit tests swap in a fake spawn for streaming
21
- * subprocesses. Production always uses `child_process.spawn`.
22
- */
23
- setSpawnFn(spawnFn: SpawnFn): void;
24
- protected getBatchCatFile(): GitBatchCatFile;
25
- closeBatchProcess(): void;
26
- static closeAll(): void;
22
+ protected getRepo(): Promise<Repository>;
23
+ close(): Promise<void>;
27
24
  configureRepository(): Promise<void>;
28
25
  parseRev(ref: string): Promise<string>;
29
26
  preBuildTreeIndex(revision: string, scopePaths: string[]): Promise<void>;
30
- /**
31
- * Spawns `git <args>`, streams stdout through a readline interface, and
32
- * yields one line at a time. Replaces the old "run command, split on EOL"
33
- * pattern that accumulated a multi-MB string for megarepo diffs / tree
34
- * listings before any downstream consumer ran.
35
- *
36
- * The spawned child is pushed into streamingChildren so closeAll()
37
- * kills it if teardown happens mid-stream. stderr is drained to the
38
- * debug log; a non-zero exit code rejects the iterator on next read.
39
- */
40
- protected _spawnLines(args: string[]): AsyncGenerator<string>;
41
- /**
42
- * One-shot buffered git invocation. Spawns `git <args>`, drains stdout
43
- * fully, and returns the trimmed UTF-8 string. Used by callers that
44
- * need the complete output as a single string (revparse, raw-style
45
- * commands, config writes) rather than a line-by-line stream.
46
- *
47
- * Mirrors _spawnLines' exit-code handling: non-zero exits throw with
48
- * the stderr tail (capped at STDERR_BUFFER_CAP) in the message. Output
49
- * is trimmed so callers receive the same shape they used to get from
50
- * the legacy `simpleGit({ trimmed: true })` configuration.
51
- */
52
- protected _gitBuffered(args: string[]): Promise<string>;
53
- private _buildExitError;
54
- private _trackChild;
27
+ protected indexRevision(revision: string): Promise<Map<string, ObjectId>>;
55
28
  protected pathExistsImpl(path: string, revision: string): boolean;
56
29
  pathExists(path: string, revision?: string): Promise<boolean>;
57
30
  getFirstCommitRef(): Promise<string>;
31
+ protected resolveObjectId(forRef: FileGitRef): Promise<ObjectId>;
32
+ protected readBlobBuffer(forRef: FileGitRef): Promise<Buffer>;
58
33
  getBufferContent(forRef: FileGitRef): Promise<Buffer>;
59
34
  getBufferContentOrEscalate(forRef: FileGitRef): Promise<Buffer>;
60
- /**
61
- * Streams a directory from `revision` as `git archive --format=tar`
62
- * entries. Yields `{ path, stream }` per file entry (directories are
63
- * skipped). The tar subprocess is registered in streamingChildren so
64
- * closeAll kills it on teardown.
65
- *
66
- * Callers MUST consume each entry's stream — even when skipping the
67
- * entry — otherwise tar-stream back-pressures and halts parsing. For
68
- * skip cases use `stream.resume()` to drain-and-discard.
69
- */
35
+ streamContent(forRef: FileGitRef): Readable;
36
+ private pipeBlobContent;
37
+ private pipeLfsObject;
70
38
  streamArchive(path: string, revision: string): AsyncGenerator<{
71
39
  path: string;
72
40
  stream: Readable;
73
41
  }>;
74
- /**
75
- * Spawns a dedicated `git cat-file blob <oid>` subprocess and returns a
76
- * Readable that peeks the first chunks for LFS pointer magic. On match,
77
- * the spawned subprocess is killed and the Readable is fed from the
78
- * resolved LFS object file. Otherwise bytes are forwarded as-is.
79
- */
80
- streamContent(forRef: FileGitRef): Readable;
81
- private _wireStreamContent;
82
- private _handoffToLfs;
83
42
  getStringContent(forRef: FileGitRef): Promise<string>;
84
43
  protected getFilesPathCached(path: string, revision: string): string[];
85
44
  getFilesPath(paths: string | string[], revision?: string): Promise<string[]>;
86
45
  listDirAtRevision(dir: string, revision: string): Promise<string[]>;
87
- gitGrep(pattern: string, path: string | string[], revision?: string): Promise<string[]>;
88
- streamDiffLines(): AsyncGenerator<string>;
89
- protected _getNumstatLines(changeType: string, detectRenames: boolean): Promise<string[]>;
90
- private _getRenameLines;
46
+ grepUnderPaths(pattern: string, path: string | string[], revision?: string): Promise<string[]>;
47
+ grepMatchingPathspecs(pattern: string, path: string | string[], revision?: string): Promise<string[]>;
48
+ private grepBlobs;
49
+ streamDiffLines(verdict: DiffScopeVerdict, scopes: readonly Pathspec[]): AsyncGenerator<string>;
50
+ getUnmatchedSourceScopes(verdict: DiffScopeVerdict, scopes: readonly Pathspec[]): readonly string[];
51
+ private requestDiff;
91
52
  }