@simbo/git-changes 2.0.0 → 2.1.1

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 CHANGED
@@ -1,5 +1,20 @@
1
1
  # @simbo/git-changes
2
2
 
3
+ ## 2.1.1
4
+
5
+ ### Patch Changes
6
+
7
+ - 48389a9: Parse Git status characters into enum members without unsafe type
8
+ assertions and allow the added status in the unstaged type to match existing
9
+ parser behavior.
10
+ - @simbo/find-git-repository-root@2.0.0
11
+
12
+ ## 2.1.0
13
+
14
+ ### Minor Changes
15
+
16
+ - 50850c2: simplify types for git changes
17
+
3
18
  ## 2.0.0
4
19
 
5
20
  ### Major Changes
package/README.md CHANGED
@@ -31,4 +31,4 @@ For a complete API reference, see the
31
31
 
32
32
  ## License
33
33
 
34
- [MIT © Simon Lepel](http://simbo.mit-license.org/2025/)
34
+ [MIT © Simon Lepel](https://simbo.mit-license.org/2025/)
@@ -8,54 +8,41 @@ export type GitChangeStatusCommon = GitChangeStatus.Modified | GitChangeStatus.D
8
8
  */
9
9
  export type GitChangeStatusWithOriginPath = GitChangeStatus.Renamed | GitChangeStatus.Copied;
10
10
  /**
11
- * Added Git change status (only for staged changes).
11
+ * Added Git change status.
12
12
  */
13
13
  export type GitChangeStatusAdded = GitChangeStatus.Added;
14
14
  /**
15
15
  * Untracked Git change status (only for unstaged changes).
16
16
  */
17
17
  export type GitChangeStatusUntracked = GitChangeStatus.Untracked;
18
+ /**
19
+ * Combined type for staged changes field.
20
+ */
18
21
  export type GitChangeStagedStatus = GitChangeStatusCommon | GitChangeStatusAdded | GitChangeStatusWithOriginPath;
19
- export type GitChangeUnstagedStatus = GitChangeStatusCommon | GitChangeStatusUntracked | GitChangeStatusWithOriginPath;
20
22
  /**
21
- * A change in a Git repository.
23
+ * Combined type for unstaged changes field.
22
24
  */
23
- export type GitChange<Staged extends GitChangeStagedStatus | undefined = GitChangeStagedStatus | undefined, Unstaged extends GitChangeUnstagedStatus | undefined = GitChangeUnstagedStatus | undefined> = GitChangeBase & (Staged extends GitChangeStagedStatus ? GitChangeStaged : object) & (Unstaged extends GitChangeUnstagedStatus ? GitChangeUnstaged : object) & (Staged extends GitChangeStatusWithOriginPath ? GitChangeWithOriginPath : object) & (Unstaged extends GitChangeStatusWithOriginPath ? GitChangeWithOriginPath : object);
25
+ export type GitChangeUnstagedStatus = GitChangeStatusCommon | GitChangeStatusAdded | GitChangeStatusUntracked | GitChangeStatusWithOriginPath;
24
26
  /**
25
- * Base interface for a change in a Git repository.
27
+ * Interface for a change in a Git repository.
26
28
  */
27
- export interface GitChangeBase {
29
+ export interface GitChange {
28
30
  /**
29
31
  * The file path of the change.
30
32
  */
31
33
  path: string;
32
- }
33
- /**
34
- * A change in a Git repository that is staged.
35
- */
36
- export interface GitChangeStaged {
37
34
  /**
38
- * The status of the change when it is staged.
35
+ * The status of the change if it is staged.
39
36
  * This can be one of the GitChangeStatus values or undefined if not staged.
40
37
  */
41
- staged: GitChangeStagedStatus;
42
- }
43
- /**
44
- * A change in a Git repository that is unstaged.
45
- */
46
- export interface GitChangeUnstaged {
38
+ staged?: GitChangeStagedStatus;
47
39
  /**
48
- * The status of the change when it is unstaged.
40
+ * The status of the change if it is unstaged.
49
41
  * This can be one of the GitChangeStatus values or undefined if not unstaged.
50
42
  */
51
- unstaged: GitChangeUnstagedStatus;
52
- }
53
- /**
54
- * A change in a Git repository that includes an origin path.
55
- */
56
- export interface GitChangeWithOriginPath {
43
+ unstaged?: GitChangeUnstagedStatus;
57
44
  /**
58
45
  * The original file path before the change (for renamed or copied files).
59
46
  */
60
- originPath: string;
47
+ originPath?: string;
61
48
  }
@@ -1,4 +1,4 @@
1
- import type { GitChangeStagedStatus, GitChangeUnstagedStatus } from './git-changes.types.js';
1
+ import type { GitChange } from './git-changes.types.js';
2
2
  /**
3
3
  * Parses a Git change status string into staged and unstaged statuses.
4
4
  *
@@ -13,7 +13,4 @@ import type { GitChangeStagedStatus, GitChangeUnstagedStatus } from './git-chang
13
13
  * @param status - A two-character string representing the Git change status.
14
14
  * @returns An object containing the staged and unstaged statuses.
15
15
  */
16
- export declare function parseGitChangeStatus(status: string): {
17
- staged: GitChangeStagedStatus | undefined;
18
- unstaged: GitChangeUnstagedStatus | undefined;
19
- };
16
+ export declare function parseGitChangeStatus(status: string): Pick<GitChange, 'staged' | 'unstaged'>;
@@ -1,5 +1,5 @@
1
1
  import { GitChangeStatus } from './git-change-status.enum.js';
2
- import { KNOWN_GIT_CHANGE_STATUSES } from './git-status-constants.js';
2
+ const trackedStatuses = Object.values(GitChangeStatus).filter(value => value !== GitChangeStatus.Untracked);
3
3
  /**
4
4
  * Parses a Git change status string into staged and unstaged statuses.
5
5
  *
@@ -21,7 +21,8 @@ export function parseGitChangeStatus(status) {
21
21
  if (status.startsWith('??')) {
22
22
  return { staged: undefined, unstaged: GitChangeStatus.Untracked };
23
23
  }
24
- const [staged, unstaged] = [status[0], status[1]].map(char => char && char !== '?' && KNOWN_GIT_CHANGE_STATUSES.has(char) ? char : undefined);
24
+ const staged = trackedStatuses.find((value) => value === status[0]);
25
+ const unstaged = trackedStatuses.find((value) => value === status[1]);
25
26
  return { staged, unstaged };
26
27
  }
27
28
  //# sourceMappingURL=parse-git-change-status.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"parse-git-change-status.js","sourceRoot":"","sources":["../src/parse-git-change-status.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,6BAA6B,CAAC;AAE9D,OAAO,EAAE,yBAAyB,EAAE,MAAM,2BAA2B,CAAC;AAEtE;;;;;;;;;;;;;GAaG;AACH,MAAM,UAAU,oBAAoB,CAAC,MAAc;IAIjD,IAAI,OAAO,MAAM,KAAK,QAAQ,IAAI,MAAM,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;QACpD,OAAO,EAAE,MAAM,EAAE,SAAS,EAAE,QAAQ,EAAE,SAAS,EAAE,CAAC;IACpD,CAAC;IAED,IAAI,MA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E,EAAE,CAAC,KAAK,KAAK,MAAM,CAAC,CAAC,CAAC,CAAC,CAAC;IAC5E,MAAM,QAAQ,GAAG,eAAe,CAAC,IAAI,CAAC,CAAC,KAAa,EAAE,EAAE,CAAC,KAAK,KAAK,MAAM,CAAC,CAAC,CAAC,CAAC,CAAC;IAE9E,OAAO,EAAE,MAAM,EAAE,QAAQ,EAAE,CAAC;AAC9B,CAAC"}
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@simbo/git-changes",
3
3
  "description": "A library to read, parse and provide Git changes information from `git status` for a local repository.",
4
- "version": "2.0.0",
4
+ "version": "2.1.1",
5
5
  "keywords": [
6
6
  "git",
7
7
  "changes",
@@ -16,7 +16,7 @@
16
16
  ],
17
17
  "author": "Simon Lepel <simbo@simbo.de> (https://simbo.de/)",
18
18
  "license": "MIT",
19
- "homepage": "http://github.com/simbo/packages/tree/main/packages/git-changes",
19
+ "homepage": "https://github.com/simbo/packages/tree/main/packages/git-changes",
20
20
  "repository": {
21
21
  "type": "git",
22
22
  "url": "github:simbo/packages"
@@ -41,18 +41,18 @@
41
41
  },
42
42
  "devDependencies": {
43
43
  "@ianvs/prettier-plugin-sort-imports": "^4.7.1",
44
- "@simbo/eslint-config": "3.0.0",
45
- "@simbo/prettier-config": "3.0.0",
44
+ "@simbo/eslint-config": "3.2.0",
45
+ "@simbo/prettier-config": "3.0.1",
46
46
  "@simbo/tsconfig": "2.0.0",
47
- "@types/node": "^24.13.6",
48
- "@vitest/coverage-v8": "^5.0.1",
49
- "@vitest/ui": "^5.0.1",
50
- "baseline-browser-mapping": "^2.11.25",
47
+ "@types/node": "^24.19.0",
48
+ "@vitest/coverage-v8": "^5.0.3",
49
+ "@vitest/ui": "^5.0.3",
50
+ "baseline-browser-mapping": "^2.11.26",
51
51
  "eslint": "^10.11.0",
52
52
  "jiti": "^2.7.0",
53
- "prettier": "^3.9.8",
53
+ "prettier": "^3.9.9",
54
54
  "typescript": "^6.0.3",
55
- "vitest": "^5.0.1"
55
+ "vitest": "^5.0.3"
56
56
  },
57
57
  "scripts": {
58
58
  "build": "tsc --project tsconfig.build.json",