sfdx-git-delta 7.1.0 → 7.3.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 (134) hide show
  1. package/README.md +27 -5
  2. package/lib/adapter/GitAdapter.d.ts +26 -12
  3. package/lib/adapter/GitAdapter.js +162 -175
  4. package/lib/adapter/GitAdapter.js.map +1 -1
  5. package/lib/adapter/ioExecutor.d.ts +6 -7
  6. package/lib/adapter/ioExecutor.js +22 -22
  7. package/lib/adapter/ioExecutor.js.map +1 -1
  8. package/lib/adapter/pathMatching.d.ts +9 -0
  9. package/lib/adapter/pathMatching.js +83 -0
  10. package/lib/adapter/pathMatching.js.map +1 -0
  11. package/lib/adapter/treeIndex.d.ts +7 -4
  12. package/lib/adapter/treeIndex.js +34 -0
  13. package/lib/adapter/treeIndex.js.map +1 -1
  14. package/lib/adapter/treeReader.d.ts +8 -0
  15. package/lib/adapter/treeReader.js +22 -0
  16. package/lib/adapter/treeReader.js.map +1 -0
  17. package/lib/commands/sgd/source/delta.d.ts +1 -0
  18. package/lib/commands/sgd/source/delta.js +5 -0
  19. package/lib/commands/sgd/source/delta.js.map +1 -1
  20. package/lib/main.d.ts +2 -2
  21. package/lib/main.js +84 -37
  22. package/lib/main.js.map +1 -1
  23. package/lib/post-processor/baseProcessor.d.ts +11 -8
  24. package/lib/post-processor/baseProcessor.js +8 -8
  25. package/lib/post-processor/baseProcessor.js.map +1 -1
  26. package/lib/post-processor/changesManifestProcessor.d.ts +3 -2
  27. package/lib/post-processor/changesManifestProcessor.js +5 -4
  28. package/lib/post-processor/changesManifestProcessor.js.map +1 -1
  29. package/lib/post-processor/flowTranslationProcessor.d.ts +6 -8
  30. package/lib/post-processor/flowTranslationProcessor.js +18 -20
  31. package/lib/post-processor/flowTranslationProcessor.js.map +1 -1
  32. package/lib/post-processor/includeProcessor.d.ts +6 -6
  33. package/lib/post-processor/includeProcessor.js +8 -7
  34. package/lib/post-processor/includeProcessor.js.map +1 -1
  35. package/lib/post-processor/packageGenerator.d.ts +3 -2
  36. package/lib/post-processor/packageGenerator.js +5 -4
  37. package/lib/post-processor/packageGenerator.js.map +1 -1
  38. package/lib/post-processor/postProcessorManager.d.ts +5 -8
  39. package/lib/post-processor/postProcessorManager.js +24 -32
  40. package/lib/post-processor/postProcessorManager.js.map +1 -1
  41. package/lib/service/botHandler.d.ts +1 -2
  42. package/lib/service/botHandler.js +17 -10
  43. package/lib/service/botHandler.js.map +1 -1
  44. package/lib/service/containedDecomposedHandler.d.ts +4 -5
  45. package/lib/service/containedDecomposedHandler.js +14 -13
  46. package/lib/service/containedDecomposedHandler.js.map +1 -1
  47. package/lib/service/customFieldHandler.d.ts +1 -2
  48. package/lib/service/customFieldHandler.js +7 -6
  49. package/lib/service/customFieldHandler.js.map +1 -1
  50. package/lib/service/customLabelHandler.d.ts +1 -2
  51. package/lib/service/customLabelHandler.js +3 -3
  52. package/lib/service/customLabelHandler.js.map +1 -1
  53. package/lib/service/customObjectHandler.d.ts +3 -4
  54. package/lib/service/customObjectHandler.js +11 -10
  55. package/lib/service/customObjectHandler.js.map +1 -1
  56. package/lib/service/decomposedHandler.d.ts +3 -4
  57. package/lib/service/decomposedHandler.js +5 -4
  58. package/lib/service/decomposedHandler.js.map +1 -1
  59. package/lib/service/diffLineInterpreter.d.ts +3 -5
  60. package/lib/service/diffLineInterpreter.js +17 -16
  61. package/lib/service/diffLineInterpreter.js.map +1 -1
  62. package/lib/service/flowHandler.d.ts +1 -2
  63. package/lib/service/flowHandler.js +9 -4
  64. package/lib/service/flowHandler.js.map +1 -1
  65. package/lib/service/inFileHandler.d.ts +8 -9
  66. package/lib/service/inFileHandler.js +25 -25
  67. package/lib/service/inFileHandler.js.map +1 -1
  68. package/lib/service/inFolderHandler.d.ts +4 -5
  69. package/lib/service/inFolderHandler.js +7 -6
  70. package/lib/service/inFolderHandler.js.map +1 -1
  71. package/lib/service/inResourceHandler.d.ts +4 -5
  72. package/lib/service/inResourceHandler.js +11 -9
  73. package/lib/service/inResourceHandler.js.map +1 -1
  74. package/lib/service/objectTranslationHandler.d.ts +1 -2
  75. package/lib/service/objectTranslationHandler.js +6 -5
  76. package/lib/service/objectTranslationHandler.js.map +1 -1
  77. package/lib/service/reportingFolderHandler.d.ts +6 -7
  78. package/lib/service/reportingFolderHandler.js +6 -6
  79. package/lib/service/reportingFolderHandler.js.map +1 -1
  80. package/lib/service/sharedFolderHandler.d.ts +4 -5
  81. package/lib/service/sharedFolderHandler.js +6 -6
  82. package/lib/service/sharedFolderHandler.js.map +1 -1
  83. package/lib/service/standardHandler.d.ts +8 -10
  84. package/lib/service/standardHandler.js +34 -36
  85. package/lib/service/standardHandler.js.map +1 -1
  86. package/lib/service/typeHandlerFactory.d.ts +7 -5
  87. package/lib/service/typeHandlerFactory.js +13 -12
  88. package/lib/service/typeHandlerFactory.js.map +1 -1
  89. package/lib/types/config.d.ts +6 -1
  90. package/lib/types/handlerResult.d.ts +7 -7
  91. package/lib/types/handlerResult.js +10 -1
  92. package/lib/types/handlerResult.js.map +1 -1
  93. package/lib/types/runContext.d.ts +21 -0
  94. package/lib/types/runContext.js +12 -0
  95. package/lib/types/runContext.js.map +1 -0
  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 +8 -6
  109. package/lib/utils/configValidator.js +56 -13
  110. package/lib/utils/configValidator.js.map +1 -1
  111. package/lib/utils/fsHelper.d.ts +5 -3
  112. package/lib/utils/fsHelper.js +12 -9
  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/metadataBoundaryResolver.d.ts +7 -5
  118. package/lib/utils/metadataBoundaryResolver.js +18 -21
  119. package/lib/utils/metadataBoundaryResolver.js.map +1 -1
  120. package/lib/utils/pathspec.d.ts +15 -0
  121. package/lib/utils/pathspec.js +71 -0
  122. package/lib/utils/pathspec.js.map +1 -0
  123. package/lib/utils/renameResolver.d.ts +6 -7
  124. package/lib/utils/renameResolver.js +10 -9
  125. package/lib/utils/renameResolver.js.map +1 -1
  126. package/lib/utils/repoGitDiff.d.ts +3 -0
  127. package/lib/utils/repoGitDiff.js +30 -1
  128. package/lib/utils/repoGitDiff.js.map +1 -1
  129. package/messages/delta.md +38 -0
  130. package/oclif.manifest.json +10 -3
  131. package/package.json +23 -22
  132. package/lib/post-processor/bundleRollupProcessor.d.ts +0 -7
  133. package/lib/post-processor/bundleRollupProcessor.js +0 -81
  134. package/lib/post-processor/bundleRollupProcessor.js.map +0 -1
package/README.md CHANGED
@@ -26,6 +26,9 @@
26
26
  > [!WARNING]
27
27
  > **Potentially breaking changes in v6**: Check out the [v6 migration guide](docs/migrating-to-v6.0.0.md) to see how you could be impacted by some changes in the new major `v6` version of the plugin, and how to migrate to this version.
28
28
 
29
+ > [!WARNING]
30
+ > **Breaking change for programmatic consumers**: `Config.mergeBase` is now a required field. Add `mergeBase: false` to your config to preserve today's behavior. See the [merge-base migration guide](docs/migrating-config-merge-base.md) for details.
31
+
29
32
  <!-- TABLE OF CONTENTS -->
30
33
  <details>
31
34
  <summary>Table of Contents</summary>
@@ -149,7 +152,7 @@ Generate incremental package manifest and source content
149
152
 
150
153
  ```
151
154
  USAGE
152
- $ sf sgd source delta -f <value> [--json] [--flags-dir <value>] [-t <value>] [-d] [-o <value>] [-r <value>] [-s
155
+ $ sf sgd source delta -f <value> [--json] [--flags-dir <value>] [-t <value>] [-b] [-d] [-o <value>] [-r <value>] [-s
153
156
  <value>...] [-i <value>] [-D <value>] [-n <value>] [-N <value>] [-M <value>] [-c <value>] [-W] [-a <value>]
154
157
 
155
158
  FLAGS
@@ -159,6 +162,8 @@ FLAGS
159
162
  -W, --ignore-whitespace ignore git diff whitespace (space, tab, eol) changes
160
163
  -a, --api-version=<value> salesforce metadata API version, default to sfdx-project.json
161
164
  "sourceApiVersion" attribute or latest version
165
+ -b, --merge-base diff from the merge base of --from and --to instead of --from itself (git
166
+ three-dot semantics)
162
167
  -c, --changes-manifest=<value> path to a JSON file grouping changed components by kind (add, modify,
163
168
  delete, rename); setting this flag also enables git rename detection
164
169
  -d, --generate-delta generate delta files in [--output-dir] folder
@@ -184,6 +189,8 @@ EXAMPLES
184
189
  $ sf sgd source delta --from "origin/development" --output-dir incremental
185
190
  - Build incremental manifest and source from the development branch
186
191
  $ sf sgd source delta --from "origin/development" --generate-delta --output-dir incremental
192
+ - Build incremental manifest from where the current branch diverged from main
193
+ $ sf sgd source delta --from "main" --merge-base --output-dir incremental
187
194
 
188
195
  FLAG DESCRIPTIONS
189
196
  -a, --api-version=<value>
@@ -201,9 +208,13 @@ FLAG DESCRIPTIONS
201
208
  * If the folder exists, its contents will be processed.
202
209
  * If the folder doesn't exist, it usually won't show any output—unless the folder was recently deleted and is part
203
210
  of a diff, in which case changes may still be picked up.
211
+
212
+ Each value must be a literal repository-relative path: wildcards (`*`, `?`, `[`), git pathspec magic (`:(...)`),
213
+ absolute paths, `..` and the empty string are all rejected. Matching is rooted at the repository root, so
214
+ `--source-dir force-app` does not match `nested/force-app/...`.
204
215
  ```
205
216
 
206
- _See code: [src/commands/sgd/source/delta.ts](https://github.com/scolladon/sfdx-git-delta/blob/v7.1.0/src/commands/sgd/source/delta.ts)_
217
+ _See code: [src/commands/sgd/source/delta.ts](https://github.com/scolladon/sfdx-git-delta/blob/v7.3.0/src/commands/sgd/source/delta.ts)_
207
218
  <!-- commandsstop -->
208
219
 
209
220
  ### Windows users
@@ -226,6 +237,9 @@ In CI/CD pipelines, for most of the CI/CD providers, the checkout operation fetc
226
237
  You need to fetch all the needed commits as the plugin needs access to the branch being compared.
227
238
  Example for Github action checkout [here](https://github.com/actions/checkout#fetch-all-history-for-all-tags-and-branches).
228
239
  If you use `-n` (`--include-file`) with metadata contained inside files you will need to have the full repo locally for the command to fully work.
240
+ With `--merge-base [-b]`, a shallow clone is an even sharper trap: `--from` and `--to` can each resolve to a valid commit while their histories still don't connect within the fetched depth, so SGD reports "no merge base found" even though the refs themselves are fine. Fetch enough history for the two branches to actually share an ancestor, not just enough for each ref to resolve.
241
+
242
+ GitHub Actions' `pull_request` trigger checks out a synthetic merge commit whose parent already **is** the base branch tip, so `merge-base(HEAD, main)` resolves to `main`'s tip and `--merge-base` silently becomes a no-op (`--from main --merge-base` behaves like `--from main`). If you need true divergence semantics in that context, target the PR head commit directly — `--to <head sha>` (from the `pull_request` event payload) — or check out `ref: <head sha>` instead of the default merge ref.
229
243
 
230
244
  In CI/CD pipelines, branches are not checked out locally when the repository is cloned, so you must specify the remote prefix.
231
245
  If you do not specify the remote in CI context, the git pointer check will raise an error (as the branch is not created locally).
@@ -278,12 +292,14 @@ sf sgd source delta --to develop --from main --output-dir .
278
292
  ```
279
293
 
280
294
  - **Comparing branches (from a common ancestor)**
281
- To compare the `develop` branch since its common ancestor with the `main` branch (i.e. ignoring the changes performed in the `main` branch after `develop` creation):
295
+ To compare the `develop` branch since its common ancestor with the `main` branch (i.e. ignoring the changes performed in the `main` branch after `develop` creation), use `--merge-base [-b]`:
282
296
 
283
297
  ```sh
284
- sf sgd source delta --to develop --from $(git merge-base develop main) --output-dir .
298
+ sf sgd source delta --to develop --from main --merge-base --output-dir .
285
299
  ```
286
300
 
301
+ This is equivalent to `git diff main...develop` (three-dot, common-ancestor semantics). Unlike the `$(git merge-base ...)` shell form, `--merge-base` resolves inside `--repo-dir` and needs no shell — the shell form always resolves in the current directory regardless of `--repo-dir`.
302
+
287
303
  ## Walkthrough
288
304
 
289
305
  Consider the following scenario:
@@ -511,6 +527,10 @@ $ tree
511
527
  $ sf sgd source delta --from commit --source-dir force-app/unpackaged/admin --source-dir force-app/unpackaged/ui
512
528
  ```
513
529
 
530
+ 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).
531
+
532
+ 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.
533
+
514
534
  > The ignored patterns specified using `--ignore-file [-i]` and `--ignore-destructive-file [-D]` still apply.
515
535
  > The `--source-dir` path must be relative to the `--repo-dir` path
516
536
 
@@ -525,7 +545,7 @@ sf sgd source delta --from baseline --to HEAD --output-dir ./delta --generate-de
525
545
  $(jq -r '.packageDirectories[] | "--source-dir", .path' sfdx-project.json)
526
546
  ```
527
547
 
528
- [jq](https://jqlang.github.io/jq/) reads every `packageDirectories[].path` entry and expands it into a `--source-dir` argument.
548
+ [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
549
 
530
550
  > See [Scoping delta generation to specific folders](#scoping-delta-generation-to-specific-folders) for the `--source-dir` behavior.
531
551
  > Prefer `--ignore-file [-i]` when you only need to skip a few known paths (e.g. `**/.claude/**`) without coupling to `sfdx-project.json`.
@@ -601,9 +621,11 @@ import sgd from 'sfdx-git-delta'
601
621
  const work = await sgd({
602
622
  to: '', // commit sha to where the diff is done. [default : "HEAD"]
603
623
  from: '', // (required) commit sha from where the diff is done. [default : git rev-list --max-parents=0 HEAD]
624
+ mergeBase: false, // (required) resolve `from` to the merge base of `from`/`to` first. [default : false]
604
625
  output: '', // source package specific output. [default : "./output"]
605
626
  apiVersion: '', // salesforce API version. [default : latest]
606
627
  repo: '', // git repository location. [default : "."]
628
+ source: ['.'], // (required) one or more repo-relative folders to scope the diff to; '.' (or an empty array) means the whole repository
607
629
  })
608
630
 
609
631
  console.log(JSON.stringify(work))
@@ -1,27 +1,41 @@
1
1
  import { Readable } from 'node:stream';
2
- import { type ObjectId, type Repository } from '@scolladon/tsgit';
2
+ import { type Commit, type ObjectId, type Repository } from '@scolladon/tsgit';
3
3
  import type { Config } from '../types/config.js';
4
4
  import type { FileGitRef } from '../types/git.js';
5
+ import type { Pathspec } from '../utils/pathspec.js';
5
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
+ };
12
+ export type DiffSpec = Readonly<{
13
+ from: string;
14
+ to: string;
15
+ detectRenames: boolean;
16
+ ignoreWhitespace: boolean;
17
+ }>;
18
+ export type DiffRequest = Readonly<{
19
+ spec: DiffSpec;
20
+ verdict: DiffScopeVerdict;
21
+ scopes: readonly Pathspec[];
22
+ }>;
7
23
  export default class GitAdapter implements GitBlobReader {
8
- protected readonly config: Config;
24
+ private readonly repo;
9
25
  private static instances;
10
26
  private static keyFor;
11
27
  static getInstance(config: Config): GitAdapter;
12
28
  static closeAll(): Promise<void>;
13
- protected readonly treeIndex: Map<string, TreeIndex>;
14
29
  protected readonly blobIdIndex: Map<string, Map<string, ObjectId>>;
15
30
  private repoHandle;
16
31
  private constructor();
17
32
  protected getRepo(): Promise<Repository>;
18
33
  close(): Promise<void>;
19
- configureRepository(): Promise<void>;
20
34
  parseRev(ref: string): Promise<string>;
21
- preBuildTreeIndex(revision: string, scopePaths: string[]): Promise<void>;
35
+ buildTreeIndex(revision: string, scopePaths: readonly string[]): Promise<TreeIndex | undefined>;
36
+ protected peelToCommit(oid: ObjectId, label: string): Promise<Commit>;
22
37
  protected indexRevision(revision: string): Promise<Map<string, ObjectId>>;
23
- protected pathExistsImpl(path: string, revision: string): boolean;
24
- pathExists(path: string, revision?: string): Promise<boolean>;
38
+ getMergeBase(from: string, to: string): Promise<string | undefined>;
25
39
  getFirstCommitRef(): Promise<string>;
26
40
  protected resolveObjectId(forRef: FileGitRef): Promise<ObjectId>;
27
41
  protected readBlobBuffer(forRef: FileGitRef): Promise<Buffer>;
@@ -35,10 +49,10 @@ export default class GitAdapter implements GitBlobReader {
35
49
  stream: Readable;
36
50
  }>;
37
51
  getStringContent(forRef: FileGitRef): Promise<string>;
38
- protected getFilesPathCached(path: string, revision: string): string[];
39
- getFilesPath(paths: string | string[], revision?: string): Promise<string[]>;
40
- listDirAtRevision(dir: string, revision: string): Promise<string[]>;
41
- gitGrep(pattern: string, path: string | string[], revision?: string): Promise<string[]>;
42
- streamDiffLines(): AsyncGenerator<string>;
52
+ grepUnderPaths(pattern: string, path: string | string[], revision: string): Promise<string[]>;
53
+ grepMatchingPathspecs(pattern: string, path: string | string[], revision: string): Promise<string[]>;
54
+ private grepBlobs;
55
+ streamDiffLines(request: DiffRequest): AsyncGenerator<string>;
56
+ getUnmatchedSourceScopes(verdict: DiffScopeVerdict, scopes: readonly Pathspec[]): readonly string[];
43
57
  private requestDiff;
44
58
  }